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

All Charts Icons Support Swift3 [Dub #629, #624, #1261] #1793

Merged
merged 9 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
06B3C0F81D99F85400B1DF43 /* LineChartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B3C0F41D99F85400B1DF43 /* LineChartTests.swift */; };
06B3C0F91D99F85400B1DF43 /* ChartsRealmTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B3C0F61D99F85400B1DF43 /* ChartsRealmTest.swift */; };
5B56A9CD1D905EB300F58178 /* Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B56A9CC1D905EB300F58178 /* Description.swift */; };
D8A58A411DCE2EF8007BB012 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D8A58A401DCE2EF8007BB012 /* Media.xcassets */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -337,6 +338,7 @@
06B3C0F41D99F85400B1DF43 /* LineChartTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineChartTests.swift; sourceTree = "<group>"; };
06B3C0F61D99F85400B1DF43 /* ChartsRealmTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartsRealmTest.swift; sourceTree = "<group>"; };
5B56A9CC1D905EB300F58178 /* Description.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Description.swift; sourceTree = "<group>"; };
D8A58A401DCE2EF8007BB012 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Media.xcassets; path = Charts/ChartsTests/Media.xcassets; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -737,6 +739,7 @@
isa = PBXGroup;
children = (
06B121111D81201C00D14B02 /* Info.plist */,
D8A58A401DCE2EF8007BB012 /* Media.xcassets */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -891,6 +894,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D8A58A411DCE2EF8007BB012 /* Media.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 6 additions & 0 deletions Charts/ChartsTests/Media.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Charts/ChartsTests/Media.xcassets/icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "star-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "star-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "star.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ChartsDemo/Classes/DemoBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ - (void)handleOption:(NSString *)key forChartView:(ChartViewBase *)chartView
[chartView setNeedsDisplay];
}

if ([key isEqualToString:@"toggleIcons"])
{
for (id<IChartDataSet> set in chartView.data.dataSets)
{
set.drawIconsEnabled = !set.isDrawIconsEnabled;
}

[chartView setNeedsDisplay];
}

if ([key isEqualToString:@"toggleHighlight"])
{
chartView.data.highlightEnabled = !chartView.data.isHighlightEnabled;
Expand Down
7 changes: 6 additions & 1 deletion ChartsDemo/Classes/Demos/BarChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -136,7 +137,11 @@ - (void)setDataCount:(int)count range:(double)range
{
double mult = (range + 1);
double val = (double) (arc4random_uniform(mult));
[yVals addObject:[[BarChartDataEntry alloc] initWithX:(double)i y:val]];
if (arc4random_uniform(100) < 25) {
[yVals addObject:[[BarChartDataEntry alloc] initWithX:val y:i data: [UIImage imageNamed:@"icon"]]];
} else {
[yVals addObject:[[BarChartDataEntry alloc] initWithX:val y:i]];
}
}

BarChartDataSet *set1 = nil;
Expand Down
6 changes: 4 additions & 2 deletions ChartsDemo/Classes/Demos/BubbleChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -103,11 +104,11 @@ - (void)setDataCount:(int)count range:(double)range
{
double val = (double) (arc4random_uniform(range));
double size = (double) (arc4random_uniform(range));
[yVals1 addObject:[[BubbleChartDataEntry alloc] initWithX:i y:val size:size]];
[yVals1 addObject:[[BubbleChartDataEntry alloc] initWithX:i y:val size:size data: [UIImage imageNamed:@"icon"]]];

val = (double) (arc4random_uniform(range));
size = (double) (arc4random_uniform(range));
[yVals2 addObject:[[BubbleChartDataEntry alloc] initWithX:i y:val size:size]];
[yVals2 addObject:[[BubbleChartDataEntry alloc] initWithX:i y:val size:size data: [UIImage imageNamed:@"icon"]]];

val = (double) (arc4random_uniform(range));
size = (double) (arc4random_uniform(range));
Expand All @@ -118,6 +119,7 @@ - (void)setDataCount:(int)count range:(double)range
[set1 setColor:ChartColorTemplates.colorful[0] alpha:0.50f];
[set1 setDrawValuesEnabled:YES];
BubbleChartDataSet *set2 = [[BubbleChartDataSet alloc] initWithValues:yVals2 label:@"DS 2"];
set1.iconsOffset = CGSizeMake(0, 15);
[set2 setColor:ChartColorTemplates.colorful[1] alpha:0.50f];
[set2 setDrawValuesEnabled:YES];
BubbleChartDataSet *set3 = [[BubbleChartDataSet alloc] initWithValues:yVals3 label:@"DS 3"];
Expand Down
3 changes: 2 additions & 1 deletion ChartsDemo/Classes/Demos/CandleStickChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -100,7 +101,7 @@ - (void)setDataCount:(int)count range:(double)range
double open = (double) (arc4random_uniform(6)) + 1.0;
double close = (double) (arc4random_uniform(6)) + 1.0;
BOOL even = i % 2 == 0;
[yVals1 addObject:[[CandleChartDataEntry alloc] initWithX:i shadowH:val + high shadowL:val - low open:even ? val + open : val - open close:even ? val - close : val + close]];
[yVals1 addObject:[[CandleChartDataEntry alloc] initWithX:i shadowH:val + high shadowL:val - low open:even ? val + open : val - open close:even ? val - close : val + close data: [UIImage imageNamed:@"icon"]]];
}

CandleChartDataSet *set1 = [[CandleChartDataSet alloc] initWithValues:yVals1 label:@"Data Set"];
Expand Down
3 changes: 2 additions & 1 deletion ChartsDemo/Classes/Demos/HorizontalBarChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -119,7 +120,7 @@ - (void)setDataCount:(int)count range:(double)range
{
double mult = (range + 1);
double val = (double) (arc4random_uniform(mult));
[yVals addObject:[[BarChartDataEntry alloc] initWithX:i * spaceForBar y:val]];
[yVals addObject:[[BarChartDataEntry alloc] initWithX:i * spaceForBar y:val data: [UIImage imageNamed:@"icon"]]];
}

BarChartDataSet *set1 = nil;
Expand Down
3 changes: 2 additions & 1 deletion ChartsDemo/Classes/Demos/LineChart1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (void)viewDidLoad
@{@"key": @"toggleCircles", @"label": @"Toggle Circles"},
@{@"key": @"toggleCubic", @"label": @"Toggle Cubic"},
@{@"key": @"toggleHorizontalCubic", @"label": @"Toggle Horizontal Cubic"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleStepped", @"label": @"Toggle Stepped"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
Expand Down Expand Up @@ -137,7 +138,7 @@ - (void)setDataCount:(int)count range:(double)range
for (int i = 0; i < count; i++)
{
double val = arc4random_uniform(range) + 3;
[values addObject:[[ChartDataEntry alloc] initWithX:i y:val]];
[values addObject:[[ChartDataEntry alloc] initWithX:i y:val data: [UIImage imageNamed:@"icon"]]];
}

LineChartDataSet *set1 = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -112,7 +113,7 @@ - (void)setChartData
[yValues addObject:[[BarChartDataEntry alloc] initWithX:15 yValues:@[ @-12, @13 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:25 yValues:@[ @-15, @15 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:35 yValues:@[ @-17, @17 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:45 yValues:@[ @-19, @20 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:45 yValues:@[ @-19, @20 ] data: [UIImage imageNamed:@"icon"]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:55 yValues:@[ @-19, @19 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:65 yValues:@[ @-16, @16 ]]];
[yValues addObject:[[BarChartDataEntry alloc] initWithX:75 yValues:@[ @-13, @14 ]]];
Expand Down
4 changes: 3 additions & 1 deletion ChartsDemo/Classes/Demos/PieChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ - (void)viewDidLoad
@{@"key": @"toggleXValues", @"label": @"Toggle X-Values"},
@{@"key": @"togglePercent", @"label": @"Toggle Percent"},
@{@"key": @"toggleHole", @"label": @"Toggle Hole"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
@{@"key": @"animateXY", @"label": @"Animate XY"},
Expand Down Expand Up @@ -93,11 +94,12 @@ - (void)setDataCount:(int)count range:(double)range

for (int i = 0; i < count; i++)
{
[values addObject:[[PieChartDataEntry alloc] initWithValue:(arc4random_uniform(mult) + mult / 5) label:parties[i % parties.count]]];
[values addObject:[[PieChartDataEntry alloc] initWithValue:(arc4random_uniform(mult) + mult / 5) label:parties[i % parties.count] data: [UIImage imageNamed:@"icon"]]];
}

PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithValues:values label:@"Election Results"];
dataSet.sliceSpace = 2.0;
dataSet.iconsOffset = CGSizeMake(0, 40);

// add a lot of colors

Expand Down
3 changes: 2 additions & 1 deletion ChartsDemo/Classes/Demos/StackedBarChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)viewDidLoad

self.options = @[
@{@"key": @"toggleValues", @"label": @"Toggle Values"},
@{@"key": @"toggleIcons", @"label": @"Toggle Icons"},
@{@"key": @"toggleHighlight", @"label": @"Toggle Highlight"},
@{@"key": @"animateX", @"label": @"Animate X"},
@{@"key": @"animateY", @"label": @"Animate Y"},
Expand Down Expand Up @@ -111,7 +112,7 @@ - (void)setDataCount:(int)count range:(double)range
double val2 = (double) (arc4random_uniform(mult) + mult / 3);
double val3 = (double) (arc4random_uniform(mult) + mult / 3);

[yVals addObject:[[BarChartDataEntry alloc] initWithX:i yValues:@[@(val1), @(val2), @(val3)]]];
[yVals addObject:[[BarChartDataEntry alloc] initWithX:i yValues:@[@(val1), @(val2), @(val3)] data: [UIImage imageNamed:@"icon"]]];
}

BarChartDataSet *set1 = nil;
Expand Down
6 changes: 6 additions & 0 deletions ChartsDemo/Resources/Images.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions ChartsDemo/Resources/Images.xcassets/icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "star-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "star-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "star.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Source/Charts/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ open class ChartBaseDataSet: NSObject, IChartDataSet
{
return drawValuesEnabled
}

/// Set this to true to draw y-icon on the chart
open var drawIconsEnabled = true

/// Returns true if y-icon drawing is enabled, false if not
open var isDrawIconsEnabled: Bool
{
return drawIconsEnabled
}

/// Offset of icon position from chart's default icon position
open var iconsOffset = CGSize(width: 0,height: 0)

/// Set the visibility of this DataSet. If not visible, the DataSet will not be drawn to the chart upon refreshing it.
open var visible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ open class BarChartDataEntry: ChartDataEntry
calcRanges()
}

/// Constructor for stacked bar entries. One data object for whole stack
public init(x: Double, yValues: [Double], data: AnyObject?)
{
super.init(x: x, y: BarChartDataEntry.calcSum(values: yValues), data: data)
self._yVals = yValues
calcPosNegSum()
}

/// Constructor for normal bars (not stacked).
public override init(x: Double, y: Double, data: AnyObject?)
{
Expand Down
9 changes: 9 additions & 0 deletions Source/Charts/Data/Interfaces/IChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public protocol IChartDataSet
/// - returns: `true` if y-value drawing is enabled, `false` ifnot
var isDrawValuesEnabled: Bool { get }

/// Set this to true to draw y-icon on the chart
var drawIconsEnabled: Bool { get set }

/// Returns true if y-icon drawing is enabled, false if not
var isDrawIconsEnabled: Bool { get }

/// Offset of y-icons drawn on the chart
var iconsOffset: CGSize { get set }

/// Set the visibility of this DataSet. If not visible, the DataSet will not be drawn to the chart upon refreshing it.
var visible: Bool { get set }

Expand Down
Loading