Compare commits
82 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b9d28bfd59 | |||
| dd1dce758e | |||
| 9fce2fc1c0 | |||
| ab1cf713e6 | |||
| 4363147303 | |||
| 8a1770c6df | |||
| f84f322598 | |||
| 04e1aa5b98 | |||
| ab07aa2399 | |||
| f01e11a0e2 | |||
| 76984c7c7c | |||
| d38a04a70d | |||
| 385d5b3589 | |||
| 90100c7277 | |||
| eca1c0507e | |||
| ac870e45ce | |||
| 74f588b7e6 | |||
| 406b64ae0c | |||
| 92e56d78c5 | |||
| 36ec328346 | |||
| b763ae540c | |||
| 7ffdf6d9da | |||
| 6531c68574 | |||
| ebae36bd2f | |||
| 8cdff2891c | |||
| 333200d041 | |||
| 6ad3bd7692 | |||
| 3531e593da | |||
| eeb9ca604c | |||
| b884108dbb | |||
| 00dd74f733 | |||
| c1938147d8 | |||
| e17c5419f4 | |||
| d0cb8b0307 | |||
| fe81df094e | |||
| 0dae570cc6 | |||
| c5c93cb660 | |||
| 3df69b0a9c | |||
| 30305cdde9 | |||
| 8e1cbba06f | |||
| 97e5acdb1a | |||
| 47f1f0ba8d | |||
| 0be9465049 | |||
| 7bed3dd5d0 | |||
| 4f1f6760d5 | |||
| 8103a1aea4 | |||
| dc6dc647ad | |||
| b6ea1a502a | |||
| afcf328158 | |||
| 49cf12c568 | |||
| 0d4b942b74 | |||
| 30a369796f | |||
| f2f35312e4 | |||
| d32f09a584 | |||
| 80e179df1d | |||
| 48da335f09 | |||
| 70c1fb897c | |||
| 30df02f804 | |||
| 9ba20e9e14 | |||
| d6d1dd8461 | |||
| b0de620503 | |||
| 8e81fb20cd | |||
| a303422d8e | |||
| 1aff68557f | |||
| ac3744c0c9 | |||
| a6ea0c30f8 | |||
| ea531e3cb1 | |||
| b1a3ebd4ed | |||
| 554f93f3d3 | |||
| 2ddd38fc9d | |||
| 6691f7a8c3 | |||
| c015531c85 | |||
| 3d036edc96 | |||
| 85c30351fe | |||
| d37383a352 | |||
| 3c6cf24cf7 | |||
| 8dbb2679ee | |||
| 867466d1d1 | |||
| 2046131143 | |||
| 208a727d88 | |||
| 43c6e9486f | |||
| 49206a01ed |
@@ -1,5 +1,74 @@
|
||||
# Changelog
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.2">2.8.2</a>
|
||||
#### 08/26/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/96">#96</a>.
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/95">#95</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.1">2.8.1</a>
|
||||
#### 08/22/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/92">#92</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.0">2.8.0</a>
|
||||
#### 08/14/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/90">#90</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.4">2.7.4</a>
|
||||
#### 08/14/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/89">#89</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.3">2.7.3</a>
|
||||
#### 08/07/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/83">#83</a>.
|
||||
|
||||
## <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>.
|
||||
|
||||
+67
-55
@@ -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
|
||||
|
||||
+31
-15
@@ -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
|
||||
{
|
||||
@@ -181,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
|
||||
@@ -219,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
|
||||
@@ -245,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
|
||||
@@ -288,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];
|
||||
|
||||
@@ -358,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
|
||||
@@ -457,6 +472,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
CGRect barViewFrame = barView.frame;
|
||||
CGRect selectionViewFrame = self.verticalSelectionView.frame;
|
||||
selectionViewFrame.origin.x = barViewFrame.origin.x;
|
||||
selectionViewFrame.size.width = barViewFrame.size.width;
|
||||
self.verticalSelectionView.frame = selectionViewFrame;
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
|
||||
@@ -480,9 +496,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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-5
@@ -24,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 +61,7 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
* The minimum and maxmimum values of the chart.
|
||||
* If no value(s) are supplied:
|
||||
*
|
||||
* minimumValue = 0
|
||||
* 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.
|
||||
@@ -55,8 +73,9 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
@property (nonatomic, assign) CGFloat minimumValue;
|
||||
@property (nonatomic, assign) CGFloat maximumValue;
|
||||
|
||||
- (void)resetMinimumValue; // resets to default (0)
|
||||
- (void)resetMaximumValue; // reset to default (chart's data source max value)
|
||||
// reset to default (chart's data source min & max value)
|
||||
- (void)resetMinimumValue;
|
||||
- (void)resetMaximumValue;
|
||||
|
||||
/**
|
||||
* Charts can either be expanded or contracted.
|
||||
@@ -75,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.
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
// Numerics
|
||||
CGFloat const kJBChartViewDefaultAnimationDuration = 0.25f;
|
||||
CGFloat const kJBChartViewDefaulMinimumValue = 0.0f;
|
||||
|
||||
// Color (JBChartSelectionView)
|
||||
static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
@@ -62,7 +61,6 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
- (void)constructChartView
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
self.minimumValue = kJBChartViewDefaulMinimumValue;
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
@@ -113,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)
|
||||
{
|
||||
@@ -127,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
|
||||
@@ -156,7 +154,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
- (void)resetMinimumValue
|
||||
{
|
||||
self.minimumValue = kJBChartViewDefaulMinimumValue; // resets to default
|
||||
_hasMinimumValue = NO; // clears min
|
||||
}
|
||||
|
||||
- (void)resetMaximumValue
|
||||
|
||||
+229
-188
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "JBChartView.h"
|
||||
|
||||
@class JBLineChartView;
|
||||
|
||||
/**
|
||||
* Current support for two line styles: solid (default) and dashed.
|
||||
*/
|
||||
@@ -22,75 +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 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>
|
||||
@protocol JBLineChartViewDataSource <JBChartViewDataSource>
|
||||
|
||||
@required
|
||||
|
||||
@@ -115,125 +49,6 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Returns the color of particular line at lineIndex within the chart.
|
||||
*
|
||||
* Default: black 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 shade a line in the chart.
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(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.
|
||||
*
|
||||
* Default: 5 points.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The width to be used to draw a line in the chart.
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Default: line width x 3.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The radius of the dots within a dotted line in the chart.
|
||||
*/
|
||||
- (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
|
||||
* must be YES for the color to apply.
|
||||
*
|
||||
* Default: white color (faded to transparent).
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
*
|
||||
* @return The color of the selection view used during chart selections.
|
||||
*/
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
/**
|
||||
* 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 lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The color to be used to highlight a line during chart selections.
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(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.
|
||||
*
|
||||
* Default: JBLineChartViewLineStyleSolid
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The line style to be used to draw a line in the chart.
|
||||
*/
|
||||
- (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.
|
||||
@@ -260,4 +75,230 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns a (custom) UIView instance representing a dot (x,y point) within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
* This protocol supercedes colorForDotAtHorizontalIndex: and dotRadiusForDotAtHorizontalIndex:.
|
||||
* If nil is returned. the original dot protocols will take precedence. During selection events, a custom
|
||||
* dot view is automatically hidden.
|
||||
*
|
||||
* Default: nil.
|
||||
*
|
||||
* @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 a line in the chart.
|
||||
*
|
||||
* @return A custom UIView instance representing a dot at a particular horizontal index within a dotted line.
|
||||
*/
|
||||
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(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).
|
||||
* @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.
|
||||
*
|
||||
* Default: black 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 shade a line in the chart.
|
||||
*/
|
||||
- (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)
|
||||
* @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.
|
||||
*
|
||||
* Default: 5 points.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The width to be used to draw a line in the chart.
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Default: line width x 3.
|
||||
*
|
||||
* @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 a line in the chart.
|
||||
*
|
||||
* @return The radius of the dots within a dotted line in the chart.
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(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 on a given line.
|
||||
* The color is automically faded to transparent (vertically). The property showsVerticalSelection
|
||||
* must be YES for the color to apply.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The color of the selection view used during chart selections of the given line.
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(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 lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The color to be used to highlight a line during chart selections.
|
||||
*/
|
||||
- (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).
|
||||
* @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.
|
||||
*
|
||||
* Default: JBLineChartViewLineStyleSolid
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The line style to be used to draw a line in the chart.
|
||||
*/
|
||||
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBLineChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
+280
-95
@@ -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,12 +134,11 @@ 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;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -182,8 +192,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,17 +357,13 @@ 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:)])
|
||||
{
|
||||
self.verticalSelectionView.bgColor = [self.dataSource verticalSelectionColorForLineChartView:self];
|
||||
}
|
||||
|
||||
// Add new selection bar
|
||||
if (self.footerView)
|
||||
@@ -382,7 +390,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
|
||||
@@ -410,7 +418,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
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,21 +427,87 @@ 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
|
||||
CGFloat maxDotLength = 0;
|
||||
if (showsDots)
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
{
|
||||
dotRadius = [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
|
||||
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
|
||||
|
||||
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
|
||||
{
|
||||
BOOL shouldEvaluateDotSize = NO;
|
||||
|
||||
// Left dot
|
||||
if (horizontalIndex == 0)
|
||||
{
|
||||
shouldEvaluateDotSize = YES;
|
||||
}
|
||||
// Right dot
|
||||
else if (horizontalIndex == (dataCount - 1))
|
||||
{
|
||||
shouldEvaluateDotSize = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat height = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
// Top
|
||||
if (height == [self cachedMaxHeight])
|
||||
{
|
||||
shouldEvaluateDotSize = YES;
|
||||
}
|
||||
|
||||
// Bottom
|
||||
else if (height == [self cachedMinHeight])
|
||||
{
|
||||
shouldEvaluateDotSize = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldEvaluateDotSize)
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
UIView *customDotView = [self.dataSource lineChartView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
if (customDotView.frame.size.width > maxDotLength || customDotView.frame.size.height > maxDotLength)
|
||||
{
|
||||
maxDotLength = fmaxf(customDotView.frame.size.width, customDotView.frame.size.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForDotAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
CGFloat dotRadius = [self.delegate lineChartView:self dotRadiusForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
if (dotRadius > maxDotLength)
|
||||
{
|
||||
maxDotLength = dotRadius;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CGFloat defaultDotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
if (defaultDotRadius > maxDotLength)
|
||||
{
|
||||
maxDotLength = defaultDotRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CGFloat currentMaxLineWidth = MAX(dotRadius, lineWidth);
|
||||
CGFloat currentMaxLineWidth = MAX(maxDotLength, lineWidth);
|
||||
if (currentMaxLineWidth > maxLineWidth)
|
||||
{
|
||||
maxLineWidth = currentMaxLineWidth;
|
||||
@@ -467,27 +541,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 +591,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,61 +614,49 @@ 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
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForDotAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
return [self.delegate lineChartView:self dotRadiusForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
else
|
||||
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
}
|
||||
|
||||
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
return [self.dataSource lineChartView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
@@ -595,9 +675,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)
|
||||
{
|
||||
@@ -622,7 +702,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
} completion:^(BOOL finished) {
|
||||
[UIView animateWithDuration:kJBLineChartViewStateAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
adjustViewFrames();
|
||||
} completion:^(BOOL finished) {
|
||||
} completion:^(BOOL adjustFinished) {
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
@@ -654,7 +734,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
|
||||
@@ -778,8 +858,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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];
|
||||
@@ -833,20 +913,27 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
|
||||
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:touchPoint:)])
|
||||
{
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
NSUInteger horizontalIndex = [self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]];
|
||||
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:horizontalIndex touchPoint:[touch locationInView:self]];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:)])
|
||||
{
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:[self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]]];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:verticalSelectionColorForLineAtLineIndex:)])
|
||||
{
|
||||
UIColor *verticalSelectionColor = [self.delegate lineChartView:self verticalSelectionColorForLineAtLineIndex:lineIndex];
|
||||
NSAssert(verticalSelectionColor != nil, @"JBLineChartView // delegate function - (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex must return a non-nil UIColor");
|
||||
self.verticalSelectionView.bgColor = verticalSelectionColor;
|
||||
}
|
||||
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.verticalSelectionView.frame.size.width * 0.5))));
|
||||
self.verticalSelectionView.frame = CGRectMake(xOffset, self.verticalSelectionView.frame.origin.y, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
@@ -861,9 +948,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)
|
||||
@@ -879,8 +966,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
_verticalSelectionViewVisible = verticalSelectionViewVisible;
|
||||
|
||||
[self bringSubviewToFront:self.verticalSelectionView];
|
||||
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
@@ -952,7 +1037,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 +1063,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
|
||||
@@ -1041,18 +1144,21 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
path.miterLimit = kJBLineChartLinesViewMiterLimit;
|
||||
|
||||
JBLineChartPoint *previousLineChartPoint = nil;
|
||||
CGFloat previousSlope;
|
||||
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;
|
||||
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 +1190,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 +1203,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++;
|
||||
@@ -1140,12 +1273,14 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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;
|
||||
@@ -1155,7 +1290,22 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1190,6 +1340,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - View Helpers
|
||||
|
||||
- (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
for (CALayer *layer in [self.layer sublayers])
|
||||
@@ -1205,6 +1357,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
|
||||
@@ -1250,19 +1417,26 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
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: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];
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotViewAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
UIView *currentDotView = [self.delegate lineChartDotsView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
// System dot
|
||||
if (currentDotView == nil)
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
currentDotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
currentDotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
currentDotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
||||
[mutableDotViews addObject:currentDotView];
|
||||
[self addSubview:currentDotView];
|
||||
|
||||
horizontalIndex++;
|
||||
}
|
||||
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
|
||||
@@ -1278,25 +1452,36 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = 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)
|
||||
for (UIView *dotView in (NSArray *)obj)
|
||||
{
|
||||
if ([key isKindOfClass:[NSNumber class]])
|
||||
{
|
||||
NSUInteger lineIndex = [((NSNumber *)key) intValue];
|
||||
NSInteger lineIndex = [((NSNumber *)key) intValue];
|
||||
|
||||
if (_selectedLineIndex == lineIndex)
|
||||
// Internal dot
|
||||
if ([dotView isKindOfClass:[JBLineChartDotView class]])
|
||||
{
|
||||
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];
|
||||
if (weakSelf.selectedLineIndex == 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: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
|
||||
}
|
||||
}
|
||||
// Custom dot
|
||||
else
|
||||
{
|
||||
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 = (_selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
|
||||
dotView.alpha = (weakSelf.selectedLineIndex == lineIndex) ? 0.0f : 1.0f; // hide custom dots on selection
|
||||
}
|
||||
}
|
||||
horizontalIndex++;
|
||||
@@ -1333,7 +1518,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
self.layer.cornerRadius = (radius * 0.5);
|
||||
self.layer.cornerRadius = (radius * 0.5f);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.5.0"
|
||||
s.version = "2.8.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.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.0"
|
||||
:tag => "v2.8.2"
|
||||
}
|
||||
|
||||
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 *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
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,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;
|
||||
@@ -221,12 +231,12 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBLineChartViewControllerChartSolidLineWidth: kJBLineChartViewControllerChartDashedLineWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? 0.0: (kJBLineChartViewControllerChartDashedLineWidth * 4);
|
||||
}
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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 |
@@ -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.0'
|
||||
platform :ios, '6.0'
|
||||
pod 'JBChartView', '~> 2.8.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
|
||||
@@ -183,7 +208,7 @@ The color, width and style of each line in the chart can be customized via the <
|
||||
|
||||
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
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // color of selection view
|
||||
}
|
||||
@@ -198,13 +223,18 @@ 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;
|
||||
|
||||
To customize the size of each dot (default 3x the line width), implement:
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
To customize the color of each dot during selection and non-selection events (default is white and black respectively), implement:
|
||||
|
||||
@@ -212,6 +242,10 @@ To customize the color of each dot during selection and non-selection events (de
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
Alternatively, you can supply your own UIView instead of using the default impelmentation (note: custom dot views are automatically hidden when selected):
|
||||
|
||||
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(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;
|
||||
@@ -223,7 +257,7 @@ Lastly, a line chart's selection events are delegated back via:
|
||||
// Update view
|
||||
}
|
||||
|
||||
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView
|
||||
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
// Update view
|
||||
}
|
||||
@@ -232,7 +266,7 @@ The <b>touchPoint</b> is especially important as it allows you to add custom ele
|
||||
|
||||
## Minimum & Maximum Values
|
||||
|
||||
By default, a chart's minimum value (y-axis) is equal to 0. The maximum is equal to the max value supplied by the dataSource. You can override either value via:
|
||||
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;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 157 KiB |
Reference in New Issue
Block a user