From c67746306837ecffe2a43c4327edca9562ce7e58 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Sun, 28 Feb 2016 22:59:51 +0200 Subject: [PATCH] DRYed duplicate demo code --- ChartsDemo/Classes/DemoBaseViewController.h | 6 ++ ChartsDemo/Classes/DemoBaseViewController.m | 76 +++++++++++++++++++ .../Demos/AnotherBarChartViewController.m | 59 +------------- .../Classes/Demos/BarChartViewController.m | 66 +--------------- .../Classes/Demos/BubbleChartViewController.m | 58 +------------- .../Demos/CandleStickChartViewController.m | 59 +------------- .../Demos/CombinedChartViewController.m | 16 +--- .../Demos/CubicLineChartViewController.m | 61 ++------------- .../Demos/HorizontalBarChartViewController.m | 66 +--------------- .../Classes/Demos/LineChart1ViewController.m | 61 ++------------- .../Classes/Demos/LineChart2ViewController.m | 61 ++------------- .../Demos/MultipleBarChartViewController.m | 65 +--------------- .../Demos/MultipleLinesChartViewController.m | 61 ++------------- .../NegativeStackedBarChartViewController.m | 65 +--------------- .../Classes/Demos/PieChartViewController.m | 32 +++----- .../PositiveNegativeBarChartViewController.m | 65 +--------------- .../Classes/Demos/RadarChartViewController.m | 38 +++------- .../Demos/ScatterChartViewController.m | 58 +------------- .../Demos/SinusBarChartViewController.m | 65 +--------------- .../Demos/StackedBarChartViewController.m | 65 +--------------- .../RealmDemos/RealmBarChartViewController.m | 56 +------------- .../RealmBubbleChartViewController.m | 49 +----------- .../RealmCandleChartViewController.m | 52 +------------ .../RealmHorizontalBarChartViewController.m | 56 +------------- .../RealmDemos/RealmLineChartViewController.m | 52 +------------ .../RealmDemos/RealmPieChartViewController.m | 23 +++--- .../RealmRadarChartViewController.m | 29 +++---- .../RealmScatterChartViewController.m | 49 +----------- 28 files changed, 178 insertions(+), 1291 deletions(-) diff --git a/ChartsDemo/Classes/DemoBaseViewController.h b/ChartsDemo/Classes/DemoBaseViewController.h index 6fe040a296..7f7e4cc3da 100644 --- a/ChartsDemo/Classes/DemoBaseViewController.h +++ b/ChartsDemo/Classes/DemoBaseViewController.h @@ -24,6 +24,12 @@ @property (nonatomic, strong) IBOutlet UIButton *optionsButton; @property (nonatomic, strong) IBOutlet NSArray *options; +@property (nonatomic, assign) BOOL shouldHideData; + +- (void)handleOption:(NSString *)key forChartView:(ChartViewBase *)chartView; + +- (void)updateChartData; + - (void)setupPieChartView:(PieChartView *)chartView; - (void)setupRadarChartView:(RadarChartView *)chartView; - (void)setupBarLineChartView:(BarLineChartViewBase *)chartView; diff --git a/ChartsDemo/Classes/DemoBaseViewController.m b/ChartsDemo/Classes/DemoBaseViewController.m index d470a6a337..af59ed1b8a 100644 --- a/ChartsDemo/Classes/DemoBaseViewController.m +++ b/ChartsDemo/Classes/DemoBaseViewController.m @@ -76,6 +76,77 @@ - (void)optionTapped:(NSString *)key } +#pragma mark - Common option actions + +- (void)handleOption:(NSString *)key forChartView:(ChartViewBase *)chartView +{ + if ([key isEqualToString:@"toggleValues"]) + { + for (id set in chartView.data.dataSets) + { + set.drawValuesEnabled = !set.isDrawValuesEnabled; + } + + [chartView setNeedsDisplay]; + } + + if ([key isEqualToString:@"toggleHighlight"]) + { + chartView.data.highlightEnabled = !chartView.data.isHighlightEnabled; + [chartView setNeedsDisplay]; + } + + if ([key isEqualToString:@"animateX"]) + { + [chartView animateWithXAxisDuration:3.0]; + } + + if ([key isEqualToString:@"animateY"]) + { + [chartView animateWithYAxisDuration:3.0]; + } + + if ([key isEqualToString:@"animateXY"]) + { + [chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; + } + + if ([key isEqualToString:@"saveToGallery"]) + { + [chartView saveToCameraRoll]; + } + + if ([key isEqualToString:@"togglePinchZoom"]) + { + BarLineChartViewBase *barLineChart = (BarLineChartViewBase *)chartView; + barLineChart.pinchZoomEnabled = !barLineChart.isPinchZoomEnabled; + + [chartView setNeedsDisplay]; + } + + if ([key isEqualToString:@"toggleAutoScaleMinMax"]) + { + BarLineChartViewBase *barLineChart = (BarLineChartViewBase *)chartView; + barLineChart.autoScaleMinMaxEnabled = !barLineChart.isAutoScaleMinMaxEnabled; + + [chartView notifyDataSetChanged]; + } + + if ([key isEqualToString:@"toggleHighlightArrow"]) + { + BarChartView *barChart = (BarChartView *)chartView; + barChart.drawHighlightArrowEnabled = !barChart.isDrawHighlightArrowEnabled; + + [chartView setNeedsDisplay]; + } + + if ([key isEqualToString:@"toggleData"]) + { + _shouldHideData = !_shouldHideData; + [self updateChartData]; + } +} + #pragma mark - Actions - (IBAction)optionsButtonTapped:(id)sender @@ -182,6 +253,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath #pragma mark - Stubs for chart view +- (void)updateChartData +{ + // Override this +} + - (void)setupPieChartView:(PieChartView *)chartView { chartView.usePercentValuesEnabled = YES; diff --git a/ChartsDemo/Classes/Demos/AnotherBarChartViewController.m b/ChartsDemo/Classes/Demos/AnotherBarChartViewController.m index 0e3aa73b78..98a937cdf5 100644 --- a/ChartsDemo/Classes/Demos/AnotherBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/AnotherBarChartViewController.m @@ -21,7 +21,6 @@ @interface AnotherBarChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -78,7 +77,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -118,61 +117,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/BarChartViewController.m b/ChartsDemo/Classes/Demos/BarChartViewController.m index d807c70ed8..10c08203e3 100644 --- a/ChartsDemo/Classes/Demos/BarChartViewController.m +++ b/ChartsDemo/Classes/Demos/BarChartViewController.m @@ -21,7 +21,6 @@ @interface BarChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -100,7 +99,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -141,68 +140,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/BubbleChartViewController.m b/ChartsDemo/Classes/Demos/BubbleChartViewController.m index 9b2f815985..597210cbbe 100644 --- a/ChartsDemo/Classes/Demos/BubbleChartViewController.m +++ b/ChartsDemo/Classes/Demos/BubbleChartViewController.m @@ -19,7 +19,6 @@ @interface BubbleChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -83,7 +82,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -145,60 +144,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/CandleStickChartViewController.m b/ChartsDemo/Classes/Demos/CandleStickChartViewController.m index 54d8e136f7..9281aa4a17 100644 --- a/ChartsDemo/Classes/Demos/CandleStickChartViewController.m +++ b/ChartsDemo/Classes/Demos/CandleStickChartViewController.m @@ -21,7 +21,6 @@ @interface CandleStickChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -83,7 +82,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -134,55 +133,6 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - if ([key isEqualToString:@"toggleShadowColorSameAsCandle"]) { for (id set in _chartView.data.dataSets) @@ -191,13 +141,10 @@ - (void)optionTapped:(NSString *)key } [_chartView notifyDataSetChanged]; + return; } - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/CombinedChartViewController.m b/ChartsDemo/Classes/Demos/CombinedChartViewController.m index 83d546aca6..dad90871cb 100644 --- a/ChartsDemo/Classes/Demos/CombinedChartViewController.m +++ b/ChartsDemo/Classes/Demos/CombinedChartViewController.m @@ -19,7 +19,6 @@ @interface CombinedChartViewController () @property (nonatomic, strong) IBOutlet CombinedChartView *chartView; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -76,7 +75,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -110,6 +109,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleBarValues"]) @@ -123,18 +123,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } - (LineChartData *)generateLineData diff --git a/ChartsDemo/Classes/Demos/CubicLineChartViewController.m b/ChartsDemo/Classes/Demos/CubicLineChartViewController.m index b6b8e17c0e..ce5cd847a7 100644 --- a/ChartsDemo/Classes/Demos/CubicLineChartViewController.m +++ b/ChartsDemo/Classes/Demos/CubicLineChartViewController.m @@ -35,7 +35,6 @@ @interface CubicLineChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -103,7 +102,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -153,16 +152,6 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleFilled"]) { for (id set in _chartView.data.dataSets) @@ -171,6 +160,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCircles"]) @@ -181,6 +171,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCubic"]) @@ -191,52 +182,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/HorizontalBarChartViewController.m b/ChartsDemo/Classes/Demos/HorizontalBarChartViewController.m index 4587f3bb2b..ed9739e2dc 100644 --- a/ChartsDemo/Classes/Demos/HorizontalBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/HorizontalBarChartViewController.m @@ -21,7 +21,6 @@ @interface HorizontalBarChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -97,7 +96,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -138,68 +137,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/LineChart1ViewController.m b/ChartsDemo/Classes/Demos/LineChart1ViewController.m index 65b539617d..80747c184f 100644 --- a/ChartsDemo/Classes/Demos/LineChart1ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart1ViewController.m @@ -21,7 +21,6 @@ @interface LineChart1ViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -115,7 +114,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -175,16 +174,6 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleFilled"]) { for (id set in _chartView.data.dataSets) @@ -193,6 +182,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCircles"]) @@ -203,6 +193,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCubic"]) @@ -213,52 +204,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0 easingOption:ChartEasingOptionEaseInCubic]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/LineChart2ViewController.m b/ChartsDemo/Classes/Demos/LineChart2ViewController.m index 2910e1bf68..62cb5e32b0 100644 --- a/ChartsDemo/Classes/Demos/LineChart2ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart2ViewController.m @@ -21,7 +21,6 @@ @interface LineChart2ViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -100,7 +99,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -171,16 +170,6 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleFilled"]) { for (id set in _chartView.data.dataSets) @@ -189,6 +178,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCircles"]) @@ -199,6 +189,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCubic"]) @@ -209,52 +200,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/MultipleBarChartViewController.m b/ChartsDemo/Classes/Demos/MultipleBarChartViewController.m index f1a5fd7c68..79e25f0951 100644 --- a/ChartsDemo/Classes/Demos/MultipleBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/MultipleBarChartViewController.m @@ -21,7 +21,6 @@ @interface MultipleBarChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -88,7 +87,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -145,67 +144,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/MultipleLinesChartViewController.m b/ChartsDemo/Classes/Demos/MultipleLinesChartViewController.m index 90ba74bc55..1351affb72 100644 --- a/ChartsDemo/Classes/Demos/MultipleLinesChartViewController.m +++ b/ChartsDemo/Classes/Demos/MultipleLinesChartViewController.m @@ -21,7 +21,6 @@ @interface MultipleLinesChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -82,7 +81,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -135,16 +134,6 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleFilled"]) { for (id set in _chartView.data.dataSets) @@ -153,6 +142,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCircles"]) @@ -163,6 +153,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCubic"]) @@ -173,52 +164,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/NegativeStackedBarChartViewController.m b/ChartsDemo/Classes/Demos/NegativeStackedBarChartViewController.m index 84f83b47fa..d759f3f8a9 100644 --- a/ChartsDemo/Classes/Demos/NegativeStackedBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/NegativeStackedBarChartViewController.m @@ -17,7 +17,6 @@ @interface NegativeStackedBarChartViewController () @property (nonatomic, strong) IBOutlet HorizontalBarChartView *chartView; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -89,7 +88,7 @@ - (void)viewDidLoad - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -141,67 +140,7 @@ - (void)didReceiveMemoryWarning - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/Demos/PieChartViewController.m b/ChartsDemo/Classes/Demos/PieChartViewController.m index 27f0612ed7..daaeb63aa1 100644 --- a/ChartsDemo/Classes/Demos/PieChartViewController.m +++ b/ChartsDemo/Classes/Demos/PieChartViewController.m @@ -21,7 +21,6 @@ @interface PieChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -66,7 +65,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -126,21 +125,12 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleXValues"]) { _chartView.drawSliceTextEnabled = !_chartView.isDrawSliceTextEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"togglePercent"]) @@ -148,6 +138,7 @@ - (void)optionTapped:(NSString *)key _chartView.usePercentValuesEnabled = !_chartView.isUsePercentValuesEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleHole"]) @@ -155,6 +146,7 @@ - (void)optionTapped:(NSString *)key _chartView.drawHoleEnabled = !_chartView.isDrawHoleEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"drawCenter"]) @@ -162,38 +154,34 @@ - (void)optionTapped:(NSString *)key _chartView.drawCenterTextEnabled = !_chartView.isDrawCenterTextEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"animateX"]) { [_chartView animateWithXAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateY"]) { [_chartView animateWithYAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateXY"]) { [_chartView animateWithXAxisDuration:1.4 yAxisDuration:1.4]; + return; } if ([key isEqualToString:@"spin"]) { [_chartView spinWithDuration:2.0 fromAngle:_chartView.rotationAngle toAngle:_chartView.rotationAngle + 360.f]; + return; } - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/PositiveNegativeBarChartViewController.m b/ChartsDemo/Classes/Demos/PositiveNegativeBarChartViewController.m index 4e4c8b8f44..bf17e5e7b5 100644 --- a/ChartsDemo/Classes/Demos/PositiveNegativeBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/PositiveNegativeBarChartViewController.m @@ -17,7 +17,6 @@ @interface PositiveNegativeBarChartViewController () @property (nonatomic, strong) IBOutlet BarChartView *chartView; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -93,7 +92,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -166,67 +165,7 @@ - (void)setChartData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/Demos/RadarChartViewController.m b/ChartsDemo/Classes/Demos/RadarChartViewController.m index 365242d3b2..f2fea32113 100644 --- a/ChartsDemo/Classes/Demos/RadarChartViewController.m +++ b/ChartsDemo/Classes/Demos/RadarChartViewController.m @@ -17,7 +17,6 @@ @interface RadarChartViewController () @property (nonatomic, strong) IBOutlet RadarChartView *chartView; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -82,7 +81,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -133,39 +132,26 @@ - (void)setChartData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleXLabels"]) { _chartView.xAxis.drawLabelsEnabled = !_chartView.xAxis.isDrawLabelsEnabled; [_chartView notifyDataSetChanged]; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleYLabels"]) { _chartView.yAxis.drawLabelsEnabled = !_chartView.yAxis.isDrawLabelsEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleRotate"]) { _chartView.rotationEnabled = !_chartView.isRotationEnabled; + return; } if ([key isEqualToString:@"toggleFill"]) @@ -176,38 +162,34 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"animateX"]) { [_chartView animateWithXAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateY"]) { [_chartView animateWithYAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateXY"]) { [_chartView animateWithXAxisDuration:1.4 yAxisDuration:1.4]; + return; } if ([key isEqualToString:@"spin"]) { [_chartView spinWithDuration:2.0 fromAngle:_chartView.rotationAngle toAngle:_chartView.rotationAngle + 360.f easingOption:ChartEasingOptionEaseInCubic]; + return; } - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/Demos/ScatterChartViewController.m b/ChartsDemo/Classes/Demos/ScatterChartViewController.m index 9ed6d7e0fc..bf3e92492e 100644 --- a/ChartsDemo/Classes/Demos/ScatterChartViewController.m +++ b/ChartsDemo/Classes/Demos/ScatterChartViewController.m @@ -21,7 +21,6 @@ @interface ScatterChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -83,7 +82,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -146,60 +145,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/SinusBarChartViewController.m b/ChartsDemo/Classes/Demos/SinusBarChartViewController.m index 8c6205ab1f..da3f29bcce 100644 --- a/ChartsDemo/Classes/Demos/SinusBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/SinusBarChartViewController.m @@ -19,7 +19,6 @@ @interface SinusBarChartViewController () @property (nonatomic, strong) IBOutlet BarChartView *chartView; @property (nonatomic, strong) IBOutlet UISlider *sliderX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -95,7 +94,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -128,67 +127,7 @@ - (void)setDataCount:(int)count - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/Demos/StackedBarChartViewController.m b/ChartsDemo/Classes/Demos/StackedBarChartViewController.m index 4f20e4838f..b344059725 100644 --- a/ChartsDemo/Classes/Demos/StackedBarChartViewController.m +++ b/ChartsDemo/Classes/Demos/StackedBarChartViewController.m @@ -21,7 +21,6 @@ @interface StackedBarChartViewController () @property (nonatomic, strong) IBOutlet UISlider *sliderY; @property (nonatomic, strong) IBOutlet UITextField *sliderTextX; @property (nonatomic, strong) IBOutlet UITextField *sliderTextY; -@property (nonatomic, assign) BOOL shouldHideData; @end @@ -89,7 +88,7 @@ - (void)didReceiveMemoryWarning - (void)updateChartData { - if (_shouldHideData) + if (self.shouldHideData) { _chartView.data = nil; return; @@ -140,67 +139,7 @@ - (void)setDataCount:(int)count range:(double)range - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - - if ([key isEqualToString:@"toggleData"]) - { - _shouldHideData = !_shouldHideData; - [self updateChartData]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - Actions diff --git a/ChartsDemo/Classes/RealmDemos/RealmBarChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmBarChartViewController.m index 299d555d3e..373209c49d 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmBarChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmBarChartViewController.m @@ -82,61 +82,7 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmBubbleChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmBubbleChartViewController.m index 409de2bb8e..fef941016b 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmBubbleChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmBubbleChartViewController.m @@ -84,54 +84,7 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmCandleChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmCandleChartViewController.m index a95bd14df7..a17e8d0ef5 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmCandleChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmCandleChartViewController.m @@ -92,55 +92,6 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } - if ([key isEqualToString:@"toggleShadowColorSameAsCandle"]) { for (id set in _chartView.data.dataSets) @@ -149,7 +100,10 @@ - (void)optionTapped:(NSString *)key } [_chartView notifyDataSetChanged]; + return; } + + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmHorizontalBarChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmHorizontalBarChartViewController.m index 78e52f1c9e..d279357d0d 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmHorizontalBarChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmHorizontalBarChartViewController.m @@ -96,61 +96,7 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlightArrow"]) - { - _chartView.drawHighlightArrowEnabled = !_chartView.isDrawHighlightArrowEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmLineChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmLineChartViewController.m index 78e45a5d39..456accb6b2 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmLineChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmLineChartViewController.m @@ -94,16 +94,6 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleFilled"]) { for (id set in _chartView.data.dataSets) @@ -112,6 +102,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCircles"]) @@ -122,6 +113,7 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleCubic"]) @@ -132,46 +124,10 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0 easingOption:ChartEasingOptionEaseInCubic]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmPieChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmPieChartViewController.m index 25bd98a77f..36ebbf97ff 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmPieChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmPieChartViewController.m @@ -100,21 +100,12 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleXValues"]) { _chartView.drawSliceTextEnabled = !_chartView.isDrawSliceTextEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"togglePercent"]) @@ -122,6 +113,7 @@ - (void)optionTapped:(NSString *)key _chartView.usePercentValuesEnabled = !_chartView.isUsePercentValuesEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleHole"]) @@ -129,6 +121,7 @@ - (void)optionTapped:(NSString *)key _chartView.drawHoleEnabled = !_chartView.isDrawHoleEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"drawCenter"]) @@ -136,32 +129,34 @@ - (void)optionTapped:(NSString *)key _chartView.drawCenterTextEnabled = !_chartView.isDrawCenterTextEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"animateX"]) { [_chartView animateWithXAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateY"]) { [_chartView animateWithYAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateXY"]) { [_chartView animateWithXAxisDuration:1.4 yAxisDuration:1.4]; + return; } if ([key isEqualToString:@"spin"]) { [_chartView spinWithDuration:2.0 fromAngle:_chartView.rotationAngle toAngle:_chartView.rotationAngle + 360.f]; + return; } - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmRadarChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmRadarChartViewController.m index 2ebdbd0cb1..fc001b5d07 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmRadarChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmRadarChartViewController.m @@ -92,39 +92,26 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - if ([key isEqualToString:@"toggleXLabels"]) { _chartView.xAxis.drawLabelsEnabled = !_chartView.xAxis.isDrawLabelsEnabled; [_chartView notifyDataSetChanged]; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleYLabels"]) { _chartView.yAxis.drawLabelsEnabled = !_chartView.yAxis.isDrawLabelsEnabled; [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"toggleRotate"]) { _chartView.rotationEnabled = !_chartView.isRotationEnabled; + return; } if ([key isEqualToString:@"toggleFill"]) @@ -135,32 +122,34 @@ - (void)optionTapped:(NSString *)key } [_chartView setNeedsDisplay]; + return; } if ([key isEqualToString:@"animateX"]) { [_chartView animateWithXAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateY"]) { [_chartView animateWithYAxisDuration:1.4]; + return; } if ([key isEqualToString:@"animateXY"]) { [_chartView animateWithXAxisDuration:1.4 yAxisDuration:1.4]; + return; } if ([key isEqualToString:@"spin"]) { [_chartView spinWithDuration:2.0 fromAngle:_chartView.rotationAngle toAngle:_chartView.rotationAngle + 360.f easingOption:ChartEasingOptionEaseInCubic]; + return; } - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate diff --git a/ChartsDemo/Classes/RealmDemos/RealmScatterChartViewController.m b/ChartsDemo/Classes/RealmDemos/RealmScatterChartViewController.m index b7ce654ee4..8e955a9440 100644 --- a/ChartsDemo/Classes/RealmDemos/RealmScatterChartViewController.m +++ b/ChartsDemo/Classes/RealmDemos/RealmScatterChartViewController.m @@ -87,54 +87,7 @@ - (void)setData - (void)optionTapped:(NSString *)key { - if ([key isEqualToString:@"toggleValues"]) - { - for (id set in _chartView.data.dataSets) - { - set.drawValuesEnabled = !set.isDrawValuesEnabled; - } - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleHighlight"]) - { - _chartView.data.highlightEnabled = !_chartView.data.isHighlightEnabled; - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"animateX"]) - { - [_chartView animateWithXAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateY"]) - { - [_chartView animateWithYAxisDuration:3.0]; - } - - if ([key isEqualToString:@"animateXY"]) - { - [_chartView animateWithXAxisDuration:3.0 yAxisDuration:3.0]; - } - - if ([key isEqualToString:@"saveToGallery"]) - { - [_chartView saveToCameraRoll]; - } - - if ([key isEqualToString:@"togglePinchZoom"]) - { - _chartView.pinchZoomEnabled = !_chartView.isPinchZoomEnabled; - - [_chartView setNeedsDisplay]; - } - - if ([key isEqualToString:@"toggleAutoScaleMinMax"]) - { - _chartView.autoScaleMinMaxEnabled = !_chartView.isAutoScaleMinMaxEnabled; - [_chartView notifyDataSetChanged]; - } + [super handleOption:key forChartView:_chartView]; } #pragma mark - ChartViewDelegate