Compare commits

..

14 Commits

Author SHA1 Message Date
Terry Worona 86440913ba Updated read me and pod spec 2014-01-02 10:20:51 -08:00
Terry Worona c1ac9e4a2f Remove ivar access except for designated functions 2014-01-02 10:02:47 -08:00
terryworona 6f185f9e53 Merge pull request #8 from l4u/cache
Reset cached max height on data reload Fixes #7
2014-01-02 10:00:55 -08:00
Leo Lou d142629dd3 Reset cached max height on data reload Fixes #7 2014-01-02 18:33:45 +08:00
Terry Worona 84d9c0f5da updated pod spec and read me 2013-12-26 10:00:12 -05:00
Terry Worona 5f400d3c91 Updated datasource to request bar view instead of color 2013-12-25 17:25:58 -05:00
Terry Worona 409b58c53c updated pod spec and read me 2013-12-23 18:02:30 -05:00
Terry Worona 0b6108dea8 resolved #4 | removed bar shadow from bar chart subviews 2013-12-23 17:50:20 -05:00
Terry Worona c7fe1c4114 updated specs and readme 2013-12-17 11:37:47 -08:00
Terry Worona 318d59dadd Fixed footer touches up alpha bug 2013-12-17 11:35:45 -08:00
Terry Worona ffd12921a4 updated read me and podspec 2013-12-14 23:26:16 -08:00
Terry Worona ef2f02743f Added footer view checks for selection views 2013-12-14 23:24:28 -08:00
terryworona 74d63d31e3 Merge pull request #2 from joelkraut/master
If there is no footer view, bars won't be added to the chart.
2013-12-14 23:18:42 -08:00
Joel Kraut 49c7bdee0c If there is no footer view, bars won't be added to the chart. 2013-12-13 15:43:58 -08:00
7 changed files with 57 additions and 36 deletions
+4 -4
View File
@@ -90,16 +90,16 @@
- (NSInteger)barPaddingForBarChartView:(JBBarChartView *)barChartView;
/**
* The color of all bars within the chart.
* A UIView subclass representing the bar at a particular index.
*
* Default: black color
* Default: solid black UIView
*
* @param barChartView The origin chart
* @param index The 0-based index of a given bar (left to right, x-axis)
*
* @return The color to be used on each of the bars within the chart.
* @return A UIView subclass. The view will automatically be resized by the chart during creation (ie. no need to set the frame).
*/
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index;
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index;
/**
* The selection color to be overlayed on a bar during touch events.
+32 -13
View File
@@ -78,6 +78,9 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBBarChartViewUndefinedMaxHeight;
/*
* The data collection holds all position information:
* constructed via datasource and delegate functions
@@ -129,25 +132,30 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
NSMutableArray *mutableBarViews = [NSMutableArray array];
for (NSNumber *key in [[self.chartDataDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)])
{
UIView *barView = [[UIView alloc] init];
if ([self.dataSource respondsToSelector:@selector(barColorForBarChartView:atIndex:)])
UIView *barView = nil; // since all bars are visible at once, no need to cache this view
if ([self.dataSource respondsToSelector:@selector(barViewForBarChartView:atIndex:)])
{
barView.backgroundColor = [self.dataSource barColorForBarChartView:self atIndex:index];
barView = [self.dataSource barViewForBarChartView:self atIndex:index];
}
else
{
barView = [[UIView alloc] init];
barView.backgroundColor = kJBBarChartViewDefaultBarColor;
}
}
CGFloat height = [self normalizedHeightForRawHeight:[self.chartDataDictionary objectForKey:key]];
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height + self.headerPadding, [self barWidth], height + kJBBarChartViewPopOffset - self.headerPadding);
barView.layer.shadowColor = [UIColor blackColor].CGColor;
barView.layer.shadowOffset = CGSizeMake(0, 0);
barView.layer.shadowOpacity = 0.4;
barView.layer.shadowRadius = 1.0;
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height + self.headerPadding, [self barWidth], height + kJBBarChartViewPopOffset - self.headerPadding);
[mutableBarViews addObject:barView];
[self insertSubview:barView belowSubview:self.footerView];
// Add new bar
if (self.footerView)
{
[self insertSubview:barView belowSubview:self.footerView];
}
else
{
[self addSubview:barView];
}
xOffset += ([self barWidth] + self.barPadding);
index++;
}
@@ -158,6 +166,8 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
* Creates a vertical selection view for touch events
*/
dispatch_block_t createSelectionView = ^{
// Remove old selection bar
if (self.selectionView)
{
[self.selectionView removeFromSuperview];
@@ -170,7 +180,16 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
{
self.selectionView.bgColor = [self.dataSource selectionBarColorForBarChartView:self];
}
[self insertSubview:self.selectionView belowSubview:self.footerView];
// Add new selection bar
if (self.footerView)
{
[self insertSubview:self.selectionView belowSubview:self.footerView];
}
else
{
[self addSubview:self.selectionView];
}
};
createDataDictionaries();
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "1.0"
s.version = "1.1.1"
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 => "v1.0"
:tag => "v1.1.1"
}
s.platform = :ios, '7.0'
+3
View File
@@ -117,6 +117,9 @@ static UIColor *kJBLineChartViewDefaultLineColor = nil;
- (void)reloadData
{
// reset cached max height
self.cachedMaxHeight = kJBLineChartViewUndefinedMaxHeight;
/*
* Subview rectangle calculations
*/
@@ -137,9 +137,11 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
return kJBBarChartViewControllerBarPadding;
}
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
{
return (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
UIView *barView = [[UIView alloc] init];
barView.backgroundColor = (index % 2 == 0) ? kJBColorBarChartBarBlue : kJBColorBarChartBarGreen;
return barView;
}
- (UIColor *)selectionBarColorForBarChartView:(JBBarChartView *)barChartView
@@ -185,7 +185,7 @@ static UIColor *kJBChartInformationViewShadowColor = nil;
{
if (hidden)
{
[UIView animateWithDuration:kJBNumericDefaultAnimationDuration * 0.5 animations:^{
[UIView animateWithDuration:kJBNumericDefaultAnimationDuration * 0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.titleLabel.alpha = 0.0;
self.separatorView.alpha = 0.0;
self.valueView.valueLabel.alpha = 0.0;
@@ -197,17 +197,14 @@ static UIColor *kJBChartInformationViewShadowColor = nil;
}
else
{
[UIView animateWithDuration:kJBNumericDefaultAnimationDuration animations:^{
[UIView animateWithDuration:kJBNumericDefaultAnimationDuration delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.titleLabel.frame = [self titleViewRectForHidden:NO];
self.titleLabel.alpha = hidden ? 0.0 : 1.0;
self.titleLabel.alpha = 1.0;
self.valueView.valueLabel.alpha = 1.0;
self.valueView.unitLabel.alpha = 1.0;
self.separatorView.frame = [self separatorViewRectForHidden:NO];
self.separatorView.alpha = hidden ? 0.0 : 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:kJBNumericDefaultAnimationDuration animations:^{
self.valueView.valueLabel.alpha = hidden ? 0.0 : 1.0;
self.valueView.unitLabel.alpha = hidden ? 0.0 : 1.0;
}];
}];
self.separatorView.alpha = 1.0;
} completion:nil];
}
}
else
+5 -5
View File
@@ -36,7 +36,7 @@ Simply add the following line to your <code>Podfile</code>:
Your Podfile should look something like:
platform :ios, '7.0'
pod 'JBChartView', '~> 1.0'
pod 'JBChartView', '~> 1.1.1'
### The Old School Way
@@ -66,7 +66,7 @@ At a minimum, you need to inform the data source how many bars are in the chart:
return ...; // number of bars in chart
}
Secondly, you nee to inform the delegate the height of each bar (automatically normalized across the entire chart):
Secondly, you need to inform the delegate the height of each bar (automatically normalized across the entire chart):
- (NSInteger)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
{
@@ -89,7 +89,7 @@ At a minimum, you need to inform the data source how many points are in the line
return ...; // number of points in chart
}
Secondly, you nee to inform the delegate the y-position of each point (automatically normalized across the entire chart):
Secondly, you need to inform the delegate the y-position of each point (automatically normalized across the entire chart):
- (NSInteger)lineChartView:(JBLineChartView *)lineChartView heightForIndex:(NSInteger)index
{
@@ -116,9 +116,9 @@ Lastly, any JBChartView subclass can be collapsed or expanded programmatically v
#### JBBarChartView
The color of a chart's bar can be customized via the <i>optional</i> protocol:
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:
- (UIColor *)barColorForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
- (UIView *)barViewForBarChartView:(JBBarChartView *)barChartView atIndex:(NSInteger)index
{
return ...; // color of line in chart
}