-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
executable file
·129 lines (126 loc) · 4.45 KB
/
script.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
window.onload = function(){
var arrayOfObjects;
var removedObjects = [];
let options = { //set plot options
series: {
points: {show: true},
lines: {show: true}
},
xaxis: {
show: true,
},
yaxes: [{position: "left"}],
legend: {
show: true,
container: $("#legend")
},
grid: {
clickable: true,
hoverable: true
}
};
arrayOfObjects = [];
keys = [];
for (let aKey in collectedData) {
keys.push(aKey);
}
sorted_keys = keys.sort();
for (let index in sorted_keys) {
let series = sorted_keys[index];
arrayOfObjects.push({data:collectedData[series], label: series, yaxis: 1});
}
// plot measurements
$.plot($("#placeholder"),arrayOfObjects,options);
$("#placeholder").bind("plothover", function(event, pos, item) {
if (item) {
$("#rawData")[0].innerHTML = item.datapoint[1] + "<br>" + arrayOfObjects[item.seriesIndex].label;
}});
$("#placeholder").bind("plotclick", function(event, pos, item) {
if (item == null) return;
removedObjects.push(arrayOfObjects.splice(item.seriesIndex,1)[0]);
$.plot($("#placeholder"),arrayOfObjects,options);
let insertionPoint = document.querySelector("#removedLines");
let box = document.createElement("input");
box.setAttribute("type", "checkbox");
box.setAttribute("value", item.series.label);
box.setAttribute("name", item.series.label);
box.innerHTML = item.series.label;
box.onclick = function(event) {
for (let seriesIndex = 0; seriesIndex < removedObjects.length; seriesIndex++) {
if (this.getAttribute("name") === removedObjects[seriesIndex].label) {
arrayOfObjects.push(removedObjects[seriesIndex]);
removedObjects.splice(seriesIndex,1);
$.plot($("#placeholder"),arrayOfObjects,options);
this.nextSibling.remove(); // remove label
this.remove(); // remove checkbox
if (removedObjects.length == 0) {
insertionPoint.removeAttribute("style");
}
break;
}
}
};
let label = document.createElement("label");
label.innerHTML = item.series.label;
insertionPoint.appendChild(box);
insertionPoint.appendChild(label);
insertionPoint.setAttribute("style", "display:block;");
});
// Create list of series
let insertionPoint = document.querySelector("#ownAxis");
let checkedBoxes = 0;
for (let seriesIndex = 0; seriesIndex < arrayOfObjects.length; seriesIndex++) {
let series = arrayOfObjects[seriesIndex];
let box = document.createElement("input");
box.setAttribute("type", "checkbox");
box.setAttribute("value", series.label);
box.setAttribute("name", series.label);
box.innerHTML = series.label;
box.onclick = function(event) {
let found = false;
for (let seriesIndex = 0; seriesIndex < arrayOfObjects.length; seriesIndex++) {
if (this.getAttribute("name") === arrayOfObjects[seriesIndex].label) {
if (arrayOfObjects[seriesIndex].yaxis === 1) {
checkedBoxes++;
if (options.yaxes.length < checkedBoxes + 1) {
options.yaxes.push({position: "right"});
}
arrayOfObjects[seriesIndex].yaxis = checkedBoxes + 1;
} else {
arrayOfObjects[seriesIndex].yaxis = 1;
checkedBoxes--;
}
$.plot($("#placeholder"),arrayOfObjects,options);
found = true;
break;
}
}
if (!found) {
for (let seriesIndex = 0; seriesIndex < removedObjects.length; seriesIndex++) {
if (this.getAttribute("name") === removedObjects[seriesIndex].label) {
if (removedObjects[seriesIndex].yaxis === 1) {
checkedBoxes++;
if (options.yaxes.length < checkedBoxes + 1) {
options.yaxes.push({position: "right"});
}
removedObjects[seriesIndex].yaxis = checkedBoxes + 1;
} else {
removedObjects[seriesIndex].yaxis = 1;
checkedBoxes--;
}
found = true;
break;
}
}
}
console.log("processing " + this.getAttribute("name") + ", checkedBoxes: " + checkedBoxes);
if (!found) {
console.log("logic error - element reference not found");
}
};
let label = document.createElement("label");
label.innerHTML = series.label;
insertionPoint.appendChild(box);
insertionPoint.appendChild(label);
}
};