@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,213 +0,0 @@
1
- import type { GraphSpec } from '@opendata-ai/openchart-core';
2
- import { afterEach, describe, expect, it, vi } from 'vitest';
3
- import { createGraph } from '../../graph-mount';
4
-
5
- // ---------------------------------------------------------------------------
6
- // Test data
7
- // ---------------------------------------------------------------------------
8
-
9
- const basicSpec: GraphSpec = {
10
- type: 'graph',
11
- nodes: [
12
- { id: 'a', label: 'Node A' },
13
- { id: 'b', label: 'Node B' },
14
- { id: 'c', label: 'Node C' },
15
- ],
16
- edges: [
17
- { source: 'a', target: 'b' },
18
- { source: 'b', target: 'c' },
19
- ],
20
- chrome: {
21
- title: 'Test Graph',
22
- subtitle: 'A simple test graph',
23
- },
24
- };
25
-
26
- const communitySpec: GraphSpec = {
27
- type: 'graph',
28
- nodes: [
29
- { id: 'a', label: 'Node A', group: 'x' },
30
- { id: 'b', label: 'Node B', group: 'x' },
31
- { id: 'c', label: 'Node C', group: 'y' },
32
- { id: 'd', label: 'Node D', group: 'y' },
33
- ],
34
- edges: [
35
- { source: 'a', target: 'b' },
36
- { source: 'c', target: 'd' },
37
- { source: 'a', target: 'c' },
38
- ],
39
- layout: {
40
- clustering: { field: 'group' },
41
- },
42
- chrome: {
43
- title: 'Community Graph',
44
- },
45
- };
46
-
47
- // ---------------------------------------------------------------------------
48
- // Helpers
49
- // ---------------------------------------------------------------------------
50
-
51
- function makeContainer(): HTMLElement {
52
- const el = document.createElement('div');
53
- // happy-dom doesn't auto-size elements; we need to provide dimensions
54
- // for getBoundingClientRect to return useful values
55
- Object.defineProperty(el, 'getBoundingClientRect', {
56
- value: () => ({
57
- width: 800,
58
- height: 600,
59
- top: 0,
60
- left: 0,
61
- bottom: 600,
62
- right: 800,
63
- x: 0,
64
- y: 0,
65
- toJSON: () => {},
66
- }),
67
- });
68
- document.body.appendChild(el);
69
- return el;
70
- }
71
-
72
- // ---------------------------------------------------------------------------
73
- // Cleanup
74
- // ---------------------------------------------------------------------------
75
-
76
- let container: HTMLElement;
77
-
78
- afterEach(() => {
79
- if (container?.parentNode) {
80
- container.parentNode.removeChild(container);
81
- }
82
- });
83
-
84
- // ---------------------------------------------------------------------------
85
- // Tests
86
- // ---------------------------------------------------------------------------
87
-
88
- describe('createGraph', () => {
89
- it('creates expected DOM structure (wrapper, canvas, chrome, legend)', () => {
90
- container = makeContainer();
91
- const graph = createGraph(container, basicSpec);
92
-
93
- // Wrapper
94
- const wrapper = container.querySelector('.oc-graph-wrapper');
95
- expect(wrapper).not.toBeNull();
96
-
97
- // Canvas
98
- const canvas = container.querySelector('.oc-graph-canvas');
99
- expect(canvas).not.toBeNull();
100
- expect(canvas?.tagName.toLowerCase()).toBe('canvas');
101
-
102
- // Chrome
103
- const chrome = container.querySelector('.oc-graph-chrome');
104
- expect(chrome).not.toBeNull();
105
-
106
- // Title
107
- const title = container.querySelector('.oc-title');
108
- expect(title).not.toBeNull();
109
- expect(title?.textContent).toBe('Test Graph');
110
-
111
- // Subtitle
112
- const subtitle = container.querySelector('.oc-subtitle');
113
- expect(subtitle).not.toBeNull();
114
- expect(subtitle?.textContent).toBe('A simple test graph');
115
-
116
- // Legend exists (even if hidden for non-community graphs)
117
- const legend = container.querySelector('.oc-graph-legend');
118
- expect(legend).not.toBeNull();
119
-
120
- graph.destroy();
121
- });
122
-
123
- it('destroy cleans up DOM and does not error on subsequent calls', () => {
124
- container = makeContainer();
125
- const graph = createGraph(container, basicSpec);
126
-
127
- expect(container.querySelector('.oc-graph-wrapper')).not.toBeNull();
128
-
129
- graph.destroy();
130
-
131
- expect(container.querySelector('.oc-graph-wrapper')).toBeNull();
132
- expect(container.querySelector('.oc-graph-canvas')).toBeNull();
133
-
134
- // Calling destroy again should not throw
135
- expect(() => graph.destroy()).not.toThrow();
136
-
137
- // Calling methods after destroy should not throw
138
- expect(() => graph.update(basicSpec)).not.toThrow();
139
- expect(() => graph.search('test')).not.toThrow();
140
- expect(() => graph.zoomToFit()).not.toThrow();
141
- expect(() => graph.resize()).not.toThrow();
142
- expect(graph.getSelectedNodes()).toEqual([]);
143
- });
144
-
145
- it('update re-initializes with new spec', () => {
146
- container = makeContainer();
147
- const graph = createGraph(container, basicSpec);
148
-
149
- const titleBefore = container.querySelector('.oc-title');
150
- expect(titleBefore?.textContent).toBe('Test Graph');
151
-
152
- graph.update(communitySpec);
153
-
154
- const titleAfter = container.querySelector('.oc-title');
155
- expect(titleAfter?.textContent).toBe('Community Graph');
156
-
157
- graph.destroy();
158
- });
159
-
160
- it('shows legend for community graphs', () => {
161
- container = makeContainer();
162
- const graph = createGraph(container, communitySpec);
163
-
164
- const legend = container.querySelector('.oc-graph-legend');
165
- expect(legend).not.toBeNull();
166
- // Community graph should have visible legend items
167
- const items = container.querySelectorAll('.oc-graph-legend-item');
168
- expect(items.length).toBeGreaterThan(0);
169
-
170
- graph.destroy();
171
- });
172
-
173
- it('search and clearSearch update without errors', () => {
174
- container = makeContainer();
175
- const graph = createGraph(container, basicSpec);
176
-
177
- expect(() => graph.search('Node')).not.toThrow();
178
- expect(() => graph.clearSearch()).not.toThrow();
179
-
180
- graph.destroy();
181
- });
182
-
183
- it('selectNode and getSelectedNodes work', () => {
184
- container = makeContainer();
185
- const graph = createGraph(container, basicSpec);
186
-
187
- graph.selectNode('a');
188
- expect(graph.getSelectedNodes()).toEqual(['a']);
189
-
190
- graph.destroy();
191
- });
192
-
193
- it('applies oc-dark class in dark mode', () => {
194
- container = makeContainer();
195
- const graph = createGraph(container, basicSpec, { darkMode: 'force' });
196
-
197
- expect(container.classList.contains('oc-dark')).toBe(true);
198
-
199
- graph.destroy();
200
- expect(container.classList.contains('oc-dark')).toBe(false);
201
- });
202
-
203
- it('onSelectionChange callback fires on selectNode', () => {
204
- container = makeContainer();
205
- const onSelectionChange = vi.fn();
206
- const graph = createGraph(container, basicSpec, { onSelectionChange });
207
-
208
- graph.selectNode('b');
209
- expect(onSelectionChange).toHaveBeenCalledWith(['b']);
210
-
211
- graph.destroy();
212
- });
213
- });
@@ -1,205 +0,0 @@
1
- import { beforeEach, describe, expect, it } from 'vitest';
2
- import type { InteractionCallbacks } from '../interaction';
3
- import { GraphInteractionManager } from '../interaction';
4
- import { SpatialIndex } from '../spatial-index';
5
- import type { PositionedNode } from '../types';
6
- import { ZoomTransform } from '../zoom';
7
-
8
- // ---------------------------------------------------------------------------
9
- // Helpers
10
- // ---------------------------------------------------------------------------
11
-
12
- function makeNode(id: string, x: number, y: number, radius = 10): PositionedNode {
13
- return {
14
- id,
15
- x,
16
- y,
17
- radius,
18
- fill: '#3b82f6',
19
- stroke: '#2563eb',
20
- strokeWidth: 1,
21
- label: id,
22
- labelPriority: 0.5,
23
- community: undefined,
24
- data: {},
25
- };
26
- }
27
-
28
- function createMockCanvas(): HTMLCanvasElement {
29
- const canvas = document.createElement('canvas');
30
- canvas.width = 800;
31
- canvas.height = 600;
32
- // Mock getBoundingClientRect for coordinate conversion
33
- canvas.getBoundingClientRect = () => ({
34
- left: 0,
35
- top: 0,
36
- right: 800,
37
- bottom: 600,
38
- width: 800,
39
- height: 600,
40
- x: 0,
41
- y: 0,
42
- toJSON: () => ({}),
43
- });
44
- return canvas;
45
- }
46
-
47
- function createCallbacks(): InteractionCallbacks & {
48
- transformChanges: ZoomTransform[];
49
- hoverChanges: (string | null)[];
50
- selectionChanges: string[][];
51
- dragStarts: string[];
52
- drags: Array<{ nodeId: string; x: number; y: number }>;
53
- dragEnds: string[];
54
- doubleClicks: string[];
55
- } {
56
- const state = {
57
- transformChanges: [] as ZoomTransform[],
58
- hoverChanges: [] as (string | null)[],
59
- selectionChanges: [] as string[][],
60
- dragStarts: [] as string[],
61
- drags: [] as Array<{ nodeId: string; x: number; y: number }>,
62
- dragEnds: [] as string[],
63
- doubleClicks: [] as string[],
64
- onTransformChange(t: ZoomTransform) {
65
- state.transformChanges.push(t);
66
- },
67
- onHoverChange(nodeId: string | null) {
68
- state.hoverChanges.push(nodeId);
69
- },
70
- onSelectionChange(nodeIds: string[]) {
71
- state.selectionChanges.push(nodeIds);
72
- },
73
- onNodeDragStart(nodeId: string) {
74
- state.dragStarts.push(nodeId);
75
- },
76
- onNodeDrag(nodeId: string, x: number, y: number) {
77
- state.drags.push({ nodeId, x, y });
78
- },
79
- onNodeDragEnd(nodeId: string) {
80
- state.dragEnds.push(nodeId);
81
- },
82
- onDoubleClick(nodeId: string) {
83
- state.doubleClicks.push(nodeId);
84
- },
85
- };
86
- return state;
87
- }
88
-
89
- // ---------------------------------------------------------------------------
90
- // Tests
91
- // ---------------------------------------------------------------------------
92
-
93
- describe('GraphInteractionManager', () => {
94
- let canvas: HTMLCanvasElement;
95
- let spatialIndex: SpatialIndex;
96
- let callbacks: ReturnType<typeof createCallbacks>;
97
- let manager: GraphInteractionManager;
98
-
99
- beforeEach(() => {
100
- canvas = createMockCanvas();
101
- spatialIndex = new SpatialIndex();
102
- callbacks = createCallbacks();
103
-
104
- const nodes = [
105
- makeNode('center', 400, 300),
106
- makeNode('left', 100, 300),
107
- makeNode('right', 700, 300),
108
- ];
109
- spatialIndex.rebuild(nodes);
110
-
111
- manager = new GraphInteractionManager(canvas, spatialIndex, callbacks);
112
- });
113
-
114
- describe('zoom', () => {
115
- it('updates transform on wheel', () => {
116
- const wheelEvent = new WheelEvent('wheel', {
117
- deltaY: -100,
118
- clientX: 400,
119
- clientY: 300,
120
- });
121
- canvas.dispatchEvent(wheelEvent);
122
-
123
- expect(callbacks.transformChanges.length).toBe(1);
124
- const t = callbacks.transformChanges[0];
125
- expect(t.k).toBeGreaterThan(1);
126
- });
127
-
128
- it('zoom in increases scale', () => {
129
- // Negative deltaY = zoom in
130
- canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: -200, clientX: 400, clientY: 300 }));
131
- const t = callbacks.transformChanges[0];
132
- expect(t.k).toBeGreaterThan(1);
133
- });
134
-
135
- it('zoom out decreases scale', () => {
136
- // Positive deltaY = zoom out
137
- canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: 200, clientX: 400, clientY: 300 }));
138
- const t = callbacks.transformChanges[0];
139
- expect(t.k).toBeLessThan(1);
140
- });
141
- });
142
-
143
- describe('hover', () => {
144
- it('fires hover change on mousemove over a node', () => {
145
- // Move over node at (400, 300) with identity transform
146
- canvas.dispatchEvent(new MouseEvent('mousemove', { clientX: 400, clientY: 300 }));
147
-
148
- expect(callbacks.hoverChanges.length).toBeGreaterThan(0);
149
- expect(callbacks.hoverChanges[callbacks.hoverChanges.length - 1]).toBe('center');
150
- });
151
-
152
- it('fires null hover on mousemove over background', () => {
153
- canvas.dispatchEvent(new MouseEvent('mousemove', { clientX: 0, clientY: 0 }));
154
-
155
- expect(callbacks.hoverChanges.length).toBeGreaterThan(0);
156
- expect(callbacks.hoverChanges[callbacks.hoverChanges.length - 1]).toBeNull();
157
- });
158
- });
159
-
160
- describe('selection', () => {
161
- it('selects a node on click', () => {
162
- // Mousedown on node
163
- canvas.dispatchEvent(new MouseEvent('mousedown', { clientX: 400, clientY: 300 }));
164
- // Mouseup without moving (click)
165
- canvas.dispatchEvent(new MouseEvent('mouseup', { clientX: 400, clientY: 300 }));
166
-
167
- expect(callbacks.selectionChanges.length).toBe(1);
168
- expect(callbacks.selectionChanges[0]).toEqual(['center']);
169
- });
170
-
171
- it('clears selection on background click', () => {
172
- // First select a node
173
- canvas.dispatchEvent(new MouseEvent('mousedown', { clientX: 400, clientY: 300 }));
174
- canvas.dispatchEvent(new MouseEvent('mouseup', { clientX: 400, clientY: 300 }));
175
-
176
- // Then click background
177
- canvas.dispatchEvent(new MouseEvent('mousedown', { clientX: 0, clientY: 0 }));
178
- canvas.dispatchEvent(new MouseEvent('mouseup', { clientX: 0, clientY: 0 }));
179
-
180
- expect(callbacks.selectionChanges.length).toBe(2);
181
- expect(callbacks.selectionChanges[1]).toEqual([]);
182
- });
183
- });
184
-
185
- describe('transform', () => {
186
- it('setTransform and getTransform work', () => {
187
- const t = new ZoomTransform(10, 20, 3);
188
- manager.setTransform(t);
189
- const got = manager.getTransform();
190
- expect(got.x).toBe(10);
191
- expect(got.y).toBe(20);
192
- expect(got.k).toBe(3);
193
- });
194
- });
195
-
196
- describe('cleanup', () => {
197
- it('destroy removes event listeners (no errors on subsequent events)', () => {
198
- manager.destroy();
199
-
200
- // Should not throw and should not trigger callbacks
201
- canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: -100, clientX: 400, clientY: 300 }));
202
- expect(callbacks.transformChanges.length).toBe(0);
203
- });
204
- });
205
- });