Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d5e5c3e1d | |||
| 7e33f7121a | |||
| 09fefa292a | |||
| 47c6d744ba | |||
| fc32f8282e | |||
| 7ee84c24f0 | |||
| 12a15f1051 | |||
| 6a8f927510 | |||
| 3bf16ecae9 | |||
| 5a7b211f16 | |||
| 189c907bb9 | |||
| 6f16ae64ab |
+14
-14
@@ -20,7 +20,7 @@
|
||||
/**
|
||||
* If showsSelection is YES, a vertical highlight will overlayed on a bar during touch events.
|
||||
*
|
||||
* Default: YES
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsSelection;
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
* Height for a bar at a given index (left to right). There is no ceiling on the the height;
|
||||
* the chart will automatically normalize all values between the overal min and max heights.
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis)
|
||||
* @param barChartView The origin chart.
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis).
|
||||
*
|
||||
* @return The y-axis height of the supplied bar index (x-axis)
|
||||
*/
|
||||
@@ -47,8 +47,8 @@
|
||||
* Occurs when a touch gesture event occurs on a given bar. The chart must be expanded, showsSelection must be YES,
|
||||
* and the selection must occur within the bounds of the chart.
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis)
|
||||
* @param barChartView The origin chart.
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis).
|
||||
*/
|
||||
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSInteger)index;
|
||||
|
||||
@@ -56,8 +56,8 @@
|
||||
* Occurs when selection ends by either ending a touch event or selecting an area that is outside the view's bounds.
|
||||
* For selection start events, see: didSelectBarAtIndex...
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param index The 0-based index of a given bar. Index will be -1 if the touch ends outside of the view's bounds.
|
||||
* @param barChartView The origin chart.
|
||||
* @param index The 0-based index of a given bar. Index will be -1 if the touch ends outside of the view's bounds.
|
||||
*/
|
||||
- (void)barChartView:(JBBarChartView *)barChartView didUnselectBarAtIndex:(NSInteger)index;
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
/**
|
||||
* The number of bars in a given bar chart is the number of vertical views shown along the x-axis.
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param barChartView The origin chart.
|
||||
*
|
||||
* @return Number of bars in the given chart, displayed horizontally along the chart's x-axis.
|
||||
*/
|
||||
@@ -83,7 +83,7 @@
|
||||
*
|
||||
* Default: 'best-guess' algorithm based on the the total number of bars and width of the chart.
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param barChartView The origin chart.
|
||||
*
|
||||
* @return Horizontal width (in pixels) between each bar.
|
||||
*/
|
||||
@@ -92,10 +92,10 @@
|
||||
/**
|
||||
* A UIView subclass representing the bar at a particular index.
|
||||
*
|
||||
* Default: solid black UIView
|
||||
* Default: solid black UIView.
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis)
|
||||
* @param barChartView The origin chart.
|
||||
* @param index The 0-based index of a given bar (left to right, x-axis).
|
||||
*
|
||||
* @return A UIView subclass. The view will automatically be resized by the chart during creation (ie. no need to set the frame).
|
||||
*/
|
||||
@@ -105,9 +105,9 @@
|
||||
* The selection color to be overlayed on a bar during touch events.
|
||||
* The color is automically faded to transparent (vertically).
|
||||
*
|
||||
* Default: white color (faded to transparent)
|
||||
* Default: white color (faded to transparent).
|
||||
*
|
||||
* @param barChartView The origin chart
|
||||
* @param barChartView The origin chart.
|
||||
*
|
||||
* @return The color to be used on each bar selection.
|
||||
*/
|
||||
|
||||
@@ -62,13 +62,18 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = NO;
|
||||
self.clipsToBounds = YES;
|
||||
_showsSelection = YES;
|
||||
_cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
return [self initWithFrame:CGRectZero];
|
||||
}
|
||||
|
||||
#pragma mark - Memory Management
|
||||
|
||||
- (void)dealloc
|
||||
|
||||
@@ -34,7 +34,7 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
@property (nonatomic, strong) UIView *headerView;
|
||||
|
||||
/**
|
||||
* The vertical padding between the header and highest chart point (bar, line, etc)
|
||||
* The vertical padding between the header and highest chart point (bar, line, etc).
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat headerPadding;
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
- (void)reloadData;
|
||||
|
||||
/**
|
||||
* State setter
|
||||
* State setter.
|
||||
*
|
||||
* @param state Either collapse or expanded.
|
||||
* @param animated Whether or not the state should be animated or not.
|
||||
@@ -60,7 +60,7 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback;
|
||||
|
||||
/**
|
||||
* State setter
|
||||
* State setter.
|
||||
*
|
||||
* @param state Either collapse or expanded.
|
||||
* @param animated Whether or not the state should be animated or not.
|
||||
@@ -76,9 +76,9 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
@interface JBChartSelectionView : UIView
|
||||
|
||||
/**
|
||||
* Base selection view color. This color will be faded to transparent vertically
|
||||
* Base selection view color. This color will be faded to transparent vertically.
|
||||
*
|
||||
* Default: white color
|
||||
* Default: white color.
|
||||
*
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *bgColor;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "1.1.5"
|
||||
s.version = "1.1.6"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Terry Worona" => "tworona@jawbone.com" }
|
||||
s.source = {
|
||||
:git => "https://github.com/Jawbone/JBChartView.git",
|
||||
:tag => "v1.1.5"
|
||||
:tag => "v1.1.6"
|
||||
}
|
||||
|
||||
s.platform = :ios, '7.0'
|
||||
|
||||
+25
-14
@@ -19,7 +19,7 @@
|
||||
/**
|
||||
* If showsSelection is YES, a vertical highlight will overlayed on a the line graph during touch events.
|
||||
*
|
||||
* Default: YES
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsSelection;
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
* Vertical position for line point at a given index (left to right). There is no ceiling on the the height;
|
||||
* the chart will automatically normalize all values between the overal min and max heights.
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* @param index The 0-based index of a given line height (left to right, x-axis)
|
||||
* @param lineChartView The origin chart.
|
||||
* @param index The 0-based index of a given line height (left to right, x-axis).
|
||||
*
|
||||
* @return The y-axis value of the supplied line index (x-axis)
|
||||
* @return The y-axis value of the supplied line index (x-axis).
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index;
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
* Occurs when a touch gesture event occurs anywhere on the chart. The chart must be expanded, showsSelection must be YES,
|
||||
* and the selection must occur within the bounds of the chart.
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* @param index The 0-based index of a selection point (left to right, x-axis)
|
||||
* @param lineChartView The origin chart.
|
||||
* @param index The 0-based index of a selection point (left to right, x-axis).
|
||||
*/
|
||||
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectChartAtIndex:(NSInteger)index;
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* Occurs when selection ends by either ending a touch event or selecting an area that is outside the view's bounds.
|
||||
* For selection start events, see: didSelectChartAtIndex...
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* @param lineChartView The origin chart.
|
||||
* @param index The 0-based index of a selection point. Index will be -1 if the touch ends outside of the view's bounds.
|
||||
*/
|
||||
- (void)lineChartView:(JBLineChartView *)lineChartView didUnselectChartAtIndex:(NSInteger)index;
|
||||
@@ -69,7 +69,7 @@
|
||||
/**
|
||||
* The number of points in a given line chart equates to the number of values along the x-axis.
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* @param lineChartView The origin chart.
|
||||
*
|
||||
* @return Number of points in the given chart.
|
||||
*/
|
||||
@@ -79,22 +79,33 @@
|
||||
|
||||
/**
|
||||
* The color of the line within the chart.
|
||||
*
|
||||
* Default: black color
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* Default: black color.
|
||||
*
|
||||
* @return The color to be used to draw the line on the chart (alphas < 1 are supported)
|
||||
* @param lineChartView The origin chart.
|
||||
*
|
||||
* @return The color to be used to draw the line on the chart (alphas < 1 are supported).
|
||||
*/
|
||||
- (UIColor *)lineColorForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
/**
|
||||
* The width of the line within the chart.
|
||||
*
|
||||
* Default: 5 points.
|
||||
*
|
||||
* @param lineChartView The origin chart.
|
||||
*
|
||||
* @return The width to be used to draw the line on the chart.
|
||||
*/
|
||||
- (CGFloat)lineWidthForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
/**
|
||||
* The selection color to be overlayed on the chart during touch events.
|
||||
* The color is automically faded to transparent (vertically).
|
||||
*
|
||||
* Default: white color (faded to transparent)
|
||||
* Default: white color (faded to transparent).
|
||||
*
|
||||
* @param lineChartView The origin chart
|
||||
* @param lineChartView The origin chart.
|
||||
*
|
||||
* @return The color to be used on chart selections.
|
||||
*/
|
||||
|
||||
+64
-48
@@ -45,7 +45,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
@property (nonatomic, assign) id<JBLineChartLineViewDelegate> delegate;
|
||||
@property (nonatomic, assign) JBLineChartLineViewState state;
|
||||
@property (nonatomic, strong) CAShapeLayer *shapeLayer;
|
||||
@property (nonatomic, assign) BOOL aniamted;
|
||||
@property (nonatomic, assign) BOOL animated;
|
||||
|
||||
// Data
|
||||
- (void)reloadData;
|
||||
@@ -63,6 +63,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
|
||||
- (NSArray *)chartDataForLineChartLineView:(JBLineChartLineView*)lineChartLineView;
|
||||
- (UIColor *)lineColorForLineChartLineView:(JBLineChartLineView*)lineChartLineView;
|
||||
- (CGFloat)lineWidthForLineChartLineView:(JBLineChartLineView*)lineChartLineView;
|
||||
|
||||
@end
|
||||
|
||||
@@ -114,28 +115,33 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
return [self initWithFrame:CGRectZero];
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
- (void)reloadData
|
||||
{
|
||||
// reset cached max height
|
||||
self.cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
|
||||
|
||||
|
||||
/*
|
||||
* Subview rectangle calculations
|
||||
*/
|
||||
CGRect mainViewRect = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, [self availableHeight]);
|
||||
|
||||
|
||||
/*
|
||||
* The data collection holds all position and marker information:
|
||||
* constructed via datasource and delegate functions
|
||||
*/
|
||||
dispatch_block_t createChartData = ^{
|
||||
|
||||
|
||||
CGFloat pointSpace = (self.bounds.size.width - (kJBLineChartLineViewEdgePadding * 2)) / ([self dataCount] - 1); // Space in between points
|
||||
CGFloat xOffset = kJBLineChartLineViewEdgePadding;
|
||||
CGFloat yOffset = 0;
|
||||
|
||||
|
||||
// Build up the data collection
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:heightForIndex:)], @"JBLineChartView // delegate must implement - (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index");
|
||||
NSMutableArray *mutableChartData = [NSMutableArray array];
|
||||
@@ -145,34 +151,34 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
CGFloat rawHeight = [self.delegate lineChartView:self heightForIndex:index];
|
||||
CGFloat normalizedHeight = [self normalizedHeightForRawHeight:rawHeight];
|
||||
yOffset = mainViewRect.size.height - normalizedHeight;
|
||||
|
||||
|
||||
chartPoint.position = CGPointMake(xOffset, yOffset);
|
||||
|
||||
|
||||
[mutableChartData addObject:chartPoint];
|
||||
xOffset += pointSpace;
|
||||
}
|
||||
|
||||
|
||||
self.chartData = [NSArray arrayWithArray:mutableChartData];
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Creates a new line graph view using the previously calculated data model
|
||||
*/
|
||||
dispatch_block_t createLineGraphView = ^{
|
||||
|
||||
|
||||
// Remove old line and overlay views
|
||||
if (self.lineView)
|
||||
{
|
||||
[self.lineView removeFromSuperview];
|
||||
self.lineView = nil;
|
||||
}
|
||||
|
||||
|
||||
// Create new line and overlay subviews
|
||||
self.lineView = [[JBLineChartLineView alloc] initWithFrame:CGRectOffset(mainViewRect, 0, self.headerView.frame.size.height + self.headerPadding)];
|
||||
self.lineView.delegate = self;
|
||||
[self addSubview:self.lineView];
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Creates a vertical selection view for touch events
|
||||
*/
|
||||
@@ -182,7 +188,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
[self.selectionView removeFromSuperview];
|
||||
self.selectionView = nil;
|
||||
}
|
||||
|
||||
|
||||
self.selectionView = [[JBChartSelectionView alloc] initWithFrame:CGRectMake(0, 0, kJBLineSelectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
|
||||
self.selectionView.alpha = 0.0;
|
||||
if ([self.dataSource respondsToSelector:@selector(selectionColorForLineChartView:)])
|
||||
@@ -191,14 +197,14 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
}
|
||||
[self insertSubview:self.selectionView belowSubview:self.footerView];
|
||||
};
|
||||
|
||||
|
||||
createChartData();
|
||||
createLineGraphView();
|
||||
createSelectionView();
|
||||
|
||||
|
||||
// Reload views
|
||||
[self.lineView reloadData];
|
||||
|
||||
|
||||
// Position header and footer
|
||||
self.headerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.headerView.frame.size.height);
|
||||
self.footerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.size.height - self.footerView.frame.size.height, self.bounds.size.width, self.footerView.frame.size.height);
|
||||
@@ -210,12 +216,12 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
CGFloat minHeight = [self minHeight];
|
||||
CGFloat maxHeight = [self maxHeight];
|
||||
|
||||
|
||||
if ((maxHeight - minHeight) <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return ((rawHeight - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
|
||||
}
|
||||
|
||||
@@ -269,12 +275,21 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
return kJBLineChartViewDefaultLineColor;
|
||||
}
|
||||
|
||||
- (CGFloat)lineWidthForLineChartLineView:(JBLineChartLineView*)lineChartLineView
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineWidthForLineChartView:)])
|
||||
{
|
||||
return [self.dataSource lineWidthForLineChartView:self];
|
||||
}
|
||||
return kJBLineChartLineViewStrokeWidth;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
[super setState:state animated:animated callback:callback];
|
||||
|
||||
|
||||
if (state == JBChartViewStateCollapsed)
|
||||
{
|
||||
[self.lineView setState:JBLineChartLineViewStateCollapsed animated:animated callback:callback];
|
||||
@@ -310,9 +325,9 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
[self setSelectionViewVisible:NO animated:YES];
|
||||
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
NSInteger index = [self indexForPoint:touchPoint];
|
||||
@@ -327,7 +342,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
- (void)setSelectionViewVisible:(BOOL)selectionViewVisible animated:(BOOL)animated
|
||||
{
|
||||
_selectionViewVisible = selectionViewVisible;
|
||||
|
||||
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
@@ -353,15 +368,15 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectChartAtIndex:)])
|
||||
{
|
||||
[self.delegate lineChartView:self didSelectChartAtIndex:[self indexForPoint:touchPoint]];
|
||||
}
|
||||
|
||||
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.selectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.selectionView.frame.size.width * 0.5))));
|
||||
self.selectionView.frame = CGRectMake(xOffset, self.selectionView.frame.origin.y, self.selectionView.frame.size.width, self.selectionView.frame.size.height);
|
||||
[self setSelectionViewVisible:YES animated:YES];
|
||||
@@ -373,15 +388,15 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectChartAtIndex:)])
|
||||
{
|
||||
[self.delegate lineChartView:self didSelectChartAtIndex:[self indexForPoint:touchPoint]];
|
||||
}
|
||||
|
||||
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.selectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.selectionView.frame.size.width * 0.5))));
|
||||
self.selectionView.frame = CGRectMake(xOffset, self.selectionView.frame.origin.y, self.selectionView.frame.size.width, self.selectionView.frame.size.height);
|
||||
[self setSelectionViewVisible:YES animated:YES];
|
||||
@@ -426,15 +441,15 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
|
||||
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
|
||||
UIBezierPath *flatPath = [UIBezierPath bezierPath];
|
||||
flatPath.miterLimit = kJBLineChartLineViewMiterLimit;
|
||||
|
||||
|
||||
UIBezierPath *dynamicPath = [UIBezierPath bezierPath];
|
||||
dynamicPath.miterLimit = kJBLineChartLineViewMiterLimit;
|
||||
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartLineView:)], @"JBLineChartLineView // delegate must implement - (NSArray *)chartDataForLineChartLineView:(JBLineChartLineView *)lineChartLineView");
|
||||
NSInteger index = 0;
|
||||
for (JBLineChartPoint *lineChartPoint in [[self.delegate chartDataForLineChartLineView:self] sortedArrayUsingSelector:@selector(compare:)])
|
||||
@@ -449,27 +464,28 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
[dynamicPath addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLineViewEdgePadding, fmax(kJBLineChartLineViewEdgePadding, lineChartPoint.position.y)))];
|
||||
[flatPath addLineToPoint:CGPointMake(lineChartPoint.position.x, ceil(self.bounds.size.height * 0.5))];
|
||||
}
|
||||
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineColorForLineChartLineView:)], @"JBLineChartLineView // delegate must implement - (UIColor *)lineColorForLineChartLineView:(JBLineChartLineView*)lineChartLineView");
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineWidthForLineChartLineView:)], @"JBLineChartLineView // delegate must implement - (UIColor *)lineWidthForLineChartLineView:(JBLineChartLineView*)lineChartLineView");
|
||||
|
||||
if (self.shapeLayer == nil)
|
||||
{
|
||||
self.shapeLayer = [CAShapeLayer layer];
|
||||
}
|
||||
|
||||
if (self.aniamted)
|
||||
|
||||
if (self.animated)
|
||||
{
|
||||
self.shapeLayer.zPosition = 0.0f;
|
||||
self.shapeLayer.strokeColor = [self.delegate lineColorForLineChartLineView:self].CGColor;
|
||||
self.shapeLayer.lineWidth = kJBLineChartLineViewStrokeWidth;
|
||||
self.shapeLayer.lineWidth = [self.delegate lineWidthForLineChartLineView:self];
|
||||
self.shapeLayer.lineCap = kCALineCapRound;
|
||||
self.shapeLayer.lineJoin = kCALineJoinRound;
|
||||
self.shapeLayer.frame = self.bounds;
|
||||
self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
|
||||
|
||||
|
||||
if (self.state == JBLineChartLineViewStateCollapsed)
|
||||
{
|
||||
self.shapeLayer.path = dynamicPath.CGPath;
|
||||
@@ -478,7 +494,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
self.shapeLayer.path = flatPath.CGPath;
|
||||
}
|
||||
|
||||
|
||||
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];
|
||||
[anim setRemovedOnCompletion:NO];
|
||||
anim.toValue = self.state == JBLineChartLineViewStateCollapsed ? (id)flatPath.CGPath : (id)dynamicPath.CGPath;
|
||||
@@ -494,7 +510,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
CGContextSaveGState(context);
|
||||
{
|
||||
CGContextSetLineWidth(context, kJBLineChartLineViewStrokeWidth);
|
||||
CGContextSetLineWidth(context, [self.delegate lineWidthForLineChartLineView:self]);
|
||||
CGContextSetStrokeColorWithColor(context, [self.delegate lineColorForLineChartLineView:self].CGColor);
|
||||
CGContextSetLineCap(context, kCGLineCapRound);
|
||||
CGContextSetLineJoin(context, kCGLineJoinRound);
|
||||
@@ -504,8 +520,8 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
}
|
||||
CGContextRestoreGState(context);
|
||||
}
|
||||
|
||||
self.aniamted = NO;
|
||||
|
||||
self.animated = NO;
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
@@ -524,13 +540,13 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dispatch_block_t callbackCopy = [callback copy];
|
||||
|
||||
|
||||
_state = state;
|
||||
self.aniamted = animated;
|
||||
self.animated = animated;
|
||||
[self setNeedsDisplay];
|
||||
|
||||
|
||||
if (animated)
|
||||
{
|
||||
[self performSelector:@selector(fireCallback:) withObject:callback afterDelay:kJBLineChartLineViewStateAnimationDuration];
|
||||
@@ -554,7 +570,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
- (void)fireCallback:(void (^)())callback
|
||||
{
|
||||
dispatch_block_t callbackCopy = [callback copy];
|
||||
|
||||
|
||||
if (callbackCopy != nil)
|
||||
{
|
||||
callbackCopy();
|
||||
|
||||
@@ -79,7 +79,8 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
|
||||
self.view.backgroundColor = kJBColorBarChartControllerBackground;
|
||||
self.navigationItem.rightBarButtonItem = [self chartToggleButtonWithTarget:self action:@selector(chartToggleButtonPressed:)];
|
||||
|
||||
self.barChartView = [[JBBarChartView alloc] initWithFrame:CGRectMake(kJBNumericDefaultPadding, kJBNumericDefaultPadding, self.view.bounds.size.width - (kJBNumericDefaultPadding * 2), kJBBarChartViewControllerChartHeight)];
|
||||
self.barChartView = [[JBBarChartView alloc] init];
|
||||
self.barChartView.frame = CGRectMake(kJBNumericDefaultPadding, kJBNumericDefaultPadding, self.view.bounds.size.width - (kJBNumericDefaultPadding * 2), kJBBarChartViewControllerChartHeight);
|
||||
self.barChartView.delegate = self;
|
||||
self.barChartView.dataSource = self;
|
||||
self.barChartView.headerPadding = kJBBarChartViewControllerChartHeaderPadding;
|
||||
|
||||
@@ -21,6 +21,7 @@ CGFloat const kJBLineChartViewControllerChartHeight = 250.0f;
|
||||
CGFloat const kJBLineChartViewControllerChartHeaderHeight = 75.0f;
|
||||
CGFloat const kJBLineChartViewControllerChartHeaderPadding = 20.0f;
|
||||
CGFloat const kJBLineChartViewControllerChartFooterHeight = 20.0f;
|
||||
CGFloat const kJBLineChartViewControllerChartLineWidth = 6.0f;
|
||||
NSInteger const kJBLineChartViewControllerNumChartPoints = 27;
|
||||
|
||||
// Strings
|
||||
@@ -75,7 +76,8 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
self.view.backgroundColor = kJBColorLineChartControllerBackground;
|
||||
self.navigationItem.rightBarButtonItem = [self chartToggleButtonWithTarget:self action:@selector(chartToggleButtonPressed:)];
|
||||
|
||||
self.lineChartView = [[JBLineChartView alloc] initWithFrame:CGRectMake(kJBNumericDefaultPadding, kJBNumericDefaultPadding, self.view.bounds.size.width - (kJBNumericDefaultPadding * 2), kJBLineChartViewControllerChartHeight)];
|
||||
self.lineChartView = [[JBLineChartView alloc] init];
|
||||
self.lineChartView.frame = CGRectMake(kJBNumericDefaultPadding, kJBNumericDefaultPadding, self.view.bounds.size.width - (kJBNumericDefaultPadding * 2), kJBLineChartViewControllerChartHeight);
|
||||
self.lineChartView.delegate = self;
|
||||
self.lineChartView.dataSource = self;
|
||||
self.lineChartView.headerPadding = kJBLineChartViewControllerChartHeaderPadding;
|
||||
@@ -158,6 +160,11 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return kJBColorLineChartLineColor;
|
||||
}
|
||||
|
||||
- (CGFloat)lineWidthForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return kJBLineChartViewControllerChartLineWidth;
|
||||
}
|
||||
|
||||
- (UIColor *)selectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
|
||||
@@ -36,7 +36,7 @@ Simply add the following line to your <code>Podfile</code>:
|
||||
Your Podfile should look something like:
|
||||
|
||||
platform :ios, '7.0'
|
||||
pod 'JBChartView', '~> 1.1.5'
|
||||
pod 'JBChartView', '~> 1.1.6'
|
||||
|
||||
### The Old School Way
|
||||
|
||||
@@ -93,7 +93,7 @@ Secondly, you need to inform the delegate the y-position of each point (automati
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index
|
||||
{
|
||||
return ...; // y-position of poinnt at index (x-axis)
|
||||
return ...; // y-position of point at index (x-axis)
|
||||
}
|
||||
|
||||
## Customization
|
||||
@@ -159,6 +159,12 @@ Furthermore, the color of the selection bar (on touch events) can be customized
|
||||
{
|
||||
return ...; // color of selection view
|
||||
}
|
||||
The width of the chart's line is defaulted to 5 (points). It can be modified through the <i>optional</i> protocol:
|
||||
|
||||
- (CGFloat)lineWidthForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return ...; // width of line
|
||||
}
|
||||
|
||||
Lastly, a line chart's selection events are delegated back via:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user