diff --git a/static/app.js b/static/app.js index 6b854ce..70c519f 100644 --- a/static/app.js +++ b/static/app.js @@ -1101,3 +1101,37 @@ document.addEventListener('DOMContentLoaded', () => { fetchEngineConfig(); setInterval(fetchEngineConfig, 120000); }); + + +// ---------------------------------------------------------------- chart sizing + +// Chart.js is configured responsive with maintainAspectRatio:false, so it should track +// its container on its own. In practice it latched onto a stale size -- the canvas sat +// at width:0px, height:288px (the old fixed h-64) while its container had grown to +// 988x648 on a large window. An explicit observer makes the chart follow the container +// whatever the window does. +function watchChartSize() { + const canvas = document.getElementById('oc-chart'); + if (!canvas || !canvas.parentElement) return; + const container = canvas.parentElement; + + const resize = () => { + if (typeof ocChart === 'undefined' || !ocChart) return; + // No explicit dimensions: with responsive + maintainAspectRatio:false, Chart.js + // measures the container itself. Passing width/height instead made the canvas grow + // but never shrink -- it ended up 988px wide inside a 435px container, overflowing + // it, which is also why the canvas is absolutely positioned now. + ocChart.resize(); + }; + + if (typeof ResizeObserver !== 'undefined') { + new ResizeObserver(resize).observe(container); + } + window.addEventListener('resize', resize); + // Run once after layout settles, in case the chart was built before the container had + // a width (which is how it ended up at 0 in the first place). + requestAnimationFrame(resize); + setTimeout(resize, 300); +} + +document.addEventListener('DOMContentLoaded', () => setTimeout(watchChartSize, 200)); diff --git a/static/index.html b/static/index.html index c639e56..07391c8 100644 --- a/static/index.html +++ b/static/index.html @@ -5,6 +5,11 @@