Compare commits

..

13 Commits

Author SHA1 Message Date
Terry Worona 833f6e9080 Fixed issue #97 2014-08-27 11:27:58 -07:00
Terry Worona eb48db2e73 Updated comment 2014-08-27 11:21:45 -07:00
Terry Worona 55b6dae956 Cleaned up bar pop animations 2014-08-27 11:19:45 -07:00
Terry Worona c44b276ae1 fixed vertical selection adjustment 2014-08-26 19:14:15 -07:00
Terry Worona 93f3d1862e simplified bar chart animations and added invert flag 2014-08-26 19:02:06 -07:00
Terry Worona 19a4a0bf5c Updated pod spec 2014-08-26 15:49:59 -07:00
Terry Worona 9d43c6dd23 updated read me and pod spec 2014-08-26 15:49:21 -07:00
Terry Worona 8598ff1488 Fixed issue #93 2014-08-26 15:46:03 -07:00
Terry Worona b9d28bfd59 Updated pod spec 2014-08-26 15:40:00 -07:00
Terry Worona dd1dce758e updated read me and change log 2014-08-26 15:39:25 -07:00
Terry Worona 9fce2fc1c0 Fixed #95 2014-08-26 15:35:40 -07:00
Terry Worona ab1cf713e6 Fixed bar chart selection view for non-homogenous bar widths 2014-08-26 15:29:05 -07:00
Terry Worona 4363147303 updated read me 2014-08-22 18:19:34 -07:00
8 changed files with 115 additions and 41 deletions
+13
View File
@@ -1,5 +1,18 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.4">2.8.4</a>
#### 08/27/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/97">#97</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.3">2.8.3</a>
#### 08/26/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/93">#93</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.2">2.8.2</a>
#### 08/26/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/96">#96</a>.
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/95">#95</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.8.1">2.8.1</a>
#### 08/22/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/issues/92">#92</a>.
+10 -1
View File
@@ -111,7 +111,7 @@
*
* @return Horizontal width (in pixels) between each bar.
*/
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
- (CGFloat)barPaddingForBarChartView:(JBBarChartView *)barChartView;
@end
@@ -127,4 +127,13 @@
*/
@property (nonatomic, assign) BOOL showsVerticalSelection;
/*
* Bars can be (vertically) positoned top to bottom instead of bottom up.
* If this property is set to YES, both the bar and the selection view will be inverted.
* For the inverted orientation to take effect, reloadData must be called.
*
* Default: NO.
*/
@property (nonatomic, assign, getter=isInverted) BOOL inverted;
@end
+76 -30
View File
@@ -12,7 +12,7 @@
CGFloat static const kJBBarChartViewBarBasePaddingMutliplier = 50.0f;
CGFloat static const kJBBarChartViewUndefinedCachedHeight = -1.0f;
CGFloat static const kJBBarChartViewStateAnimationDuration = 0.05f;
CGFloat static const kJBBarChartViewPopOffset = 10.0f; // used to offset bars for 'pop' animations
CGFloat static const kJBBarChartViewStatePopOffset = 10.0f;
NSInteger static const kJBBarChartViewUndefinedBarIndex = -1;
// Colors (JBChartView)
@@ -29,6 +29,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
@property (nonatomic, strong) NSDictionary *chartDataDictionary; // key = column, value = height
@property (nonatomic, strong) NSArray *barViews;
@property (nonatomic, strong) NSArray *cachedBarViewHeights;
@property (nonatomic, assign) CGFloat barPadding;
@property (nonatomic, assign) CGFloat cachedMaxHeight;
@property (nonatomic, assign) CGFloat cachedMinHeight;
@@ -42,7 +43,6 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (CGFloat)availableHeight;
- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight;
- (CGFloat)barWidth;
- (CGFloat)popOffset;
// Touch helpers
- (NSInteger)barViewIndexForPoint:(CGPoint)point;
@@ -167,9 +167,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
[barView removeFromSuperview];
}
self.cachedBarViewHeights = nil;
CGFloat xOffset = 0;
NSUInteger index = 0;
NSMutableArray *mutableBarViews = [NSMutableArray array];
NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray array];
for (NSNumber *key in [[self.chartDataDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)])
{
UIView *barView = nil; // since all bars are visible at once, no need to cache this view
@@ -195,11 +198,13 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
barView.backgroundColor = backgroundColor;
}
barView.tag = index;
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
CGFloat extensionHeight = height > 0.0 ? kJBBarChartViewPopOffset : 0.0;
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height + extensionHeight);
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height);
[mutableBarViews addObject:barView];
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:height]];
// Add new bar
if (self.footerView)
@@ -215,6 +220,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
index++;
}
self.barViews = [NSArray arrayWithArray:mutableBarViews];
self.cachedBarViewHeights = [NSArray arrayWithArray:mutableCachedBarViewHeights];
};
/*
@@ -229,7 +235,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
self.verticalSelectionView = nil;
}
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height - self.footerView.frame.size.height)];
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, [self barWidth], self.bounds.size.height - self.footerView.frame.size.height - self.headerView.frame.size.height - self.headerPadding)];
self.verticalSelectionView.alpha = 0.0;
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
if ([self.delegate respondsToSelector:@selector(barSelectionColorForBarChartView:)])
@@ -248,6 +254,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
[self addSubview:self.verticalSelectionView];
}
self.verticalSelectionView.transform = self.inverted ? CGAffineTransformMakeScale(1.0, -1.0) : CGAffineTransformIdentity;
};
createDataDictionaries();
@@ -296,42 +304,85 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
return 0;
}
- (CGFloat)popOffset
{
return self.bounds.size.height - self.footerView.frame.size.height;
}
#pragma mark - Setters
- (void)setState:(JBChartViewState)state animated:(BOOL)animated force:(BOOL)force callback:(void (^)())callback
{
[super setState:state animated:animated force:force callback:callback];
__weak JBBarChartView* weakSelf = self;
void (^updateBarView)(UIView *barView, BOOL popBar);
updateBarView = ^(UIView *barView, BOOL popBar) {
if (weakSelf.inverted)
{
if (weakSelf.state == JBChartViewStateExpanded)
{
if (popBar)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue]);
}
}
else if (weakSelf.state == JBChartViewStateCollapsed)
{
if (popBar)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, 0.0f);
}
}
}
else
{
if (weakSelf.state == JBChartViewStateExpanded)
{
if (popBar)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] - kJBBarChartViewStatePopOffset, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue], barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue]);
}
}
else if (weakSelf.state == JBChartViewStateCollapsed)
{
if (popBar)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height - weakSelf.footerView.frame.size.height - [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] - kJBBarChartViewStatePopOffset, barView.frame.size.width, [[weakSelf.cachedBarViewHeights objectAtIndex:barView.tag] floatValue] + kJBBarChartViewStatePopOffset);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height, barView.frame.size.width, 0.0f);
}
}
}
};
dispatch_block_t callbackCopy = [callback copy];
if ([self.barViews count] > 0)
{
if (animated)
{
CGFloat popOffset = [self popOffset];
NSUInteger index = 0;
for (UIView *barView in self.barViews)
{
[UIView animateWithDuration:kJBBarChartViewStateAnimationDuration delay:(kJBBarChartViewStateAnimationDuration * 0.5) * index options:UIViewAnimationOptionBeginFromCurrentState animations:^{
barView.frame = CGRectMake(barView.frame.origin.x, popOffset - barView.frame.size.height, barView.frame.size.width, barView.frame.size.height);
updateBarView(barView, YES);
} completion:^(BOOL finished) {
[UIView animateWithDuration:kJBBarChartViewStateAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
if (state == JBChartViewStateExpanded)
{
barView.frame = CGRectMake(barView.frame.origin.x, popOffset - barView.frame.size.height + kJBBarChartViewPopOffset, barView.frame.size.width, barView.frame.size.height);
}
else if (state == JBChartViewStateCollapsed)
{
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
}
updateBarView(barView, NO);
} completion:^(BOOL lastBarFinished) {
if (index == [self.barViews count] - 1)
if (barView.tag == [self.barViews count] - 1)
{
if (callbackCopy)
{
@@ -347,14 +398,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
for (UIView *barView in self.barViews)
{
if (state == JBChartViewStateExpanded)
{
barView.frame = CGRectMake(barView.frame.origin.x, (self.bounds.size.height + kJBBarChartViewPopOffset) - (barView.frame.size.height + self.footerView.frame.size.height), barView.frame.size.width, barView.frame.size.height);
}
else if (state == JBChartViewStateCollapsed)
{
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
}
updateBarView(barView, NO);
}
if (callbackCopy)
{
@@ -472,6 +516,8 @@ 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;
selectionViewFrame.origin.y = self.headerView.frame.size.height + self.headerPadding;
self.verticalSelectionView.frame = selectionViewFrame;
[self setVerticalSelectionViewVisible:YES animated:YES];
+3 -2
View File
@@ -361,7 +361,7 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
{
selectionViewWidth = MIN([self.delegate verticalSelectionWidthForLineChartView:self], self.bounds.size.width);
}
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height)];
self.verticalSelectionView = [[JBChartVerticalSelectionView alloc] initWithFrame:CGRectMake(0, 0, selectionViewWidth, self.bounds.size.height - self.footerView.frame.size.height - self.headerView.frame.size.height - self.headerPadding)];
self.verticalSelectionView.alpha = 0.0;
self.verticalSelectionView.hidden = !self.showsVerticalSelection;
@@ -935,7 +935,8 @@ static UIColor *kJBLineChartViewDefaultDotSelectionColor = nil;
}
CGFloat xOffset = fmin(self.bounds.size.width - self.verticalSelectionView.frame.size.width, fmax(0, touchPoint.x - (ceil(self.verticalSelectionView.frame.size.width * 0.5))));
self.verticalSelectionView.frame = CGRectMake(xOffset, self.verticalSelectionView.frame.origin.y, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
CGFloat yOffset = self.headerView.frame.size.height + self.headerPadding;
self.verticalSelectionView.frame = CGRectMake(xOffset, yOffset, self.verticalSelectionView.frame.size.width, self.verticalSelectionView.frame.size.height);
[self setVerticalSelectionViewVisible:YES animated:YES];
}
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.8.1"
s.version = "2.8.4"
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.8.1"
:tag => "v2.8.4"
}
s.platform = :ios, '6.0'
@@ -18,10 +18,10 @@
CGFloat const kJBBarChartViewControllerChartHeight = 250.0f;
CGFloat const kJBBarChartViewControllerChartPadding = 10.0f;
CGFloat const kJBBarChartViewControllerChartHeaderHeight = 80.0f;
CGFloat const kJBBarChartViewControllerChartHeaderPadding = 10.0f;
CGFloat const kJBBarChartViewControllerChartHeaderPadding = 20.0f;
CGFloat const kJBBarChartViewControllerChartFooterHeight = 25.0f;
CGFloat const kJBBarChartViewControllerChartFooterPadding = 5.0f;
NSUInteger kJBBarChartViewControllerBarPadding = 1;
CGFloat const kJBBarChartViewControllerBarPadding = 1.0f;
NSInteger const kJBBarChartViewControllerNumBars = 12;
NSInteger const kJBBarChartViewControllerMaxBarHeight = 10;
NSInteger const kJBBarChartViewControllerMinBarHeight = 5;
@@ -108,6 +108,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
self.barChartView.dataSource = self;
self.barChartView.headerPadding = kJBBarChartViewControllerChartHeaderPadding;
self.barChartView.minimumValue = 0.0f;
self.barChartView.inverted = NO;
self.barChartView.backgroundColor = kJBColorBarChartBackground;
JBChartHeaderView *headerView = [[JBChartHeaderView alloc] initWithFrame:CGRectMake(kJBBarChartViewControllerChartPadding, ceil(self.view.bounds.size.height * 0.5) - ceil(kJBBarChartViewControllerChartHeaderHeight * 0.5), self.view.bounds.size.width - (kJBBarChartViewControllerChartPadding * 2), kJBBarChartViewControllerChartHeaderHeight)];
@@ -177,7 +178,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
return [UIColor whiteColor];
}
- (NSUInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView
- (CGFloat)barPaddingForBarChartView:(JBBarChartView *)barChartView
{
return kJBBarChartViewControllerBarPadding;
}
@@ -231,7 +231,7 @@ 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);
}
+6 -2
View File
@@ -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.8.1'
pod 'JBChartView', '~> 2.8.4'
### The Old School Way
@@ -150,6 +150,10 @@ Lastly, any JBChartView subclass can be collapsed or expanded programmatically v
#### JBBarChartView
By default, a bar chart will orient all bars from the bottom up. Setting the following invert proprery to YES will cause both the selection view and bars to orient themselves top down.
@property (nonatomic, assign, getter=isInverted) BOOL inverted;
By default, a chart's bars will be black and flat. They can be customized by supplying a UIView subclass through the <i>optional</i> protocol:
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index
@@ -242,7 +246,7 @@ 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 a custom dot view instead of using the default circular impelmentation (note: custom dot views are automatically hidden when selected):
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;