kevinzhow

add highlight on bar animation #58

... ... @@ -8,6 +8,7 @@
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#import "PNBar.h"
#define xLabelMargin 15
#define yLabelMargin 15
... ... @@ -27,6 +28,9 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
@property (nonatomic) NSArray *xLabels;
@property (nonatomic) NSArray *yLabels;
@property (nonatomic) NSArray *yValues;
@property (nonatomic) NSMutableArray * bars;
@property (nonatomic) CGFloat xLabelWidth;
@property (nonatomic) int yValueMax;
@property (nonatomic) UIColor *strokeColor;
... ...
... ... @@ -9,10 +9,9 @@
#import "PNBarChart.h"
#import "PNColor.h"
#import "PNChartLabel.h"
#import "PNBar.h"
@interface PNBarChart () {
NSMutableArray *_bars;
NSMutableArray *_labels;
}
... ...
... ... @@ -8,7 +8,10 @@
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#import "PNChart.h"
@interface PCChartsTableViewController : UITableViewController<PNChartDelegate>
@property (nonatomic) PNBarChart * barChart;
@end
... ...
... ... @@ -105,23 +105,23 @@
barChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
barChartLabel.textAlignment = NSTextAlignmentCenter;
PNBarChart * barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
barChart.backgroundColor = [UIColor clearColor];
barChart.yLabelFormatter = ^(CGFloat yValue){
self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
self.barChart.backgroundColor = [UIColor clearColor];
self.barChart.yLabelFormatter = ^(CGFloat yValue){
CGFloat yValueParsed = yValue;
NSString * labelText = [NSString stringWithFormat:@"%1.f",yValueParsed];
return labelText;
};
barChart.labelMarginTop = 5.0;
[barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
[barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]];
[barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]];
[barChart strokeChart];
self.barChart.labelMarginTop = 5.0;
[self.barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
[self.barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]];
[self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]];
[self.barChart strokeChart];
barChart.delegate = self;
self.barChart.delegate = self;
[viewController.view addSubview:barChartLabel];
[viewController.view addSubview:barChart];
[viewController.view addSubview:self.barChart];
viewController.title = @"Bar Chart";
}else if ([segue.identifier isEqualToString:@"circleChart"])
... ... @@ -191,7 +191,30 @@
- (void)userClickedOnBarCharIndex:(NSInteger)barIndex
{
NSLog(@"Click on bar %@", @(barIndex));
PNBar * bar = [self.barChart.bars objectAtIndex:barIndex];
CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue= @1.0;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.toValue= @1.1;
animation.duration= 0.2;
animation.repeatCount = 0;
animation.autoreverses = YES;
animation.removedOnCompletion = YES;
animation.fillMode=kCAFillModeForwards;
[bar.layer addAnimation:animation forKey:@"Float"];
}
@end
... ...