@opendata-ai/openchart-vanilla 8.0.0-rc.2 → 8.0.0-rc.21
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-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-ENXSUXC5.js → chunk-KNT5AZ2O.js} +7309 -5490
- package/dist/chunk-KNT5AZ2O.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 +283 -24
- package/dist/index.js +2012 -763
- package/dist/index.js.map +1 -1
- package/dist/{mount-CUKQLeqD.d.ts → mount-Dvv8NYIv.d.ts} +117 -3
- package/dist/simulation-worker.js +83 -2
- package/dist/static.js +7 -69
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +3 -2
- package/dist/story/index.js +5 -3
- 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-ENXSUXC5.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 -902
- 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 -293
- 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 -1777
- 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 -88
- package/src/map-mount.ts +0 -701
- package/src/map-renderer.ts +0 -338
- package/src/map-transition.ts +0 -83
- 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,280 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Annotation,
|
|
3
|
-
ChartLayout,
|
|
4
|
-
ChartSpec,
|
|
5
|
-
ChromeKey,
|
|
6
|
-
ElementRef,
|
|
7
|
-
GraphSpec,
|
|
8
|
-
LayerSpec,
|
|
9
|
-
TextAnnotation,
|
|
10
|
-
} from '@opendata-ai/openchart-core';
|
|
11
|
-
import { elementRef } from '@opendata-ai/openchart-core';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Find a DOM element inside the SVG that matches the given ElementRef.
|
|
15
|
-
*/
|
|
16
|
-
export function findElementByRef(svg: SVGElement, ref: ElementRef): SVGElement | null {
|
|
17
|
-
switch (ref.type) {
|
|
18
|
-
case 'annotation': {
|
|
19
|
-
if (ref.id) {
|
|
20
|
-
const byId = svg.querySelector(`[data-annotation-id="${ref.id}"]`);
|
|
21
|
-
if (byId) return byId as SVGElement;
|
|
22
|
-
}
|
|
23
|
-
return svg.querySelector(`[data-annotation-index="${ref.index}"]`) as SVGElement | null;
|
|
24
|
-
}
|
|
25
|
-
case 'chrome':
|
|
26
|
-
return svg.querySelector(`[data-chrome-key="${ref.key}"]`) as SVGElement | null;
|
|
27
|
-
case 'series-label':
|
|
28
|
-
return svg.querySelector(`.oc-mark-label[data-series="${ref.series}"]`) as SVGElement | null;
|
|
29
|
-
// The editable legend is the color legend. Excluding the size legend
|
|
30
|
-
// explicitly rather than relying on it rendering second: `querySelector`
|
|
31
|
-
// takes the first match, so a bare `.oc-legend` would silently retarget
|
|
32
|
-
// (and drag) the wrong legend if render order ever changed.
|
|
33
|
-
case 'legend':
|
|
34
|
-
return svg.querySelector('.oc-legend:not(.oc-legend--size)') as SVGElement | null;
|
|
35
|
-
case 'legend-entry':
|
|
36
|
-
return svg.querySelector(
|
|
37
|
-
`.oc-legend:not(.oc-legend--size) [data-legend-index="${ref.index}"]`,
|
|
38
|
-
) as SVGElement | null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Build an ElementRef from a DOM element's data attributes.
|
|
44
|
-
*/
|
|
45
|
-
export function buildElementRef(
|
|
46
|
-
element: Element,
|
|
47
|
-
_specAnnotations: Annotation[],
|
|
48
|
-
): ElementRef | null {
|
|
49
|
-
const annotationEl = element.closest('[data-annotation-index]');
|
|
50
|
-
if (annotationEl) {
|
|
51
|
-
const index = Number(annotationEl.getAttribute('data-annotation-index'));
|
|
52
|
-
const id = annotationEl.getAttribute('data-annotation-id') ?? undefined;
|
|
53
|
-
return elementRef.annotation(index, id);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const chromeEl = element.closest('[data-chrome-key]');
|
|
57
|
-
if (chromeEl) {
|
|
58
|
-
const key = chromeEl.getAttribute('data-chrome-key') as ChromeKey;
|
|
59
|
-
if (key) return elementRef.chrome(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const seriesLabelEl = element.closest('.oc-mark-label[data-series]');
|
|
63
|
-
if (seriesLabelEl) {
|
|
64
|
-
const series = seriesLabelEl.getAttribute('data-series');
|
|
65
|
-
if (series) return elementRef.seriesLabel(series);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const legendEntryEl = element.closest('[data-legend-index]');
|
|
69
|
-
if (legendEntryEl) {
|
|
70
|
-
const index = Number(legendEntryEl.getAttribute('data-legend-index'));
|
|
71
|
-
const series = legendEntryEl.getAttribute('data-legend-label') ?? '';
|
|
72
|
-
return elementRef.legendEntry(series, index);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Only the color legend is selectable/editable. A click inside the size legend
|
|
76
|
-
// resolves to no ref rather than reporting the *color* legend's ref, which is
|
|
77
|
-
// what a bare `.oc-legend` match would do.
|
|
78
|
-
const legendEl = element.closest('.oc-legend');
|
|
79
|
-
if (legendEl && !legendEl.classList.contains('oc-legend--size')) return elementRef.legend();
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get an ordered list of all editable ElementRefs from the current spec and layout.
|
|
86
|
-
*/
|
|
87
|
-
export function getEditableElements(
|
|
88
|
-
spec: ChartSpec | LayerSpec | GraphSpec,
|
|
89
|
-
layout: ChartLayout,
|
|
90
|
-
): ElementRef[] {
|
|
91
|
-
const refs: ElementRef[] = [];
|
|
92
|
-
|
|
93
|
-
const chromeKeys: ChromeKey[] = ['title', 'subtitle', 'source', 'byline', 'footer'];
|
|
94
|
-
for (const key of chromeKeys) {
|
|
95
|
-
if (layout.chrome[key]) {
|
|
96
|
-
refs.push(elementRef.chrome(key));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const annotations: Annotation[] =
|
|
101
|
-
'annotations' in spec && Array.isArray(spec.annotations) ? spec.annotations : [];
|
|
102
|
-
for (let i = 0; i < annotations.length; i++) {
|
|
103
|
-
refs.push(elementRef.annotation(i, annotations[i].id));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const seriesLabels: string[] = [];
|
|
107
|
-
for (const mark of layout.marks) {
|
|
108
|
-
if (mark.type === 'line' && mark.label?.visible && mark.seriesKey) {
|
|
109
|
-
seriesLabels.push(mark.seriesKey);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
seriesLabels.sort();
|
|
113
|
-
for (const series of seriesLabels) {
|
|
114
|
-
refs.push(elementRef.seriesLabel(series));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if ('entries' in layout.legend && layout.legend.entries.length > 0) {
|
|
118
|
-
refs.push(elementRef.legend());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return refs;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Check if an ElementRef points to a text-editable element.
|
|
126
|
-
*/
|
|
127
|
-
export function isTextEditable(ref: ElementRef, specAnnotations: Annotation[]): boolean {
|
|
128
|
-
if (ref.type === 'chrome') return true;
|
|
129
|
-
if (ref.type === 'annotation') {
|
|
130
|
-
const annotation = specAnnotations[ref.index];
|
|
131
|
-
return annotation?.type === 'text';
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Get the current text content for an element ref.
|
|
138
|
-
*/
|
|
139
|
-
export function getElementText(
|
|
140
|
-
ref: ElementRef,
|
|
141
|
-
spec: ChartSpec | LayerSpec | GraphSpec,
|
|
142
|
-
): string | null {
|
|
143
|
-
if (ref.type === 'chrome') {
|
|
144
|
-
const chromeConfig = 'chrome' in spec ? spec.chrome : undefined;
|
|
145
|
-
if (!chromeConfig) return null;
|
|
146
|
-
const entry = chromeConfig[ref.key];
|
|
147
|
-
if (typeof entry === 'string') return entry;
|
|
148
|
-
if (typeof entry === 'object' && entry !== null && 'text' in entry) {
|
|
149
|
-
return (entry as { text: string }).text;
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
if (ref.type === 'annotation') {
|
|
154
|
-
const annotations: Annotation[] =
|
|
155
|
-
'annotations' in spec && Array.isArray(spec.annotations) ? spec.annotations : [];
|
|
156
|
-
const annotation = annotations[ref.index];
|
|
157
|
-
if (annotation?.type === 'text') return (annotation as TextAnnotation).text ?? null;
|
|
158
|
-
if (annotation?.label) return annotation.label;
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Compare two ElementRefs for equality.
|
|
166
|
-
*/
|
|
167
|
-
export function refsEqual(a: ElementRef | null, b: ElementRef | null): boolean {
|
|
168
|
-
if (a === null || b === null) return a === b;
|
|
169
|
-
if (a.type !== b.type) return false;
|
|
170
|
-
switch (a.type) {
|
|
171
|
-
case 'annotation': {
|
|
172
|
-
const bAnno = b as typeof a;
|
|
173
|
-
if (a.id && bAnno.id) return a.id === bAnno.id;
|
|
174
|
-
return a.index === bAnno.index;
|
|
175
|
-
}
|
|
176
|
-
case 'chrome':
|
|
177
|
-
return a.key === (b as typeof a).key;
|
|
178
|
-
case 'series-label':
|
|
179
|
-
return a.series === (b as typeof a).series;
|
|
180
|
-
case 'legend':
|
|
181
|
-
return true;
|
|
182
|
-
case 'legend-entry': {
|
|
183
|
-
const bEntry = b as typeof a;
|
|
184
|
-
return a.index === bEntry.index && a.series === bEntry.series;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Render a selection overlay rectangle around a target element.
|
|
191
|
-
*/
|
|
192
|
-
export function renderSelectionOverlay(
|
|
193
|
-
svg: SVGElement,
|
|
194
|
-
ref: ElementRef,
|
|
195
|
-
layout: ChartLayout,
|
|
196
|
-
): SVGGElement | null {
|
|
197
|
-
const target = findElementByRef(svg, ref);
|
|
198
|
-
if (!target) return null;
|
|
199
|
-
|
|
200
|
-
const bbox = (target as SVGGraphicsElement).getBBox();
|
|
201
|
-
const padding = 4;
|
|
202
|
-
|
|
203
|
-
const accentColor = layout.theme.colors.categorical?.[0] ?? '#4f46e5';
|
|
204
|
-
|
|
205
|
-
const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
206
|
-
g.setAttribute('class', 'oc-selection-overlay');
|
|
207
|
-
|
|
208
|
-
const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
209
|
-
rect.setAttribute('x', String(bbox.x - padding));
|
|
210
|
-
rect.setAttribute('y', String(bbox.y - padding));
|
|
211
|
-
rect.setAttribute('width', String(bbox.width + padding * 2));
|
|
212
|
-
rect.setAttribute('height', String(bbox.height + padding * 2));
|
|
213
|
-
rect.setAttribute('rx', '3');
|
|
214
|
-
rect.setAttribute('fill', 'transparent');
|
|
215
|
-
rect.setAttribute('stroke', accentColor);
|
|
216
|
-
rect.setAttribute('stroke-width', '1.5');
|
|
217
|
-
rect.setAttribute('pointer-events', 'none');
|
|
218
|
-
|
|
219
|
-
g.appendChild(rect);
|
|
220
|
-
svg.appendChild(g);
|
|
221
|
-
|
|
222
|
-
return g;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Create a visually-hidden data table from the chart's a11y fallback data.
|
|
227
|
-
*/
|
|
228
|
-
export function createScreenReaderTable(
|
|
229
|
-
layout: ChartLayout,
|
|
230
|
-
container: HTMLElement,
|
|
231
|
-
): HTMLTableElement | null {
|
|
232
|
-
const data = layout.a11y.dataTableFallback;
|
|
233
|
-
if (!data || data.length === 0) return null;
|
|
234
|
-
|
|
235
|
-
const table = document.createElement('table');
|
|
236
|
-
table.className = 'oc-sr-only';
|
|
237
|
-
table.style.position = 'absolute';
|
|
238
|
-
table.style.width = '1px';
|
|
239
|
-
table.style.height = '1px';
|
|
240
|
-
table.style.padding = '0';
|
|
241
|
-
table.style.margin = '-1px';
|
|
242
|
-
table.style.overflow = 'hidden';
|
|
243
|
-
table.style.clipPath = 'inset(50%)';
|
|
244
|
-
table.style.whiteSpace = 'nowrap';
|
|
245
|
-
table.style.borderWidth = '0';
|
|
246
|
-
table.setAttribute('role', 'table');
|
|
247
|
-
table.setAttribute('aria-label', `Data table: ${layout.a11y.altText}`);
|
|
248
|
-
|
|
249
|
-
if (data.length > 0) {
|
|
250
|
-
const thead = document.createElement('thead');
|
|
251
|
-
const headerRow = document.createElement('tr');
|
|
252
|
-
const headers = data[0] as unknown[];
|
|
253
|
-
for (const header of headers) {
|
|
254
|
-
const th = document.createElement('th');
|
|
255
|
-
th.textContent = String(header ?? '');
|
|
256
|
-
th.setAttribute('scope', 'col');
|
|
257
|
-
headerRow.appendChild(th);
|
|
258
|
-
}
|
|
259
|
-
thead.appendChild(headerRow);
|
|
260
|
-
table.appendChild(thead);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (data.length > 1) {
|
|
264
|
-
const tbody = document.createElement('tbody');
|
|
265
|
-
for (let i = 1; i < data.length; i++) {
|
|
266
|
-
const tr = document.createElement('tr');
|
|
267
|
-
const cells = data[i] as unknown[];
|
|
268
|
-
for (const cell of cells) {
|
|
269
|
-
const td = document.createElement('td');
|
|
270
|
-
td.textContent = String(cell ?? '');
|
|
271
|
-
tr.appendChild(td);
|
|
272
|
-
}
|
|
273
|
-
tbody.appendChild(tr);
|
|
274
|
-
}
|
|
275
|
-
table.appendChild(tbody);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
container.appendChild(table);
|
|
279
|
-
return table;
|
|
280
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { TooltipContent } from '@opendata-ai/openchart-core';
|
|
2
|
-
import type { TooltipManager } from '../tooltip';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Wire tooltip events on mark elements inside an SVG.
|
|
6
|
-
* Returns a cleanup function to remove all listeners.
|
|
7
|
-
*/
|
|
8
|
-
export function wireTooltipEvents(
|
|
9
|
-
svg: SVGElement,
|
|
10
|
-
tooltipDescriptors: Map<string, TooltipContent>,
|
|
11
|
-
tooltipManager: TooltipManager,
|
|
12
|
-
): () => void {
|
|
13
|
-
const markElements = svg.querySelectorAll('[data-mark-id]');
|
|
14
|
-
const cleanups: Array<() => void> = [];
|
|
15
|
-
|
|
16
|
-
for (const el of markElements) {
|
|
17
|
-
const markId = el.getAttribute('data-mark-id');
|
|
18
|
-
if (!markId) continue;
|
|
19
|
-
|
|
20
|
-
const content = tooltipDescriptors.get(markId);
|
|
21
|
-
if (!content) continue;
|
|
22
|
-
|
|
23
|
-
const handleMouseEnter = (e: Event) => {
|
|
24
|
-
const mouseEvent = e as MouseEvent;
|
|
25
|
-
const svgRect = svg.getBoundingClientRect();
|
|
26
|
-
const x = mouseEvent.clientX - svgRect.left;
|
|
27
|
-
const y = mouseEvent.clientY - svgRect.top;
|
|
28
|
-
tooltipManager.show(content, x, y);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const handleMouseMove = (e: Event) => {
|
|
32
|
-
const mouseEvent = e as MouseEvent;
|
|
33
|
-
const svgRect = svg.getBoundingClientRect();
|
|
34
|
-
const x = mouseEvent.clientX - svgRect.left;
|
|
35
|
-
const y = mouseEvent.clientY - svgRect.top;
|
|
36
|
-
tooltipManager.show(content, x, y);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const handleMouseLeave = () => {
|
|
40
|
-
tooltipManager.hide();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const handleTouchStart = (e: Event) => {
|
|
44
|
-
const touchEvent = e as TouchEvent;
|
|
45
|
-
if (touchEvent.touches.length > 0) {
|
|
46
|
-
const touch = touchEvent.touches[0];
|
|
47
|
-
const svgRect = svg.getBoundingClientRect();
|
|
48
|
-
const x = touch.clientX - svgRect.left;
|
|
49
|
-
const y = touch.clientY - svgRect.top;
|
|
50
|
-
tooltipManager.show(content, x, y);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
el.addEventListener('mouseenter', handleMouseEnter);
|
|
55
|
-
el.addEventListener('mousemove', handleMouseMove);
|
|
56
|
-
el.addEventListener('mouseleave', handleMouseLeave);
|
|
57
|
-
el.addEventListener('touchstart', handleTouchStart);
|
|
58
|
-
|
|
59
|
-
cleanups.push(() => {
|
|
60
|
-
el.removeEventListener('mouseenter', handleMouseEnter);
|
|
61
|
-
el.removeEventListener('mousemove', handleMouseMove);
|
|
62
|
-
el.removeEventListener('mouseleave', handleMouseLeave);
|
|
63
|
-
el.removeEventListener('touchstart', handleTouchStart);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return () => {
|
|
68
|
-
for (const cleanup of cleanups) {
|
|
69
|
-
cleanup();
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
package/src/map-camera.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map camera utilities: zoom, pan, and focus for map visualizations.
|
|
3
|
-
*
|
|
4
|
-
* Reuses the existing camera-math infrastructure from the scrollytelling
|
|
5
|
-
* system. The camera transform is applied as an SVG `transform` attribute
|
|
6
|
-
* on the `[data-oc-map-camera]` group, never as a CSS transform.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { MapLayout } from '@opendata-ai/openchart-core';
|
|
10
|
-
import type { Camera, CameraTarget } from './story/camera-math';
|
|
11
|
-
import { cameraTransform, FULL_VIEW, fitTarget } from './story/camera-math';
|
|
12
|
-
|
|
13
|
-
export type { Camera } from './story/camera-math';
|
|
14
|
-
|
|
15
|
-
export interface MapCameraOptions {
|
|
16
|
-
/** Transition duration in ms. 0 snaps instantly. Default 600. */
|
|
17
|
-
duration?: number;
|
|
18
|
-
/** Padding in map-local units around the target. Default 16. */
|
|
19
|
-
padding?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Compute a CameraTarget from the union of feature bounds.
|
|
24
|
-
* Returns null if no matching features found.
|
|
25
|
-
*/
|
|
26
|
-
export function focusTargetForFeatures(
|
|
27
|
-
layout: MapLayout,
|
|
28
|
-
ids: Array<string | number>,
|
|
29
|
-
padding = 16,
|
|
30
|
-
): CameraTarget | null {
|
|
31
|
-
const idSet = new Set(ids.map(String));
|
|
32
|
-
let minX = Infinity;
|
|
33
|
-
let minY = Infinity;
|
|
34
|
-
let maxX = -Infinity;
|
|
35
|
-
let maxY = -Infinity;
|
|
36
|
-
let found = false;
|
|
37
|
-
|
|
38
|
-
for (const f of layout.features) {
|
|
39
|
-
if (idSet.has(String(f.id))) {
|
|
40
|
-
found = true;
|
|
41
|
-
minX = Math.min(minX, f.bounds.x);
|
|
42
|
-
minY = Math.min(minY, f.bounds.y);
|
|
43
|
-
maxX = Math.max(maxX, f.bounds.x + f.bounds.width);
|
|
44
|
-
maxY = Math.max(maxY, f.bounds.y + f.bounds.height);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!found) return null;
|
|
49
|
-
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY, padding };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Compute the Camera for a target, fitting against mapSize.
|
|
54
|
-
* Returns the full-view camera if no target provided.
|
|
55
|
-
*/
|
|
56
|
-
export function cameraForTarget(layout: MapLayout, target?: CameraTarget | null): Camera {
|
|
57
|
-
const vb = layout.mapSize;
|
|
58
|
-
if (!target) return fitTarget(FULL_VIEW(vb), vb);
|
|
59
|
-
const cam = fitTarget(target, vb);
|
|
60
|
-
return { ...cam, k: Math.max(1, Math.min(40, cam.k)) };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Apply a camera transform to the map's camera group.
|
|
65
|
-
* Toggles vector-effect="non-scaling-stroke" on features/borders while zoomed.
|
|
66
|
-
*/
|
|
67
|
-
export function applyMapCamera(svg: SVGElement, camera: Camera, layout: MapLayout): void {
|
|
68
|
-
const cameraGroup = svg.querySelector('[data-oc-map-camera]');
|
|
69
|
-
if (!cameraGroup) return;
|
|
70
|
-
|
|
71
|
-
const vb = layout.mapSize;
|
|
72
|
-
const isZoomed = Math.abs(camera.k - 1) > 1e-3;
|
|
73
|
-
|
|
74
|
-
if (isZoomed) {
|
|
75
|
-
cameraGroup.setAttribute('transform', cameraTransform(camera, vb));
|
|
76
|
-
// Toggle non-scaling-stroke so strokes don't fatten when zoomed
|
|
77
|
-
const paths = svg.querySelectorAll('.oc-map-feature, .oc-map-borders path');
|
|
78
|
-
for (const p of paths) {
|
|
79
|
-
p.setAttribute('vector-effect', 'non-scaling-stroke');
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
cameraGroup.removeAttribute('transform');
|
|
83
|
-
const paths = svg.querySelectorAll('.oc-map-feature, .oc-map-borders path');
|
|
84
|
-
for (const p of paths) {
|
|
85
|
-
p.removeAttribute('vector-effect');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|