-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchart.js
More file actions
46 lines (44 loc) · 1.08 KB
/
chart.js
File metadata and controls
46 lines (44 loc) · 1.08 KB
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
define(['src/util/color'], function (Color) {
return {
getChart(x, y, options) {
options = options || {};
if (x.length !== y.length || y.length === 0) {
throw new Error('Invalid data length');
}
let chart = {
data: [],
axis: [
{
label: options.xLabel || '',
},
{
label: options.yLabel || '',
},
],
};
let species = Object.keys(y[0]);
let colors = Color.getDistinctColors(species.length);
for (var i = 0; i < species.length; i++) {
let data = {};
chart.data.push(data);
// eslint-disable-next-line no-loop-func
data.y = y.map((y) => {
return y[species[i]];
});
if (options.xLog) {
data.x = x.map((v) => -Math.log10(v));
} else {
data.x = x;
}
data.label = species[i];
data.xAxis = 0;
data.yAxis = 1;
data.defaultStyle = {
lineColor: colors[i],
lineWidth: 1,
};
}
return chart;
},
};
});