From d9992e46d10c02e7e398d75bfdf3ba6cf51210a5 Mon Sep 17 00:00:00 2001 From: "ahmed.mujtaba" Date: Tue, 25 Aug 2026 12:54:04 +0500 Subject: [PATCH] correct the error --- .gitignore | 4 +++- frontend/src/lib/charts.js | 12 +++++++++++- frontend/src/ui/Chart.jsx | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 274ae0d..d189398 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,6 @@ tests/** # Root-anchored: backend/candidate_forms/ is the forms domain package and IS tracked. /candidate_forms/ frontend/dist/** */ -docker.local.frontend/dist/** */ \ No newline at end of file +docker.local.frontend/dist/** */ +frontend/dist/index.html +frontend/dist/index.html diff --git a/frontend/src/lib/charts.js b/frontend/src/lib/charts.js index f86617a..08f73d8 100644 --- a/frontend/src/lib/charts.js +++ b/frontend/src/lib/charts.js @@ -48,7 +48,17 @@ function css(name) { return getComputedStyle(document.documentElement).getProper const dpr = window.devicePixelRatio || 1; const rect = canvas.getBoundingClientRect(); const w = rect.width || canvas.clientWidth || 600; - const h = parseInt(canvas.getAttribute('height')) || 260; + // The LOGICAL height, remembered on first setup. Reading the `height` + // attribute here instead would read back the DEVICE-pixel value written + // below (h * dpr): with dpr > 1 every redraw multiplied the canvas by dpr, + // and the ResizeObserver on the auto-height .chart-wrap fed each growth + // straight back in — canvases reached millions of px tall and the chart + // became an invisible speck at the top of a giant blank canvas. + let h = Number(canvas.dataset.baseHeight); + if (!h) { + h = parseInt(canvas.getAttribute('height')) || 260; + canvas.dataset.baseHeight = String(h); + } canvas.width = w * dpr; canvas.height = h * dpr; canvas.style.height = h + 'px'; const ctx = canvas.getContext('2d'); diff --git a/frontend/src/ui/Chart.jsx b/frontend/src/ui/Chart.jsx index 2d6d55f..e96f608 100644 --- a/frontend/src/ui/Chart.jsx +++ b/frontend/src/ui/Chart.jsx @@ -29,6 +29,11 @@ export default function Chart({ type, data, options, height = 260, className = ' const canvas = ref.current if (!canvas || typeof Charts[type] !== 'function') return undefined + // setup() caches the logical height on first draw (dataset.baseHeight) so a + // redraw never reads back the device-pixel height it wrote. Clear it here so + // a changed `height` prop is picked up rather than the stale cached value. + delete canvas.dataset.baseHeight + const draw = () => { if (canvas.isConnected && canvas.getBoundingClientRect().width > 0) { Charts[type](canvas, data, options)