Compare commits

...

3 Commits

Author SHA1 Message Date
terryworona 706dbc1859 fixed up documentation error 2016-04-27 18:49:47 -07:00
terryworona 6cce1ae272 Update change log and pod spec 2016-02-29 14:56:58 -08:00
terryworona 0b603cde1f Fixes #201 2016-02-29 14:55:15 -08:00
5 changed files with 159 additions and 150 deletions
+8 -2
View File
@@ -1,8 +1,14 @@
# Change Log
## [Unreleased](https://github.com/Jawbone/JBChartView/tree/HEAD)
## [v3.0.8](https://github.com/Jawbone/JBChartView/tree/v3.0.8) (2016-02-29)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.7...v3.0.8)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.6...HEAD)
**Fixed bugs:**
- Cannot change bar colors after initial load [\#201](https://github.com/Jawbone/JBChartView/issues/201)
## [v3.0.7](https://github.com/Jawbone/JBChartView/tree/v3.0.7) (2016-02-26)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.6...v3.0.7)
**Closed issues:**
+138 -132
View File
@@ -250,122 +250,122 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
__weak JBBarChartView* weakSelf = self;
self.cachedBarViewHeights = nil;
__block NSUInteger barViewsCount = [self.barViews count];
dispatch_block_t updateExistingBarViewsBlock = ^{
__block CGFloat xOffset = 0;
[weakSelf.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
CGFloat height = [weakSelf normalizedHeightForRawHeight:(NSNumber *)obj];
if (index < [weakSelf.barViews count])
{
// Update bar
UIView *barView = [weakSelf.barViews objectAtIndex:index];
if (weakSelf.inverted)
if (shouldAnimate)
{
self.cachedBarViewHeights = nil;
__block NSUInteger barViewsCount = [self.barViews count];
dispatch_block_t updateExistingBarViewsBlock = ^{
__block CGFloat xOffset = 0;
[weakSelf.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
CGFloat height = [weakSelf normalizedHeightForRawHeight:(NSNumber *)obj];
if (index < [weakSelf.barViews count])
{
barView.frame = CGRectMake(xOffset, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], height);
// Update bar
UIView *barView = [weakSelf.barViews objectAtIndex:index];
if (weakSelf.inverted)
{
barView.frame = CGRectMake(xOffset, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], height);
}
else
{
barView.frame = CGRectMake(xOffset, weakSelf.bounds.size.height - height - weakSelf.footerView.frame.size.height, [weakSelf barWidth], height);
}
xOffset += ([weakSelf barWidth] + weakSelf.barPadding);
}
else
}];
};
dispatch_block_t preAddBarViewsBlock = ^{
__block CGFloat xOffset = 0;
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
if (index >= barViewsCount)
{
barView.frame = CGRectMake(xOffset, weakSelf.bounds.size.height - height - weakSelf.footerView.frame.size.height, [weakSelf barWidth], height);
// Create bar
UIView *barView = [weakSelf createBarViewForIndex:index];
if (weakSelf.inverted)
{
barView.frame = CGRectMake(xOffset, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], 0.0f);
}
else
{
barView.frame = CGRectMake(xOffset, self.bounds.size.height, [weakSelf barWidth], 0.0f);
}
// Update stored view
weakSelf.barViews = [NSArray arrayWithArray:[weakSelf.barViews arrayByAddingObject:barView]];
// Add bar to view
[weakSelf insertBarView:barView];
}
xOffset += ([weakSelf barWidth] + weakSelf.barPadding);
}
}];
};
dispatch_block_t preAddBarViewsBlock = ^{
__block CGFloat xOffset = 0;
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
if (index >= barViewsCount)
{
// Create bar
UIView *barView = [weakSelf createBarViewForIndex:index];
if (weakSelf.inverted)
}];
};
dispatch_block_t postAddBarViewsBlock = ^{
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
if (index >= barViewsCount)
{
barView.frame = CGRectMake(xOffset, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], 0.0f);
CGFloat height = [weakSelf normalizedHeightForRawHeight:(NSNumber *)obj];
UIView *barView = [weakSelf.barViews objectAtIndex:index];
if (weakSelf.inverted)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], height);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height - height - weakSelf.footerView.frame.size.height, [weakSelf barWidth], height);
}
}
else
{
barView.frame = CGRectMake(xOffset, self.bounds.size.height, [weakSelf barWidth], 0.0f);
}
// Update stored view
weakSelf.barViews = [NSArray arrayWithArray:[weakSelf.barViews arrayByAddingObject:barView]];
// Add bar to view
[weakSelf insertBarView:barView];
}
xOffset += ([weakSelf barWidth] + weakSelf.barPadding);
}];
};
dispatch_block_t postAddBarViewsBlock = ^{
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
if (index >= barViewsCount)
}];
};
dispatch_block_t preRemoveBarViewsBlock = ^{
// Move existing (removed) bars down
for (NSUInteger index=[weakSelf.chartData count]; index<[weakSelf.barViews count]; index++)
{
CGFloat height = [weakSelf normalizedHeightForRawHeight:(NSNumber *)obj];
UIView *barView = [weakSelf.barViews objectAtIndex:index];
if (weakSelf.inverted)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, [weakSelf barWidth], height);
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, 0.0f);
}
else
{
barView.frame = CGRectMake(barView.frame.origin.x, self.bounds.size.height - height - weakSelf.footerView.frame.size.height, [weakSelf barWidth], height);
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
}
}
}];
};
dispatch_block_t preRemoveBarViewsBlock = ^{
};
// Move existing (removed) bars down
for (NSUInteger index=[weakSelf.chartData count]; index<[weakSelf.barViews count]; index++)
{
UIView *barView = [weakSelf.barViews objectAtIndex:index];
if (weakSelf.inverted)
dispatch_block_t postRemoveBarViewsBlock = ^{
// Remove existing (removed) bars
for (NSUInteger index=[weakSelf.chartData count]; index<[weakSelf.barViews count]; index++)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.headerView.frame.size.height + weakSelf.headerPadding, barView.frame.size.width, 0.0f);
UIView *barView = [weakSelf.barViews objectAtIndex:index];
[barView removeFromSuperview];
}
else
// Update bar view collection
NSMutableArray *mutableBarViews = [NSMutableArray arrayWithArray:weakSelf.barViews];
[mutableBarViews removeObjectsInRange:(NSRange){[weakSelf.chartData count], [weakSelf.barViews count] - [weakSelf.chartData count]}];
weakSelf.barViews = [NSArray arrayWithArray:mutableBarViews];
};
dispatch_block_t refreshedCachedBarViewHeightsBlock = ^{
NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray arrayWithArray:weakSelf.cachedBarViewHeights];
for (UIView *barView in weakSelf.barViews)
{
barView.frame = CGRectMake(barView.frame.origin.x, weakSelf.bounds.size.height, barView.frame.size.width, barView.frame.size.height);
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:barView.frame.size.height]];
}
}
};
dispatch_block_t postRemoveBarViewsBlock = ^{
weakSelf.cachedBarViewHeights = [NSArray arrayWithArray:mutableCachedBarViewHeights];
};
// Remove existing (removed) bars
for (NSUInteger index=[weakSelf.chartData count]; index<[weakSelf.barViews count]; index++)
{
UIView *barView = [weakSelf.barViews objectAtIndex:index];
[barView removeFromSuperview];
}
// Update bar view collection
NSMutableArray *mutableBarViews = [NSMutableArray arrayWithArray:weakSelf.barViews];
[mutableBarViews removeObjectsInRange:(NSRange){[weakSelf.chartData count], [weakSelf.barViews count] - [weakSelf.chartData count]}];
weakSelf.barViews = [NSArray arrayWithArray:mutableBarViews];
};
dispatch_block_t refreshedCachedBarViewHeightsBlock = ^{
NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray arrayWithArray:weakSelf.cachedBarViewHeights];
for (UIView *barView in weakSelf.barViews)
{
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:barView.frame.size.height]];
}
weakSelf.cachedBarViewHeights = [NSArray arrayWithArray:mutableCachedBarViewHeights];
};
/*
* New data model equal;
* Update existing bars to accomodate new model.
*/
if ([self.chartData count] == [self.barViews count])
{
if (shouldAnimate)
/*
* New data model equal;
* Update existing bars to accomodate new model.
*/
if ([self.chartData count] == [self.barViews count])
{
[UIView animateWithDuration:kJBBarChartViewReloadDataAnimationDuration animations:^{
updateExistingBarViewsBlock();
@@ -374,21 +374,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
completionBlock();
}];
}
else
{
updateExistingBarViewsBlock();
refreshedCachedBarViewHeightsBlock();
completionBlock();
}
}
/*
* New data model greater;
* Update existing bars to accomodate new model & add new bars.
*/
else if ([self.chartData count] > [self.barViews count])
{
if (shouldAnimate)
/*
* New data model greater;
* Update existing bars to accomodate new model & add new bars.
*/
else if ([self.chartData count] > [self.barViews count])
{
[UIView animateWithDuration:kJBBarChartViewReloadDataAnimationDuration animations:^{
updateExistingBarViewsBlock();
@@ -402,23 +393,12 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
}];
}];
}
else
{
updateExistingBarViewsBlock();
preAddBarViewsBlock();
postAddBarViewsBlock();
refreshedCachedBarViewHeightsBlock();
completionBlock();
}
}
/*
* New data model less;
* Update existing bars to accomodate new model & remove legacy bars.
*/
else if ([self.chartData count] < [self.barViews count])
{
if (shouldAnimate)
/*
* New data model less;
* Update existing bars to accomodate new model & remove legacy bars.
*/
else if ([self.chartData count] < [self.barViews count])
{
[UIView animateWithDuration:kJBBarChartViewReloadDataAnimationDuration animations:^{
preRemoveBarViewsBlock();
@@ -432,14 +412,35 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
}];
}];
}
else
}
else
{
// Remove old bars
for (UIView *barView in self.barViews)
{
preRemoveBarViewsBlock();
postRemoveBarViewsBlock();
updateExistingBarViewsBlock();
refreshedCachedBarViewHeightsBlock();
completionBlock();
[barView removeFromSuperview];
}
self.cachedBarViewHeights = nil;
__block CGFloat xOffset = 0;
__block NSMutableArray *mutableBarViews = [NSMutableArray array];
__block NSMutableArray *mutableCachedBarViewHeights = [NSMutableArray array];
[self.chartData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
UIView *barView = [weakSelf createBarViewForIndex:index];
CGFloat height = [weakSelf normalizedHeightForRawHeight:(NSNumber *)obj];
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - weakSelf.footerView.frame.size.height, [weakSelf barWidth], height);
[mutableBarViews addObject:barView];
[mutableCachedBarViewHeights addObject:[NSNumber numberWithFloat:height]];
[weakSelf insertBarView:barView];
xOffset += ([weakSelf barWidth] + weakSelf.barPadding);
index++;
}];
self.barViews = [NSArray arrayWithArray:mutableBarViews];
self.cachedBarViewHeights = [NSArray arrayWithArray:mutableCachedBarViewHeights];
}
};
@@ -464,6 +465,11 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
createSelectionViewBlock();
createBarViewsBlock();
layoutHeaderAndFooterBlock();
if (!shouldAnimate)
{
completionBlock(); // animated versions call this internally
}
}
- (void)reloadData
+4 -4
View File
@@ -330,7 +330,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection color of a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
* As well, lineChartView:colorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default)
*
* Default: matches lineChartView:colorForLineAtLineIndex:.
*
@@ -344,7 +344,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection gradient layer of a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGradient.
* As well, lineChartView:colorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGradient.
*
* Note: gradients do not support multiple alphas. The alpha of gradient's first color be used throughout.
*
@@ -360,7 +360,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection fill color under a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionFillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
* As well, lineChartView:fillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleSolid (default).
*
* Default: matches lineChartView:fillColorForLineAtLineIndex:.
*
@@ -374,7 +374,7 @@ typedef NS_ENUM(NSInteger, JBLineChartViewColorStyle) {
/**
* Returns the selection fill gradient layer under a line within the chart during touch events.
* The property showsLineSelection must be YES for the color to apply.
* As well, lineChartView:selectionFillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGrdient.
* As well, lineChartView:fillColorStyleForLineAtLineIndex: must return JBLineChartViewColorStyleGrdient.
*
* Note: gradients do not support multiple alphas. The alpha of gradient's first color be used throughout.
*
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "3.0.7"
s.version = "3.0.8"
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 => "v3.0.7"
:tag => "v3.0.8"
}
s.platform = :ios, '6.0'
@@ -205,18 +205,15 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
- (void)chartToggleButtonPressed:(id)sender
{
int randomNumber = (-3) + rand() % (3-(-3));
UIView *buttonImageView = [self.navigationItem.rightBarButtonItem valueForKey:kJBBarChartViewControllerNavButtonViewKey];
buttonImageView.userInteractionEnabled = NO;
NSMutableArray *mutableChartData = [NSMutableArray array];
for (int i=0; i<(kJBBarChartViewControllerNumBars + randomNumber ); i++)
{
NSInteger delta = ((kJBBarChartViewControllerNumBars + randomNumber) - labs(((kJBBarChartViewControllerNumBars + randomNumber) - i) - i)) + 2;
[mutableChartData addObject:[NSNumber numberWithFloat:MAX((delta * kJBBarChartViewControllerMinBarHeight), arc4random() % (delta * kJBBarChartViewControllerMaxBarHeight))]];
}
self.chartData = [NSArray arrayWithArray:mutableChartData];
CGAffineTransform transform = self.barChartView.state == JBChartViewStateExpanded ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
buttonImageView.transform = transform;
[self.barChartView reloadDataAnimated:YES];
[self.barChartView setState:self.barChartView.state == JBChartViewStateExpanded ? JBChartViewStateCollapsed : JBChartViewStateExpanded animated:YES callback:^{
buttonImageView.userInteractionEnabled = YES;
}];
}
#pragma mark - Overrides