Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7927cddb7 | |||
| 0f2d4d766c | |||
| 64de3e6e23 | |||
| 87fb8ee7b8 | |||
| 7c0dfe3eb5 | |||
| 87b62ad2b1 | |||
| 9c0d788418 | |||
| de009f0236 | |||
| d46e4fe14d | |||
| 236336fdf3 | |||
| 9b60a1d662 | |||
| 3700b4e2e2 | |||
| 8c03033a1c | |||
| bb084b1b89 | |||
| 1c7c8b2e52 | |||
| 79a57d98e3 | |||
| 20d6b6081b | |||
| 20bbbdcc86 | |||
| 51ac8a1d63 | |||
| 68d04a2cdb | |||
| b7734ef189 | |||
| f6d2fe8b62 | |||
| 5c9679f448 | |||
| 037225a386 | |||
| 0fe979bd22 | |||
| 31b64ed7e4 | |||
| c30398c3ea | |||
| bc08322a3a | |||
| 213973f4ed | |||
| 28d40bcb31 | |||
| d4df0184a2 | |||
| 4f313aab80 |
@@ -1,5 +1,41 @@
|
||||
# Changelog
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.2">2.4.2</a>
|
||||
#### 04/30/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/46">#46</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.1">2.4.1</a>
|
||||
#### 04/30/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/45">#45</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.4.0">2.4.0</a>
|
||||
#### 04/28/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/23">#23</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.3.0">2.3.0</a>
|
||||
#### 04/17/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/34">#34</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.2.0">2.2.0</a>
|
||||
#### 04/14/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/37">#37</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.6">2.1.6</a>
|
||||
#### 04/11/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/33">#33</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.5">2.1.5</a>
|
||||
#### 04/10/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/30">#30</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.4">2.1.4</a>
|
||||
#### 04/10/14
|
||||
- Added ability to specify a radius for dotted lines.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.3">2.1.3</a>
|
||||
#### 04/03/14
|
||||
- Added the ability to force a chart's state.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.2">2.1.2</a>
|
||||
#### 04/02/14
|
||||
- Added dynamic padding to JBLineChartView (based on max line width).
|
||||
|
||||
@@ -238,6 +238,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
// Position header and footer
|
||||
self.headerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.headerView.frame.size.height);
|
||||
self.footerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.size.height - self.footerView.frame.size.height, self.bounds.size.width, self.footerView.frame.size.height);
|
||||
|
||||
// Refresh state
|
||||
[self setState:self.state animated:NO callback:nil force:YES];
|
||||
}
|
||||
|
||||
#pragma mark - View Quick Accessors
|
||||
@@ -298,9 +301,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
|
||||
{
|
||||
[super setState:state animated:animated callback:callback];
|
||||
[super setState:state animated:animated callback:callback force:force];
|
||||
|
||||
dispatch_block_t callbackCopy = [callback copy];
|
||||
|
||||
@@ -355,7 +358,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
callbackCopy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -366,6 +369,11 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
[self setState:state animated:animated callback:callback force:NO];
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (CGFloat)cachedMinHeight
|
||||
|
||||
@@ -66,6 +66,16 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
*/
|
||||
- (void)reloadData;
|
||||
|
||||
/**
|
||||
* State setter.
|
||||
*
|
||||
* @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).
|
||||
*/
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force;
|
||||
|
||||
/**
|
||||
* State setter.
|
||||
*
|
||||
|
||||
+32
-6
@@ -17,6 +17,10 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
@interface JBChartView ()
|
||||
|
||||
// Construction
|
||||
- (void)constructChartView;
|
||||
|
||||
// Validation
|
||||
- (void)validateHeaderAndFooterHeights;
|
||||
|
||||
@end
|
||||
@@ -25,14 +29,22 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
#pragma mark - Alloc/Init
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
self = [super initWithCoder:aDecoder];
|
||||
if (self)
|
||||
{
|
||||
[self constructChartView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
_mininumValue = kJBChartViewUndefinedMinimumValue;
|
||||
_maximumValue = kJBChartViewUndefinedMaximumValue;
|
||||
[self constructChartView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -42,6 +54,15 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
return [self initWithFrame:CGRectZero];
|
||||
}
|
||||
|
||||
#pragma mark - Construction
|
||||
|
||||
- (void)constructChartView
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
_mininumValue = kJBChartViewUndefinedMinimumValue;
|
||||
_maximumValue = kJBChartViewUndefinedMaximumValue;
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (void)reloadData
|
||||
@@ -49,7 +70,7 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
// Override
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
#pragma mark - Validation
|
||||
|
||||
- (void)validateHeaderAndFooterHeights
|
||||
{
|
||||
@@ -90,9 +111,9 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
|
||||
{
|
||||
if (_state == state)
|
||||
if ((_state == state) && !force)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -102,6 +123,11 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
// Override
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
[self setState:state animated:animated callback:callback force:NO];
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated
|
||||
{
|
||||
[self setState:state animated:animated callback:nil];
|
||||
|
||||
Regular → Executable
+61
-4
@@ -70,7 +70,8 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
* Occurs whenever there is a touch gesture on the chart (chart must be expanded).
|
||||
* The horizontal index is the closest index to the touch point & is clamped to it's max/min value if it moves outside of the view's bounds.
|
||||
* The lineIndex remains constant until the line is unselected and will be highlighted using the (optional) selectionColorForLineAtLineIndex: protocol.
|
||||
* Futhermore, all other lines that aren't selected will be dimmed to 50% opacity throughout the duration of the touch/move.
|
||||
* 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
|
||||
@@ -126,6 +127,21 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the color of a particular dot in a line at lineIndex within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
|
||||
*
|
||||
* Default: black color.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The color to be used to color a dot within a dotted line in the chart.
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the width of particular line at lineIndex within the chart.
|
||||
*
|
||||
@@ -138,6 +154,33 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the radius of all dots in a particular line at lineIndex within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
* Any value can be returned for lineIndex's that don't support dots, as it will never be called.
|
||||
*
|
||||
* Default: line width x 3.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The radius of the dots within a dotted line in the chart.
|
||||
*/
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the width of the (vertical) selection view to be overlayed on the chart during touch events.
|
||||
* The property showsVerticalSelection must be YES for the width to apply. The width is clamped to the
|
||||
* maxmimum width of the chart's bounds.
|
||||
*
|
||||
* Default: 20px.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
*
|
||||
* @return The width of the selection view used during chart selections.
|
||||
*/
|
||||
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
/**
|
||||
* Returns the (vertical) selection color to be overlayed on the chart during touch events.
|
||||
* The color is automically faded to transparent (vertically). The property showsVerticalSelection
|
||||
@@ -147,7 +190,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
*
|
||||
* @return The color to be used on chart selections.
|
||||
* @return The color of the selection view used during chart selections.
|
||||
*/
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView;
|
||||
|
||||
@@ -164,6 +207,20 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the selection color to be overlayed on a line within the chart during touch events.
|
||||
* The property showsLineSelection must be YES for the color to apply.
|
||||
*
|
||||
* Default: white color.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).point.
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return The color to be used to highlight a dot within a dotted line during chart selections.
|
||||
*/
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns the line style of a particular line at lineIndex within the chart.
|
||||
* See JBLineChartViewLineStyle for line style descriptions.
|
||||
@@ -192,14 +249,14 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns whether or not a line should be smoothed (rounded end caps and connections).
|
||||
* 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 ends and connections.
|
||||
* @return Whether or not a line should smooth it's connections and end caps.
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
|
||||
Regular → Executable
+163
-49
@@ -22,11 +22,13 @@ typedef NS_ENUM(NSUInteger, JBLineChartHorizontalIndexClamp){
|
||||
CGFloat static const kJBLineChartLinesViewStrokeWidth = 5.0;
|
||||
CGFloat static const kJBLineChartLinesViewMiterLimit = -5.0;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultLinePhase = 1.0f;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.5f;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultDimmedOpacity = 0.20f;
|
||||
NSInteger static const kJBLineChartLinesViewUnselectedLineIndex = -1;
|
||||
CGFloat static const kJBLineChartLinesViewSmoothThresholdSlope = 0.01f;
|
||||
NSInteger static const kJBLineChartLinesViewSmoothThresholdVertical = 1;
|
||||
|
||||
// Numerics (JBLineChartDotsView)
|
||||
NSInteger static const kJBLineChartDotsViewRadiusFactor = 3; // 3x size of line width
|
||||
NSInteger static const kJBLineChartDotsViewDefaultRadiusFactor = 3; // 3x size of line width
|
||||
NSInteger static const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
|
||||
// Numerics (JBLineSelectionView)
|
||||
@@ -44,7 +46,9 @@ static NSArray *kJBLineChartLineViewDefaultDashPattern = nil;
|
||||
|
||||
// Colors (JBLineChartView)
|
||||
static UIColor *kJBLineChartViewDefaultLineColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultDotColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
@interface JBLineLayer : CAShapeLayer
|
||||
|
||||
@@ -113,8 +117,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
- (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)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -170,7 +177,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
if (self == [JBLineChartView class])
|
||||
{
|
||||
kJBLineChartViewDefaultLineColor = [UIColor blackColor];
|
||||
kJBLineChartViewDefaultDotColor = [UIColor blackColor];
|
||||
kJBLineChartViewDefaultLineSelectionColor = [UIColor whiteColor];
|
||||
kJBLineChartViewDefaultDotSelectionColor = [UIColor whiteColor];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +246,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
CGFloat pointSpace = (self.bounds.size.width - (chartPadding * 2)) / ([self dataCount] - 1); // Space in between points
|
||||
CGFloat xOffset = chartPadding;
|
||||
CGFloat yOffset = 0;
|
||||
|
||||
|
||||
NSMutableArray *mutableChartData = [NSMutableArray array];
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
@@ -246,7 +255,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex];
|
||||
NSMutableArray *chartPointData = [NSMutableArray array];
|
||||
for (NSUInteger horizontalIndex=0; horizontalIndex<dataCount; horizontalIndex++)
|
||||
{
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartView:verticalValueForHorizontalIndex:atLineIndex:)], @"JBLineChartView // delegate must implement - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat rawHeight = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
NSAssert(rawHeight >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
|
||||
@@ -281,7 +290,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
// Create new line and overlay subviews
|
||||
self.linesView = [[JBLineChartLinesView alloc] initWithFrame:CGRectOffset(mainViewRect, 0, self.headerView.frame.size.height + self.headerPadding)];
|
||||
self.linesView.delegate = self;
|
||||
|
||||
|
||||
// Add new lines view
|
||||
if (self.footerView)
|
||||
{
|
||||
@@ -330,7 +339,12 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
self.verticalSelectionView = nil;
|
||||
}
|
||||
|
||||
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, kJBLineSelectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
|
||||
CGFloat selectionViewWidth = kJBLineSelectionViewWidth;
|
||||
if ([self.dataSource respondsToSelector:@selector(verticalSelectionWidthForLineChartView:)])
|
||||
{
|
||||
selectionViewWidth = MIN([self.dataSource verticalSelectionWidthForLineChartView:self], self.bounds.size.width);
|
||||
}
|
||||
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
|
||||
self.verticalSelectionView.alpha = 0.0;
|
||||
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
|
||||
if ([self.dataSource respondsToSelector:@selector(verticalSelectionColorForLineChartView:)])
|
||||
@@ -361,6 +375,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
// Position header and footer
|
||||
self.headerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.headerView.frame.size.height);
|
||||
self.footerView.frame = CGRectMake(self.bounds.origin.x, self.bounds.size.height - self.footerView.frame.size.height, self.bounds.size.width, self.footerView.frame.size.height);
|
||||
|
||||
// Refresh state
|
||||
[self setState:self.state animated:NO callback:nil force:YES];
|
||||
}
|
||||
|
||||
#pragma mark - View Quick Accessors
|
||||
@@ -393,7 +410,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
}
|
||||
|
||||
- (CGFloat)maxHeight
|
||||
{
|
||||
{
|
||||
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
|
||||
{
|
||||
return MAX(self.maximumValue, self.cachedMaxHeight);
|
||||
@@ -403,21 +420,39 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
- (CGFloat)padding
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
||||
CGFloat maxLineWidth = 0.0f;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
|
||||
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
{
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
CGFloat maxWidth = 0.0f;
|
||||
for (int lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
BOOL showsDots = NO;
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
|
||||
{
|
||||
CGFloat lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
|
||||
if (lineWidth > maxWidth)
|
||||
showsDots = [self.dataSource lineChartView:self showsDotsForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
CGFloat lineWidth = kJBLineChartLinesViewStrokeWidth; // default
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
||||
{
|
||||
lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineWidth];
|
||||
}
|
||||
|
||||
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
|
||||
if (showsDots)
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
{
|
||||
maxWidth = lineWidth;
|
||||
dotRadius = [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
}
|
||||
return ceil(maxWidth * 0.5);
|
||||
|
||||
CGFloat currentMaxLineWidth = MAX(dotRadius, lineWidth);
|
||||
if (currentMaxLineWidth > maxLineWidth)
|
||||
{
|
||||
maxLineWidth = currentMaxLineWidth;
|
||||
}
|
||||
}
|
||||
return ceil(kJBLineChartLinesViewStrokeWidth * 0.5);
|
||||
return ceil(maxLineWidth * 0.5);
|
||||
}
|
||||
|
||||
- (NSUInteger)dataCount
|
||||
@@ -475,15 +510,6 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return [self padding];
|
||||
}
|
||||
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self smoothLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:lineStyleForLineAtLineIndex:)])
|
||||
@@ -493,6 +519,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return JBLineChartViewLineStyleSolid;
|
||||
}
|
||||
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self smoothLineAtLineIndex:lineIndex];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - JBLineChartDotsViewDelegate
|
||||
|
||||
- (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView*)lineChartDotsView
|
||||
@@ -509,6 +544,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return kJBLineChartViewDefaultLineColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:colorForDotAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
return kJBLineChartViewDefaultDotColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForLineAtLineIndex:)])
|
||||
@@ -518,6 +562,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return kJBLineChartViewDefaultLineSelectionColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:selectionColorForDotAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self selectionColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
return kJBLineChartViewDefaultDotSelectionColor;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
||||
@@ -527,6 +580,18 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return kJBLineChartLinesViewStrokeWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
{
|
||||
return [self.dataSource lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
{
|
||||
return [self padding];
|
||||
@@ -543,9 +608,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force
|
||||
{
|
||||
[super setState:state animated:animated callback:callback];
|
||||
[super setState:state animated:animated callback:callback force:force];
|
||||
|
||||
if ([self.chartData count] > 0)
|
||||
{
|
||||
@@ -576,7 +641,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
[UIView animateWithDuration:kJBLineChartViewStateAnimationDuration delay:(self.state == JBChartViewStateExpanded) ? kJBLineChartViewStateAnimationDelay : 0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
adjustViewAlphas();
|
||||
} completion:nil];
|
||||
@@ -600,6 +665,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
[self setState:state animated:animated callback:callback force:NO];
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (CGFloat)cachedMinHeight
|
||||
@@ -808,8 +878,12 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
{
|
||||
[self.delegate didUnselectLineInLineChartView:self];
|
||||
}
|
||||
[self.linesView setSelectedLineIndex:kJBLineChartLinesViewUnselectedLineIndex animated:YES];
|
||||
[self.dotsView setSelectedLineIndex:kJBLineChartDotsViewUnselectedLineIndex animated:YES];
|
||||
|
||||
if (self.showsLineSelection)
|
||||
{
|
||||
[self.linesView setSelectedLineIndex:kJBLineChartLinesViewUnselectedLineIndex animated:YES];
|
||||
[self.dotsView setSelectedLineIndex:kJBLineChartDotsViewUnselectedLineIndex animated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
@@ -849,8 +923,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
{
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
|
||||
[self.linesView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
|
||||
[self.dotsView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
|
||||
if (self.showsLineSelection)
|
||||
{
|
||||
[self.linesView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
|
||||
[self.dotsView setSelectedLineIndex:[self lineIndexForPoint:touchPoint] animated:YES];
|
||||
}
|
||||
[self touchesBeganOrMovedWithTouches:touches];
|
||||
}
|
||||
|
||||
@@ -976,8 +1053,15 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
UIBezierPath *path = [UIBezierPath bezierPath];
|
||||
path.miterLimit = kJBLineChartLinesViewMiterLimit;
|
||||
|
||||
JBLineChartPoint *previousLineChartPoint = nil;
|
||||
CGFloat previousSlope;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:smoothLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
BOOL smoothLine = [self.delegate lineChartLinesView:self smoothLineAtLineIndex:lineIndex];
|
||||
|
||||
NSUInteger index = 0;
|
||||
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
|
||||
NSArray *sortedLineData = [lineData sortedArrayUsingSelector:@selector(compare:)];
|
||||
for (JBLineChartPoint *lineChartPoint in sortedLineData)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
@@ -985,9 +1069,37 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
JBLineChartPoint *nextLineChartPoint = nil;
|
||||
if (index != ([lineData count] - 1))
|
||||
{
|
||||
nextLineChartPoint = [sortedLineData objectAtIndex:(index + 1)];
|
||||
}
|
||||
|
||||
CGFloat nextSlope = (nextLineChartPoint != nil) ? ((nextLineChartPoint.position.y - lineChartPoint.position.y)) / ((nextLineChartPoint.position.x - lineChartPoint.position.x)) : previousSlope;
|
||||
CGFloat currentSlope = ((lineChartPoint.position.y - previousLineChartPoint.position.y)) / (lineChartPoint.position.x-previousLineChartPoint.position.x);
|
||||
|
||||
BOOL deltaFromNextSlope = ((currentSlope >= (nextSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope <= (nextSlope - kJBLineChartLinesViewSmoothThresholdSlope)));
|
||||
BOOL deltaFromPreviousSlope = ((currentSlope >= (previousSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope <= (previousSlope - kJBLineChartLinesViewSmoothThresholdSlope)));
|
||||
BOOL deltaFromPreviousY = (lineChartPoint.position.y >= previousLineChartPoint.position.y + kJBLineChartLinesViewSmoothThresholdVertical) || (lineChartPoint.position.y <= previousLineChartPoint.position.y - kJBLineChartLinesViewSmoothThresholdVertical);
|
||||
|
||||
if (smoothLine && deltaFromNextSlope && deltaFromPreviousSlope && deltaFromPreviousY)
|
||||
{
|
||||
CGFloat deltaX = lineChartPoint.position.x - previousLineChartPoint.position.x;
|
||||
CGFloat controlPointX = previousLineChartPoint.position.x + (deltaX / 2);
|
||||
|
||||
CGPoint controlPoint1 = CGPointMake(controlPointX, previousLineChartPoint.position.y);
|
||||
CGPoint controlPoint2 = CGPointMake(controlPointX, lineChartPoint.position.y);
|
||||
|
||||
[path addCurveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y))) controlPoint1:controlPoint1 controlPoint2:controlPoint2];
|
||||
}
|
||||
else
|
||||
{
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
}
|
||||
|
||||
previousSlope = currentSlope;
|
||||
}
|
||||
|
||||
previousLineChartPoint = lineChartPoint;
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -1004,9 +1116,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
shapeLayer.strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:lineIndex].CGColor;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:smoothLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
BOOL smoothLine = [self.delegate lineChartLinesView:self smoothLineAtLineIndex:lineIndex];
|
||||
if (smoothLine)
|
||||
if (smoothLine == YES)
|
||||
{
|
||||
shapeLayer.lineCap = kCALineCapRound;
|
||||
shapeLayer.lineJoin = kCALineJoinRound;
|
||||
@@ -1151,20 +1261,22 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
if ([self.delegate lineChartDotsView:self showsDotsForLineAtLineIndex:lineIndex]) // line at index contains dots
|
||||
{
|
||||
NSMutableArray *mutableDotViews = [NSMutableArray array];
|
||||
NSUInteger horizontalIndex = 0;
|
||||
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:widthForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat lineWidth = [self.delegate lineChartDotsView:self widthForLineAtLineIndex:lineIndex];
|
||||
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewRadiusFactor;
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
|
||||
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
||||
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForLineAtLineIndex:lineIndex];
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
[mutableDotViews addObject:dotView];
|
||||
[self addSubview:dotView];
|
||||
|
||||
horizontalIndex++;
|
||||
}
|
||||
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
|
||||
}
|
||||
@@ -1181,6 +1293,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
dispatch_block_t adjustDots = ^{
|
||||
[self.dotViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||
NSUInteger horizontalIndex = 0;
|
||||
for (JBLineChartDotView *dotView in (NSArray *)obj)
|
||||
{
|
||||
if ([key isKindOfClass:[NSNumber class]])
|
||||
@@ -1189,16 +1302,17 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
if (_selectedLineIndex == lineIndex)
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForLineAtLineIndex:lineIndex];
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForLineAtLineIndex:lineIndex];
|
||||
dotView.alpha = (_selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity;
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
dotView.alpha = (_selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : 0.0f; // hide dots on off-selection
|
||||
}
|
||||
}
|
||||
horizontalIndex++;
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.1.2"
|
||||
s.version = "2.4.2"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
s.screenshot = "https://raw.github.com/Jawbone/JBChartView/master/Screenshots/main.png"
|
||||
|
||||
s.license = { :type => 'Apache', :file => 'LICENSE' }
|
||||
s.author = { "Terry Worona" => "tworona@jawbone.com" }
|
||||
s.source = {
|
||||
:git => "https://github.com/Jawbone/JBChartView.git",
|
||||
:tag => "v2.1.2"
|
||||
:tag => "v2.4.2"
|
||||
}
|
||||
|
||||
s.platform = :ios, '7.0'
|
||||
s.source_files = 'Classes', 'Classes/**/*.{h,m}'
|
||||
s.source_files = 'Classes/**/*.{h,m}'
|
||||
s.requires_arc = true
|
||||
end
|
||||
@@ -211,11 +211,21 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidLineColor: kJBColorLineChartDefaultDashedLineColor;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView widthForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBLineChartViewControllerChartSolidLineWidth: kJBLineChartViewControllerChartDashedLineWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? 0.0: (kJBLineChartViewControllerChartDashedLineWidth * 4);
|
||||
}
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
@@ -226,6 +236,11 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidSelectedLineColor: kJBColorLineChartDefaultDashedSelectedLineColor;
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBColorLineChartDefaultSolidSelectedLineColor: kJBColorLineChartDefaultDashedSelectedLineColor;
|
||||
}
|
||||
|
||||
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? JBLineChartViewLineStyleSolid : JBLineChartViewLineStyleDashed;
|
||||
|
||||
@@ -38,7 +38,7 @@ Simply add the following line to your <code>Podfile</code>:
|
||||
Your Podfile should look something like:
|
||||
|
||||
platform :ios, '7.0'
|
||||
pod 'JBChartView', '~> 2.1.2'
|
||||
pod 'JBChartView', '~> 2.4.2'
|
||||
|
||||
### The Old School Way
|
||||
|
||||
@@ -181,13 +181,18 @@ The color, width and style of each line in the chart can be customized via the <
|
||||
return ...; // style of line in chart
|
||||
}
|
||||
|
||||
Furthermore, the color of the selection bar and line can be customized via the <i>optional</i> protocols:
|
||||
Furthermore, the color and width of the selection view along with the color of the selected line can be customized via the <i>optional</i> protocols:
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return ...; // color of selection view
|
||||
}
|
||||
|
||||
- (CGFloat)verticalSelectionWidthForLineChartView:(JBLineChartView *)lineChartView
|
||||
{
|
||||
return ...; // width of selection view
|
||||
}
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // color of selected line
|
||||
@@ -196,8 +201,18 @@ Furthermore, the color of the selection bar and line can be customized via the <
|
||||
By default, each line will not show dots for each point. To enable this on a per-line basis:
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
To customize the size of each dot (default 3x the line width), implement:
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
As well, by default, each line will have squared off end caps and connection points. To enable line smoothing:
|
||||
To customize the color of each dot during selection and non-selection events (default is white and black respectively), implement:
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
As well, by default, each line will have squared off end caps and connection points. To enable rounded connections and end caps:
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user