-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnvd3-chart-factory.js
106 lines (100 loc) · 2.46 KB
/
nvd3-chart-factory.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
'use strict';
/**
* @ngdoc function
* @name apacheZeppelinGsocApp.NVD3ChartFactory
* @description
* # Extending Gobal Chart Factory for NVD3 Chart Model
*
*/
angular.module('apacheZeppelinGsocApp').factory('NVD3ChartFactory', function(ChartMetaService, ChartFactory) {
var ChartList = {
'Bar': 'discreteBarChart',
'Line': 'lineChart'
};
//NVD3 Chart model
var NVD3ChartChartModel = {
options: {
chart: {
type: 'discreteBarChart',
height: 300,
width: 500,
showLegend: true,
margin: {
top: 20,
right: 20,
bottom: 20,
left: 20
},
x: function(d) {
return d.valuex;
},
y: function(d) {
return d.value;
},
showValues: true,
transitionDuration: 500,
xAxis: {
axisLabel: 'X Axis'
},
yAxis: {
axisLabel: 'Y Axis',
axisLabelDistance: 10
}
}
},
data: []
};
function getNVD3(error, rows) {
var data = {
'values': rows
};
NVD3ChartChartModel.data[0] = data;
console.log(NVD3ChartChartModel.data);
}
function nvd3Model(d) {
return {
label: d.Make,
value: +d.Length,
valuex: +d.No
};
}
function setChartTypeView(chartType) {
NVD3ChartFactory.viewModel.options.chart.type = ChartList[chartType];
}
var NVD3Chart = {
model: nvd3Model,
get: getNVD3
};
//nvd3 chart
var NVD3ChartFactory = new ChartFactory('NVD3Chart', NVD3Chart);
NVD3ChartFactory.viewModel = NVD3ChartChartModel;
NVD3ChartFactory.setChartType = function(chartType) {
NVD3ChartFactory.type = chartType;
setChartTypeView(chartType);
};
NVD3ChartFactory.setChartAxis = function(data) {
loadYAxisLabel(data);
};
NVD3ChartFactory.dataTransform = function() {
ChartMetaService.getChartData().row(NVD3Chart.model).get(NVD3Chart.get);
};
// define a new internal private method for this chart object
var nvd3AxisLabels = {};
function getNVD3Yaxis(error, rows) {
console.log(rows);
nvd3AxisLabels = rows;
NVD3ChartFactory.viewModel.options.chart.xAxis = {
'axisLabel': 'Make',
'tickFormat': function(d) {
return nvd3AxisLabels[d];
}
};
}
function nvd3YaxisModel(d) {
return d.Make;
}
function loadYAxisLabel(fileName) {
nvd3AxisLabels = d3.csv(fileName).row(nvd3YaxisModel).get(getNVD3Yaxis);
}
return NVD3ChartFactory;
});