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
6 changes: 5 additions & 1 deletion GraphKit/Example/ExampleListVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "ExampleBarVC.h"
#import "ExampleBarGraphVC.h"
#import "ExampleStackedBarGraphVC.h"
#import "ExampleLineGraph.h"

#import "UIColor+GraphKit.h"
Expand All @@ -26,7 +27,7 @@ - (void)viewDidLoad {
self.title = @"GraphKit";
self.view.backgroundColor = [UIColor gk_cloudsColor];

self.data = @[@"Bar", @"Bar Graph", @"Line Graph"];
self.data = @[@"Bar", @"Bar Graph", @"Stacked Bar Graph", @"Line Graph"];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];

Expand All @@ -53,6 +54,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
vc = [[ExampleBarGraphVC alloc] initWithNibName:@"ExampleBarGraphVC" bundle:nil];
break;
case 2:
vc = [[ExampleStackedBarGraphVC alloc] initWithNibName:@"ExampleStackedBarGraphVC" bundle:nil];
break;
case 3:
vc = [[ExampleLineGraph alloc] initWithNibName:@"ExampleLineGraph" bundle:nil];
break;
default:
Expand Down
12 changes: 8 additions & 4 deletions GraphKit/Example/ExampleListVC.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ExampleListVC">
Expand All @@ -26,9 +27,12 @@
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" translucent="NO" prompted="NO"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
26 changes: 26 additions & 0 deletions GraphKit/Example/ExampleStackedBarGraphVC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ExampleStackedBarGraphVC.h
// GraphKit
//
// Created by Erich Grunewald on 27/04/15.
// Copyright (c) 2015 Michal Konturek. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "GraphKit.h"

@interface ExampleStackedBarGraphVC : UIViewController<GKStackedBarGraphDataSource>

@property (nonatomic, weak) IBOutlet GKStackedBarGraph *graphView;

@property (nonatomic, strong) NSArray *data;
@property (nonatomic, strong) NSArray *labels;

- (IBAction)onButtonFill:(id)sender;

- (IBAction)onButtonChange:(id)sender;

- (IBAction)onButtonReset:(id)sender;

@end
102 changes: 102 additions & 0 deletions GraphKit/Example/ExampleStackedBarGraphVC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// ExampleStackedBarGraphVC.m
// GraphKit
//
// Created by Erich Grunewald on 27/04/15.
// Copyright (c) 2015 Michal Konturek. All rights reserved.
//

#import "ExampleStackedBarGraphVC.h"

#import "UIViewController+BButton.h"

@interface ExampleStackedBarGraphVC ()

@property (nonatomic, strong) NSArray *colors;
@property (nonatomic, assign) BOOL warmColors;

@end

@implementation ExampleStackedBarGraphVC

- (void)viewDidLoad {
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;

[self setupButtons];

self.view.backgroundColor = [UIColor gk_cloudsColor];

self.data = @[@[@11, @14, @49, @12],
@[@25, @4, @8, @8],
@[@7, @38, @17, @28],
@[@28, @5, @8, @59]];
self.labels = @[@"DE", @"PL", @"CN", @"JP"];

self.colors = @[@[[UIColor gk_midnightBlueColor],
[UIColor gk_wisteriaColor],
[UIColor gk_peterRiverColor],
[UIColor gk_emerlandColor]
],
@[[UIColor gk_pomegranateColor],
[UIColor gk_alizarinColor],
[UIColor gk_sunflowerColor],
[UIColor gk_amethystColor]
]];

self.graphView.dataSource = self;

[self.graphView draw];

self.warmColors = NO;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)onButtonFill:(id)sender {
[self.graphView draw];
}

- (IBAction)onButtonChange:(id)sender {
self.warmColors = !self.warmColors;
self.graphView.barColors = self.colors[self.warmColors];
}

- (IBAction)onButtonReset:(id)sender {
[self.graphView reset];
}


#pragma mark - GKStackedBarGraphDataSource

- (NSInteger)numberOfBars {
return [self.data count];
}

- (NSInteger)numberOfStacks {
return [[self.data firstObject] count];
}

- (NSNumber *)valueForBarAtIndex:(NSInteger)index stack:(NSInteger)stack {
return self.data[index][stack];
}

- (UIColor *)colorForBarAtIndex:(NSInteger)index stack:(NSInteger)stack {
return self.colors[0][stack];
}

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

- (CFTimeInterval)animationDurationForBarAtIndex:(NSInteger)index {
id barValues = self.data[index];
CGFloat percentage = [[barValues valueForKeyPath:@"@sum.self"] doubleValue];
percentage = (percentage / 100);
return (self.graphView.animationDuration * percentage);
}

@end
64 changes: 64 additions & 0 deletions GraphKit/Example/ExampleStackedBarGraphVC.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ExampleStackedBarGraphVC">
<connections>
<outlet property="graphView" destination="MmA-T7-dVQ" id="iTT-LE-3hD"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" id="MmA-T7-dVQ" customClass="GKStackedBarGraph">
<rect key="frame" x="0.0" y="40" width="320" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="qoZ-fh-agP" customClass="BButton">
<rect key="frame" x="120" y="257" width="80" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Reset">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonReset:" destination="-1" eventType="touchUpInside" id="8I3-Mj-fbB"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="U74-0Y-fwz" customClass="BButton">
<rect key="frame" x="32" y="257" width="80" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Fill">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonFill:" destination="-1" eventType="touchUpInside" id="Qpe-cp-Scz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="ATO-y0-Ket" customClass="BButton">
<rect key="frame" x="208" y="257" width="80" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Color">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonChange:" destination="-1" eventType="touchUpInside" id="lo3-iG-aXs"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" translucent="NO" prompted="NO"/>
<point key="canvasLocation" x="445" y="465"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
Loading