From baa2f0eea4ad30cba499b8e0ef371148348ec5ad Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 28 Sep 2023 11:08:31 +0200 Subject: [PATCH] Smart resize of plot in mobile UI --- base.js | 18 +++++++++++++++--- src/main.rs | 5 +++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/base.js b/base.js index aa21183..80a5f46 100644 --- a/base.js +++ b/base.js @@ -5,6 +5,8 @@ let dataY2 = []; let dataY3 = []; let xMin = Number.MAX_SAFE_INTEGER; let xMax = 0; +let height = 600; +let isMobile = false; function buttonsPlugin(opts) { return { @@ -39,7 +41,7 @@ function buttonsPlugin(opts) { function getSize() { return { width: document.getElementById("plot").clientWidth, - height: 600 + height: height }; } @@ -154,15 +156,25 @@ function processCSV() { // mobile view: activate 24h initially setTimeout(() => { - const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) - const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) + const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); + const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0); if (vh > vw) { document.getElementById("day").click(); + height = vh / 2; + uplot.setSize(getSize()); + isMobile = true; } }, 500); // automatically resize plot window.addEventListener("resize", e => { + const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); + const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) + if (isMobile && vw > vh) { + height = vh; + } else if (isMobile && vh > vw) { + height = vh / 2; + } uplot.setSize(getSize()); }); } diff --git a/src/main.rs b/src/main.rs index 1dea627..967344a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,11 +19,12 @@ fn main() { } // exclude outliers (> X °C diff and not between consecutive values) // remember, measurements are done once every 10 minutes - // it is unlikely the temp. will sway by 2.4 ° C in that timeframe + // it is unlikely the temp. will sway by 1.9 °C in that timeframe windows_mut_each(&mut values, 3, |vars| { - if vars[1].0 - vars[0].0 >= 5000000 { + if vars[1].0 - vars[0].0 >= 5000000 { // keep measurements after long gaps return; } + // spike up if vars[1].1.abs_diff(vars[0].1) >= 19 && vars[1].1 > vars[0].1 && vars[1].1 > vars[2].1 { vars[1].3 = false; }