Smart resize of plot in mobile UI

This commit is contained in:
FliegendeWurst 2023-09-28 11:08:31 +02:00
parent 489d92cd9c
commit baa2f0eea4
2 changed files with 18 additions and 5 deletions

18
base.js
View File

@ -5,6 +5,8 @@ let dataY2 = [];
let dataY3 = []; let dataY3 = [];
let xMin = Number.MAX_SAFE_INTEGER; let xMin = Number.MAX_SAFE_INTEGER;
let xMax = 0; let xMax = 0;
let height = 600;
let isMobile = false;
function buttonsPlugin(opts) { function buttonsPlugin(opts) {
return { return {
@ -39,7 +41,7 @@ function buttonsPlugin(opts) {
function getSize() { function getSize() {
return { return {
width: document.getElementById("plot").clientWidth, width: document.getElementById("plot").clientWidth,
height: 600 height: height
}; };
} }
@ -154,15 +156,25 @@ function processCSV() {
// mobile view: activate 24h initially // mobile view: activate 24h initially
setTimeout(() => { setTimeout(() => {
const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
if (vh > vw) { if (vh > vw) {
document.getElementById("day").click(); document.getElementById("day").click();
height = vh / 2;
uplot.setSize(getSize());
isMobile = true;
} }
}, 500); }, 500);
// automatically resize plot // automatically resize plot
window.addEventListener("resize", e => { 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()); uplot.setSize(getSize());
}); });
} }

View File

@ -19,11 +19,12 @@ fn main() {
} }
// exclude outliers (> X °C diff and not between consecutive values) // exclude outliers (> X °C diff and not between consecutive values)
// remember, measurements are done once every 10 minutes // 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| { 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; 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 { 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; vars[1].3 = false;
} }