Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 019aa1e

Browse files
committed
Bug fixes:
Line clipsToBounds to avoid drawing outside the box (when extrapolating nulls or user set minValue too High) Top/Bottom reference lines were outside box When Bezier off and Interpolate nulls off, properly draws line segments now Removed VMA NSLog from TestBed/MasterController
1 parent 1169854 commit 019aa1e

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

Classes/BEMLine.m

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
3333
_enableLeftReferenceFrameLine = YES;
3434
_enableBottomReferenceFrameLine = YES;
3535
_interpolateNullValues = YES;
36+
self.clipsToBounds = YES;
3637
}
3738
return self;
3839
}
@@ -59,8 +60,8 @@ - (void)drawRect:(CGRect)rect {
5960
if (self.enableReferenceFrame == YES) {
6061
if (self.enableBottomReferenceFrameLine) {
6162
// Bottom Line
62-
[referenceFramePath moveToPoint:CGPointMake(0, self.frame.size.height)];
63-
[referenceFramePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
63+
[referenceFramePath moveToPoint:CGPointMake(0, self.frame.size.height-self.referenceLineWidth/4)];
64+
[referenceFramePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height-self.referenceLineWidth/4)];
6465
}
6566

6667
if (self.enableLeftReferenceFrameLine) {
@@ -71,8 +72,8 @@ - (void)drawRect:(CGRect)rect {
7172

7273
if (self.enableTopReferenceFrameLine) {
7374
// Top Line
74-
[referenceFramePath moveToPoint:CGPointMake(0+self.referenceLineWidth/4, 0)];
75-
[referenceFramePath addLineToPoint:CGPointMake(self.frame.size.width, 0)];
75+
[referenceFramePath moveToPoint:CGPointMake(0+self.referenceLineWidth/4, self.referenceLineWidth/4)];
76+
[referenceFramePath addLineToPoint:CGPointMake(self.frame.size.width, self.referenceLineWidth/4)];
7677
}
7778

7879
if (self.enableRightReferenceFrameLine) {
@@ -192,12 +193,12 @@ - (void)drawRect:(CGRect)rect {
192193
fillBottom = [BEMLine quadCurvedPathWithPoints:self.bottomPointsArray open:NO];
193194
fillTop = [BEMLine quadCurvedPathWithPoints:self.topPointsArray open:NO];
194195
} else if (!self.disableMainLine && !self.bezierCurveIsEnabled) {
195-
line = [BEMLine linesToPoints:self.points];
196-
fillBottom = [BEMLine linesToPoints:self.bottomPointsArray];
197-
fillTop = [BEMLine linesToPoints:self.topPointsArray];
196+
line = [BEMLine linesToPoints:self.points open:YES];
197+
fillBottom = [BEMLine linesToPoints:self.bottomPointsArray open:NO];
198+
fillTop = [BEMLine linesToPoints:self.topPointsArray open:NO];
198199
} else {
199-
fillBottom = [BEMLine linesToPoints:self.bottomPointsArray];
200-
fillTop = [BEMLine linesToPoints:self.topPointsArray];
200+
fillBottom = [BEMLine linesToPoints:self.bottomPointsArray open:NO];
201+
fillTop = [BEMLine linesToPoints:self.topPointsArray open:NO];
201202
}
202203

203204
//----------------------------//
@@ -340,15 +341,22 @@ - (void)drawRect:(CGRect)rect {
340341
return bottomPoints;
341342
}
342343

343-
+ (UIBezierPath *)linesToPoints:(NSArray <NSValue *> *)points {
344+
+ (UIBezierPath *)linesToPoints:(NSArray <NSValue *> *)points open:(BOOL) canSkipPoints {
344345
UIBezierPath *path = [UIBezierPath bezierPath];
345346
NSValue *value = points[0];
346347
CGPoint p1 = [value CGPointValue];
347348
[path moveToPoint:p1];
348349

349350
for (NSValue * point in points) {
351+
if (point == value) continue; //already at first point
350352
CGPoint p2 = [point CGPointValue];
351-
[path addLineToPoint:p2];
353+
354+
if (canSkipPoints && (p1.y >= BEMNullGraphValue || p2.y >= BEMNullGraphValue)) {
355+
[path moveToPoint:p2];
356+
} else {
357+
[path addLineToPoint:p2];
358+
}
359+
p1 = p2;
352360
}
353361
return path;
354362
}

Classes/BEMSimpleLineGraphView.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,11 @@ - (CGFloat) calculateWidestLabel {
519519
} else {
520520
widestNumber = [self labelWidthForValue:self.frame.size.height] ;
521521
}
522-
return MAX(widestNumber, [self.averageLine.title sizeWithAttributes:attributes].width);
522+
if (self.averageLine.enableAverageLine) {
523+
return MAX(widestNumber, [self.averageLine.title sizeWithAttributes:attributes].width);
524+
} else {
525+
return widestNumber;
526+
}
523527
}
524528

525529

@@ -1003,6 +1007,7 @@ - (void)drawYAxis {
10031007
if ([self.delegate respondsToSelector:@selector(baseValueForYAxisOnLineGraph:)] && [self.delegate respondsToSelector:@selector(incrementValueForYAxisOnLineGraph:)]) {
10041008
value = [self.delegate baseValueForYAxisOnLineGraph:self];
10051009
increment = [self.delegate incrementValueForYAxisOnLineGraph:self];
1010+
if (increment <= 0) increment = 1;
10061011
numberOfLabels = (NSUInteger) ((self.maxValue - value)/increment)+1;
10071012
if (numberOfLabels > 100) {
10081013
NSLog(@"[BEMSimpleLineGraph] Increment does not properly lay out Y axis, bailing early");
@@ -1447,7 +1452,7 @@ - (CGFloat)yPositionForDotValue:(CGFloat)dotValue {
14471452
CGFloat percentValue = (dotValue - self.minValue) / (self.maxValue - self.minValue);
14481453
CGFloat topOfChart = self.frame.size.height - padding/2.0f;
14491454
CGFloat sizeOfChart = self.frame.size.height - padding;
1450-
positionOnYAxis = topOfChart - percentValue * sizeOfChart + self.XAxisLabelYOffset/2;
1455+
positionOnYAxis = topOfChart - percentValue * sizeOfChart + self.XAxisLabelYOffset;
14511456
}
14521457
} else {
14531458
positionOnYAxis = ((self.frame.size.height) - dotValue);

Sample Project/TestBed/MasterViewController.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ - (void)viewDidLoad {
206206
-(void) viewWillAppear:(BOOL)animated {
207207
[super viewWillAppear:animated];
208208
if (!self.hasRestoredUI) [self restoreUI];
209-
NSLog(@"VWA");
210209
}
211210

212211
-(void) decodeRestorableStateWithCoder:(NSCoder *)coder {

0 commit comments

Comments
 (0)