New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added area diagram functionality #42
Changes from 11 commits
d08627d
037520e
e141e92
9e476d5
6b7af10
311be6b
cd3d28a
c0bdb6e
f526229
5954082
07880a5
287d9b4
e2b436a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,8 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ | |
|
||
@interface JBLineChartView : JBChartView | ||
|
||
@property (nonatomic, weak) id<JBLineChartViewDelegate> delegate; | ||
@property (nonatomic, weak) id<JBLineChartViewDataSource> dataSource; | ||
@property (nonatomic, weak) IBOutlet id<JBLineChartViewDelegate> delegate; | ||
@property (nonatomic, weak) IBOutlet id<JBLineChartViewDataSource> dataSource; | ||
|
||
/** | ||
* Vertical highlight overlayed on a line graph during touch events. | ||
|
@@ -46,6 +46,32 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ | |
*/ | ||
@property (nonatomic, assign) BOOL showsLineSelection; | ||
|
||
/** | ||
* A highlight shown on a area under a line within the graph during touch events. The highlighted area | ||
* is the on under the closest line to the touch point and corresponds to the lineIndex delegatd back via | ||
* didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex: | ||
* | ||
* Default: NO. | ||
*/ | ||
@property (nonatomic, assign) BOOL showsAreaSelection; | ||
|
||
/** | ||
* Fills the area under the lines till the next lane below or the bottom. | ||
* For best results the lines should not intersect each other. One way to achive this is | ||
* makeing the diagramm cumulative by setting the BOOL isCumulative to YES | ||
* | ||
* Default: NO. | ||
*/ | ||
@property (nonatomic, assign) BOOL fillsAreaBelowLine; | ||
|
||
/** | ||
* If YES the chart adds the value of the next line to the previous. The distance of a line to the one below | ||
* represents the upper lines real value. For best results you should also set the BOOL fillsAreaBelowLine to YES | ||
* | ||
* Default: NO. | ||
*/ | ||
@property (nonatomic, assign) BOOL isCumulative; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer if this were simplified to a single delegate function:
If NO, then business as usual. If YES, we draw the area under the line @ the same color as line itself (same goes for selection events). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As well, with this pattern, we could have a combination of filled and non filled lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A delegate method for the filling is a good idea. But this creates a new question: When filled and non filled lines are combined, e.g. the lower line is non filled and the higher one is, should only the space between the higher and the lower be filled or everything between the higher line and the x-axis? But I would keep the property for the cumulative lines as this can be used intependently from the filling and it affects all lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just discovered that there already is a delegate method for filling. I just didn't use it.
|
||
@end | ||
|
||
@protocol JBLineChartViewDelegate <NSObject> | ||
|
@@ -127,6 +153,18 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ | |
*/ | ||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForLineAtLineIndex:(NSUInteger)lineIndex; | ||
|
||
/** | ||
* Returns the color of particular area under the line at lineIndex within the chart. | ||
* | ||
* Default: black color. | ||
* | ||
* @param lineChartView The line chart object requesting this information. | ||
* @param lineIndex An index number identifying a line in the chart. | ||
* | ||
* @return The color to be used to shade a line in the chart. | ||
*/ | ||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView colorForAreaUnderLineAtLineIndex:(NSUInteger)lineIndex; | ||
|
||
/** | ||
* Returns the color of a particular dot in a line at lineIndex within the chart. | ||
* For this value to apply, showsDotsForLineAtLineIndex: must return YES for the line at lineIndex. | ||
|
@@ -207,6 +245,19 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ | |
*/ | ||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForLineAtLineIndex:(NSUInteger)lineIndex; | ||
|
||
/** | ||
* Returns the selection color to be overlayed on a area under a line within the chart during touch events. | ||
* The property showsAreaSelection must be YES for the color to apply. | ||
* | ||
* Default: white color. | ||
* | ||
* @param lineChartView The line chart object requesting this information. | ||
* @param lineIndex An index number identifying a line in the chart. | ||
* | ||
* @return The color to be used to highlight a line during chart selections. | ||
*/ | ||
- (UIColor *)lineChartView:(JBLineChartView *)lineChartView selectionColorForAreaUnderLineAtLineIndex:(NSUInteger)lineIndex; | ||
|
||
/** | ||
* Returns the selection color to be overlayed on a line within the chart during touch events. | ||
* The property showsLineSelection must be YES for the color to apply. | ||
|
@@ -260,4 +311,16 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ | |
*/ | ||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex; | ||
|
||
/** | ||
* Returns whether or not the area under the line should be filled | ||
* | ||
* Default: NO | ||
* | ||
* @param lineChartView The line chart object requesting this information. | ||
* @param lineIndex An index number identifying a line in the chart. | ||
* | ||
* @return Whether or not the area under the line should be filled | ||
*/ | ||
- (BOOL)lineChartView:(JBLineChartView *)lineChartView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex; | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these IBOutlets (forgive my naiveness, I never use IB); can the chart not be used with IB without these declared as outlets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the IBOutlets make it possible to set the delegate and the dataSource directly in IB, like it's possible for standard UI elements like UITextField. It's just for convinience, the charts can be used without the IBOutlets, too.