-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchart-controllers.js
119 lines (110 loc) · 3.56 KB
/
chart-controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
/**
* @ngdoc function
* @name apacheZeppelinGsocApp.controller:ChartCtrl
* @description
* # ChartCtrl
* Controller of chart library, type.
*
* @author madhuka udantha
*/
angular.module('apacheZeppelinGsocApp').controller('ChartCtrl', function($scope,
ChartFactory, GoogleChartFactory, HighChartFactory, NVD3ChartFactory,
ChartService, ChartMetaService, chartConfig) {
var vm = this;
//loading from chart config file.
var libraryName = chartConfig.libraryName;
var files = chartConfig.dataFiles;
var chartTypes = chartConfig.chartTypes;
function renderChart(chart, datax) {
datax.row(chart.model).get(chart.get);
}
var data = {};
function loadData(fileName) {
setButtonActive('dataButton', fileName);
data = getData(fileName);
ChartMetaService.setChartDataSetName(fileName);
drawChart(data);
}
function loadChartLibrary(libraryIndex) {
setButtonActive('chartLibraryButton', libraryName[libraryIndex].library);
ChartMetaService.setChartLib(libraryName[libraryIndex].library);
ChartMetaService.setChartTemplateURL(libraryName[libraryIndex].template);
if (ChartMetaService.getChartType() === null) {
//setting default chart type
ChartMetaService.setChartType('Bar');
}
drawChart(data);
}
function getChartTemplateURL() {
return ChartMetaService.getChartTemplateURL();
}
function loadChartType(chartType) {
ChartMetaService.setChartType(chartType);
setButtonActive('chartTypeButton', chartType);
drawChart(data);
//To-Do CHart model will be completing for rendering the chart
}
//chart is generated from service, service is using HighChartfactory.HighCHart Factory is extended version of ChartFactory.
function drawChart(data) {
//Checking chart requirement is completed
var myNewChart = {};
var myChartType = ChartMetaService.getChartType();
console.log(myChartType);
switch (ChartMetaService.getChartLib()) {
case 'NVD3Chart':
//set data for NVD3
ChartService.updateData();
myNewChart = ChartService.getNVD3Chart(myChartType);
//only for nvd3 for fixing the bug
vm.data = myNewChart.viewModel.data;
vm.options = myNewChart.viewModel.options;
console.log('VM Level');
console.log(vm.data);
console.log(myNewChart.viewModel.data);
break;
case 'highChart':
myNewChart = ChartService.getHighChart(myChartType);
vm.chartConfig = myNewChart.viewModel;
break;
case 'googleChart':
//ChartService.updateGoogleData();
myNewChart = ChartService.getGoogleChart(myChartType);
vm.chart = myNewChart.viewModel;
console.log('VM Level');
console.log(vm.chart.data.rows);
break;
}
if (myNewChart.model) {
//renderChart(myNewChart.model, data);
}
//NVD3 axis update
}
function getData(fileName) {
return d3.csv('data/' + fileName + '.csv');
}
//default button picker
var active = {
'dataButton': false,
'chartLibraryButton': false,
'chartTypeButton': false
};
function setButtonActive(set, type) {
active[set] = type;
}
function isButtonActive(set, type) {
return active[set] === type;
}
function isButtonSelected(set) {
return active[set];
}
vm.loadData = loadData;
vm.isButtonActive = isButtonActive;
vm.isButtonSelected = isButtonSelected;
vm.loadChartLibrary = loadChartLibrary;
vm.loadChartType = loadChartType;
vm.files = files;
vm.libraryName = libraryName;
vm.chartTypes = chartTypes;
vm.getChartTemplateURL = getChartTemplateURL;
});