forked from Boris-Em/BEMSimpleLineGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBEMSimpleLineGraphView.h
297 lines (175 loc) · 12.7 KB
/
BEMSimpleLineGraphView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//
// BEMSimpleLineGraphView.h
// SimpleLineGraph
//
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//
#if __has_feature(objc_modules)
// We recommend enabling Objective-C Modules in your project Build Settings for numerous benefits over regular #imports. Read more from the Modules documentation: http://clang.llvm.org/docs/Modules.html
@import Foundation;
@import UIKit;
@import CoreGraphics;
#else
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#endif
#import "BEMCircle.h"
#import "BEMLine.h"
#import "BEMAnimations.h"
@protocol BEMSimpleLineGraphDelegate;
/// Simple line graph / chart UIView subclass for iOS apps. Creates beautiful line graphs (without huge memory impacts) using QuartzCore.
@interface BEMSimpleLineGraphView : UIView <BEMAnimationDelegate, UIGestureRecognizerDelegate>
//------------------------------------------------------------------------------------//
//----- DELEGATE ---------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// BEMSimpleLineGraphView delegate object is essential to the line graph. The delegate provides the graph with data and various parameters for creating the line graph. The delegate can be set from the interface or from code.
@property (assign) IBOutlet id <BEMSimpleLineGraphDelegate> delegate;
//------------------------------------------------------------------------------------//
//----- METHODS ----------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// Reload the graph, all delegate methods are called again and the graph is reloaded. Similar to calling reloadData on a UITableView.
- (void)reloadGraph;
/** Takes a snapshot of the graph.
@return The snapshot of the graph as a UIImage object. */
- (UIImage *)graphSnapshotImage NS_AVAILABLE_IOS(7_0);
/** Calculates the average (mean) of all points on the line graph.
@return The average (mean) number of the points on the graph. Originally a float. */
- (NSNumber *)calculatePointValueAverage;
/** Calculates the sum of all points on the line graph.
@return The sum of the points on the graph. Originally a float. */
- (NSNumber *)calculatePointValueSum;
/** Calculates the median of all points on the line graph.
@return The median number of the points on the graph. Originally a float. */
- (NSNumber *)calculatePointValueMedian;
/** Calculates the mode of all points on the line graph.
@return The mode number of the points on the graph. Originally a float. */
- (NSNumber *)calculatePointValueMode;
/** Calculates the standard deviation of all points on the line graph.
@return The standard deviation of the points on the graph. Originally a float. */
- (NSNumber *)calculateLineGraphStandardDeviation;
/** Calculates the minimum value of all points on the line graph.
@return The minimum number of the points on the graph. Originally a float. */
- (NSNumber *)calculateMinimumPointValue;
/** Calculates the maximum value of all points on the line graph.
@return The maximum value of the points on the graph. Originally a float. */
- (NSNumber *)calculateMaximumPointValue;
/** All the displayed values of the X-Axis.
@return An array of NSStrings, one for each displayed X-Axis label. The array is sorted from the left side of the graph to the right side. */
- (NSArray *)graphValuesForXAxis;
/** All the data points on the graph.
@return An array of NSNumbers, one for each data point. The array is sorted from the left side of the graph to the right side. */
- (NSArray *)graphValuesForDataPoints;
//------------------------------------------------------------------------------------//
//----- PROPERTIES -------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// The graph's label font used on various axis. This property may be privately overwritten, do not expect full functionality from this property.
@property (strong, nonatomic) UIFont *labelFont;
/// Speed of the animation when the graph appears. From 0 to 10, 0 meaning no animation, 1 very slow and 10 very fast. Default value is 5.
@property (nonatomic) NSInteger animationGraphEntranceSpeed;
/// If set to yes, the graph will respond to touch events. The 2 methods above should therefore be implemented. Default value is NO.
@property (nonatomic) BOOL enableTouchReport;
/// The way the graph is drawn, with or withough bezier curved lines. Default value is NO;
@property (nonatomic) BOOL enableBezierCurve;
/// Color of the bottom part of the graph (between the line and the X-axis).
@property (strong, nonatomic) UIColor *colorBottom;
/// Alpha of the bottom part of the graph (between the line and the X-axis).
@property (nonatomic) CGFloat alphaBottom;
/// Color of the top part of the graph (between the line and the top of the view the graph is drawn in).
@property (strong, nonatomic) UIColor *colorTop;
/// Alpha of the top part of the graph (between the line and the top of the view the graph is drawn in).
@property (nonatomic) CGFloat alphaTop;
/// Color of the line of the graph.
@property (strong, nonatomic) UIColor *colorLine;
/// Alpha of the line of the graph.
@property (nonatomic) CGFloat alphaLine;
/// Width of the line of the graph. Default value is 1.0.
@property (nonatomic) CGFloat widthLine;
/// Color of the label's text displayed on the X-Axis.
@property (strong, nonatomic) UIColor *colorXaxisLabel;
@property (strong, nonatomic) UIColor *colorDot;
// Defaults to YES.
@property (nonatomic) BOOL shouldHideDots;
@property (nonatomic) CGFloat dotDiameter;
@end
/// Line Graph Delegate. Used to pupulate the graph with data, similar to how a UITableView works.
@protocol BEMSimpleLineGraphDelegate <NSObject>
@required
//----- DATA SOURCE -----//
/** The number of points along the X-axis of the graph.
@param graph The graph object requesting the total number of points.
@return The total number of points in the line graph. */
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph;
/** The vertical position for a point at the given index. It corresponds to the Y-axis value of the Graph.
@param graph The graph object requesting the point value.
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
@return The Y-axis value at a given index. */
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index;
@optional
//----- GRAPH EVENTS -----//
/** Sent to the delegate each time the line graph is loaded or reloaded.
@param graph The graph object that is about to be loaded or reloaded. */
- (void)lineGraphDidBeginLoading:(BEMSimpleLineGraphView *)graph;
/** Sent to the delegate each time the line graph is finishes loading or reloading.
@param graph The graph object that finished loading or reloading. */
- (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph;
//----- CUSTOMIZATION -----//
/** The color of the line at the given index. This is called for each line in the graph, every time an update is made.
@param graph The graph object requesting the line color.
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
@return The color of the line. Specifying nil will cause the line to use the color specifed for the graph. */
- (UIColor *)lineGraph:(BEMSimpleLineGraphView *)graph lineColorForIndex:(NSInteger)index;
/** The alpha of the line at the given index. This is called for each line in the graph, every time an update is made.
@param graph The graph object requesting the line alpha.
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
@return The alpha value of the line, between 0.0 and 1.0. Specifying nil will cause the line to use the alpha specifed for the graph. */
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph lineAlphaForIndex:(NSInteger)index;
//----- TOUCH EVENTS -----//
/** Sent to the delegate when the user starts touching the graph. The property 'enableTouchReport' must be set to YES.
@param graph The graph object which was touched by the user.
@param index The closest index (X-axis) from the location the user is currently touching. */
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index;
/** Sent to the delegate when the user stops touching the graph.
@param graph The graph object which was touched by the user.
@param index The closest index (X-axis) from the location the user last touched. */
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithClosestIndex:(CGFloat)index;
//----- X AXIS -----//
/** The number of free space between labels on the X-axis to avoid overlapping.
@discussion For example returning '1' would mean that half of the labels on the X-axis are not displayed: the first is not displayed, the second is, the third is not etc. Returning '0' would mean that all of the labels will be displayed. Finally, returning a value equal to the number of labels will only display the first and last label.
@param graph The graph object which is requesting the number of gaps between the labels.
@return The number of labels to "jump" between each displayed label on the X-axis. */
- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph;
/** The string to display on the label on the X-axis at a given index. Please note that the number of strings to be returned should be equal to the number of points in the Graph.
@param graph The graph object which is requesting the label on the specified X-Axis position.
@param index The index from left to right of a given label on the X-axis. Is the same index as the one for the points. The first value for the index is 0. */
- (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index;
//----- DEPRECATED -----//
/** \b DEPRECATED. Use \p numberOfPointsInLineGraph: instead. The number of points along the X-axis of the graph.
@deprecated Deprecated in 1.3. Use \p numberOfPointsInLineGraph: instead.
@return Number of points. */
- (int)numberOfPointsInGraph __deprecated;
/** \b DEPRECATED. Use \p lineGraph:valueForPointAtIndex: instead.
@deprecated Deprecated in 1.3. Use \p lineGraph:valueForPointAtIndex: instead.
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
@return The Y-axis value at a given index. */
- (float)valueForIndex:(NSInteger)index __deprecated;
/** \b DEPRECATED. Use \p lineGraph:didTouchGraphWithClosestIndex: instead. Gets called when the user starts touching the graph. The property 'enableTouchReport' must be set to YES.
@deprecated Deprecated in 1.3. Use \p lineGraph:didTouchGraphWithClosestIndex: instead.
@param index The closest index (X-axis) from the location the user is currently touching. */
- (void)didTouchGraphWithClosestIndex:(int)index __deprecated;
/** \b DEPRECATED. Use \p lineGraph:didReleaseTouchFromGraphWithClosestIndex: instead. Gets called when the user stops touching the graph.
@deprecated Deprecated in 1.3. Use \p lineGraph:didReleaseTouchFromGraphWithClosestIndex: instead.
@param index The closest index (X-axis) from the location the user last touched. */
- (void)didReleaseGraphWithClosestIndex:(float)index __deprecated;
/** \b DEPRECATED. Use \p numberOfGapsBetweenLabelsOnLineGraph: instead. The number of free space between labels on the X-axis to avoid overlapping.
@deprecated Deprecated in 1.3. Use \p numberOfGapsBetweenLabelsOnLineGraph: instead.
@discussion For example returning '1' would mean that half of the labels on the X-axis are not displayed: the first is not displayed, the second is, the third is not etc. Returning '0' would mean that all of the labels will be displayed. Finally, returning a value equal to the number of labels will only display the first and last label.
@return The number of labels to "jump" between each displayed label on the X-axis. */
- (int)numberOfGapsBetweenLabels __deprecated;
/** \b DEPRECATED. Use \p lineGraph:labelOnXAxisForIndex: instead. The string to display on the label on the X-axis at a given index. Please note that the number of strings to be returned should be equal to the number of points in the Graph.
@deprecated Deprecated in 1.3. Use \p lineGraph:labelOnXAxisForIndex: instead.
@param index The index from left to right of a given label on the X-axis. Is the same index as the one for the points. The first value for the index is 0. */
- (NSString *)labelOnXAxisForIndex:(NSInteger)index __deprecated;
@end