Skip to content
Source
Sign inSign up
TanStack/charts

`dodgeY` and `dodgeX` have no way to keep a swarm inside the plot when it does not fit #174

Closedquantizor(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: @tanstack/charts 1.0.0.

When enough rows share nearly the same value, the dodge layouts stack dots past the plot edge. Nothing bounds the offsets, so dots paint over whatever sits above the chart (the root <svg> is overflow:visible). With clip: true they are cut off at the plot edge instead, but the clipped dots stay keyboard and pointer targets, so focus can land on a dot nobody can see.

The offsets come from dodgeOffsets (dodge-internal.ts); dodgeY adds them to the anchor baseline (dodge.ts), and dot only checks that each position is finite. Nothing compares the laid-out extent with chart.height, and the dodge docs do not say what happens.

const rows = Array.from({ length: n }, (_, i) => ({ id: `r${i}`, v: 50 + (i % 7) * 0.2 })) // n large enough that the stack is taller than the plot
defineChart({
  marks: [dot(rows, { x: 'v', key: 'id', r: 4, layout: dodgeY({ anchor: 'bottom' }) })],
  scales: { x: { scale: scaleLinear().domain([0, 100]) }, y: null },
})
// scene.points[*].y runs far above scene.chart.y

The workaround today is a custom createDotLayout that re-implements the packer, since dodgeOffsets is not exported.

Would it be possible to add an opt-in policy for a swarm that does not fit, for example dodgeY({ fit: 'overflow' | 'compress' }), where 'compress' scales the offsets to the plot extent? Exporting the offset solver would also let applications bound it themselves, and a development warning when the extent passes the plot would help.

  1. Available in 1.1.0: both dodge layouts accept fit: 'compress'. It keeps the offsets inside the plot without shrinking the dots or changing the measured coordinate. Compression can overlap dots, and a dot wider than the available dimension throws rather than pretending it fits. The default is still overflow. Docs.

  2. tannerlinsley closed this

Sign in to join this conversation.