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 4 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
4 changes: 2 additions & 2 deletions Classes/BEMSimpleLineGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,13 @@ 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.
@return The suffix to append to the popup report. */
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph;
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph index:(NSUInteger)index;
Copy link
Owner

Choose a reason for hiding this comment

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

Please rename the method to - (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index;.
The comment also needs to be updated.



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

Choose a reason for hiding this comment

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

Please rename the method to - (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index;.
The comment also needs to be updated.



/** Optional method to always display some of the pop up labels on the graph.
Expand Down
35 changes: 20 additions & 15 deletions Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
return self;
}

-(void)awakeFromNib{
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this necessary? commonInit will now be called twice, which is not good.

Copy link
Author

Choose a reason for hiding this comment

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

ok, I'll fix it.

[self commonInit];
}

- (void)commonInit {
// Do any initialization that's common to both -initWithFrame: and -initWithCoder: in this method

Expand Down Expand Up @@ -360,11 +364,11 @@ - (void)layoutTouchReport {

NSString *prefix = @"";
NSString *suffix = @"";
if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)]) {
suffix = [self.delegate popUpSuffixForlineGraph:self];
if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:index:)]) {
suffix = [self.delegate popUpSuffixForlineGraph:self index:0];
Copy link
Owner

Choose a reason for hiding this comment

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

The index passed here shouldn't be 0.
Here we're trying to determine the size of the longest possible popuplabel.
Therefore, we shouldn't get the pop up suffix at index 0, but instead the longest pop up suffix.

}
if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)]) {
prefix = [self.delegate popUpPrefixForlineGraph:self];
if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)]) {
prefix = [self.delegate popUpPrefixForlineGraph:self index:0];
Copy link
Owner

Choose a reason for hiding this comment

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

See comment on line 368.

}

NSString *fullString = [NSString stringWithFormat:@"%@%@%@", prefix, longestString, suffix];
Expand Down Expand Up @@ -1089,13 +1093,14 @@ - (void)displayPermanentLabelForPoint:(BEMCircle *)circleDot {
NSString *prefix = @"";
NSString *suffix = @"";

if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:)])
suffix = [self.delegate popUpSuffixForlineGraph:self];
int index = (int)(circleDot.tag - DotFirstTag100);
Copy link
Owner

Choose a reason for hiding this comment

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

Why casting to an int here?
NSInteger index = (circleDot.tag - DotFirstTag100); would cause problems?


if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)])
prefix = [self.delegate popUpPrefixForlineGraph:self];
if ([self.delegate respondsToSelector:@selector(popUpSuffixForlineGraph:index:)])
suffix = [self.delegate popUpSuffixForlineGraph:self index:index];

if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)])
prefix = [self.delegate popUpPrefixForlineGraph:self index: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 +1396,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:index:)])
self.popUpLabel.text = [NSString stringWithFormat:@"%li%@", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue], [self.delegate popUpSuffixForlineGraph:self index:index]];
else
self.popUpLabel.text = [NSString stringWithFormat:@"%li", (long)[dataPoints[(NSInteger) closestDot.tag - DotFirstTag100] integerValue]];

Expand Down Expand Up @@ -1426,11 +1431,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:index:)]) {
suffix = [self.delegate popUpSuffixForlineGraph:self index:index];
}
if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:)]) {
prefix = [self.delegate popUpPrefixForlineGraph:self];
if ([self.delegate respondsToSelector:@selector(popUpPrefixForlineGraph:index:)]) {
prefix = [self.delegate popUpPrefixForlineGraph:self index:index];
}
NSNumber *value = dataPoints[index];
NSString *formattedValue = [NSString stringWithFormat:self.formatStringForValues, value.doubleValue];
Expand Down
2 changes: 1 addition & 1 deletion Sample Project/SimpleLineChart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

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.

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 index:(NSUInteger)index{
return popUpPrefix;
}

- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph {
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph index:(NSUInteger)index{
return popUpSuffix;
}

Expand Down