@opendata-ai/openchart-vanilla 8.0.0-rc.8 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-W34KN7FD.js → chunk-2NAQRP66.js} +2 -2
- package/dist/{chunk-UZ7J3NOF.js → chunk-6BUCYCLD.js} +7314 -5605
- package/dist/chunk-6BUCYCLD.js.map +1 -0
- package/dist/chunk-DCODCLWI.js +234 -0
- package/dist/chunk-DCODCLWI.js.map +1 -0
- package/dist/{chunk-5EOV5JQZ.js → chunk-EKAUQAAX.js} +50 -46
- package/dist/chunk-EKAUQAAX.js.map +1 -0
- package/dist/chunk-RM5XS6NR.js +113 -0
- package/dist/chunk-RM5XS6NR.js.map +1 -0
- package/dist/chunk-T32UHMZA.js +282 -0
- package/dist/chunk-T32UHMZA.js.map +1 -0
- package/dist/export-gif.d.ts +113 -0
- package/dist/export-gif.js +21 -0
- package/dist/export-gif.js.map +1 -0
- package/dist/index.d.ts +309 -27
- package/dist/index.js +2020 -836
- package/dist/index.js.map +1 -1
- package/dist/{mount-CUKQLeqD.d.ts → mount-CL-nA0f-.d.ts} +85 -2
- package/dist/simulation-worker.js +83 -2
- package/dist/static.d.ts +2 -0
- package/dist/static.js +8 -69
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +25 -9
- package/dist/story/index.js +9 -7
- package/dist/story/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +14 -6
- package/dist/chunk-5EOV5JQZ.js.map +0 -1
- package/dist/chunk-UZ7J3NOF.js.map +0 -1
- package/src/__test-fixtures__/dom.ts +0 -70
- package/src/__test-fixtures__/specs.ts +0 -214
- package/src/__tests__/animation.test.ts +0 -358
- package/src/__tests__/annotations-render.test.ts +0 -201
- package/src/__tests__/compound-labels.test.ts +0 -122
- package/src/__tests__/continuous-legend.test.ts +0 -91
- package/src/__tests__/crosshair.test.ts +0 -130
- package/src/__tests__/edit-events.test.ts +0 -950
- package/src/__tests__/events.test.ts +0 -387
- package/src/__tests__/export.test.ts +0 -241
- package/src/__tests__/font-race.test.ts +0 -199
- package/src/__tests__/gradient-ids.test.ts +0 -159
- package/src/__tests__/gradient-utils.test.ts +0 -125
- package/src/__tests__/known-bugs-render.test.ts +0 -183
- package/src/__tests__/map.test.ts +0 -636
- package/src/__tests__/mount.test.ts +0 -357
- package/src/__tests__/pattern-fills.test.ts +0 -105
- package/src/__tests__/resize-timing.test.ts +0 -218
- package/src/__tests__/sankey.test.ts +0 -133
- package/src/__tests__/selection-events.test.ts +0 -869
- package/src/__tests__/series-search.test.ts +0 -311
- package/src/__tests__/static.test.ts +0 -141
- package/src/__tests__/svg-renderer.test.ts +0 -895
- package/src/__tests__/table-keyboard.test.ts +0 -361
- package/src/__tests__/table-mount.test.ts +0 -639
- package/src/__tests__/tilemap.test.ts +0 -158
- package/src/__tests__/tooltip.test.ts +0 -337
- package/src/__tests__/transition.test.ts +0 -1792
- package/src/__tests__/update-scrolly-matrix.test.ts +0 -563
- package/src/__tests__/you-draw-it.test.ts +0 -273
- package/src/animation-vars.ts +0 -42
- package/src/animation.ts +0 -76
- package/src/barlist-mount.ts +0 -383
- package/src/barlist-renderer.ts +0 -267
- package/src/dom-helpers.ts +0 -17
- package/src/export.ts +0 -482
- package/src/gradient-utils.ts +0 -138
- package/src/graph/__tests__/canvas-renderer.test.ts +0 -713
- package/src/graph/__tests__/graph-mount.test.ts +0 -213
- package/src/graph/__tests__/interaction.test.ts +0 -205
- package/src/graph/__tests__/keyboard.test.ts +0 -653
- package/src/graph/__tests__/search.test.ts +0 -88
- package/src/graph/__tests__/simulation.test.ts +0 -233
- package/src/graph/__tests__/spatial-index.test.ts +0 -142
- package/src/graph/__tests__/zoom.test.ts +0 -203
- package/src/graph/canvas-renderer.ts +0 -747
- package/src/graph/interaction.ts +0 -367
- package/src/graph/keyboard.ts +0 -208
- package/src/graph/search.ts +0 -50
- package/src/graph/simulation-worker-url.ts +0 -12
- package/src/graph/simulation-worker.ts +0 -278
- package/src/graph/simulation.ts +0 -422
- package/src/graph/spatial-index.ts +0 -121
- package/src/graph/types.ts +0 -47
- package/src/graph/worker-protocol.ts +0 -70
- package/src/graph/zoom.ts +0 -134
- package/src/graph-mount.ts +0 -888
- package/src/index.ts +0 -76
- package/src/interactions/chart-events.ts +0 -139
- package/src/interactions/crosshair.ts +0 -233
- package/src/interactions/drag-handler.ts +0 -175
- package/src/interactions/editing-drags.ts +0 -515
- package/src/interactions/index.ts +0 -25
- package/src/interactions/keyboard-nav.ts +0 -111
- package/src/interactions/legend-interaction.ts +0 -46
- package/src/interactions/selection.ts +0 -280
- package/src/interactions/tooltip-events.ts +0 -72
- package/src/map-camera.ts +0 -111
- package/src/map-mount.ts +0 -792
- package/src/map-renderer.ts +0 -460
- package/src/map-transition.ts +0 -99
- package/src/measure-text.ts +0 -134
- package/src/mount.ts +0 -1382
- package/src/pattern-utils.ts +0 -110
- package/src/renderers/annotations.ts +0 -388
- package/src/renderers/axes.ts +0 -351
- package/src/renderers/brand.ts +0 -87
- package/src/renderers/chrome.ts +0 -196
- package/src/renderers/endpoint-labels.ts +0 -150
- package/src/renderers/legend.ts +0 -311
- package/src/renderers/marks.ts +0 -561
- package/src/renderers/metrics.ts +0 -63
- package/src/renderers/svg-dom.ts +0 -40
- package/src/renderers/table-cells.ts +0 -446
- package/src/resize-observer.ts +0 -46
- package/src/sankey-mount.ts +0 -622
- package/src/sankey-renderer.ts +0 -614
- package/src/series-search.ts +0 -392
- package/src/static.ts +0 -251
- package/src/story/__tests__/camera-math.test.ts +0 -145
- package/src/story/__tests__/create-chart-story.test.ts +0 -317
- package/src/story/__tests__/progress-math.test.ts +0 -95
- package/src/story/__tests__/scroll-driver.test.ts +0 -130
- package/src/story/__tests__/tween.test.ts +0 -159
- package/src/story/camera-math.ts +0 -125
- package/src/story/create-chart-story.ts +0 -353
- package/src/story/crossfade.ts +0 -70
- package/src/story/index.ts +0 -39
- package/src/story/progress-math.ts +0 -85
- package/src/story/resolve-camera-target.ts +0 -119
- package/src/story/scroll-driver.ts +0 -206
- package/src/story/story-camera.ts +0 -49
- package/src/story/tween.ts +0 -112
- package/src/story/types.ts +0 -76
- package/src/svg-ids.ts +0 -23
- package/src/svg-renderer.ts +0 -383
- package/src/table-keyboard.ts +0 -266
- package/src/table-mount.ts +0 -567
- package/src/table-renderer.ts +0 -414
- package/src/text-edit-overlay.ts +0 -255
- package/src/theme-tokens.ts +0 -51
- package/src/tilemap-mount.ts +0 -511
- package/src/tilemap-renderer.ts +0 -396
- package/src/tooltip.ts +0 -177
- package/src/transition.ts +0 -2816
- package/src/you-draw-it.ts +0 -480
- /package/dist/{chunk-W34KN7FD.js.map → chunk-2NAQRP66.js.map} +0 -0
|
@@ -1,563 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scrolly step-pattern matrix for `chart.update(spec)`.
|
|
3
|
-
*
|
|
4
|
-
* A scrollytelling driver patches a base spec per step ({ data?, encoding?,
|
|
5
|
-
* annotations?, highlight? }) and calls update() as the reader scrolls. This
|
|
6
|
-
* suite exercises each step pattern end-to-end through the public
|
|
7
|
-
* createChart()/update() API on one column chart and one line chart:
|
|
8
|
-
*
|
|
9
|
-
* - data-only change (same keys, new values)
|
|
10
|
-
* - y-domain change (values that force a rescale)
|
|
11
|
-
* - annotation add / remove / move
|
|
12
|
-
* - highlight change
|
|
13
|
-
* - series / category add & remove (enter/exit ghosts)
|
|
14
|
-
* - rapid-fire interrupted updates (scroll jitter)
|
|
15
|
-
* - reduced motion (snap, no tween)
|
|
16
|
-
* - entrance-in-flight (update during entrance snaps)
|
|
17
|
-
*
|
|
18
|
-
* All specs here use `animation: { enter: false }`. With `animation: true`,
|
|
19
|
-
* createChart() arms an entrance-cleanup timer (~1.2s real setTimeout) and
|
|
20
|
-
* any update() inside that window fails canTransition gate 6
|
|
21
|
-
* (entranceInFlight) -- the chart snaps instead of tweening. The
|
|
22
|
-
* entrance-in-flight test at the bottom pins that behavior down explicitly.
|
|
23
|
-
*
|
|
24
|
-
* transition.test.ts covers the transition internals (gates, runTransition,
|
|
25
|
-
* normalizePointArrays); this file stays on the public API surface.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
import type { ChartLayout, ChartSpec } from '@opendata-ai/openchart-core';
|
|
29
|
-
import { compileChart } from '@opendata-ai/openchart-engine';
|
|
30
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
31
|
-
import { createContainer } from '../__test-fixtures__/dom';
|
|
32
|
-
import { createChart } from '../mount';
|
|
33
|
-
import { renderChartSVG } from '../svg-renderer';
|
|
34
|
-
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// rAF mock (same pattern as transition.test.ts)
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
let rafCallbacks: Map<number, FrameRequestCallback>;
|
|
40
|
-
let nextRafId: number;
|
|
41
|
-
|
|
42
|
-
function setupRafMock() {
|
|
43
|
-
rafCallbacks = new Map();
|
|
44
|
-
nextRafId = 1;
|
|
45
|
-
|
|
46
|
-
vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback): number => {
|
|
47
|
-
const id = nextRafId++;
|
|
48
|
-
rafCallbacks.set(id, cb);
|
|
49
|
-
return id;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
vi.stubGlobal('cancelAnimationFrame', (id: number): void => {
|
|
53
|
-
rafCallbacks.delete(id);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Pump all pending rAF callbacks at the given timestamp. */
|
|
58
|
-
function pumpRaf(timestamp: number) {
|
|
59
|
-
const cbs = Array.from(rafCallbacks.entries());
|
|
60
|
-
rafCallbacks.clear();
|
|
61
|
-
for (const [, cb] of cbs) {
|
|
62
|
-
cb(timestamp);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Run any in-flight transition to completion. */
|
|
67
|
-
function runToCompletion(totalMs = 5000) {
|
|
68
|
-
pumpRaf(0);
|
|
69
|
-
pumpRaf(totalMs);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
setupRafMock();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
document.body.innerHTML = '';
|
|
78
|
-
vi.restoreAllMocks();
|
|
79
|
-
// restoreAllMocks does NOT undo vi.stubGlobal; without this the
|
|
80
|
-
// reduced-motion matchMedia stub leaks into later tests and masks
|
|
81
|
-
// the entrance-window gate behind the reduced-motion gate.
|
|
82
|
-
vi.unstubAllGlobals();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
// Spec builders
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* update/exit enabled, enter disabled: the scrolly configuration that lets
|
|
91
|
-
* update() transition immediately after mount (see file header).
|
|
92
|
-
*/
|
|
93
|
-
const SCROLLY_ANIMATION = { enter: false } as const;
|
|
94
|
-
|
|
95
|
-
function columnSpec(
|
|
96
|
-
data: Array<{ category: string; value: number }>,
|
|
97
|
-
extra: Partial<ChartSpec> = {},
|
|
98
|
-
): ChartSpec {
|
|
99
|
-
return {
|
|
100
|
-
animation: SCROLLY_ANIMATION,
|
|
101
|
-
mark: 'bar',
|
|
102
|
-
data,
|
|
103
|
-
encoding: {
|
|
104
|
-
x: { field: 'category', type: 'nominal' },
|
|
105
|
-
y: { field: 'value', type: 'quantitative' },
|
|
106
|
-
},
|
|
107
|
-
...extra,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function lineSpec(
|
|
112
|
-
data: Array<{ month: string; value: number; series: string }>,
|
|
113
|
-
extra: Partial<ChartSpec> = {},
|
|
114
|
-
): ChartSpec {
|
|
115
|
-
return {
|
|
116
|
-
animation: SCROLLY_ANIMATION,
|
|
117
|
-
mark: 'line',
|
|
118
|
-
data,
|
|
119
|
-
encoding: {
|
|
120
|
-
x: { field: 'month', type: 'ordinal' },
|
|
121
|
-
y: { field: 'value', type: 'quantitative' },
|
|
122
|
-
color: { field: 'series', type: 'nominal' },
|
|
123
|
-
},
|
|
124
|
-
...extra,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const COL_A = [
|
|
129
|
-
{ category: 'Q1', value: 100 },
|
|
130
|
-
{ category: 'Q2', value: 200 },
|
|
131
|
-
{ category: 'Q3', value: 150 },
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
const COL_B = [
|
|
135
|
-
{ category: 'Q1', value: 150 },
|
|
136
|
-
{ category: 'Q2', value: 180 },
|
|
137
|
-
{ category: 'Q3', value: 220 },
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
/** Same categories, values an order of magnitude larger: forces a y rescale. */
|
|
141
|
-
const COL_RESCALE = [
|
|
142
|
-
{ category: 'Q1', value: 1200 },
|
|
143
|
-
{ category: 'Q2', value: 2400 },
|
|
144
|
-
{ category: 'Q3', value: 1800 },
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
const COL_EXIT = [
|
|
148
|
-
{ category: 'Q1', value: 100 },
|
|
149
|
-
{ category: 'Q2', value: 200 },
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
const COL_ENTER = [...COL_A, { category: 'Q4', value: 250 }];
|
|
153
|
-
|
|
154
|
-
function seriesData(values: Record<string, number[]>) {
|
|
155
|
-
const months = ['Jan', 'Feb', 'Mar', 'Apr'];
|
|
156
|
-
return Object.entries(values).flatMap(([series, vals]) =>
|
|
157
|
-
vals.map((value, i) => ({ month: months[i], value, series })),
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const LINE_AB = seriesData({ A: [10, 20, 15, 30], B: [40, 35, 45, 50] });
|
|
162
|
-
const LINE_AB2 = seriesData({ A: [15, 25, 35, 20], B: [30, 45, 40, 60] });
|
|
163
|
-
const LINE_A_ONLY = seriesData({ A: [10, 20, 15, 30] });
|
|
164
|
-
|
|
165
|
-
// ---------------------------------------------------------------------------
|
|
166
|
-
// Helpers
|
|
167
|
-
// ---------------------------------------------------------------------------
|
|
168
|
-
|
|
169
|
-
function compile(spec: ChartSpec, width = 600, height = 400): ChartLayout {
|
|
170
|
-
return compileChart(spec, { width, height });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function mountChart(spec: ChartSpec) {
|
|
174
|
-
const container = createContainer();
|
|
175
|
-
const chart = createChart(container, spec);
|
|
176
|
-
return {
|
|
177
|
-
chart,
|
|
178
|
-
container,
|
|
179
|
-
svg: () => container.querySelector('svg') as SVGSVGElement,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Rect geometry keyed by data-key. */
|
|
184
|
-
function rectGeometry(svg: SVGElement): Map<string, string> {
|
|
185
|
-
const result = new Map<string, string>();
|
|
186
|
-
for (const g of svg.querySelectorAll('.oc-mark-rect[data-key]')) {
|
|
187
|
-
const key = g.getAttribute('data-key') as string;
|
|
188
|
-
const rect = g.querySelector('rect');
|
|
189
|
-
const path = g.querySelector('path');
|
|
190
|
-
if (rect) {
|
|
191
|
-
result.set(
|
|
192
|
-
key,
|
|
193
|
-
[
|
|
194
|
-
rect.getAttribute('x'),
|
|
195
|
-
rect.getAttribute('y'),
|
|
196
|
-
rect.getAttribute('width'),
|
|
197
|
-
rect.getAttribute('height'),
|
|
198
|
-
].join(','),
|
|
199
|
-
);
|
|
200
|
-
} else if (path) {
|
|
201
|
-
result.set(key, path.getAttribute('d') ?? '');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return result;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** Line path `d` strings keyed by data-key. */
|
|
208
|
-
function linePaths(svg: SVGElement): Map<string, string> {
|
|
209
|
-
const result = new Map<string, string>();
|
|
210
|
-
for (const g of svg.querySelectorAll('.oc-mark-line[data-key]')) {
|
|
211
|
-
const key = g.getAttribute('data-key') as string;
|
|
212
|
-
const path = g.querySelector('path');
|
|
213
|
-
if (path) {
|
|
214
|
-
result.set(key, path.getAttribute('d') ?? '');
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Render a spec into a standalone SVG (what update() must converge to). */
|
|
221
|
-
function freshRender(spec: ChartSpec): SVGSVGElement {
|
|
222
|
-
const container = createContainer();
|
|
223
|
-
return renderChartSVG(compile(spec), container) as SVGSVGElement;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function expectGeometryMatches(actual: Map<string, string>, expected: Map<string, string>) {
|
|
227
|
-
expect([...actual.keys()].sort()).toEqual([...expected.keys()].sort());
|
|
228
|
-
for (const [key, geom] of actual) {
|
|
229
|
-
expect(geom, `geometry for ${key}`).toBe(expected.get(key));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function ghosts(root: ParentNode): number {
|
|
234
|
-
return root.querySelectorAll('.oc-ghost').length;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// ---------------------------------------------------------------------------
|
|
238
|
-
// Column chart step patterns
|
|
239
|
-
// ---------------------------------------------------------------------------
|
|
240
|
-
|
|
241
|
-
describe('column chart: scrolly step patterns through update()', () => {
|
|
242
|
-
it('data-only change tweens through intermediate geometry and lands on the fresh render', () => {
|
|
243
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
244
|
-
const before = rectGeometry(svg());
|
|
245
|
-
|
|
246
|
-
chart.update(columnSpec(COL_B));
|
|
247
|
-
// A transition must actually be scheduled -- not the instant-swap path.
|
|
248
|
-
expect(rafCallbacks.size).toBeGreaterThan(0);
|
|
249
|
-
|
|
250
|
-
pumpRaf(0);
|
|
251
|
-
pumpRaf(250); // mid-flight of the 500ms default update phase
|
|
252
|
-
const mid = rectGeometry(svg());
|
|
253
|
-
const final = rectGeometry(freshRender(columnSpec(COL_B)));
|
|
254
|
-
// Mid-flight geometry is between states: differs from both start and end.
|
|
255
|
-
expect(mid).not.toEqual(before);
|
|
256
|
-
expect(mid).not.toEqual(final);
|
|
257
|
-
|
|
258
|
-
pumpRaf(5000);
|
|
259
|
-
expectGeometryMatches(rectGeometry(svg()), final);
|
|
260
|
-
expect(ghosts(svg())).toBe(0);
|
|
261
|
-
|
|
262
|
-
chart.destroy();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('y-domain change rescales: geometry and y-axis ticks match the fresh render', () => {
|
|
266
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
267
|
-
const ticksBefore = [...svg().querySelectorAll('.oc-axis-y .oc-axis-tick')].map(
|
|
268
|
-
(t) => t.textContent,
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
chart.update(columnSpec(COL_RESCALE));
|
|
272
|
-
runToCompletion();
|
|
273
|
-
|
|
274
|
-
const fresh = freshRender(columnSpec(COL_RESCALE));
|
|
275
|
-
expectGeometryMatches(rectGeometry(svg()), rectGeometry(fresh));
|
|
276
|
-
|
|
277
|
-
const ticksAfter = [...svg().querySelectorAll('.oc-axis-y .oc-axis-tick')].map(
|
|
278
|
-
(t) => t.textContent,
|
|
279
|
-
);
|
|
280
|
-
const ticksFresh = [...fresh.querySelectorAll('.oc-axis-y .oc-axis-tick')].map(
|
|
281
|
-
(t) => t.textContent,
|
|
282
|
-
);
|
|
283
|
-
expect(ticksAfter).not.toEqual(ticksBefore);
|
|
284
|
-
expect(ticksAfter).toEqual(ticksFresh);
|
|
285
|
-
expect(ghosts(svg())).toBe(0);
|
|
286
|
-
|
|
287
|
-
chart.destroy();
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('category exit ghosts the removed bar, then cleans it up', () => {
|
|
291
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
292
|
-
|
|
293
|
-
chart.update(columnSpec(COL_EXIT)); // Q3 exits
|
|
294
|
-
// Ghosts are created synchronously before the first frame.
|
|
295
|
-
expect(ghosts(svg())).toBeGreaterThan(0);
|
|
296
|
-
|
|
297
|
-
runToCompletion();
|
|
298
|
-
expect(ghosts(svg())).toBe(0);
|
|
299
|
-
expectGeometryMatches(rectGeometry(svg()), rectGeometry(freshRender(columnSpec(COL_EXIT))));
|
|
300
|
-
|
|
301
|
-
chart.destroy();
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it('category enter adds the new bar and converges on the fresh render', () => {
|
|
305
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
306
|
-
|
|
307
|
-
chart.update(columnSpec(COL_ENTER)); // Q4 enters
|
|
308
|
-
runToCompletion();
|
|
309
|
-
|
|
310
|
-
const geometry = rectGeometry(svg());
|
|
311
|
-
expect(geometry.size).toBe(4);
|
|
312
|
-
expectGeometryMatches(geometry, rectGeometry(freshRender(columnSpec(COL_ENTER))));
|
|
313
|
-
expect(ghosts(svg())).toBe(0);
|
|
314
|
-
|
|
315
|
-
chart.destroy();
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('rapid-fire interrupted updates settle on the last spec with no orphaned ghosts', () => {
|
|
319
|
-
const { chart, container, svg } = mountChart(columnSpec(COL_A));
|
|
320
|
-
|
|
321
|
-
// Scroll jitter: four steps in quick succession, some mid-tween, some
|
|
322
|
-
// back-to-back with no frame in between, including an exit step whose
|
|
323
|
-
// ghost must not survive the interruption.
|
|
324
|
-
chart.update(columnSpec(COL_B));
|
|
325
|
-
pumpRaf(0);
|
|
326
|
-
pumpRaf(120);
|
|
327
|
-
chart.update(columnSpec(COL_EXIT)); // spawns a ghost for Q3
|
|
328
|
-
pumpRaf(0);
|
|
329
|
-
pumpRaf(60);
|
|
330
|
-
chart.update(columnSpec(COL_RESCALE)); // no frame pumped since last update
|
|
331
|
-
chart.update(columnSpec(COL_ENTER));
|
|
332
|
-
runToCompletion();
|
|
333
|
-
|
|
334
|
-
expectGeometryMatches(rectGeometry(svg()), rectGeometry(freshRender(columnSpec(COL_ENTER))));
|
|
335
|
-
// No ghost anywhere in the container, and no rAF loop left running.
|
|
336
|
-
expect(ghosts(container)).toBe(0);
|
|
337
|
-
expect(rafCallbacks.size).toBe(0);
|
|
338
|
-
|
|
339
|
-
chart.destroy();
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
// ---------------------------------------------------------------------------
|
|
344
|
-
// Line chart step patterns
|
|
345
|
-
// ---------------------------------------------------------------------------
|
|
346
|
-
|
|
347
|
-
describe('line chart: scrolly step patterns through update()', () => {
|
|
348
|
-
it('data-only change morphs paths and lands on the fresh render', () => {
|
|
349
|
-
const { chart, svg } = mountChart(lineSpec(LINE_AB));
|
|
350
|
-
const before = linePaths(svg());
|
|
351
|
-
|
|
352
|
-
chart.update(lineSpec(LINE_AB2));
|
|
353
|
-
expect(rafCallbacks.size).toBeGreaterThan(0);
|
|
354
|
-
|
|
355
|
-
pumpRaf(0);
|
|
356
|
-
pumpRaf(250);
|
|
357
|
-
const mid = linePaths(svg());
|
|
358
|
-
const final = linePaths(freshRender(lineSpec(LINE_AB2)));
|
|
359
|
-
expect(mid).not.toEqual(before);
|
|
360
|
-
expect(mid).not.toEqual(final);
|
|
361
|
-
|
|
362
|
-
pumpRaf(5000);
|
|
363
|
-
expectGeometryMatches(linePaths(svg()), final);
|
|
364
|
-
expect(ghosts(svg())).toBe(0);
|
|
365
|
-
|
|
366
|
-
chart.destroy();
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('series exit ghosts the removed line, then cleans it up', () => {
|
|
370
|
-
const { chart, svg } = mountChart(lineSpec(LINE_AB));
|
|
371
|
-
|
|
372
|
-
chart.update(lineSpec(LINE_A_ONLY)); // series B exits
|
|
373
|
-
expect(ghosts(svg())).toBeGreaterThan(0);
|
|
374
|
-
|
|
375
|
-
runToCompletion();
|
|
376
|
-
expect(ghosts(svg())).toBe(0);
|
|
377
|
-
const paths = linePaths(svg());
|
|
378
|
-
expect(paths.size).toBe(1);
|
|
379
|
-
expectGeometryMatches(paths, linePaths(freshRender(lineSpec(LINE_A_ONLY))));
|
|
380
|
-
|
|
381
|
-
chart.destroy();
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it('series enter adds the new line and converges on the fresh render', () => {
|
|
385
|
-
const { chart, svg } = mountChart(lineSpec(LINE_A_ONLY));
|
|
386
|
-
|
|
387
|
-
chart.update(lineSpec(LINE_AB)); // series B enters
|
|
388
|
-
runToCompletion();
|
|
389
|
-
|
|
390
|
-
const paths = linePaths(svg());
|
|
391
|
-
expect(paths.size).toBe(2);
|
|
392
|
-
expectGeometryMatches(paths, linePaths(freshRender(lineSpec(LINE_AB))));
|
|
393
|
-
expect(ghosts(svg())).toBe(0);
|
|
394
|
-
|
|
395
|
-
chart.destroy();
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it('highlight change fades stroke to the muted color instead of snapping', () => {
|
|
399
|
-
const base = lineSpec(LINE_AB);
|
|
400
|
-
const highlighted = lineSpec(LINE_AB, {
|
|
401
|
-
encoding: {
|
|
402
|
-
x: { field: 'month', type: 'ordinal' },
|
|
403
|
-
y: { field: 'value', type: 'quantitative' },
|
|
404
|
-
color: { field: 'series', type: 'nominal', highlight: ['A'] },
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
// Find a mark whose stroke the highlight mutes.
|
|
409
|
-
const layoutBase = compile(base);
|
|
410
|
-
const layoutHl = compile(highlighted);
|
|
411
|
-
const mutedIdx = layoutHl.marks.findIndex(
|
|
412
|
-
(m, i) =>
|
|
413
|
-
(m as { stroke?: string }).stroke !== (layoutBase.marks[i] as { stroke?: string }).stroke,
|
|
414
|
-
);
|
|
415
|
-
expect(mutedIdx).toBeGreaterThanOrEqual(0);
|
|
416
|
-
const mutedKey = (layoutHl.marks[mutedIdx] as { key?: string }).key as string;
|
|
417
|
-
const toStroke = (layoutHl.marks[mutedIdx] as { stroke?: string }).stroke;
|
|
418
|
-
|
|
419
|
-
const { chart, svg } = mountChart(base);
|
|
420
|
-
chart.update(highlighted);
|
|
421
|
-
|
|
422
|
-
const el = svg().querySelector(`[data-key="${mutedKey}"] path`) as SVGElement;
|
|
423
|
-
pumpRaf(0);
|
|
424
|
-
// At the start of the fade the stroke is NOT yet the muted color.
|
|
425
|
-
expect(el.getAttribute('stroke')).not.toBe(toStroke);
|
|
426
|
-
|
|
427
|
-
pumpRaf(5000);
|
|
428
|
-
expect(el.getAttribute('stroke')).toBe(toStroke);
|
|
429
|
-
|
|
430
|
-
chart.destroy();
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('rapid-fire interrupted updates settle on the last spec with no orphaned ghosts', () => {
|
|
434
|
-
const { chart, container, svg } = mountChart(lineSpec(LINE_AB));
|
|
435
|
-
|
|
436
|
-
chart.update(lineSpec(LINE_A_ONLY)); // B exits: ghost path in flight
|
|
437
|
-
pumpRaf(0);
|
|
438
|
-
pumpRaf(100);
|
|
439
|
-
chart.update(lineSpec(LINE_AB2)); // B re-enters mid-exit
|
|
440
|
-
pumpRaf(0);
|
|
441
|
-
chart.update(lineSpec(LINE_AB)); // no frame pumped since last update
|
|
442
|
-
runToCompletion();
|
|
443
|
-
|
|
444
|
-
expectGeometryMatches(linePaths(svg()), linePaths(freshRender(lineSpec(LINE_AB))));
|
|
445
|
-
expect(ghosts(container)).toBe(0);
|
|
446
|
-
expect(rafCallbacks.size).toBe(0);
|
|
447
|
-
|
|
448
|
-
chart.destroy();
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
// ---------------------------------------------------------------------------
|
|
453
|
-
// Annotation steps
|
|
454
|
-
// ---------------------------------------------------------------------------
|
|
455
|
-
|
|
456
|
-
describe('annotation steps through update()', () => {
|
|
457
|
-
const NOTE = { id: 'note', type: 'text' as const, x: 'Q2', y: 180, text: 'Peak' };
|
|
458
|
-
|
|
459
|
-
it('annotation add fades the new annotation in', () => {
|
|
460
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
461
|
-
|
|
462
|
-
chart.update(columnSpec(COL_A, { annotations: [NOTE] }));
|
|
463
|
-
|
|
464
|
-
const annotation = svg().querySelector('.oc-annotation') as SVGElement;
|
|
465
|
-
expect(annotation).not.toBeNull();
|
|
466
|
-
// From-state applied synchronously: fading in from 0.
|
|
467
|
-
expect(annotation.style.opacity).toBe('0');
|
|
468
|
-
|
|
469
|
-
runToCompletion();
|
|
470
|
-
expect(annotation.style.opacity).toBe('1');
|
|
471
|
-
|
|
472
|
-
chart.destroy();
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
it('annotation move tweens via a transform offset and clears it on completion', () => {
|
|
476
|
-
const { chart, svg } = mountChart(columnSpec(COL_A, { annotations: [NOTE] }));
|
|
477
|
-
|
|
478
|
-
chart.update(columnSpec(COL_A, { annotations: [{ ...NOTE, x: 'Q3', y: 120 }] }));
|
|
479
|
-
|
|
480
|
-
const annotation = svg().querySelector('.oc-annotation') as SVGElement;
|
|
481
|
-
pumpRaf(0);
|
|
482
|
-
pumpRaf(250);
|
|
483
|
-
// Mid-flight: sliding from the old position via an SVG transform.
|
|
484
|
-
expect(annotation.getAttribute('transform')).toMatch(/translate/);
|
|
485
|
-
// A moved annotation is the same annotation: it must not re-fade.
|
|
486
|
-
expect(annotation.style.opacity).not.toBe('0');
|
|
487
|
-
|
|
488
|
-
pumpRaf(5000);
|
|
489
|
-
// Completion drops the offset so the DOM matches what render() produced.
|
|
490
|
-
expect(annotation.hasAttribute('transform')).toBe(false);
|
|
491
|
-
|
|
492
|
-
chart.destroy();
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('annotation remove disappears immediately (known limitation: no exit fade)', () => {
|
|
496
|
-
const { chart, svg } = mountChart(columnSpec(COL_A, { annotations: [NOTE] }));
|
|
497
|
-
expect(svg().querySelector('.oc-annotation')).not.toBeNull();
|
|
498
|
-
|
|
499
|
-
chart.update(columnSpec(COL_A));
|
|
500
|
-
// render() tears the old SVG down and annotations are not ghosted, so the
|
|
501
|
-
// annotation is gone before the first frame. Documented in
|
|
502
|
-
// docs/integration-guide.md ("Driving charts from scroll").
|
|
503
|
-
expect(svg().querySelector('.oc-annotation')).toBeNull();
|
|
504
|
-
|
|
505
|
-
runToCompletion();
|
|
506
|
-
expect(svg().querySelector('.oc-annotation')).toBeNull();
|
|
507
|
-
expect(ghosts(svg())).toBe(0);
|
|
508
|
-
|
|
509
|
-
chart.destroy();
|
|
510
|
-
});
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// ---------------------------------------------------------------------------
|
|
514
|
-
// Reduced motion
|
|
515
|
-
// ---------------------------------------------------------------------------
|
|
516
|
-
|
|
517
|
-
describe('reduced motion through update()', () => {
|
|
518
|
-
it('snaps to the final state with no tween and no ghosts', () => {
|
|
519
|
-
vi.stubGlobal('matchMedia', (query: string) => ({
|
|
520
|
-
matches: query === '(prefers-reduced-motion: reduce)',
|
|
521
|
-
media: query,
|
|
522
|
-
addEventListener: () => {},
|
|
523
|
-
removeEventListener: () => {},
|
|
524
|
-
}));
|
|
525
|
-
|
|
526
|
-
const { chart, svg } = mountChart(columnSpec(COL_A));
|
|
527
|
-
chart.update(columnSpec(COL_EXIT));
|
|
528
|
-
|
|
529
|
-
// No transition scheduled: geometry is already final, nothing ghosted.
|
|
530
|
-
expect(rafCallbacks.size).toBe(0);
|
|
531
|
-
expect(ghosts(svg())).toBe(0);
|
|
532
|
-
expectGeometryMatches(rectGeometry(svg()), rectGeometry(freshRender(columnSpec(COL_EXIT))));
|
|
533
|
-
|
|
534
|
-
chart.destroy();
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
// ---------------------------------------------------------------------------
|
|
539
|
-
// Entrance-in-flight
|
|
540
|
-
// ---------------------------------------------------------------------------
|
|
541
|
-
|
|
542
|
-
describe('update() during the entrance animation window', () => {
|
|
543
|
-
it('snaps instead of transitioning while the entrance cleanup timer is armed', () => {
|
|
544
|
-
// Full `animation: true`: mount arms the entrance-cleanup timer, and an
|
|
545
|
-
// update() inside that window (~duration + stagger + 700ms) fails
|
|
546
|
-
// canTransition gate 6. Scrolly drivers that want step 1 -> step 2 to
|
|
547
|
-
// tween must disable the entrance phase ({ enter: false }) or tolerate
|
|
548
|
-
// the first step snapping when the reader scrolls immediately.
|
|
549
|
-
const spec = { ...columnSpec(COL_A), animation: true } as ChartSpec;
|
|
550
|
-
const { chart, svg } = mountChart(spec);
|
|
551
|
-
|
|
552
|
-
chart.update({ ...columnSpec(COL_B), animation: true } as ChartSpec);
|
|
553
|
-
|
|
554
|
-
expect(rafCallbacks.size).toBe(0); // no transition scheduled
|
|
555
|
-
expect(ghosts(svg())).toBe(0);
|
|
556
|
-
expectGeometryMatches(
|
|
557
|
-
rectGeometry(svg()),
|
|
558
|
-
rectGeometry(freshRender({ ...columnSpec(COL_B), animation: true } as ChartSpec)),
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
chart.destroy();
|
|
562
|
-
});
|
|
563
|
-
});
|