Compare commits

..

8 Commits

Author SHA1 Message Date
Terry Worona a303422d8e updated read me, pod spec, etc 2014-05-13 19:44:52 -07:00
Terry Worona 1aff68557f Cleaned up demo code and add min value to bar charts 2014-05-13 19:42:14 -07:00
terryworona ac3744c0c9 Merge pull request #57 from pala/master
Fixed barView's frame.
2014-05-13 19:33:55 -07:00
Tao Zhang a6ea0c30f8 Update JBBarChartView.m 2014-05-13 21:56:02 -04:00
pala ea531e3cb1 Fixed barView's frame. 2014-05-13 19:42:06 -04:00
terryworona b1a3ebd4ed Merge pull request #55 from pala/patch-1
Update sample code in readme
2014-05-13 10:39:24 -07:00
Tao Zhang 554f93f3d3 Update sample code 2014-05-12 23:41:25 -04:00
Terry Worona 2ddd38fc9d updated change log 2014-05-07 09:55:10 -07:00
7 changed files with 16 additions and 126 deletions
+5 -1
View File
@@ -1,8 +1,12 @@
# Changelog
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.5">2.5.5</a>
#### 05/13/14
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/57">#57</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.4">2.5.4</a>
#### 05/07/14
- Additional fixes to issue <a href="https://github.com/Jawbone/JBChartView/pull/53">#53</a>.
- Fixes issue <a href="https://github.com/Jawbone/JBChartView/pull/53">#53</a>.
## <a href="https://github.com/Jawbone/JBChartView/tree/v2.5.3">2.5.3</a>
#### 05/06/14
+1 -1
View File
@@ -198,7 +198,7 @@ static UIColor *kJBBarChartViewDefaultBarColor = nil;
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.headerPadding, [self barWidth], height + extensionHeight - self.headerPadding);
barView.frame = CGRectMake(xOffset, self.bounds.size.height - height - self.footerView.frame.size.height, [self barWidth], height + extensionHeight);
[mutableBarViews addObject:barView];
// Add new bar
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "2.5.4"
s.version = "2.5.5"
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.5.4"
:tag => "v2.5.5"
}
s.platform = :ios, '7.0'
@@ -107,6 +107,7 @@ NSString * const kJBBarChartViewControllerNavButtonViewKey = @"view";
self.barChartView.delegate = self;
self.barChartView.dataSource = self;
self.barChartView.headerPadding = kJBBarChartViewControllerChartHeaderPadding;
self.barChartView.minimumValue = 0.0f;
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)];
@@ -10,7 +10,6 @@
@interface JBBarChartFooterView : UIView
@property (nonatomic, strong) UIColor *footerBackgroundColor; // footer background (default = black)
@property (nonatomic, assign) CGFloat padding; // label left & right padding (default = 4.0)
@property (nonatomic, readonly) UILabel *leftLabel;
@property (nonatomic, readonly) UILabel *rightLabel;
@@ -10,30 +10,12 @@
// Numerics
CGFloat const kJBBarChartFooterPolygonViewDefaultPadding = 4.0f;
CGFloat const kJBBarChartFooterPolygonViewArrowHeight = 8.0f;
CGFloat const kJBBarChartFooterPolygonViewArrowWidth = 16.0f;
// Colors
static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
static UIColor *kJBBarChartFooterViewDefaultBackgroundColor = nil;
@protocol JBBarChartFooterPolygonViewDelegate;
@interface JBBarChartFooterView ()
@interface JBBarChartFooterPolygonView : UIView
@property (nonatomic, weak) id<JBBarChartFooterPolygonViewDelegate> delegate;
@end
@protocol JBBarChartFooterPolygonViewDelegate <NSObject>
- (UIColor *)backgroundColorForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView;
- (CGFloat)paddingForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView;
@end
@interface JBBarChartFooterView () <JBBarChartFooterPolygonViewDelegate>
@property (nonatomic, strong) JBBarChartFooterPolygonView *polygonView;
@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *rightLabel;
@@ -47,7 +29,7 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
{
if (self == [JBBarChartFooterView class])
{
kJBBarChartFooterPolygonViewDefaultBackgroundColor = kJBColorBarChartControllerBackground;
kJBBarChartFooterViewDefaultBackgroundColor = kJBColorBarChartControllerBackground;
}
}
@@ -56,15 +38,10 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = kJBBarChartFooterPolygonViewDefaultBackgroundColor;
self.backgroundColor = kJBBarChartFooterViewDefaultBackgroundColor;
_footerBackgroundColor = kJBBarChartFooterPolygonViewDefaultBackgroundColor;
_padding = kJBBarChartFooterPolygonViewDefaultPadding;
_polygonView = [[JBBarChartFooterPolygonView alloc] initWithFrame:CGRectMake(self.bounds.origin.x, self.bounds.origin.y - kJBBarChartFooterPolygonViewArrowHeight, self.bounds.size.width, self.bounds.size.height + kJBBarChartFooterPolygonViewArrowHeight)];
_polygonView.delegate = self;
[self addSubview:_polygonView];
_leftLabel = [[UILabel alloc] init];
_leftLabel.adjustsFontSizeToFitWidth = YES;
_leftLabel.font = kJBFontFooterLabel;
@@ -100,95 +77,4 @@ static UIColor *kJBBarChartFooterPolygonViewDefaultBackgroundColor = nil;
self.rightLabel.frame = CGRectMake(CGRectGetMaxX(_leftLabel.frame), yOffset, width, self.bounds.size.height);
}
#pragma mark - JBBarChartFooterPolygonViewDelegate
- (UIColor *)backgroundColorForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView
{
return self.footerBackgroundColor;
}
- (CGFloat)paddingForChartFooterPolygonView:(JBBarChartFooterPolygonView *)chartFooterPolygonView
{
return self.padding;
}
@end
@implementation JBBarChartFooterPolygonView
#pragma mark - Alloc/Init
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
}
return self;
}
#pragma mark - Drawing
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
// Background gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.0, 1.0 };
NSAssert([self.delegate respondsToSelector:@selector(backgroundColorForChartFooterPolygonView:)], @"JBChartFooterPolygonView // delegate must implement - (UIColor *)backgroundColorForChartFooterPolygonView");
NSAssert([self.delegate respondsToSelector:@selector(paddingForChartFooterPolygonView:)], @"JBChartFooterPolygonView // delegate must implement - (CGFloat)paddingForChartFooterPolygonView");
UIColor *bgColor = [self.delegate backgroundColorForChartFooterPolygonView:self];
NSArray *colors = @[(__bridge id)bgColor.CGColor, (__bridge id)bgColor.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
// Polygon shape
CGFloat xOffset = self.bounds.origin.x;
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
CGFloat padding = [self.delegate paddingForChartFooterPolygonView:self];
NSArray *polygonPoints = @[[NSValue valueWithCGPoint:CGPointMake(xOffset, height)],
[NSValue valueWithCGPoint:CGPointMake(xOffset, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding + ceil(kJBBarChartFooterPolygonViewArrowWidth * 0.5), 0)],
[NSValue valueWithCGPoint:CGPointMake(xOffset + padding + kJBBarChartFooterPolygonViewArrowWidth, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width - padding - kJBBarChartFooterPolygonViewArrowWidth, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width - padding - ceil(kJBBarChartFooterPolygonViewArrowWidth * 0.5), 0.0)],
[NSValue valueWithCGPoint:CGPointMake(width - padding, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width, kJBBarChartFooterPolygonViewArrowHeight)],
[NSValue valueWithCGPoint:CGPointMake(width, height)],
[NSValue valueWithCGPoint:CGPointMake(xOffset, height)]];
// Draw polygon
NSValue *pointValue = polygonPoints[0];
CGContextSaveGState(context);
{
NSInteger index = 0;
for (pointValue in polygonPoints)
{
CGPoint point = [pointValue CGPointValue];
if (index == 0)
{
CGContextMoveToPoint(context, point.x, point.y);
}
else
{
CGContextAddLineToPoint(context, point.x, point.y);
}
index++;
}
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)), CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)), 0);
}
CGContextRestoreGState(context);
CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace);
}
@end
+3 -3
View File
@@ -38,7 +38,7 @@ Simply add the following line to your <code>Podfile</code>:
Your Podfile should look something like:
platform :ios, '7.0'
pod 'JBChartView', '~> 2.5.4'
pod 'JBChartView', '~> 2.5.5'
### The Old School Way
@@ -63,14 +63,14 @@ To initialize a <i>JBBarChartView</i>, you only need a few lines of code (see be
At a minimum, you need to inform the data source how many bars are in the chart:
- (NSInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView
{
return ...; // number of bars in chart
}
Secondly, you need to inform the delegate the height of each bar (automatically normalized across the entire chart):
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSInteger)index
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index
{
return ...; // height of bar at index
}