Skip to content

Commit

Permalink
some demos updated to toggle icons
Browse files Browse the repository at this point in the history
  • Loading branch information
abjurato committed Nov 5, 2016
1 parent 5161890 commit fbba515
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
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

0 comments on commit fbba515

Please sign in to comment.