-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartBuilderService.js
85 lines (82 loc) · 4.07 KB
/
chartBuilderService.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
class ChartBuilderService {
constructor() {}
static generateChart(type, containerId, dataset, options, additionalOptions = {}) {
return new Promise((resolve, reject) => {
setTimeout(() => {
let container = document.getElementById(containerId);
if (container) {
let Builder;
container.innerHTML = '';
switch (type) {
// D3Plus based
case 'MAP_TOPOJSON':
Builder = require('./d3plus/topoJsonChartBuilderService');
break;
case 'LINE':
Builder = require('./d3plus/lineChartBuilderService');
break;
case 'STACKED': // Unused
Builder = require('./d3plus/stackedLineChartBuilderService');
break;
case 'BAR':
Builder = require('./d3plus/barChartBuilderService');
break;
case 'TREEMAP':
Builder = require('./d3plus/treemapChartBuilderService');
break;
case 'SCATTERPLOT': // Unused
Builder = require('./d3plus/scatterChartBuilderService');
break;
case 'BOXPLOT': // Unused
Builder = require('./d3plus/boxplotChartBuilderService');
break;
// D3 based
case 'CALENDAR': // Unused
Builder = require('./d3/calendarChartBuilderService');
break;
case 'SANKEYD3': // Unused
Builder = require('./d3/sankeyChartBuilderService');
break;
// Leaflet based
case 'MAP_BUBBLES':
Builder = require('./leaflet/bubblesChartBuilderService');
break;
case 'MAP_CLUSTER':
Builder = require('./leaflet/clusterChartBuilderService');
break;
case 'MAP_HEAT':
Builder = require('./leaflet/heatChartBuilderService');
break;
case 'MAP_POLYGON': // Unused
Builder = require('./leaflet/polygonsChartBuilderService');
break;
case 'MAP_MIGRATION': // New - untested
Builder = require('./leaflet/migrationMapChartBuilderService');
break;
default:
break;
}
if (Builder) {
try {
let chart = (new Builder()).generateChart(containerId, dataset, options, additionalOptions);
resolve(chart);
} catch (err) {
reject(err);
}
} else {
reject("Falha ao gerar o gráfico")
}
}
}, 0);
})
}
static regenerateChart(chartHandler, type, containerId, dataset, options, additionalOptions = {}) {
if (['MAP_TOPOJSON', 'LINE', 'STACKED', 'BAR', 'TREEMAP', 'SCATTERPLOT', 'BOXPLOT', 'CALENDAR', 'SANKEYD3'].includes(type)) {
return ChartBuilderService.generateChart(type, containerId, dataset, options, additionalOptions);
} else if (['MAP_BUBBLES', 'MAP_CLUSTER', 'MAP_HEAT', 'MAP_POLYGON', 'MAP_MIGRATION'].includes(type)) {
chartHandler.removeChart();
return ChartBuilderService.generateChart(type, containerId, dataset, options, additionalOptions);
}
}
}
module.exports = ChartBuilderService