Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 78b2aa1964 | |||
| d9ab659422 | |||
| 71df60f9a3 | |||
| 728b9420a9 | |||
| fe42e4f61d | |||
| 45cf0d66ba | |||
| 5aecb0ba92 | |||
| 6f14f4099f | |||
| 9fa369ce8d | |||
| 9828034f6b | |||
| 58f57fcef2 | |||
| 69ce275d1a |
@@ -1,5 +1,20 @@
|
||||
# Change Log
|
||||
|
||||
## [v2.8.19](https://github.com/Jawbone/JBChartView/tree/v2.8.19) (2015-11-23)
|
||||
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v2.8.18...v2.8.19)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Straight lines [\#94](https://github.com/Jawbone/JBChartView/issues/94)
|
||||
|
||||
## [v2.8.18](https://github.com/Jawbone/JBChartView/tree/v2.8.18) (2015-11-22)
|
||||
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v2.8.17...v2.8.18)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Vertical values should be supplied by the DataSource delegate for LineCharts [\#180](https://github.com/Jawbone/JBChartView/issues/180)
|
||||
- JBLineChartDotsView reloadData performance issues [\#179](https://github.com/Jawbone/JBChartView/issues/179)
|
||||
|
||||
## [v2.8.17](https://github.com/Jawbone/JBChartView/tree/v2.8.17) (2015-11-21)
|
||||
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v2.8.16...v2.8.17)
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
* If you already implement barChartView:barViewAtIndex: delegate - this method has no effect.
|
||||
* If a custom UIView isn't supplied, a flat bar will be made automatically (default color black).
|
||||
*
|
||||
* Default: if none specified - calls barChartView:barViewAtIndex:.
|
||||
* Default: black color.
|
||||
*
|
||||
* @param barChartView The bar chart object requesting this information.
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis).
|
||||
@@ -89,6 +89,19 @@
|
||||
*/
|
||||
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
|
||||
|
||||
/**
|
||||
* If you already implement barChartView:barViewAtIndex: delegate - this method has no effect.
|
||||
* If a custom UIView isn't supplied and barChartView:colorForBarViewAtIndex: isn't implemented, then
|
||||
* a gradient layer may be supplied to be used across all bars within the chart.
|
||||
*
|
||||
* Default: black color.
|
||||
*
|
||||
* @param barChartView The bar chart object requesting this information.
|
||||
*
|
||||
* @return The gradient layer to be used as a mask over all bars within the chart.
|
||||
*/
|
||||
- (CAGradientLayer *)barGradientForBarChartView:(JBBarChartView *)barChartView;
|
||||
|
||||
/**
|
||||
* The selection color to be overlayed on a bar during touch events.
|
||||
* The color is automatically faded to transparent (vertically). The property showsVerticalSelection
|
||||
|
||||
+141
-31
@@ -25,7 +25,27 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBBarChartView ()
|
||||
@protocol JBGradientBarViewDelegate;
|
||||
|
||||
@interface JBGradientBarView: UIView
|
||||
|
||||
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
|
||||
@property (nonatomic, weak) id<JBGradientBarViewDelegate> delegate;
|
||||
|
||||
// Initialization
|
||||
- (void)construct;
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBGradientBarViewDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
- (CGRect)chartViewBoundsForGradientBarView:(JBGradientBarView *)gradientBarView;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBBarChartView () <JBGradientBarViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) NSDictionary *chartDataDictionary; // key = column, value = height
|
||||
@property (nonatomic, strong) NSArray *barViews;
|
||||
@@ -178,36 +198,49 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray array];
|
||||
for (NSNumber *key in [[self.chartDataDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)])
|
||||
{
|
||||
UIView *barView = nil; // since all bars are visible at once, no need to cache this view
|
||||
if ([self.dataSource respondsToSelector:@selector(barChartView:barViewAtIndex:)])
|
||||
{
|
||||
barView = [self.dataSource barChartView:self barViewAtIndex:index];
|
||||
NSAssert(barView != nil, @"JBBarChartView // datasource function - (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index must return a non-nil UIView subclass");
|
||||
}
|
||||
else
|
||||
{
|
||||
barView = [[UIView alloc] init];
|
||||
UIColor *backgroundColor = nil;
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)])
|
||||
{
|
||||
backgroundColor = [self.delegate barChartView:self colorForBarViewAtIndex:index];
|
||||
NSAssert(backgroundColor != nil, @"JBBarChartView // delegate function - (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index must return a non-nil UIColor");
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundColor = kJBBarChartViewDefaultBarColor;
|
||||
}
|
||||
|
||||
barView.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
UIView *barView = nil;
|
||||
{
|
||||
// Custom bar
|
||||
if ([self.dataSource respondsToSelector:@selector(barChartView:barViewAtIndex:)])
|
||||
{
|
||||
UIView *customBarView = [self.dataSource barChartView:self barViewAtIndex:index];
|
||||
if (customBarView != nil)
|
||||
{
|
||||
barView = customBarView;
|
||||
}
|
||||
}
|
||||
|
||||
// Color bar
|
||||
if ([self.delegate respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)] && barView == nil)
|
||||
{
|
||||
UIColor *backgroundColor = [self.delegate barChartView:self colorForBarViewAtIndex:index];
|
||||
if (backgroundColor != nil)
|
||||
{
|
||||
barView = [[UIView alloc] init];
|
||||
barView.backgroundColor = backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
// Gradient
|
||||
if ([self.delegate respondsToSelector:@selector(barGradientForBarChartView:)] && barView == nil)
|
||||
{
|
||||
CAGradientLayer *gradientLayer = [self.delegate barGradientForBarChartView:self];
|
||||
if (gradientLayer != nil)
|
||||
{
|
||||
barView = [[JBGradientBarView alloc] init];
|
||||
((JBGradientBarView *)barView).delegate = self;
|
||||
((JBGradientBarView *)barView).gradientLayer = gradientLayer;
|
||||
}
|
||||
}
|
||||
|
||||
// Default
|
||||
if (barView == nil)
|
||||
{
|
||||
barView = [[UIView alloc] init];
|
||||
barView.backgroundColor = kJBBarChartViewDefaultBarColor;
|
||||
}
|
||||
}
|
||||
barView.tag = index;
|
||||
|
||||
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
|
||||
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height);
|
||||
[mutableBarViews addObject:barView];
|
||||
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:height]];
|
||||
|
||||
// Add new bar
|
||||
if (self.footerView)
|
||||
@@ -218,7 +251,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
[self addSubview:barView];
|
||||
}
|
||||
|
||||
|
||||
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
|
||||
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height);
|
||||
[mutableBarViews addObject:barView];
|
||||
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:height]];
|
||||
|
||||
xOffset += ([self barWidth] + self.barPadding);
|
||||
index++;
|
||||
}
|
||||
@@ -643,4 +681,76 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
[self touchesEndedOrCancelledWithTouches:touches];
|
||||
}
|
||||
|
||||
#pragma mark - JBGradientBarViewDelegate
|
||||
|
||||
- (CGRect)chartViewBoundsForGradientBarView:(JBGradientBarView *)gradientBarView
|
||||
{
|
||||
return self.bounds;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation JBGradientBarView
|
||||
|
||||
#pragma mark - Alloc/Init
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
[self construct];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
[self construct];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setGradientLayer:(CAGradientLayer *)gradientLayer
|
||||
{
|
||||
if (_gradientLayer != nil)
|
||||
{
|
||||
[_gradientLayer removeFromSuperlayer];
|
||||
_gradientLayer = nil;
|
||||
}
|
||||
|
||||
_gradientLayer = gradientLayer;
|
||||
_gradientLayer.masksToBounds = YES;
|
||||
[self.layer insertSublayer:_gradientLayer atIndex:0];
|
||||
}
|
||||
|
||||
#pragma mark - Construction
|
||||
|
||||
- (void)construct
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
[super setFrame:frame];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(chartViewBoundsForGradientBarView:)])
|
||||
{
|
||||
_gradientLayer.frame = [self.delegate chartViewBoundsForGradientBarView:self]; // gradient is as large as the chart
|
||||
_gradientLayer.frame = CGRectOffset(_gradientLayer.frame, -CGRectGetMinX(frame), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_gradientLayer.frame = self.bounds;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -24,6 +24,20 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
JBLineChartViewLineStyleDashed
|
||||
};
|
||||
|
||||
/**
|
||||
* Current support for two line color styles: solid (default) and gradient.
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, JBLineChartViewLineColorStyle){
|
||||
/**
|
||||
* Solid line and fill color.
|
||||
*/
|
||||
JBLineChartViewLineColorStyleSolid,
|
||||
/**
|
||||
* Gradient line and fill color.
|
||||
*/
|
||||
JBLineChartViewLineColorStyleGradient
|
||||
};
|
||||
|
||||
@protocol JBLineChartViewDataSource <JBChartViewDataSource>
|
||||
|
||||
@required
|
||||
@@ -78,6 +92,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
/**
|
||||
* Returns the opacity value to be used for dimming the line & fill during selection events.
|
||||
* This value is applied to the line or fill's opacity anytime it's not selected (but another line is).
|
||||
* This applies to both solid and gradient line styles.
|
||||
*
|
||||
* Default: 0.2.
|
||||
*
|
||||
@@ -185,6 +200,18 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the gradient layer to be used for a particular line at lineIndex within the chart.
|
||||
*
|
||||
* Default: black to light gray.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The gradient layer to be used as a mask for the line in the chart.
|
||||
*/
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView gradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the fill color of particular line at lineIndex within the chart.
|
||||
*
|
||||
@@ -197,6 +224,18 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView fillColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the gradient layer to be used for a fill of a particular line at lineIndex within the chart.
|
||||
*
|
||||
* Default: white to light gray.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The fill color to show under a line in the chart.
|
||||
*/
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the color of a particular dot in a line at lineIndex within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
@@ -277,6 +316,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the gradient layer to be overlayed on a line during touch events.
|
||||
* Alpha of gradient is controlled by the color returned from lineChartView:selectionColorForLineAtLineIndex:
|
||||
*
|
||||
* Default: matches lineChartView:gradientForLineAtLineIndex:.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The gradient layer to be used as a mask for the line in the chart.
|
||||
*/
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the selection fill color to be overlayed under a line within the chart during touch events.
|
||||
* The property showsLineSelection must be YES for the color to apply.
|
||||
@@ -290,6 +342,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionFillColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the gradient layer to be used for the selection fill to be overlayed under a line during touch events.
|
||||
* Alpha of gradient is controlled by the color returned from lineChartView:selectionFillColorForLineAtLineIndex:
|
||||
*
|
||||
* Default: matches lineChartView:fillGradientForLineAtLineIndex.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The fill color to show under a line in the chart.
|
||||
*/
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the selection color to be overlayed on a line within the chart during touch events.
|
||||
* The property showsLineSelection must be YES for the color to apply.
|
||||
@@ -317,6 +382,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the line color style of a particular line at lineIndex within the chart.
|
||||
* See JBLineChartViewLineColorStyle for line color style descriptions.
|
||||
*
|
||||
* Default: JBLineChartViewLineColorStyleSolid.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The line style to be used to draw a line in the chart.
|
||||
*/
|
||||
- (JBLineChartViewLineColorStyle)lineChartView:(JBLineChartView *)lineChartView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBLineChartView : JBChartView
|
||||
|
||||
+187
-44
@@ -23,8 +23,8 @@ CGFloat static const kJBLineChartLinesViewStrokeWidth = 5.0;
|
||||
CGFloat static const kJBLineChartLinesViewMiterLimit = -5.0;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultLinePhase = 1.0f;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.20f;
|
||||
NSInteger static const kJBLineChartLinesViewUnselectedLineIndex = -1;
|
||||
CGFloat static const kJBLineChartLinesViewSmoothThresholdSlope = 0.01f;
|
||||
NSInteger static const kJBLineChartLinesViewUnselectedLineIndex = -1;
|
||||
NSInteger static const kJBLineChartLinesViewSmoothThresholdVertical = 1;
|
||||
|
||||
// Numerics (JBLineChartDotsView)
|
||||
@@ -35,10 +35,12 @@ NSInteger static const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
CGFloat static const kJBLineSelectionViewWidth = 20.0f;
|
||||
|
||||
// Numerics (JBLineChartView)
|
||||
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
|
||||
CGFloat static const kJBLineChartViewUndefinedCachedHeight = -1.0f;
|
||||
CGFloat static const kJBLineChartViewStateAnimationDuration = 0.25f;
|
||||
CGFloat static const kJBLineChartViewStateAnimationDelay = 0.05f;
|
||||
CGFloat static const kJBLineChartViewStateBounceOffset = 15.0f;
|
||||
CGFloat static const kJBLineChartViewDefaultStartPoint = 0.0;
|
||||
CGFloat static const kJBLineChartViewDefaultEndPoint = 1.0;
|
||||
NSInteger static const kJBLineChartUnselectedLineIndex = -1;
|
||||
|
||||
// Collections (JBLineChartLineView)
|
||||
@@ -51,6 +53,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultLineSelectionFillColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultDotColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientStartColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientEndColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientFillStartColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientFillEndColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientSelectionStartColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientSelectionEndColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientSelectionFillStartColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultGradientSelectionFillEndColor = nil;
|
||||
|
||||
|
||||
@interface JBChartView (Private)
|
||||
|
||||
@@ -63,6 +74,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
@property (nonatomic, assign) NSUInteger tag;
|
||||
@property (nonatomic, assign) JBLineChartViewLineStyle lineStyle;
|
||||
@property (nonatomic, assign) JBLineChartViewLineColorStyle lineColorStyle;
|
||||
|
||||
@end
|
||||
|
||||
@@ -107,11 +119,15 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
- (NSArray *)chartDataForLineChartLinesView:(JBLineChartLinesView*)lineChartLinesView;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedFillColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView;
|
||||
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (JBLineChartViewLineColorStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionOpacityAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -142,7 +158,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
@@ -203,6 +218,14 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
kJBLineChartViewDefaultLineSelectionFillColor = [UIColor clearColor];
|
||||
kJBLineChartViewDefaultDotColor = [UIColor blackColor];
|
||||
kJBLineChartViewDefaultDotSelectionColor = [UIColor whiteColor];
|
||||
kJBLineChartViewDefaultGradientStartColor = [UIColor blackColor];
|
||||
kJBLineChartViewDefaultGradientEndColor = [UIColor lightGrayColor];
|
||||
kJBLineChartViewDefaultGradientFillStartColor = [UIColor whiteColor];
|
||||
kJBLineChartViewDefaultGradientFillEndColor = [UIColor lightGrayColor];
|
||||
kJBLineChartViewDefaultGradientSelectionStartColor = [UIColor whiteColor];
|
||||
kJBLineChartViewDefaultGradientSelectionEndColor = [UIColor darkGrayColor];
|
||||
kJBLineChartViewDefaultGradientSelectionFillStartColor = [UIColor clearColor];
|
||||
kJBLineChartViewDefaultGradientSelectionFillEndColor = [UIColor clearColor];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,8 +263,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
_showsVerticalSelection = YES;
|
||||
_showsLineSelection = YES;
|
||||
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
_cachedMinHeight = kJBLineChartViewUndefinedCachedHeight;
|
||||
_cachedMaxHeight = kJBLineChartViewUndefinedCachedHeight;
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
@@ -249,8 +272,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
- (void)reloadData
|
||||
{
|
||||
// Reset cached max height
|
||||
self.cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
self.cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
self.cachedMinHeight = kJBLineChartViewUndefinedCachedHeight;
|
||||
self.cachedMaxHeight = kJBLineChartViewUndefinedCachedHeight;
|
||||
|
||||
// Padding
|
||||
CGFloat chartPadding = [self padding];
|
||||
@@ -291,7 +314,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
rawHeight = 0; //set to 0 so we can calculate the x position
|
||||
}
|
||||
|
||||
CGFloat normalizedHeight = [self normalizedHeightForRawHeight:rawHeight];
|
||||
CGFloat normalizedHeight = [self padding] + [self normalizedHeightForRawHeight:rawHeight];
|
||||
yOffset = mainViewRect.size.height - normalizedHeight;
|
||||
|
||||
chartPoint.position = CGPointMake(xOffset, yOffset);
|
||||
@@ -433,13 +456,15 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
CGFloat minHeight = [self minimumValue];
|
||||
CGFloat maxHeight = [self maximumValue];
|
||||
|
||||
CGFloat availableHeightWithPadding = [self availableHeight] - ([self padding] * 2);
|
||||
|
||||
if ((maxHeight - minHeight) <= 0)
|
||||
{
|
||||
return [self availableHeight];
|
||||
return availableHeightWithPadding;
|
||||
}
|
||||
|
||||
return ((rawHeight - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
|
||||
return ((rawHeight - minHeight) / (maxHeight - minHeight)) * availableHeightWithPadding;
|
||||
}
|
||||
|
||||
- (CGFloat)availableHeight
|
||||
@@ -544,7 +569,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
maxLineWidth = currentMaxLineWidth;
|
||||
}
|
||||
}
|
||||
return ceil(maxLineWidth * 0.5);
|
||||
return (maxLineWidth * 0.5);
|
||||
}
|
||||
|
||||
- (NSUInteger)dataCount
|
||||
@@ -589,6 +614,30 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return kJBLineChartViewDefaultLineSelectionColor;
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:gradientForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self gradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
// Default gradient
|
||||
CAGradientLayer *gradient = [CAGradientLayer new];
|
||||
gradient.startPoint = CGPointMake(kJBLineChartViewDefaultStartPoint, kJBLineChartViewDefaultStartPoint);
|
||||
gradient.endPoint = CGPointMake(kJBLineChartViewDefaultEndPoint, kJBLineChartViewDefaultEndPoint);
|
||||
gradient.colors = @[(id)kJBLineChartViewDefaultGradientStartColor.CGColor, (id)kJBLineChartViewDefaultGradientEndColor.CGColor];
|
||||
return gradient;
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionGradientForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self selectionGradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return [self.delegate lineChartView:self gradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:fillColorForLineAtLineIndex:)])
|
||||
@@ -607,6 +656,30 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return kJBLineChartViewDefaultLineSelectionFillColor;
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:fillGradientForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self fillGradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
// Default gradient
|
||||
CAGradientLayer *gradient = [CAGradientLayer new];
|
||||
gradient.startPoint = CGPointMake(kJBLineChartViewDefaultStartPoint, kJBLineChartViewDefaultStartPoint);
|
||||
gradient.endPoint = CGPointMake(kJBLineChartViewDefaultEndPoint, kJBLineChartViewDefaultEndPoint);
|
||||
gradient.colors = @[(id)kJBLineChartViewDefaultGradientFillStartColor.CGColor, (id)kJBLineChartViewDefaultGradientFillEndColor.CGColor];
|
||||
return gradient;
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionFillGradientForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self selectionFillGradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return [self.delegate lineChartView:self fillGradientForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
||||
@@ -616,11 +689,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return kJBLineChartLinesViewStrokeWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView
|
||||
{
|
||||
return [self padding];
|
||||
}
|
||||
|
||||
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
|
||||
@@ -630,6 +698,15 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return JBLineChartViewLineStyleSolid;
|
||||
}
|
||||
|
||||
- (JBLineChartViewLineColorStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:lineColorStyleForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self lineColorStyleForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return JBLineChartViewLineColorStyleSolid;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
|
||||
@@ -709,11 +786,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
{
|
||||
return [self padding];
|
||||
}
|
||||
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
|
||||
@@ -818,7 +890,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
- (CGFloat)cachedMinHeight
|
||||
{
|
||||
if (_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
if (_cachedMinHeight == kJBLineChartViewUndefinedCachedHeight)
|
||||
{
|
||||
CGFloat minHeight = FLT_MAX;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
@@ -845,7 +917,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
- (CGFloat)cachedMaxHeight
|
||||
{
|
||||
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
if (_cachedMaxHeight == kJBLineChartViewUndefinedCachedHeight)
|
||||
{
|
||||
CGFloat maxHeight = 0;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
@@ -1038,7 +1110,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
self.verticalSelectionView.bgColor = verticalSelectionColor;
|
||||
}
|
||||
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.verticalSelectionView.frame.size.width * 0.5))));
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (self.verticalSelectionView.frame.size.width * 0.5)));
|
||||
CGFloat yOffset = self.headerView.frame.size.height + self.headerPadding;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoHeaderPaddingForChartView:)])
|
||||
@@ -1219,9 +1291,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (NSArray *)chartDataForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
|
||||
NSArray *chartData = [self.delegate chartDataForLineChartLinesView:self];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
|
||||
CGFloat padding = [self.delegate paddingForLineChartLinesView:self];
|
||||
|
||||
NSUInteger lineIndex = 0;
|
||||
for (NSArray *lineData in chartData)
|
||||
@@ -1256,7 +1325,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
if (!visiblePointFound)
|
||||
{
|
||||
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
[path moveToPoint:CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y)];
|
||||
firstXPosition = lineChartPoint.position.x;
|
||||
firstYPosition = lineChartPoint.position.y;
|
||||
visiblePointFound = YES;
|
||||
@@ -1284,11 +1353,11 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
CGPoint controlPoint1 = CGPointMake(controlPointX, previousLineChartPoint.position.y);
|
||||
CGPoint controlPoint2 = CGPointMake(controlPointX, lineChartPoint.position.y);
|
||||
|
||||
[path addCurveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y))) controlPoint1:controlPoint1 controlPoint2:controlPoint2];
|
||||
[path addCurveToPoint:CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y) controlPoint1:controlPoint1 controlPoint2:controlPoint2];
|
||||
}
|
||||
else
|
||||
{
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y)];
|
||||
}
|
||||
|
||||
lastXPosition = lineChartPoint.position.x;
|
||||
@@ -1322,6 +1391,9 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
shapeFillLayer.fillColor = [self.delegate lineChartLinesView:self fillColorForLineAtLineIndex:lineIndex].CGColor;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:lineColorStyleForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (JBLineChartViewLineColorStyle)lineChartLineView:(JBLineChartLinesView *)lineChartLinesView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
shapeLayer.lineColorStyle = [self.delegate lineChartLinesView:self lineColorStyleForLineAtLineIndex:lineIndex];
|
||||
|
||||
if (smoothLine == YES)
|
||||
{
|
||||
shapeLayer.lineCap = kCALineCapRound;
|
||||
@@ -1347,18 +1419,35 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
if(visiblePointFound)
|
||||
{
|
||||
[fillPath addLineToPoint:CGPointMake(lastXPosition + ceil(padding * 0.5), lastYPosition)];
|
||||
[fillPath addLineToPoint:CGPointMake(lastXPosition + ceil(padding * 0.5), self.bounds.size.height)];
|
||||
[fillPath addLineToPoint:CGPointMake(lastXPosition, lastYPosition)];
|
||||
[fillPath addLineToPoint:CGPointMake(lastXPosition, self.bounds.size.height)];
|
||||
|
||||
[fillPath addLineToPoint:CGPointMake(firstXPosition - ceil(padding * 0.5), self.bounds.size.height)];
|
||||
[fillPath addLineToPoint:CGPointMake(firstXPosition - ceil(padding * 0.5), firstYPosition)];
|
||||
[fillPath addLineToPoint:CGPointMake(firstXPosition, self.bounds.size.height)];
|
||||
[fillPath addLineToPoint:CGPointMake(firstXPosition, firstYPosition)];
|
||||
}
|
||||
|
||||
|
||||
shapeFillLayer.path = fillPath.CGPath;
|
||||
shapeFillLayer.frame = self.bounds;
|
||||
|
||||
[self.layer addSublayer:shapeFillLayer];
|
||||
[self.layer addSublayer:shapeLayer];
|
||||
|
||||
if (shapeLayer.lineColorStyle == JBLineChartViewLineColorStyleGradient)
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillGradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
CAGradientLayer *fillGradient = [self.delegate lineChartLinesView:self fillGradientForLineAtLineIndex:lineIndex];
|
||||
fillGradient.frame = shapeFillLayer.frame;
|
||||
fillGradient.mask = shapeFillLayer;
|
||||
[self.layer addSublayer:fillGradient];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:gradientForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CAGradientLayer *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView gradientForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
CAGradientLayer *lineGradient = [self.delegate lineChartLinesView:self gradientForLineAtLineIndex:lineIndex];
|
||||
lineGradient.frame = shapeLayer.frame;
|
||||
lineGradient.mask = shapeLayer;
|
||||
[self.layer addSublayer:lineGradient];
|
||||
}
|
||||
else // shapeLayer.lineColorStyle == JBLineChartViewLineColorStyleSolid (default)
|
||||
{
|
||||
[self.layer addSublayer:shapeFillLayer];
|
||||
[self.layer addSublayer:shapeLayer];
|
||||
}
|
||||
|
||||
lineIndex++;
|
||||
}
|
||||
@@ -1383,6 +1472,9 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
__weak JBLineChartLinesView* weakSelf = self;
|
||||
|
||||
dispatch_block_t adjustLines = ^{
|
||||
NSMutableArray *layersToReplace = [NSMutableArray array];
|
||||
NSString * const oldLayerKey = @"oldLayer";
|
||||
NSString * const newLayerKey = @"newLayer";
|
||||
for (CALayer *layer in [weakSelf.layer sublayers])
|
||||
{
|
||||
if ([layer isKindOfClass:[JBLineLayer class]])
|
||||
@@ -1419,6 +1511,60 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
((JBFillLayer *)layer).opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:((JBLineLayer *)layer).tag];
|
||||
}
|
||||
}
|
||||
else if ([layer isKindOfClass:[CAGradientLayer class]])
|
||||
{
|
||||
if ([layer.mask isKindOfClass:[JBLineLayer class]])
|
||||
{
|
||||
JBLineLayer *lineLayer = (JBLineLayer *)layer.mask;
|
||||
if (lineLayer.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:lineLayer.tag];
|
||||
selectedGradient.frame = layer.frame;
|
||||
selectedGradient.mask = layer.mask;
|
||||
selectedGradient.opacity = 1.0f;
|
||||
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: selectedGradient}];
|
||||
}
|
||||
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:lineLayer.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");
|
||||
((JBLineLayer *)layer).opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : [self.delegate lineChartLinesView:self dimmedSelectionOpacityAtLineIndex:lineLayer.tag];
|
||||
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: unselectedGradient}];
|
||||
}
|
||||
}
|
||||
else if ([layer.mask isKindOfClass:[JBFillLayer class]])
|
||||
{
|
||||
JBFillLayer *fillLayer = (JBFillLayer *)layer.mask;
|
||||
if (fillLayer.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:fillLayer.tag];
|
||||
selectedFillGradient.frame = layer.frame;
|
||||
selectedFillGradient.mask = layer.mask;
|
||||
selectedFillGradient.opacity = 1.0f;
|
||||
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: selectedFillGradient}];
|
||||
}
|
||||
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:fillLayer.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:fillLayer.tag];
|
||||
[layersToReplace addObject:@{oldLayerKey: layer, newLayerKey: unselectedFillGradient}];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (NSDictionary *layerPair in layersToReplace)
|
||||
{
|
||||
[weakSelf.layer replaceSublayer:layerPair[oldLayerKey] with:layerPair[newLayerKey]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1513,10 +1659,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
|
||||
NSArray *chartData = [self.delegate chartDataForLineChartDotsView:self];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
|
||||
CGFloat padding = [self.delegate paddingForLineChartDotsView:self];
|
||||
|
||||
|
||||
NSUInteger lineIndex = 0;
|
||||
NSMutableDictionary *mutableDotViewsDict = [NSMutableDictionary dictionary];
|
||||
for (NSArray *lineData in chartData)
|
||||
@@ -1550,7 +1693,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
currentDotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
currentDotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
||||
currentDotView.center = CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y);
|
||||
[mutableDotViews addObject:currentDotView];
|
||||
[self addSubview:currentDotView];
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ By default, a chart's bars will be black and flat. They can be customized by sup
|
||||
If you don't require a custom UIView, simply supply a color for the bar instead:
|
||||
|
||||
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
|
||||
|
||||
If a solid color isn't your cup of tea, you can expose a gradient to be applied across the entire chart:
|
||||
|
||||
- (CAGradientLayer *)barGradientForBarChartView:(JBBarChartView *)barChartView;
|
||||
|
||||
Furthermore, the color of the selection bar (on touch events) can be customized via the <i>optional</i> protocol:
|
||||
|
||||
@@ -40,6 +44,8 @@ Furthermore, the color of the selection bar (on touch events) can be customized
|
||||
return ...; // color of selection view
|
||||
}
|
||||
|
||||
<b>Note</b>: The delegate will request a custom UIView, followed by a color and lastly a gradient. If nothing is supplied, a plain black bar will be used.
|
||||
|
||||
Lastly, a bar chart's selection events are delegated back via:
|
||||
|
||||
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint
|
||||
@@ -78,6 +84,28 @@ The color, width and style of each line in the chart can be customized via the <
|
||||
return ...; // style of line in chart
|
||||
}
|
||||
|
||||
Additionally, the line style of a line can be customzized via the <i>optional</i> protocol. If a gradient is used, the color for the line and fill of the line will control the alpha value of the gradient.
|
||||
|
||||
- (JBLineChartViewLineColorStyle)lineChartView:(JBLineChartView *)lineChartView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // line style of line in chart
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView gradientForLineAtLineIndex:(NSUInteger)lineIndex {
|
||||
return ...; // gradient for line in chart
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex {
|
||||
return ...; // gradient for area under line in chart
|
||||
}
|
||||
|
||||
Defining a gradient to use is simple and flexible. For example, this would be a horizontal gradient from blue to green:
|
||||
|
||||
CAGradientLayer *gradient = [CAGradientLayer new];
|
||||
gradient.startPoint = CGPointMake(0.0, 0.0);
|
||||
gradient.endPoint = CGPointMake(1.0, 0.0);
|
||||
gradient.colors = @[(id)[UIColor blueColor].CGColor, (id)[UIColor greenColor].CGColor];
|
||||
|
||||
Furthermore, the color and width of the selection view along with the color of the selected line can be customized via the <i>optional</i> protocols:
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
@@ -100,6 +128,18 @@ Furthermore, the color and width of the selection view along with the color of t
|
||||
return ...; // color of area under selected line
|
||||
}
|
||||
|
||||
When using a gradient for the line or fill, a different gradient can provided for selection. If the selection gradient is not provided, it will default to the line and fill gradient provided for the line.
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView selectionGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // gradient for selected line
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView selectionFillGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // gradient for area under selected line
|
||||
}
|
||||
|
||||
By default, each line will not show dots for each point. To enable this on a per-line basis:
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.8.16"
|
||||
s.version = "2.8.19"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Terry Worona" => "tworona@jawbone.com" }
|
||||
s.source = {
|
||||
:git => "https://github.com/Jawbone/JBChartView.git",
|
||||
:tag => "v2.8.16"
|
||||
:tag => "v2.8.19"
|
||||
}
|
||||
|
||||
s.platform = :ios, '6.0'
|
||||
|
||||
@@ -29,8 +29,14 @@
|
||||
#define kJBColorLineChartHeaderSeparatorColor UIColorFromHex(0x8eb6b7)
|
||||
#define kJBColorLineChartDefaultSolidLineColor [UIColor colorWithWhite:1.0 alpha:0.5]
|
||||
#define kJBColorLineChartDefaultSolidSelectedLineColor [UIColor colorWithWhite:1.0 alpha:1.0]
|
||||
#define kJBColorLineChartDefaultDashedLineColor [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]
|
||||
#define kJBColorLineChartDefaultDashedLineColor [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0]
|
||||
#define kJBColorLineChartDefaultDashedSelectedLineColor [UIColor colorWithWhite:1.0 alpha:1.0]
|
||||
#define kJBColorLineChartDefaultSolidFillColor [UIColor clearColor]
|
||||
#define kJBColorLineChartDefaultDashedFillColor [UIColor colorWithWhite:1.0 alpha:0.3]
|
||||
#define kJBColorLineChartDefaultGradientStartColor UIColorFromHex(0x0000FF)
|
||||
#define kJBColorLineChartDefaultGradientEndColor UIColorFromHex(0x00FF00)
|
||||
#define kJBColorLineChartDefaultFillGradientStartColor UIColorFromHex(0xFFFFFF)
|
||||
#define kJBColorLineChartDefaultFillGradientEndColor UIColorFromHex(0xbe0000)
|
||||
|
||||
#define mark - Area Chart
|
||||
|
||||
|
||||
@@ -240,6 +240,43 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView fillColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidFillColor : kJBColorLineChartDefaultDashedFillColor;
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView gradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if (lineIndex == JBLineChartLineSolid)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAGradientLayer *gradient = [CAGradientLayer new];
|
||||
gradient.startPoint = CGPointMake(0.0, 0.0);
|
||||
gradient.endPoint = CGPointMake(1.0, 0.0);
|
||||
gradient.colors = @[(id)kJBColorLineChartDefaultGradientStartColor.CGColor, (id)kJBColorLineChartDefaultGradientEndColor.CGColor];
|
||||
return gradient;
|
||||
}
|
||||
}
|
||||
|
||||
- (CAGradientLayer *)lineChartView:(JBLineChartView *)lineChartView fillGradientForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if (lineIndex == JBLineChartLineSolid)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
CAGradientLayer *gradient = [CAGradientLayer new];
|
||||
gradient.startPoint = CGPointMake(0.0, 0.0);
|
||||
gradient.endPoint = CGPointMake(1.0, 0.0);
|
||||
gradient.colors = @[(id)kJBColorLineChartDefaultFillGradientStartColor.CGColor, (id)kJBColorLineChartDefaultFillGradientEndColor.CGColor];
|
||||
return gradient;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
|
||||
@@ -275,6 +312,11 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? JBLineChartViewLineStyleSolid : JBLineChartViewLineStyleDashed;
|
||||
}
|
||||
|
||||
- (JBLineChartViewLineColorStyle)lineChartView:(JBLineChartView *)lineChartView lineColorStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? JBLineChartViewLineColorStyleSolid : JBLineChartViewLineColorStyleGradient;
|
||||
}
|
||||
|
||||
#pragma mark - Buttons
|
||||
|
||||
- (void)chartToggleButtonPressed:(id)sender
|
||||
|
||||
@@ -43,7 +43,7 @@ Simply add the following line to your <code>Podfile</code>:
|
||||
|
||||
### The Old School Way
|
||||
|
||||
The simpliest way to use JBChartView with your application is to drag and drop the <i>/Classes</i> folder into you're Xcode 5 project. It's also recommended you rename the <i>/Classes</i> folder to something more descriptive (ie. "<i>Jawbone - JBChartView</i>").
|
||||
The simplest way to use JBChartView with your application is to drag and drop the <i>/Classes</i> folder into you're Xcode 5 project. It's also recommended you rename the <i>/Classes</i> folder to something more descriptive (ie. "<i>Jawbone - JBChartView</i>").
|
||||
|
||||
<center>
|
||||
<img src="https://raw.github.com/Jawbone/JBChartView/master/Screenshots/installation.png">
|
||||
@@ -153,7 +153,7 @@ Lastly, ensure you have set the *frame* of your lineChartView & call *reloadData
|
||||
|
||||
## Customization
|
||||
|
||||
Both the line and bar charts support a robust set of customization options. Read more about them <a href="Customization.md">here</a>.
|
||||
Both the line and bar charts support a robust set of customization options. Read more about them <a href="Customization.md">here</a>.
|
||||
|
||||
## Minimum & Maximum Values
|
||||
|
||||
@@ -171,7 +171,7 @@ The min/max values are clamped to the ceiling and floor of the actual min/max va
|
||||
|
||||
## Performance
|
||||
|
||||
The nature of charting is to display all available information, unlike a UITableView, which can cache rows that are offscreen. JBChartView's performance will suffer if the number of data points exceed the resolution of the device. The same issue exists with MKMapVie, when hundreds of pins are supplied within a certain geographic area. It's why Apple recommends clustering to avoid performance issues. As such, for large datasets, we recommend that your dataSource to supply a subset of points - perhaps 'clustering' those that are close to one another.
|
||||
The nature of charting is to display all available information, unlike a UITableView, which can cache rows that are offscreen. JBChartView's performance will suffer if the number of data points exceed the resolution of the device. The same issue exists with MKMapView, when hundreds of pins are supplied within a certain geographic area. It's why Apple recommends clustering to avoid performance issues. As such, for large datasets, we recommend that your dataSource to supply a subset of points; clustering those that are close to one another.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user