Compare commits

..

29 Commits

Author SHA1 Message Date
terryworona 9292655de8 messing around with loading states 2016-08-28 17:59:02 -07:00
terryworona 5468952b53 update change log and pod spec 2016-06-22 12:57:40 -07:00
terryworona af508bb50c Fixed setState crasher with cached bar heights 2016-06-22 12:52:18 -07:00
terryworona 988c8c9ab9 update pod spec and changelog 2016-06-22 11:44:14 -07:00
terryworona 7944c03962 Merge pull request #209 from loumoore/master
Handle NaN line slope in line chart selection code.
2016-06-21 17:33:45 -07:00
Lou Moore e28a0113f8 PR feedback 2016-06-21 17:31:32 -07:00
Lou Moore 40ae91de47 Handle NaN line slope in line chart selection code. 2016-06-21 17:19:10 -07:00
terryworona 251b6e888f updated pod spec and change log 2016-05-30 19:35:38 -07:00
terryworona c2558f9975 Fixes 207 2016-05-30 19:30:42 -07:00
terryworona 2d1450340b updated pod spec and change log 2016-04-27 18:52:35 -07:00
terryworona 706dbc1859 fixed up documentation error 2016-04-27 18:49:47 -07:00
terryworona 6cce1ae272 Update change log and pod spec 2016-02-29 14:56:58 -08:00
terryworona 0b603cde1f Fixes #201 2016-02-29 14:55:15 -08:00
terryworona eacc211dbd Updated changelog and pod spec 2016-02-25 16:46:29 -08:00
terryworona 641fb7f5fa Fixed bar reloadDataAnimated: crash & non animated performance issues 2016-02-25 16:45:13 -08:00
terryworona 28a660c57f Updated pod spec and change log 2016-01-21 13:29:58 -08:00
terryworona 52c8d632b7 Updated readme 2016-01-21 13:28:43 -08:00
terryworona 59eebf6015 even more cleanup 2016-01-21 13:21:45 -08:00
terryworona 036c01dc03 More naming convention fixes 2016-01-21 13:18:15 -08:00
terryworona 063079f171 Fixed datasource naming conventions 2016-01-21 13:15:33 -08:00
terryworona dc56268f29 exposed dot dimming value 2016-01-21 13:13:48 -08:00
terryworona f56b539fe4 change log and pod spec 2016-01-20 15:25:41 -08:00
terryworona e4b0820418 Fixed one more warning 2016-01-20 15:22:20 -08:00
terryworona d30d5b9c96 Updated change log 2016-01-20 14:55:17 -08:00
terryworona 8db9d7baaf Updated pod spec 2016-01-20 14:54:24 -08:00
terryworona d49515c97e Fixed warnings 2016-01-20 14:53:04 -08:00
terryworona 7dfcd44d8c Updated change log and pod spec 2016-01-20 14:31:01 -08:00
terryworona 4e511f7164 Fixed #197 2016-01-20 14:25:49 -08:00
terryworona cd2c79ffa7 new version 2016-01-18 20:19:43 -08:00
16 changed files with 358 additions and 121 deletions
+74
View File
@@ -1,5 +1,79 @@
# Change Log
## [v3.0.12](https://github.com/Jawbone/JBChartView/tree/v3.0.12) (2016-06-22)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.11...v3.0.12)
## [v3.0.11](https://github.com/Jawbone/JBChartView/tree/v3.0.11) (2016-06-22)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.10...v3.0.11)
**Fixed bugs:**
- barChartView:barViewAtIndex: not called when reloading bar chart animated [\#207](https://github.com/Jawbone/JBChartView/issues/207)
**Closed issues:**
- Not able to change the color of linechart with custom color [\#208](https://github.com/Jawbone/JBChartView/issues/208)
**Merged pull requests:**
- Handle NaN line slope in line chart selection code. [\#209](https://github.com/Jawbone/JBChartView/pull/209) ([loumoore](https://github.com/loumoore))
## [v3.0.10](https://github.com/Jawbone/JBChartView/tree/v3.0.10) (2016-05-31)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.9...v3.0.10)
## [v3.0.9](https://github.com/Jawbone/JBChartView/tree/v3.0.9) (2016-04-28)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.8...v3.0.9)
**Implemented enhancements:**
- ability to set line chart view padding [\#205](https://github.com/Jawbone/JBChartView/issues/205)
**Fixed bugs:**
- old gradient fill shows if chart is scrolled offscreen [\#204](https://github.com/Jawbone/JBChartView/issues/204)
**Closed issues:**
- example of using gradient for fills [\#202](https://github.com/Jawbone/JBChartView/issues/202)
## [v3.0.8](https://github.com/Jawbone/JBChartView/tree/v3.0.8) (2016-02-29)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.7...v3.0.8)
**Fixed bugs:**
- Cannot change bar colors after initial load [\#201](https://github.com/Jawbone/JBChartView/issues/201)
## [v3.0.7](https://github.com/Jawbone/JBChartView/tree/v3.0.7) (2016-02-26)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.6...v3.0.7)
**Closed issues:**
- Directions not set in UIViewController [\#199](https://github.com/Jawbone/JBChartView/issues/199)
- Many Line Charts in Table View [\#198](https://github.com/Jawbone/JBChartView/issues/198)
## [v3.0.6](https://github.com/Jawbone/JBChartView/tree/v3.0.6) (2016-01-21)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.5...v3.0.6)
## [v3.0.5](https://github.com/Jawbone/JBChartView/tree/v3.0.5) (2016-01-20)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.4...v3.0.5)
## [v3.0.4](https://github.com/Jawbone/JBChartView/tree/v3.0.4) (2016-01-20)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.3...v3.0.4)
## [v3.0.3](https://github.com/Jawbone/JBChartView/tree/v3.0.3) (2016-01-20)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.2...v3.0.3)
**Closed issues:**
- Dot alpha doesn't return after unselection [\#197](https://github.com/Jawbone/JBChartView/issues/197)
## [v3.0.2](https://github.com/Jawbone/JBChartView/tree/v3.0.2) (2016-01-19)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.1...v3.0.2)
**Merged pull requests:**
- Make sure to import dependent framework header explicitly [\#196](https://github.com/Jawbone/JBChartView/pull/196) ([yasuoza](https://github.com/yasuoza))
## [v3.0.1](https://github.com/Jawbone/JBChartView/tree/v3.0.1) (2016-01-16)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.0...v3.0.1)
+36 -10
View File
@@ -12,12 +12,12 @@
#import "JBGradientBarView.h"
// Numerics
CGFloat const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
CGFloat const kJBBarChartViewUndefinedCachedHeight = -1.0f;
CGFloat const kJBBarChartViewStateAnimationDuration = 0.05f;
CGFloat const kJBBarChartViewReloadDataAnimationDuration = 0.15f;
CGFloat const kJBBarChartViewStatePopOffset = 10.0f;
NSInteger const kJBBarChartViewUndefinedBarIndex = -1;
static CGFloat const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
static CGFloat const kJBBarChartViewUndefinedCachedHeight = -1.0f;
static CGFloat const kJBBarChartViewStateAnimationDuration = 0.05f;
static CGFloat const kJBBarChartViewReloadDataAnimationDuration = 0.15f;
static CGFloat const kJBBarChartViewStatePopOffset = 10.0f;
static NSInteger const kJBBarChartViewUndefinedBarIndex = -1;
// Colors (JBChartView)
static UIColor *kJBBarChartViewDefaultBarColor = nil;
@@ -111,6 +111,10 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)construct
{
_chartData = [NSArray array];
_barViews = [NSArray array];
_cachedBarViewHeights = [NSArray array];
_showsVerticalSelection = YES;
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
@@ -145,6 +149,28 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
* Final block to refresh state and turn off reloading bit
*/
dispatch_block_t completionBlock = ^{
if (animated)
{
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
// Grab old bar
UIView *oldBarView = [self.barViews objectAtIndex:index];
// Update bar instance
UIView *barView = [self createBarViewForIndex:index];
barView.frame = oldBarView.frame;
// Swap subviews
[oldBarView removeFromSuperview];
[self insertBarView:barView];
// Update bar colection
NSMutableArray *mutableBarViews = [NSMutableArray arrayWithArray:self.barViews];
[mutableBarViews replaceObjectAtIndex:index withObject:barView];
self.barViews = [NSArray arrayWithArray:mutableBarViews];
}];
}
self.reloading = NO;
[self setState:self.state animated:NO force:YES callback:nil];
};
@@ -383,7 +409,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
preAddBarViewsBlock();
[UIView animateWithDuration:kJBBarChartViewReloadDataAnimationDuration delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
postAddBarViewsBlock();
} completion:^(BOOL finished) {
} completion:^(BOOL finished2) {
refreshedCachedBarViewHeightsBlock();
completionBlock();
}];
@@ -402,7 +428,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
postRemoveBarViewsBlock();
[UIView animateWithDuration:kJBBarChartViewReloadDataAnimationDuration delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
updateExistingBarViewsBlock();
} completion:^(BOOL finished) {
} completion:^(BOOL finished2) {
refreshedCachedBarViewHeightsBlock();
completionBlock();
}];
@@ -580,7 +606,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
dispatch_block_t callbackCopy = [callback copy];
if ([self.barViews count] > 0)
if ([self.barViews count] > 0 && [self.cachedBarViewHeights count] == [self.barViews count])
{
if (animated)
{
@@ -753,7 +779,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
if (gradientLayer != nil)
{
barView = [[JBGradientBarView alloc] init];
((JBGradientBarView *)barView).delegate = self;
((JBGradientBarView *)barView).dataSource = self;
((JBGradientBarView *)barView).gradientLayer = gradientLayer;
}
}
+1 -1
View File
@@ -23,7 +23,7 @@
@interface JBGradientBarView: UIView
@property (nonatomic, weak) id<JBGradientBarViewDataSource> delegate;
@property (nonatomic, weak) id<JBGradientBarViewDataSource> dataSource;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@end
+2 -2
View File
@@ -66,9 +66,9 @@
{
[super setFrame:frame];
if ([self.delegate respondsToSelector:@selector(chartViewBoundsForGradientBarView:)])
if ([self.dataSource respondsToSelector:@selector(chartViewBoundsForGradientBarView:)])
{
_gradientLayer.frame = [self.delegate chartViewBoundsForGradientBarView:self]; // gradient is as large as the chart
_gradientLayer.frame = [self.dataSource chartViewBoundsForGradientBarView:self]; // gradient is as large as the chart
_gradientLayer.frame = CGRectOffset(_gradientLayer.frame, -CGRectGetMinX(frame), 0);
}
else
+9
View File
@@ -69,6 +69,15 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
@property (nonatomic, weak) id<JBChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBChartViewDelegate> delegate;
/*
* Since loading is such a common UIView requirement,
* setting to YES will snapshot the chart, blur it, and display a loading indicator.
*/
@property (nonatomic, assign) BOOL loading;
- (void)setLoading:(BOOL)loading animated:(BOOL)animated callback:(void (^)())callback;
- (void)setLoading:(BOOL)loading animated:(BOOL)animated;
/**
* Header and footer views are shown above and below the chart respectively.
* Each view will be stretched horizontally to fill width of chart.
+105
View File
@@ -16,6 +16,8 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
@interface JBChartView ()
@property (nonatomic, strong) UIImageView *loadingImageView;
@property (nonatomic, assign) BOOL hasMaximumValue;
@property (nonatomic, assign) BOOL hasMinimumValue;
@@ -77,8 +79,111 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
NSAssert((self.headerView.bounds.size.height + self.footerView.bounds.size.height) <= self.bounds.size.height, @"JBChartView // the combined height of the footer and header can not be greater than the total height of the chart.");
}
#pragma mark - Getters
+ (UIImage *)imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
#pragma mark - Setters
- (void)setLoading:(BOOL)loading animated:(BOOL)animated callback:(void (^)())callback
{
if (_loading == loading)
{
return;
}
_loading = loading;
if (loading) // show
{
UIImage *snapshotImage = [JBChartView imageWithView:self];
self.loadingImageView = [[UIImageView alloc] initWithImage:snapshotImage];
self.loadingImageView.frame = self.bounds;
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
effectView.frame = self.loadingImageView.frame;
[self.loadingImageView addSubview:effectView];
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityIndicatorView startAnimating];
activityIndicatorView.frame = CGRectMake(ceil(self.loadingImageView.frame.size.width * 0.5) - ceil(activityIndicatorView.frame.size.width * 0.5), ceil(self.loadingImageView.frame.size.height * 0.5) - ceil(activityIndicatorView.frame.size.height * 0.5), activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
[self.loadingImageView addSubview:activityIndicatorView];
if (animated)
{
self.loadingImageView.alpha = 0.0;
[self addSubview:self.loadingImageView];
[UIView animateWithDuration:0.25 animations:^{
self.loadingImageView.alpha = 1.0;
} completion:^(BOOL finished) {
if (callback)
{
callback();
}
}];
}
else
{
[self addSubview:self.loadingImageView];
if (callback)
{
callback();
}
}
}
else // hide
{
if (self.loadingImageView != nil)
{
if (animated)
{
[UIView animateWithDuration:0.25 animations:^{
self.loadingImageView.alpha = 0.0;
} completion:^(BOOL finished) {
[self.loadingImageView removeFromSuperview];
if (callback)
{
callback();
}
}];
}
else
{
[self.loadingImageView removeFromSuperview];
if (callback)
{
callback();
}
}
}
else
{
if (callback)
{
callback();
}
}
}
}
- (void)setLoading:(BOOL)loading animated:(BOOL)animated
{
[self setLoading:loading animated:animated callback:nil];
}
- (void)setLoading:(BOOL)loading
{
[self setLoading:loading animated:NO];
}
- (void)setHeaderView:(UIView *)headerView
{
if (_headerView)
+17 -4
View File
@@ -104,6 +104,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns the opacity value to be used for dimming the dots during selection events.
* This value is applied to all dots within a line anytime it's not selected (but another line is).
*
* Default: 0.0.
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return A value between 0.0 and 1.0 (will be clamped accordingly).
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dimmedSelectionDotOpacityAtLineIndex:(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.
@@ -317,7 +330,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection color of a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
* As well, lineChartView:colorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default)
*
* Default: matches lineChartView:colorForLineAtLineIndex:.
*
@@ -331,7 +344,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection gradient layer of a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGradient.
* As well, lineChartView:colorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGradient.
*
* Note: gradients do not support multiple alphas. The alpha of gradient's first color be used throughout.
*
@@ -347,7 +360,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection fill color under a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionFillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
* As well, lineChartView:fillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
*
* Default: matches lineChartView:fillColorForLineAtLineIndex:.
*
@@ -361,7 +374,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection fill gradient layer under a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionFillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGrdient.
* As well, lineChartView:fillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGrdient.
*
* Note: gradients do not support multiple alphas. The alpha of gradient's first color be used throughout.
*
+29 -19
View File
@@ -33,18 +33,19 @@ static UIColor *kJBLineChartViewDefaultFillGradientStartColor = nil;
static UIColor *kJBLineChartViewDefaultFillGradientEndColor = nil;
// Numerics
CGFloat const kJBLineChartViewDefaultVerticalSelectionViewWidth = 20.0f;
CGFloat const kJBLineChartViewUndefinedCachedHeight = -1.0f;
CGFloat const kJBLineChartViewStateAnimationDuration = 0.25f;
CGFloat const kJBLineChartViewStateAnimationDelay = 0.05f;
CGFloat const kJBLineChartViewStateBounceOffset = 15.0f;
CGFloat const kJBLineChartViewDefaultStartPoint = 0.0;
CGFloat const kJBLineChartViewDefaultEndPoint = 1.0;
CGFloat const kJBLineChartViewReloadAnimationDuration = 0.1;
CGFloat const kJBLineChartViewDefaultDimmedSelectionOpacity = 0.20f;
CGFloat const kJBLineChartViewDefaultStrokeWidth = 5.0f;
NSInteger const kJBLineChartViewDefaultDotRadiusFactor = 3; // 3x size of line width
NSInteger const kJBLineChartUnselectedLineIndex = -1;
static CGFloat const kJBLineChartViewDefaultVerticalSelectionViewWidth = 20.0f;
static CGFloat const kJBLineChartViewUndefinedCachedHeight = -1.0f;
static CGFloat const kJBLineChartViewStateAnimationDuration = 0.25f;
static CGFloat const kJBLineChartViewStateAnimationDelay = 0.05f;
static CGFloat const kJBLineChartViewStateBounceOffset = 15.0f;
static CGFloat const kJBLineChartViewDefaultStartPoint = 0.0;
static CGFloat const kJBLineChartViewDefaultEndPoint = 1.0;
static CGFloat const kJBLineChartViewReloadAnimationDuration = 0.1;
static CGFloat const kJBLineChartViewDefaultDimmedLineAndFillSelectionOpacity = 0.20f;
static CGFloat const kJBLineChartViewDefaultDimmedDotSelectionOpacity = 0.0f;
static CGFloat const kJBLineChartViewDefaultStrokeWidth = 5.0f;
static NSInteger const kJBLineChartViewDefaultDotRadiusFactor = 3; // 3x size of line width
static NSInteger const kJBLineChartUnselectedLineIndex = -1;
@interface JBChartView (Private)
@@ -265,7 +266,7 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
if (self.linesView == nil)
{
self.linesView = [[JBLineChartLinesView alloc] initWithFrame:linesViewRect];
self.linesView.delegate = self;
self.linesView.dataSource = self;
}
else
{
@@ -293,7 +294,7 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
if (self.dotsView == nil)
{
self.dotsView = [[JBLineChartDotsView alloc] initWithFrame:dotViewRect];
self.dotsView.delegate = self;
self.dotsView.dataSource = self;
}
else
{
@@ -396,7 +397,7 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
[weakSelf.dotsView reloadDataAnimated:YES callback:^{
JBLineChartDotsView *updatedDotsView = [[JBLineChartDotsView alloc] initWithFrame:weakSelf.dotsView.frame];
updatedDotsView.delegate = self;
updatedDotsView.dataSource = self;
updatedDotsView.alpha = 0.0f;
// Add updated dots view (hidden)
@@ -591,7 +592,7 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
{
return [self.dataSource lineChartView:self dimmedSelectionOpacityAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultDimmedSelectionOpacity;
return kJBLineChartViewDefaultDimmedLineAndFillSelectionOpacity;
}
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex
@@ -736,6 +737,15 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
return NO;
}
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dimmedSelectionDotOpacityAtLineIndex:)])
{
return [self.dataSource lineChartView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultDimmedDotSelectionOpacity;
}
#pragma mark - Setters
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
@@ -1025,8 +1035,8 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
// Touch point
CGPoint normalizedTouchPoint = CGPointMake(point.x, self.linesView.bounds.size.height - point.y);
// Slope
CGFloat lineSlope = (CGFloat)(rightPoint.y - leftPoint.y) / (CGFloat)(rightPoint.x - leftPoint.x);
// Slope - set to zero if x coordinates are the same and would result in a NaN value
CGFloat lineSlope = rightPoint.x != leftPoint.x ? (CGFloat)(rightPoint.y - leftPoint.y) / (CGFloat)(rightPoint.x - leftPoint.x) : 0.0f;
// Insersection point
CGPoint interesectionPoint = CGPointMake(normalizedTouchPoint.x, (lineSlope * (normalizedTouchPoint.x - leftPoint.x)) + leftPoint.y);
@@ -1053,7 +1063,7 @@ NSInteger const kJBLineChartUnselectedLineIndex = -1;
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];
NSInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
if (lineIndex == kJBLineChartLinesViewUnselectedLineIndex || [((JBLineChartLine *)[self.lineChartLines objectAtIndex:lineIndex]).lineChartPoints count] <= 0)
{
+2 -1
View File
@@ -16,7 +16,7 @@ extern NSInteger const kJBLineChartDotsViewUnselectedLineIndex;
@interface JBLineChartDotsView : UIView
@property (nonatomic, assign) id<JBLineChartDotsViewDataSource> delegate;
@property (nonatomic, assign) id<JBLineChartDotsViewDataSource> dataSource;
@property (nonatomic, assign) NSInteger selectedLineIndex;
@property (nonatomic, strong) NSDictionary *dotViewsDict;
@@ -42,5 +42,6 @@ extern NSInteger const kJBLineChartDotsViewUnselectedLineIndex;
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex;
@end
+24 -21
View File
@@ -21,7 +21,7 @@
// Numerics
static CGFloat const kJBLineChartDotsViewReloadDataAnimationDuration = 0.15f;
NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
@implementation JBLineChartDotsView
@@ -41,8 +41,8 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
- (void)reloadDataAnimated:(BOOL)animated callback:(void (^)())callback
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (NSArray *)lineChartLinesForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
NSArray *lineChartLines = [self.delegate lineChartLinesForLineChartDotsView:self];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesForLineChartDotsView:)], @"JBLineChartDotsView // dataSource must implement - (NSArray *)lineChartLinesForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
NSArray *lineChartLines = [self.dataSource lineChartLinesForLineChartDotsView:self];
if (animated)
{
@@ -57,8 +57,8 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
NSUInteger lineIndex = 0;
for (JBLineChartLine *lineChartLine in lineChartLines)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:showsDotsForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex");
if ([self.delegate lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:showsDotsForLineAtLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex");
if ([self.dataSource lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
{
NSArray *sortedLineChartPoints = [lineChartLine.lineChartPoints sortedArrayUsingSelector:@selector(compare:)];
for (NSUInteger horizontalIndex = 0; horizontalIndex < [sortedLineChartPoints count]; horizontalIndex++)
@@ -102,8 +102,8 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
NSMutableDictionary *mutableDotViewsDict = [NSMutableDictionary dictionary];
for (JBLineChartLine *lineChartLine in lineChartLines)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:showsDotsForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex");
if ([self.delegate lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:showsDotsForLineAtLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex");
if ([self.dataSource lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
{
NSMutableArray *mutableDotViews = [NSMutableArray array];
NSArray *sortedLineChartPoints = [lineChartLine.lineChartPoints sortedArrayUsingSelector:@selector(compare:)];
@@ -164,24 +164,27 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
{
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];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource 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
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex];
}
}
// Custom dot
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
BOOL hideDotView = [self.delegate lineChartDotsView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
BOOL hideDotView = [self.dataSource lineChartDotsView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (weakSelf.selectedLineIndex == lineIndex)
{
dotView.alpha = hideDotView ? 0.0f : 1.0f;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = hideDotView ? [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex] : 1.0f;
}
else
{
@@ -215,19 +218,19 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = 0.25f;
- (UIView *)dotViewForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotViewAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
UIView *dotView = [self.delegate lineChartDotsView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dotViewAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
UIView *dotView = [self.dataSource lineChartDotsView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
// System dot
if (dotView == 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];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat dotRadius = [self.dataSource lineChartDotsView:self dotRadiusForLineAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
dotView = [[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");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
return dotView;
+1 -1
View File
@@ -16,7 +16,7 @@ extern NSInteger const kJBLineChartLinesViewUnselectedLineIndex;
@interface JBLineChartLinesView : UIView
@property (nonatomic, assign) id<JBLineChartLinesViewDataSource> delegate;
@property (nonatomic, assign) id<JBLineChartLinesViewDataSource> dataSource;
@property (nonatomic, assign) NSInteger selectedLineIndex; // -1 to unselect
// Data
+40 -40
View File
@@ -62,8 +62,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
{
[super drawRect:rect];
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (NSArray *)lineChartLinesForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
NSArray *chartData = [self.delegate lineChartLinesForLineChartLinesView:self];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesForLineChartLinesView:)], @"JBLineChartLinesView // dataSource must implement - (NSArray *)lineChartLinesForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
NSArray *chartData = [self.dataSource lineChartLinesForLineChartLinesView:self];
for (NSUInteger lineIndex=0; lineIndex<[chartData count]; lineIndex++)
{
@@ -90,18 +90,18 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
}
// Width
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.lineWidth = [self.dataSource lineChartLinesView:self widthForLineAtLineIndex:lineIndex];
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineFillLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineFillLayer.lineWidth = [self.dataSource lineChartLinesView:self widthForLineAtLineIndex:lineIndex];
// Colors
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:lineIndex].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.dataSource lineChartLinesView:self colorForLineAtLineIndex:lineIndex].CGColor;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineFillLayer.fillColor = [self.delegate lineChartLinesView:self fillColorForLineAtLineIndex:lineIndex].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineFillLayer.fillColor = [self.dataSource lineChartLinesView:self fillColorForLineAtLineIndex:lineIndex].CGColor;
// Bounds
shapeLineLayer.frame = self.bounds;
@@ -126,8 +126,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
JBGradientLineLayer *gradientLineFillLayer = [self gradientLineLayerForLineIndex:lineIndex filled:YES];
if (gradientLineFillLayer == nil)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
gradientLineFillLayer = [[JBGradientLineLayer alloc] initWithGradientLayer:[self.delegate lineChartLinesView:self fillGradientForLineAtLineIndex:lineIndex] tag:lineIndex filled:YES currentPath:nil];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:fillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
gradientLineFillLayer = [[JBGradientLineLayer alloc] initWithGradientLayer:[self.dataSource lineChartLinesView:self fillGradientForLineAtLineIndex:lineIndex] tag:lineIndex filled:YES currentPath:nil];
}
gradientLineFillLayer.frame = shapeLineFillLayer.frame;
@@ -168,8 +168,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
JBGradientLineLayer *gradientLineLayer = [self gradientLineLayerForLineIndex:lineIndex filled:NO];
if (gradientLineLayer == nil)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:gradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex");
gradientLineLayer = [[JBGradientLineLayer alloc] initWithGradientLayer:[self.delegate lineChartLinesView:self gradientForLineAtLineIndex:lineIndex] tag:lineIndex filled:NO currentPath:linePath];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:gradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex");
gradientLineLayer = [[JBGradientLineLayer alloc] initWithGradientLayer:[self.dataSource lineChartLinesView:self gradientForLineAtLineIndex:lineIndex] tag:lineIndex filled:NO currentPath:linePath];
}
gradientLineLayer.frame = shapeLineLayer.frame;
@@ -197,8 +197,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
- (void)reloadDataAnimated:(BOOL)animated callback:(void (^)())callback
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (NSArray *)lineChartLinesForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
NSArray *chartData = [self.delegate lineChartLinesForLineChartLinesView:self];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesForLineChartLinesView:)], @"JBLineChartLinesView // dataSource must implement - (NSArray *)lineChartLinesForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
NSArray *chartData = [self.dataSource lineChartLinesForLineChartLinesView:self];
NSUInteger lineCount = [chartData count];
@@ -320,18 +320,18 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Selected solid fill
if (weakSelf.selectedLineIndex >= 0 && ((unsigned)shapeLineLayer.tag == weakSelf.selectedLineIndex))
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectionFillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.fillColor = [self.delegate lineChartLinesView:self selectionFillColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:selectionFillColorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.fillColor = [self.dataSource lineChartLinesView:self selectionFillColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
shapeLineLayer.opacity = 1.0f;
}
// Unselected solid fill
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.fillColor = [self.delegate lineChartLinesView:self fillColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.fillColor = [self.dataSource lineChartLinesView:self fillColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
}
}
else
@@ -339,18 +339,18 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Selected solid line
if (weakSelf.selectedLineIndex >= 0 && ((unsigned)shapeLineLayer.tag == weakSelf.selectedLineIndex))
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectionColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.delegate lineChartLinesView:self selectionColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:selectionColorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.dataSource lineChartLinesView:self selectionColorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
shapeLineLayer.opacity = 1.0f;
}
// Unselected solid line
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.strokeColor = [self.dataSource lineChartLinesView:self colorForLineAtLineIndex:shapeLineLayer.tag].CGColor;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
}
}
}
@@ -371,8 +371,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Selected gradient fill
if (weakSelf.selectedLineIndex >= 0 && ((unsigned)shapeLineLayer.tag == weakSelf.selectedLineIndex))
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectionFillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *selectedFillGradient = [self.delegate lineChartLinesView:self selectionFillGradientForLineAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:selectionFillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *selectedFillGradient = [self.dataSource lineChartLinesView:self selectionFillGradientForLineAtLineIndex:shapeLineLayer.tag];
selectedFillGradient.frame = layer.frame;
selectedFillGradient.mask = layer.mask;
selectedFillGradient.opacity = 1.0f;
@@ -381,12 +381,12 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Unselected gradient fill
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *unselectedFillGradient = [self.delegate lineChartLinesView:self fillGradientForLineAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:fillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *unselectedFillGradient = [self.dataSource lineChartLinesView:self fillGradientForLineAtLineIndex:shapeLineLayer.tag];
unselectedFillGradient.frame = layer.frame;
unselectedFillGradient.mask = layer.mask;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
unselectedFillGradient.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
unselectedFillGradient.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: unselectedFillGradient}];
}
}
@@ -395,8 +395,8 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Selected gradient line
if (weakSelf.selectedLineIndex >= 0 && ((unsigned)shapeLineLayer.tag == weakSelf.selectedLineIndex))
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectionGradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *selectedGradient = [self.delegate lineChartLinesView:self selectionGradientForLineAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:selectionGradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *selectedGradient = [self.dataSource lineChartLinesView:self selectionGradientForLineAtLineIndex:shapeLineLayer.tag];
selectedGradient.frame = layer.frame;
selectedGradient.mask = layer.mask;
selectedGradient.opacity = 1.0f;
@@ -405,12 +405,12 @@ NSInteger const kJBLineChartLinesViewUnselectedLineIndex = -1;
// Unselected gradient line
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:gradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *unselectedGradient = [self.delegate lineChartLinesView:self gradientForLineAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:gradientForLineAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex");
CAGradientLayer *unselectedGradient = [self.dataSource lineChartLinesView:self gradientForLineAtLineIndex:shapeLineLayer.tag];
unselectedGradient.frame = layer.frame;
unselectedGradient.mask = layer.mask;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartLinesView:dimmedSelectionOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex");
shapeLineLayer.opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:shapeLineLayer.tag];
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: unselectedGradient}];
}
}
+8 -1
View File
@@ -198,8 +198,15 @@ Upon selection, all other lines (+ fills) will be dimmed to 20% opacity (default
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex
{
// Return new opacity (0.0 to hide completely, and 1.0 to have no effect)
// Return unselected line opacity (0.0 to hide completely, and 1.0 to have no effect)
}
The dot selection opacity (default 0%) can also be modified via:
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex
{
// Return unselected dot opacity (0.0 to hide completely and 1.0 to have no effect)
}
If you don't want a line to be selectable:
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "3.0.1"
s.version = "3.0.12"
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 => "v3.0.1"
:tag => "v3.0.12"
}
s.platform = :ios, '6.0'
@@ -205,18 +205,15 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
- (void)chartToggleButtonPressed:(id)sender
{
int randomNumber = (-3) + rand() % (3-(-3));
UIView *buttonImageView = [self.navigationItem.rightBarButtonItem valueForKey:kJBBarChartViewControllerNavButtonViewKey];
buttonImageView.userInteractionEnabled = NO;
NSMutableArray *mutableChartData = [NSMutableArray array];
for (int i=0; i<(kJBBarChartViewControllerNumBars + randomNumber ); i++)
{
NSInteger delta = ((kJBBarChartViewControllerNumBars + randomNumber) - labs(((kJBBarChartViewControllerNumBars + randomNumber) - i) - i)) + 2;
[mutableChartData addObject:[NSNumber numberWithFloat:MAX((delta * kJBBarChartViewControllerMinBarHeight), arc4random() % (delta * kJBBarChartViewControllerMaxBarHeight))]];
}
self.chartData = [NSArray arrayWithArray:mutableChartData];
CGAffineTransform transform = self.barChartView.state == JBChartViewStateExpanded ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
buttonImageView.transform = transform;
[self.barChartView reloadDataAnimated:YES];
[self.barChartView setState:self.barChartView.state == JBChartViewStateExpanded ? JBChartViewStateCollapsed : JBChartViewStateExpanded animated:YES callback:^{
buttonImageView.userInteractionEnabled = YES;
}];
}
#pragma mark - Overrides
@@ -305,15 +305,7 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
- (void)chartToggleButtonPressed:(id)sender
{
UIView *buttonImageView = [self.navigationItem.rightBarButtonItem valueForKey:kJBLineChartViewControllerNavButtonViewKey];
buttonImageView.userInteractionEnabled = NO;
CGAffineTransform transform = self.lineChartView.state == JBChartViewStateExpanded ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
buttonImageView.transform = transform;
[self.lineChartView setState:self.lineChartView.state == JBChartViewStateExpanded ? JBChartViewStateCollapsed : JBChartViewStateExpanded animated:YES callback:^{
buttonImageView.userInteractionEnabled = YES;
}];
[self.chartView setLoading:!self.chartView.loading animated:YES];
}
#pragma mark - Overrides