From 6b8c2062ef2f76f77e373e0264b4d3c5e9ded316 Mon Sep 17 00:00:00 2001 From: xenofem Date: Sat, 16 Apr 2022 02:49:35 -0400 Subject: [PATCH] save date range in URL --- static/poopGraph.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/static/poopGraph.js b/static/poopGraph.js index dac4192..eeb0c62 100644 --- a/static/poopGraph.js +++ b/static/poopGraph.js @@ -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 = ""; + } +}