-
Notifications
You must be signed in to change notification settings - Fork 1
/
logviewer.chart.js
99 lines (82 loc) · 2.05 KB
/
logviewer.chart.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
function getLabels() {
var labels = [];
var selects = document.querySelectorAll('.seriesSelect')
var numSelects = selects.length
for (var i = 0; i < numSelects; i++) {
const selectedLabel = selects[i].value;
if (!!dataStore.dataSeries[selectedLabel]) {
labels.push(selectedLabel)
}
}
return labels;
}
function getDiffs(labels) {
var diffs = []
for (var i = 0; i < labels.length; i++) {
var label = labels[i]
var diff = dataStore.dataSeries.maxValues[label] - dataStore.dataSeries.minValues[label]
diffs.push(diff)
}
return diffs;
}
let g;
function resetChart() {
const labels = getLabels();
const series = {}
const diffs = getDiffs(labels)
const mindiff = Math.min.apply(Math, diffs)
const maxdiff = Math.max.apply(Math, diffs)
const logdiff = Math.log10(maxdiff) - Math.log10(mindiff)
if (logdiff >= 2) { //We need more axis
for (var i = 0; i < labels.length; i++) {
const label = labels[i]
series[label] = {}
if (dataStore.dataSeries.maxValues[label] > 1000) {
series[label]['axis'] = 'y1'
} else {
series[label]['axis'] = 'y2'
}
}
}
const times = dataStore.dataSeries[dataStore.dataSeries.XAxis]
const data = []
for (var i = 0; i < dataStore.dataSeries[labels[0]].length; i++) {
const row = [times[i]];
for (var j = 0; j < labels.length; j++) {
const labelIndex = labels[j];
if (!!dataStore.dataSeries[labelIndex]) {
row.push(dataStore.dataSeries[labelIndex][i]);
}
}
data.push(row)
}
labels.unshift(dataStore.dataSeries.XAxis)
const options = {
width: '100%',
showRangeSelector: true,
interactionModel: Dygraph.defaultInteractionModel,
labels: labels,
legend: 'follow',
series: series,
highlightCallback: updateMap,
axes: {
y: {
axisLabelWidth: 60
},
y2: {
// set axis-related properties here
labelsKMB: true
}
},
} // the options
if (g == null) {
console.log("Creating g");
g = new Dygraph(
document.getElementById("chart"), // containing div
data, options
);
} else {
console.log("Updating g");
g.updateOptions(options);
}
}