Skip to content

Commit 866434e

Browse files
committed
update vega-lite spec
1 parent 7b2826d commit 866434e

File tree

1 file changed

+74
-48
lines changed

1 file changed

+74
-48
lines changed

resources/report/dashboard/script.js

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
// Tab switching
22
document.querySelectorAll(".tab-link").forEach(button => {
3-
button.addEventListener("click", () => {
4-
document.querySelectorAll(".tab-link").forEach(btn => btn.classList.remove("active"));
5-
document.querySelectorAll(".tab-content").forEach(tab => tab.classList.remove("active"));
6-
button.classList.add("active");
7-
document.getElementById(button.dataset.tab).classList.add("active");
8-
});
3+
button.addEventListener("click", () => {
4+
document.querySelectorAll(".tab-link").forEach(btn => btn.classList.remove("active"));
5+
document.querySelectorAll(".tab-content").forEach(tab => tab.classList.remove("active"));
6+
button.classList.add("active");
7+
document.getElementById(button.dataset.tab).classList.add("active");
8+
});
99
});
1010

1111

1212
// Initialize selection widgets
1313
const choicesInstances = {};
1414

1515
choicesInstances["source-select"] = new Choices("#source-select", {
16-
searchEnabled: false,
17-
removeItemButton: true,
18-
shouldSort: false,
19-
itemSelectText: "",
20-
placeholder: false
16+
searchEnabled: false,
17+
removeItemButton: true,
18+
shouldSort: false,
19+
itemSelectText: "",
20+
placeholder: false
2121
});
2222
document.getElementById("source-select").addEventListener("change", updateChart);
2323

2424
choicesInstances["metric-select"] = new Choices("#metric-select", {
25-
searchEnabled: false,
26-
removeItemButton: true,
27-
shouldSort: false,
28-
itemSelectText: "",
29-
placeholder: false
25+
searchEnabled: false,
26+
removeItemButton: true,
27+
shouldSort: false,
28+
itemSelectText: "",
29+
placeholder: false
3030
});
3131
document.getElementById("metric-select").addEventListener("change", updateChart);
3232

3333
choicesInstances["param-select"] = new Choices("#param-select", {
34-
searchEnabled: false,
35-
removeItemButton: true,
36-
shouldSort: false,
37-
itemSelectText: "",
38-
placeholder: false
34+
searchEnabled: false,
35+
removeItemButton: true,
36+
shouldSort: false,
37+
itemSelectText: "",
38+
placeholder: false
3939
});
4040
document.getElementById("param-select").addEventListener("change", updateChart);
4141

@@ -44,25 +44,51 @@ data = JSON.parse(document.getElementById("verif-data").textContent)
4444

4545
// Define base spec
4646
var spec = {
47-
"data": {
48-
"values": data
49-
},
47+
"data": { "values": data },
48+
"params": [
49+
{
50+
"name": "xZoom",
51+
"select": {
52+
"type": "interval",
53+
"encodings": ["x"],
54+
"zoom": "wheel![!event.shiftKey]"
55+
},
56+
"bind": "scales"
57+
}
58+
],
5059
"facet": {
5160
"column": { "field": "param" },
5261
"row": { "field": "metric" }
5362
},
5463
"spec": {
55-
"mark": { "type": "line" },
64+
"mark": "line",
5665
"width": 300,
5766
"height": 200,
5867
"encoding": {
59-
"x": { "field": "lead_time", "type": "ordinal" },
60-
"y": { "field": "value", "type": "quantitative" , "scale": { "zero": false }},
61-
"color": { "field": "source", "legend": { "orient": "top", "labelLimit": 1000, "symbolSize": 1000 } }
62-
}
68+
"x": {
69+
"field": "lead_time",
70+
"type": "quantitative",
71+
"axis": { "labels": true, "ticks": true },
72+
},
73+
"y": {
74+
"field": "value",
75+
"type": "quantitative",
76+
"scale": { "zero": false }
77+
},
78+
"color": {
79+
"field": "source",
80+
"legend": { "orient": "top", "labelLimit": 1000, "symbolSize": 1000 }
81+
}
82+
},
83+
"transform": [
84+
{
85+
"filter": { "param": "xZoom" }
86+
}
87+
]
6388
},
6489
"resolve": {
6590
"scale": {
91+
"x": "shared",
6692
"y": "independent"
6793
}
6894
}
@@ -72,32 +98,32 @@ var spec = {
7298
// Define functions
7399

74100
function getSelectedValues(id) {
75-
return choicesInstances[id].getValue(true)
101+
return choicesInstances[id].getValue(true)
76102
}
77103

78104
function updateChart() {
79-
const selectedSources = getSelectedValues("source-select");
80-
const selectedparams = getSelectedValues("param-select");
81-
const selectedMetrics = getSelectedValues("metric-select");
105+
const selectedSources = getSelectedValues("source-select");
106+
const selectedparams = getSelectedValues("param-select");
107+
const selectedMetrics = getSelectedValues("metric-select");
82108

83-
const newSpec = JSON.parse(JSON.stringify(spec));
84-
const filters = [];
109+
const newSpec = JSON.parse(JSON.stringify(spec));
110+
const filters = [];
85111

86-
if (selectedSources.length > 0) {
87-
filters.push({ field: "source", oneOf: selectedSources });
88-
}
89-
if (selectedparams.length > 0) {
90-
filters.push({ field: "param", oneOf: selectedparams });
91-
}
92-
if (selectedMetrics.length > 0) {
93-
filters.push({ field: "metric", oneOf: selectedMetrics });
94-
}
112+
if (selectedSources.length > 0) {
113+
filters.push({ field: "source", oneOf: selectedSources });
114+
}
115+
if (selectedparams.length > 0) {
116+
filters.push({ field: "param", oneOf: selectedparams });
117+
}
118+
if (selectedMetrics.length > 0) {
119+
filters.push({ field: "metric", oneOf: selectedMetrics });
120+
}
95121

96-
if (filters.length > 0) {
97-
newSpec.transform = [{ filter: { and: filters } }];
98-
}
122+
if (filters.length > 0) {
123+
newSpec.transform = [{ filter: { and: filters } }];
124+
}
99125

100-
vegaEmbed('#vis', newSpec, { actions: false });
126+
vegaEmbed('#vis', newSpec, { actions: false });
101127
}
102128

103129
// Initial chart

0 commit comments

Comments
 (0)