correct the error
parent
347856e8f8
commit
d9992e46d1
|
|
@ -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/** */
|
||||
docker.local.frontend/dist/** */
|
||||
frontend/dist/index.html
|
||||
frontend/dist/index.html
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue