-
Notifications
You must be signed in to change notification settings - Fork 381
Delegate
Similar to a UITableView, BEMSimpleLineGraph uses a delegate to change the graph's appearance and receive events. Unlike the data source, you are not required to implement a delegate. Please refer to Getting Started - Setup for instructions on setting-up your delegate.
When the line graph starts or completes loading it will call one of the following delegate methods. You should not attempt to reload the graph's data source or change its layout while it is updating.
This method is sent to the delegate when the graph begins loading. The graph will begin loading after it is first initialized and when it is reloaded after initialization.
- (void)lineGraphDidBeginLoading:(BEMSimpleLineGraphView *)graph {
// Prepare for loading
}
This method is sent to the delegate when the graph finishes loading. The graph is considered finished loading when all initial loading has been completed and the data source has been updated. Graph animations may still be taking place when this method is called.
- (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph {
// Update interface after reloading the graph. Ensure the data source is synced-up.
}
WARNING Calling the
graphSnapshotImage
method before the graph finishes drawing and animating may result in anil
or partially rendered image of the graph. Please uselineGraphDidFinishDrawing
to know when it is acceptable to use this API.
This method is sent to the delegate when the graph finishes drawing and animating. The entrance animation time is used to calculate when the graph has finished animating, laying out subviews, and drawing. It is acceptable to use the graphSnapshotImage
API after this method is called.
- (void) lineGraphDidFinishDrawing:(BEMSimpleLineGraphView *)graph {
// Update any interface elements that rely on a full rendered graph
}
The delegate provides two methods which provide fine-grained control over graph popups.
Retrieves the optional suffix to append to the popup report. The popup suffix is a string which is appended to the numerical value of a popup. In the example below, a popup which read "26.7" would now read "26.7 miles".
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView *)graph {
return @"miles";
}
Optional method to always display specific popup labels on the graph. The alwaysDisplayPopUpLabels
property must be set to YES for this method to have any affect. This method is called for each point on the graph, from left to right. Use the index parameter to determine which point the method is being called for.
- (BOOL)lineGraph:(BEMSimpleLineGraphView *)graph alwaysDisplayPopUpAtIndex:(CGFloat)index {
if (index == 0 || index == 10) return YES;
else return NO;
}
The delegate provides two methods which provide fine-grained control over touch events.
Sent to the delegate when the user starts touching the graph. The property enableTouchReport
must be set to YES. The index parameter provides the closest index (X-axis) from the location the user is currently touching.
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index {
// Update the interface to display relevant data
}
Sent to the delegate when the user stops touching the graph. The index parameter provides the closest index (X-axis) to which the user last touched.
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithClosestIndex:(CGFloat)index {
// Update the interface to display relevant data
}
Use the delegate to control spacing between x-axis labels. The numberOfGapsBetweenLabelsOnLineGraph:
method is sent to the delegate to retrieve the number of free space between labels on the X-axis to avoid overlapping. Return the number of labels to "jump" between each displayed label on the X-axis. 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.
- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
return 1;
}
Use the delegate to control the number of y-axis labels. The numberOfYAxisLabelsOnLineGraph:
method is sent to the delegate when autoScaleYAxis
is set to NO. Calculates the total height of the graph and evenly spaces the labels based on the graph height. Default value is 3. Return the number of labels displayed on the Y-axis.
- (NSInteger)numberOfYAxisLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
return 3;
}