Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5210eff99 | |||
| 956386c7db | |||
| c6dfb48047 | |||
| fff2bd22d6 | |||
| 23e8e3084a | |||
| d04eaa2622 | |||
| e24d2487f1 | |||
| d3a92dd70f | |||
| c73f494034 | |||
| 80708acda1 | |||
| 6308ee1b19 | |||
| 62965bbd9f | |||
| 06bf8b5033 | |||
| c2a16d0fbb | |||
| 9548b2ab32 | |||
| 295fb40a0b | |||
| e29ebd39ab | |||
| 27b0493b9b | |||
| 04f40aac1a | |||
| 833f6e9080 | |||
| eb48db2e73 | |||
| 55b6dae956 | |||
| c44b276ae1 | |||
| 93f3d1862e | |||
| 19a4a0bf5c | |||
| 9d43c6dd23 | |||
| 8598ff1488 | |||
| 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 |
@@ -1,5 +1,55 @@
|
||||
# Changelog
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.7">2.8.7</a>
|
||||
#### 09/08/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/107">#107</a>.
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/106">#106</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.5">2.8.5</a>
|
||||
#### 08/28/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/98">#98</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.4">2.8.4</a>
|
||||
#### 08/27/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/97">#97</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.3">2.8.3</a>
|
||||
#### 08/26/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/93">#93</a>.
|
||||
|
||||
## <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>.
|
||||
|
||||
+70
-62
@@ -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,49 +72,9 @@
|
||||
* 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
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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;
|
||||
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView;
|
||||
|
||||
/**
|
||||
* If you already implement barChartView:barViewAtIndex: delegate - this method has no effect.
|
||||
@@ -116,7 +90,7 @@
|
||||
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;
|
||||
|
||||
/**
|
||||
* The selection color to be overlayed on a bar during touch events.
|
||||
* The selection color to be overlayed on a bar during touch events.
|
||||
* The color is automatically faded to transparent (vertically). The property showsVerticalSelection
|
||||
* must be YES for the color to apply.
|
||||
*
|
||||
@@ -128,4 +102,38 @@
|
||||
*/
|
||||
- (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.
|
||||
*/
|
||||
- (CGFloat)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;
|
||||
|
||||
/*
|
||||
* Bars can be (vertically) positoned top to bottom instead of bottom up.
|
||||
* If this property is set to YES, both the bar and the selection view will be inverted.
|
||||
* For the inverted orientation to take effect, reloadData must be called.
|
||||
*
|
||||
* Default: NO.
|
||||
*/
|
||||
@property (nonatomic, assign, getter=isInverted) BOOL inverted;
|
||||
|
||||
@end
|
||||
|
||||
+129
-47
@@ -12,7 +12,7 @@
|
||||
CGFloat static const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
|
||||
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
|
||||
CGFloat static const kJBBarChartViewStateAnimationDuration = 0.05f;
|
||||
CGFloat static const kJBBarChartViewPopOffset = 10.0f; // used to offset bars for 'pop' animations
|
||||
CGFloat static const kJBBarChartViewStatePopOffset = 10.0f;
|
||||
NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
|
||||
|
||||
// Colors (JBChartView)
|
||||
@@ -29,6 +29,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
|
||||
@property (nonatomic, strong) NSDictionary *chartDataDictionary; // key = column, value = height
|
||||
@property (nonatomic, strong) NSArray *barViews;
|
||||
@property (nonatomic, strong) NSArray *cachedBarViewHeights;
|
||||
@property (nonatomic, assign) CGFloat barPadding;
|
||||
@property (nonatomic, assign) CGFloat cachedMaxHeight;
|
||||
@property (nonatomic, assign) CGFloat cachedMinHeight;
|
||||
@@ -42,7 +43,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
- (CGFloat)availableHeight;
|
||||
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight;
|
||||
- (CGFloat)barWidth;
|
||||
- (CGFloat)popOffset;
|
||||
|
||||
// Touch helpers
|
||||
- (NSInteger)barViewIndexForPoint:(CGPoint)point;
|
||||
@@ -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
|
||||
{
|
||||
@@ -167,9 +167,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
[barView removeFromSuperview];
|
||||
}
|
||||
|
||||
self.cachedBarViewHeights = nil;
|
||||
|
||||
CGFloat xOffset = 0;
|
||||
NSUInteger index = 0;
|
||||
NSMutableArray *mutableBarViews = [NSMutableArray array];
|
||||
NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray array];
|
||||
for (NSNumber *key in [[self.chartDataDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)])
|
||||
{
|
||||
UIView *barView = nil; // since all bars are visible at once, no need to cache this view
|
||||
@@ -183,10 +186,10 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
barView = [[UIView alloc] init];
|
||||
UIColor *backgroundColor = nil;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)])
|
||||
if ([self.delegate respondsToSelector:@selector(barChartView:colorForBarViewAtIndex:)])
|
||||
{
|
||||
backgroundColor = [self.dataSource barChartView:self colorForBarViewAtIndex:index];
|
||||
NSAssert(backgroundColor != nil, @"JBBarChartView // datasource function - (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index must return a non-nil UIColor");
|
||||
backgroundColor = [self.delegate barChartView:self colorForBarViewAtIndex:index];
|
||||
NSAssert(backgroundColor != nil, @"JBBarChartView // delegate function - (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index must return a non-nil UIColor");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -195,11 +198,13 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
|
||||
barView.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
barView.tag = index;
|
||||
|
||||
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 barWidth], height + extensionHeight);
|
||||
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height);
|
||||
[mutableBarViews addObject:barView];
|
||||
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:height]];
|
||||
|
||||
// Add new bar
|
||||
if (self.footerView)
|
||||
@@ -215,6 +220,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
index++;
|
||||
}
|
||||
self.barViews = [NSArray arrayWithArray:mutableBarViews];
|
||||
self.cachedBarViewHeights = [NSArray arrayWithArray:mutableCachedBarViewHeights];
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -229,12 +235,32 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
self.verticalSelectionView = nil;
|
||||
}
|
||||
|
||||
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height - self.footerView.frame.size.height)];
|
||||
CGFloat verticalSelectionViewHeight = self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding - self.footerPadding;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoHeaderPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoHeaderPaddingForChartView:self])
|
||||
{
|
||||
verticalSelectionViewHeight += self.headerPadding;
|
||||
}
|
||||
}
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoFooterPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoFooterPaddingForChartView:self])
|
||||
{
|
||||
verticalSelectionViewHeight += self.footerPadding;
|
||||
}
|
||||
}
|
||||
|
||||
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], verticalSelectionViewHeight)];
|
||||
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
|
||||
@@ -246,6 +272,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
[self addSubview:self.verticalSelectionView];
|
||||
}
|
||||
|
||||
self.verticalSelectionView.transform = self.inverted ? CGAffineTransformMakeScale(1.0, -1.0) : CGAffineTransformIdentity;
|
||||
};
|
||||
|
||||
createDataDictionaries();
|
||||
@@ -258,14 +286,14 @@ 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
|
||||
|
||||
- (CGFloat)availableHeight
|
||||
{
|
||||
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding;
|
||||
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding - self.footerPadding;
|
||||
}
|
||||
|
||||
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight
|
||||
@@ -294,16 +322,68 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (CGFloat)popOffset
|
||||
{
|
||||
return self.bounds.size.height - self.footerView.frame.size.height;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback 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];
|
||||
|
||||
__weak JBBarChartView* weakSelf = self;
|
||||
|
||||
void (^updateBarView)(UIView *barView, BOOL popBar);
|
||||
|
||||
updateBarView = ^(UIView *barView, BOOL popBar) {
|
||||
if (weakSelf.inverted)
|
||||
{
|
||||
if (weakSelf.state == JBChartViewStateExpanded)
|
||||
{
|
||||
if (popBar)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue]);
|
||||
}
|
||||
}
|
||||
else if (weakSelf.state == JBChartViewStateCollapsed)
|
||||
{
|
||||
if (popBar)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weakSelf.state == JBChartViewStateExpanded)
|
||||
{
|
||||
if (popBar)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - weakSelf.footerPadding - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] - kJBBarChartViewStatePopOffset, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - weakSelf.footerPadding - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue], barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue]);
|
||||
}
|
||||
}
|
||||
else if (weakSelf.state == JBChartViewStateCollapsed)
|
||||
{
|
||||
if (popBar)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - weakSelf.footerPadding - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] - kJBBarChartViewStatePopOffset, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height, barView.frame.size.width, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dispatch_block_t callbackCopy = [callback copy];
|
||||
|
||||
@@ -311,25 +391,16 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
if (animated)
|
||||
{
|
||||
CGFloat popOffset = [self popOffset];
|
||||
|
||||
NSUInteger index = 0;
|
||||
for (UIView *barView in self.barViews)
|
||||
{
|
||||
[UIView animateWithDuration:kJBBarChartViewStateAnimationDuration delay:(kJBBarChartViewStateAnimationDuration * 0.5) * index options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, popOffset - barView.frame.size.height, barView.frame.size.width, barView.frame.size.height);
|
||||
updateBarView(barView, YES);
|
||||
} completion:^(BOOL finished) {
|
||||
[UIView animateWithDuration:kJBBarChartViewStateAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
if (state == JBChartViewStateExpanded)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, popOffset - barView.frame.size.height + kJBBarChartViewPopOffset, barView.frame.size.width, barView.frame.size.height);
|
||||
}
|
||||
else if (state == JBChartViewStateCollapsed)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
|
||||
}
|
||||
updateBarView(barView, NO);
|
||||
} completion:^(BOOL lastBarFinished) {
|
||||
if (index == [self.barViews count] - 1)
|
||||
if (barView.tag == [self.barViews count] - 1)
|
||||
{
|
||||
if (callbackCopy)
|
||||
{
|
||||
@@ -345,14 +416,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
for (UIView *barView in self.barViews)
|
||||
{
|
||||
if (state == JBChartViewStateExpanded)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, (self.bounds.size.height + kJBBarChartViewPopOffset) - (barView.frame.size.height + self.footerView.frame.size.height), barView.frame.size.width, barView.frame.size.height);
|
||||
}
|
||||
else if (state == JBChartViewStateCollapsed)
|
||||
{
|
||||
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
|
||||
}
|
||||
updateBarView(barView, NO);
|
||||
}
|
||||
if (callbackCopy)
|
||||
{
|
||||
@@ -371,7 +435,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
|
||||
@@ -470,6 +534,24 @@ 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;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoHeaderPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoHeaderPaddingForChartView:self])
|
||||
{
|
||||
selectionViewFrame.origin.y = self.headerView.frame.size.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectionViewFrame.origin.y = self.headerView.frame.size.height + self.headerPadding;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectionViewFrame.origin.y = self.headerView.frame.size.height + self.headerPadding;
|
||||
}
|
||||
|
||||
self.verticalSelectionView.frame = selectionViewFrame;
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
|
||||
@@ -493,9 +575,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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
-2
@@ -7,9 +7,12 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
extern CGFloat const kJBChartViewDefaultAnimationDuration;
|
||||
|
||||
@class JBChartView;
|
||||
|
||||
/**
|
||||
* At a minimum, a chart can support two states, along with animations to-and-from.
|
||||
*/
|
||||
@@ -24,8 +27,48 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
JBChartViewStateCollapsed
|
||||
};
|
||||
|
||||
@protocol JBChartViewDataSource <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Returns whether or not the chart's selection view should extend into the header padding.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param chartView The chart object requesting this information.
|
||||
*
|
||||
* @return Whether or not a chart's selection view should extend into the header padding.
|
||||
*/
|
||||
- (BOOL)shouldExtendSelectionViewIntoHeaderPaddingForChartView:(JBChartView *)chartView;
|
||||
|
||||
/**
|
||||
* Returns whether or not the chart's selection view should extend into the footer padding.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param chartView The chart object requesting this information.
|
||||
*
|
||||
* @return Whether or not a chart's selection view should extend into the footer padding.
|
||||
*/
|
||||
- (BOOL)shouldExtendSelectionViewIntoFooterPaddingForChartView:(JBChartView *)chartView;
|
||||
|
||||
@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.
|
||||
@@ -36,9 +79,18 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
|
||||
/**
|
||||
* The vertical padding between the header and highest chart point (bar, line, etc).
|
||||
* By default, the selection view will extend into the header padding area. To modify this behaviour,
|
||||
* implement the dataSource protocol - (BOOL)shouldExtendSelectionViewIntoHeaderPaddingForChartView:(JBChartView *)chartView.
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat headerPadding;
|
||||
|
||||
/**
|
||||
* The vertical padding between the footer and lowest chart point (bar, line, etc).
|
||||
* By default, the selection view will extend into the footer padding area. To modify this behaviour,
|
||||
* implement the dataSource protocol - (BOOL)shouldExtendSelectionViewIntoFooterPaddingForChartView:(JBChartView *)chartView.
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat footerPadding;
|
||||
|
||||
/**
|
||||
* The minimum and maxmimum values of the chart.
|
||||
* If no value(s) are supplied:
|
||||
@@ -76,10 +128,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.
|
||||
|
||||
@@ -111,7 +111,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
|
||||
{
|
||||
if ((_state == state) && !force)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
[self setState:state animated:animated callback:callback force:NO];
|
||||
[self setState:state animated:animated force:NO callback:callback];
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated
|
||||
|
||||
+130
-100
@@ -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,6 +49,105 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Returns whether or not a line should show a dot for each point.
|
||||
* Dot size is relative to the line width and not adjustable.
|
||||
* Dot color is equal to the line color and not adjustable.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return Whether or not a line should show a dot for each chart point.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns whether or not a line should be rendered with curved connections and rounded end caps.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return Whether or not a line should smooth it's connections and end caps.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* 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 will not be hidden unless lineChartView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:
|
||||
* is implemented.
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Returns whether or not a (custom) dot view should be hidden on selection events.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @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 Whether or not a (custom) dot view should be hidden on selection events.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView shouldHideDotViewOnSelectionAtHorizontalIndex:(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.
|
||||
*
|
||||
@@ -147,7 +180,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
* 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 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.
|
||||
@@ -169,20 +202,21 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
/**
|
||||
* Returns the radius of all dots in a particular line at lineIndex within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
|
||||
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
|
||||
*
|
||||
* Default: line width x 3.
|
||||
*
|
||||
* @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 dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (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
|
||||
* 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.
|
||||
@@ -194,17 +228,16 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
/**
|
||||
* Returns the (vertical) selection color to be overlayed on the chart during touch events.
|
||||
* 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.
|
||||
*
|
||||
* Default: white color (faded to transparent).
|
||||
*
|
||||
* @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.
|
||||
* @return The color of the selection view used during chart selections of the given line.
|
||||
*/
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView;
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the selection color to be overlayed on a line within the chart during touch events.
|
||||
@@ -239,7 +272,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
* 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 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.
|
||||
@@ -259,30 +292,27 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns whether or not a line should show a dot for each point.
|
||||
* Dot size is relative to the line width and not adjustable.
|
||||
* Dot color is equal to the line color and not adjustable.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return Whether or not a line should show a dot for each chart point.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
@end
|
||||
|
||||
@interface JBLineChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Returns whether or not a line should be rendered with curved connections and rounded end caps.
|
||||
* Vertical highlight overlayed on a line graph during touch events.
|
||||
*
|
||||
* Default: NO
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return Whether or not a line should smooth it's connections and end caps.
|
||||
* Default: YES.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
@property (nonatomic, assign) BOOL showsVerticalSelection;
|
||||
|
||||
/**
|
||||
* A highlight shown on a line within the graph during touch events. The highlighted line
|
||||
* is the closest line to the touch point and corresponds to the lineIndex delegatd back via
|
||||
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex:
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsLineSelection;
|
||||
|
||||
@end
|
||||
|
||||
+219
-95
@@ -134,12 +134,12 @@ 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;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -267,7 +267,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
NSMutableArray *mutableChartData = [NSMutableArray array];
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; 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];
|
||||
@@ -358,17 +359,32 @@ 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)];
|
||||
|
||||
CGFloat verticalSelectionViewHeight = self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding - self.footerPadding;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoHeaderPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoHeaderPaddingForChartView:self])
|
||||
{
|
||||
verticalSelectionViewHeight += self.headerPadding;
|
||||
}
|
||||
}
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoFooterPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoFooterPaddingForChartView:self])
|
||||
{
|
||||
verticalSelectionViewHeight += self.footerPadding;
|
||||
}
|
||||
}
|
||||
|
||||
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, verticalSelectionViewHeight)];
|
||||
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)
|
||||
@@ -395,7 +411,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
|
||||
@@ -415,15 +431,16 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
- (CGFloat)availableHeight
|
||||
{
|
||||
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding;
|
||||
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding - self.footerPadding;
|
||||
}
|
||||
|
||||
- (CGFloat)padding
|
||||
{
|
||||
CGFloat maxLineWidth = 0.0f;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; lineIndex++)
|
||||
{
|
||||
BOOL showsDots = NO;
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
|
||||
@@ -432,21 +449,86 @@ 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:lineIndex];
|
||||
lineWidth = [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
|
||||
CGFloat maxDotLength = 0;
|
||||
if (showsDots)
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; 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;
|
||||
@@ -459,7 +541,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
NSUInteger dataCount = 0;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; lineIndex++)
|
||||
{
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
|
||||
NSUInteger lineDataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
|
||||
@@ -480,45 +563,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.dataSource respondsToSelector:@selector(lineChartView:fillColorForLineAtLineIndex:)])
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:fillColorForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self fillColorForLineAtLineIndex:lineIndex];
|
||||
return [self.delegate lineChartView:self fillColorForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return kJBLineChartViewDefaultLineFillColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedFillColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionFillColorForLineAtLineIndex:)])
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:selectionFillColorForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self selectionFillColorForLineAtLineIndex:lineIndex];
|
||||
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;
|
||||
}
|
||||
@@ -530,9 +613,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;
|
||||
}
|
||||
@@ -553,61 +636,58 @@ 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;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
@@ -626,9 +706,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)
|
||||
{
|
||||
@@ -685,7 +765,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
|
||||
@@ -696,7 +776,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
CGFloat minHeight = FLT_MAX;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; 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];
|
||||
@@ -722,7 +803,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
CGFloat maxHeight = 0;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; 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];
|
||||
@@ -818,9 +900,10 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
NSUInteger shortestDistance = INT_MAX;
|
||||
NSInteger selectedIndex = kJBLineChartUnselectedLineIndex;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
NSInteger numberOfLines = [self.dataSource numberOfLinesInLineChartView:self];
|
||||
|
||||
// Iterate all lines
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
for (NSUInteger lineIndex=0; lineIndex<numberOfLines; lineIndex++)
|
||||
{
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex");
|
||||
if ([self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex] > rightHorizontalIndex)
|
||||
@@ -864,22 +947,40 @@ 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);
|
||||
CGFloat yOffset = self.headerView.frame.size.height + self.headerPadding;
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(shouldExtendSelectionViewIntoHeaderPaddingForChartView:)])
|
||||
{
|
||||
if ([self.dataSource shouldExtendSelectionViewIntoHeaderPaddingForChartView:self])
|
||||
{
|
||||
yOffset = self.headerView.frame.size.height;
|
||||
}
|
||||
}
|
||||
|
||||
self.verticalSelectionView.frame = CGRectMake(xOffset, yOffset, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
}
|
||||
|
||||
@@ -892,9 +993,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)
|
||||
@@ -910,8 +1011,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
_verticalSelectionViewVisible = verticalSelectionViewVisible;
|
||||
|
||||
[self bringSubviewToFront:self.verticalSelectionView];
|
||||
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
@@ -1363,19 +1462,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]];
|
||||
@@ -1396,22 +1502,40 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
dispatch_block_t adjustDots = ^{
|
||||
[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]])
|
||||
{
|
||||
NSInteger lineIndex = [((NSNumber *)key) intValue];
|
||||
|
||||
if (weakSelf.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 = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
BOOL hideDotView = [self.delegate lineChartDotsView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
if (weakSelf.selectedLineIndex == lineIndex)
|
||||
{
|
||||
dotView.alpha = hideDotView ? 0.0f : 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
dotView.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
horizontalIndex++;
|
||||
@@ -1448,7 +1572,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
self.layer.cornerRadius = (radius * 0.5);
|
||||
self.layer.cornerRadius = (radius * 0.5f);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.6.3"
|
||||
s.version = "2.8.7"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Terry Worona" => "tworona@jawbone.com" }
|
||||
s.source = {
|
||||
:git => "https://github.com/Jawbone/JBChartView.git",
|
||||
:tag => "v2.6.3"
|
||||
:tag => "v2.8.7"
|
||||
}
|
||||
|
||||
s.platform = :ios, '6.0'
|
||||
|
||||
@@ -170,6 +170,28 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"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 NO;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - JBLineChartViewDelegate
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
@@ -187,24 +209,12 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
|
||||
[self.tooltipView setText:[[self.monthlySymbols 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 == JBLineChartLineSun) ? kJBColorAreaChartDefaultSunLineColor: kJBColorAreaChartDefaultMoonLineColor;
|
||||
@@ -225,7 +235,7 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
|
||||
return kJBAreaChartViewControllerChartLineWidth;
|
||||
}
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
@@ -250,16 +260,6 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
|
||||
return JBLineChartViewLineStyleSolid;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - Buttons
|
||||
|
||||
- (void)chartToggleButtonPressed:(id)sender
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
CGFloat const kJBBarChartViewControllerChartHeight = 250.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartPadding = 10.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartHeaderHeight = 80.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartHeaderPadding = 10.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartHeaderPadding = 20.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartFooterHeight = 25.0f;
|
||||
CGFloat const kJBBarChartViewControllerChartFooterPadding = 5.0f;
|
||||
NSUInteger kJBBarChartViewControllerBarPadding = 1;
|
||||
CGFloat const kJBBarChartViewControllerBarPadding = 1.0f;
|
||||
NSInteger const kJBBarChartViewControllerNumBars = 12;
|
||||
NSInteger const kJBBarChartViewControllerMaxBarHeight = 10;
|
||||
NSInteger const kJBBarChartViewControllerMinBarHeight = 5;
|
||||
@@ -108,6 +108,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
|
||||
self.barChartView.dataSource = self;
|
||||
self.barChartView.headerPadding = kJBBarChartViewControllerChartHeaderPadding;
|
||||
self.barChartView.minimumValue = 0.0f;
|
||||
self.barChartView.inverted = NO;
|
||||
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)];
|
||||
@@ -137,11 +138,16 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
|
||||
[self.barChartView setState:JBChartViewStateExpanded];
|
||||
}
|
||||
|
||||
#pragma mark - JBBarChartViewDelegate
|
||||
#pragma mark - JBChartViewDataSource
|
||||
|
||||
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index
|
||||
- (BOOL)shouldExtendSelectionViewIntoHeaderPaddingForChartView:(JBChartView *)chartView
|
||||
{
|
||||
return [[self.chartData objectAtIndex:index] floatValue];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)shouldExtendSelectionViewIntoFooterPaddingForChartView:(JBChartView *)chartView
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - JBBarChartViewDataSource
|
||||
@@ -151,21 +157,6 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
|
||||
return kJBBarChartViewControllerNumBars;
|
||||
}
|
||||
|
||||
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView
|
||||
{
|
||||
return kJBBarChartViewControllerBarPadding;
|
||||
}
|
||||
|
||||
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index
|
||||
{
|
||||
return (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
|
||||
}
|
||||
|
||||
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
|
||||
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint
|
||||
{
|
||||
NSNumber *valueNumber = [self.chartData objectAtIndex:index];
|
||||
@@ -176,12 +167,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];
|
||||
}
|
||||
|
||||
- (CGFloat)barPaddingForBarChartView:(JBBarChartView *)barChartView
|
||||
{
|
||||
return kJBBarChartViewControllerBarPadding;
|
||||
}
|
||||
|
||||
#pragma mark - Buttons
|
||||
|
||||
- (void)chartToggleButtonPressed:(id)sender
|
||||
|
||||
@@ -171,6 +171,40 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
[self.lineChartView setState:JBChartViewStateExpanded];
|
||||
}
|
||||
|
||||
#pragma mark - JBChartViewDataSource
|
||||
|
||||
- (BOOL)shouldExtendSelectionViewIntoHeaderPaddingForChartView:(JBChartView *)chartView
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)shouldExtendSelectionViewIntoFooterPaddingForChartView:(JBChartView *)chartView
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
#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 +222,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 +243,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 +268,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
|
||||
|
||||
@@ -43,7 +43,7 @@ Simply add the following line to your <code>Podfile</code>:
|
||||
Your Podfile should look something like:
|
||||
|
||||
platform :ios, '6.0'
|
||||
pod 'JBChartView', '~> 2.6.3'
|
||||
pod 'JBChartView', '~> 2.8.7'
|
||||
|
||||
### The Old School Way
|
||||
|
||||
@@ -73,8 +73,8 @@ For more information about adding bridging headers see <a href="https://develope
|
||||
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:
|
||||
@@ -101,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:
|
||||
@@ -150,6 +150,10 @@ Lastly, any JBChartView subclass can be collapsed or expanded programmatically v
|
||||
|
||||
#### JBBarChartView
|
||||
|
||||
A bar chart can be inverted such that it's orientation is top->down (including the selection view) by setting the following property:
|
||||
|
||||
@property (nonatomic, assign, getter=isInverted) BOOL inverted;
|
||||
|
||||
By default, a chart's bars will be black and flat. They can be customized by supplying a UIView subclass through the <i>optional</i> protocol:
|
||||
|
||||
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index
|
||||
@@ -175,7 +179,7 @@ Lastly, a bar chart's selection events are delegated back via:
|
||||
// Update view
|
||||
}
|
||||
|
||||
- (void)didUnselectBarChartView:(JBBarChartView *)barChartView
|
||||
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView
|
||||
{
|
||||
// Update view
|
||||
}
|
||||
@@ -208,7 +212,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
|
||||
}
|
||||
@@ -234,7 +238,7 @@ By default, each line will not show dots for each point. To enable this on a per
|
||||
|
||||
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:
|
||||
|
||||
@@ -242,6 +246,14 @@ 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:
|
||||
|
||||
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
Custom dot views are automatically shown when selected unless the following is implemented:
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView shouldHideDotViewOnSelectionAtHorizontalIndex:(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;
|
||||
@@ -253,7 +265,7 @@ Lastly, a line chart's selection events are delegated back via:
|
||||
// Update view
|
||||
}
|
||||
|
||||
- (void)didUnselectLineInLineChartView:(JBLineChartView *)lineChartView
|
||||
- (void)didDeselectLineInLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
// Update view
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user