Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 112b72d35f | |||
| f436a12413 | |||
| 8f1159fda6 | |||
| 5468952b53 | |||
| af508bb50c | |||
| 988c8c9ab9 | |||
| 7944c03962 | |||
| e28a0113f8 | |||
| 40ae91de47 | |||
| 251b6e888f | |||
| c2558f9975 | |||
| 2d1450340b | |||
| 706dbc1859 | |||
| 6cce1ae272 | |||
| 0b603cde1f | |||
| eacc211dbd | |||
| 641fb7f5fa | |||
| 28a660c57f | |||
| 52c8d632b7 | |||
| 59eebf6015 | |||
| 036c01dc03 | |||
| 063079f171 | |||
| dc56268f29 | |||
| f56b539fe4 |
@@ -1,5 +1,79 @@
|
||||
# Change Log
|
||||
|
||||
## [v3.0.13](https://github.com/Jawbone/JBChartView/tree/v3.0.13) (2017-02-08)
|
||||
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.12...v3.0.13)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- selectionColorForDotAtHorizontalIndex doesn't change color [\#221](https://github.com/Jawbone/JBChartView/issues/221)
|
||||
- 内存泄露(leak!) [\#219](https://github.com/Jawbone/JBChartView/issues/219)
|
||||
- wrong dot color with NAN after click graph [\#216](https://github.com/Jawbone/JBChartView/issues/216)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Amazing issue with width of JBLineChartView [\#220](https://github.com/Jawbone/JBChartView/issues/220)
|
||||
- Bar chart doesn't paint inside selected UITableViewCell [\#214](https://github.com/Jawbone/JBChartView/issues/214)
|
||||
- Does not conform with protocol [\#212](https://github.com/Jawbone/JBChartView/issues/212)
|
||||
- \[question\] Does JBChartView support logarithmic scale? [\#211](https://github.com/Jawbone/JBChartView/issues/211)
|
||||
- Fixed tool tip in Bar chart [\#210](https://github.com/Jawbone/JBChartView/issues/210)
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -41,7 +41,8 @@ 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 kJBLineChartViewDefaultDimmedSelectionOpacity = 0.20f;
|
||||
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;
|
||||
@@ -265,7 +266,7 @@ static 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 @@ static 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 @@ static 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 @@ static 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 @@ static 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 @@ static 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -41,8 +41,8 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
|
||||
- (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 = -1;
|
||||
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 = -1;
|
||||
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:)];
|
||||
@@ -112,12 +112,13 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
JBLineChartPoint *lineChartPoint = [sortedLineChartPoints objectAtIndex:horizontalIndex];
|
||||
if(lineChartPoint.hidden)
|
||||
{
|
||||
continue;
|
||||
[mutableDotViews addObject:[NSNull null]];
|
||||
continue;
|
||||
}
|
||||
|
||||
UIView *dotView = [self dotViewForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
dotView.center = CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y);
|
||||
[mutableDotViews addObject:dotView];
|
||||
[mutableDotViews addObject:dotView];
|
||||
[self addSubview:dotView];
|
||||
}
|
||||
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
|
||||
@@ -158,36 +159,42 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
if ([key isKindOfClass:[NSNumber class]])
|
||||
{
|
||||
NSInteger lineIndex = [((NSNumber *)key) intValue];
|
||||
|
||||
// Internal dot
|
||||
if ([dotView isKindOfClass:[JBLineChartDotView class]])
|
||||
{
|
||||
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: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];
|
||||
if (weakSelf.selectedLineIndex == lineIndex)
|
||||
{
|
||||
dotView.alpha = hideDotView ? 0.0f : 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
dotView.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (![dotView isKindOfClass:[NSNull class]])
|
||||
{
|
||||
// Internal dot
|
||||
if ([dotView isKindOfClass:[JBLineChartDotView class]])
|
||||
{
|
||||
if (weakSelf.selectedLineIndex == 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.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.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)
|
||||
{
|
||||
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
|
||||
{
|
||||
dotView.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
horizontalIndex++;
|
||||
}
|
||||
@@ -215,19 +222,19 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
|
||||
- (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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "3.0.4"
|
||||
s.version = "3.0.13"
|
||||
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.4"
|
||||
:tag => "v3.0.13"
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user