Skip to content

Commit 9e8ef03

Browse files
Merge branch 'develop'
2 parents c7aa776 + 3f9a7d8 commit 9e8ef03

File tree

7 files changed

+98
-26
lines changed

7 files changed

+98
-26
lines changed

GraphKit/Example/ExampleBarGraphVC.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ - (void)viewDidLoad {
3232
// self.graphView.barWidth = 22;
3333
// self.graphView.barHeight = 140;
3434
// self.graphView.marginBar = 25;
35+
// self.graphView.animationDuration = 2.0;
36+
3537
self.graphView.dataSource = self;
3638

37-
[self.graphView construct];
38-
self.graphView.animationDuration = 2.0;
3939
[self.graphView draw];
4040

4141
self.green = YES;

README.md

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# GraphKit
22

3-
[![License MIT](https://go-shields.herokuapp.com/license-MIT-blue.png)](https://github.com/michalkonturek/GraphKit/blob/master/LICENSE)
4-
[![Build Platform](https://cocoapod-badges.herokuapp.com/p/GraphKit/badge.png)](https://github.com/michalkonturek/GraphKit)
5-
[![Build Version](https://cocoapod-badges.herokuapp.com/v/GraphKit/badge.png)](https://github.com/michalkonturek/GraphKit)
3+
[![License MIT](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/michalkonturek/GraphKit/blob/master/LICENSE)
4+
[![CocoaPods](https://img.shields.io/cocoapods/v/GraphKit.svg?style=flat)](https://github.com/michalkonturek/GraphKit)
5+
[![License MIT](http://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/michalkonturek)
6+
67

78
A lightweight library of animated charts for iOS.
89

@@ -19,4 +20,78 @@ Source code of this project is available under the standard MIT license. Please
1920

2021
### Bar Graph
2122

22-
### Line Graph
23+
![Build Platform](images/bar-graph.png)
24+
25+
Initialize `GKBarGraph` from nib or programmatically:
26+
27+
```objc
28+
CGRect frame = CGRectMake(0, 40, 320, 200);
29+
self.graphView = [[GKBarGraph alloc] initWithFrame:frame];
30+
```
31+
32+
then set `GKGraphViewDataSource`
33+
34+
```objc
35+
self.graphView.dataSource = self;
36+
```
37+
38+
and call `draw` method.
39+
40+
```objc
41+
[self.graphView draw];
42+
```
43+
44+
45+
Please see [example][BAR].
46+
47+
[BAR]:https://github.com/michalkonturek/GraphKit/blob/master/GraphKit/Example/ExampleBarGraphVC.m
48+
49+
50+
#### `GKBarGraphDataSource` Protocol
51+
52+
```objc
53+
@required
54+
- (NSInteger)numberOfBars;
55+
- (NSNumber *)valueForBarAtIndex:(NSInteger)index;
56+
57+
@optional
58+
- (UIColor *)colorForBarAtIndex:(NSInteger)index;
59+
- (CFTimeInterval)animationDurationForBarAtIndex:(NSInteger)index;
60+
- (NSString *)titleForBarAtIndex:(NSInteger)index;
61+
```
62+
63+
64+
### Line Graph
65+
66+
![Build Platform](images/line-graph.png)
67+
68+
```objc
69+
CGRect frame = CGRectMake(0, 40, 320, 200);
70+
self.graphView = [[GKLineGraph alloc] initWithFrame:frame];
71+
72+
self.graph.dataSource = self;
73+
self.graph.lineWidth = 3.0;
74+
75+
[self.graph draw];
76+
```
77+
78+
Please see [example][LINE].
79+
80+
[LINE]:https://github.com/michalkonturek/GraphKit/blob/master/GraphKit/Example/ExampleLineGraph.m
81+
82+
83+
#### `GKLineGraphDataSource` Protocol
84+
85+
```objc
86+
@required
87+
- (NSInteger)numberOfLines;
88+
- (UIColor *)colorForLineAtIndex:(NSInteger)index;
89+
- (NSArray *)valuesForLineAtIndex:(NSInteger)index;
90+
91+
@optional
92+
- (CFTimeInterval)animationDurationForLineAtIndex:(NSInteger)index;
93+
- (NSString *)titleForLineAtIndex:(NSInteger)index;
94+
```
95+
96+
<!--[@MichalKonturek](https://twitter.com/MichalKonturek)-->
97+

Source/BarGraph/GKBar.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#import "UIColor+GraphKit.h"
1414

15+
static CFTimeInterval kDefaultAnimationDuration = 1.0;
16+
1517
@interface GKBar ()
1618

1719
@property (atomic, assign) BOOL animationInProgress;
@@ -47,7 +49,7 @@ - (id)initWithFrame:(CGRect)frame {
4749

4850
- (void)_init {
4951
self.animated = YES;
50-
self.animationDuration = 0.5;
52+
self.animationDuration = kDefaultAnimationDuration;
5153
self.clipsToBounds = YES;
5254
self.cornerRadius = 2.0;
5355
self.foregroundColor = [UIColor gk_turquoiseColor];

Source/BarGraph/GKBarGraph.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
@property (nonatomic, assign) CGFloat barWidth;
2626
@property (nonatomic, assign) CGFloat marginBar;
2727

28-
- (instancetype)redraw;
29-
- (instancetype)construct;
30-
- (instancetype)draw;
31-
- (instancetype)reset;
28+
- (void)draw;
29+
- (void)reset;
3230

3331
@end
3432

Source/BarGraph/GKBarGraph.m

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
static CGFloat kDefaultLabelWidth = 40;
2020
static CGFloat kDefaultLabelHeight = 15;
2121

22+
static CGFloat kDefaultAnimationDuration = 2.0;
23+
2224
@implementation GKBarGraph
2325

2426
- (id)initWithCoder:(NSCoder *)aDecoder {
@@ -39,6 +41,7 @@ - (id)initWithFrame:(CGRect)frame {
3941
}
4042

4143
- (void)_init {
44+
self.animationDuration = kDefaultAnimationDuration;
4245
self.barHeight = kDefaultBarHeight;
4346
self.barWidth = kDefaultBarWidth;
4447
self.marginBar = kDefaultBarMargin;
@@ -65,26 +68,22 @@ - (void)setBarColor:(UIColor *)color {
6568
}];
6669
}
6770

68-
- (instancetype)redraw {
69-
return [[self construct] draw];
70-
}
71-
72-
- (instancetype)construct {
73-
NSAssert(self.dataSource, @"GKBarGraph : No data source is assgined.");
74-
71+
- (void)draw {
7572
[self _construct];
76-
[self _positionBars];
77-
[self _positionLabels];
78-
79-
return self;
73+
[self _drawBars];
8074
}
8175

8276
- (void)_construct {
77+
NSAssert(self.dataSource, @"GKBarGraph : No data source is assgined.");
78+
8379
if ([self _hasBars]) [self _removeBars];
8480
if ([self _hasLabels]) [self _removeLabels];
8581

8682
[self _constructBars];
8783
[self _constructLabels];
84+
85+
[self _positionBars];
86+
[self _positionLabels];
8887
}
8988

9089
- (BOOL)_hasBars {
@@ -186,7 +185,7 @@ - (void)_positionLabels {
186185
}];
187186
}
188187

189-
- (instancetype)draw {
188+
- (void)_drawBars {
190189
__block NSInteger idx = 0;
191190
id source = self.dataSource;
192191
[self.bars mk_each:^(GKBar *item) {
@@ -202,14 +201,12 @@ - (instancetype)draw {
202201
item.percentage = [[source valueForBarAtIndex:idx] doubleValue];
203202
idx++;
204203
}];
205-
return self;
206204
}
207205

208-
- (instancetype)reset {
206+
- (void)reset {
209207
[self.bars mk_each:^(GKBar *item) {
210208
[item reset];
211209
}];
212-
return self;
213210
}
214211

215212
@end

images/bar-graph.png

14.3 KB
Loading

images/line-graph.png

76.4 KB
Loading

0 commit comments

Comments
 (0)