save date range in URL
This commit is contained in:
parent
4eeabbb770
commit
6b8c2062ef
|
@ -1,3 +1,10 @@
|
||||||
|
const hash = window.location.hash.substring(1);
|
||||||
|
if (hash !== "") {
|
||||||
|
const [start, end] = hash.split(":");
|
||||||
|
document.getElementById('startDate').value = start;
|
||||||
|
document.getElementById('endDate').value = end;
|
||||||
|
}
|
||||||
|
|
||||||
fetch('/data.json')
|
fetch('/data.json')
|
||||||
.then(resp => resp.json())
|
.then(resp => resp.json())
|
||||||
.then(plot)
|
.then(plot)
|
||||||
|
@ -239,10 +246,23 @@ function plot(data) {
|
||||||
options.scales.x.min = e.target.value;
|
options.scales.x.min = e.target.value;
|
||||||
northChart.update();
|
northChart.update();
|
||||||
southChart.update();
|
southChart.update();
|
||||||
|
updateHash();
|
||||||
});
|
});
|
||||||
document.getElementById('endDate').addEventListener('input', (e) => {
|
document.getElementById('endDate').addEventListener('input', (e) => {
|
||||||
options.scales.x.max = e.target.value;
|
options.scales.x.max = e.target.value;
|
||||||
northChart.update();
|
northChart.update();
|
||||||
southChart.update();
|
southChart.update();
|
||||||
|
updateHash();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateHash() {
|
||||||
|
console.log("updating hash");
|
||||||
|
const start = document.getElementById('startDate').value;
|
||||||
|
const end = document.getElementById('endDate').value;
|
||||||
|
if (start !== "" || end !== "") {
|
||||||
|
window.location.hash = start + ":" + end;
|
||||||
|
} else {
|
||||||
|
window.location.hash = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue