Compare commits

...

86 Commits

Author SHA1 Message Date
Terry Worona 6531c68574 version update 2014-08-04 13:37:33 -07:00
Terry Worona ebae36bd2f Pushed base datasource and delegate protocols up to JBChartView (for extensibility) 2014-08-04 13:17:04 -07:00
Terry Worona 8cdff2891c Updated version 2014-08-04 10:15:05 -07:00
Terry Worona 333200d041 Fixed issue #77 2014-08-04 10:13:05 -07:00
Terry Worona 6ad3bd7692 Readme update 2014-08-02 12:20:25 -07:00
Terry Worona 3531e593da update change log, read me, pod spec 2014-08-02 12:13:12 -07:00
Terry Worona eeb9ca604c More refactors 2014-08-02 12:02:01 -07:00
Terry Worona b884108dbb More line chart refactors 2014-08-02 11:46:25 -07:00
Terry Worona 00dd74f733 Started JBLineChartView refactor 2014-08-02 11:22:58 -07:00
Terry Worona c1938147d8 Cleaned up warning 2014-08-02 11:17:09 -07:00
Terry Worona e17c5419f4 Refactor JBBarChartView datasource and delegate 2014-08-02 11:14:36 -07:00
Terry Worona d0cb8b0307 Updated pod spec 2014-07-31 13:30:53 -07:00
Terry Worona fe81df094e Updated change log and read me 2014-07-31 13:29:58 -07:00
Terry Worona 0dae570cc6 Fixed line width bug for JBLineChartView 2014-07-31 13:28:07 -07:00
Terry Worona c5c93cb660 update version, read me, pod spec 2014-07-25 16:43:34 -07:00
Terry Worona 3df69b0a9c more demo chart cleanup 2014-07-25 16:19:28 -07:00
Terry Worona 30305cdde9 String cleanup 2014-07-25 16:12:00 -07:00
Terry Worona 8e1cbba06f Fixed chart coloring 2014-07-25 16:00:07 -07:00
Terry Worona 97e5acdb1a added area controller and assets 2014-07-25 15:55:48 -07:00
Terry Worona 47f1f0ba8d Reverted base to iOS 6 2014-07-25 15:22:08 -07:00
Terry Worona 0be9465049 Fixed OS checks 2014-07-25 15:18:47 -07:00
Terry Worona 7bed3dd5d0 updated pod spec, change log and read me 2014-07-25 14:18:23 -07:00
Luo Sheng 4f1f6760d5 Update the Podspec. 2014-07-25 12:28:33 +08:00
Luo Sheng 8103a1aea4 Make the demo run in iOS 6 too. 2014-07-25 12:27:51 +08:00
Luo Sheng dc6dc647ad Use sizeWithFont: method for iOS 6. 2014-07-25 12:23:26 +08:00
Terry Worona b6ea1a502a Updated pod spec 2014-07-24 16:20:10 -07:00
Terry Worona afcf328158 Fixed readme 2014-07-24 15:43:47 -07:00
Terry Worona 49cf12c568 updated read me and change log of fill functions 2014-07-24 15:39:37 -07:00
Terry Worona 0d4b942b74 Merge branch 'master' of https://github.com/Jawbone/JBChartView 2014-07-24 15:25:22 -07:00
Terry Worona 30a369796f Minor cleanup of PR #71 2014-07-24 15:25:15 -07:00
Terry Worona f2f35312e4 Updated read me 2014-07-24 14:32:22 -07:00
terryworona d32f09a584 Merge pull request #67 from jonparker/master
Added documentation for usage in a Swift project
2014-07-18 11:15:44 -07:00
Damien Legrand 80e179df1d Fill Color
Fill color for line chart :
* Default color is clearColor
* The user can define a color and a selection color for each line with
two new methods in JBLineChartViewDataSource protocol
2014-07-17 17:38:24 +02:00
Terry Worona 48da335f09 added spark friends link 2014-06-30 19:24:06 -07:00
Terry Worona 70c1fb897c added more demos section 2014-06-24 13:05:52 -07:00
Terry Worona 30df02f804 screen update 2014-06-24 12:58:50 -07:00
Terry Worona 9ba20e9e14 updated screenshot 2014-06-24 12:52:37 -07:00
Terry Worona d6d1dd8461 Updated screenshot 2014-06-24 12:21:21 -07:00
Jonathan Parker b0de620503 Added link to iOS documentation. 2014-06-23 15:49:26 +10:00
Jonathan Parker 8e81fb20cd Added instructions for use in a Swift project. 2014-06-23 15:46:37 +10:00
Terry Worona a303422d8e updated read me, pod spec, etc 2014-05-13 19:44:52 -07:00
Terry Worona 1aff68557f Cleaned up demo code and add min value to bar charts 2014-05-13 19:42:14 -07:00
terryworona ac3744c0c9 Merge pull request #57 from pala/master
Fixed barView's frame.
2014-05-13 19:33:55 -07:00
Tao Zhang a6ea0c30f8 Update JBBarChartView.m 2014-05-13 21:56:02 -04:00
pala ea531e3cb1 Fixed barView's frame. 2014-05-13 19:42:06 -04:00
terryworona b1a3ebd4ed Merge pull request #55 from pala/patch-1
Update sample code in readme
2014-05-13 10:39:24 -07:00
Tao Zhang 554f93f3d3 Update sample code 2014-05-12 23:41:25 -04:00
Terry Worona 2ddd38fc9d updated change log 2014-05-07 09:55:10 -07:00
Terry Worona 6691f7a8c3 Updated comment, read me, pod spec, etc 2014-05-07 09:47:32 -07:00
terryworona c015531c85 Merge pull request #53 from skywinder/bar-color-delegate
Add delegate method barChartView:colorForBarViewAtIndex: to JBBarChartViewDataSource
2014-05-07 09:40:43 -07:00
terryworona 3d036edc96 Merge pull request #52 from skywinder/compiling-warrnings-and-typos
Compiling warrnings and typos
2014-05-07 09:36:48 -07:00
Petr Korolev 85c30351fe Add new delegate method to JBBarChartView
Implement logic to set specifed color before set the default kJBBarChartViewDefaultBarColor
Add call of this code to Example project
2014-05-07 15:33:50 +03:00
Petr Korolev d37383a352 fix typo 2014-05-07 14:59:34 +03:00
Petr Korolev 3c6cf24cf7 Cast to correct return type (NSUInteger) 2014-05-07 14:37:28 +03:00
Terry Worona 8dbb2679ee Updated log, spec and read me 2014-05-06 14:05:24 -07:00
Terry Worona 867466d1d1 More more compile error 2014-05-06 14:04:17 -07:00
Terry Worona 2046131143 Updated read me, pod spec, etc. 2014-05-06 13:40:21 -07:00
Terry Worona 208a727d88 Fixed compiler warnings 2014-05-06 13:38:24 -07:00
Terry Worona 43c6e9486f Updated version, pod spec, etc 2014-05-05 12:33:39 -07:00
Terry Worona 49206a01ed Fixed issue #48 2014-05-05 12:31:12 -07:00
Terry Worona e2b17820bf readme updates 2014-05-04 14:47:21 -07:00
Terry Worona b59904e5b9 updated for new version 2014-05-04 14:45:27 -07:00
Terry Worona 1d8f78d751 Fixed issue #48 2014-05-04 14:07:27 -07:00
Terry Worona 3cc39124b8 updated version 2014-05-04 09:48:10 -07:00
terryworona bedd7e2c71 Merge pull request #49 from simonnickel/master
fixed typo, renamed mininum -> minimum
2014-05-04 09:44:03 -07:00
Simon Nickel 786af91666 fixed typo, renamed mininum -> minimum 2014-05-03 22:18:42 +02:00
Terry Worona b7927cddb7 Fixes issue #46 2014-04-30 22:58:47 -07:00
Terry Worona 0f2d4d766c updated change log, pod spec, etc 2014-04-30 10:04:01 -07:00
terryworona 64de3e6e23 Merge pull request #45 from ktran03/smoothCurveFix
Smooth curve fix
2014-04-30 09:59:22 -07:00
ktran03 87fb8ee7b8 missing variable in condition 2014-04-29 22:03:40 -04:00
ktran03 7c0dfe3eb5 smooth curve fix for more straight line cases 2014-04-29 21:55:47 -04:00
Terry Worona 87b62ad2b1 updated change log, pod spec, read me 2014-04-28 12:06:03 -07:00
Terry Worona 9c0d788418 More style updates 2014-04-28 12:00:59 -07:00
Terry Worona de009f0236 PR #39 cleanup 2014-04-28 11:25:45 -07:00
ktran03 d46e4fe14d changed compare condition to using slope instead of vertical diff 2014-04-26 18:32:40 -04:00
ktran03 236336fdf3 added check for y-value difference if exceeds threshold 2014-04-25 15:14:16 -04:00
ktran03 9b60a1d662 Expose smooth option through delegate, fix diffs 2014-04-24 14:35:54 -04:00
ktran03 3700b4e2e2 smooth curve using bezierpath 2014-04-19 20:15:53 -04:00
Terry Worona 8c03033a1c Added screenshot to pod spec 2014-04-18 10:14:42 -07:00
Terry Worona bb084b1b89 Fixes issue #34 2014-04-17 18:32:58 -07:00
Terry Worona 1c7c8b2e52 Updated read me, pod spec etc for new version 2014-04-14 10:36:07 -07:00
Terry Worona 79a57d98e3 Clamp selection width to width of chart 2014-04-14 10:32:50 -07:00
Terry Worona 20d6b6081b Fixed comment 2014-04-14 10:30:24 -07:00
terryworona 20bbbdcc86 Merge pull request #37 from veducm/master
Added delegate method to configure the width of the vertical selection bar in a line chart.
2014-04-14 10:27:51 -07:00
Edu Caselles 51ac8a1d63 Added delegate method to configure the width of the vertical selection bar in a line chart. 2014-04-14 01:35:20 +02:00
Terry Worona 68d04a2cdb Fixes issue #36 2014-04-12 09:11:41 -07:00
29 changed files with 1227 additions and 510 deletions
+76
View File
@@ -1,5 +1,81 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.2">2.7.2</a>
#### 08/04/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/78">#78</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.1">2.7.1</a>
#### 08/04/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/77">#77</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.0">2.7.0</a>
#### 08/02/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/76">#76</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.6.3">2.6.3</a>
#### 07/31/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/75">#75</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.6.2">2.6.2</a>
#### 07/25/14
- Added new controller (JBAreaChartViewController) to demonstrate area charts.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.6.1">2.6.1</a>
#### 07/25/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/74">#74</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.6.0">2.6.0</a>
#### 07/24/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/71">#71</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.5">2.5.5</a>
#### 05/13/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/57">#57</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.4">2.5.4</a>
#### 05/07/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/53">#53</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.3">2.5.3</a>
#### 05/06/14
- More compiler warning fixes.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.2">2.5.2</a>
#### 05/06/14
- Fixed compiler warnings.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.1">2.5.1</a>
#### 05/05/14
- Additional fixes to issue <a href="https://github.com/Jawbone/JBChartView/pull/48">#48</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.0">2.5.0</a>
#### 05/04/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/48">#48</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.3">2.4.3</a>
#### 05/04/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/49">#49</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.2">2.4.2</a>
#### 04/30/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/46">#46</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.1">2.4.1</a>
#### 04/30/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/45">#45</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.0">2.4.0</a>
#### 04/28/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/23">#23</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.3.0">2.3.0</a>
#### 04/17/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/34">#34</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.2.0">2.2.0</a>
#### 04/14/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/37">#37</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.6">2.1.6</a>
#### 04/11/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/33">#33</a>.
+67 -55
View File
@@ -9,29 +9,43 @@
// Views
#import "JBChartView.h"
@protocol JBBarChartViewDelegate;
@protocol JBBarChartViewDataSource;
@class JBBarChartView;
@interface JBBarChartView : JBChartView
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
/**
* Vertical highlight overlayed on bar during touch events.
*
* Default: YES.
*/
@property (nonatomic, assign) BOOL showsVerticalSelection;
@end
@protocol JBBarChartViewDelegate <NSObject>
@protocol JBBarChartViewDataSource <JBChartViewDataSource>
@required
/**
* Height for a bar at a given index (left to right). There is no ceiling on the the height;
* The number of bars in a given bar chart is the number of vertical views shown along the x-axis.
*
* @param barChartView The bar chart object requesting this information.
*
* @return Number of bars in the given chart, displayed horizontally along the chart's x-axis.
*/
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView;
@optional
/**
* A UIView subclass representing the bar at a particular index.
*
* Default: solid black UIView.
*
* @param barChartView The bar chart object requesting this information.
* @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).
*/
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index;
@end
@protocol JBBarChartViewDelegate <JBChartViewDelegate>
@required
/**
* 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 bar chart object requesting this information.
@@ -39,7 +53,7 @@
*
* @return The y-axis height of the supplied bar index (x-axis)
*/
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index;
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index;
@optional
@@ -58,53 +72,26 @@
* 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 A bar chart object informing the delegate about the unselection.
* @param barChartView A bar chart object informing the delegate about the deselection.
*/
- (void)didUnselectBarChartView:(JBBarChartView *)barChartView;
@end
@protocol JBBarChartViewDataSource <NSObject>
@required
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView;
/**
* The number of bars in a given bar chart is the number of vertical views shown along the x-axis.
* 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).
*
* @param barChartView The bar chart object requesting this information.
*
* @return Number of bars in the given chart, displayed horizontally along the chart's x-axis.
*/
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView;
@optional
/**
* Horizontal padding between bars.
*
* Default: 'best-guess' algorithm based on the the total number of bars and width of the chart.
*
* @param barChartView The bar chart object requesting this information.
*
* @return Horizontal width (in pixels) between each bar.
*/
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
/**
* A UIView subclass representing the bar at a particular index.
*
* Default: solid black UIView.
* Default: if none specified - calls barChartView:barViewAtIndex:.
*
* @param barChartView The bar chart object requesting this information.
* @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).
* @return The color to be used to color a bar in the chart.
*/
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index;
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
/**
* The selection color to be overlayed on a bar during touch events.
* The color is automically faded to transparent (vertically). The property showsVerticalSelection
* The selection color to be overlayed on a bar during touch events.
* The color is automatically faded to transparent (vertically). The property showsVerticalSelection
* must be YES for the color to apply.
*
* Default: white color (faded to transparent).
@@ -115,4 +102,29 @@
*/
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView;
/**
* Horizontal padding between bars.
*
* Default: 'best-guess' algorithm based on the the total number of bars and width of the chart.
*
* @param barChartView The bar chart object requesting this information.
*
* @return Horizontal width (in pixels) between each bar.
*/
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
@end
@interface JBBarChartView : JBChartView
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
/**
* Vertical highlight overlayed on bar during touch events.
*
* Default: YES.
*/
@property (nonatomic, assign) BOOL showsVerticalSelection;
@end
+48 -48
View File
@@ -18,6 +18,13 @@ NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
// Colors (JBChartView)
static UIColor *kJBBarChartViewDefaultBarColor = nil;
@interface JBChartView (Private)
- (BOOL)hasMaximumValue;
- (BOOL)hasMinimumValue;
@end
@interface JBBarChartView ()
@property (nonatomic, strong) NSDictionary *chartDataDictionary; // key = column, value = height
@@ -34,8 +41,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
// View quick accessors
- (CGFloat)availableHeight;
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight;
- (CGFloat)minHeight;
- (CGFloat)maxHeight;
- (CGFloat)barWidth;
- (CGFloat)popOffset;
@@ -125,12 +130,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
NSUInteger dataCount = [self.dataSource numberOfBarsInBarChartView:self];
// Build up the data collection
NSAssert([self.delegate respondsToSelector:@selector(barChartView:heightForBarViewAtAtIndex:)], @"JBBarChartView // delegate must implement - (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index");
NSAssert([self.delegate respondsToSelector:@selector(barChartView:heightForBarViewAtIndex:)], @"JBBarChartView // delegate must implement - (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index");
NSMutableDictionary *dataDictionary = [NSMutableDictionary dictionary];
for (NSUInteger index=0; index<dataCount; index++)
{
CGFloat height = [self.delegate barChartView:self heightForBarViewAtAtIndex:index];
NSAssert(height >= 0, @"JBBarChartView // datasource function - (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index must return a CGFloat >= 0");
CGFloat height = [self.delegate barChartView:self heightForBarViewAtIndex:index];
NSAssert(height >= 0, @"JBBarChartView // datasource function - (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index must return a CGFloat >= 0");
[dataDictionary setObject:[NSNumber numberWithFloat:height] forKey:[NSNumber numberWithInt:(int)index]];
}
self.chartDataDictionary = [NSDictionary dictionaryWithDictionary:dataDictionary];
@@ -140,9 +145,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
* Determines the padding between bars as a function of # of bars
*/
dispatch_block_t createBarPadding = ^{
if ([self.dataSource respondsToSelector:@selector(barPaddingForBarChartView:)])
if ([self.delegate respondsToSelector:@selector(barPaddingForBarChartView:)])
{
self.barPadding = [self.dataSource barPaddingForBarChartView:self];
self.barPadding = [self.delegate barPaddingForBarChartView:self];
}
else
{
@@ -176,11 +181,24 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
else
{
barView = [[UIView alloc] init];
barView.backgroundColor = kJBBarChartViewDefaultBarColor;
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;
}
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
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);
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height + extensionHeight);
[mutableBarViews addObject:barView];
// Add new bar
@@ -214,9 +232,11 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height - self.footerView.frame.size.height)];
self.verticalSelectionView.alpha = 0.0;
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
if ([self.dataSource respondsToSelector:@selector(barSelectionColorForBarChartView:)])
if ([self.delegate respondsToSelector:@selector(barSelectionColorForBarChartView:)])
{
self.verticalSelectionView.bgColor = [self.dataSource barSelectionColorForBarChartView:self];
UIColor *selectionViewBackgroundColor = [self.delegate barSelectionColorForBarChartView:self];
NSAssert(selectionViewBackgroundColor != nil, @"JBBarChartView // delegate function - (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView must return a non-nil UIColor");
self.verticalSelectionView.bgColor = selectionViewBackgroundColor;
}
// Add new selection bar
@@ -240,7 +260,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
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);
// Refresh state
[self setState:self.state animated:NO callback:nil force:YES];
[self setState:self.state animated:NO force:YES callback:nil];
}
#pragma mark - View Quick Accessors
@@ -252,8 +272,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight
{
CGFloat minHeight = [self minHeight];
CGFloat maxHeight = [self maxHeight];
CGFloat minHeight = [self minimumValue];
CGFloat maxHeight = [self maximumValue];
CGFloat value = [rawHeight floatValue];
if ((maxHeight - minHeight) <= 0)
@@ -264,24 +284,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return ((value - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
}
- (CGFloat)minHeight
{
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
{
return MIN(self.mininumValue, self.cachedMinHeight);
}
return self.cachedMinHeight;
}
- (CGFloat)maxHeight
{
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
{
return MAX(self.maximumValue, self.cachedMaxHeight);
}
return self.cachedMaxHeight;
}
- (CGFloat)barWidth
{
NSUInteger barCount = [[self.chartDataDictionary allKeys] count];
@@ -301,9 +303,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
#pragma mark - Setters
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
{
[super setState:state animated:animated callback:callback force:force];
[super setState:state animated:animated force:force callback:callback];
dispatch_block_t callbackCopy = [callback copy];
@@ -371,7 +373,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
{
[self setState:state animated:animated callback:callback force:NO];
[self setState:state animated:animated force:NO callback:callback];
}
#pragma mark - Getters
@@ -380,8 +382,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
if(_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
{
// min height is min value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
NSArray *chartValues = [[NSMutableArray arrayWithArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
_cachedMinHeight = [[chartValues firstObject] floatValue];
}
return _cachedMinHeight;
@@ -391,29 +392,28 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
{
// max height is max value across all goals and values
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
NSArray *chartValues = [[NSMutableArray arrayWithArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
_cachedMaxHeight = [[chartValues lastObject] floatValue];
}
return _cachedMaxHeight;
}
- (CGFloat)mininumValue
- (CGFloat)minimumValue
{
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
if ([self hasMinimumValue])
{
return self.cachedMinHeight;
return fminf(self.cachedMinHeight, [super minimumValue]);
}
return [super mininumValue];
return self.cachedMinHeight;
}
- (CGFloat)maximumValue
{
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
if ([self hasMaximumValue])
{
return self.cachedMaxHeight;
return fmaxf(self.cachedMaxHeight, [super maximumValue]);
}
return [super maximumValue];
return self.cachedMaxHeight;
}
#pragma mark - Touch Helpers
@@ -495,9 +495,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
[self setVerticalSelectionViewVisible:NO animated:YES];
if ([self.delegate respondsToSelector:@selector(didUnselectBarChartView:)])
if ([self.delegate respondsToSelector:@selector(didDeselectBarChartView:)])
{
[self.delegate didUnselectBarChartView:self];
[self.delegate didDeselectBarChartView:self];
}
}
+29 -6
View File
@@ -9,8 +9,6 @@
#import <Foundation/Foundation.h>
extern CGFloat const kJBChartViewDefaultAnimationDuration;
extern CGFloat const kJBChartViewUndefinedMinimumValue; // helper for undefined min/max values
extern CGFloat const kJBChartViewUndefinedMaximumValue;
/**
* At a minimum, a chart can support two states, along with animations to-and-from.
@@ -26,8 +24,26 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
JBChartViewStateCollapsed
};
@protocol JBChartViewDataSource <NSObject>
// Extend (via subclass) to add custom functionality
@end
@protocol JBChartViewDelegate <NSObject>
// Extend (via subclass) to add custom functionality
@end
@interface JBChartView : UIView
/*
* Base dataSource and delegate protocols.
*/
@property (nonatomic, weak) id<JBChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBChartViewDelegate> delegate;
/**
* Header and footer views are shown above and below the chart respectively.
* Each view will be stretched horizontally to fill width of chart.
@@ -43,7 +59,10 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
/**
* The minimum and maxmimum values of the chart.
* If no value(s) are supplied, the min and max values of the chart's data source are used.
* If no value(s) are supplied:
*
* minimumValue = chart's data source min value.
* maxmimumValue = chart's data source max value.
*
* If value(s) are supplied, they must be >= 0, otherwise an assertion will be thrown.
* The min/max values are clamped to the ceiling and floor of the actual min/max values of the chart's data source;
@@ -51,9 +70,13 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
*
* For min/max modifications to take effect, reloadData must be called.
*/
@property (nonatomic, assign) CGFloat mininumValue;
@property (nonatomic, assign) CGFloat minimumValue;
@property (nonatomic, assign) CGFloat maximumValue;
// reset to default (chart's data source min & max value)
- (void)resetMinimumValue;
- (void)resetMaximumValue;
/**
* Charts can either be expanded or contracted.
* By default, a chart should be expanded on initialization.
@@ -71,10 +94,10 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
*
* @param state Either collapse or expanded.
* @param animated Whether or not the state should be animated or not.
* @param callback Called once the animation is completed. If animated == NO, then callback is immediate.
* @param force If current state == new state, then setting force to YES will re-configure the chart (default NO).
* @param callback Called once the animation is completed. If animated == NO, then callback is immediate.
*/
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force;
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback;
/**
* State setter.
+21 -9
View File
@@ -8,15 +8,17 @@
#import "JBChartView.h"
// Numerics
CGFloat const kJBChartViewDefaultAnimationDuration = 0.25f;
CGFloat const kJBChartViewUndefinedMinimumValue = -1.0f;
CGFloat const kJBChartViewUndefinedMaximumValue = -1.0f;
// Color (JBChartSelectionView)
static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
@interface JBChartView ()
@property (nonatomic, assign) BOOL hasMaximumValue;
@property (nonatomic, assign) BOOL hasMinimumValue;
// Construction
- (void)constructChartView;
@@ -59,8 +61,6 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
- (void)constructChartView
{
self.clipsToBounds = YES;
_mininumValue = kJBChartViewUndefinedMinimumValue;
_maximumValue = kJBChartViewUndefinedMaximumValue;
}
#pragma mark - Public
@@ -111,7 +111,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
[self reloadData];
}
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
{
if ((_state == state) && !force)
{
@@ -125,7 +125,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
{
[self setState:state animated:animated callback:callback force:NO];
[self setState:state animated:animated force:NO callback:callback];
}
- (void)setState:(JBChartViewState)state animated:(BOOL)animated
@@ -138,16 +138,28 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
[self setState:state animated:NO];
}
- (void)setMininumValue:(CGFloat)mininumValue
- (void)setMinimumValue:(CGFloat)minimumValue
{
NSAssert(mininumValue >= 0, @"JBChartView // the minimumValue must be >= 0.");
_mininumValue = mininumValue;
NSAssert(minimumValue >= 0, @"JBChartView // the minimumValue must be >= 0.");
_minimumValue = minimumValue;
_hasMinimumValue = YES;
}
- (void)setMaximumValue:(CGFloat)maximumValue
{
NSAssert(maximumValue >= 0, @"JBChartView // the maximumValue must be >= 0.");
_maximumValue = maximumValue;
_hasMaximumValue = YES;
}
- (void)resetMinimumValue
{
_hasMinimumValue = NO; // clears min
}
- (void)resetMaximumValue
{
_hasMaximumValue = NO; // clears max
}
@end
Regular → Executable
+158 -91
View File
@@ -8,6 +8,8 @@
#import "JBChartView.h"
@class JBLineChartView;
/**
* Current support for two line styles: solid (default) and dashed.
*/
@@ -22,74 +24,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
JBLineChartViewLineStyleDashed
};
@protocol JBLineChartViewDelegate;
@protocol JBLineChartViewDataSource;
@interface JBLineChartView : JBChartView
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
/**
* Vertical highlight overlayed on a line graph during touch events.
*
* Default: YES.
*/
@property (nonatomic, assign) BOOL showsVerticalSelection;
/**
* A highlight shown on a line within the graph during touch events. The highlighted line
* is the closest line to the touch point and corresponds to the lineIndex delegatd back via
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex:
*
* Default: YES.
*/
@property (nonatomic, assign) BOOL showsLineSelection;
@end
@protocol JBLineChartViewDelegate <NSObject>
@required
/**
* Vertical value for a 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 line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param lineIndex An index number identifying the closest line in the chart to the current touch point.
*
* @return The y-axis value of the supplied line index (x-axis)
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
@optional
/**
* Occurs whenever there is a touch gesture on the chart (chart must be expanded).
* The horizontal index is the closest index to the touch point & is clamped to it's max/min value if it moves outside of the view's bounds.
* The lineIndex remains constant until the line is unselected and will be highlighted using the (optional) selectionColorForLineAtLineIndex: protocol.
* Futhermore, all other lines that aren't selected will be dimmed to 50% opacity throughout the duration of the touch/move.
*
* @param lineChartView A line chart object informing the delegate about the new selection.
* @param lineIndex An index number identifying the closest line in the chart to the current touch
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param touchPoint The touch point in relation to the chart's bounds (excludes footer and header).
*/
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex touchPoint:(CGPoint)touchPoint;
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex;
/**
* Occurs when selection ends by ending a touch event. For selection start events, see: didSelectChartAtIndex:
*
* @param lineChartView A line chart object informing the delegate about the unselection.
*/
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView;
@end
@protocol JBLineChartViewDataSource <NSObject>
@protocol JBLineChartViewDataSource <JBChartViewDataSource>
@required
@@ -114,6 +49,74 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
@optional
/**
* Returns whether or not a line should show a dot for each point.
* Dot size is relative to the line width and not adjustable.
* Dot color is equal to the line color and not adjustable.
*
* Default: NO
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return Whether or not a line should show a dot for each chart point.
*/
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns whether or not a line should be rendered with curved connections and rounded end caps.
*
* Default: NO
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return Whether or not a line should smooth it's connections and end caps.
*/
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
@end
@protocol JBLineChartViewDelegate <JBChartViewDelegate>
@required
/**
* Vertical value for a 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 line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
* @param lineIndex An index number identifying the closest line in the chart to the current touch point.
*
* @return The y-axis value of the supplied line index (x-axis)
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
@optional
/**
* Occurs whenever there is a touch gesture on the chart (chart must be expanded).
* The horizontal index is the closest index to the touch point & is clamped to it's max/min value if it moves outside of the view's bounds.
* The lineIndex remains constant until the line is deselected and will be highlighted using the (optional) selectionColorForLineAtLineIndex: protocol.
* Futhermore, all other lines that aren't selected will be dimmed to 20%% opacity throughout the duration of the touch/move. Any dotted line that isn't the
* primary selection will have it's dots dimmed to hidden (to avoid transparency issues).
*
* @param lineChartView A line chart object informing the delegate about the new selection.
* @param lineIndex An index number identifying the closest line in the chart to the current touch
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param touchPoint The touch point in relation to the chart's bounds (excludes footer and header).
*/
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex touchPoint:(CGPoint)touchPoint;
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex;
/**
* Occurs when selection ends by ending a touch event. For selection start events, see: didSelectChartAtIndex:
*
* @param lineChartView A line chart object informing the delegate about the deselection.
*/
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView;
/**
* Returns the color of particular line at lineIndex within the chart.
*
@@ -126,6 +129,33 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns the fill color of particular line at lineIndex within the chart.
*
* Default: clear color.
*
* @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.
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView fillColorForLineAtLineIndex:(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.
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
*
* Default: black color.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color to be used to color a dot within a dotted line in the chart.
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
/**
* Returns the width of particular line at lineIndex within the chart.
*
@@ -141,7 +171,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
/**
* Returns the radius of all dots in a particular line at lineIndex within the chart.
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
*
* Default: line width x 3.
*
@@ -152,6 +182,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*/
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns the width of the (vertical) selection view to be overlayed on the chart during touch events.
* The property showsVerticalSelection must be YES for the width to apply. The width is clamped to the
* maxmimum width of the chart's bounds.
*
* Default: 20px.
*
* @param lineChartView The line chart object requesting this information.
*
* @return The width of the selection view used during chart selections.
*/
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView;
/**
* Returns the (vertical) selection color to be overlayed on the chart during touch events.
* The color is automically faded to transparent (vertically). The property showsVerticalSelection
@@ -161,7 +204,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*
* @param lineChartView The line chart object requesting this information.
*
* @return The color to be used on chart selections.
* @return The color of the selection view used during chart selections.
*/
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView;
@@ -178,6 +221,33 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(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.
*
* Default: clear color.
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color to be used to highlight under a line during chart selections.
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionFillColorForLineAtLineIndex:(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.
*
* Default: white color.
*
* @param lineChartView The line chart object requesting this information.
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
* @param lineIndex An index number identifying a line in the chart.
*
* @return The color to be used to highlight a dot within a dotted line during chart selections.
*/
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
/**
* Returns the line style of a particular line at lineIndex within the chart.
* See JBLineChartViewLineStyle for line style descriptions.
@@ -191,30 +261,27 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
*/
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
/**
* Returns whether or not a line should show a dot for each point.
* Dot size is relative to the line width and not adjustable.
* Dot color is equal to the line color and not adjustable.
*
* Default: NO
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return Whether or not a line should show a dot for each chart point.
*/
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
@end
@interface JBLineChartView : JBChartView
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
/**
* Returns whether or not a line should be smoothed (rounded end caps and connections).
* Vertical highlight overlayed on a line graph during touch events.
*
* Default: NO
*
* @param lineChartView The line chart object requesting this information.
* @param lineIndex An index number identifying a line in the chart.
*
* @return Whether or not a line should smooth it's ends and connections.
* Default: YES.
*/
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
@property (nonatomic, assign) BOOL showsVerticalSelection;
/**
* A highlight shown on a line within the graph during touch events. The highlighted line
* is the closest line to the touch point and corresponds to the lineIndex delegatd back via
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex:
*
* Default: YES.
*/
@property (nonatomic, assign) BOOL showsLineSelection;
@end
Regular → Executable
+253 -100
View File
@@ -22,8 +22,10 @@ typedef NS_ENUM(NSUInteger, JBLineChartHorizontalIndexClamp){
CGFloat static const kJBLineChartLinesViewStrokeWidth = 5.0;
CGFloat static const kJBLineChartLinesViewMiterLimit = -5.0;
CGFloat static const kJBLineChartLinesViewDefaultLinePhase = 1.0f;
CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.5f;
CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.20f;
NSInteger static const kJBLineChartLinesViewUnselectedLineIndex = -1;
CGFloat static const kJBLineChartLinesViewSmoothThresholdSlope = 0.01f;
NSInteger static const kJBLineChartLinesViewSmoothThresholdVertical = 1;
// Numerics (JBLineChartDotsView)
NSInteger static const kJBLineChartDotsViewDefaultRadiusFactor = 3; // 3x size of line width
@@ -44,7 +46,18 @@ static NSArray *kJBLineChartLineViewDefaultDashPattern = nil;
// Colors (JBLineChartView)
static UIColor *kJBLineChartViewDefaultLineColor = nil;
static UIColor *kJBLineChartViewDefaultLineFillColor = nil;
static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
static UIColor *kJBLineChartViewDefaultLineSelectionFillColor = nil;
static UIColor *kJBLineChartViewDefaultDotColor = nil;
static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
@interface JBChartView (Private)
- (BOOL)hasMaximumValue;
- (BOOL)hasMinimumValue;
@end
@interface JBLineLayer : CAShapeLayer
@@ -53,6 +66,12 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
@end
@interface JBFillLayer : CAShapeLayer
@property (nonatomic, assign) NSUInteger tag;
@end
@interface JBLineChartPoint : NSObject
@property (nonatomic, assign) CGPoint position;
@@ -78,6 +97,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
// View helpers
- (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex;
- (JBFillLayer *)fillLayerForLineIndex:(NSUInteger)lineIndex;
@end
@@ -86,6 +106,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (NSArray *)chartDataForLineChartLinesView:(JBLineChartLinesView*)lineChartLinesView;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedFillColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView;
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
@@ -112,8 +134,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
@protocol JBLineChartDotsViewDelegate <NSObject>
- (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView*)lineChartDotsView;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
@@ -143,8 +165,6 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
// View quick accessors
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight;
- (CGFloat)availableHeight;
- (CGFloat)minHeight;
- (CGFloat)maxHeight;
- (CGFloat)padding;
- (NSUInteger)dataCount;
@@ -171,7 +191,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
if (self == [JBLineChartView class])
{
kJBLineChartViewDefaultLineColor = [UIColor blackColor];
kJBLineChartViewDefaultLineFillColor = [UIColor clearColor];
kJBLineChartViewDefaultLineSelectionColor = [UIColor whiteColor];
kJBLineChartViewDefaultLineSelectionFillColor = [UIColor clearColor];
kJBLineChartViewDefaultDotColor = [UIColor blackColor];
kJBLineChartViewDefaultDotSelectionColor = [UIColor whiteColor];
}
}
@@ -238,7 +262,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
CGFloat pointSpace = (self.bounds.size.width - (chartPadding * 2)) / ([self dataCount] - 1); // Space in between points
CGFloat xOffset = chartPadding;
CGFloat yOffset = 0;
NSMutableArray *mutableChartData = [NSMutableArray array];
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
@@ -247,7 +271,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
NSMutableArray *chartPointData = [NSMutableArray array];
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
{
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
CGFloat rawHeight = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert(rawHeight >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
@@ -282,7 +306,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
// Create new line and overlay subviews
self.linesView = [[JBLineChartLinesView alloc] initWithFrame:CGRectOffset(mainViewRect, 0, self.headerView.frame.size.height + self.headerPadding)];
self.linesView.delegate = self;
// Add new lines view
if (self.footerView)
{
@@ -331,12 +355,19 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
self.verticalSelectionView = nil;
}
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, kJBLineSelectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
CGFloat selectionViewWidth = kJBLineSelectionViewWidth;
if ([self.delegate respondsToSelector:@selector(verticalSelectionWidthForLineChartView:)])
{
selectionViewWidth = MIN([self.delegate verticalSelectionWidthForLineChartView:self], self.bounds.size.width);
}
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
self.verticalSelectionView.alpha = 0.0;
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
if ([self.dataSource respondsToSelector:@selector(verticalSelectionColorForLineChartView:)])
if ([self.delegate respondsToSelector:@selector(verticalSelectionColorForLineChartView:)])
{
self.verticalSelectionView.bgColor = [self.dataSource verticalSelectionColorForLineChartView:self];
UIColor *selectionViewBackgroundColor = [self.delegate verticalSelectionColorForLineChartView:self];
NSAssert(selectionViewBackgroundColor != nil, @"JBLineChartView // delegate function - (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView must return a non-nil UIColor");
self.verticalSelectionView.bgColor = selectionViewBackgroundColor;
}
// Add new selection bar
@@ -364,15 +395,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
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);
// Refresh state
[self setState:self.state animated:NO callback:nil force:YES];
[self setState:self.state animated:NO force:YES callback:nil];
}
#pragma mark - View Quick Accessors
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight
{
CGFloat minHeight = [self minHeight];
CGFloat maxHeight = [self maxHeight];
CGFloat minHeight = [self minimumValue];
CGFloat maxHeight = [self maximumValue];
if ((maxHeight - minHeight) <= 0)
{
@@ -387,30 +418,12 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding;
}
- (CGFloat)minHeight
{
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
{
return MIN(self.mininumValue, self.cachedMinHeight);
}
return self.cachedMinHeight;
}
- (CGFloat)maxHeight
{
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
{
return MAX(self.maximumValue, self.cachedMaxHeight);
}
return self.cachedMaxHeight;
}
- (CGFloat)padding
{
CGFloat maxLineWidth = 0.0f;
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
{
BOOL showsDots = NO;
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
@@ -419,17 +432,17 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
}
CGFloat lineWidth = kJBLineChartLinesViewStrokeWidth; // default
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
{
lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineWidth];
lineWidth = [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
}
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
if (showsDots)
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
{
dotRadius = [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
dotRadius = [self.delegate lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
}
}
@@ -467,27 +480,45 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:colorForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:colorForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self colorForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self colorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineColor;
}
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionColorForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self selectionColorForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self selectionColorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineSelectionColor;
}
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.delegate respondsToSelector:@selector(lineChartView:fillColorForLineAtLineIndex:)])
{
return [self.delegate lineChartView:self fillColorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineFillColor;
}
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedFillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionFillColorForLineAtLineIndex:)])
{
return [self.delegate lineChartView:self selectionFillColorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineSelectionFillColor;
}
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
}
return kJBLineChartLinesViewStrokeWidth;
}
@@ -497,6 +528,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return [self padding];
}
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.delegate respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
{
return [self.delegate lineChartView:self lineStyleForLineAtLineIndex:lineIndex];
}
return JBLineChartViewLineStyleSolid;
}
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
@@ -506,15 +546,6 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return NO;
}
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self lineStyleForLineAtLineIndex:lineIndex];
}
return JBLineChartViewLineStyleSolid;
}
#pragma mark - JBLineChartDotsViewDelegate
- (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView*)lineChartDotsView
@@ -522,38 +553,38 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return self.chartData;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:colorForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:colorForDotAtHorizontalIndex:atLineIndex:)])
{
return [self.dataSource lineChartView:self colorForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineColor;
return kJBLineChartViewDefaultDotColor;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionColorForDotAtHorizontalIndex:atLineIndex:)])
{
return [self.dataSource lineChartView:self selectionColorForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self selectionColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineSelectionColor;
return kJBLineChartViewDefaultDotSelectionColor;
}
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
}
return kJBLineChartLinesViewStrokeWidth;
}
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
}
else
{
@@ -577,9 +608,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
#pragma mark - Setters
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
{
[super setState:state animated:animated callback:callback force:force];
[super setState:state animated:animated force:force callback:callback];
if ([self.chartData count] > 0)
{
@@ -604,7 +635,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
} completion:^(BOOL finished) {
[UIView animateWithDuration:kJBLineChartViewStateAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
adjustViewFrames();
} completion:^(BOOL finished) {
} completion:^(BOOL adjustFinished) {
if (callback)
{
callback();
@@ -636,7 +667,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
{
[self setState:state animated:animated callback:callback force:NO];
[self setState:state animated:animated force:NO callback:callback];
}
#pragma mark - Getters
@@ -693,22 +724,22 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return _cachedMaxHeight;
}
- (CGFloat)mininumValue
- (CGFloat)minimumValue
{
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
if ([self hasMinimumValue])
{
return self.cachedMinHeight;
return fminf(self.cachedMinHeight, [super minimumValue]);
}
return [super mininumValue];
return self.cachedMinHeight;
}
- (CGFloat)maximumValue
{
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
if ([self hasMaximumValue])
{
return self.cachedMaxHeight;
return fmaxf(self.cachedMaxHeight, [super maximumValue]);
}
return [super maximumValue];
return self.cachedMaxHeight;
}
#pragma mark - Touch Helpers
@@ -760,8 +791,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
- (NSInteger)lineIndexForPoint:(CGPoint)point
{
// Find the horizontal indexes
NSInteger leftHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampLeft];
NSInteger rightHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampRight];
NSUInteger leftHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampLeft];
NSUInteger rightHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampRight];
// Padding
CGFloat chartPadding = [self padding];
@@ -843,9 +874,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
[self setVerticalSelectionViewVisible:NO animated:YES];
if ([self.delegate respondsToSelector:@selector(didUnselectLineInLineChartView:)])
if ([self.delegate respondsToSelector:@selector(didDeselectLineInLineChartView:)])
{
[self.delegate didUnselectLineInLineChartView:self];
[self.delegate didDeselectLineInLineChartView:self];
}
if (self.showsLineSelection)
@@ -934,7 +965,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
self = [super init];
if (self)
{
self.zPosition = 0.0f;
self.zPosition = 0.1f;
self.fillColor = [UIColor clearColor].CGColor;
}
return self;
@@ -960,6 +991,24 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
@end
@implementation JBFillLayer
#pragma mark - Alloc/Init
- (id)init
{
self = [super init];
if (self)
{
self.zPosition = 0.0f;
self.strokeColor = [UIColor clearColor].CGColor;
self.lineWidth = 0.0f;
}
return self;
}
@end
@implementation JBLineChartPoint
#pragma mark - Alloc/Init
@@ -1022,18 +1071,57 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
UIBezierPath *path = [UIBezierPath bezierPath];
path.miterLimit = kJBLineChartLinesViewMiterLimit;
JBLineChartPoint *previousLineChartPoint = nil;
CGFloat previousSlope = 0.0f;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:smoothLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex");
BOOL smoothLine = [self.delegate lineChartLinesView:self smoothLineAtLineIndex:lineIndex];
NSUInteger index = 0;
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
NSArray *sortedLineData = [lineData sortedArrayUsingSelector:@selector(compare:)];
CGFloat firstXPosition = 0.0f;
CGFloat lastXPosition = 0.0f;
for (JBLineChartPoint *lineChartPoint in sortedLineData)
{
if (index == 0)
{
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
firstXPosition = lineChartPoint.position.x;
}
else
{
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
JBLineChartPoint *nextLineChartPoint = nil;
if (index != ([lineData count] - 1))
{
nextLineChartPoint = [sortedLineData objectAtIndex:(index + 1)];
}
CGFloat nextSlope = (nextLineChartPoint != nil) ? ((nextLineChartPoint.position.y - lineChartPoint.position.y)) / ((nextLineChartPoint.position.x - lineChartPoint.position.x)) : previousSlope;
CGFloat currentSlope = ((lineChartPoint.position.y - previousLineChartPoint.position.y)) / (lineChartPoint.position.x-previousLineChartPoint.position.x);
BOOL deltaFromNextSlope = ((currentSlope >= (nextSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope <= (nextSlope - kJBLineChartLinesViewSmoothThresholdSlope)));
BOOL deltaFromPreviousSlope = ((currentSlope >= (previousSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope <= (previousSlope - kJBLineChartLinesViewSmoothThresholdSlope)));
BOOL deltaFromPreviousY = (lineChartPoint.position.y >= previousLineChartPoint.position.y + kJBLineChartLinesViewSmoothThresholdVertical) || (lineChartPoint.position.y <= previousLineChartPoint.position.y - kJBLineChartLinesViewSmoothThresholdVertical);
if (smoothLine && deltaFromNextSlope && deltaFromPreviousSlope && deltaFromPreviousY)
{
CGFloat deltaX = lineChartPoint.position.x - previousLineChartPoint.position.x;
CGFloat controlPointX = previousLineChartPoint.position.x + (deltaX / 2);
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];
}
else
{
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
}
lastXPosition = lineChartPoint.position.x;
previousSlope = currentSlope;
}
previousLineChartPoint = lineChartPoint;
index++;
}
@@ -1043,30 +1131,54 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
shapeLayer = [JBLineLayer layer];
}
JBFillLayer *shapeFillLayer = [self fillLayerForLineIndex:lineIndex];
if (shapeFillLayer == nil)
{
shapeFillLayer = [JBFillLayer layer];
}
shapeLayer.tag = lineIndex;
shapeFillLayer.tag = lineIndex;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:lineStyleForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (JBLineChartViewLineStyle)lineChartLineView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLayer.lineStyle = [self.delegate lineChartLinesView:self lineStyleForLineAtLineIndex:lineIndex];
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLayer.strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:lineIndex].CGColor;
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:smoothLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
BOOL smoothLine = [self.delegate lineChartLinesView:self smoothLineAtLineIndex:lineIndex];
if (smoothLine)
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;
if (smoothLine == YES)
{
shapeLayer.lineCap = kCALineCapRound;
shapeLayer.lineJoin = kCALineJoinRound;
shapeFillLayer.lineCap = kCALineCapRound;
shapeFillLayer.lineJoin = kCALineJoinRound;
}
else
{
shapeLayer.lineCap = kCALineCapButt;
shapeLayer.lineJoin = kCALineJoinMiter;
shapeFillLayer.lineCap = kCALineCapButt;
shapeFillLayer.lineJoin = kCALineJoinMiter;
}
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex");
shapeLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex];
shapeLayer.path = path.CGPath;
shapeLayer.frame = self.bounds;
// Continue the path for the fill layer (close and fill)
UIBezierPath *fillPath = [path copy];
[fillPath addLineToPoint:CGPointMake(lastXPosition, self.bounds.size.height - padding)];
[fillPath addLineToPoint:CGPointMake(firstXPosition, self.bounds.size.height - padding)];
shapeFillLayer.path = fillPath.CGPath;
shapeFillLayer.frame = self.bounds;
[self.layer addSublayer:shapeFillLayer];
[self.layer addSublayer:shapeLayer];
lineIndex++;
@@ -1089,12 +1201,14 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
{
_selectedLineIndex = selectedLineIndex;
__weak JBLineChartLinesView* weakSelf = self;
dispatch_block_t adjustLines = ^{
for (CALayer *layer in [self.layer sublayers])
for (CALayer *layer in [weakSelf.layer sublayers])
{
if ([layer isKindOfClass:[JBLineLayer class]])
{
if (((JBLineLayer *)layer).tag == _selectedLineIndex)
if (((NSInteger)((JBLineLayer *)layer).tag) == weakSelf.selectedLineIndex)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectedColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex");
((JBLineLayer *)layer).strokeColor = [self.delegate lineChartLinesView:self selectedColorForLineAtLineIndex:((JBLineLayer *)layer).tag].CGColor;
@@ -1104,7 +1218,22 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
((JBLineLayer *)layer).strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:((JBLineLayer *)layer).tag].CGColor;
((JBLineLayer *)layer).opacity = (_selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity;
((JBLineLayer *)layer).opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity;
}
}
else if ([layer isKindOfClass:[JBFillLayer class]])
{
if (((NSInteger)((JBFillLayer *)layer).tag) == weakSelf.selectedLineIndex)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectedFillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedFillColorForLineAtLineIndex:(NSUInteger)lineIndex");
((JBFillLayer *)layer).fillColor = [self.delegate lineChartLinesView:self selectedFillColorForLineAtLineIndex:((JBLineLayer *)layer).tag].CGColor;
((JBFillLayer *)layer).opacity = 1.0f;
}
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillColorForLineAtLineIndex:(NSUInteger)lineIndex");
((JBFillLayer *)layer).fillColor = [self.delegate lineChartLinesView:self fillColorForLineAtLineIndex:((JBLineLayer *)layer).tag].CGColor;
((JBFillLayer *)layer).opacity = (weakSelf.selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity;
}
}
}
@@ -1139,6 +1268,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
}
}
#pragma mark - View Helpers
- (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex
{
for (CALayer *layer in [self.layer sublayers])
@@ -1154,6 +1285,21 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
return nil;
}
- (JBFillLayer *)fillLayerForLineIndex:(NSUInteger)lineIndex
{
for (CALayer *layer in [self.layer sublayers])
{
if ([layer isKindOfClass:[JBFillLayer class]])
{
if (((JBFillLayer *)layer).tag == lineIndex)
{
return (JBFillLayer *)layer;
}
}
}
return nil;
}
@end
@implementation JBLineChartDotsView
@@ -1197,19 +1343,22 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
if ([self.delegate lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
{
NSMutableArray *mutableDotViews = [NSMutableArray array];
NSUInteger horizontalIndex = 0;
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
{
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex");
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtLineIndex:lineIndex];
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForLineAtLineIndex:lineIndex];
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
[mutableDotViews addObject:dotView];
[self addSubview:dotView];
horizontalIndex++;
}
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
}
@@ -1224,26 +1373,30 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
{
_selectedLineIndex = selectedLineIndex;
__weak JBLineChartDotsView* weakSelf = self;
dispatch_block_t adjustDots = ^{
[self.dotViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[weakSelf.dotViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSUInteger horizontalIndex = 0;
for (JBLineChartDotView *dotView in (NSArray *)obj)
{
if ([key isKindOfClass:[NSNumber class]])
{
NSUInteger lineIndex = [((NSNumber *)key) intValue];
NSInteger lineIndex = [((NSNumber *)key) intValue];
if (_selectedLineIndex == lineIndex)
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForLineAtLineIndex:lineIndex];
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
else
{
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForLineAtLineIndex:lineIndex];
dotView.alpha = (_selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity;
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
}
}
horizontalIndex++;
}
}];
};
@@ -1,17 +1,19 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.1.6"
s.version = "2.7.2"
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
s.homepage = "https://github.com/Jawbone/JBChartView"
s.screenshot = "https://raw.github.com/Jawbone/JBChartView/master/Screenshots/main.jpg"
s.license = { :type => 'Apache', :file => 'LICENSE' }
s.author = { "Terry Worona" => "tworona@jawbone.com" }
s.source = {
:git => "https://github.com/Jawbone/JBChartView.git",
:tag => "v2.1.6"
:tag => "v2.7.2"
}
s.platform = :ios, '7.0'
s.source_files = 'Classes', 'Classes/**/*.{h,m}'
s.platform = :ios, '6.0'
s.source_files = 'Classes/**/*.{h,m}'
s.requires_arc = true
end
@@ -33,6 +33,9 @@
9B6A68DB1829ADE1006DB3BF /* JBBarChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B6A68DA1829ADE1006DB3BF /* JBBarChartView.m */; };
9B6A68DE1829BE63006DB3BF /* JBBarChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B6A68DD1829BE63006DB3BF /* JBBarChartViewController.m */; };
9B6A68E11829BED5006DB3BF /* JBLineChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B6A68E01829BED5006DB3BF /* JBLineChartViewController.m */; };
9B7967EC198313E30003A2B0 /* JBAreaChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B7967EB198313E30003A2B0 /* JBAreaChartViewController.m */; };
9B7967EF198317540003A2B0 /* icon-area-chart.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B7967ED198317540003A2B0 /* icon-area-chart.png */; };
9B7967F0198317540003A2B0 /* icon-area-chart@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B7967EE198317540003A2B0 /* icon-area-chart@2x.png */; };
9BD57BBC18D13D1A00ACFA52 /* JBChartTooltipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BD57BBB18D13D1A00ACFA52 /* JBChartTooltipView.m */; };
9BE0B0AD182AD26400232023 /* JBLineChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BE0B0AC182AD26400232023 /* JBLineChartView.m */; };
9BE0B0C7182B161000232023 /* JBChartHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BE0B0C6182B161000232023 /* JBChartHeaderView.m */; };
@@ -86,6 +89,10 @@
9B6A68DD1829BE63006DB3BF /* JBBarChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBBarChartViewController.m; sourceTree = "<group>"; };
9B6A68DF1829BED5006DB3BF /* JBLineChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBLineChartViewController.h; sourceTree = "<group>"; };
9B6A68E01829BED5006DB3BF /* JBLineChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBLineChartViewController.m; sourceTree = "<group>"; };
9B7967EA198313E30003A2B0 /* JBAreaChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBAreaChartViewController.h; sourceTree = "<group>"; };
9B7967EB198313E30003A2B0 /* JBAreaChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBAreaChartViewController.m; sourceTree = "<group>"; };
9B7967ED198317540003A2B0 /* icon-area-chart.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-area-chart.png"; sourceTree = "<group>"; };
9B7967EE198317540003A2B0 /* icon-area-chart@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-area-chart@2x.png"; sourceTree = "<group>"; };
9BD57BBA18D13D1A00ACFA52 /* JBChartTooltipView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBChartTooltipView.h; sourceTree = "<group>"; };
9BD57BBB18D13D1A00ACFA52 /* JBChartTooltipView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBChartTooltipView.m; sourceTree = "<group>"; };
9BE0B0AB182AD26400232023 /* JBLineChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JBLineChartView.h; path = ../../Classes/JBLineChartView.h; sourceTree = "<group>"; };
@@ -183,6 +190,8 @@
isa = PBXGroup;
children = (
9B603D3B182C6E79000A76D0 /* Base */,
9B7967EA198313E30003A2B0 /* JBAreaChartViewController.h */,
9B7967EB198313E30003A2B0 /* JBAreaChartViewController.m */,
9B6A68DC1829BE63006DB3BF /* JBBarChartViewController.h */,
9B6A68DD1829BE63006DB3BF /* JBBarChartViewController.m */,
9B07251F1829822A0052109B /* JBChartListViewController.h */,
@@ -219,6 +228,8 @@
9B603D44182C7002000A76D0 /* Images */ = {
isa = PBXGroup;
children = (
9B7967ED198317540003A2B0 /* icon-area-chart.png */,
9B7967EE198317540003A2B0 /* icon-area-chart@2x.png */,
9B698F07182D720E003C135F /* icon-arrow.png */,
9B698F08182D720E003C135F /* icon-arrow@2x.png */,
9B698F12182D7DAE003C135F /* icon-bar-chart.png */,
@@ -368,8 +379,10 @@
9B698F18182D7DAE003C135F /* icon-line-chart.png in Resources */,
9B2E530F18218CF20079B9D2 /* InfoPlist.strings in Resources */,
9B698F17182D7DAE003C135F /* icon-bar-chart@2x.png in Resources */,
9B7967EF198317540003A2B0 /* icon-area-chart.png in Resources */,
9B603D47182C7002000A76D0 /* icon-jawbone-logo.png in Resources */,
9B603D48182C7002000A76D0 /* icon-jawbone-logo@2x.png in Resources */,
9B7967F0198317540003A2B0 /* icon-area-chart@2x.png in Resources */,
9B698F19182D7DAE003C135F /* icon-line-chart@2x.png in Resources */,
9B698F0A182D720E003C135F /* icon-arrow@2x.png in Resources */,
);
@@ -398,6 +411,7 @@
9BEE694618D2789E005D9BA7 /* JBBaseChartViewController.m in Sources */,
9B6A68E11829BED5006DB3BF /* JBLineChartViewController.m in Sources */,
9B2E533F18218D310079B9D2 /* AppDelegate.m in Sources */,
9B7967EC198313E30003A2B0 /* JBAreaChartViewController.m in Sources */,
9BD57BBC18D13D1A00ACFA52 /* JBChartTooltipView.m in Sources */,
9B603D4B182C7117000A76D0 /* JBBaseViewController.m in Sources */,
9B0725211829822A0052109B /* JBChartListViewController.m in Sources */,
@@ -498,7 +512,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "JBChartViewDemo/JBChartViewDemo-Prefix.pch";
INFOPLIST_FILE = "JBChartViewDemo/JBChartViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -512,7 +526,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "JBChartViewDemo/JBChartViewDemo-Prefix.pch";
INFOPLIST_FILE = "JBChartViewDemo/JBChartViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -10,7 +10,8 @@
typedef NS_ENUM(NSInteger, JBChartTableCellType){
JBChartTableCellTypeLineChart,
JBChartTableCellTypeBarChart
JBChartTableCellTypeBarChart,
JBChartTableCellTypeAreaChart
};
@interface JBChartTableCell : UITableViewCell
@@ -22,7 +22,21 @@
- (void)setType:(JBChartTableCellType)type
{
_type = type;
self.accessoryView = [[UIImageView alloc] initWithImage:_type == JBChartTableCellTypeBarChart ? [UIImage imageNamed:kJBImageIconBarChart] : [UIImage imageNamed:kJBImageIconLineChart]];
UIImage *image = nil;
switch (type) {
case JBChartTableCellTypeBarChart:
image = [UIImage imageNamed:kJBImageIconBarChart];
break;
case JBChartTableCellTypeLineChart:
image = [UIImage imageNamed:kJBImageIconLineChart];
break;
case JBChartTableCellTypeAreaChart:
image = [UIImage imageNamed:kJBImageIconAreaChart];
break;
default:
break;
}
self.accessoryView = [[UIImageView alloc] initWithImage:image];
}
@end
@@ -32,6 +32,21 @@
#define kJBColorLineChartDefaultDashedLineColor [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]
#define kJBColorLineChartDefaultDashedSelectedLineColor [UIColor colorWithWhite:1.0 alpha:1.0]
#define mark - Area Chart
#define kJBColorAreaChartControllerBackground UIColorFromHex(0xb7e3e4)
#define kJBColorAreaChartBackground UIColorFromHex(0xb7e3e4)
#define kJBColorAreaChartHeader UIColorFromHex(0x1c474e)
#define kJBColorAreaChartHeaderSeparatorColor UIColorFromHex(0x8eb6b7)
#define kJBColorAreaChartDefaultSunLineColor [UIColor clearColor]
#define kJBColorAreaChartDefaultSunAreaColor [UIColorFromHex(0xfcfb3a) colorWithAlphaComponent:0.5]
#define kJBColorAreaChartDefaultSunSelectedLineColor [UIColor clearColor]
#define kJBColorAreaChartDefaultSunSelectedAreaColor UIColorFromHex(0xfcfb3a)
#define kJBColorAreaChartDefaultMoonLineColor [UIColor clearColor]
#define kJBColorAreaChartDefaultMoonAreaColor [[UIColor blackColor] colorWithAlphaComponent:0.5]
#define kJBColorAreaChartDefaultMoonSelectedLineColor [UIColor clearColor]
#define kJBColorAreaChartDefaultMoonSelectedAreaColor [UIColor blackColor]
#pragma mark - Tooltips
#define kJBColorTooltipColor [UIColor colorWithWhite:1.0 alpha:0.9]
@@ -15,6 +15,7 @@
#define kJBStringLabel2012 localize(@"label.2012", @"2012")
#define kJBStringLabelAverageMonthlyTemperature localize(@"label.average.monthly.temperature", @"Average Monthly Temperature")
#define kJBStringLabelWorldwide2012 localize(@"label.worldwide.2013", @"Worldwide - 2012")
#define kJBStringLabelWorldwide2011 localize(@"label.worldwide.2013", @"Worldwide - 2011")
#define kJBStringLabelWorldwideAverage localize(@"label.worldwide.average", @"Worldwide Average")
#define kJBStringLabelDegreesFahrenheit localize(@"label.degrees.fahrenheit", @"%d%@F")
#define kJBStringLabelDegreeSymbol localize(@"label.degree.symbol", @"\u00B0")
@@ -27,3 +28,13 @@
#define kJBStringLabelMm localize(@"label.mm", @"mm")
#define kJBStringLabelMetropolitanAverage localize(@"label.metropolitan.average", @"Metropolitan Average")
#define kJBStringLabelNationalAverage localize(@"label.national.average", @"National Average")
#pragma mark - Labels (Area Chart)
#define kJBStringLabel2011 localize(@"label.2011", @"2011")
#define kJBStringLabelSeattle2014 localize(@"label.seattle.2014", @"Seattle - 2014")
#define kJBStringLabelAverageShineHoursOfSunMoon localize(@"label.average.shine.hours.of.sun.moon", @"Average Shine Hours of Sun/Moon")
#define kJBStringLabelAverageShineHours localize(@"label.average.shine.hours", @"Average Shine Hours")
#define kJBStringLabelHours localize(@"label.hours", @"h")
#define kJBStringLabelMoon localize(@"label.moon", @"Moon")
#define kJBStringLabelSun localize(@"label.sun", @"Sun")
@@ -12,3 +12,4 @@
#define kJBImageIconArrow @"icon-arrow.png"
#define kJBImageIconLineChart @"icon-line-chart.png"
#define kJBImageIconBarChart @"icon-bar-chart.png"
#define kJBImageIconAreaChart @"icon-area-chart.png"
@@ -8,6 +8,10 @@
#import "JBBaseNavigationController.h"
// Numerics
NSInteger const kJBBaseNavigationControllerBarTintColorMinSystemVersion = 7;
NSInteger const kJBBaseNavigationControllerTintColorMinSystemVersion = 7;
@implementation JBBaseNavigationController
#pragma mark - Alloc/Init
@@ -18,9 +22,23 @@
if (self)
{
self.navigationBar.translucent = NO;
[[UINavigationBar appearance] setBarTintColor:kJBColorNavigationTint];
[[UINavigationBar appearance] setTintColor:kJBColorNavigationBarTint];
self.interactivePopGestureRecognizer.enabled = NO;
// Bar tint (iOS 7)
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= kJBBaseNavigationControllerBarTintColorMinSystemVersion)
{
[[UINavigationBar appearance] setBarTintColor:kJBColorNavigationTint];
}
// Tint (iOS 7)
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= kJBBaseNavigationControllerTintColorMinSystemVersion)
{
[[UINavigationBar appearance] setTintColor:kJBColorNavigationBarTint];
}
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.enabled = NO;
}
}
return self;
}
@@ -19,7 +19,9 @@
- (void)loadView
{
[super loadView];
self.edgesForExtendedLayout = UIRectEdgeTop;
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeTop;
}
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kJBImageIconJawboneLogo]];
}
@@ -0,0 +1,13 @@
//
// JBAreaChartViewController.h
// JBChartViewDemo
//
// Created by Lars Ott on 21.04.14.
// Copyright (c) 2014 Jawbone. All rights reserved.
//
#import "JBBaseChartViewController.h"
@interface JBAreaChartViewController : JBBaseChartViewController
@end
@@ -0,0 +1,285 @@
//
// JBAreaChartViewController.m
// JBChartViewDemo
//
// Created by Lars Ott on 21.04.14.
// Copyright (c) 2014 Jawbone. All rights reserved.
//
#import "JBAreaChartViewController.h"
// Views
#import "JBLineChartView.h"
#import "JBChartHeaderView.h"
#import "JBLineChartFooterView.h"
#import "JBChartInformationView.h"
#define ARC4RANDOM_MAX 0x100000000
typedef NS_ENUM(NSInteger, JBLineChartLine){
JBLineChartLineSun,
JBLineChartLineMoon,
JBLineChartLineCount
};
// Numerics
CGFloat const kJBAreaChartViewControllerChartHeight = 250.0f;
CGFloat const kJBAreaChartViewControllerChartPadding = 10.0f;
CGFloat const kJBAreaChartViewControllerChartHeaderHeight = 75.0f;
CGFloat const kJBAreaChartViewControllerChartHeaderPadding = 20.0f;
CGFloat const kJBAreaChartViewControllerChartFooterHeight = 20.0f;
CGFloat const kJBAreaChartViewControllerChartLineWidth = 2.0f;
NSInteger const kJBAreaChartViewControllerMaxNumChartPoints = 12;
// Strings
NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
@interface JBAreaChartViewController () <JBLineChartViewDelegate, JBLineChartViewDataSource>
@property (nonatomic, strong) JBLineChartView *lineChartView;
@property (nonatomic, strong) JBChartInformationView *informationView;
@property (nonatomic, strong) NSArray *chartData;
@property (nonatomic, strong) NSArray *monthlySymbols;
// Buttons
- (void)chartToggleButtonPressed:(id)sender;
// Helpers
- (void)initFakeData;
- (NSArray *)largestLineData; // largest collection of fake line data
@end
@implementation JBAreaChartViewController
#pragma mark - Alloc/Init
- (id)init
{
self = [super init];
if (self)
{
[self initFakeData];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self initFakeData];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[self initFakeData];
}
return self;
}
#pragma mark - Data
- (void)initFakeData
{
NSMutableArray *mutableLineCharts = [NSMutableArray array];
for (int lineIndex=0; lineIndex<JBLineChartLineCount; lineIndex++)
{
NSMutableArray *mutableChartData = [NSMutableArray array];
for (int i=0; i<kJBAreaChartViewControllerMaxNumChartPoints; i++)
{
[mutableChartData addObject:[NSNumber numberWithFloat:((double)arc4random() / ARC4RANDOM_MAX) * 12]]; // random number between 0 and 12
}
[mutableLineCharts addObject:mutableChartData];
}
_chartData = [NSArray arrayWithArray:mutableLineCharts];
_monthlySymbols = [[[NSDateFormatter alloc] init] shortMonthSymbols];
}
- (NSArray *)largestLineData
{
NSArray *largestLineData = nil;
for (NSArray *lineData in self.chartData)
{
if ([lineData count] > [largestLineData count])
{
largestLineData = lineData;
}
}
return largestLineData;
}
#pragma mark - View Lifecycle
- (void)loadView
{
[super loadView];
self.view.backgroundColor = kJBColorLineChartControllerBackground;
self.navigationItem.rightBarButtonItem = [self chartToggleButtonWithTarget:self action:@selector(chartToggleButtonPressed:)];
self.lineChartView = [[JBLineChartView alloc] init];
self.lineChartView.frame = CGRectMake(kJBAreaChartViewControllerChartPadding, kJBAreaChartViewControllerChartPadding, self.view.bounds.size.width - (kJBAreaChartViewControllerChartPadding * 2), kJBAreaChartViewControllerChartHeight);
self.lineChartView.delegate = self;
self.lineChartView.dataSource = self;
self.lineChartView.headerPadding =kJBAreaChartViewControllerChartHeaderPadding;
self.lineChartView.backgroundColor = kJBColorLineChartBackground;
JBChartHeaderView *headerView = [[JBChartHeaderView alloc] initWithFrame:CGRectMake(kJBAreaChartViewControllerChartPadding, ceil(self.view.bounds.size.height * 0.5) - ceil(kJBAreaChartViewControllerChartHeaderHeight * 0.5), self.view.bounds.size.width - (kJBAreaChartViewControllerChartPadding * 2), kJBAreaChartViewControllerChartHeaderHeight)];
headerView.titleLabel.text = [kJBStringLabelAverageShineHoursOfSunMoon uppercaseString];
headerView.titleLabel.textColor = kJBColorLineChartHeader;
headerView.titleLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.25];
headerView.titleLabel.shadowOffset = CGSizeMake(0, 1);
headerView.subtitleLabel.text = kJBStringLabel2011;
headerView.subtitleLabel.textColor = kJBColorLineChartHeader;
headerView.subtitleLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.25];
headerView.subtitleLabel.shadowOffset = CGSizeMake(0, 1);
headerView.separatorColor = kJBColorLineChartHeaderSeparatorColor;
self.lineChartView.headerView = headerView;
JBLineChartFooterView *footerView = [[JBLineChartFooterView alloc] initWithFrame:CGRectMake(kJBAreaChartViewControllerChartPadding, ceil(self.view.bounds.size.height * 0.5) - ceil(kJBAreaChartViewControllerChartFooterHeight * 0.5), self.view.bounds.size.width - (kJBAreaChartViewControllerChartPadding * 2), kJBAreaChartViewControllerChartFooterHeight)];
footerView.backgroundColor = [UIColor clearColor];
footerView.leftLabel.text = [[self.monthlySymbols firstObject] uppercaseString];
footerView.leftLabel.textColor = [UIColor whiteColor];
footerView.rightLabel.text = [[self.monthlySymbols lastObject] uppercaseString];;
footerView.rightLabel.textColor = [UIColor whiteColor];
footerView.sectionCount = [[self chartData] count];
self.lineChartView.footerView = footerView;
[self.view addSubview:self.lineChartView];
self.informationView = [[JBChartInformationView alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, CGRectGetMaxY(self.lineChartView.frame), self.view.bounds.size.width, self.view.bounds.size.height - CGRectGetMaxY(self.lineChartView.frame) - CGRectGetMaxY(self.navigationController.navigationBar.frame))];
[self.informationView setValueAndUnitTextColor:[UIColor colorWithWhite:1.0 alpha:0.75]];
[self.informationView setTitleTextColor:kJBColorLineChartHeader];
[self.informationView setTextShadowColor:nil];
[self.informationView setSeparatorColor:kJBColorLineChartHeaderSeparatorColor];
[self.view addSubview:self.informationView];
[self.lineChartView reloadData];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.lineChartView setState:JBChartViewStateExpanded];
}
#pragma mark - JBLineChartViewDataSource
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView
{
return [self.chartData count];
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex
{
return [[self.chartData objectAtIndex:lineIndex] count];
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
{
return NO;
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex
{
return YES;
}
#pragma mark - JBLineChartViewDelegate
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
return [[[self.chartData objectAtIndex:lineIndex] objectAtIndex:horizontalIndex] floatValue];
}
- (void)lineChartView:(JBLineChartView *)lineChartView didSelectLineAtIndex:(NSUInteger)lineIndex horizontalIndex:(NSUInteger)horizontalIndex touchPoint:(CGPoint)touchPoint
{
NSNumber *valueNumber = [[self.chartData objectAtIndex:lineIndex] objectAtIndex:horizontalIndex];
[self.informationView setValueText:[NSString stringWithFormat:@"%.1f", [valueNumber floatValue]] unitText:kJBStringLabelHours];
[self.informationView setTitleText:lineIndex == JBLineChartLineSun ? kJBStringLabelSun : kJBStringLabelMoon];
[self.informationView setHidden:NO animated:YES];
[self setTooltipVisible:YES animated:YES atTouchPoint:touchPoint];
[self.tooltipView setText:[[self.monthlySymbols objectAtIndex:horizontalIndex] uppercaseString]];
}
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
{
[self.informationView setHidden:YES animated:YES];
[self setTooltipVisible:NO animated:YES];
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunLineColor: kJBColorAreaChartDefaultMoonLineColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView fillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunAreaColor : kJBColorAreaChartDefaultMoonAreaColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunLineColor: kJBColorAreaChartDefaultMoonLineColor;
}
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex
{
return kJBAreaChartViewControllerChartLineWidth;
}
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
{
return [UIColor whiteColor];
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunSelectedLineColor: kJBColorAreaChartDefaultMoonSelectedLineColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionFillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunSelectedAreaColor : kJBColorAreaChartDefaultMoonSelectedAreaColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunSelectedLineColor: kJBColorAreaChartDefaultMoonSelectedLineColor;
}
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
{
return JBLineChartViewLineStyleSolid;
}
#pragma mark - Buttons
- (void)chartToggleButtonPressed:(id)sender
{
UIView *buttonImageView = [self.navigationItem.rightBarButtonItem valueForKey:kJBAreaChartViewControllerNavButtonViewKey];
buttonImageView.userInteractionEnabled = NO;
CGAffineTransform transform = self.lineChartView.state == JBChartViewStateExpanded ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
buttonImageView.transform = transform;
[self.lineChartView setState:self.lineChartView.state == JBChartViewStateExpanded ? JBChartViewStateCollapsed : JBChartViewStateExpanded animated:YES callback:^{
buttonImageView.userInteractionEnabled = YES;
}];
}
#pragma mark - Overrides
- (JBChartView *)chartView
{
return self.lineChartView;
}
@end
@@ -21,7 +21,7 @@ CGFloat const kJBBarChartViewControllerChartHeaderHeight = 80.0f;
CGFloat const kJBBarChartViewControllerChartHeaderPadding = 10.0f;
CGFloat const kJBBarChartViewControllerChartFooterHeight = 25.0f;
CGFloat const kJBBarChartViewControllerChartFooterPadding = 5.0f;
CGFloat const kJBBarChartViewControllerBarPadding = 1;
NSUInteger kJBBarChartViewControllerBarPadding = 1;
NSInteger const kJBBarChartViewControllerNumBars = 12;
NSInteger const kJBBarChartViewControllerMaxBarHeight = 10;
NSInteger const kJBBarChartViewControllerMinBarHeight = 5;
@@ -107,6 +107,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
self.barChartView.delegate = self;
self.barChartView.dataSource = self;
self.barChartView.headerPadding = kJBBarChartViewControllerChartHeaderPadding;
self.barChartView.minimumValue = 0.0f;
self.barChartView.backgroundColor = kJBColorBarChartBackground;
JBChartHeaderView *headerView = [[JBChartHeaderView alloc] initWithFrame:CGRectMake(kJBBarChartViewControllerChartPadding, ceil(self.view.bounds.size.height * 0.5) - ceil(kJBBarChartViewControllerChartHeaderHeight * 0.5), self.view.bounds.size.width - (kJBBarChartViewControllerChartPadding * 2), kJBBarChartViewControllerChartHeaderHeight)];
@@ -136,13 +137,6 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
[self.barChartView setState:JBChartViewStateExpanded];
}
#pragma mark - JBBarChartViewDelegate
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index
{
return [[self.chartData objectAtIndex:index] floatValue];
}
#pragma mark - JBBarChartViewDataSource
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView
@@ -150,23 +144,6 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
return kJBBarChartViewControllerNumBars;
}
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView
{
return kJBBarChartViewControllerBarPadding;
}
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index
{
UIView *barView = [[UIView alloc] init];
barView.backgroundColor = (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
return barView;
}
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView
{
return [UIColor whiteColor];
}
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint
{
NSNumber *valueNumber = [self.chartData objectAtIndex:index];
@@ -177,12 +154,34 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
[self.tooltipView setText:[[self.monthlySymbols objectAtIndex:index] uppercaseString]];
}
- (void)didUnselectBarChartView:(JBBarChartView *)barChartView
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView
{
[self.informationView setHidden:YES animated:YES];
[self setTooltipVisible:NO animated:YES];
}
#pragma mark - JBBarChartViewDelegate
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index
{
return [[self.chartData objectAtIndex:index] floatValue];
}
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index
{
return (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
}
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView
{
return [UIColor whiteColor];
}
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView
{
return kJBBarChartViewControllerBarPadding;
}
#pragma mark - Buttons
- (void)chartToggleButtonPressed:(id)sender
@@ -11,6 +11,7 @@
// Controllers
#import "JBBarChartViewController.h"
#import "JBLineChartViewController.h"
#import "JBAreaChartViewController.h"
// Views
#import "JBChartTableCell.h"
@@ -18,6 +19,7 @@
typedef NS_ENUM(NSInteger, JBChartListViewControllerRow){
JBChartListViewControllerRowLineChart,
JBChartListViewControllerRowBarChart,
JBChartListViewControllerRowAreaChart,
JBChartListViewControllerRowCount
};
@@ -50,10 +52,34 @@ NSInteger const kJBChartListViewControllerCellHeight = 100;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
JBChartTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kJBChartListViewControllerCellIdentifier forIndexPath:indexPath];
cell.textLabel.text = indexPath.row == JBChartListViewControllerRowLineChart ? kJBStringLabelAverageDailyRainfall : kJBStringLabelAverageMonthlyTemperature;
cell.detailTextLabel.text = indexPath.row == JBChartListViewControllerRowLineChart ? kJBStringLabelSanFrancisco2013 : kJBStringLabelWorldwide2012;
cell.type = indexPath.row == JBChartListViewControllerRowLineChart ? JBChartTableCellTypeLineChart : JBChartTableCellTypeBarChart;
JBChartTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kJBChartListViewControllerCellIdentifier forIndexPath:indexPath];
NSString *text = nil;
NSString *detailText = nil;
JBChartTableCellType type = -1;
switch (indexPath.row) {
case JBChartListViewControllerRowLineChart:
text = kJBStringLabelAverageDailyRainfall;
detailText = kJBStringLabelSanFrancisco2013;
type = JBChartTableCellTypeLineChart;
break;
case JBChartListViewControllerRowBarChart:
text = kJBStringLabelAverageMonthlyTemperature;
detailText = kJBStringLabelWorldwide2012;
type = JBChartTableCellTypeBarChart;
break;
case JBChartListViewControllerRowAreaChart:
text = kJBStringLabelAverageShineHours;
detailText = kJBStringLabelWorldwide2011;
type = JBChartTableCellTypeAreaChart;
break;
default:
break;
}
cell.textLabel.text = text;
cell.detailTextLabel.text = detailText;
cell.type = type;
return cell;
}
@@ -78,6 +104,11 @@ NSInteger const kJBChartListViewControllerCellHeight = 100;
JBBarChartViewController *barChartController = [[JBBarChartViewController alloc] init];
[self.navigationController pushViewController:barChartController animated:YES];
}
else if (indexPath.row == JBChartListViewControllerRowAreaChart)
{
JBAreaChartViewController *areaChartController = [[JBAreaChartViewController alloc] init];
[self.navigationController pushViewController:areaChartController animated:YES];
}
}
@end
@@ -171,6 +171,28 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
[self.lineChartView setState:JBChartViewStateExpanded];
}
#pragma mark - JBLineChartViewDataSource
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView
{
return [self.chartData count];
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex
{
return [[self.chartData objectAtIndex:lineIndex] count];
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
{
return lineIndex == JBLineChartViewLineStyleDashed;
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex
{
return lineIndex == JBLineChartViewLineStyleSolid;
}
#pragma mark - JBLineChartViewDelegate
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
@@ -188,29 +210,22 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
[self.tooltipView setText:[[self.daysOfWeek objectAtIndex:horizontalIndex] uppercaseString]];
}
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
{
[self.informationView setHidden:YES animated:YES];
[self setTooltipVisible:NO animated:YES];
}
#pragma mark - JBLineChartViewDataSource
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView
{
return [self.chartData count];
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex
{
return [[self.chartData objectAtIndex:lineIndex] count];
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
}
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSolid) ? kJBLineChartViewControllerChartSolidLineWidth: kJBLineChartViewControllerChartDashedLineWidth;
@@ -231,21 +246,16 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidSelectedLineColor: kJBColorLineChartDefaultDashedSelectedLineColor;
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidSelectedLineColor: kJBColorLineChartDefaultDashedSelectedLineColor;
}
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
{
return (lineIndex == JBLineChartLineSolid) ? JBLineChartViewLineStyleSolid : JBLineChartViewLineStyleDashed;
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
{
return lineIndex == JBLineChartViewLineStyleDashed;
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex
{
return lineIndex == JBLineChartViewLineStyleSolid;
}
#pragma mark - Buttons
- (void)chartToggleButtonPressed:(id)sender
@@ -10,7 +10,6 @@
@interface JBBarChartFooterView : UIView
@property (nonatomic, strong) UIColor *footerBackgroundColor; // footer background (default = black)
@property (nonatomic, assign) CGFloat padding; // label left & right padding (default = 4.0)
@property (nonatomic, readonly) UILabel *leftLabel;
@property (nonatomic, readonly) UILabel *rightLabel;
@@ -10,30 +10,12 @@
// Numerics
CGFloat const kJBBarChartFooterPolygonViewDefaultPadding = 4.0f;
CGFloat const kJBBarChartFooterPolygonViewArrowHeight = 8.0f;
CGFloat const kJBBarChartFooterPolygonViewArrowWidth = 16.0f;
// Colors
static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
static UIColor *kJBBarChartFooterViewDefaultBackgroundColor = nil;
@protocol JBBarChartFooterPolygonViewDelegate;
@interface JBBarChartFooterView ()
@interface JBBarChartFooterPolygonView : UIView
@property (nonatomic, weak) id<JBBarChartFooterPolygonViewDelegate> delegate;
@end
@protocol JBBarChartFooterPolygonViewDelegate <NSObject>
- (UIColor *)backgroundColorForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView;
- (CGFloat)paddingForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView;
@end
@interface JBBarChartFooterView () <JBBarChartFooterPolygonViewDelegate>
@property (nonatomic, strong) JBBarChartFooterPolygonView *polygonView;
@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *rightLabel;
@@ -47,7 +29,7 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
{
if (self == [JBBarChartFooterView class])
{
kJBBarChartFooterPolygonViewDefaultBackgroundColor = kJBColorBarChartControllerBackground;
kJBBarChartFooterViewDefaultBackgroundColor = kJBColorBarChartControllerBackground;
}
}
@@ -56,15 +38,10 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = kJBBarChartFooterPolygonViewDefaultBackgroundColor;
self.backgroundColor = kJBBarChartFooterViewDefaultBackgroundColor;
_footerBackgroundColor = kJBBarChartFooterPolygonViewDefaultBackgroundColor;
_padding = kJBBarChartFooterPolygonViewDefaultPadding;
_polygonView = [[JBBarChartFooterPolygonView alloc] initWithFrame:CGRectMake(self.bounds.origin.x, self.bounds.origin.y - kJBBarChartFooterPolygonViewArrowHeight, self.bounds.size.width, self.bounds.size.height + kJBBarChartFooterPolygonViewArrowHeight)];
_polygonView.delegate = self;
[self addSubview:_polygonView];
_leftLabel = [[UILabel alloc] init];
_leftLabel.adjustsFontSizeToFitWidth = YES;
_leftLabel.font = kJBFontFooterLabel;
@@ -100,95 +77,4 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
self.rightLabel.frame = CGRectMake(CGRectGetMaxX(_leftLabel.frame), yOffset, width, self.bounds.size.height);
}
#pragma mark - JBBarChartFooterPolygonViewDelegate
- (UIColor *)backgroundColorForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView
{
return self.footerBackgroundColor;
}
- (CGFloat)paddingForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView
{
return self.padding;
}
@end
@implementation JBBarChartFooterPolygonView
#pragma mark - Alloc/Init
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
}
return self;
}
#pragma mark - Drawing
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
// Background gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.0, 1.0 };
NSAssert([self.delegate respondsToSelector:@selector(backgroundColorForChartFooterPolygonView:)], @"JBChartFooterPolygonView // delegate must implement - (UIColor *)backgroundColorForChartFooterPolygonView");
NSAssert([self.delegate respondsToSelector:@selector(paddingForChartFooterPolygonView:)], @"JBChartFooterPolygonView // delegate must implement - (CGFloat)paddingForChartFooterPolygonView");
UIColor *bgColor = [self.delegate backgroundColorForChartFooterPolygonView:self];
NSArray *colors = @[(__bridge id)bgColor.CGColor, (__bridge id)bgColor.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
// Polygon shape
CGFloat xOffset = self.bounds.origin.x;
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
CGFloat padding = [self.delegate paddingForChartFooterPolygonView:self];
NSArray *polygonPoints = @[[NSValue valueWithCGPoint:CGPointMake(xOffset, height)],
[NSValue valueWithCGPoint:CGPointMake(xOffset, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding + ceil(kJBBarChartFooterPolygonViewArrowWidth * 0.5), 0)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding + kJBBarChartFooterPolygonViewArrowWidth, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width - padding - kJBBarChartFooterPolygonViewArrowWidth, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width - padding - ceil(kJBBarChartFooterPolygonViewArrowWidth * 0.5), 0.0)],
[NSValue valueWithCGPoint:CGPointMake(width - padding, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width, height)],
[NSValue valueWithCGPoint:CGPointMake(xOffset, height)]];
// Draw polygon
NSValue *pointValue = polygonPoints[0];
CGContextSaveGState(context);
{
NSInteger index = 0;
for (pointValue in polygonPoints)
{
CGPoint point = [pointValue CGPointValue];
if (index == 0)
{
CGContextMoveToPoint(context, point.x, point.y);
}
else
{
CGContextAddLineToPoint(context, point.x, point.y);
}
index++;
}
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)), CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)), 0);
}
CGContextRestoreGState(context);
CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace);
}
@end
@@ -261,8 +261,25 @@ static UIColor *kJBChartInformationViewShadowColor = nil;
- (void)layoutSubviews
{
CGSize valueLabelSize = [self.valueLabel.text sizeWithAttributes:@{NSFontAttributeName:self.valueLabel.font}];
CGSize unitLabelSize = [self.unitLabel.text sizeWithAttributes:@{NSFontAttributeName:self.unitLabel.font}];
CGSize valueLabelSize = CGSizeZero;
if ([self.valueLabel.text respondsToSelector:@selector(sizeWithAttributes:)])
{
valueLabelSize = [self.valueLabel.text sizeWithAttributes:@{NSFontAttributeName:self.valueLabel.font}];
}
else
{
valueLabelSize = [self.valueLabel.text sizeWithFont:self.valueLabel.font];
}
CGSize unitLabelSize = CGSizeZero;
if ([self.unitLabel.text respondsToSelector:@selector(sizeWithAttributes:)])
{
unitLabelSize = [self.unitLabel.text sizeWithAttributes:@{NSFontAttributeName:self.unitLabel.font}];
}
else
{
unitLabelSize = [self.unitLabel.text sizeWithFont:self.unitLabel.font];
}
CGFloat xOffset = ceil((self.bounds.size.width - (valueLabelSize.width + unitLabelSize.width)) * 0.5);
Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+71 -15
View File
@@ -1,7 +1,7 @@
# JBChartView
<br/>
<p align="center">
<img src="https://raw.github.com/Jawbone/JBChartView/master/Screenshots/main.png">
<img src="https://raw.github.com/Jawbone/JBChartView/master/Screenshots/main.jpg">
</p>
Introducing <b>JBChartView - </b> Jawbone's iOS-based charting library for both line and bar graphs. It is easy to set-up, and highly customizable.
@@ -18,13 +18,18 @@ Refer to the <a href="https://github.com/Jawbone/JBChartView/blob/master/CHANGEL
## Requirements
- Requires iOS 7 or later
- Requires iOS 6 or later
- Requires Automatic Reference Counting (ARC)
## Demo
## Demo Project
Build and run the <i>JBChartViewDemo</i> project in Xcode. The demo demonstrates the use of both the line and bar charts. It also outlines how a chart's appearance can be customized.
## More Demos
- <a href="https://github.com/Jawbone/anscombe-quartet-ios">Amsombe's Quartet</a>: project showcasing the use of JBChartView in the classic data visualization example known as Anscombe's Quartet.
- <a href="https://github.com/Jawbone/spark-friends-ios">Spark Friends</a>: project showcasing the use of JBChartView in the context of sparklines and (fake) user step data.
## Installation
<a href="http://cocoapods.org/" target="_blank">CocoaPods</a> is the recommended method of installing JBChartView.
@@ -37,8 +42,8 @@ Simply add the following line to your <code>Podfile</code>:
Your Podfile should look something like:
platform :ios, '7.0'
pod 'JBChartView', '~> 2.1.6'
platform :ios, '6.0'
pod 'JBChartView', '~> 2.7.2'
### The Old School Way
@@ -52,25 +57,36 @@ The simpliest way to use JBChartView with your application is to drag and drop t
All JBChartView implementations have a similiar data source and delgate pattern to <i>UITableView</i>. If you're familiar with using a <i>UITableView</i> or <i>UITableViewController</i>, using a JBChartView subclass should be a breeze!
#### Swift Projects
To use JBCartView in a Swift project add the following to your bridging header (JBChartView-Bridging-Header.h):
#import <UIKit/UIKit.h>
#import "JBChartView/JBChartView.h"
#import "JBChartView/JBBarChartView.h"
#import "JBChartView/JBLineChartView.h"
For more information about adding bridging headers see <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html" target="_blank">Swift and Objective-C in the Same Project</a>.
#### JBBarChartView
To initialize a <i>JBBarChartView</i>, you only need a few lines of code (see below). Bar charts can also be initialized via a <b>nib</b> or with a <b>frame</b>.
JBBarChartView *barChartView = [[JBBarChartView alloc] init];
barChartView.delegate = self;
barChartView.dataSource = self;
barChartView.delegate = self;
[self addSubview:barChartView];
At a minimum, you need to inform the data source how many bars are in the chart:
- (NSInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView
{
return ...; // number of bars in chart
}
Secondly, you need to inform the delegate the height of each bar (automatically normalized across the entire chart):
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index
{
return ...; // height of bar at index
}
@@ -85,8 +101,8 @@ Lastly, ensure you have set the *frame* of your barChartView & call *reloadData*
Similiarily, to initialize a JBLineChartView, you only need a few lines of code (see below). Line charts can also be initialized via a <b>nib</b> or with a <b>frame</b>.
JBLineChartView *lineChartView = [[JBLineChartView alloc] init];
lineChartView.delegate = self;
lineChartView.dataSource = self;
lineChartView.delegate = self;
[self addSubview:lineChartView];
At a minimum, you need to inform the data source how many lines and vertical data points (for each line) are in the chart:
@@ -140,6 +156,10 @@ By default, a chart's bars will be black and flat. They can be customized by sup
{
return ...; // color of line in chart
}
If you don't require a custom UIView, simply supply a color for the bar instead:
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
Furthermore, the color of the selection bar (on touch events) can be customized via the <i>optional</i> protocol:
@@ -155,7 +175,7 @@ Lastly, a bar chart's selection events are delegated back via:
// Update view
}
- (void)didUnselectBarChartView:(JBBarChartView *)barChartView
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView
{
// Update view
}
@@ -171,6 +191,11 @@ The color, width and style of each line in the chart can be customized via the <
return ...; // color of line in chart
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView fillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return ...; // color of area under line in chart
}
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex
{
return ...; // width of line in chart
@@ -181,27 +206,43 @@ The color, width and style of each line in the chart can be customized via the <
return ...; // style of line in chart
}
Furthermore, the color of the selection bar and line can be customized via the <i>optional</i> protocols:
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 *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
{
return ...; // color of selection view
}
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView
{
return ...; // width of selection view
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return ...; // color of selected line
}
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionFillColorForLineAtLineIndex:(NSUInteger)lineIndex
{
return ...; // color of 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;
To customize the size of each dot, implement (default is 3x the line width):
To customize the size of each dot (default 3x the line width), implement:
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
As well, by default, each line will have squared off end caps and connection points. To enable line smoothing:
To customize the color of each dot during selection and non-selection events (default is white and black respectively), implement:
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
As well, by default, each line will have squared off end caps and connection points. To enable rounded connections and end caps:
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
@@ -212,12 +253,27 @@ Lastly, a line chart's selection events are delegated back via:
// Update view
}
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
{
// Update view
}
The <b>touchPoint</b> is especially important as it allows you to add custom elements to your chart during selection events. Refer to the demo project (<b>JBLineChartViewController</b>) to see how a tooltip can be used to display additional information during selection events.
## Minimum & Maximum Values
By default, a chart's minimum and maximum values are equal to the min and max supplied by the dataSource. You can override either value via:
- (void)setMinimumValue:(CGFloat)minimumValue;
- (void)setMaximumValue:(CGFloat)maximumValue;
If value(s) are supplied, they must be >= 0, otherwise an assertion will be thrown. To reset the values back to their original defaults:
- (void)resetMinimumValue;
- (void)resetMaximumValue;
The min/max values are clamped to the ceiling and floor of the actual min/max values of the chart's data source; for example, if a maximumValue of 20 is supplied & the chart's actual max is 100, then 100 will be used. For min/max modifications to take effect, reloadData must be called.
## License
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB