Compare commits

...

34 Commits

Author SHA1 Message Date
Terry Worona 3d5e5c3e1d Updated podspect 2014-03-02 17:24:33 -08:00
Terry Worona 7e33f7121a Updated read me 2014-03-02 17:23:53 -08:00
Terry Worona 09fefa292a Added assert check for line width and added hookups to demo project 2014-03-02 17:16:51 -08:00
Terry Worona 47c6d744ba added periods to comments 2014-03-02 17:14:49 -08:00
Terry Worona fc32f8282e Moved pod spec back into /Classes 2014-03-02 17:10:31 -08:00
terryworona 7ee84c24f0 Merge pull request #15 from kmcbride/line-customization
Added customization for line width
2014-03-02 17:06:44 -08:00
Terry Worona 12a15f1051 Added default init for bar and line charts. 2014-03-02 16:49:03 -08:00
Kylan McBride 6a8f927510 Moved podspec location 2014-02-14 22:36:25 -08:00
Kylan McBride 3bf16ecae9 Added line width customization 2014-02-14 22:34:23 -08:00
Kylan McBride 5a7b211f16 Fixed Typo and excess whitespace 2014-02-14 22:32:44 -08:00
terryworona 189c907bb9 Merge pull request #14 from Undo1/patch-1
fix spelling mistake
2014-02-14 09:38:35 -08:00
Undo1 6f16ae64ab fix spelling mistake 2014-02-13 20:06:11 -07:00
Terry Worona b911dfa9e2 Updated version 2014-02-11 16:47:54 -08:00
Terry Worona 2335a371b6 Fixed selection view cancelled bug 2014-02-07 10:23:48 -08:00
Terry Worona b41d7ad944 Don't clip bar chart views 2014-02-07 09:52:57 -08:00
Terry Worona 4ffb2e1e0c Fixed minor bar chart animation bugs 2014-02-07 09:39:56 -08:00
Terry Worona 9ae2adb81c Updated version and read me 2014-02-06 10:58:29 -08:00
Terry Worona 185782daab Fixed compilation warnings 2014-02-06 10:48:28 -08:00
Terry Worona 51acae13a1 updated read me and pod spec 2014-01-06 13:25:55 -08:00
Terry Worona 03217243d9 Fixed float bugs 2014-01-06 12:23:21 -08:00
Terry Worona 072e45902d Removed unused cached height 2014-01-06 12:08:30 -08:00
Terry Worona 326037ce93 Added precision to line and bar charts & fixed cached height bug 2014-01-06 12:06:19 -08:00
terryworona f447549666 Merge pull request #11 from sampage/patch-1
Fixes small typos in README
2014-01-06 10:39:48 -08:00
Sam Page eba1d39ba3 Fixes small typos in README
"initialze" -> "initialize"
2014-01-06 15:51:15 +11:00
Terry Worona 8d28b65add Updated pod spec to latest version 2014-01-03 10:57:33 -08:00
Terry Worona e72a54356e Updated datasource to require CGFloats for heights instead of Integers. ss 2014-01-03 10:54:28 -08:00
Terry Worona 86440913ba Updated read me and pod spec 2014-01-02 10:20:51 -08:00
Terry Worona c1ac9e4a2f Remove ivar access except for designated functions 2014-01-02 10:02:47 -08:00
terryworona 6f185f9e53 Merge pull request #8 from l4u/cache
Reset cached max height on data reload Fixes #7
2014-01-02 10:00:55 -08:00
Leo Lou d142629dd3 Reset cached max height on data reload Fixes #7 2014-01-02 18:33:45 +08:00
Terry Worona 84d9c0f5da updated pod spec and read me 2013-12-26 10:00:12 -05:00
Terry Worona 5f400d3c91 Updated datasource to request bar view instead of color 2013-12-25 17:25:58 -05:00
Terry Worona 409b58c53c updated pod spec and read me 2013-12-23 18:02:30 -05:00
Terry Worona 0b6108dea8 resolved #4 | removed bar shadow from bar chart subviews 2013-12-23 17:50:20 -05:00
9 changed files with 255 additions and 173 deletions
+18 -18
View File
@@ -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,12 +34,12 @@
* 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)
*/
- (NSInteger)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index;
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index;
@optional
@@ -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,31 +83,31 @@
*
* 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.
*/
- (NSInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
/**
* The color of all bars within the chart.
* A UIView subclass representing the bar at a particular index.
*
* Default: black color
* 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 The color to be used on each of the bars within the chart.
* @return A UIView subclass. The view will automatically be resized by the chart during creation (ie. no need to set the frame).
*/
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index;
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index;
/**
* 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.
*/
+58 -37
View File
@@ -9,11 +9,11 @@
#import "JBBarChartView.h"
// Numerics
CGFloat const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
CGFloat const kJBBarChartViewUndefinedMaxHeight = -1.0f;
CGFloat const kJBBarChartViewStateAnimationDuration = 0.05f;
CGFloat const kJBBarChartViewPopOffset = 10.0f; // used to offset bars for 'pop' animations
NSInteger const kJBBarChartViewUndefinedBarIndex = -1;
CGFloat static const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
CGFloat static const kJBBarChartViewUndefinedMaxHeight = -1.0f;
CGFloat static const kJBBarChartViewStateAnimationDuration = 0.05f;
CGFloat static const kJBBarChartViewPopOffset = 10.0f; // used to offset bars for 'pop' animations
NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
// Colors (JBChartView)
static UIColor *kJBBarChartViewDefaultBarColor = nil;
@@ -33,10 +33,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (CGFloat)maxHeight;
- (CGFloat)minHeight;
- (CGFloat)barWidth;
- (CGFloat)popOffset;
// Touch helpers
- (NSInteger)barViewIndexForPoint:(CGPoint)point;
- (UIView *)barViewForForPoint:(CGPoint)point;
- (void)touchesEndedOrCancelledWithTouches:(NSSet *)touches;
// Setters
- (void)setSelectionViewVisible:(BOOL)selectionViewVisible animated:(BOOL)animated;
@@ -67,6 +69,11 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return self;
}
- (id)init
{
return [self initWithFrame:CGRectZero];
}
#pragma mark - Memory Management
- (void)dealloc
@@ -78,6 +85,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
/*
* The data collection holds all position information:
* constructed via datasource and delegate functions
@@ -93,7 +103,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
NSMutableDictionary *dataDictionary = [NSMutableDictionary dictionary];
for (NSInteger index=0; index<dataCount; index++)
{
[dataDictionary setObject:[NSNumber numberWithInt:(int)[self.delegate barChartView:self heightForBarViewAtAtIndex:index]] forKey:[NSNumber numberWithInt:(int)index]];
[dataDictionary setObject:[NSNumber numberWithFloat:[self.delegate barChartView:self heightForBarViewAtAtIndex:index]] forKey:[NSNumber numberWithInt:(int)index]];
}
self.chartDataDictionary = [NSDictionary dictionaryWithDictionary:dataDictionary];
};
@@ -112,7 +122,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
self.barPadding = (1/(float)totalBars) * kJBBarChartViewBarBasePaddingMutliplier;
}
};
/*
* Creates a new bar graph view using the previously calculated data model
*/
@@ -129,23 +139,19 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
NSMutableArray *mutableBarViews = [NSMutableArray array];
for (NSNumber *key in [[self.chartDataDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)])
{
UIView *barView = [[UIView alloc] init];
if ([self.dataSource respondsToSelector:@selector(barColorForBarChartView:atIndex:)])
UIView *barView = nil; // since all bars are visible at once, no need to cache this view
if ([self.dataSource respondsToSelector:@selector(barViewForBarChartView:atIndex:)])
{
barView.backgroundColor = [self.dataSource barColorForBarChartView:self atIndex:index];
barView = [self.dataSource barViewForBarChartView:self atIndex:index];
}
else
{
barView = [[UIView alloc] init];
barView.backgroundColor = kJBBarChartViewDefaultBarColor;
}
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height + self.headerPadding, [self barWidth], height + kJBBarChartViewPopOffset - self.headerPadding);
barView.layer.shadowColor = [UIColor blackColor].CGColor;
barView.layer.shadowOffset = CGSizeMake(0, 0);
barView.layer.shadowOpacity = 0.4;
barView.layer.shadowRadius = 1.0;
CGFloat extensionHeight = height > 0.0 ? kJBBarChartViewPopOffset : 0.0;
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height + self.headerPadding, [self barWidth], height + extensionHeight - self.headerPadding);
[mutableBarViews addObject:barView];
// Add new bar
@@ -176,7 +182,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
self.selectionView = nil;
}
self.selectionView = [[JBChartSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height)];
self.selectionView = [[JBChartSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height - self.footerView.frame.size.height)];
self.selectionView.alpha = 0.0;
if ([self.dataSource respondsToSelector:@selector(selectionBarColorForBarChartView:)])
{
@@ -199,7 +205,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
createBars();
createSelectionView();
// Position header and footer
// 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);
}
@@ -222,7 +228,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return 0;
}
return ceil(((value - minHeight) / (maxHeight - minHeight)) * [self availableHeight]);
return ((value - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
}
- (CGFloat)maxHeight
@@ -253,6 +259,11 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return 0;
}
- (CGFloat)popOffset
{
return self.bounds.size.height - self.footerView.frame.size.height;
}
#pragma mark - Setters
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
@@ -263,9 +274,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
if (animated)
{
CGFloat popOffset = self.bounds.size.height - self.footerView.frame.size.height;
CGFloat popOffset = [self popOffset];
NSInteger index = 0;
NSUInteger index = 0;
for (UIView *barView in self.barViews)
{
[UIView animateWithDuration:kJBBarChartViewStateAnimationDuration delay:(kJBBarChartViewStateAnimationDuration * 0.5) * index options:UIViewAnimationOptionBeginFromCurrentState animations:^{
@@ -280,7 +291,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
}
} completion:^(BOOL finished) {
} completion:^(BOOL lastBarFinished) {
if (index == [self.barViews count] - 1)
{
if (callbackCopy)
@@ -351,6 +362,23 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return barView;
}
- (void)touchesEndedOrCancelledWithTouches:(NSSet *)touches
{
if (!self.showsSelection || self.state == JBChartViewStateCollapsed)
{
return;
}
[self setSelectionViewVisible:NO animated:YES];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSInteger index = [self barViewIndexForPoint:touchPoint];
if ([self.delegate respondsToSelector:@selector(barChartView:didUnselectBarAtIndex:)])
{
[self.delegate barChartView:self didUnselectBarAtIndex:index];
}
}
#pragma mark - Setters
- (void)setSelectionViewVisible:(BOOL)selectionViewVisible animated:(BOOL)animated
@@ -360,7 +388,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
if (animated)
{
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.selectionView.alpha = _selectionViewVisible ? 1.0 : 0.0;
self.selectionView.alpha = self.selectionViewVisible ? 1.0 : 0.0;
} completion:nil];
}
else
@@ -430,19 +458,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.showsSelection || self.state == JBChartViewStateCollapsed)
{
return;
}
[self setSelectionViewVisible:NO animated:YES];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSInteger index = [self barViewIndexForPoint:touchPoint];
if ([self.delegate respondsToSelector:@selector(barChartView:didUnselectBarAtIndex:)])
{
[self.delegate barChartView:self didUnselectBarAtIndex:index];
}
[self touchesEndedOrCancelledWithTouches:touches];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEndedOrCancelledWithTouches:touches];
}
@end
+5 -5
View File
@@ -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;
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "1.0.2"
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.0.2"
:tag => "v1.1.6"
}
s.platform = :ios, '7.0'
+27 -16
View File
@@ -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,12 +33,12 @@
* 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).
*/
- (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index;
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index;
@optional
@@ -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,8 +55,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: didSelectChartAtIndex...
*
* @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.
* @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.
*/
+105 -72
View File
@@ -18,16 +18,16 @@ typedef NS_ENUM(NSInteger, JBLineChartLineViewState){
};
// Numerics (JBLineChartLineView)
CGFloat const kJBLineChartLineViewEdgePadding = 10.0;
CGFloat const kJBLineChartLineViewStrokeWidth = 5.0;
CGFloat const kJBLineChartLineViewMiterLimit = -5.0;
CGFloat const kJBLineChartLineViewStateAnimationDuration = 0.25f;
CGFloat static const kJBLineChartLineViewEdgePadding = 10.0;
CGFloat static const kJBLineChartLineViewStrokeWidth = 5.0;
CGFloat static const kJBLineChartLineViewMiterLimit = -5.0;
CGFloat static const kJBLineChartLineViewStateAnimationDuration = 0.25f;
// Numerics (JBLineSelectionView)
CGFloat const kJBLineSelectionViewWidth = 20.0f;
CGFloat static const kJBLineSelectionViewWidth = 20.0f;
// Numerics (JBLineChartView)
CGFloat const kJBLineChartViewUndefinedMaxHeight = -1.0f;
CGFloat static const kJBLineChartViewUndefinedMaxHeight = -1.0f;
// Colors (JBLineChartView)
static UIColor *kJBLineChartViewDefaultLineColor = nil;
@@ -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
@@ -75,7 +76,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
@property (nonatomic, assign) BOOL selectionViewVisible;
// View quick accessors
- (CGFloat)normalizedHeightForRawHeight:(NSInteger)rawHeight;
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight;
- (CGFloat)availableHeight;
- (CGFloat)maxHeight;
- (CGFloat)minHeight;
@@ -83,6 +84,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
// Touch helpers
- (NSInteger)indexForPoint:(CGPoint)point;
- (void)touchesEndedOrCancelledWithTouches:(NSSet *)touches;
// Setters
- (void)setSelectionViewVisible:(BOOL)selectionViewVisible animated:(BOOL)animated;
@@ -106,17 +108,25 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
self = [super initWithFrame:frame];
if (self)
{
self.clipsToBounds = NO;
self.clipsToBounds = NO;
_showsSelection = YES;
_cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
}
return self;
}
- (id)init
{
return [self initWithFrame:CGRectZero];
}
#pragma mark - Data
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
/*
* Subview rectangle calculations
*/
@@ -127,7 +137,7 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
* 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;
@@ -138,38 +148,37 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
for (NSInteger index=0; index<[self dataCount]; index++)
{
JBLineChartPoint *chartPoint = [[JBLineChartPoint alloc] init];
NSInteger rawHeight = [self.delegate lineChartView:self heightForIndex:index];
CGFloat rawHeight = [self.delegate lineChartView:self heightForIndex:index];
CGFloat normalizedHeight = [self normalizedHeightForRawHeight:rawHeight];
yOffset = mainViewRect.size.height - normalizedHeight;
//yOffset = mainViewRect.size.height - yOffset;
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
*/
@@ -179,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:)])
@@ -188,11 +197,11 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
}
[self insertSubview:self.selectionView belowSubview:self.footerView];
};
createChartData();
createLineGraphView();
createSelectionView();
// Reload views
[self.lineView reloadData];
@@ -203,17 +212,17 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
#pragma mark - View Quick Accessors
- (CGFloat)normalizedHeightForRawHeight:(NSInteger)rawHeight
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight
{
CGFloat minHeight = [self minHeight];
CGFloat maxHeight = [self maxHeight];
if ((maxHeight - minHeight) <= 0)
{
return 0;
}
return ceil(((rawHeight - minHeight) / (maxHeight - minHeight)) * [self availableHeight]);
return ((rawHeight - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
}
- (CGFloat)availableHeight
@@ -223,16 +232,20 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
- (CGFloat)maxHeight
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:heightForIndex:)], @"JBLineChartView // delegate must implement - (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index");
NSInteger maxHeight = 0;
for (NSInteger index=0; index<[self dataCount]; index++)
if (self.cachedMaxHeight == kJBLineChartViewUndefinedMaxHeight)
{
if (([self.delegate lineChartView:self heightForIndex:index]) > maxHeight)
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:heightForIndex:)], @"JBLineChartView // delegate must implement - (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index");
CGFloat maxHeight = 0;
for (NSInteger index=0; index<[self dataCount]; index++)
{
maxHeight = [self.delegate lineChartView:self heightForIndex:index];
if (([self.delegate lineChartView:self heightForIndex:index]) > maxHeight)
{
maxHeight = [self.delegate lineChartView:self heightForIndex:index];
}
}
self.cachedMaxHeight = maxHeight;
}
return maxHeight;
return self.cachedMaxHeight;
}
- (CGFloat)minHeight
@@ -262,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];
@@ -297,16 +319,34 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
return selectedIndex;
}
- (void)touchesEndedOrCancelledWithTouches:(NSSet *)touches
{
if (!self.showsSelection || self.state == JBChartViewStateCollapsed)
{
return;
}
[self setSelectionViewVisible:NO animated:YES];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSInteger index = [self indexForPoint:touchPoint];
if ([self.delegate respondsToSelector:@selector(lineChartView:didUnselectChartAtIndex:)])
{
[self.delegate lineChartView:self didUnselectChartAtIndex:index];
}
}
#pragma mark - Setters
- (void)setSelectionViewVisible:(BOOL)selectionViewVisible animated:(BOOL)animated
{
_selectionViewVisible = selectionViewVisible;
if (animated)
{
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.selectionView.alpha = _selectionViewVisible ? 1.0 : 0.0;
self.selectionView.alpha = self.selectionViewVisible ? 1.0 : 0.0;
} completion:nil];
}
else
@@ -328,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];
@@ -348,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];
@@ -364,20 +404,12 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.showsSelection || self.state == JBChartViewStateCollapsed)
{
return;
}
[self setSelectionViewVisible:NO animated:YES];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSInteger index = [self indexForPoint:touchPoint];
if ([self.delegate respondsToSelector:@selector(lineChartView:didUnselectChartAtIndex:)])
{
[self.delegate lineChartView:self didUnselectChartAtIndex:index];
}
[self touchesEndedOrCancelledWithTouches:touches];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEndedOrCancelledWithTouches:touches];
}
@end
@@ -409,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:)])
@@ -432,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;
@@ -461,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;
@@ -477,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);
@@ -487,8 +520,8 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
}
CGContextRestoreGState(context);
}
self.aniamted = NO;
self.animated = NO;
}
#pragma mark - Data
@@ -507,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];
@@ -65,7 +65,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
NSMutableArray *mutableChartData = [NSMutableArray array];
for (int i=0; i<kJBBarChartViewControllerNumBars; i++)
{
[mutableChartData addObject:[NSNumber numberWithInteger:MAX(kJBBarChartViewControllerMinBarHeight, arc4random() % kJBBarChartViewControllerMaxBarHeight)]]; // fake height
[mutableChartData addObject:[NSNumber numberWithFloat:MAX(kJBBarChartViewControllerMinBarHeight, arc4random() % kJBBarChartViewControllerMaxBarHeight)]]; // fake height
}
_chartData = [NSArray arrayWithArray:mutableChartData];
}
@@ -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;
@@ -120,9 +121,9 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
#pragma mark - JBBarChartViewDelegate
- (NSInteger)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
{
return [[self.chartData objectAtIndex:index] intValue];
return [[self.chartData objectAtIndex:index] floatValue];
}
#pragma mark - JBBarChartViewDataSource
@@ -137,9 +138,11 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
return kJBBarChartViewControllerBarPadding;
}
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
{
return (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
UIView *barView = [[UIView alloc] init];
barView.backgroundColor = (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
return barView;
}
- (UIColor *)selectionBarColorForBarChartView:(JBBarChartView *)barChartView
@@ -14,13 +14,15 @@
#import "JBLineChartFooterView.h"
#import "JBChartInformationView.h"
#define ARC4RANDOM_MAX 0x100000000
// Numerics
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;
NSInteger const kJBLineChartViewControllerMaxPointValue = 100; // max random value
// Strings
NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
@@ -60,7 +62,7 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
NSMutableArray *mutableChartData = [NSMutableArray array];
for (int i=0; i<kJBLineChartViewControllerNumChartPoints; i++)
{
[mutableChartData addObject:[NSNumber numberWithInteger:arc4random() % kJBLineChartViewControllerMaxPointValue]];
[mutableChartData addObject:[NSNumber numberWithFloat:((double)arc4random() / ARC4RANDOM_MAX)]]; // random number between 0 and 1
}
_chartData = [NSArray arrayWithArray:mutableChartData];
}
@@ -74,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;
@@ -127,15 +130,15 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
#pragma mark - JBLineChartViewDelegate
- (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index
{
return [[self.chartData objectAtIndex:index] intValue];
return [[self.chartData objectAtIndex:index] floatValue];
}
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectChartAtIndex:(NSInteger)index
{
NSNumber *valueNumber = [self.chartData objectAtIndex:index];
[self.informationView setValueText:[NSString stringWithFormat:@"%d", [valueNumber intValue]] unitText:kJBStringLabelMm];
[self.informationView setValueText:[NSString stringWithFormat:@"%.2f", [valueNumber floatValue]] unitText:kJBStringLabelMm];
[self.informationView setTitleText:[NSString stringWithFormat:@"%d", [kJBStringLabel1987 intValue] + (int)index]];
[self.informationView setHidden:NO animated:YES];
}
@@ -157,6 +160,11 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
return kJBColorLineChartLineColor;
}
- (CGFloat)lineWidthForLineChartView:(JBLineChartView *)lineChartView
{
return kJBLineChartViewControllerChartLineWidth;
}
- (UIColor *)selectionColorForLineChartView:(JBLineChartView *)lineChartView
{
return [UIColor whiteColor];
+17 -11
View File
@@ -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.0.2'
pod 'JBChartView', '~> 1.1.6'
### The Old School Way
@@ -52,7 +52,7 @@ Both JBChartView implementations have a similiar data source and delgate pattern
#### JBBarChartView
To initialze a <i>JBBarChartView</i>, you only need a few lines of code:
To initialize a <i>JBBarChartView</i>, you only need a few lines of code:
JBBarChartView *barChartView = [[JBBarChartView alloc] init];
barChartView.delegate = self;
@@ -66,16 +66,16 @@ At a minimum, you need to inform the data source how many bars are in the chart:
return ...; // number of bars in chart
}
Secondly, you nee to inform the delegate the height of each bar (automatically normalized across the entire chart):
Secondly, you need to inform the delegate the height of each bar (automatically normalized across the entire chart):
- (NSInteger)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
{
return ...; // height of bar at index
}
#### JBLineChartView
Similiarily, to initialze a JBLineChartView, you only need a few lines of code:
Similiarily, to initialize a JBLineChartView, you only need a few lines of code:
JBLineChartView *lineChartView = [[JBLineChartView alloc] init];
lineChartView.delegate = self;
@@ -89,11 +89,11 @@ At a minimum, you need to inform the data source how many points are in the line
return ...; // number of points in chart
}
Secondly, you nee to inform the delegate the y-position of each point (automatically normalized across the entire chart):
Secondly, you need to inform the delegate the y-position of each point (automatically normalized across the entire chart):
- (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index
- (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
@@ -116,9 +116,9 @@ Lastly, any JBChartView subclass can be collapsed or expanded programmatically v
#### JBBarChartView
The color of a chart's bar can be customized via the <i>optional</i> protocol:
By default, a chart's bars will be black and flat. They can be customized by supplying a UIView subclass through the <i>optional</i> protocol:
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
{
return ...; // color of line in chart
}
@@ -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:
@@ -176,4 +182,4 @@ A JBLineChartView visuaul overview can be found <a href="https://raw.github.com/
## License
Usage is provided under the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License</a> (v2.0). See <a href="https://github.com/Jawbone/JBChartView/blob/master/LICENSE">LICENSE</a> for full details.
Usage is provided under the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License</a> (v2.0). See <a href="https://github.com/Jawbone/JBChartView/blob/master/LICENSE">LICENSE</a> for full details.