-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreateChart.js
57 lines (43 loc) · 1.27 KB
/
createChart.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
import chart from './chart/index';
import { select } from 'd3';
export var chartCount = 0;
export default function createChart(element = 'body', config = {}, controls = null) {
let thisChart = Object.create(chart);
thisChart.div = element;
thisChart.config = Object.create(config);
thisChart.controls = controls;
thisChart.raw_data = [];
thisChart.filters = [];
thisChart.marks = [];
thisChart.wrap = select(thisChart.div).append('div').datum(thisChart);
thisChart.events = {
onInit() {},
onLayout() {},
onPreprocess() {},
onDatatransform() {},
onDraw() {},
onResize() {},
onDestroy() {}
};
thisChart.on = function(event, callback) {
let possible_events = [
'init',
'layout',
'preprocess',
'datatransform',
'draw',
'resize',
'destroy'
];
if (possible_events.indexOf(event) < 0) {
return;
}
if (callback) {
thisChart.events['on' + event.charAt(0).toUpperCase() + event.slice(1)] = callback;
}
};
//increment thisChart count to get unique thisChart id
chartCount++;
thisChart.id = chartCount;
return thisChart;
}