-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeplot.js
169 lines (143 loc) · 3.5 KB
/
makeplot.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'plotedit.json', false);
httpRequest.send();
var plotVars = JSON.parse(httpRequest.responseText).plotVars;
//console.log(plotVars);
var pltColors = [];
for (var i in window.chartColors) { pltColors.push(window.chartColors[i]); }
var foo = [
window.chartColors.blue,
window.chartColors.green,
window.chartColors.red,
window.chartColors.yellow
];
var config = {};
var axisOpts = [];
var axisids = [];
var plotYaxes = [];
var sideKey = {"R": "right", "L": "left"};
plot_it = function() {
var xdata = [];
var ydata = [];
var k = -1; // for indexing color
var curAxisOption = 'L1';
var curYaxis = {};
var defYaxis = {
position: "left",
//id: curAxisOption
};
var rightAxis = {
position: "right",
id: "R1",
ticks: {
fontColor: window.chartColors.red, // this here
stepSize: 1,
display: false
},
gridLines: {
display: false,
}
};
for (var v in plotVars) {
// There is only one X axis
if (plotVars[v].Axis === "x") {
xdata = data[v];
var plotXaxes = [{
display: true,
scaleLabel: {
display: true,
labelString: plotVars[v].Label
}
}];
}
// Y axes
else {
k += 1;
if (k >= pltColors.length) { k = 0; }
var yaxid = plotVars[v].Options;
console.log(yaxid);
//var new_data = {};
if (plotVars[v].isBool) {
var new_data = {
data: data[v],
type: "line",
label: plotVars[v].Label,
fill: 'origin',
borderColor: pltColors[k],
backgroundColor: pltColors[k].replace(')', ', 0.2)').replace('rgb', 'rgba'),
lineTension: 0,
yAxisID: yaxid
}
cur_id = yaxid;
cur_ticks = {
"min": 0,
"max": 1,
fontColor: pltColors[k],
stepSize: 1,
display: true
};
cur_gridlines = {display: false };
}
else {
var new_data = {
type: "line",
label: plotVars[v].Label,
fill: false,
data: data[v],
borderColor: pltColors[k],
backgroundColor: pltColors[k],
lineTension: 0,
yAxisID: yaxid,
}
cur_id = yaxid;
cur_ticks = { fontColor: pltColors[k] };
cur_gridlines = { display: true };
//curYaxis.id = yaxid;
console.log(curYaxis);
}
curYaxis = {
id: cur_id,
position: sideKey[plotVars[v].Options[0]],
ticks: cur_ticks,
gridLines: cur_gridlines
}
if (axisids.indexOf(yaxid) < 0) {
axisids.push(yaxid);
plotYaxes.push(curYaxis);
}
ydata.push(new_data);
}
}
config = {
data: {
labels: xdata,
datasets: ydata
},
options: {
responsive: true,
animation : false,
title: {
display: true,
text: getfile
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: plotXaxes,
yAxes: plotYaxes
}
}
};
if (axisids.length === 1) {
config.options.scales.yAxes[0].ticks.fontColor = "rgb(51,51,51)";
console.log("gray axis");
}
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};