Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b9d28bfd59 | |||
| dd1dce758e | |||
| 9fce2fc1c0 | |||
| ab1cf713e6 | |||
| 4363147303 | |||
| 8a1770c6df | |||
| f84f322598 | |||
| 04e1aa5b98 | |||
| ab07aa2399 | |||
| f01e11a0e2 | |||
| 76984c7c7c | |||
| d38a04a70d | |||
| 385d5b3589 | |||
| 90100c7277 | |||
| eca1c0507e | |||
| ac870e45ce | |||
| 74f588b7e6 | |||
| 406b64ae0c | |||
| 92e56d78c5 | |||
| 36ec328346 | |||
| b763ae540c | |||
| 7ffdf6d9da | |||
| 6531c68574 | |||
| ebae36bd2f |
+26
-1
@@ -1,6 +1,31 @@
|
||||
# Changelog
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.7.0">2.7.1</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>.
|
||||
|
||||
|
||||
+18
-19
@@ -9,24 +9,9 @@
|
||||
// Views
|
||||
#import "JBChartView.h"
|
||||
|
||||
@protocol JBBarChartViewDataSource;
|
||||
@protocol JBBarChartViewDelegate;
|
||||
@class JBBarChartView;
|
||||
|
||||
@interface JBBarChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Vertical highlight overlayed on bar during touch events.
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsVerticalSelection;
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBBarChartViewDataSource <NSObject>
|
||||
@protocol JBBarChartViewDataSource <JBChartViewDataSource>
|
||||
|
||||
@required
|
||||
|
||||
@@ -55,12 +40,12 @@
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBBarChartViewDelegate <NSObject>
|
||||
@protocol JBBarChartViewDelegate <JBChartViewDelegate>
|
||||
|
||||
@required
|
||||
|
||||
/**
|
||||
* Height for a bar at a given index (left to right). There is no ceiling on the the height;
|
||||
* 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.
|
||||
@@ -129,3 +114,17 @@
|
||||
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBBarChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Vertical highlight overlayed on bar during touch events.
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsVerticalSelection;
|
||||
|
||||
@end
|
||||
|
||||
@@ -472,6 +472,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
CGRect barViewFrame = barView.frame;
|
||||
CGRect selectionViewFrame = self.verticalSelectionView.frame;
|
||||
selectionViewFrame.origin.x = barViewFrame.origin.x;
|
||||
selectionViewFrame.size.width = barViewFrame.size.width;
|
||||
self.verticalSelectionView.frame = selectionViewFrame;
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
|
||||
|
||||
@@ -24,8 +24,26 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
JBChartViewStateCollapsed
|
||||
};
|
||||
|
||||
@protocol JBChartViewDataSource <NSObject>
|
||||
|
||||
// Extend (via subclass) to add custom functionality
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBChartViewDelegate <NSObject>
|
||||
|
||||
// Extend (via subclass) to add custom functionality
|
||||
|
||||
@end
|
||||
|
||||
@interface JBChartView : UIView
|
||||
|
||||
/*
|
||||
* Base dataSource and delegate protocols.
|
||||
*/
|
||||
@property (nonatomic, weak) id<JBChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Header and footer views are shown above and below the chart respectively.
|
||||
* Each view will be stretched horizontally to fill width of chart.
|
||||
|
||||
+53
-37
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "JBChartView.h"
|
||||
|
||||
@class JBLineChartView;
|
||||
|
||||
/**
|
||||
* Current support for two line styles: solid (default) and dashed.
|
||||
*/
|
||||
@@ -22,33 +24,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
JBLineChartViewLineStyleDashed
|
||||
};
|
||||
|
||||
@protocol JBLineChartViewDataSource;
|
||||
@protocol JBLineChartViewDelegate;
|
||||
|
||||
@interface JBLineChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Vertical highlight overlayed on a line graph during touch events.
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsVerticalSelection;
|
||||
|
||||
/**
|
||||
* A highlight shown on a line within the graph during touch events. The highlighted line
|
||||
* is the closest line to the touch point and corresponds to the lineIndex delegatd back via
|
||||
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex:
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsLineSelection;
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBLineChartViewDataSource <NSObject>
|
||||
@protocol JBLineChartViewDataSource <JBChartViewDataSource>
|
||||
|
||||
@required
|
||||
|
||||
@@ -99,9 +75,26 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*/
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
/**
|
||||
* Returns a (custom) UIView instance representing a dot (x,y point) within the chart.
|
||||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex.
|
||||
* This protocol supercedes colorForDotAtHorizontalIndex: and dotRadiusForDotAtHorizontalIndex:.
|
||||
* If nil is returned. the original dot protocols will take precedence. During selection events, a custom
|
||||
* dot view is automatically hidden.
|
||||
*
|
||||
* Default: nil.
|
||||
*
|
||||
* @param lineChartView The line chart object requesting this information.
|
||||
* @param horizontalIndex The 0-based horizontal index of a selection point (left to right, x-axis).
|
||||
* @param lineIndex An index number identifying a line in the chart.
|
||||
*
|
||||
* @return A custom UIView instance representing a dot at a particular horizontal index within a dotted line.
|
||||
*/
|
||||
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
|
||||
@protocol JBLineChartViewDelegate <NSObject>
|
||||
@protocol JBLineChartViewDelegate <JBChartViewDelegate>
|
||||
|
||||
@required
|
||||
|
||||
@@ -128,7 +121,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
*
|
||||
* @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 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;
|
||||
@@ -173,7 +166,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.
|
||||
@@ -200,11 +193,12 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
* 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.
|
||||
@@ -220,17 +214,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.
|
||||
@@ -265,7 +258,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.
|
||||
@@ -286,3 +279,26 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){
|
||||
- (JBLineChartViewLineStyle)lineChartView:(JBLineChartView *)lineChartView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBLineChartView : JBChartView
|
||||
|
||||
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Vertical highlight overlayed on a line graph during touch events.
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsVerticalSelection;
|
||||
|
||||
/**
|
||||
* A highlight shown on a line within the graph during touch events. The highlighted line
|
||||
* is the closest line to the touch point and corresponds to the lineIndex delegatd back via
|
||||
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex:
|
||||
*
|
||||
* Default: YES.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL showsLineSelection;
|
||||
|
||||
@end
|
||||
|
||||
+128
-40
@@ -137,7 +137,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -363,12 +364,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
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.delegate respondsToSelector:@selector(verticalSelectionColorForLineChartView:)])
|
||||
{
|
||||
UIColor *selectionViewBackgroundColor = [self.delegate verticalSelectionColorForLineChartView:self];
|
||||
NSAssert(selectionViewBackgroundColor != nil, @"JBLineChartView // delegate function - (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView must return a non-nil UIColor");
|
||||
self.verticalSelectionView.bgColor = selectionViewBackgroundColor;
|
||||
}
|
||||
|
||||
// Add new selection bar
|
||||
if (self.footerView)
|
||||
@@ -437,16 +432,82 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
lineWidth = [self.delegate lineChartView:self widthForLineAtLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewDefaultRadiusFactor; // default
|
||||
CGFloat maxDotLength = 0;
|
||||
if (showsDots)
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++)
|
||||
{
|
||||
dotRadius = [self.delegate 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;
|
||||
@@ -580,16 +641,22 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
return kJBLineChartLinesViewStrokeWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForLineAtLineIndex:)])
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:dotRadiusForDotAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self.delegate lineChartView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
return [self.delegate lineChartView:self dotRadiusForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
else
|
||||
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
}
|
||||
|
||||
- (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:dotViewAtHorizontalIndex:atLineIndex:)])
|
||||
{
|
||||
return [self lineChartDotsView:lineChartDotsView widthForLineAtLineIndex:lineIndex] * kJBLineChartDotsViewDefaultRadiusFactor;
|
||||
return [self.dataSource lineChartView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
@@ -846,20 +913,27 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
|
||||
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:touchPoint:)])
|
||||
{
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
NSUInteger horizontalIndex = [self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]];
|
||||
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:horizontalIndex touchPoint:[touch locationInView:self]];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:)])
|
||||
{
|
||||
NSUInteger lineIndex = self.linesView.selectedLineIndex != kJBLineChartLinesViewUnselectedLineIndex ? self.linesView.selectedLineIndex : [self lineIndexForPoint:touchPoint];
|
||||
[self.delegate lineChartView:self didSelectLineAtIndex:lineIndex horizontalIndex:[self horizontalIndexForPoint:touchPoint indexClamp:JBLineChartHorizontalIndexClampNone lineData:[self.chartData objectAtIndex:lineIndex]]];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:verticalSelectionColorForLineAtLineIndex:)])
|
||||
{
|
||||
UIColor *verticalSelectionColor = [self.delegate lineChartView:self verticalSelectionColorForLineAtLineIndex:lineIndex];
|
||||
NSAssert(verticalSelectionColor != nil, @"JBLineChartView // delegate function - (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex must return a non-nil UIColor");
|
||||
self.verticalSelectionView.bgColor = verticalSelectionColor;
|
||||
}
|
||||
|
||||
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.verticalSelectionView.frame.size.width * 0.5))));
|
||||
self.verticalSelectionView.frame = CGRectMake(xOffset, self.verticalSelectionView.frame.origin.y, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
|
||||
[self setVerticalSelectionViewVisible:YES animated:YES];
|
||||
@@ -892,8 +966,6 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
{
|
||||
_verticalSelectionViewVisible = verticalSelectionViewVisible;
|
||||
|
||||
[self bringSubviewToFront:self.verticalSelectionView];
|
||||
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:kJBChartViewDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
@@ -1345,19 +1417,26 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
NSMutableArray *mutableDotViews = [NSMutableArray array];
|
||||
NSUInteger horizontalIndex = 0;
|
||||
for (JBLineChartPoint *lineChartPoint in [lineData sortedArrayUsingSelector:@selector(compare:)])
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtLineIndex:lineIndex];
|
||||
|
||||
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
||||
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
dotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
[mutableDotViews addObject:dotView];
|
||||
[self addSubview:dotView];
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotViewAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIView *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
UIView *currentDotView = [self.delegate lineChartDotsView:self dotViewAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
// System dot
|
||||
if (currentDotView == nil)
|
||||
{
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:dotRadiusForLineAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView dotRadiusForLineAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
CGFloat dotRadius = [self.delegate lineChartDotsView:self dotRadiusForLineAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
|
||||
currentDotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // delegate must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
|
||||
currentDotView.backgroundColor = [self.delegate lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
|
||||
}
|
||||
|
||||
currentDotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)));
|
||||
[mutableDotViews addObject:currentDotView];
|
||||
[self addSubview:currentDotView];
|
||||
|
||||
horizontalIndex++;
|
||||
}
|
||||
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
|
||||
@@ -1378,22 +1457,31 @@ 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
|
||||
dotView.alpha = (weakSelf.selectedLineIndex == lineIndex) ? 0.0f : 1.0f; // hide custom dots on selection
|
||||
}
|
||||
}
|
||||
horizontalIndex++;
|
||||
@@ -1430,7 +1518,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
self.layer.cornerRadius = (radius * 0.5);
|
||||
self.layer.cornerRadius = (radius * 0.5f);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.7.1"
|
||||
s.version = "2.8.2"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
@@ -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.7.1"
|
||||
:tag => "v2.8.2"
|
||||
}
|
||||
|
||||
s.platform = :ios, '6.0'
|
||||
|
||||
@@ -235,7 +235,7 @@ NSString * const kJBAreaChartViewControllerNavButtonViewKey = @"view";
|
||||
return kJBAreaChartViewControllerChartLineWidth;
|
||||
}
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
|
||||
@@ -231,12 +231,12 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
return (lineIndex == JBLineChartLineSolid) ? kJBLineChartViewControllerChartSolidLineWidth: kJBLineChartViewControllerChartDashedLineWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView dotRadiusForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return (lineIndex == JBLineChartLineSolid) ? 0.0: (kJBLineChartViewControllerChartDashedLineWidth * 4);
|
||||
}
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return [UIColor whiteColor];
|
||||
}
|
||||
|
||||
@@ -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.7.1'
|
||||
pod 'JBChartView', '~> 2.8.2'
|
||||
|
||||
### The Old School Way
|
||||
|
||||
@@ -208,7 +208,7 @@ The color, width and style of each line in the chart can be customized via the <
|
||||
|
||||
Furthermore, the color and width of the selection view along with the color of the selected line can be customized via the <i>optional</i> protocols:
|
||||
|
||||
- (UIColor *)verticalSelectionColorForLineChartView:(JBLineChartView *)lineChartView
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView verticalSelectionColorForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
return ...; // color of selection view
|
||||
}
|
||||
@@ -234,7 +234,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 +242,10 @@ To customize the color of each dot during selection and non-selection events (de
|
||||
|
||||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
Alternatively, you can supply your own UIView instead of using the default impelmentation (note: custom dot views are automatically hidden when selected):
|
||||
|
||||
- (UIView *)lineChartView:(JBLineChartView *)lineChartView dotViewAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
As well, by default, each line will have squared off end caps and connection points. To enable rounded connections and end caps:
|
||||
|
||||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
Reference in New Issue
Block a user