Compare commits

...

5 Commits

Author SHA1 Message Date
Terry Worona b6262462c5 Updated pod spec change log and read me 2014-04-02 11:49:52 -07:00
Terry Worona 1080089753 Added dynamic padding to line chart view 2014-04-02 11:46:42 -07:00
Terry Worona 0afba01a9a Updated read me and pod spec 2014-04-02 10:26:59 -07:00
Terry Worona 63b47667ec Fixed min and max value properties 2014-04-02 09:08:12 -07:00
Terry Worona 4d6baf066f cleaned up cached constants 2014-04-02 08:50:43 -07:00
5 changed files with 193 additions and 108 deletions
+8
View File
@@ -1,5 +1,13 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.2">2.1.2</a>
#### 04/02/14
- Added dynamic padding to JBLineChartView (based on max line width).
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.1">2.1.1</a>
#### 04/02/14
- Fixed minimumValue and maximumValue getter functions.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.0">2.1.0</a>
#### 03/30/14
- Added minimumValue and maximumValue properties.
+48 -31
View File
@@ -10,8 +10,7 @@
// Numerics
CGFloat static const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
CGFloat static const kJBBarChartViewUndefinedMaxHeight = -1.0f;
CGFloat static const kJBBarChartViewUndefinedMinHeight = -1.0f;
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
CGFloat static const kJBBarChartViewStateAnimationDuration = 0.05f;
CGFloat static const kJBBarChartViewPopOffset = 10.0f; // used to offset bars for 'pop' animations
NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
@@ -35,8 +34,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
// View quick accessors
- (CGFloat)availableHeight;
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight;
- (CGFloat)maxHeight;
- (CGFloat)minHeight;
- (CGFloat)maxHeight;
- (CGFloat)barWidth;
- (CGFloat)popOffset;
@@ -96,7 +95,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)construct
{
_showsVerticalSelection = YES;
_cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
}
#pragma mark - Memory Management
@@ -111,7 +111,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
self.cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
self.cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
/*
* The data collection holds all position information:
@@ -262,19 +263,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (CGFloat)minHeight
{
BOOL hasCachedMinHeight = self.cachedMinHeight != kJBBarChartViewUndefinedMinHeight;
dispatch_block_t calculateCachedMinHeight = ^{
// min height is min value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
self.cachedMinHeight = [[chartValues firstObject] floatValue];
};
if (!hasCachedMinHeight)
{
calculateCachedMinHeight();
}
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
{
return MIN(self.mininumValue, self.cachedMinHeight);
@@ -284,19 +272,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (CGFloat)maxHeight
{
BOOL hasCachedMaxHeight = self.cachedMaxHeight != kJBBarChartViewUndefinedMaxHeight;
dispatch_block_t calculateCachedMaxHeight = ^{
// max height is max value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
self.cachedMaxHeight = [[chartValues lastObject] floatValue];
};
if (!hasCachedMaxHeight)
{
calculateCachedMaxHeight();
}
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
{
return MAX(self.maximumValue, self.cachedMaxHeight);
@@ -391,6 +366,48 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
}
}
#pragma mark - Getters
- (CGFloat)cachedMinHeight
{
if(_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
{
// min height is min value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
_cachedMinHeight = [[chartValues firstObject] floatValue];
}
return _cachedMinHeight;
}
- (CGFloat)cachedMaxHeight
{
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
{
// max height is max value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
_cachedMaxHeight = [[chartValues lastObject] floatValue];
}
return _cachedMaxHeight;
}
- (CGFloat)mininumValue
{
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
{
return self.cachedMinHeight;
}
return [super mininumValue];
}
- (CGFloat)maximumValue
{
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
{
return self.cachedMaxHeight;
}
return [super maximumValue];
}
#pragma mark - Touch Helpers
- (NSInteger)barViewIndexForPoint:(CGPoint)point
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.1.0"
s.version = "2.1.2"
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
s.homepage = "https://github.com/Jawbone/JBChartView"
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
s.author = { "Terry Worona" => "tworona@jawbone.com" }
s.source = {
:git => "https://github.com/Jawbone/JBChartView.git",
:tag => "v2.1.0"
:tag => "v2.1.2"
}
s.platform = :ios, '7.0'
+134 -74
View File
@@ -19,7 +19,6 @@ typedef NS_ENUM(NSUInteger, JBLineChartHorizontalIndexClamp){
};
// Numerics (JBLineChartLineView)
CGFloat static const kJBLineChartLinesViewEdgePadding = 10.0;
CGFloat static const kJBLineChartLinesViewStrokeWidth = 5.0;
CGFloat static const kJBLineChartLinesViewMiterLimit = -5.0;
CGFloat static const kJBLineChartLinesViewDefaultLinePhase = 1.0f;
@@ -34,8 +33,7 @@ NSInteger static const kJBLineChartDotsViewUnselectedLineIndex = -1;
CGFloat static const kJBLineSelectionViewWidth = 20.0f;
// Numerics (JBLineChartView)
CGFloat static const kJBLineChartViewUndefinedMaxHeight = -1.0f;
CGFloat static const kJBLineChartViewUndefinedMinHeight = -1.0f;
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
CGFloat static const kJBLineChartViewStateAnimationDuration = 0.25f;
CGFloat static const kJBLineChartViewStateAnimationDelay = 0.05f;
CGFloat static const kJBLineChartViewStateBounceOffset = 15.0f;
@@ -89,6 +87,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView;
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex;
@@ -116,6 +115,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
@end
@@ -142,8 +142,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
// View quick accessors
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight;
- (CGFloat)availableHeight;
- (CGFloat)maxHeight;
- (CGFloat)minHeight;
- (CGFloat)maxHeight;
- (CGFloat)padding;
- (NSUInteger)dataCount;
// Touch helpers
@@ -207,15 +208,20 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
{
_showsVerticalSelection = YES;
_showsLineSelection = YES;
_cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
}
#pragma mark - Data
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
// Reset cached max height
self.cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
self.cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
// Padding
CGFloat chartPadding = [self padding];
/*
* Subview rectangle calculations
@@ -228,8 +234,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
*/
dispatch_block_t createChartData = ^{
CGFloat pointSpace = (self.bounds.size.width - (kJBLineChartLinesViewEdgePadding * 2)) / ([self dataCount] - 1); // Space in between points
CGFloat xOffset = kJBLineChartLinesViewEdgePadding;
CGFloat pointSpace = (self.bounds.size.width - (chartPadding * 2)) / ([self dataCount] - 1); // Space in between points
CGFloat xOffset = chartPadding;
CGFloat yOffset = 0;
NSMutableArray *mutableChartData = [NSMutableArray array];
@@ -255,7 +261,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
xOffset += pointSpace;
}
[mutableChartData addObject:chartPointData];
xOffset = kJBLineChartLinesViewEdgePadding;
xOffset = chartPadding;
}
self.chartData = [NSArray arrayWithArray:mutableChartData];
};
@@ -379,34 +385,6 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (CGFloat)minHeight
{
BOOL hasCachedMinHeight = self.cachedMinHeight != kJBLineChartViewUndefinedMinHeight;
dispatch_block_t calculateCachedMinHeight = ^{
CGFloat minHeight = FLT_MAX;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat height = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
if (height < minHeight)
{
minHeight = height;
}
}
}
self.cachedMinHeight = minHeight;
};
if (!hasCachedMinHeight)
{
calculateCachedMinHeight();
}
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
{
return MIN(self.mininumValue, self.cachedMinHeight);
@@ -415,35 +393,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
}
- (CGFloat)maxHeight
{
BOOL hasCachedMaxHeight = self.cachedMaxHeight != kJBLineChartViewUndefinedMaxHeight;
dispatch_block_t calculateCachedMaxHeight = ^{
CGFloat maxHeight = 0;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat height = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
if (height > maxHeight)
{
maxHeight = height;
}
}
}
self.cachedMaxHeight = maxHeight;
};
if (!hasCachedMaxHeight)
{
calculateCachedMaxHeight();
}
{
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
{
return MAX(self.maximumValue, self.cachedMaxHeight);
@@ -451,6 +401,25 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return self.cachedMaxHeight;
}
- (CGFloat)padding
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
{
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
CGFloat maxWidth = 0.0f;
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
CGFloat lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
if (lineWidth > maxWidth)
{
maxWidth = lineWidth;
}
}
return ceil(maxWidth * 0.5);
}
return ceil(kJBLineChartLinesViewStrokeWidth * 0.5);
}
- (NSUInteger)dataCount
{
NSUInteger dataCount = 0;
@@ -501,6 +470,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return kJBLineChartLinesViewStrokeWidth;
}
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView
{
return [self padding];
}
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
@@ -553,6 +527,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return kJBLineChartLinesViewStrokeWidth;
}
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
{
return [self padding];
}
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
@@ -621,6 +600,78 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
}
}
#pragma mark - Getters
- (CGFloat)cachedMinHeight
{
if (_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
{
CGFloat minHeight = FLT_MAX;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat height = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
if (height < minHeight)
{
minHeight = height;
}
}
}
_cachedMinHeight = minHeight;
}
return _cachedMinHeight;
}
- (CGFloat)cachedMaxHeight
{
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
{
CGFloat maxHeight = 0;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat height = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
if (height > maxHeight)
{
maxHeight = height;
}
}
}
_cachedMaxHeight = maxHeight;
}
return _cachedMaxHeight;
}
- (CGFloat)mininumValue
{
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
{
return self.cachedMinHeight;
}
return [super mininumValue];
}
- (CGFloat)maximumValue
{
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
{
return self.cachedMaxHeight;
}
return [super maximumValue];
}
#pragma mark - Touch Helpers
- (CGPoint)clampPoint:(CGPoint)point toBounds:(CGRect)bounds padding:(CGFloat)padding
@@ -673,6 +724,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
NSInteger leftHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampLeft];
NSInteger rightHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampRight];
// Padding
CGFloat chartPadding = [self padding];
NSUInteger shortestDistance = INT_MAX;
NSInteger selectedIndex = kJBLineChartUnselectedLineIndex;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
@@ -687,11 +741,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
// Left point
JBLineChartPoint *leftLineChartPoint = [lineData objectAtIndex:leftHorizontalIndex];
CGPoint leftPoint = CGPointMake(leftLineChartPoint.position.x, fmin(fmax(kJBLineChartLinesViewEdgePadding, self.linesView.bounds.size.height - leftLineChartPoint.position.y), self.linesView.bounds.size.height - kJBLineChartLinesViewEdgePadding));
CGPoint leftPoint = CGPointMake(leftLineChartPoint.position.x, fmin(fmax(chartPadding, self.linesView.bounds.size.height - leftLineChartPoint.position.y), self.linesView.bounds.size.height - chartPadding));
// Right point
JBLineChartPoint *rightLineChartPoint = [lineData objectAtIndex:rightHorizontalIndex];
CGPoint rightPoint = CGPointMake(rightLineChartPoint.position.x, fmin(fmax(kJBLineChartLinesViewEdgePadding, self.linesView.bounds.size.height - rightLineChartPoint.position.y), self.linesView.bounds.size.height - kJBLineChartLinesViewEdgePadding));
CGPoint rightPoint = CGPointMake(rightLineChartPoint.position.x, fmin(fmax(chartPadding, self.linesView.bounds.size.height - rightLineChartPoint.position.y), self.linesView.bounds.size.height - chartPadding));
// Touch point
CGPoint normalizedTouchPoint = CGPointMake(point.x, self.linesView.bounds.size.height - point.y);
@@ -721,7 +775,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
}
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:kJBLineChartLinesViewEdgePadding];
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:touchPoint:)])
{
@@ -794,7 +848,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:kJBLineChartLinesViewEdgePadding];
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
[self.linesView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
[self.dotsView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
[self touchesBeganOrMovedWithTouches:touches];
@@ -912,6 +966,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (NSArray *)chartDataForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
NSArray *chartData = [self.delegate chartDataForLineChartLinesView:self];
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
CGFloat padding = [self.delegate paddingForLineChartLinesView:self];
NSUInteger lineIndex = 0;
for (NSArray *lineData in chartData)
@@ -924,11 +981,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
{
if (index == 0)
{
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)))];
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
}
else
{
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)))];
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
}
index++;
@@ -1081,6 +1138,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
NSArray *chartData = [self.delegate chartDataForLineChartDotsView:self];
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
CGFloat padding = [self.delegate paddingForLineChartDotsView:self];
NSUInteger lineIndex = 0;
NSMutableDictionary *mutableDotViewsDict = [NSMutableDictionary dictionary];
@@ -1098,7 +1158,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewRadiusFactor;
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)));
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForLineAtLineIndex:lineIndex];
+1 -1
View File
@@ -38,7 +38,7 @@ Simply add the following line to your <code>Podfile</code>:
Your Podfile should look something like:
platform :ios, '7.0'
pod 'JBChartView', '~> 2.1.0'
pod 'JBChartView', '~> 2.1.2'
### The Old School Way