Skip to content

Commit fd993c0

Browse files
committed
Bug fixes:
Some reference lines not appearing Sometimes highest xaxis label doesn't appear Nudge y labels onto page Highest y label doesn't appear when averagelabel is off When changing data sources, sometimes minXDisplayed gets out of sync Several properties not properly restored.
1 parent 13b0172 commit fd993c0

3 files changed

Lines changed: 47 additions & 28 deletions

File tree

Classes/BEMSimpleLineGraphView.m

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ - (void)drawXAxis {
904904
if (CGRectContainsRect(self.backgroundXAxis.bounds, labelXAxis.frame)){
905905
[self.backgroundXAxis addSubview:labelXAxis];
906906
if (self.enableReferenceXAxisLines &&
907-
(self.dataPoints[index].CGPointValue.y < BEMNullGraphValue || self.interpolateNullValues)) {
907+
(allLabelLocations[index].CGPointValue.y < BEMNullGraphValue || self.interpolateNullValues)) {
908908
[newReferenceLinePoints addObject:@(positionOnXAxis)];
909909
}
910910
}
@@ -970,7 +970,7 @@ - (UILabel *)xAxisLabelWithText:(NSString *) text atLocation:(CGFloat) positionO
970970
if (positionOnXAxis + halfWidth >= 0) positionOnXAxis = MAX(positionOnXAxis, halfWidth);
971971
CGFloat rightEdge = CGRectGetMaxX(self.backgroundXAxis.bounds) ;
972972
if (positionOnXAxis - halfWidth <= rightEdge) {
973-
positionOnXAxis = MIN(positionOnXAxis, rightEdge - halfWidth);
973+
positionOnXAxis = MIN(positionOnXAxis, rightEdge - halfWidth-.1);
974974
}
975975
labelXAxis.frame = lRect;
976976
labelXAxis.center = CGPointMake(positionOnXAxis, CGRectGetMidY(self.backgroundXAxis.bounds));
@@ -1020,8 +1020,21 @@ - (UILabel *)yAxisLabelWithText:(NSString *)text atValue:(CGFloat)value reuseNum
10201020
labelYAxis.textColor = self.colorYaxisLabel;
10211021
labelYAxis.backgroundColor = [UIColor clearColor];
10221022
CGFloat yAxisPosition = [self yPositionForDotValue:value];
1023+
if (self.enableXAxisLabel && self.positionXAxisTop) {
1024+
//because y axis frame is independent of xaxis presence (as opposed to dot view), we have to adjust here
1025+
yAxisPosition += CGRectGetHeight(self.backgroundXAxis.frame);
1026+
}
1027+
CGFloat halfLabel = labelHeight/2;
1028+
CGFloat topEdge = CGRectGetMaxY(self.backgroundYAxis.bounds);
1029+
//nudge partially visible top/bottom labels onto screen
1030+
if (yAxisPosition > -halfLabel && yAxisPosition < halfLabel) {
1031+
yAxisPosition = halfLabel;
1032+
} else if (yAxisPosition > topEdge - halfLabel && yAxisPosition < topEdge +halfLabel) {
1033+
yAxisPosition = topEdge - halfLabel;
1034+
}
10231035
labelYAxis.center = CGPointMake(xValueForCenterLabelYAxis, yAxisPosition);
10241036

1037+
10251038
return labelYAxis;
10261039
}
10271040

@@ -1127,7 +1140,8 @@ - (void)drawYAxis {
11271140
for (UILabel * label in newLabels) {
11281141
if (label == newLabels[0] || //always show first label
11291142
(CGRectIsNull(CGRectIntersection(prevLabel.frame, label.frame)) &&
1130-
CGRectIsNull(CGRectIntersection(averageLabel.frame, label.frame)) &&
1143+
(!averageLabel ||
1144+
CGRectIsNull(CGRectIntersection(averageLabel.frame, label.frame))) &&
11311145
CGRectContainsRect(self.backgroundYAxis.bounds, label.frame))) {
11321146
prevLabel = label; //no overlap and inside frame, so show this one
11331147
} else {
@@ -1646,6 +1660,10 @@ -(void) getData {
16461660
self.maxXValue = self.numberOfPoints-1;
16471661
#endif
16481662

1663+
if (self.minXDisplayedValue < self.minXValue || self.minXDisplayedValue > self.maxXValue) {
1664+
//possibly caller changed all our data out from under us...
1665+
self.minXDisplayedValue = self.minXValue;
1666+
}
16491667
//now calculate point locations in view
16501668
CGFloat xAxisWidth = CGRectGetMaxX(self.dotsView.bounds);
16511669
CGFloat totalValueRangeWidth = self.maxXValue - self.minXValue;

0 commit comments

Comments
 (0)