From 489d92cd9c5ad832bc6f62ab8e4e68ea54ffd562 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 27 Sep 2023 11:44:25 +0200 Subject: [PATCH] Automatically resize plot --- base.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/base.js b/base.js index 00c8373..aa21183 100644 --- a/base.js +++ b/base.js @@ -36,14 +36,20 @@ function buttonsPlugin(opts) { }; } +function getSize() { + return { + width: document.getElementById("plot").clientWidth, + height: 600 + }; +} + function processCSV() { let plotData = [dataX, dataY, dataY2]; let opts = { title: "Temperature and humidity stats", id: "chart1", class: "my-chart", - width: document.getElementById("plot").clientWidth, - height: 600, + ...getSize(), plugins: [ buttonsPlugin({}) ], @@ -154,6 +160,11 @@ function processCSV() { document.getElementById("day").click(); } }, 500); + + // automatically resize plot + window.addEventListener("resize", e => { + uplot.setSize(getSize()); + }); } Papa.parse('./x.csv', { delimiter: ",",