Skip to content
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

Closed
wants to merge 13 commits into from
Closed
4 changes: 2 additions & 2 deletions Classes/JBBarChartView.h
Expand Up @@ -14,8 +14,8 @@

@interface JBBarChartView : JBChartView

@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
@property (nonatomic, weak) IBOutlet id<JBBarChartViewDelegate> delegate;
Copy link
Collaborator

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?

Copy link
Author

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.
screenshot 2014-05-05 10 33 56

@property (nonatomic, weak) IBOutlet id<JBBarChartViewDataSource> dataSource;

/**
* Vertical highlight overlayed on bar during touch events.
Expand Down
67 changes: 65 additions & 2 deletions Classes/JBLineChartView.h 100755 → 100644
Expand Up @@ -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.
Expand All @@ -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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this were simplified to a single delegate function:

- (BOOL)lineChartView:(JBLineChartView *)lineChartView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex;

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).

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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?
I would prefere the latter since otherwise it would look a bit strange.

But I would keep the property for the cumulative lines as this can be used intependently from the filling and it affects all lines.

Copy link
Author

Choose a reason for hiding this comment

The 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.

 *  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

@protocol JBLineChartViewDelegate <NSObject>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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