Compare commits

...

38 Commits

Author SHA1 Message Date
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
27 changed files with 862 additions and 270 deletions
+24
View File
@@ -1,5 +1,29 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.0">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>.
+52 -52
View File
@@ -9,13 +9,13 @@
// Views
#import "JBChartView.h"
@protocol JBBarChartViewDelegate;
@protocol JBBarChartViewDataSource;
@protocol JBBarChartViewDelegate;
@interface JBBarChartView : JBChartView
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
/**
* Vertical highlight overlayed on bar during touch events.
@@ -26,44 +26,6 @@
@end
@protocol JBBarChartViewDelegate <NSObject>
@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.
* @param index The 0-based index of a given bar (left to right, x-axis).
*
* @return The y-axis height of the supplied bar index (x-axis)
*/
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index;
@optional
/**
* Occurs when a touch gesture event occurs on a given bar (chart must be expanded).
* and the selection must occur within the bounds of the chart.
*
* @param barChartView A bar chart object informing the delegate about the new selection.
* @param index The 0-based index of a given bar (left to right, x-axis).
* @param touchPoint The touch point in relation to the chart's bounds (excludes footer and header).
*/
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint;
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index;
/**
* 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.
*/
- (void)didUnselectBarChartView:(JBBarChartView *)barChartView;
@end
@protocol JBBarChartViewDataSource <NSObject>
@required
@@ -79,17 +41,6 @@
@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.
*
@@ -102,6 +53,44 @@
*/
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index;
@end
@protocol JBBarChartViewDelegate <NSObject>
@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.
* @param index The 0-based index of a given bar (left to right, x-axis).
*
* @return The y-axis height of the supplied bar index (x-axis)
*/
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index;
@optional
/**
* Occurs when a touch gesture event occurs on a given bar (chart must be expanded).
* and the selection must occur within the bounds of the chart.
*
* @param barChartView A bar chart object informing the delegate about the new selection.
* @param index The 0-based index of a given bar (left to right, x-axis).
* @param touchPoint The touch point in relation to the chart's bounds (excludes footer and header).
*/
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint;
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index;
/**
* 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 deselection.
*/
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView;
/**
* 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).
@@ -116,7 +105,7 @@
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
/**
* The selection color to be overlayed on a bar during touch events.
* 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.
*
@@ -128,4 +117,15 @@
*/
- (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
+18 -16
View File
@@ -130,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];
@@ -145,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
{
@@ -183,10 +183,10 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
barView = [[UIView alloc] init];
UIColor *backgroundColor = nil;
if ([self.dataSource respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)])
if ([self.delegate respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)])
{
backgroundColor = [self.dataSource barChartView:self colorForBarViewAtIndex:index];
NSAssert(backgroundColor != nil, @"JBBarChartView // datasource function - (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index must return a non-nil UIColor");
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
{
@@ -232,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
@@ -258,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
@@ -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
@@ -493,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];
}
}
+2 -2
View File
@@ -76,10 +76,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.
+2 -2
View File
@@ -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
+97 -72
View File
@@ -22,13 +22,13 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
JBLineChartViewLineStyleDashed
};
@protocol JBLineChartViewDelegate;
@protocol JBLineChartViewDataSource;
@protocol JBLineChartViewDelegate;
@interface JBLineChartView : JBChartView
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
/**
* Vertical highlight overlayed on a line graph during touch events.
@@ -48,48 +48,6 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
@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 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 unselection.
*/
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView;
@end
@protocol JBLineChartViewDataSource <NSObject>
@required
@@ -115,6 +73,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 <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 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.
*
@@ -127,6 +153,18 @@ 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.
@@ -157,7 +195,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.
*
@@ -170,7 +208,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
/**
* 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
* 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.
@@ -207,6 +245,19 @@ 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.
@@ -234,30 +285,4 @@ 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;
/**
* 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
+146 -53
View File
@@ -46,8 +46,10 @@ static NSArray *kJBLineChartLineViewDefaultDashPattern = nil;
// Colors (JBLineChartView)
static UIColor *kJBLineChartViewDefaultLineColor = nil;
static UIColor *kJBLineChartViewDefaultDotColor = nil;
static UIColor *kJBLineChartViewDefaultLineFillColor = nil;
static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
static UIColor *kJBLineChartViewDefaultLineSelectionFillColor = nil;
static UIColor *kJBLineChartViewDefaultDotColor = nil;
static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
@interface JBChartView (Private)
@@ -64,6 +66,12 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
@end
@interface JBFillLayer : CAShapeLayer
@property (nonatomic, assign) NSUInteger tag;
@end
@interface JBLineChartPoint : NSObject
@property (nonatomic, assign) CGPoint position;
@@ -89,6 +97,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
// View helpers
- (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex;
- (JBFillLayer *)fillLayerForLineIndex:(NSUInteger)lineIndex;
@end
@@ -97,6 +106,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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;
@@ -123,9 +134,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
@protocol JBLineChartDotsViewDelegate <NSObject>
- (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView*)lineChartDotsView;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(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;
@@ -182,8 +191,10 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
if (self == [JBLineChartView class])
{
kJBLineChartViewDefaultLineColor = [UIColor blackColor];
kJBLineChartViewDefaultDotColor = [UIColor blackColor];
kJBLineChartViewDefaultLineFillColor = [UIColor clearColor];
kJBLineChartViewDefaultLineSelectionColor = [UIColor whiteColor];
kJBLineChartViewDefaultLineSelectionFillColor = [UIColor clearColor];
kJBLineChartViewDefaultDotColor = [UIColor blackColor];
kJBLineChartViewDefaultDotSelectionColor = [UIColor whiteColor];
}
}
@@ -345,16 +356,18 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
}
CGFloat selectionViewWidth = kJBLineSelectionViewWidth;
if ([self.dataSource respondsToSelector:@selector(verticalSelectionWidthForLineChartView:)])
if ([self.delegate respondsToSelector:@selector(verticalSelectionWidthForLineChartView:)])
{
selectionViewWidth = MIN([self.dataSource verticalSelectionWidthForLineChartView:self], self.bounds.size.width);
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
@@ -382,7 +395,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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
@@ -419,17 +432,17 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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 *kJBLineChartViewDefaultDotSelectionColor = 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;
}
@@ -499,9 +530,9 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self lineStyleForLineAtLineIndex:lineIndex];
return [self.delegate lineChartView:self lineStyleForLineAtLineIndex:lineIndex];
}
return JBLineChartViewLineStyleSolid;
}
@@ -522,56 +553,38 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
return self.chartData;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:colorForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self colorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineColor;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:colorForDotAtHorizontalIndex:atLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:colorForDotAtHorizontalIndex:atLineIndex:)])
{
return [self.dataSource lineChartView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
return [self.delegate lineChartView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
return kJBLineChartViewDefaultDotColor;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForLineAtLineIndex:)])
{
return [self.dataSource lineChartView:self selectionColorForLineAtLineIndex:lineIndex];
}
return kJBLineChartViewDefaultLineSelectionColor;
}
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
{
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForDotAtHorizontalIndex:atLineIndex:)])
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionColorForDotAtHorizontalIndex:atLineIndex:)])
{
return [self.dataSource lineChartView:self selectionColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
return [self.delegate lineChartView:self selectionColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
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
{
@@ -595,9 +608,9 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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)
{
@@ -654,7 +667,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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
@@ -861,9 +874,9 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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)
@@ -952,7 +965,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
self = [super init];
if (self)
{
self.zPosition = 0.0f;
self.zPosition = 0.1f;
self.fillColor = [UIColor clearColor].CGColor;
}
return self;
@@ -978,6 +991,24 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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
@@ -1048,11 +1079,14 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
NSUInteger index = 0;
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
{
@@ -1084,6 +1118,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
[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;
@@ -1096,28 +1131,54 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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: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++;
@@ -1160,6 +1221,21 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
((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;
}
}
}
};
@@ -1192,6 +1268,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
}
}
#pragma mark - View Helpers
- (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex
{
for (CALayer *layer in [self.layer sublayers])
@@ -1207,6 +1285,21 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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
+4 -4
View File
@@ -1,19 +1,19 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.5.5"
s.version = "2.7.1"
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.png"
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.5.5"
:tag => "v2.7.1"
}
s.platform = :ios, '7.0'
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
@@ -137,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
@@ -151,21 +144,6 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
return kJBBarChartViewControllerNumBars;
}
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView
{
return kJBBarChartViewControllerBarPadding;
}
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index
{
return (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
}
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView
{
return [UIColor whiteColor];
}
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint
{
NSNumber *valueNumber = [self.chartData objectAtIndex:index];
@@ -176,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,24 +210,12 @@ 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;
@@ -246,16 +256,6 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
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
@@ -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

+35 -9
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.5.5'
platform :ios, '6.0'
pod 'JBChartView', '~> 2.7.1'
### The Old School Way
@@ -52,13 +57,24 @@ 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:
@@ -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:
@@ -159,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
}
@@ -175,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
@@ -202,6 +223,11 @@ Furthermore, the color and width of the selection view along with the color of t
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;
@@ -227,7 +253,7 @@ Lastly, a line chart's selection events are delegated back via:
// Update view
}
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
{
// Update view
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB