From 677742343270dbec205efcd7c7e883776a347fe5 Mon Sep 17 00:00:00 2001 From: xzming Date: Thu, 10 Mar 2016 11:22:40 +0800 Subject: [PATCH 1/4] supply index for current popUp. --- Classes/BEMSimpleLineGraphView.h | 4 ++-- Classes/BEMSimpleLineGraphView.m | 37 ++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Classes/BEMSimpleLineGraphView.h b/Classes/BEMSimpleLineGraphView.h index 86873f1..68368ed 100644 --- a/Classes/BEMSimpleLineGraphView.h +++ b/Classes/BEMSimpleLineGraphView.h @@ -449,13 +449,13 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView Date: Thu, 10 Mar 2016 11:28:06 +0800 Subject: [PATCH 2/4] update method. --- Sample Project/SimpleLineChart/ViewController.m | 2 +- Sample Project/SimpleLineChartTests/CustomizationTests.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample Project/SimpleLineChart/ViewController.m b/Sample Project/SimpleLineChart/ViewController.m index 9ca680d..e3a5433 100644 --- a/Sample Project/SimpleLineChart/ViewController.m +++ b/Sample Project/SimpleLineChart/ViewController.m @@ -240,7 +240,7 @@ - (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph { // Use this method for tasks after the graph has finished drawing } */ -- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph { +- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph index:(NSUInteger)index{ return @" people"; } diff --git a/Sample Project/SimpleLineChartTests/CustomizationTests.m b/Sample Project/SimpleLineChartTests/CustomizationTests.m index 6eb8b8b..d483d75 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 index:(NSUInteger)index{ return popUpPrefix; } -- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph { +- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph index:(NSUInteger)index{ return popUpSuffix; } From ef2a7256c4e8595e01223a36d3ba1bbeb4b9fdf6 Mon Sep 17 00:00:00 2001 From: xzming Date: Thu, 10 Mar 2016 14:14:01 +0800 Subject: [PATCH 3/4] revert DotLastTag1000. --- Classes/BEMSimpleLineGraphView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/BEMSimpleLineGraphView.m b/Classes/BEMSimpleLineGraphView.m index dc8ccf6..58c3cce 100644 --- a/Classes/BEMSimpleLineGraphView.m +++ b/Classes/BEMSimpleLineGraphView.m @@ -24,7 +24,7 @@ typedef NS_ENUM(NSInteger, BEMInternalTags) { DotFirstTag100 = 100, - DotLastTag1000 = 10000, + DotLastTag1000 = 1000, LabelYAxisTag2000 = 2000, BackgroundYAxisTag2100 = 2100, BackgroundXAxisTag2200 = 2200, From fb434aa68a8226591d145dbc07367aff6e789690 Mon Sep 17 00:00:00 2001 From: xzming Date: Fri, 11 Mar 2016 10:44:54 +0800 Subject: [PATCH 4/4] update comments and parameter's name for popUpSuffixForlineGraph and popUpPrefixForlineGraph. remove awakeFromNib to avoid commonInit be called twice. use the longestString index for popUp. --- Classes/BEMSimpleLineGraphView.h | 6 ++- Classes/BEMSimpleLineGraphView.m | 43 ++++++++++--------- .../SimpleLineChart/ViewController.m | 4 +- .../SimpleLineChartTests/CustomizationTests.m | 4 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Classes/BEMSimpleLineGraphView.h b/Classes/BEMSimpleLineGraphView.h index 4f1a8f9..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:index:)]) { - suffix = [self.delegate popUpSuffixForlineGraph:self index:0]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) { + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; } - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)]) { - prefix = [self.delegate popUpPrefixForlineGraph:self index:0]; + if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:atIndex:)]) { + prefix = [self.delegate popUpPrefixForlineGraph:self atIndex:index]; } NSString *fullString = [NSString stringWithFormat:@"%@%@%@", prefix, longestString, suffix]; @@ -1093,13 +1094,13 @@ - (void)displayPermanentLabelForPoint:(BEMCircle *)circleDot { NSString *prefix = @""; NSString *suffix = @""; - int index = (int)(circleDot.tag - DotFirstTag100); + NSUInteger index = circleDot.tag - DotFirstTag100; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:index:)]) - suffix = [self.delegate popUpSuffixForlineGraph:self index:index]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)]) - prefix = [self.delegate popUpPrefixForlineGraph:self index:index]; + if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:atIndex:)]) + prefix = [self.delegate popUpPrefixForlineGraph:self atIndex:index]; NSNumber *value = dataPoints[index]; // @((NSInteger) circleDot.absoluteValue) NSString *formattedValue = [NSString stringWithFormat:self.formatStringForValues, value.doubleValue]; @@ -1396,8 +1397,8 @@ - (void)setUpPopUpLabelAbovePoint:(BEMCircle *)closestPoint { CGPoint popUpViewCenter = CGPointZero; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:index:)]) - self.popUpLabel.text = [NSString stringWithFormat:@"%li%@", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue], [self.delegate popUpSuffixForlineGraph:self index:index]]; + 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]]; @@ -1431,11 +1432,11 @@ - (void)setUpPopUpLabelAbovePoint:(BEMCircle *)closestPoint { } completion:nil]; NSString *prefix = @""; NSString *suffix = @""; - if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:index:)]) { - suffix = [self.delegate popUpSuffixForlineGraph:self index:index]; + if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:atIndex:)]) { + suffix = [self.delegate popUpSuffixForlineGraph:self atIndex:index]; } - if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)]) { - prefix = [self.delegate popUpPrefixForlineGraph:self index:index]; + 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 e3a5433..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 index:(NSUInteger)index{ +- (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 d483d75..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 index:(NSUInteger)index{ +- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{ return popUpPrefix; } -- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph index:(NSUInteger)index{ +- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{ return popUpSuffix; }