Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d4df0184a2 | |||
| 4f313aab80 | |||
| b6262462c5 | |||
| 1080089753 | |||
| 0afba01a9a | |||
| 63b47667ec | |||
| 4d6baf066f | |||
| 359ef7d0ea | |||
| 7b1e6475f2 | |||
| 2b8853780c | |||
| 0754e2e5d2 | |||
| 52b722013e |
+18
-1
@@ -1,12 +1,29 @@
|
||||
# Changelog
|
||||
|
||||
## <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).
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.1">2.1.1</a>
|
||||
#### 04/02/14
|
||||
- Fixed minimumValue and maximumValue getter functions.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.1.0">2.1.0</a>
|
||||
#### 03/30/14
|
||||
- Added minimumValue and maximumValue properties.
|
||||
- Changed default min value implementation from 0 to chart's actual minimum value.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.0.2">2.0.2</a>
|
||||
#### 03/27/14
|
||||
- Added the ability to add point dots for lines in JBLineChartView.
|
||||
- Streamlined line styling.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.0.1">2.0.1</a>
|
||||
### 03/19/14
|
||||
#### 03/19/14
|
||||
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/22">#22</a>.
|
||||
|
||||
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.0.0">2.0.0</a>
|
||||
|
||||
+74
-19
@@ -10,7 +10,7 @@
|
||||
|
||||
// Numerics
|
||||
CGFloat static const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
|
||||
CGFloat static const kJBBarChartViewUndefinedMaxHeight = -1.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
|
||||
NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
|
||||
@@ -24,6 +24,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
@property (nonatomic, strong) NSArray *barViews;
|
||||
@property (nonatomic, assign) CGFloat barPadding;
|
||||
@property (nonatomic, assign) CGFloat cachedMaxHeight;
|
||||
@property (nonatomic, assign) CGFloat cachedMinHeight;
|
||||
@property (nonatomic, strong) JBChartVerticalSelectionView *verticalSelectionView;
|
||||
@property (nonatomic, assign) BOOL verticalSelectionViewVisible;
|
||||
|
||||
@@ -33,8 +34,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
// View quick accessors
|
||||
- (CGFloat)availableHeight;
|
||||
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight;
|
||||
- (CGFloat)maxHeight;
|
||||
- (CGFloat)minHeight;
|
||||
- (CGFloat)maxHeight;
|
||||
- (CGFloat)barWidth;
|
||||
- (CGFloat)popOffset;
|
||||
|
||||
@@ -94,7 +95,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
- (void)construct
|
||||
{
|
||||
_showsVerticalSelection = YES;
|
||||
_cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
|
||||
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
}
|
||||
|
||||
#pragma mark - Memory Management
|
||||
@@ -109,7 +111,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
- (void)reloadData
|
||||
{
|
||||
// reset cached max height
|
||||
self.cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
|
||||
self.cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
self.cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
|
||||
/*
|
||||
* The data collection holds all position information:
|
||||
@@ -235,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
|
||||
@@ -258,20 +264,22 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
return ((value - minHeight) / (maxHeight - minHeight)) * [self availableHeight];
|
||||
}
|
||||
|
||||
- (CGFloat)maxHeight
|
||||
{
|
||||
if (self.cachedMaxHeight == kJBBarChartViewUndefinedMaxHeight)
|
||||
{
|
||||
// max height is max value across all goals and values
|
||||
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
|
||||
self.cachedMaxHeight = [[chartValues lastObject] floatValue];
|
||||
}
|
||||
return self.cachedMaxHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)minHeight
|
||||
{
|
||||
return 0;
|
||||
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
|
||||
{
|
||||
return MIN(self.mininumValue, self.cachedMinHeight);
|
||||
}
|
||||
return self.cachedMinHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)maxHeight
|
||||
{
|
||||
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
|
||||
{
|
||||
return MAX(self.maximumValue, self.cachedMaxHeight);
|
||||
}
|
||||
return self.cachedMaxHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)barWidth
|
||||
@@ -293,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];
|
||||
|
||||
@@ -350,7 +358,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
|
||||
{
|
||||
callbackCopy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -361,6 +369,53 @@ 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
|
||||
{
|
||||
if(_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
{
|
||||
// min height is min value across all goals and values
|
||||
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
|
||||
_cachedMinHeight = [[chartValues firstObject] floatValue];
|
||||
}
|
||||
return _cachedMinHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)cachedMaxHeight
|
||||
{
|
||||
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
{
|
||||
// max height is max value across all goals and values
|
||||
NSArray *chartValues = [[[self.chartDataDictionary allValues] arrayByAddingObjectsFromArray:[self.chartDataDictionary allValues]] sortedArrayUsingSelector:@selector(compare:)];
|
||||
_cachedMaxHeight = [[chartValues lastObject] floatValue];
|
||||
}
|
||||
return _cachedMaxHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)mininumValue
|
||||
{
|
||||
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
|
||||
{
|
||||
return self.cachedMinHeight;
|
||||
}
|
||||
return [super mininumValue];
|
||||
}
|
||||
|
||||
- (CGFloat)maximumValue
|
||||
{
|
||||
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
|
||||
{
|
||||
return self.cachedMaxHeight;
|
||||
}
|
||||
return [super maximumValue];
|
||||
}
|
||||
|
||||
#pragma mark - Touch Helpers
|
||||
|
||||
- (NSInteger)barViewIndexForPoint:(CGPoint)point
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
extern CGFloat const kJBChartViewDefaultAnimationDuration;
|
||||
extern CGFloat const kJBChartViewUndefinedMinimumValue; // helper for undefined min/max values
|
||||
extern CGFloat const kJBChartViewUndefinedMaximumValue;
|
||||
|
||||
/**
|
||||
* At a minimum, a chart can support two states, along with animations to-and-from.
|
||||
@@ -39,6 +41,19 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat headerPadding;
|
||||
|
||||
/**
|
||||
* The minimum and maxmimum values of the chart.
|
||||
* If no value(s) are supplied, the min and max values of the chart's data source are used.
|
||||
*
|
||||
* If value(s) are supplied, they must be >= 0, otherwise an assertion will be thrown.
|
||||
* The min/max values are clamped to the ceiling and floor of the actual min/max values of the chart's data source;
|
||||
* for example, if a maximumValue of 20 is supplied & the chart's actual max is 100, then 100 will be used.
|
||||
*
|
||||
* For min/max modifications to take effect, reloadData must be called.
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat mininumValue;
|
||||
@property (nonatomic, assign) CGFloat maximumValue;
|
||||
|
||||
/**
|
||||
* Charts can either be expanded or contracted.
|
||||
* By default, a chart should be expanded on initialization.
|
||||
@@ -51,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.
|
||||
*
|
||||
|
||||
+23
-2
@@ -9,6 +9,8 @@
|
||||
#import "JBChartView.h"
|
||||
|
||||
CGFloat const kJBChartViewDefaultAnimationDuration = 0.25f;
|
||||
CGFloat const kJBChartViewUndefinedMinimumValue = -1.0f;
|
||||
CGFloat const kJBChartViewUndefinedMaximumValue = -1.0f;
|
||||
|
||||
// Color (JBChartSelectionView)
|
||||
static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
@@ -29,6 +31,8 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
if (self)
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
_mininumValue = kJBChartViewUndefinedMinimumValue;
|
||||
_maximumValue = kJBChartViewUndefinedMaximumValue;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -86,9 +90,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;
|
||||
}
|
||||
@@ -98,6 +102,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];
|
||||
@@ -108,6 +117,18 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
[self setState:state animated:NO];
|
||||
}
|
||||
|
||||
- (void)setMininumValue:(CGFloat)mininumValue
|
||||
{
|
||||
NSAssert(mininumValue >= 0, @"JBChartView // the minimumValue must be >= 0.");
|
||||
_mininumValue = mininumValue;
|
||||
}
|
||||
|
||||
- (void)setMaximumValue:(CGFloat)maximumValue
|
||||
{
|
||||
NSAssert(maximumValue >= 0, @"JBChartView // the maximumValue must be >= 0.");
|
||||
_maximumValue = maximumValue;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation JBChartVerticalSelectionView
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "JBChartView"
|
||||
s.version = "2.0.2"
|
||||
s.version = "2.1.3"
|
||||
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
|
||||
s.homepage = "https://github.com/Jawbone/JBChartView"
|
||||
|
||||
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Terry Worona" => "tworona@jawbone.com" }
|
||||
s.source = {
|
||||
:git => "https://github.com/Jawbone/JBChartView.git",
|
||||
:tag => "v2.0.2"
|
||||
:tag => "v2.1.3"
|
||||
}
|
||||
|
||||
s.platform = :ios, '7.0'
|
||||
|
||||
+154
-41
@@ -19,7 +19,6 @@ typedef NS_ENUM(NSUInteger, JBLineChartHorizontalIndexClamp){
|
||||
};
|
||||
|
||||
// Numerics (JBLineChartLineView)
|
||||
CGFloat static const kJBLineChartLinesViewEdgePadding = 10.0;
|
||||
CGFloat static const kJBLineChartLinesViewStrokeWidth = 5.0;
|
||||
CGFloat static const kJBLineChartLinesViewMiterLimit = -5.0;
|
||||
CGFloat static const kJBLineChartLinesViewDefaultLinePhase = 1.0f;
|
||||
@@ -34,7 +33,7 @@ NSInteger static const kJBLineChartDotsViewUnselectedLineIndex = -1;
|
||||
CGFloat static const kJBLineSelectionViewWidth = 20.0f;
|
||||
|
||||
// Numerics (JBLineChartView)
|
||||
CGFloat static const kJBLineChartViewUndefinedMaxHeight = -1.0f;
|
||||
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
|
||||
CGFloat static const kJBLineChartViewStateAnimationDuration = 0.25f;
|
||||
CGFloat static const kJBLineChartViewStateAnimationDelay = 0.05f;
|
||||
CGFloat static const kJBLineChartViewStateBounceOffset = 15.0f;
|
||||
@@ -88,6 +87,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView;
|
||||
- (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@@ -115,6 +115,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView widthForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView;
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
|
||||
|
||||
@end
|
||||
@@ -132,6 +133,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
@property (nonatomic, strong) JBLineChartDotsView *dotsView;
|
||||
@property (nonatomic, strong) JBChartVerticalSelectionView *verticalSelectionView;
|
||||
@property (nonatomic, assign) CGFloat cachedMaxHeight;
|
||||
@property (nonatomic, assign) CGFloat cachedMinHeight;
|
||||
@property (nonatomic, assign) BOOL verticalSelectionViewVisible;
|
||||
|
||||
// Initialization
|
||||
@@ -140,8 +142,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
// View quick accessors
|
||||
- (CGFloat)normalizedHeightForRawHeight:(CGFloat)rawHeight;
|
||||
- (CGFloat)availableHeight;
|
||||
- (CGFloat)maxHeight;
|
||||
- (CGFloat)minHeight;
|
||||
- (CGFloat)maxHeight;
|
||||
- (CGFloat)padding;
|
||||
- (NSUInteger)dataCount;
|
||||
|
||||
// Touch helpers
|
||||
@@ -205,15 +208,20 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
{
|
||||
_showsVerticalSelection = YES;
|
||||
_showsLineSelection = YES;
|
||||
_cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
|
||||
_cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
_cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
- (void)reloadData
|
||||
{
|
||||
// reset cached max height
|
||||
self.cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
|
||||
// Reset cached max height
|
||||
self.cachedMinHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
self.cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight;
|
||||
|
||||
// Padding
|
||||
CGFloat chartPadding = [self padding];
|
||||
|
||||
/*
|
||||
* Subview rectangle calculations
|
||||
@@ -226,8 +234,8 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
*/
|
||||
dispatch_block_t createChartData = ^{
|
||||
|
||||
CGFloat pointSpace = (self.bounds.size.width - (kJBLineChartLinesViewEdgePadding * 2)) / ([self dataCount] - 1); // Space in between points
|
||||
CGFloat xOffset = kJBLineChartLinesViewEdgePadding;
|
||||
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];
|
||||
@@ -253,7 +261,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
xOffset += pointSpace;
|
||||
}
|
||||
[mutableChartData addObject:chartPointData];
|
||||
xOffset = kJBLineChartLinesViewEdgePadding;
|
||||
xOffset = chartPadding;
|
||||
}
|
||||
self.chartData = [NSArray arrayWithArray:mutableChartData];
|
||||
};
|
||||
@@ -353,6 +361,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
|
||||
@@ -375,35 +386,41 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return self.bounds.size.height - self.headerView.frame.size.height - self.footerView.frame.size.height - self.headerPadding;
|
||||
}
|
||||
|
||||
- (CGFloat)maxHeight
|
||||
- (CGFloat)minHeight
|
||||
{
|
||||
if (self.cachedMaxHeight == kJBLineChartViewUndefinedMaxHeight)
|
||||
if (self.mininumValue != kJBChartViewUndefinedMinimumValue)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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];
|
||||
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
|
||||
if (height > maxHeight)
|
||||
{
|
||||
maxHeight = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.cachedMaxHeight = maxHeight;
|
||||
return MIN(self.mininumValue, self.cachedMinHeight);
|
||||
}
|
||||
return self.cachedMinHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)maxHeight
|
||||
{
|
||||
if (self.maximumValue != kJBChartViewUndefinedMaximumValue)
|
||||
{
|
||||
return MAX(self.maximumValue, self.cachedMaxHeight);
|
||||
}
|
||||
return self.cachedMaxHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)minHeight
|
||||
- (CGFloat)padding
|
||||
{
|
||||
return 0;
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:widthForLineAtLineIndex:)])
|
||||
{
|
||||
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++)
|
||||
{
|
||||
CGFloat lineWidth = [self.dataSource lineChartView:self widthForLineAtLineIndex:lineIndex];
|
||||
if (lineWidth > maxWidth)
|
||||
{
|
||||
maxWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
return ceil(maxWidth * 0.5);
|
||||
}
|
||||
return ceil(kJBLineChartLinesViewStrokeWidth * 0.5);
|
||||
}
|
||||
|
||||
- (NSUInteger)dataCount
|
||||
@@ -456,6 +473,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return kJBLineChartLinesViewStrokeWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView
|
||||
{
|
||||
return [self padding];
|
||||
}
|
||||
|
||||
- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:smoothLineAtLineIndex:)])
|
||||
@@ -508,6 +530,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
return kJBLineChartLinesViewStrokeWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView
|
||||
{
|
||||
return [self padding];
|
||||
}
|
||||
|
||||
- (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex
|
||||
{
|
||||
if ([self.dataSource respondsToSelector:@selector(lineChartView:showsDotsForLineAtLineIndex:)])
|
||||
@@ -519,9 +546,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)
|
||||
{
|
||||
@@ -552,7 +579,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
[UIView animateWithDuration:kJBLineChartViewStateAnimationDuration delay:(self.state == JBChartViewStateExpanded) ? kJBLineChartViewStateAnimationDelay : 0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
|
||||
adjustViewAlphas();
|
||||
} completion:nil];
|
||||
@@ -576,6 +603,83 @@ 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
|
||||
{
|
||||
if (_cachedMinHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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];
|
||||
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
|
||||
if (height < minHeight)
|
||||
{
|
||||
minHeight = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
_cachedMinHeight = minHeight;
|
||||
}
|
||||
return _cachedMinHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)cachedMaxHeight
|
||||
{
|
||||
if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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];
|
||||
NSAssert(height >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0");
|
||||
if (height > maxHeight)
|
||||
{
|
||||
maxHeight = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
_cachedMaxHeight = maxHeight;
|
||||
}
|
||||
return _cachedMaxHeight;
|
||||
}
|
||||
|
||||
- (CGFloat)mininumValue
|
||||
{
|
||||
if ([super mininumValue] == kJBChartViewUndefinedMinimumValue)
|
||||
{
|
||||
return self.cachedMinHeight;
|
||||
}
|
||||
return [super mininumValue];
|
||||
}
|
||||
|
||||
- (CGFloat)maximumValue
|
||||
{
|
||||
if ([super maximumValue] == kJBChartViewUndefinedMaximumValue)
|
||||
{
|
||||
return self.cachedMaxHeight;
|
||||
}
|
||||
return [super maximumValue];
|
||||
}
|
||||
|
||||
#pragma mark - Touch Helpers
|
||||
|
||||
- (CGPoint)clampPoint:(CGPoint)point toBounds:(CGRect)bounds padding:(CGFloat)padding
|
||||
@@ -628,6 +732,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
NSInteger leftHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampLeft];
|
||||
NSInteger rightHorizontalIndex = [self horizontalIndexForPoint:point indexClamp:JBLineChartHorizontalIndexClampRight];
|
||||
|
||||
// Padding
|
||||
CGFloat chartPadding = [self padding];
|
||||
|
||||
NSUInteger shortestDistance = INT_MAX;
|
||||
NSInteger selectedIndex = kJBLineChartUnselectedLineIndex;
|
||||
NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView");
|
||||
@@ -642,11 +749,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
// Left point
|
||||
JBLineChartPoint *leftLineChartPoint = [lineData objectAtIndex:leftHorizontalIndex];
|
||||
CGPoint leftPoint = CGPointMake(leftLineChartPoint.position.x, fmin(fmax(kJBLineChartLinesViewEdgePadding, self.linesView.bounds.size.height - leftLineChartPoint.position.y), self.linesView.bounds.size.height - kJBLineChartLinesViewEdgePadding));
|
||||
CGPoint leftPoint = CGPointMake(leftLineChartPoint.position.x, fmin(fmax(chartPadding, self.linesView.bounds.size.height - leftLineChartPoint.position.y), self.linesView.bounds.size.height - chartPadding));
|
||||
|
||||
// Right point
|
||||
JBLineChartPoint *rightLineChartPoint = [lineData objectAtIndex:rightHorizontalIndex];
|
||||
CGPoint rightPoint = CGPointMake(rightLineChartPoint.position.x, fmin(fmax(kJBLineChartLinesViewEdgePadding, self.linesView.bounds.size.height - rightLineChartPoint.position.y), self.linesView.bounds.size.height - kJBLineChartLinesViewEdgePadding));
|
||||
CGPoint rightPoint = CGPointMake(rightLineChartPoint.position.x, fmin(fmax(chartPadding, self.linesView.bounds.size.height - rightLineChartPoint.position.y), self.linesView.bounds.size.height - chartPadding));
|
||||
|
||||
// Touch point
|
||||
CGPoint normalizedTouchPoint = CGPointMake(point.x, self.linesView.bounds.size.height - point.y);
|
||||
@@ -676,7 +783,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
}
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:kJBLineChartLinesViewEdgePadding];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:[self padding]];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(lineChartView:didSelectLineAtIndex:horizontalIndex:touchPoint:)])
|
||||
{
|
||||
@@ -749,7 +856,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchPoint = [self clampPoint:[touch locationInView:self.linesView] toBounds:self.linesView.bounds padding:kJBLineChartLinesViewEdgePadding];
|
||||
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];
|
||||
[self touchesBeganOrMovedWithTouches:touches];
|
||||
@@ -867,6 +974,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (NSArray *)chartDataForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
|
||||
NSArray *chartData = [self.delegate chartDataForLineChartLinesView:self];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartLinesView:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView");
|
||||
CGFloat padding = [self.delegate paddingForLineChartLinesView:self];
|
||||
|
||||
NSUInteger lineIndex = 0;
|
||||
for (NSArray *lineData in chartData)
|
||||
@@ -879,11 +989,11 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)))];
|
||||
[path moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
}
|
||||
else
|
||||
{
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)))];
|
||||
[path addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))];
|
||||
}
|
||||
|
||||
index++;
|
||||
@@ -1036,6 +1146,9 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(chartDataForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (NSArray *)chartDataForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
|
||||
NSArray *chartData = [self.delegate chartDataForLineChartDotsView:self];
|
||||
|
||||
NSAssert([self.delegate respondsToSelector:@selector(paddingForLineChartDotsView:)], @"JBLineChartDotsView // delegate must implement - (CGFloat)paddingForLineChartDotsView:(JBLineChartDotsView *)lineChartDotsView");
|
||||
CGFloat padding = [self.delegate paddingForLineChartDotsView:self];
|
||||
|
||||
NSUInteger lineIndex = 0;
|
||||
NSMutableDictionary *mutableDotViewsDict = [NSMutableDictionary dictionary];
|
||||
@@ -1053,7 +1166,7 @@ static UIColor *kJBLineChartViewDefaultLineSelectionColor = nil;
|
||||
CGFloat dotRadius = lineWidth * kJBLineChartDotsViewRadiusFactor;
|
||||
|
||||
JBLineChartDotView *dotView = [[JBLineChartDotView alloc] initWithRadius:dotRadius];
|
||||
dotView.center = CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - kJBLineChartLinesViewEdgePadding, fmax(kJBLineChartLinesViewEdgePadding, lineChartPoint.position.y)));
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user