Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions GraphKit/Example/ExampleLineGraph.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import "UIViewController+BButton.h"

@interface ExampleLineGraph ()
@interface ExampleLineGraph () <GKLineGraphDelegate>

@end

Expand All @@ -32,17 +32,26 @@ - (void)viewDidLoad {
- (void)_setupExampleGraph {

self.data = @[
@[@20, @40, @20, @60, @40, @140, @80],
@[@-20, @-80, @20, @60, @40, @140, @80],
@[@40, @20, @60, @100, @60, @20, @60],
@[@80, @60, @40, @160, @100, @40, @110],
@[@120, @150, @80, @120, @140, @100, @0],
// @[@620, @650, @580, @620, @540, @400, @0]
// @[@620, @650, @580, @620, @540, @400, @0]
];

self.labels = @[@"2001", @"2002", @"2003", @"2004", @"2005", @"2006", @"2007"];

self.graph.dataSource = self;
self.graph.lineWidth = 3.0;
self.graph.delegate = self;
self.graph.lineWidth = 1.5;
self.graph.ensureXAxisVisibility = YES;
self.graph.drawHorizontalGridLines = YES;
self.graph.drawVerticalGridLines = NO;
self.graph.drawCoordinateSystem = YES;

self.graph.coordinateSystemColor = [UIColor darkGrayColor];
self.graph.gridLinesColor = [UIColor lightGrayColor];
self.graph.labelTextColor = [UIColor darkGrayColor];

self.graph.valueLabelCount = 6;

Expand All @@ -60,10 +69,6 @@ - (void)_setupTestingGraphLow {
@[@10, @4, @8, @2, @9, @3, @6],
@[@1, @2, @3, @4, @5, @6, @10]
];
// self.data = @[
// @[@2, @2, @2, @2, @2, @2, @6],
// @[@1, @1, @1, @1, @1, @1, @1]
// ];

self.labels = @[@"2001", @"2002", @"2003", @"2004", @"2005", @"2006", @"2007"];

Expand All @@ -73,6 +78,8 @@ - (void)_setupTestingGraphLow {
// self.graph.startFromZero = YES;
self.graph.valueLabelCount = 10;

self.graph.ensureXAxisVisibility = YES;

[self.graph draw];
}

Expand Down Expand Up @@ -120,7 +127,8 @@ - (UIColor *)colorForLineAtIndex:(NSInteger)index {
id colors = @[[UIColor gk_turquoiseColor],
[UIColor gk_peterRiverColor],
[UIColor gk_alizarinColor],
[UIColor gk_sunflowerColor]
[UIColor gk_sunflowerColor],
[UIColor gk_amethystColor]
];
return [colors objectAtIndex:index];
}
Expand All @@ -130,11 +138,43 @@ - (NSArray *)valuesForLineAtIndex:(NSInteger)index {
}

- (CFTimeInterval)animationDurationForLineAtIndex:(NSInteger)index {
return [[@[@1, @1.6, @2.2, @1.4] objectAtIndex:index] doubleValue];
// return [[@[@1, @1.6, @2.2, @1.4] objectAtIndex:index] doubleValue];
return 0.75f;
}

- (NSString *)titleForLineAtIndex:(NSInteger)index {
return [self.labels objectAtIndex:index];
}

- (NSArray* ) dashPatternForLineAtIndex:(NSInteger)index
{
return [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:3],[NSDecimalNumber numberWithInt:3],nil];
}

#pragma mark - GKLineGraphDelegate
- (void)lineGraph:(GKLineGraph *)lineGraph willSelectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint)targetPoint
{

}

- (void)lineGraph:(GKLineGraph *)lineGraph didSelectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint)targetPoint
{
NSLog (@"Did select value %i on line #%i", dataPoint.valueIndex, dataPoint.lineIndex);
}

- (void)lineGraph:(GKLineGraph *)lineGraph willDeselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint)targetPoint
{

}

- (void)lineGraph:(GKLineGraph *)lineGraph didDeselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint)targetPoint
{
NSLog (@"Did deselect value %i on line #%i", dataPoint.valueIndex, dataPoint.lineIndex);
}

- (void)lineGraph:(GKLineGraph *)lineGraph didReselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint)targetPoint
{

}

@end
6 changes: 6 additions & 0 deletions GraphKit/GraphKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
84F0E98E1902B30C00FA4810 /* ExampleListVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F0E98C1902B30C00FA4810 /* ExampleListVC.m */; };
84F0E98F1902B30C00FA4810 /* ExampleListVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84F0E98D1902B30C00FA4810 /* ExampleListVC.xib */; };
973F4746059343C9A462AA2D /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 74E12B5B49644056930176BC /* libPods.a */; };
B758FCEB19673B7C00F843E5 /* GKLineDataPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = B758FCEA19673B7C00F843E5 /* GKLineDataPoint.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -87,6 +88,8 @@
84F0E98B1902B30C00FA4810 /* ExampleListVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleListVC.h; sourceTree = "<group>"; };
84F0E98C1902B30C00FA4810 /* ExampleListVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleListVC.m; sourceTree = "<group>"; };
84F0E98D1902B30C00FA4810 /* ExampleListVC.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ExampleListVC.xib; sourceTree = "<group>"; };
B758FCE919673B7C00F843E5 /* GKLineDataPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GKLineDataPoint.h; sourceTree = "<group>"; };
B758FCEA19673B7C00F843E5 /* GKLineDataPoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GKLineDataPoint.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -236,6 +239,8 @@
847259201904AB8F00819664 /* LineGraph */ = {
isa = PBXGroup;
children = (
B758FCE919673B7C00F843E5 /* GKLineDataPoint.h */,
B758FCEA19673B7C00F843E5 /* GKLineDataPoint.m */,
847259211904ABE200819664 /* GKLineGraph.h */,
847259221904ABE200819664 /* GKLineGraph.m */,
);
Expand Down Expand Up @@ -382,6 +387,7 @@
84654C2418FE8EE300160F11 /* AppDelegate.m in Sources */,
847259291905C1D300819664 /* UIColor+GraphKit.m in Sources */,
84654C5918FF4C8300160F11 /* ExampleBarGraphVC.m in Sources */,
B758FCEB19673B7C00F843E5 /* GKLineDataPoint.m in Sources */,
8472591E1904AA4F00819664 /* ExampleLineGraph.m in Sources */,
84654C4C18FE909A00160F11 /* GKBar.m in Sources */,
84654C2018FE8EE300160F11 /* main.m in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions Source/LineGraph/GKLineDataPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GKLineDataPoint.h
// GraphKit
//
// Created by Martin Brandt on 03.07.14.
// Copyright (c) 2014 Michal Konturek. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface GKLineDataPoint : NSObject

@property (nonatomic, assign) NSInteger lineIndex;
@property (nonatomic, assign) NSInteger valueIndex;

- (BOOL) isEmptyDataPoint;
- (BOOL) isEqual:(GKLineDataPoint *)dataPoint;

@end
36 changes: 36 additions & 0 deletions Source/LineGraph/GKLineDataPoint.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// GKLineDataPoint.m
// GraphKit
//
// Created by Martin Brandt on 03.07.14.
// Copyright (c) 2014 Michal Konturek. All rights reserved.
//

#import "GKLineDataPoint.h"

@implementation GKLineDataPoint

- (instancetype) init {
self = [super init];
if (self) {
[self _init];
}
return self;
}

- (void)_init {
self.lineIndex = -1;
self.valueIndex = -1;
}

- (BOOL) isEmptyDataPoint
{
return _lineIndex == -1 && _valueIndex == -1;
}

- (BOOL) isEqual:(GKLineDataPoint *)dataPoint
{
return _lineIndex == dataPoint.lineIndex && _valueIndex == dataPoint.valueIndex;
}

@end
36 changes: 30 additions & 6 deletions Source/LineGraph/GKLineGraph.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,36 @@
//

#import <UIKit/UIKit.h>
#import "GKLineDataPoint.h"

@protocol GKLineGraphDataSource;
@protocol GKLineGraphDelegate;

@interface GKLineGraph : UIView

@property (nonatomic, assign) BOOL animated;
@property (nonatomic, assign) CFTimeInterval animationDuration;

@property (nonatomic, weak, readwrite) id <GKLineGraphDelegate> delegate;
@property (nonatomic, assign) id<GKLineGraphDataSource> dataSource;

@property (nonatomic, assign) CGFloat lineWidth;
@property (nonatomic, assign) CGFloat margin;

@property (nonatomic, assign) NSInteger valueLabelCount;
//@property (nonatomic, strong) NSNumber *maxValue;

@property (nonatomic, assign) CGFloat *minValue;
@property (nonatomic, assign) BOOL startFromZero;
@property (nonatomic, assign) BOOL ensureXAxisVisibility;
@property (nonatomic, assign) BOOL drawCoordinateSystem;
@property (nonatomic, assign) BOOL drawVerticalGridLines;
@property (nonatomic, assign) BOOL drawHorizontalGridLines;
@property (nonatomic, assign) NSInteger touchDistanceThreshold;
@property (nonatomic, assign) BOOL drawXAxisLabelsAtAxis;

@property (nonatomic, strong) UIColor *coordinateSystemColor;
@property (nonatomic, strong) UIColor *gridLinesColor;
@property (nonatomic, strong) UIColor *labelTextColor;

- (void)draw;
- (void)reset;
Expand All @@ -50,13 +62,25 @@

@protocol GKLineGraphDataSource <NSObject>

- (NSInteger)numberOfLines;
- (UIColor *)colorForLineAtIndex:(NSInteger)index;
- (NSArray *)valuesForLineAtIndex:(NSInteger)index;
- (NSInteger) numberOfLines;
- (UIColor *) colorForLineAtIndex: (NSInteger)index;
- (NSArray *) valuesForLineAtIndex: (NSInteger)index;

@optional
- (CFTimeInterval)animationDurationForLineAtIndex:(NSInteger)index;

- (NSString *)titleForLineAtIndex:(NSInteger)index;
- (CFTimeInterval) animationDurationForLineAtIndex:(NSInteger)index;
- (NSString *) titleForLineAtIndex:(NSInteger)index;
- (NSString *) identifierForLineAtIndex:(NSInteger)index;
- (NSArray *) dashPatternForLineAtIndex: (NSInteger)index;

@end

@protocol GKLineGraphDelegate <NSObject>

- (void)lineGraph:(GKLineGraph *)lineGraph willSelectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint) targetPoint;
- (void)lineGraph:(GKLineGraph *)lineGraph didSelectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint) targetPoint;
- (void)lineGraph:(GKLineGraph *)lineGraph willDeselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint) targetPoint;
- (void)lineGraph:(GKLineGraph *)lineGraph didDeselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint) targetPoint;
- (void)lineGraph:(GKLineGraph *)lineGraph didReselectDataPoint:(GKLineDataPoint *)dataPoint AtPoint:(CGPoint) targetPoint;

@end
Loading