save date range in URL

main
xenofem 2022-04-16 02:49:35 -04:00
parent 4eeabbb770
commit 6b8c2062ef
1 changed files with 20 additions and 0 deletions

View File

@ -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')
.then(resp => resp.json())
.then(plot)
@ -239,10 +246,23 @@ function plot(data) {
options.scales.x.min = e.target.value;
northChart.update();
southChart.update();
updateHash();
});
document.getElementById('endDate').addEventListener('input', (e) => {
options.scales.x.max = e.target.value;
northChart.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 = "";
}
}