@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.
Files changed (147) hide show
  1. package/dist/{chunk-W34KN7FD.js → chunk-2NAQRP66.js} +2 -2
  2. package/dist/{chunk-UZ7J3NOF.js → chunk-6BUCYCLD.js} +7314 -5605
  3. package/dist/chunk-6BUCYCLD.js.map +1 -0
  4. package/dist/chunk-DCODCLWI.js +234 -0
  5. package/dist/chunk-DCODCLWI.js.map +1 -0
  6. package/dist/{chunk-5EOV5JQZ.js → chunk-EKAUQAAX.js} +50 -46
  7. package/dist/chunk-EKAUQAAX.js.map +1 -0
  8. package/dist/chunk-RM5XS6NR.js +113 -0
  9. package/dist/chunk-RM5XS6NR.js.map +1 -0
  10. package/dist/chunk-T32UHMZA.js +282 -0
  11. package/dist/chunk-T32UHMZA.js.map +1 -0
  12. package/dist/export-gif.d.ts +113 -0
  13. package/dist/export-gif.js +21 -0
  14. package/dist/export-gif.js.map +1 -0
  15. package/dist/index.d.ts +309 -27
  16. package/dist/index.js +2020 -836
  17. package/dist/index.js.map +1 -1
  18. package/dist/{mount-CUKQLeqD.d.ts → mount-CL-nA0f-.d.ts} +85 -2
  19. package/dist/simulation-worker.js +83 -2
  20. package/dist/static.d.ts +2 -0
  21. package/dist/static.js +8 -69
  22. package/dist/static.js.map +1 -1
  23. package/dist/story/index.d.ts +25 -9
  24. package/dist/story/index.js +9 -7
  25. package/dist/story/index.js.map +1 -1
  26. package/dist/styles.css +1 -1
  27. package/dist/styles.css.map +1 -1
  28. package/package.json +14 -6
  29. package/dist/chunk-5EOV5JQZ.js.map +0 -1
  30. package/dist/chunk-UZ7J3NOF.js.map +0 -1
  31. package/src/__test-fixtures__/dom.ts +0 -70
  32. package/src/__test-fixtures__/specs.ts +0 -214
  33. package/src/__tests__/animation.test.ts +0 -358
  34. package/src/__tests__/annotations-render.test.ts +0 -201
  35. package/src/__tests__/compound-labels.test.ts +0 -122
  36. package/src/__tests__/continuous-legend.test.ts +0 -91
  37. package/src/__tests__/crosshair.test.ts +0 -130
  38. package/src/__tests__/edit-events.test.ts +0 -950
  39. package/src/__tests__/events.test.ts +0 -387
  40. package/src/__tests__/export.test.ts +0 -241
  41. package/src/__tests__/font-race.test.ts +0 -199
  42. package/src/__tests__/gradient-ids.test.ts +0 -159
  43. package/src/__tests__/gradient-utils.test.ts +0 -125
  44. package/src/__tests__/known-bugs-render.test.ts +0 -183
  45. package/src/__tests__/map.test.ts +0 -636
  46. package/src/__tests__/mount.test.ts +0 -357
  47. package/src/__tests__/pattern-fills.test.ts +0 -105
  48. package/src/__tests__/resize-timing.test.ts +0 -218
  49. package/src/__tests__/sankey.test.ts +0 -133
  50. package/src/__tests__/selection-events.test.ts +0 -869
  51. package/src/__tests__/series-search.test.ts +0 -311
  52. package/src/__tests__/static.test.ts +0 -141
  53. package/src/__tests__/svg-renderer.test.ts +0 -895
  54. package/src/__tests__/table-keyboard.test.ts +0 -361
  55. package/src/__tests__/table-mount.test.ts +0 -639
  56. package/src/__tests__/tilemap.test.ts +0 -158
  57. package/src/__tests__/tooltip.test.ts +0 -337
  58. package/src/__tests__/transition.test.ts +0 -1792
  59. package/src/__tests__/update-scrolly-matrix.test.ts +0 -563
  60. package/src/__tests__/you-draw-it.test.ts +0 -273
  61. package/src/animation-vars.ts +0 -42
  62. package/src/animation.ts +0 -76
  63. package/src/barlist-mount.ts +0 -383
  64. package/src/barlist-renderer.ts +0 -267
  65. package/src/dom-helpers.ts +0 -17
  66. package/src/export.ts +0 -482
  67. package/src/gradient-utils.ts +0 -138
  68. package/src/graph/__tests__/canvas-renderer.test.ts +0 -713
  69. package/src/graph/__tests__/graph-mount.test.ts +0 -213
  70. package/src/graph/__tests__/interaction.test.ts +0 -205
  71. package/src/graph/__tests__/keyboard.test.ts +0 -653
  72. package/src/graph/__tests__/search.test.ts +0 -88
  73. package/src/graph/__tests__/simulation.test.ts +0 -233
  74. package/src/graph/__tests__/spatial-index.test.ts +0 -142
  75. package/src/graph/__tests__/zoom.test.ts +0 -203
  76. package/src/graph/canvas-renderer.ts +0 -747
  77. package/src/graph/interaction.ts +0 -367
  78. package/src/graph/keyboard.ts +0 -208
  79. package/src/graph/search.ts +0 -50
  80. package/src/graph/simulation-worker-url.ts +0 -12
  81. package/src/graph/simulation-worker.ts +0 -278
  82. package/src/graph/simulation.ts +0 -422
  83. package/src/graph/spatial-index.ts +0 -121
  84. package/src/graph/types.ts +0 -47
  85. package/src/graph/worker-protocol.ts +0 -70
  86. package/src/graph/zoom.ts +0 -134
  87. package/src/graph-mount.ts +0 -888
  88. package/src/index.ts +0 -76
  89. package/src/interactions/chart-events.ts +0 -139
  90. package/src/interactions/crosshair.ts +0 -233
  91. package/src/interactions/drag-handler.ts +0 -175
  92. package/src/interactions/editing-drags.ts +0 -515
  93. package/src/interactions/index.ts +0 -25
  94. package/src/interactions/keyboard-nav.ts +0 -111
  95. package/src/interactions/legend-interaction.ts +0 -46
  96. package/src/interactions/selection.ts +0 -280
  97. package/src/interactions/tooltip-events.ts +0 -72
  98. package/src/map-camera.ts +0 -111
  99. package/src/map-mount.ts +0 -792
  100. package/src/map-renderer.ts +0 -460
  101. package/src/map-transition.ts +0 -99
  102. package/src/measure-text.ts +0 -134
  103. package/src/mount.ts +0 -1382
  104. package/src/pattern-utils.ts +0 -110
  105. package/src/renderers/annotations.ts +0 -388
  106. package/src/renderers/axes.ts +0 -351
  107. package/src/renderers/brand.ts +0 -87
  108. package/src/renderers/chrome.ts +0 -196
  109. package/src/renderers/endpoint-labels.ts +0 -150
  110. package/src/renderers/legend.ts +0 -311
  111. package/src/renderers/marks.ts +0 -561
  112. package/src/renderers/metrics.ts +0 -63
  113. package/src/renderers/svg-dom.ts +0 -40
  114. package/src/renderers/table-cells.ts +0 -446
  115. package/src/resize-observer.ts +0 -46
  116. package/src/sankey-mount.ts +0 -622
  117. package/src/sankey-renderer.ts +0 -614
  118. package/src/series-search.ts +0 -392
  119. package/src/static.ts +0 -251
  120. package/src/story/__tests__/camera-math.test.ts +0 -145
  121. package/src/story/__tests__/create-chart-story.test.ts +0 -317
  122. package/src/story/__tests__/progress-math.test.ts +0 -95
  123. package/src/story/__tests__/scroll-driver.test.ts +0 -130
  124. package/src/story/__tests__/tween.test.ts +0 -159
  125. package/src/story/camera-math.ts +0 -125
  126. package/src/story/create-chart-story.ts +0 -353
  127. package/src/story/crossfade.ts +0 -70
  128. package/src/story/index.ts +0 -39
  129. package/src/story/progress-math.ts +0 -85
  130. package/src/story/resolve-camera-target.ts +0 -119
  131. package/src/story/scroll-driver.ts +0 -206
  132. package/src/story/story-camera.ts +0 -49
  133. package/src/story/tween.ts +0 -112
  134. package/src/story/types.ts +0 -76
  135. package/src/svg-ids.ts +0 -23
  136. package/src/svg-renderer.ts +0 -383
  137. package/src/table-keyboard.ts +0 -266
  138. package/src/table-mount.ts +0 -567
  139. package/src/table-renderer.ts +0 -414
  140. package/src/text-edit-overlay.ts +0 -255
  141. package/src/theme-tokens.ts +0 -51
  142. package/src/tilemap-mount.ts +0 -511
  143. package/src/tilemap-renderer.ts +0 -396
  144. package/src/tooltip.ts +0 -177
  145. package/src/transition.ts +0 -2816
  146. package/src/you-draw-it.ts +0 -480
  147. /package/dist/{chunk-W34KN7FD.js.map → chunk-2NAQRP66.js.map} +0 -0
@@ -1,636 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { createContainer } from '../__test-fixtures__/dom';
3
- import { createMap } from '../map-mount';
4
-
5
- function mockReducedMotion() {
6
- return vi.spyOn(window, 'matchMedia').mockImplementation(
7
- (q) =>
8
- ({
9
- matches: q.includes('reduced-motion'),
10
- media: '',
11
- onchange: null,
12
- addEventListener: vi.fn(),
13
- removeEventListener: vi.fn(),
14
- addListener: vi.fn(),
15
- removeListener: vi.fn(),
16
- dispatchEvent: vi.fn(),
17
- }) as MediaQueryList,
18
- );
19
- }
20
-
21
- // ---------------------------------------------------------------------------
22
- // Shared fixtures
23
- // ---------------------------------------------------------------------------
24
-
25
- // Minimal valid TopoJSON with 3 US states (delta-encoded arcs).
26
- const MINI_TOPO = {
27
- type: 'Topology',
28
- objects: {
29
- states: {
30
- type: 'GeometryCollection',
31
- geometries: [
32
- { type: 'Polygon', id: '06', properties: { name: 'California' }, arcs: [[0]] },
33
- { type: 'Polygon', id: '48', properties: { name: 'Texas' }, arcs: [[1]] },
34
- { type: 'Polygon', id: '36', properties: { name: 'New York' }, arcs: [[2]] },
35
- ],
36
- },
37
- },
38
- arcs: [
39
- [
40
- [-122, 37],
41
- [4, -3],
42
- [-3, 2],
43
- [-1, 1],
44
- ],
45
- [
46
- [-100, 31],
47
- [6, -1],
48
- [-3, -4],
49
- [-3, 5],
50
- ],
51
- [
52
- [-74, 41],
53
- [1, -1],
54
- [-3, 2],
55
- [2, -1],
56
- ],
57
- ],
58
- };
59
-
60
- const basicMapSpec = {
61
- type: 'map' as const,
62
- geo: { features: MINI_TOPO, projection: 'mercator' as const },
63
- data: [
64
- { fips: '06', value: 10 },
65
- { fips: '48', value: 20 },
66
- ],
67
- encoding: {
68
- key: { field: 'fips', type: 'nominal' as const },
69
- color: { field: 'value', type: 'quantitative' as const },
70
- },
71
- };
72
-
73
- // ---------------------------------------------------------------------------
74
- // Tests
75
- // ---------------------------------------------------------------------------
76
-
77
- describe('createMap', () => {
78
- let container: HTMLDivElement;
79
-
80
- beforeEach(() => {
81
- container = createContainer();
82
- });
83
-
84
- afterEach(() => {
85
- document.body.innerHTML = '';
86
- });
87
-
88
- it('mounts an SVG with path elements', () => {
89
- const instance = createMap(container, basicMapSpec, { responsive: false });
90
-
91
- const svg = container.querySelector('svg');
92
- expect(svg).not.toBeNull();
93
- expect(svg!.classList.contains('oc-map')).toBe(true);
94
-
95
- const features = container.querySelectorAll('.oc-map-feature');
96
- expect(features.length).toBe(3);
97
-
98
- instance.destroy();
99
- });
100
-
101
- it('update() re-renders with new data', () => {
102
- const instance = createMap(container, basicMapSpec, { responsive: false });
103
-
104
- instance.update({
105
- ...basicMapSpec,
106
- data: [
107
- { fips: '06', value: 100 },
108
- { fips: '48', value: 200 },
109
- { fips: '36', value: 300 },
110
- ],
111
- });
112
-
113
- const features = container.querySelectorAll('.oc-map-feature');
114
- expect(features.length).toBe(3);
115
-
116
- instance.destroy();
117
- });
118
-
119
- it('destroy() removes SVG from DOM', () => {
120
- const instance = createMap(container, basicMapSpec, { responsive: false });
121
-
122
- expect(container.querySelector('svg')).not.toBeNull();
123
- instance.destroy();
124
- expect(container.querySelector('svg')).toBeNull();
125
- });
126
-
127
- it('SVG does not have oc-chart-root class', () => {
128
- const instance = createMap(container, basicMapSpec, { responsive: false });
129
-
130
- const svg = container.querySelector('svg');
131
- expect(svg).not.toBeNull();
132
- expect(svg!.classList.contains('oc-chart-root')).toBe(false);
133
- expect(svg!.classList.contains('oc-map')).toBe(true);
134
-
135
- instance.destroy();
136
- });
137
-
138
- it('viewBox matches layout dimensions', () => {
139
- const instance = createMap(container, basicMapSpec, { responsive: false });
140
-
141
- const svg = container.querySelector('svg');
142
- expect(svg).not.toBeNull();
143
- const viewBox = svg!.getAttribute('viewBox');
144
- expect(viewBox).toBe(`0 0 ${instance.layout.width} ${instance.layout.height}`);
145
-
146
- instance.destroy();
147
- });
148
-
149
- it('no gradient legend group present for quantitative map', () => {
150
- const instance = createMap(container, basicMapSpec, { responsive: false });
151
-
152
- // Old hand-rolled gradient legend used .oc-map-legend; it should be gone
153
- const oldLegend = container.querySelector('.oc-map-legend');
154
- expect(oldLegend).toBeNull();
155
-
156
- // Continuous legend uses the shared .oc-legend class
157
- const legend = container.querySelector('.oc-legend');
158
- expect(legend).not.toBeNull();
159
-
160
- instance.destroy();
161
- });
162
-
163
- it('exposes layout property', () => {
164
- const instance = createMap(container, basicMapSpec, { responsive: false });
165
-
166
- expect(instance.layout).toBeDefined();
167
- expect(instance.layout.features.length).toBeGreaterThan(0);
168
-
169
- instance.destroy();
170
- });
171
-
172
- it('export("svg") returns a string containing SVG content', () => {
173
- const instance = createMap(container, basicMapSpec, { responsive: false });
174
-
175
- const svgString = instance.export('svg');
176
- expect(typeof svgString).toBe('string');
177
- expect(svgString).toContain('<svg');
178
- expect(svgString).toContain('oc-map');
179
-
180
- instance.destroy();
181
- });
182
-
183
- it('stamps data-key on feature paths equal to feature id', () => {
184
- const instance = createMap(container, basicMapSpec, { responsive: false });
185
-
186
- const features = container.querySelectorAll('.oc-map-feature');
187
- for (const feature of features) {
188
- const featureId = feature.getAttribute('data-feature-id');
189
- const dataKey = feature.getAttribute('data-key');
190
- expect(dataKey).not.toBeNull();
191
- expect(dataKey).toBe(featureId);
192
- }
193
-
194
- instance.destroy();
195
- });
196
-
197
- it('stagger custom property is at most 80ms for any feature count', () => {
198
- const instance = createMap(container, basicMapSpec, { responsive: false });
199
-
200
- const svg = container.querySelector('svg');
201
- expect(svg).not.toBeNull();
202
-
203
- const staggerValue = svg!.style.getPropertyValue('--oc-animation-stagger');
204
- if (staggerValue) {
205
- const numericMs = parseFloat(staggerValue);
206
- expect(numericMs).toBeLessThanOrEqual(80);
207
- }
208
-
209
- instance.destroy();
210
- });
211
-
212
- it('camera group [data-oc-map-camera] wraps features and borders', () => {
213
- const instance = createMap(container, basicMapSpec, { responsive: false });
214
-
215
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
216
- expect(cameraGroup).not.toBeNull();
217
-
218
- // Features and borders should be inside the camera group
219
- const features = cameraGroup!.querySelector('.oc-map-features');
220
- const borders = cameraGroup!.querySelector('.oc-map-borders');
221
- expect(features).not.toBeNull();
222
- expect(borders).not.toBeNull();
223
-
224
- // Chrome and legend should NOT be inside the camera group
225
- const chrome = cameraGroup!.querySelector('.oc-chrome');
226
- expect(chrome).toBeNull();
227
-
228
- instance.destroy();
229
- });
230
-
231
- it('zoomTo applies a transform with scale > 1 and sets vector-effect', () => {
232
- const instance = createMap(container, basicMapSpec, { responsive: false });
233
-
234
- // Use New York ('36') which is small enough relative to the full map to produce a zoom > 1
235
- instance.zoomTo('36', { duration: 0 });
236
-
237
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
238
- expect(cameraGroup).not.toBeNull();
239
-
240
- const transform = cameraGroup!.getAttribute('transform');
241
- expect(transform).not.toBeNull();
242
- // Transform should contain a scale factor > 1
243
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
244
- expect(scaleMatch).not.toBeNull();
245
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
246
-
247
- // vector-effect should be set on feature paths
248
- const featurePaths = container.querySelectorAll('.oc-map-feature');
249
- for (const p of featurePaths) {
250
- expect(p.getAttribute('vector-effect')).toBe('non-scaling-stroke');
251
- }
252
-
253
- instance.destroy();
254
- });
255
-
256
- it('resetView removes the transform and vector-effect', () => {
257
- const instance = createMap(container, basicMapSpec, { responsive: false });
258
-
259
- // First zoom in to New York (small enough to produce zoom > 1)
260
- instance.zoomTo('36', { duration: 0 });
261
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
262
- expect(cameraGroup!.getAttribute('transform')).not.toBeNull();
263
-
264
- // Then reset
265
- instance.resetView({ duration: 0 });
266
- expect(cameraGroup!.getAttribute('transform')).toBeNull();
267
-
268
- // vector-effect should be removed
269
- const featurePaths = container.querySelectorAll('.oc-map-feature');
270
- for (const p of featurePaths) {
271
- expect(p.getAttribute('vector-effect')).toBeNull();
272
- }
273
-
274
- instance.destroy();
275
- });
276
-
277
- it('zoomTo with unknown feature id warns via console.warn', () => {
278
- const instance = createMap(container, basicMapSpec, { responsive: false });
279
-
280
- const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
281
-
282
- instance.zoomTo('NONEXISTENT', { duration: 0 });
283
- expect(warnSpy).toHaveBeenCalledOnce();
284
- expect(warnSpy.mock.calls[0][0]).toContain('NONEXISTENT');
285
-
286
- warnSpy.mockRestore();
287
- instance.destroy();
288
- });
289
-
290
- it('spec with geo.focus snaps camera on first render', () => {
291
- const focusSpec = {
292
- ...basicMapSpec,
293
- geo: { ...basicMapSpec.geo, focus: '36' },
294
- };
295
- const instance = createMap(container, focusSpec, { responsive: false });
296
-
297
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
298
- expect(cameraGroup).not.toBeNull();
299
-
300
- // Camera should be applied (transform present because '36' is small enough to zoom)
301
- const transform = cameraGroup!.getAttribute('transform');
302
- expect(transform).not.toBeNull();
303
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
304
- expect(scaleMatch).not.toBeNull();
305
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
306
-
307
- instance.destroy();
308
- });
309
-
310
- it('chrome paints after the map group so the title sits above a zoomed map', () => {
311
- const chromeSpec = {
312
- ...basicMapSpec,
313
- chrome: { title: 'Test Title' },
314
- };
315
- const instance = createMap(container, chromeSpec, { responsive: false });
316
-
317
- const svg = container.querySelector('svg')!;
318
- const kids = [...svg.children];
319
- const mapGroupIdx = kids.findIndex((k) => k.classList.contains('oc-map-group'));
320
- const chromeIdx = kids.findIndex((k) => k.classList.contains('oc-chrome'));
321
- expect(mapGroupIdx).toBeGreaterThanOrEqual(0);
322
- expect(chromeIdx).toBeGreaterThan(mapGroupIdx);
323
-
324
- instance.destroy();
325
- });
326
-
327
- it('features outside geo.focus rest at the dim opacity', () => {
328
- const focusSpec = {
329
- ...basicMapSpec,
330
- geo: { ...basicMapSpec.geo, focus: '36' },
331
- };
332
- const instance = createMap(container, focusSpec, { responsive: false });
333
-
334
- const focused = container.querySelector('.oc-map-feature[data-feature-id="36"]') as SVGElement;
335
- const dimmed = container.querySelector('.oc-map-feature[data-feature-id="06"]') as SVGElement;
336
- expect(focused).not.toBeNull();
337
- expect(dimmed).not.toBeNull();
338
- // Focused feature is full opacity; a feature outside the focus set is dimmed.
339
- expect(dimmed.style.opacity).toBe('0.25');
340
- expect(focused.style.opacity === '' || focused.style.opacity === '1').toBe(true);
341
-
342
- instance.destroy();
343
- });
344
-
345
- // ---------------------------------------------------------------------------
346
- // Point layer rendering
347
- // ---------------------------------------------------------------------------
348
-
349
- describe('point layer', () => {
350
- const pointSpec = {
351
- type: 'map' as const,
352
- geo: { features: MINI_TOPO, projection: 'mercator' as const },
353
- data: [],
354
- encoding: {
355
- key: { field: 'id', type: 'nominal' as const },
356
- },
357
- points: {
358
- data: [
359
- { lat: 34, lon: -118, name: 'LA', value: 100 },
360
- { lat: 40.7, lon: -74, name: 'NYC', value: 500 },
361
- ],
362
- longitude: { field: 'lon', type: 'quantitative' as const },
363
- latitude: { field: 'lat', type: 'quantitative' as const },
364
- size: { field: 'value', type: 'quantitative' as const },
365
- key: { field: 'name', type: 'nominal' as const },
366
- },
367
- };
368
-
369
- it('renders point circles inside camera group', () => {
370
- const instance = createMap(container, pointSpec, { responsive: false });
371
-
372
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
373
- expect(cameraGroup).not.toBeNull();
374
-
375
- const points = cameraGroup!.querySelectorAll('.oc-map-point');
376
- expect(points.length).toBe(2);
377
-
378
- instance.destroy();
379
- });
380
-
381
- it('stores data-base-r on point circles', () => {
382
- const instance = createMap(container, pointSpec, { responsive: false });
383
-
384
- const points = container.querySelectorAll('.oc-map-point');
385
- expect(points.length).toBe(2);
386
-
387
- for (const p of points) {
388
- const baseR = p.getAttribute('data-base-r');
389
- expect(baseR).not.toBeNull();
390
- const r = p.getAttribute('r');
391
- expect(r).not.toBeNull();
392
- expect(baseR).toBe(r);
393
- }
394
-
395
- instance.destroy();
396
- });
397
-
398
- it('counter-scales radius when camera is zoomed', () => {
399
- const instance = createMap(container, pointSpec, { responsive: false });
400
-
401
- // Grab initial radii
402
- const pointsBefore = container.querySelectorAll('.oc-map-point');
403
- const initialRadii = Array.from(pointsBefore).map((p) =>
404
- Number(p.getAttribute('data-base-r')),
405
- );
406
- expect(initialRadii.length).toBe(2);
407
- for (const r of initialRadii) {
408
- expect(r).toBeGreaterThan(0);
409
- }
410
-
411
- // Zoom to New York which will scale > 1
412
- instance.zoomTo('36', { duration: 0 });
413
-
414
- // After zoom, r should be smaller than base-r (counter-scaled)
415
- const pointsAfter = container.querySelectorAll('.oc-map-point');
416
- for (let i = 0; i < pointsAfter.length; i++) {
417
- const currentR = Number(pointsAfter[i].getAttribute('r'));
418
- const baseR = Number(pointsAfter[i].getAttribute('data-base-r'));
419
- expect(currentR).toBeLessThan(baseR);
420
- }
421
-
422
- instance.destroy();
423
- });
424
-
425
- it('geo.focus with points: true applies camera zoom on first render', () => {
426
- const focusPointsSpec = {
427
- ...pointSpec,
428
- geo: { ...pointSpec.geo, focus: { points: true, padding: 8 } },
429
- animation: false,
430
- };
431
- const instance = createMap(container, focusPointsSpec, { responsive: false });
432
-
433
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
434
- expect(cameraGroup).not.toBeNull();
435
-
436
- const transform = cameraGroup!.getAttribute('transform');
437
- expect(transform).not.toBeNull();
438
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
439
- expect(scaleMatch).not.toBeNull();
440
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
441
-
442
- instance.destroy();
443
- });
444
-
445
- it('geo.focus with points: true applies camera zoom even with entrance animation', () => {
446
- const focusPointsSpec = {
447
- ...pointSpec,
448
- geo: { ...pointSpec.geo, focus: { points: true, padding: 8 } },
449
- animation: true,
450
- };
451
- const instance = createMap(container, focusPointsSpec, { responsive: false });
452
-
453
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
454
- expect(cameraGroup).not.toBeNull();
455
-
456
- const transform = cameraGroup!.getAttribute('transform');
457
- expect(transform).not.toBeNull();
458
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
459
- expect(scaleMatch).not.toBeNull();
460
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
461
-
462
- instance.destroy();
463
- });
464
-
465
- it('resize() preserves points focus camera', () => {
466
- const focusPointsSpec = {
467
- ...pointSpec,
468
- geo: { ...pointSpec.geo, focus: { points: true, padding: 8 } },
469
- animation: false,
470
- };
471
- const instance = createMap(container, focusPointsSpec, { responsive: false });
472
-
473
- // First render should have camera applied
474
- const cameraGroup1 = container.querySelector('[data-oc-map-camera]');
475
- expect(cameraGroup1!.getAttribute('transform')).not.toBeNull();
476
-
477
- // Simulate a resize
478
- instance.resize();
479
-
480
- // Camera should still be applied after resize
481
- const cameraGroup2 = container.querySelector('[data-oc-map-camera]');
482
- expect(cameraGroup2).not.toBeNull();
483
- const transform = cameraGroup2!.getAttribute('transform');
484
- expect(transform).not.toBeNull();
485
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
486
- expect(scaleMatch).not.toBeNull();
487
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
488
-
489
- instance.destroy();
490
- });
491
-
492
- it('geo.focus with points filter applies camera zoom on first render', () => {
493
- const focusPointsSpec = {
494
- ...pointSpec,
495
- geo: {
496
- ...pointSpec.geo,
497
- focus: { points: { field: 'name', value: 'NYC' }, padding: 12 },
498
- },
499
- animation: false,
500
- };
501
- const instance = createMap(container, focusPointsSpec, { responsive: false });
502
-
503
- const cameraGroup = container.querySelector('[data-oc-map-camera]');
504
- expect(cameraGroup).not.toBeNull();
505
-
506
- const transform = cameraGroup!.getAttribute('transform');
507
- expect(transform).not.toBeNull();
508
- const scaleMatch = transform!.match(/scale\(([\d.]+)\)/);
509
- expect(scaleMatch).not.toBeNull();
510
- expect(Number(scaleMatch![1])).toBeGreaterThan(1);
511
-
512
- instance.destroy();
513
- });
514
-
515
- it('update() with changed points focus drives camera (tween)', () => {
516
- const spec1 = {
517
- ...pointSpec,
518
- geo: { ...pointSpec.geo, focus: { points: true, padding: 8 } },
519
- animation: false,
520
- };
521
- const instance = createMap(container, spec1, { responsive: false });
522
-
523
- const transform1 = container.querySelector('[data-oc-map-camera]')!.getAttribute('transform');
524
- expect(transform1).not.toBeNull();
525
-
526
- // Mock reduced-motion AFTER createMap so it only affects update()'s
527
- // driveCamera() call, making the tween snap instantly.
528
- const spy = mockReducedMotion();
529
-
530
- const spec2 = {
531
- ...pointSpec,
532
- geo: {
533
- ...pointSpec.geo,
534
- focus: { points: { field: 'name', value: 'NYC' }, padding: 12 },
535
- },
536
- animation: false,
537
- };
538
- instance.update(spec2);
539
-
540
- // Re-query after update (render creates a new SVG)
541
- const transform2 = container.querySelector('[data-oc-map-camera]')!.getAttribute('transform');
542
- expect(transform2).not.toBeNull();
543
- expect(transform2).not.toBe(transform1);
544
-
545
- spy.mockRestore();
546
- instance.destroy();
547
- });
548
-
549
- it('update() null -> features -> points -> null preserves camera at each step', () => {
550
- // Reproduces the scrollytelling sequence: full view -> zoom to counties ->
551
- // zoom to points cluster -> back to full view
552
- const spy = mockReducedMotion();
553
-
554
- // Step 0: no focus
555
- const specStep0 = {
556
- ...pointSpec,
557
- geo: { ...pointSpec.geo, focus: null },
558
- animation: false,
559
- };
560
- const instance = createMap(container, specStep0, { responsive: false });
561
- const cg0 = container.querySelector('[data-oc-map-camera]')!;
562
- expect(cg0.getAttribute('transform')).toBeNull();
563
-
564
- // Step 1: feature focus
565
- const specStep1 = {
566
- ...pointSpec,
567
- geo: { ...pointSpec.geo, focus: { features: ['48'], padding: 0 } },
568
- animation: false,
569
- };
570
- instance.update(specStep1);
571
- const cg1 = container.querySelector('[data-oc-map-camera]')!;
572
- const t1 = cg1.getAttribute('transform');
573
- expect(t1).not.toBeNull();
574
- const scale1 = Number(t1!.match(/scale\(([\d.]+)\)/)![1]);
575
- expect(scale1).toBeGreaterThan(1);
576
-
577
- // Step 2: points focus (the transition that breaks in production)
578
- const specStep2 = {
579
- ...pointSpec,
580
- geo: {
581
- ...pointSpec.geo,
582
- focus: { points: { field: 'name', value: 'NYC' }, padding: 0 },
583
- },
584
- animation: false,
585
- };
586
- instance.update(specStep2);
587
- const cg2 = container.querySelector('[data-oc-map-camera]')!;
588
- const t2 = cg2.getAttribute('transform');
589
- expect(t2).not.toBeNull();
590
- const scale2 = Number(t2!.match(/scale\(([\d.]+)\)/)![1]);
591
- expect(scale2).toBeGreaterThan(1);
592
-
593
- // Step 3: back to null
594
- const specStep3 = {
595
- ...pointSpec,
596
- geo: { ...pointSpec.geo, focus: null },
597
- animation: false,
598
- };
599
- instance.update(specStep3);
600
- const cg3 = container.querySelector('[data-oc-map-camera]')!;
601
- expect(cg3.getAttribute('transform')).toBeNull();
602
-
603
- spy.mockRestore();
604
- instance.destroy();
605
- });
606
-
607
- it('update() from points focus to null resets camera', () => {
608
- const spec1 = {
609
- ...pointSpec,
610
- geo: { ...pointSpec.geo, focus: { points: true, padding: 8 } },
611
- animation: false,
612
- };
613
- const instance = createMap(container, spec1, { responsive: false });
614
-
615
- expect(
616
- container.querySelector('[data-oc-map-camera]')!.getAttribute('transform'),
617
- ).not.toBeNull();
618
-
619
- const spy = mockReducedMotion();
620
-
621
- const spec2 = {
622
- ...pointSpec,
623
- geo: { ...pointSpec.geo, focus: null },
624
- animation: false,
625
- };
626
- instance.update(spec2);
627
-
628
- // Re-query after update
629
- const transform = container.querySelector('[data-oc-map-camera]')!.getAttribute('transform');
630
- expect(transform).toBeNull();
631
-
632
- spy.mockRestore();
633
- instance.destroy();
634
- });
635
- });
636
- });