Compare commits

...

15 Commits

Author SHA1 Message Date
Terry Worona 8a1770c6df Updated pod spec 2014-08-22 18:13:52 -07:00
Terry Worona f84f322598 updated read me 2014-08-22 18:13:20 -07:00
Terry Worona 04e1aa5b98 Hide custom dots on selector for now 2014-08-22 18:10:30 -07:00
Terry Worona ab07aa2399 Fixed padding issues 2014-08-22 15:36:08 -07:00
Terry Worona f01e11a0e2 Added custom dot views to line chart 2014-08-22 14:21:06 -07:00
Terry Worona 76984c7c7c added protocols for custom dots 2014-08-22 12:07:09 -07:00
Terry Worona d38a04a70d Added dot radius on a per horizontal index basis 2014-08-22 11:52:53 -07:00
Terry Worona 385d5b3589 Updated pod spec 2014-08-14 19:26:18 -07:00
Terry Worona 90100c7277 updated read me and change log 2014-08-14 19:25:39 -07:00
Terry Worona eca1c0507e Cleaned up PR #90 2014-08-14 19:23:19 -07:00
terryworona ac870e45ce Merge pull request #90 from mszaro/master
Add per-line vertical selection color support.
2014-08-14 19:17:19 -07:00
mszaro 74f588b7e6 Update comment. 2014-08-14 18:51:48 -07:00
mszaro 406b64ae0c Implement per-line vertical selection colors 2014-08-14 18:50:55 -07:00
Terry Worona 92e56d78c5 updates specs and read me 2014-08-14 18:01:04 -07:00
Terry Worona 36ec328346 Fixed issue #89 2014-08-14 17:57:39 -07:00
7 changed files with 177 additions and 60 deletions
+12
View File
@@ -1,5 +1,17 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.1">2.8.1</a>
#### 08/22/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/92">#92</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.0">2.8.0</a>
#### 08/14/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/90">#90</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.4">2.7.4</a>
#### 08/14/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/89">#89</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.3">2.7.3</a>
#### 08/07/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/83">#83</a>.
+26 -9
View File
@@ -75,6 +75,23 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*/
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns a (custom) UIView instance representing a dot (x,y point) within the chart.
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
* This protocol supercedes colorForDotAtHorizontalIndex: and dotRadiusForDotAtHorizontalIndex:.
* If nil is returned. the original dot protocols will take precedence. During selection events, a custom
* dot view is automatically hidden.
*
* Default: nil.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param lineIndex An index number identifying a line in the chart.
*
* @return A custom UIView instance representing a dot at a particular horizontal index within a dotted line.
*/
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
@end
@protocol JBLineChartViewDelegate <JBChartViewDelegate>
@@ -104,7 +121,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*
* @param lineChartView A line chart object informing the delegate about the new selection.
* @param lineIndex An index number identifying the closest line in the chart to the current touch
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param touchPoint The touch point in relation to the chart's bounds (excludes footer and header).
*/
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex touchPoint:(CGPoint)touchPoint;
@@ -149,7 +166,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
* Default: black color.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis)
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color to be used to color a dot within a dotted line in the chart.
@@ -176,11 +193,12 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
* Default: line width x 3.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param lineIndex An index number identifying a line in the chart.
*
* @return The radius of the dots within a dotted line in the chart.
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
/**
* Returns the width of the (vertical) selection view to be overlayed on the chart during touch events.
@@ -196,17 +214,16 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView;
/**
* Returns the (vertical) selection color to be overlayed on the chart during touch events.
* Returns the (vertical) selection color to be overlayed on the chart during touch events on a given line.
* The color is automically faded to transparent (vertically). The property showsVerticalSelection
* must be YES for the color to apply.
*
* Default: white color (faded to transparent).
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color of the selection view used during chart selections.
* @return The color of the selection view used during chart selections of the given line.
*/
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView;
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns the selection color to be overlayed on a line within the chart during touch events.
@@ -241,7 +258,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
* Default: white color.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color to be used to highlight a dot within a dotted line during chart selections.
+128 -44
View File
@@ -137,7 +137,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
@@ -363,12 +364,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
self.verticalSelectionView.alpha = 0.0;
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
if ([self.delegate respondsToSelector:@selector(verticalSelectionColorForLineChartView:)])
{
UIColor *selectionViewBackgroundColor = [self.delegate verticalSelectionColorForLineChartView:self];
NSAssert(selectionViewBackgroundColor != nil, @"JBLineChartView // delegate function - (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView must return a non-nil UIColor");
self.verticalSelectionView.bgColor = selectionViewBackgroundColor;
}
// Add new selection bar
if (self.footerView)
@@ -437,20 +432,82 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
lineWidth = [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
}
CGFloat dotRadius = 0;
CGFloat maxDotLength = 0;
if (showsDots)
{
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
dotRadius = [self.delegate lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
}
else
{
dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
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++)
{
BOOL shouldEvaluateDotSize = NO;
// Left dot
if (horizontalIndex == 0)
{
shouldEvaluateDotSize = YES;
}
// Right dot
else if (horizontalIndex == (dataCount - 1))
{
shouldEvaluateDotSize = YES;
}
else
{
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];
// Top
if (height == [self cachedMaxHeight])
{
shouldEvaluateDotSize = YES;
}
// Bottom
else if (height == [self cachedMinHeight])
{
shouldEvaluateDotSize = YES;
}
}
if (shouldEvaluateDotSize)
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
{
UIView *customDotView = [self.dataSource lineChartView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (customDotView.frame.size.width > maxDotLength || customDotView.frame.size.height > maxDotLength)
{
maxDotLength = fmaxf(customDotView.frame.size.width, customDotView.frame.size.height);
}
}
}
else if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForDotAtHorizontalIndex:atLineIndex:)])
{
CGFloat dotRadius = [self.delegate lineChartView:self dotRadiusForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (dotRadius > maxDotLength)
{
maxDotLength = dotRadius;
}
}
else
{
CGFloat defaultDotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor;
if (defaultDotRadius > maxDotLength)
{
maxDotLength = defaultDotRadius;
}
}
}
}
}
}
CGFloat currentMaxLineWidth = MAX(dotRadius, lineWidth);
CGFloat currentMaxLineWidth = MAX(maxDotLength, lineWidth);
if (currentMaxLineWidth > maxLineWidth)
{
maxLineWidth = currentMaxLineWidth;
@@ -584,16 +641,22 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
return kJBLineChartLinesViewStrokeWidth;
}
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForDotAtHorizontalIndex:atLineIndex:)])
{
return [self.delegate lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self dotRadiusForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
else
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
}
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
{
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
return [self.dataSource lineChartView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
return nil;
}
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
@@ -850,20 +913,27 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:touchPoint:)])
{
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
NSUInteger horizontalIndex = [self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]];
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:horizontalIndex touchPoint:[touch locationInView:self]];
}
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:)])
{
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:[self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]]];
}
if ([self.delegate respondsToSelector:@selector(lineChartView:verticalSelectionColorForLineAtLineIndex:)])
{
UIColor *verticalSelectionColor = [self.delegate lineChartView:self verticalSelectionColorForLineAtLineIndex:lineIndex];
NSAssert(verticalSelectionColor != nil, @"JBLineChartView // delegate function - (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex must return a non-nil UIColor");
self.verticalSelectionView.bgColor = verticalSelectionColor;
}
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.verticalSelectionView.frame.size.width * 0.5))));
self.verticalSelectionView.frame = CGRectMake(xOffset, self.verticalSelectionView.frame.origin.y, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
[self setVerticalSelectionViewVisible:YES animated:YES];
@@ -896,8 +966,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
{
_verticalSelectionViewVisible = verticalSelectionViewVisible;
[self bringSubviewToFront:self.verticalSelectionView];
if (animated)
{
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
@@ -1349,19 +1417,26 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
NSMutableArray *mutableDotViews = [NSMutableArray array];
NSUInteger horizontalIndex = 0;
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex");
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtLineIndex:lineIndex];
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
[mutableDotViews addObject:dotView];
[self addSubview:dotView];
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotViewAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
UIView *currentDotView = [self.delegate lineChartDotsView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
// System dot
if (currentDotView == nil)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
currentDotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
currentDotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
currentDotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
[mutableDotViews addObject:currentDotView];
[self addSubview:currentDotView];
horizontalIndex++;
}
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
@@ -1382,22 +1457,31 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
dispatch_block_t adjustDots = ^{
[weakSelf.dotViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSUInteger horizontalIndex = 0;
for (JBLineChartDotView *dotView in (NSArray *)obj)
for (UIView *dotView in (NSArray *)obj)
{
if ([key isKindOfClass:[NSNumber class]])
{
NSInteger lineIndex = [((NSNumber *)key) intValue];
if (weakSelf.selectedLineIndex == lineIndex)
// Internal dot
if ([dotView isKindOfClass:[JBLineChartDotView class]])
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
}
}
// Custom dot
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
dotView.alpha = (weakSelf.selectedLineIndex == lineIndex) ? 0.0f : 1.0f; // hide custom dots on selection
}
}
horizontalIndex++;
@@ -1434,7 +1518,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
if (self)
{
self.clipsToBounds = YES;
self.layer.cornerRadius = (radius * 0.5);
self.layer.cornerRadius = (radius * 0.5f);
}
return self;
}
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.7.3"
s.version = "2.8.1"
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
s.homepage = "https://github.com/Jawbone/JBChartView"
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.author = { "Terry Worona" => "tworona@jawbone.com" }
s.source = {
:git => "https://github.com/Jawbone/JBChartView.git",
:tag => "v2.7.3"
:tag => "v2.8.1"
}
s.platform = :ios, '6.0'
@@ -235,7 +235,7 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
return kJBAreaChartViewControllerChartLineWidth;
}
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return [UIColor whiteColor];
}
@@ -236,7 +236,7 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
return (lineIndex == JBLineChartLineSolid) ? 0.0: (kJBLineChartViewControllerChartDashedLineWidth * 4);
}
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return [UIColor whiteColor];
}
+7 -3
View File
@@ -43,7 +43,7 @@ Simply add the following line to your <code>Podfile</code>:
Your Podfile should look something like:
platform :ios, '6.0'
pod 'JBChartView', '~> 2.7.3'
pod 'JBChartView', '~> 2.8.1'
### The Old School Way
@@ -208,7 +208,7 @@ The color, width and style of each line in the chart can be customized via the <
Furthermore, the color and width of the selection view along with the color of the selected line can be customized via the <i>optional</i> protocols:
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return ...; // color of selection view
}
@@ -234,7 +234,7 @@ By default, each line will not show dots for each point. To enable this on a per
To customize the size of each dot (default 3x the line width), implement:
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
To customize the color of each dot during selection and non-selection events (default is white and black respectively), implement:
@@ -242,6 +242,10 @@ To customize the color of each dot during selection and non-selection events (de
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
Alternatively, you can supply a custom dot view instead of using the default circular impelmentation (note: custom dot views are automatically hidden when selected):
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
As well, by default, each line will have squared off end caps and connection points. To enable rounded connections and end caps:
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;