From c979e1a60b8a770c91e36bad812ed167e61d66b2 Mon Sep 17 00:00:00 2001 From: madhuka Date: Mon, 29 Jun 2015 16:21:39 +0530 Subject: [PATCH] Removing switch --- app/scripts/config/chart-config.js | 3 +++ app/scripts/controllers/chart-controllers.js | 27 ++++++-------------- app/scripts/services/chart-meta-service.js | 7 +++++ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/scripts/config/chart-config.js b/app/scripts/config/chart-config.js index 22c5b5a..aa28a6e 100644 --- a/app/scripts/config/chart-config.js +++ b/app/scripts/config/chart-config.js @@ -11,12 +11,15 @@ angular.module('apacheZeppelinGsocApp') .constant('chartConfig', { 'libraryName': [{ 'library': 'highChart', + 'service': 'getHighChart', 'template': 'views/charts/highchart.html' }, { 'library': 'NVD3Chart', + 'service': 'getNVD3Chart', 'template': 'views/charts/nvd3chart.html' }, { 'library': 'googleChart', + 'service': 'getGoogleChart', 'template': 'views/charts/googlechart.html' }], 'dataFiles': ['car', 'bike'], diff --git a/app/scripts/controllers/chart-controllers.js b/app/scripts/controllers/chart-controllers.js index 43006a0..d1b9767 100644 --- a/app/scripts/controllers/chart-controllers.js +++ b/app/scripts/controllers/chart-controllers.js @@ -33,6 +33,7 @@ angular.module('apacheZeppelinGsocApp').controller('ChartCtrl', function($scope, setButtonActive('chartLibraryButton', libraryName[libraryIndex].library); ChartMetaService.setChartLib(libraryName[libraryIndex].library); ChartMetaService.setChartTemplateURL(libraryName[libraryIndex].template); + ChartMetaService.setChartService(libraryName[libraryIndex].service); if (ChartMetaService.getChartType() === null) { //setting default chart type ChartMetaService.setChartType('Bar'); @@ -55,26 +56,14 @@ angular.module('apacheZeppelinGsocApp').controller('ChartCtrl', function($scope, //Checking chart requirement is completed var myNewChart = {}; var myChartType = ChartMetaService.getChartType(); - console.log(myChartType); - switch (ChartMetaService.getChartLib()) { - case 'NVD3Chart': - //set data for NVD3 - myNewChart = ChartService.getNVD3Chart(myChartType); - vm.chart = myNewChart.viewModel; - break; - case 'highChart': - myNewChart = ChartService.getHighChart(myChartType); - vm.chart = myNewChart.viewModel; - break; - case 'googleChart': - myNewChart = ChartService.getGoogleChart(myChartType); - vm.chart = myNewChart.viewModel; - break; + var chartService = ChartMetaService.getChartService(); + if (chartService !== null) { + myNewChart = ChartService[chartService](myChartType); + vm.chart = myNewChart.viewModel; + if (myNewChart.model) { + renderChart(myNewChart.model, data); + } } - if (myNewChart.model) { - renderChart(myNewChart.model, data); - } - //NVD3 axis update } function getData(fileName) { diff --git a/app/scripts/services/chart-meta-service.js b/app/scripts/services/chart-meta-service.js index e839e09..4913d8b 100644 --- a/app/scripts/services/chart-meta-service.js +++ b/app/scripts/services/chart-meta-service.js @@ -11,6 +11,7 @@ angular.module('apacheZeppelinGsocApp').service('ChartMetaService', function() { var MetaModel = { ChartLib: null, ChartTemplateURL: null, + ChartService: null, ChartType: null, ChartDataSetName: null, ChartDataSetPath: null, @@ -26,6 +27,9 @@ angular.module('apacheZeppelinGsocApp').service('ChartMetaService', function() { this.getChartTemplateURL = function() { return MetaModel.ChartTemplateURL; }; + this.getChartService = function() { + return MetaModel.ChartService; + }; this.getChartDataSetName = function() { return MetaModel.ChartDataSetName; }; @@ -45,6 +49,9 @@ angular.module('apacheZeppelinGsocApp').service('ChartMetaService', function() { this.setChartTemplateURL = function(ChartTemplateURL) { MetaModel.ChartTemplateURL = ChartTemplateURL; }; + this.setChartService = function(ChartService) { + MetaModel.ChartService = ChartService; + }; this.setChartDataSetName = function(ChartDataSetName) { MetaModel.ChartDataSetName = ChartDataSetName; MetaModel.ChartDataSetPath = 'data/' + ChartDataSetName + '.csv';