@opendata-ai/openchart-vanilla 8.0.0-rc.9 → 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-SPILUE5S.js → chunk-2NAQRP66.js} +2 -2
- package/dist/{chunk-IZQBT6QM.js → chunk-6BUCYCLD.js} +7283 -5881
- 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-QW7ZB6NE.js → chunk-EKAUQAAX.js} +49 -45
- 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-IZQBT6QM.js.map +0 -1
- package/dist/chunk-QW7ZB6NE.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 -1477
- package/src/__tests__/editable-prop.test.ts +0 -174
- 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__/invert.test.ts +0 -187
- 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 -1062
- 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 -649
- package/src/interactions/index.ts +0 -27
- package/src/interactions/invert.ts +0 -54
- package/src/interactions/keyboard-nav.ts +0 -111
- package/src/interactions/legend-interaction.ts +0 -46
- package/src/interactions/selection.ts +0 -286
- package/src/interactions/tooltip-events.ts +0 -72
- package/src/map-camera.ts +0 -111
- package/src/map-mount.ts +0 -797
- package/src/map-renderer.ts +0 -476
- package/src/map-transition.ts +0 -99
- package/src/measure-text.ts +0 -134
- package/src/mount.ts +0 -1434
- 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 -312
- 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 -389
- 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-SPILUE5S.js.map → chunk-2NAQRP66.js.map} +0 -0
|
@@ -1,649 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Annotation,
|
|
3
|
-
type AnnotationOffset,
|
|
4
|
-
type ChartLayout,
|
|
5
|
-
type ChartSpec,
|
|
6
|
-
type ChromeKey,
|
|
7
|
-
type ElementEdit,
|
|
8
|
-
elementRef,
|
|
9
|
-
type GraphSpec,
|
|
10
|
-
type RangeAnnotation,
|
|
11
|
-
type RefLineAnnotation,
|
|
12
|
-
type TextAnnotation,
|
|
13
|
-
} from '@opendata-ai/openchart-core';
|
|
14
|
-
import { createDragHandler } from './drag-handler';
|
|
15
|
-
import { invertScale } from './invert';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Wire drag-to-reposition on text annotation labels.
|
|
19
|
-
* Returns a cleanup function to remove all listeners.
|
|
20
|
-
*/
|
|
21
|
-
export function wireAnnotationDrag(
|
|
22
|
-
svg: SVGElement,
|
|
23
|
-
specAnnotations: Annotation[],
|
|
24
|
-
onAnnotationEdit:
|
|
25
|
-
| ((annotation: TextAnnotation, updatedOffset: AnnotationOffset) => void)
|
|
26
|
-
| undefined,
|
|
27
|
-
onEdit: ((edit: ElementEdit) => void) | undefined,
|
|
28
|
-
setDragging: (dragging: boolean) => void,
|
|
29
|
-
): () => void {
|
|
30
|
-
const annotationElements = svg.querySelectorAll('.oc-annotation-text');
|
|
31
|
-
const cleanups: Array<() => void> = [];
|
|
32
|
-
|
|
33
|
-
for (const el of annotationElements) {
|
|
34
|
-
const indexStr = el.getAttribute('data-annotation-index');
|
|
35
|
-
if (indexStr === null) continue;
|
|
36
|
-
|
|
37
|
-
const index = Number(indexStr);
|
|
38
|
-
const specAnnotation = specAnnotations[index];
|
|
39
|
-
if (!specAnnotation || specAnnotation.type !== 'text') continue;
|
|
40
|
-
|
|
41
|
-
const textAnnotation = specAnnotation as TextAnnotation;
|
|
42
|
-
const annotationG = el as SVGGElement;
|
|
43
|
-
|
|
44
|
-
annotationG.style.cursor = 'grab';
|
|
45
|
-
|
|
46
|
-
const connectorLine = annotationG.querySelector('line.oc-annotation-connector');
|
|
47
|
-
const origX2 = connectorLine ? Number(connectorLine.getAttribute('x2')) : 0;
|
|
48
|
-
const origY2 = connectorLine ? Number(connectorLine.getAttribute('y2')) : 0;
|
|
49
|
-
|
|
50
|
-
const curvedPath = annotationG.querySelector('path.oc-annotation-connector');
|
|
51
|
-
const arrowhead = annotationG.querySelector('polyline.oc-annotation-arrowhead');
|
|
52
|
-
const hasCurvedConnector = curvedPath !== null;
|
|
53
|
-
|
|
54
|
-
const origDx = textAnnotation.offset?.dx ?? 0;
|
|
55
|
-
const origDy = textAnnotation.offset?.dy ?? 0;
|
|
56
|
-
|
|
57
|
-
const cleanup = createDragHandler({
|
|
58
|
-
element: annotationG,
|
|
59
|
-
svg: svg as unknown as SVGSVGElement,
|
|
60
|
-
onMove: (dx, dy) => {
|
|
61
|
-
annotationG.setAttribute('transform', `translate(${dx}, ${dy})`);
|
|
62
|
-
|
|
63
|
-
if (connectorLine && !hasCurvedConnector) {
|
|
64
|
-
connectorLine.setAttribute('x2', String(origX2 - dx));
|
|
65
|
-
connectorLine.setAttribute('y2', String(origY2 - dy));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (hasCurvedConnector) {
|
|
69
|
-
if (curvedPath) curvedPath.setAttribute('display', 'none');
|
|
70
|
-
if (arrowhead) arrowhead.setAttribute('display', 'none');
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
onEnd: (dx, dy, moved) => {
|
|
74
|
-
annotationG.removeAttribute('transform');
|
|
75
|
-
|
|
76
|
-
if (connectorLine && !hasCurvedConnector) {
|
|
77
|
-
connectorLine.setAttribute('x2', String(origX2));
|
|
78
|
-
connectorLine.setAttribute('y2', String(origY2));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (hasCurvedConnector) {
|
|
82
|
-
if (curvedPath) curvedPath.removeAttribute('display');
|
|
83
|
-
if (arrowhead) arrowhead.removeAttribute('display');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (moved) {
|
|
87
|
-
const newOffset: AnnotationOffset = {
|
|
88
|
-
dx: origDx + dx,
|
|
89
|
-
dy: origDy + dy,
|
|
90
|
-
};
|
|
91
|
-
onAnnotationEdit?.(textAnnotation, newOffset);
|
|
92
|
-
onEdit?.({
|
|
93
|
-
type: 'annotation',
|
|
94
|
-
element: elementRef.annotation(
|
|
95
|
-
index,
|
|
96
|
-
textAnnotation.id,
|
|
97
|
-
`/annotations/${index}/offset`,
|
|
98
|
-
),
|
|
99
|
-
annotation: textAnnotation,
|
|
100
|
-
offset: newOffset,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
setDragging,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
cleanups.push(cleanup);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return () => {
|
|
111
|
-
for (const cleanup of cleanups) {
|
|
112
|
-
cleanup();
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Wire drag on connector endpoint handles for text annotations.
|
|
119
|
-
* Returns a cleanup function that removes handles and all listeners.
|
|
120
|
-
*/
|
|
121
|
-
export function wireConnectorEndpointDrag(
|
|
122
|
-
svg: SVGElement,
|
|
123
|
-
specAnnotations: Annotation[],
|
|
124
|
-
onEdit: (edit: ElementEdit) => void,
|
|
125
|
-
setDragging: (dragging: boolean) => void,
|
|
126
|
-
): () => void {
|
|
127
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
128
|
-
const cleanups: Array<() => void> = [];
|
|
129
|
-
const annotationGroups = svg.querySelectorAll('.oc-annotation-text');
|
|
130
|
-
|
|
131
|
-
for (const el of annotationGroups) {
|
|
132
|
-
const annotationG = el as SVGGElement;
|
|
133
|
-
const indexStr = annotationG.getAttribute('data-annotation-index');
|
|
134
|
-
if (indexStr === null) continue;
|
|
135
|
-
|
|
136
|
-
const index = Number(indexStr);
|
|
137
|
-
const specAnnotation = specAnnotations[index];
|
|
138
|
-
if (!specAnnotation || specAnnotation.type !== 'text') continue;
|
|
139
|
-
|
|
140
|
-
const textAnnotation = specAnnotation as TextAnnotation;
|
|
141
|
-
|
|
142
|
-
const connectorLine = annotationG.querySelector('line.oc-annotation-connector');
|
|
143
|
-
const curvedPath = annotationG.querySelector('path.oc-annotation-connector');
|
|
144
|
-
if (!connectorLine && !curvedPath) continue;
|
|
145
|
-
|
|
146
|
-
let fromX: number, fromY: number, toX: number, toY: number;
|
|
147
|
-
if (connectorLine) {
|
|
148
|
-
fromX = Number(connectorLine.getAttribute('x1')) || 0;
|
|
149
|
-
fromY = Number(connectorLine.getAttribute('y1')) || 0;
|
|
150
|
-
toX = Number(connectorLine.getAttribute('x2')) || 0;
|
|
151
|
-
toY = Number(connectorLine.getAttribute('y2')) || 0;
|
|
152
|
-
} else {
|
|
153
|
-
const pathD = curvedPath!.getAttribute('d') ?? '';
|
|
154
|
-
const mMatch = pathD.match(/M\s*([\d.e+-]+)\s+([\d.e+-]+)/);
|
|
155
|
-
fromX = mMatch ? Number(mMatch[1]) : 0;
|
|
156
|
-
fromY = mMatch ? Number(mMatch[2]) : 0;
|
|
157
|
-
// The open-V arrowhead is a polyline "baseLeft tip baseRight": the tip is
|
|
158
|
-
// the middle point.
|
|
159
|
-
const arrowhead = annotationG.querySelector('polyline.oc-annotation-arrowhead');
|
|
160
|
-
const points = arrowhead?.getAttribute('points')?.split(' ') ?? [];
|
|
161
|
-
const [px, py] = (points[1] ?? '0,0').split(',');
|
|
162
|
-
toX = Number(px) || 0;
|
|
163
|
-
toY = Number(py) || 0;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const endpoints: Array<{ name: 'from' | 'to'; cx: number; cy: number }> = [
|
|
167
|
-
{ name: 'from', cx: fromX, cy: fromY },
|
|
168
|
-
{ name: 'to', cx: toX, cy: toY },
|
|
169
|
-
];
|
|
170
|
-
|
|
171
|
-
const createdHandles: SVGCircleElement[] = [];
|
|
172
|
-
|
|
173
|
-
for (const ep of endpoints) {
|
|
174
|
-
if (!Number.isFinite(ep.cx) || !Number.isFinite(ep.cy)) continue;
|
|
175
|
-
|
|
176
|
-
const handleEl = document.createElementNS(SVG_NS, 'circle') as SVGCircleElement;
|
|
177
|
-
handleEl.setAttribute('class', 'oc-connector-handle');
|
|
178
|
-
handleEl.setAttribute('data-endpoint', ep.name);
|
|
179
|
-
handleEl.setAttribute('cx', String(ep.cx));
|
|
180
|
-
handleEl.setAttribute('cy', String(ep.cy));
|
|
181
|
-
handleEl.setAttribute('r', '4');
|
|
182
|
-
handleEl.setAttribute('opacity', '0');
|
|
183
|
-
handleEl.setAttribute('fill', 'currentColor');
|
|
184
|
-
handleEl.setAttribute('stroke', 'currentColor');
|
|
185
|
-
annotationG.appendChild(handleEl);
|
|
186
|
-
createdHandles.push(handleEl);
|
|
187
|
-
|
|
188
|
-
const origCx = ep.cx;
|
|
189
|
-
const origCy = ep.cy;
|
|
190
|
-
|
|
191
|
-
const stopProp = (e: Event) => {
|
|
192
|
-
e.stopPropagation();
|
|
193
|
-
};
|
|
194
|
-
handleEl.addEventListener('mousedown', stopProp);
|
|
195
|
-
handleEl.addEventListener('touchstart', stopProp);
|
|
196
|
-
cleanups.push(() => {
|
|
197
|
-
handleEl.removeEventListener('mousedown', stopProp);
|
|
198
|
-
handleEl.removeEventListener('touchstart', stopProp);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const cleanup = createDragHandler({
|
|
202
|
-
element: handleEl,
|
|
203
|
-
svg: svg as unknown as SVGSVGElement,
|
|
204
|
-
onMove: (dx, dy) => {
|
|
205
|
-
handleEl.setAttribute('cx', String(origCx + dx));
|
|
206
|
-
handleEl.setAttribute('cy', String(origCy + dy));
|
|
207
|
-
|
|
208
|
-
if (connectorLine) {
|
|
209
|
-
if (ep.name === 'from') {
|
|
210
|
-
connectorLine.setAttribute('x1', String(origCx + dx));
|
|
211
|
-
connectorLine.setAttribute('y1', String(origCy + dy));
|
|
212
|
-
} else {
|
|
213
|
-
connectorLine.setAttribute('x2', String(origCx + dx));
|
|
214
|
-
connectorLine.setAttribute('y2', String(origCy + dy));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
onEnd: (dx, dy, moved) => {
|
|
219
|
-
handleEl.setAttribute('cx', String(origCx));
|
|
220
|
-
handleEl.setAttribute('cy', String(origCy));
|
|
221
|
-
|
|
222
|
-
if (connectorLine) {
|
|
223
|
-
if (ep.name === 'from') {
|
|
224
|
-
connectorLine.setAttribute('x1', String(origCx));
|
|
225
|
-
connectorLine.setAttribute('y1', String(origCy));
|
|
226
|
-
} else {
|
|
227
|
-
connectorLine.setAttribute('x2', String(origCx));
|
|
228
|
-
connectorLine.setAttribute('y2', String(origCy));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (moved) {
|
|
233
|
-
const existingOffset = textAnnotation.connectorOffset?.[ep.name];
|
|
234
|
-
const origEndDx = existingOffset?.dx ?? 0;
|
|
235
|
-
const origEndDy = existingOffset?.dy ?? 0;
|
|
236
|
-
onEdit({
|
|
237
|
-
type: 'annotation-connector',
|
|
238
|
-
element: elementRef.annotation(
|
|
239
|
-
index,
|
|
240
|
-
textAnnotation.id,
|
|
241
|
-
`/annotations/${index}/connectorOffset/${ep.name}`,
|
|
242
|
-
),
|
|
243
|
-
annotation: textAnnotation,
|
|
244
|
-
endpoint: ep.name,
|
|
245
|
-
offset: { dx: origEndDx + dx, dy: origEndDy + dy },
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
setDragging,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
cleanups.push(cleanup);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const showHandles = () => {
|
|
256
|
-
for (const h of createdHandles) {
|
|
257
|
-
h.setAttribute('opacity', '0.6');
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
const hideHandles = () => {
|
|
261
|
-
for (const h of createdHandles) {
|
|
262
|
-
h.setAttribute('opacity', '0');
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
annotationG.addEventListener('mouseenter', showHandles);
|
|
267
|
-
annotationG.addEventListener('mouseleave', hideHandles);
|
|
268
|
-
cleanups.push(() => {
|
|
269
|
-
annotationG.removeEventListener('mouseenter', showHandles);
|
|
270
|
-
annotationG.removeEventListener('mouseleave', hideHandles);
|
|
271
|
-
for (const h of createdHandles) {
|
|
272
|
-
h.remove();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return () => {
|
|
278
|
-
for (const cleanup of cleanups) {
|
|
279
|
-
cleanup();
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Wire drag on range and refline annotation labels.
|
|
286
|
-
* Returns a cleanup function.
|
|
287
|
-
*/
|
|
288
|
-
export function wireAnnotationLabelDrag(
|
|
289
|
-
svg: SVGElement,
|
|
290
|
-
specAnnotations: Annotation[],
|
|
291
|
-
onEdit: (edit: ElementEdit) => void,
|
|
292
|
-
setDragging: (dragging: boolean) => void,
|
|
293
|
-
): () => void {
|
|
294
|
-
const cleanups: Array<() => void> = [];
|
|
295
|
-
|
|
296
|
-
const selectors = [
|
|
297
|
-
'.oc-annotation-range .oc-annotation-label',
|
|
298
|
-
'.oc-annotation-refline .oc-annotation-label',
|
|
299
|
-
];
|
|
300
|
-
|
|
301
|
-
for (const selector of selectors) {
|
|
302
|
-
const labels = svg.querySelectorAll(selector);
|
|
303
|
-
|
|
304
|
-
for (const label of labels) {
|
|
305
|
-
const annotationG = label.closest('.oc-annotation') as SVGGElement | null;
|
|
306
|
-
if (!annotationG) continue;
|
|
307
|
-
|
|
308
|
-
const indexStr = annotationG.getAttribute('data-annotation-index');
|
|
309
|
-
if (indexStr === null) continue;
|
|
310
|
-
|
|
311
|
-
const index = Number(indexStr);
|
|
312
|
-
const specAnnotation = specAnnotations[index];
|
|
313
|
-
if (!specAnnotation) continue;
|
|
314
|
-
|
|
315
|
-
const labelEl = label as SVGTextElement;
|
|
316
|
-
labelEl.style.cursor = 'grab';
|
|
317
|
-
|
|
318
|
-
const isRange = specAnnotation.type === 'range';
|
|
319
|
-
const existingLabelOffset = isRange
|
|
320
|
-
? (specAnnotation as RangeAnnotation).labelOffset
|
|
321
|
-
: (specAnnotation as RefLineAnnotation).labelOffset;
|
|
322
|
-
const origLabelDx = existingLabelOffset?.dx ?? 0;
|
|
323
|
-
const origLabelDy = existingLabelOffset?.dy ?? 0;
|
|
324
|
-
|
|
325
|
-
const cleanup = createDragHandler({
|
|
326
|
-
element: labelEl,
|
|
327
|
-
svg: svg as unknown as SVGSVGElement,
|
|
328
|
-
onMove: (dx, dy) => {
|
|
329
|
-
(labelEl as SVGElement & ElementCSSInlineStyle).style.transform =
|
|
330
|
-
`translate(${dx}px, ${dy}px)`;
|
|
331
|
-
},
|
|
332
|
-
onEnd: (dx, dy, moved) => {
|
|
333
|
-
(labelEl as SVGElement & ElementCSSInlineStyle).style.transform = '';
|
|
334
|
-
|
|
335
|
-
if (moved) {
|
|
336
|
-
if (isRange) {
|
|
337
|
-
onEdit({
|
|
338
|
-
type: 'range-label',
|
|
339
|
-
element: elementRef.annotation(
|
|
340
|
-
index,
|
|
341
|
-
specAnnotation.id,
|
|
342
|
-
`/annotations/${index}/labelOffset`,
|
|
343
|
-
),
|
|
344
|
-
annotation: specAnnotation as RangeAnnotation,
|
|
345
|
-
labelOffset: { dx: origLabelDx + dx, dy: origLabelDy + dy },
|
|
346
|
-
});
|
|
347
|
-
} else {
|
|
348
|
-
onEdit({
|
|
349
|
-
type: 'refline-label',
|
|
350
|
-
element: elementRef.annotation(
|
|
351
|
-
index,
|
|
352
|
-
specAnnotation.id,
|
|
353
|
-
`/annotations/${index}/labelOffset`,
|
|
354
|
-
),
|
|
355
|
-
annotation: specAnnotation as RefLineAnnotation,
|
|
356
|
-
labelOffset: { dx: origLabelDx + dx, dy: origLabelDy + dy },
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
setDragging,
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
cleanups.push(cleanup);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return () => {
|
|
369
|
-
for (const cleanup of cleanups) {
|
|
370
|
-
cleanup();
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Wire drag on chrome text elements (title, subtitle, source, byline, footer).
|
|
377
|
-
* Returns a cleanup function.
|
|
378
|
-
*/
|
|
379
|
-
export function wireChromeDrag(
|
|
380
|
-
svg: SVGElement,
|
|
381
|
-
spec: ChartSpec | GraphSpec,
|
|
382
|
-
onEdit: (edit: ElementEdit) => void,
|
|
383
|
-
setDragging: (dragging: boolean) => void,
|
|
384
|
-
): () => void {
|
|
385
|
-
const chromeTexts = svg.querySelectorAll('.oc-chrome text[data-chrome-key]');
|
|
386
|
-
const cleanups: Array<() => void> = [];
|
|
387
|
-
|
|
388
|
-
const chromeConfig = 'chrome' in spec ? spec.chrome : undefined;
|
|
389
|
-
|
|
390
|
-
for (const el of chromeTexts) {
|
|
391
|
-
const textEl = el as SVGTextElement;
|
|
392
|
-
const key = textEl.getAttribute('data-chrome-key') as ChromeKey;
|
|
393
|
-
if (!key) continue;
|
|
394
|
-
|
|
395
|
-
const chromeEntry = chromeConfig?.[key];
|
|
396
|
-
const existingOffset =
|
|
397
|
-
typeof chromeEntry === 'object' && chromeEntry !== null ? chromeEntry.offset : undefined;
|
|
398
|
-
const origChromeDx = existingOffset?.dx ?? 0;
|
|
399
|
-
const origChromeDy = existingOffset?.dy ?? 0;
|
|
400
|
-
|
|
401
|
-
textEl.style.cursor = 'grab';
|
|
402
|
-
|
|
403
|
-
const cleanup = createDragHandler({
|
|
404
|
-
element: textEl,
|
|
405
|
-
svg: svg as unknown as SVGSVGElement,
|
|
406
|
-
onMove: (dx, dy) => {
|
|
407
|
-
(textEl as SVGElement & ElementCSSInlineStyle).style.transform =
|
|
408
|
-
`translate(${dx}px, ${dy}px)`;
|
|
409
|
-
},
|
|
410
|
-
onEnd: (dx, dy, moved) => {
|
|
411
|
-
(textEl as SVGElement & ElementCSSInlineStyle).style.transform = '';
|
|
412
|
-
|
|
413
|
-
if (moved) {
|
|
414
|
-
onEdit({
|
|
415
|
-
type: 'chrome',
|
|
416
|
-
key,
|
|
417
|
-
text: textEl.textContent ?? '',
|
|
418
|
-
offset: { dx: origChromeDx + dx, dy: origChromeDy + dy },
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
},
|
|
422
|
-
setDragging,
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
cleanups.push(cleanup);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return () => {
|
|
429
|
-
for (const cleanup of cleanups) {
|
|
430
|
-
cleanup();
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Wire drag on the legend group.
|
|
437
|
-
* Returns a cleanup function.
|
|
438
|
-
*/
|
|
439
|
-
export function wireLegendDrag(
|
|
440
|
-
svg: SVGElement,
|
|
441
|
-
spec: ChartSpec | GraphSpec,
|
|
442
|
-
onEdit: (edit: ElementEdit) => void,
|
|
443
|
-
setDragging: (dragging: boolean) => void,
|
|
444
|
-
): () => void {
|
|
445
|
-
// The color legend: it owns `spec.legend.offset`, which is what a drag writes
|
|
446
|
-
// back. The size legend is not draggable and must not be picked up here.
|
|
447
|
-
const legendG = svg.querySelector('.oc-legend:not(.oc-legend--size)') as SVGGElement | null;
|
|
448
|
-
if (!legendG) return () => {};
|
|
449
|
-
|
|
450
|
-
const cleanups: Array<() => void> = [];
|
|
451
|
-
|
|
452
|
-
const legendConfig = 'legend' in spec ? spec.legend : undefined;
|
|
453
|
-
const origLegendDx = legendConfig?.offset?.dx ?? 0;
|
|
454
|
-
const origLegendDy = legendConfig?.offset?.dy ?? 0;
|
|
455
|
-
|
|
456
|
-
legendG.style.cursor = 'grab';
|
|
457
|
-
|
|
458
|
-
const cleanup = createDragHandler({
|
|
459
|
-
element: legendG,
|
|
460
|
-
svg: svg as unknown as SVGSVGElement,
|
|
461
|
-
onMove: (dx, dy) => {
|
|
462
|
-
(legendG as SVGElement & ElementCSSInlineStyle).style.transform =
|
|
463
|
-
`translate(${dx}px, ${dy}px)`;
|
|
464
|
-
},
|
|
465
|
-
onEnd: (dx, dy, moved) => {
|
|
466
|
-
(legendG as SVGElement & ElementCSSInlineStyle).style.transform = '';
|
|
467
|
-
|
|
468
|
-
if (moved) {
|
|
469
|
-
onEdit({ type: 'legend', offset: { dx: origLegendDx + dx, dy: origLegendDy + dy } });
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
setDragging,
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
cleanups.push(cleanup);
|
|
476
|
-
|
|
477
|
-
return () => {
|
|
478
|
-
for (const cleanup of cleanups) {
|
|
479
|
-
cleanup();
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Wire drag on series label elements (.oc-mark-label[data-series]).
|
|
486
|
-
* Returns a cleanup function.
|
|
487
|
-
*/
|
|
488
|
-
export function wireSeriesLabelDrag(
|
|
489
|
-
svg: SVGElement,
|
|
490
|
-
spec: ChartSpec | GraphSpec,
|
|
491
|
-
onEdit: (edit: ElementEdit) => void,
|
|
492
|
-
setDragging: (dragging: boolean) => void,
|
|
493
|
-
): () => void {
|
|
494
|
-
const labels = svg.querySelectorAll('.oc-mark-label');
|
|
495
|
-
const cleanups: Array<() => void> = [];
|
|
496
|
-
|
|
497
|
-
const rawLabels = 'labels' in spec ? spec.labels : undefined;
|
|
498
|
-
const labelsConfig = typeof rawLabels === 'object' ? rawLabels : undefined;
|
|
499
|
-
|
|
500
|
-
for (const label of labels) {
|
|
501
|
-
const labelEl = label as SVGTextElement;
|
|
502
|
-
const series =
|
|
503
|
-
labelEl.getAttribute('data-series') ??
|
|
504
|
-
labelEl.closest('[data-series]')?.getAttribute('data-series');
|
|
505
|
-
if (!series) continue;
|
|
506
|
-
|
|
507
|
-
const existingSeriesOffset = labelsConfig?.offsets?.[series];
|
|
508
|
-
const origSeriesDx = existingSeriesOffset?.dx ?? 0;
|
|
509
|
-
const origSeriesDy = existingSeriesOffset?.dy ?? 0;
|
|
510
|
-
|
|
511
|
-
labelEl.style.cursor = 'grab';
|
|
512
|
-
|
|
513
|
-
const cleanup = createDragHandler({
|
|
514
|
-
element: labelEl,
|
|
515
|
-
svg: svg as unknown as SVGSVGElement,
|
|
516
|
-
onMove: (dx, dy) => {
|
|
517
|
-
(labelEl as SVGElement & ElementCSSInlineStyle).style.transform =
|
|
518
|
-
`translate(${dx}px, ${dy}px)`;
|
|
519
|
-
},
|
|
520
|
-
onEnd: (dx, dy, moved) => {
|
|
521
|
-
(labelEl as SVGElement & ElementCSSInlineStyle).style.transform = '';
|
|
522
|
-
|
|
523
|
-
if (moved) {
|
|
524
|
-
onEdit({
|
|
525
|
-
type: 'series-label',
|
|
526
|
-
series,
|
|
527
|
-
offset: { dx: origSeriesDx + dx, dy: origSeriesDy + dy },
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
setDragging,
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
cleanups.push(cleanup);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
return () => {
|
|
538
|
-
for (const cleanup of cleanups) {
|
|
539
|
-
cleanup();
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Wire drag on annotation anchor handles (the data-point dot).
|
|
546
|
-
* Dragging the anchor repositions the annotation in data space, emitting
|
|
547
|
-
* new x/y values via onEdit. Returns a cleanup function.
|
|
548
|
-
*/
|
|
549
|
-
export function wireAnchorDrag(
|
|
550
|
-
svg: SVGElement,
|
|
551
|
-
specAnnotations: Annotation[],
|
|
552
|
-
layout: ChartLayout,
|
|
553
|
-
onEdit: ((edit: ElementEdit) => void) | undefined,
|
|
554
|
-
setDragging: (d: boolean) => void,
|
|
555
|
-
): () => void {
|
|
556
|
-
if (!onEdit || !layout.xInvert || !layout.yInvert) return () => {};
|
|
557
|
-
|
|
558
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
559
|
-
const cleanups: Array<() => void> = [];
|
|
560
|
-
const annotationGroups = svg.querySelectorAll('.oc-annotation-text');
|
|
561
|
-
|
|
562
|
-
for (const el of annotationGroups) {
|
|
563
|
-
const annotationG = el as SVGGElement;
|
|
564
|
-
const indexStr = annotationG.getAttribute('data-annotation-index');
|
|
565
|
-
if (indexStr === null) continue;
|
|
566
|
-
|
|
567
|
-
const index = Number(indexStr);
|
|
568
|
-
const specAnnotation = specAnnotations[index];
|
|
569
|
-
if (!specAnnotation || specAnnotation.type !== 'text') continue;
|
|
570
|
-
|
|
571
|
-
const textAnnotation = specAnnotation as TextAnnotation;
|
|
572
|
-
|
|
573
|
-
const resolved = layout.annotations.find((a) => a.specIndex === index);
|
|
574
|
-
if (!resolved?.dot) continue;
|
|
575
|
-
|
|
576
|
-
const anchorX = resolved.dot.x;
|
|
577
|
-
const anchorY = resolved.dot.y;
|
|
578
|
-
|
|
579
|
-
const handleEl = document.createElementNS(SVG_NS, 'circle') as SVGCircleElement;
|
|
580
|
-
handleEl.setAttribute('class', 'oc-anchor-handle');
|
|
581
|
-
handleEl.setAttribute('cx', String(anchorX));
|
|
582
|
-
handleEl.setAttribute('cy', String(anchorY));
|
|
583
|
-
handleEl.setAttribute('r', '4');
|
|
584
|
-
handleEl.setAttribute('opacity', '0');
|
|
585
|
-
handleEl.setAttribute('fill', 'currentColor');
|
|
586
|
-
handleEl.setAttribute('stroke', 'currentColor');
|
|
587
|
-
handleEl.style.cursor = 'grab';
|
|
588
|
-
annotationG.appendChild(handleEl);
|
|
589
|
-
|
|
590
|
-
const stopProp = (e: Event) => {
|
|
591
|
-
e.stopPropagation();
|
|
592
|
-
};
|
|
593
|
-
handleEl.addEventListener('mousedown', stopProp);
|
|
594
|
-
handleEl.addEventListener('touchstart', stopProp);
|
|
595
|
-
cleanups.push(() => {
|
|
596
|
-
handleEl.removeEventListener('mousedown', stopProp);
|
|
597
|
-
handleEl.removeEventListener('touchstart', stopProp);
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
const cleanup = createDragHandler({
|
|
601
|
-
element: handleEl,
|
|
602
|
-
svg: svg as unknown as SVGSVGElement,
|
|
603
|
-
onMove: (dx, dy) => {
|
|
604
|
-
handleEl.setAttribute('cx', String(anchorX + dx));
|
|
605
|
-
handleEl.setAttribute('cy', String(anchorY + dy));
|
|
606
|
-
},
|
|
607
|
-
onEnd: (dx, dy, moved) => {
|
|
608
|
-
handleEl.setAttribute('cx', String(anchorX));
|
|
609
|
-
handleEl.setAttribute('cy', String(anchorY));
|
|
610
|
-
|
|
611
|
-
if (moved) {
|
|
612
|
-
const newX = invertScale(layout.xInvert!, anchorX + dx);
|
|
613
|
-
const newY = invertScale(layout.yInvert!, anchorY + dy);
|
|
614
|
-
onEdit({
|
|
615
|
-
type: 'annotation-anchor',
|
|
616
|
-
element: elementRef.annotation(index, textAnnotation.id, `/annotations/${index}`),
|
|
617
|
-
annotation: textAnnotation,
|
|
618
|
-
x: newX,
|
|
619
|
-
y: newY,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
setDragging,
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
cleanups.push(cleanup);
|
|
627
|
-
|
|
628
|
-
const showHandle = () => {
|
|
629
|
-
handleEl.setAttribute('opacity', '0.6');
|
|
630
|
-
};
|
|
631
|
-
const hideHandle = () => {
|
|
632
|
-
handleEl.setAttribute('opacity', '0');
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
annotationG.addEventListener('mouseenter', showHandle);
|
|
636
|
-
annotationG.addEventListener('mouseleave', hideHandle);
|
|
637
|
-
cleanups.push(() => {
|
|
638
|
-
annotationG.removeEventListener('mouseenter', showHandle);
|
|
639
|
-
annotationG.removeEventListener('mouseleave', hideHandle);
|
|
640
|
-
handleEl.remove();
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return () => {
|
|
645
|
-
for (const cleanup of cleanups) {
|
|
646
|
-
cleanup();
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export { wireChartEvents } from './chart-events';
|
|
2
|
-
export { wireVoronoiTooltipEvents } from './crosshair';
|
|
3
|
-
export type { DragConfig } from './drag-handler';
|
|
4
|
-
export { createDragHandler } from './drag-handler';
|
|
5
|
-
export {
|
|
6
|
-
wireAnchorDrag,
|
|
7
|
-
wireAnnotationDrag,
|
|
8
|
-
wireAnnotationLabelDrag,
|
|
9
|
-
wireChromeDrag,
|
|
10
|
-
wireConnectorEndpointDrag,
|
|
11
|
-
wireLegendDrag,
|
|
12
|
-
wireSeriesLabelDrag,
|
|
13
|
-
} from './editing-drags';
|
|
14
|
-
export { invertScale } from './invert';
|
|
15
|
-
export { wireKeyboardNav } from './keyboard-nav';
|
|
16
|
-
export { wireLegendInteraction } from './legend-interaction';
|
|
17
|
-
export {
|
|
18
|
-
buildElementRef,
|
|
19
|
-
createScreenReaderTable,
|
|
20
|
-
findElementByRef,
|
|
21
|
-
getEditableElements,
|
|
22
|
-
getElementText,
|
|
23
|
-
isTextEditable,
|
|
24
|
-
refsEqual,
|
|
25
|
-
renderSelectionOverlay,
|
|
26
|
-
} from './selection';
|
|
27
|
-
export { wireTooltipEvents } from './tooltip-events';
|