diff --git a/Classes/BEMSimpleLineGraphView.h b/Classes/BEMSimpleLineGraphView.h index 49521e3..65f13bb 100644 --- a/Classes/BEMSimpleLineGraphView.h +++ b/Classes/BEMSimpleLineGraphView.h @@ -448,14 +448,16 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView minValueString.length) { longestString = maxValueString; + index = [dataPoints indexOfObject:maxPointValue]; } else { longestString = minValueString; + index = [dataPoints indexOfObject:minPointValue]; } NSString *prefix = @""; NSString *suffix = @""; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)]) { - suffix = [self.delegate popUpSuffixForlineGraph:self]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) { + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; } - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)]) { - prefix = [self.delegate popUpPrefixForlineGraph:self]; + if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:atIndex:)]) { + prefix = [self.delegate popUpPrefixForlineGraph:self atIndex:index]; } NSString *fullString = [NSString stringWithFormat:@"%@%@%@", prefix, longestString, suffix]; @@ -1089,13 +1094,14 @@ - (void)displayPermanentLabelForPoint:(BEMCircle *)circleDot { NSString *prefix = @""; NSString *suffix = @""; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)]) - suffix = [self.delegate popUpSuffixForlineGraph:self]; + NSUInteger index = circleDot.tag - DotFirstTag100; - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)]) - prefix = [self.delegate popUpPrefixForlineGraph:self]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; + + if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:atIndex:)]) + prefix = [self.delegate popUpPrefixForlineGraph:self atIndex:index]; - int index = (int)(circleDot.tag - DotFirstTag100); NSNumber *value = dataPoints[index]; // @((NSInteger) circleDot.absoluteValue) NSString *formattedValue = [NSString stringWithFormat:self.formatStringForValues, value.doubleValue]; permanentPopUpLabel.text = [NSString stringWithFormat:@"%@%@%@", prefix, formattedValue, suffix]; @@ -1391,8 +1397,8 @@ - (void)setUpPopUpLabelAbovePoint:(BEMCircle *)closestPoint { CGPoint popUpViewCenter = CGPointZero; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)]) - self.popUpLabel.text = [NSString stringWithFormat:@"%li%@", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue], [self.delegate popUpSuffixForlineGraph:self]]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) + self.popUpLabel.text = [NSString stringWithFormat:@"%li%@", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue], [self.delegate popUpSuffixForlineGraph:self atIndex:index]]; else self.popUpLabel.text = [NSString stringWithFormat:@"%li", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue]]; @@ -1426,11 +1432,11 @@ - (void)setUpPopUpLabelAbovePoint:(BEMCircle *)closestPoint { } completion:nil]; NSString *prefix = @""; NSString *suffix = @""; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)]) { - suffix = [self.delegate popUpSuffixForlineGraph:self]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) { + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; } - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)]) { - prefix = [self.delegate popUpPrefixForlineGraph:self]; + if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:atIndex:)]) { + prefix = [self.delegate popUpPrefixForlineGraph:self atIndex:index]; } NSNumber *value = dataPoints[index]; NSString *formattedValue = [NSString stringWithFormat:self.formatStringForValues, value.doubleValue]; diff --git a/Sample Project/SimpleLineChart/ViewController.m b/Sample Project/SimpleLineChart/ViewController.m index 9ca680d..b57fca6 100644 --- a/Sample Project/SimpleLineChart/ViewController.m +++ b/Sample Project/SimpleLineChart/ViewController.m @@ -240,11 +240,11 @@ - (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph { // Use this method for tasks after the graph has finished drawing } */ -- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph { +- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index{ return @" people"; } -//- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph { +//- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index{ // return @"$ "; //} diff --git a/Sample Project/SimpleLineChartTests/CustomizationTests.m b/Sample Project/SimpleLineChartTests/CustomizationTests.m index 6eb8b8b..bd4140b 100644 --- a/Sample Project/SimpleLineChartTests/CustomizationTests.m +++ b/Sample Project/SimpleLineChartTests/CustomizationTests.m @@ -51,11 +51,11 @@ - (NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForI return xAxisLabelString; } -- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph { +- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{ return popUpPrefix; } -- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph { +- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{ return popUpSuffix; }