Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/presentation-subscriber-reentry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/charts': patch
---

Keep presentation subscribers and animation completion on the newest scene when a subscriber renders another scene.
4 changes: 2 additions & 2 deletions benchmarks/comparison/bundle-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"sources": {
"tanstack": {
"kind": "workspace",
"revision": "c6f214c5ec07e6795948373d9f1180620e7c7201",
"inputDigest": "sha256:b5b15f9b76251512fbd07e610230c361e8f26d4c2c1ee465d58bddaf7cca061d"
"revision": "92e0801c28415cbedd85f677d29598f90fb0fd31",
"inputDigest": "sha256:f10c7eef40f5970f90b33c27d99555ac9290300a0b570ffda61403f2372f7f61"
},
"chartjs": {
"kind": "package",
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/conformance/previews/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"width": 288,
"height": 192,
"sourceHash": "0a9bce517636862b84f408fe6efd422af1785018a4f7da10a1fd53964ee5ee2e",
"sourceHash": "4d24007b5db8817671c815c5351fba8d43d33716a9415f4c11e71021d9ed9510",
"assets": [
{
"id": "01-line-gaps",
Expand Down
4 changes: 2 additions & 2 deletions docs/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ turning untested behavior into a checkmark.

| Library | Package | Measured source |
| -------------------------------------------------------------------------------------- | -------------------- | ------------------- |
| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `c6f214c` |
| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `92e0801` |
| [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` |
| [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` |
| [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` |
| [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` |

The competitor versions are exact package pins, not latest versions inferred
at page render time. The measured TanStack workspace revision is `c6f214c`.
at page render time. The measured TanStack workspace revision is `92e0801`.

## Capability matrix

Expand Down
4 changes: 2 additions & 2 deletions packages/charts-core/docs/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ turning untested behavior into a checkmark.

| Library | Package | Measured source |
| -------------------------------------------------------------------------------------- | -------------------- | ------------------- |
| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `c6f214c` |
| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `92e0801` |
| [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` |
| [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` |
| [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` |
| [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` |

The competitor versions are exact package pins, not latest versions inferred
at page render time. The measured TanStack workspace revision is `c6f214c`.
at page render time. The measured TanStack workspace revision is `92e0801`.

## Capability matrix

Expand Down
126 changes: 126 additions & 0 deletions packages/charts-core/src/motion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,132 @@ const rows = [
{ id: 'b', category: 'B', value: 80 },
]

describe('presentation subscriber re-entry', () => {
it('defers notifications while a motion callback nests a render', () => {
const frames = installManagedFrames()
const container = document.createElement('div')
const surface = motion<{ x: number; y: number }>({ initial: false }).mount(
container,
() => {},
)
let armed = false
let insideCallback = false
const observedInside: boolean[] = []
const makeScene = (value: number) =>
createChartScene(
defineChart({
marks: [
dot([{ x: 1, y: value }], {
x: 'x',
y: 'y',
motion: () => {
if (armed) {
armed = false
insideCallback = true
surface.render(makeScene(3), { ariaLabel: 'three' })
insideCallback = false
}
return { transition: { type: 'tween', duration: 100 } }
},
}),
],
scales: {
x: { scale: scaleLinear().domain([0, 2]) },
y: { scale: scaleLinear().domain([0, 4]) },
},
guides: false,
}),
{ width: 400, height: 200 },
)
try {
surface.render(makeScene(1), { ariaLabel: 'one' })
surface.subscribePresentationPoints?.(() =>
observedInside.push(insideCallback),
)
armed = true
surface.render(makeScene(2), { ariaLabel: 'two' })
expect(observedInside).not.toContain(true)
} finally {
surface.destroy()
frames.restore()
}
})
it.each(['snap', 'initial', 'mid', 'finish', 'cancel'])(
'keeps the newest render after %s notification re-entry',
(phase) => {
const frames = installManagedFrames()
const makeScene = (revision: number) =>
createChartScene(
defineChart({
marks: [dot([{ x: 1, y: revision, revision }], { x: 'x', y: 'y' })],
scales: {
x: { scale: scaleLinear().domain([0, 2]) },
y: { scale: scaleLinear().domain([0, 4]) },
},
guides: false,
}),
{ width: 400, height: 200 },
)
const container = document.createElement('div')
const surface = motion<{ x: number; y: number; revision: number }>({
initial: false,
transition: {
type: 'tween',
duration: phase === 'snap' ? 0 : 100,
easing: 'linear',
},
}).mount(container, () => {})
const third = makeScene(3)
let armed = phase === 'snap' || phase === 'initial'
let reentered = false
const observations: number[] = []
try {
surface.render(makeScene(1), { ariaLabel: 'one' })
surface.subscribePresentationPoints?.((points) => {
if (armed && !reentered && points[0]?.datum.revision === 2) {
reentered = true
surface.render(third, { ariaLabel: 'three' })
}
})
surface.subscribePresentationPoints?.((points) => {
observations.push(points[0]!.datum.revision)
})
surface.render(makeScene(2), { ariaLabel: 'two' })
if (phase === 'cancel') {
armed = true
surface.render(makeScene(4), { ariaLabel: 'four' })
}
if (phase !== 'snap') {
frames.run(0)
if (phase === 'mid') armed = true
frames.run(50)
armed = true
frames.run(100)
if (frames.pending()) frames.run(200)
if (frames.pending()) frames.run(400)
}
const expected = phase === 'cancel' ? 4 : 3
expect(reentered).toBe(phase !== 'cancel')
expect(observations).toContain(expected)
expect(
observations.slice(observations.indexOf(expected)),
).not.toContain(2)
expect(container.querySelector('svg')?.getAttribute('aria-label')).toBe(
phase === 'cancel' ? 'four' : 'three',
)
expect(surface.getPresentationPoints?.()).toBeUndefined()
expect(
Number(container.querySelector('circle')?.getAttribute('cy')),
).toBeCloseTo(makeScene(expected).points[0]!.y)
} finally {
surface.destroy()
expect(frames.pending()).toBe(0)
frames.restore()
}
},
)
})

describe('motion resize policy', () => {
it.each([false, true])(
'handles a resize during entrance with resize: %s',
Expand Down
Loading