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

Feature Enhancement: Supply current popUp index parameter for lineGraph #256

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Classes/BEMSimpleLineGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,16 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel

/** The optional suffix to append to the popup report.
@param graph The graph object requesting the total number of points.
@param index The current popUp index of the points on the graph.
@return The suffix to append to the popup report. */
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph;
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index;


/** The optional prefix to append to the popup report.
@param graph The graph object requesting the total number of points.
@param index The current popUp index of the points on the graph.
@return The prefix to prepend to the popup report. */
- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph;
- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index;


/** Optional method to always display some of the pop up labels on the graph.
Expand Down
40 changes: 23 additions & 17 deletions Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,28 @@ - (void)layoutTouchReport {
self.popUpView.alpha = 0;
[self addSubview:self.popUpView];
} else {
NSString *maxValueString = [NSString stringWithFormat:self.formatStringForValues, [self calculateMaximumPointValue].doubleValue];
NSString *minValueString = [NSString stringWithFormat:self.formatStringForValues, [self calculateMinimumPointValue].doubleValue];
NSNumber *maxPointValue = [self calculateMaximumPointValue];
NSNumber *minPointValue = [self calculateMinimumPointValue];
NSUInteger index = 0;
NSString *maxValueString = [NSString stringWithFormat:self.formatStringForValues, maxPointValue.doubleValue];
NSString *minValueString = [NSString stringWithFormat:self.formatStringForValues, minPointValue.doubleValue];

NSString *longestString = @"";
if (maxValueString.length > 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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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]];

Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions Sample Project/SimpleLineChart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented out method on line 247 also needs to be updated with the new parameter index.

//- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph {
//- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index{
// return @"$ ";
//}

Expand Down
4 changes: 2 additions & 2 deletions Sample Project/SimpleLineChartTests/CustomizationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down