Skip to content

Commit cbe4d79

Browse files
authored
Merge pull request #4260 from yancat160/fix/chart-canvas-overflow-on-resize
fix: keep charts responsive when the viewport resizes
2 parents 5e773bd + 54e038f commit cbe4d79

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/components/charts/Chart.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,20 @@ export function Chart({
122122
return (
123123
<Column gap="6">
124124
<Box {...props}>
125-
<canvas ref={canvas} />
125+
{/*
126+
Position the canvas absolutely inside a relative-positioned
127+
wrapper. Chart.js writes inline pixel sizes onto the canvas, and
128+
while it lives in the normal flow that pixel width propagates up
129+
as min/max-content through every flex parent into the surrounding
130+
CSS Grid track, pinning the chart's column at its widest measured
131+
size and only resetting on a full page reload. Taking the canvas
132+
out of flow with position: absolute breaks that propagation; the
133+
wrapper sizes purely from its parent (width: 100%, height: 100%)
134+
and Chart.js' ResizeObserver picks up viewport changes.
135+
*/}
136+
<div style={{ position: 'relative', width: '100%', height: '100%', overflow: 'hidden' }}>
137+
<canvas ref={canvas} style={{ position: 'absolute', top: 0, left: 0 }} />
138+
</div>
126139
</Box>
127140
<Legend items={legendItems} onClick={handleLegendClick} />
128141
</Column>

0 commit comments

Comments
 (0)