@opendata-ai/openchart-vue 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/src/Graph.ts DELETED
@@ -1,179 +0,0 @@
1
- /**
2
- * Vue Graph component: thin wrapper around the vanilla adapter.
3
- *
4
- * Mounts a graph instance on render, updates when spec changes,
5
- * and cleans up on unmount. All heavy lifting is done by the vanilla
6
- * createGraph() function.
7
- *
8
- * Exposes imperative methods via defineExpose for use with useGraph().
9
- */
10
-
11
- import type { DarkMode, GraphSpec, ThemeConfig } from '@opendata-ai/openchart-core';
12
- import {
13
- createGraph,
14
- type GraphInstance,
15
- type GraphMountOptions,
16
- } from '@opendata-ai/openchart-vanilla';
17
- import {
18
- type CSSProperties,
19
- defineComponent,
20
- h,
21
- inject,
22
- onMounted,
23
- onUnmounted,
24
- type PropType,
25
- ref,
26
- watch,
27
- } from 'vue';
28
- import { VizDarkModeKey, VizThemeKey } from './context';
29
-
30
- export interface GraphProps {
31
- spec: GraphSpec;
32
- theme?: ThemeConfig;
33
- darkMode?: DarkMode;
34
- class?: string;
35
- style?: string | CSSProperties;
36
- }
37
-
38
- export const Graph = defineComponent({
39
- name: 'Graph',
40
- props: {
41
- spec: {
42
- type: Object as PropType<GraphSpec>,
43
- required: true,
44
- },
45
- theme: {
46
- type: Object as PropType<ThemeConfig>,
47
- default: undefined,
48
- },
49
- darkMode: {
50
- type: String as PropType<DarkMode>,
51
- default: undefined,
52
- },
53
- class: {
54
- type: String,
55
- default: undefined,
56
- },
57
- style: {
58
- type: [String, Object] as PropType<string | CSSProperties>,
59
- default: undefined,
60
- },
61
- },
62
- emits: {
63
- 'node-click': (_node: Record<string, unknown>) => true,
64
- 'node-double-click': (_node: Record<string, unknown>) => true,
65
- 'selection-change': (_nodeIds: string[]) => true,
66
- },
67
- setup(props, { emit, expose }) {
68
- const containerRef = ref<HTMLDivElement | null>(null);
69
- let instance: GraphInstance | null = null;
70
- let prevSpec = '';
71
-
72
- // Inject theme/darkMode from provider as fallbacks
73
- const contextTheme = inject(VizThemeKey, undefined);
74
- const contextDarkMode = inject(VizDarkModeKey, undefined);
75
-
76
- function resolveTheme(): ThemeConfig | undefined {
77
- return props.theme ?? contextTheme?.value;
78
- }
79
-
80
- function resolveDarkMode(): DarkMode | undefined {
81
- return props.darkMode ?? contextDarkMode?.value;
82
- }
83
-
84
- function mountGraph() {
85
- const container = containerRef.value;
86
- if (!container) return;
87
-
88
- const options: GraphMountOptions = {
89
- theme: resolveTheme(),
90
- darkMode: resolveDarkMode(),
91
- onNodeClick: (node: Record<string, unknown>) => emit('node-click', node),
92
- onNodeDoubleClick: (node: Record<string, unknown>) => emit('node-double-click', node),
93
- onSelectionChange: (nodeIds: string[]) => emit('selection-change', nodeIds),
94
- responsive: true,
95
- };
96
-
97
- instance = createGraph(container, props.spec, options);
98
- prevSpec = JSON.stringify(props.spec);
99
- }
100
-
101
- function destroyGraph() {
102
- instance?.destroy();
103
- instance = null;
104
- prevSpec = '';
105
- }
106
-
107
- // Expose imperative methods for useGraph() composable
108
- expose({
109
- search(query: string) {
110
- instance?.search(query);
111
- },
112
- clearSearch() {
113
- instance?.clearSearch();
114
- },
115
- zoomToFit() {
116
- instance?.zoomToFit();
117
- },
118
- zoomToNode(nodeId: string) {
119
- instance?.zoomToNode(nodeId);
120
- },
121
- selectNode(nodeId: string) {
122
- instance?.selectNode(nodeId);
123
- },
124
- getSelectedNodes(): string[] {
125
- return instance?.getSelectedNodes() ?? [];
126
- },
127
- get instance() {
128
- return instance;
129
- },
130
- });
131
-
132
- onMounted(() => {
133
- mountGraph();
134
- });
135
-
136
- onUnmounted(() => {
137
- destroyGraph();
138
- });
139
-
140
- // Watch spec changes
141
- watch(
142
- () => JSON.stringify(props.spec),
143
- (newVal) => {
144
- if (!instance) return;
145
- if (newVal !== prevSpec) {
146
- prevSpec = newVal;
147
- instance.update(props.spec);
148
- }
149
- },
150
- );
151
-
152
- // Recreate graph when theme or darkMode change
153
- watch(
154
- [
155
- () => props.theme,
156
- () => props.darkMode,
157
- () => contextTheme?.value,
158
- () => contextDarkMode?.value,
159
- ],
160
- () => {
161
- if (!containerRef.value) return;
162
- destroyGraph();
163
- mountGraph();
164
- },
165
- );
166
-
167
- const rootClass = () => {
168
- const base = 'oc-graph-root';
169
- return props.class ? `${base} ${props.class}` : base;
170
- };
171
-
172
- return () =>
173
- h('div', {
174
- ref: containerRef,
175
- class: rootClass(),
176
- style: props.style,
177
- });
178
- },
179
- });
package/src/Map.ts DELETED
@@ -1,160 +0,0 @@
1
- /**
2
- * Vue Map component: thin wrapper around the vanilla adapter.
3
- *
4
- * Mounts a map instance on render, updates when spec changes,
5
- * and cleans up on unmount. All heavy lifting is done by the vanilla
6
- * createMap() function.
7
- */
8
-
9
- import type { DarkMode, MapSpec, ThemeConfig } from '@opendata-ai/openchart-core';
10
-
11
- type MapFeatureEvent = {
12
- id: string | number;
13
- name?: string;
14
- data: Record<string, unknown> | null;
15
- };
16
-
17
- import { createMap, type MapInstance, type MapMountOptions } from '@opendata-ai/openchart-vanilla';
18
- import {
19
- type CSSProperties,
20
- defineComponent,
21
- h,
22
- inject,
23
- onMounted,
24
- onUnmounted,
25
- type PropType,
26
- ref,
27
- watch,
28
- } from 'vue';
29
- import { VizDarkModeKey, VizThemeKey } from './context';
30
-
31
- export interface MapProps {
32
- spec: MapSpec;
33
- theme?: ThemeConfig;
34
- darkMode?: DarkMode;
35
- class?: string;
36
- style?: string | CSSProperties;
37
- }
38
-
39
- export const GeoMap = defineComponent({
40
- name: 'GeoMap',
41
- props: {
42
- spec: {
43
- type: Object as PropType<MapSpec>,
44
- required: true,
45
- },
46
- theme: {
47
- type: Object as PropType<ThemeConfig>,
48
- default: undefined,
49
- },
50
- darkMode: {
51
- type: String as PropType<DarkMode>,
52
- default: undefined,
53
- },
54
- class: {
55
- type: String,
56
- default: undefined,
57
- },
58
- style: {
59
- type: [String, Object] as PropType<string | CSSProperties>,
60
- default: undefined,
61
- },
62
- },
63
- emits: {
64
- 'mark-click': (_event: MapFeatureEvent) => true,
65
- 'mark-hover': (_event: MapFeatureEvent | null) => true,
66
- },
67
- setup(props, { emit, expose }) {
68
- const containerRef = ref<HTMLDivElement | null>(null);
69
- let instance: MapInstance | null = null;
70
- let prevSpec = '';
71
-
72
- // Inject theme/darkMode from provider as fallbacks
73
- const contextTheme = inject(VizThemeKey, undefined);
74
- const contextDarkMode = inject(VizDarkModeKey, undefined);
75
-
76
- function resolveTheme(): ThemeConfig | undefined {
77
- return props.theme ?? contextTheme?.value;
78
- }
79
-
80
- function resolveDarkMode(): DarkMode | undefined {
81
- return props.darkMode ?? contextDarkMode?.value;
82
- }
83
-
84
- function mountMap() {
85
- const container = containerRef.value;
86
- if (!container) return;
87
-
88
- const options: MapMountOptions = {
89
- theme: resolveTheme(),
90
- darkMode: resolveDarkMode(),
91
- onMarkClick: (feature) => emit('mark-click', feature),
92
- onMarkHover: (feature) => emit('mark-hover', feature),
93
- responsive: true,
94
- };
95
-
96
- instance = createMap(container, props.spec, options);
97
- prevSpec = JSON.stringify(props.spec);
98
- }
99
-
100
- function destroyMap() {
101
- instance?.destroy();
102
- instance = null;
103
- prevSpec = '';
104
- }
105
-
106
- // Expose imperative access to the instance
107
- expose({
108
- get instance() {
109
- return instance;
110
- },
111
- });
112
-
113
- onMounted(() => {
114
- mountMap();
115
- });
116
-
117
- onUnmounted(() => {
118
- destroyMap();
119
- });
120
-
121
- // Watch spec changes
122
- watch(
123
- () => JSON.stringify(props.spec),
124
- (newVal) => {
125
- if (!instance) return;
126
- if (newVal !== prevSpec) {
127
- prevSpec = newVal;
128
- instance.update(props.spec);
129
- }
130
- },
131
- );
132
-
133
- // Recreate map when theme or darkMode change
134
- watch(
135
- [
136
- () => props.theme,
137
- () => props.darkMode,
138
- () => contextTheme?.value,
139
- () => contextDarkMode?.value,
140
- ],
141
- () => {
142
- if (!containerRef.value) return;
143
- destroyMap();
144
- mountMap();
145
- },
146
- );
147
-
148
- const rootClass = () => {
149
- const base = 'oc-map-root';
150
- return props.class ? `${base} ${props.class}` : base;
151
- };
152
-
153
- return () =>
154
- h('div', {
155
- ref: containerRef,
156
- class: rootClass(),
157
- style: props.style,
158
- });
159
- },
160
- });
package/src/Sankey.ts DELETED
@@ -1,161 +0,0 @@
1
- /**
2
- * Vue Sankey component: thin wrapper around the vanilla adapter.
3
- *
4
- * Mounts a sankey instance on render, updates when spec changes,
5
- * and cleans up on unmount. All heavy lifting is done by the vanilla
6
- * createSankey() function.
7
- */
8
-
9
- import type { DarkMode, SankeySpec, ThemeConfig } from '@opendata-ai/openchart-core';
10
- import {
11
- createSankey,
12
- type SankeyInstance,
13
- type SankeyMountOptions,
14
- } from '@opendata-ai/openchart-vanilla';
15
- import {
16
- type CSSProperties,
17
- defineComponent,
18
- h,
19
- inject,
20
- onMounted,
21
- onUnmounted,
22
- type PropType,
23
- ref,
24
- watch,
25
- } from 'vue';
26
- import { VizDarkModeKey, VizThemeKey } from './context';
27
-
28
- export interface SankeyProps {
29
- spec: SankeySpec;
30
- theme?: ThemeConfig;
31
- darkMode?: DarkMode;
32
- class?: string;
33
- style?: string | CSSProperties;
34
- }
35
-
36
- export const Sankey = defineComponent({
37
- name: 'Sankey',
38
- props: {
39
- spec: {
40
- type: Object as PropType<SankeySpec>,
41
- required: true,
42
- },
43
- theme: {
44
- type: Object as PropType<ThemeConfig>,
45
- default: undefined,
46
- },
47
- darkMode: {
48
- type: String as PropType<DarkMode>,
49
- default: undefined,
50
- },
51
- class: {
52
- type: String,
53
- default: undefined,
54
- },
55
- style: {
56
- type: [String, Object] as PropType<string | CSSProperties>,
57
- default: undefined,
58
- },
59
- },
60
- emits: {
61
- 'node-click': (_node: Record<string, unknown>) => true,
62
- 'link-click': (_link: Record<string, unknown>) => true,
63
- 'node-hover': (_node: Record<string, unknown> | null) => true,
64
- 'link-hover': (_link: Record<string, unknown> | null) => true,
65
- },
66
- setup(props, { emit, expose }) {
67
- const containerRef = ref<HTMLDivElement | null>(null);
68
- let instance: SankeyInstance | null = null;
69
- let prevSpec = '';
70
-
71
- // Inject theme/darkMode from provider as fallbacks
72
- const contextTheme = inject(VizThemeKey, undefined);
73
- const contextDarkMode = inject(VizDarkModeKey, undefined);
74
-
75
- function resolveTheme(): ThemeConfig | undefined {
76
- return props.theme ?? contextTheme?.value;
77
- }
78
-
79
- function resolveDarkMode(): DarkMode | undefined {
80
- return props.darkMode ?? contextDarkMode?.value;
81
- }
82
-
83
- function mountSankey() {
84
- const container = containerRef.value;
85
- if (!container) return;
86
-
87
- const options: SankeyMountOptions = {
88
- theme: resolveTheme(),
89
- darkMode: resolveDarkMode(),
90
- onNodeClick: (node: Record<string, unknown>) => emit('node-click', node),
91
- onLinkClick: (link: Record<string, unknown>) => emit('link-click', link),
92
- onNodeHover: (node: Record<string, unknown> | null) => emit('node-hover', node),
93
- onLinkHover: (link: Record<string, unknown> | null) => emit('link-hover', link),
94
- responsive: true,
95
- };
96
-
97
- instance = createSankey(container, props.spec, options);
98
- prevSpec = JSON.stringify(props.spec);
99
- }
100
-
101
- function destroySankey() {
102
- instance?.destroy();
103
- instance = null;
104
- prevSpec = '';
105
- }
106
-
107
- // Expose imperative access to the instance
108
- expose({
109
- get instance() {
110
- return instance;
111
- },
112
- });
113
-
114
- onMounted(() => {
115
- mountSankey();
116
- });
117
-
118
- onUnmounted(() => {
119
- destroySankey();
120
- });
121
-
122
- // Watch spec changes
123
- watch(
124
- () => JSON.stringify(props.spec),
125
- (newVal) => {
126
- if (!instance) return;
127
- if (newVal !== prevSpec) {
128
- prevSpec = newVal;
129
- instance.update(props.spec);
130
- }
131
- },
132
- );
133
-
134
- // Recreate sankey when theme or darkMode change
135
- watch(
136
- [
137
- () => props.theme,
138
- () => props.darkMode,
139
- () => contextTheme?.value,
140
- () => contextDarkMode?.value,
141
- ],
142
- () => {
143
- if (!containerRef.value) return;
144
- destroySankey();
145
- mountSankey();
146
- },
147
- );
148
-
149
- const rootClass = () => {
150
- const base = 'oc-sankey-root';
151
- return props.class ? `${base} ${props.class}` : base;
152
- };
153
-
154
- return () =>
155
- h('div', {
156
- ref: containerRef,
157
- class: rootClass(),
158
- style: props.style,
159
- });
160
- },
161
- });
@@ -1,41 +0,0 @@
1
- /**
2
- * VizThemeProvider: provides a theme and dark mode preference to all
3
- * descendant Chart, DataTable, and Graph components without prop drilling.
4
- *
5
- * Components use the context values as fallbacks when no explicit
6
- * `theme` or `darkMode` prop is passed.
7
- */
8
-
9
- import type { DarkMode, ThemeConfig } from '@opendata-ai/openchart-core';
10
- import { computed, defineComponent, type PropType, provide } from 'vue';
11
- import { VizDarkModeKey, VizThemeKey } from './context';
12
-
13
- export interface VizThemeProviderProps {
14
- theme: ThemeConfig | undefined;
15
- darkMode?: DarkMode;
16
- }
17
-
18
- export const VizThemeProvider = defineComponent({
19
- name: 'VizThemeProvider',
20
- props: {
21
- theme: {
22
- type: Object as PropType<ThemeConfig | undefined>,
23
- default: undefined,
24
- },
25
- darkMode: {
26
- type: String as PropType<DarkMode>,
27
- default: undefined,
28
- },
29
- },
30
- setup(props, { slots }) {
31
- // Wrap in computed() so changes to props propagate reactively
32
- // through the injection system.
33
- const themeRef = computed(() => props.theme);
34
- const darkModeRef = computed(() => props.darkMode);
35
-
36
- provide(VizThemeKey, themeRef);
37
- provide(VizDarkModeKey, darkModeRef);
38
-
39
- return () => slots.default?.();
40
- },
41
- });
package/src/TileMap.ts DELETED
@@ -1,164 +0,0 @@
1
- /**
2
- * Vue TileMap component: thin wrapper around the vanilla adapter.
3
- *
4
- * Mounts a tilemap instance on render, updates when spec changes,
5
- * and cleans up on unmount. All heavy lifting is done by the vanilla
6
- * createTileMap() function.
7
- */
8
-
9
- import type { DarkMode, ThemeConfig, TileMapSpec } from '@opendata-ai/openchart-core';
10
- import {
11
- createTileMap,
12
- type TileMapInstance,
13
- type TileMapMountOptions,
14
- } from '@opendata-ai/openchart-vanilla';
15
- import {
16
- type CSSProperties,
17
- defineComponent,
18
- h,
19
- inject,
20
- onMounted,
21
- onUnmounted,
22
- type PropType,
23
- ref,
24
- watch,
25
- } from 'vue';
26
- import { VizDarkModeKey, VizThemeKey } from './context';
27
-
28
- export interface TileMapTileEvent {
29
- stateCode: string;
30
- stateName: string;
31
- value: number | null;
32
- data: Record<string, unknown>;
33
- }
34
-
35
- export interface TileMapProps {
36
- spec: TileMapSpec;
37
- theme?: ThemeConfig;
38
- darkMode?: DarkMode;
39
- class?: string;
40
- style?: string | CSSProperties;
41
- }
42
-
43
- export const TileMap = defineComponent({
44
- name: 'TileMap',
45
- props: {
46
- spec: {
47
- type: Object as PropType<TileMapSpec>,
48
- required: true,
49
- },
50
- theme: {
51
- type: Object as PropType<ThemeConfig>,
52
- default: undefined,
53
- },
54
- darkMode: {
55
- type: String as PropType<DarkMode>,
56
- default: undefined,
57
- },
58
- class: {
59
- type: String,
60
- default: undefined,
61
- },
62
- style: {
63
- type: [String, Object] as PropType<string | CSSProperties>,
64
- default: undefined,
65
- },
66
- },
67
- emits: {
68
- 'tile-click': (_tile: TileMapTileEvent) => true,
69
- 'tile-hover': (_tile: TileMapTileEvent | null) => true,
70
- },
71
- setup(props, { emit, expose }) {
72
- const containerRef = ref<HTMLDivElement | null>(null);
73
- let instance: TileMapInstance | null = null;
74
- let prevSpec = '';
75
-
76
- // Inject theme/darkMode from provider as fallbacks
77
- const contextTheme = inject(VizThemeKey, undefined);
78
- const contextDarkMode = inject(VizDarkModeKey, undefined);
79
-
80
- function resolveTheme(): ThemeConfig | undefined {
81
- return props.theme ?? contextTheme?.value;
82
- }
83
-
84
- function resolveDarkMode(): DarkMode | undefined {
85
- return props.darkMode ?? contextDarkMode?.value;
86
- }
87
-
88
- function mountTileMap() {
89
- const container = containerRef.value;
90
- if (!container) return;
91
-
92
- const options: TileMapMountOptions = {
93
- theme: resolveTheme(),
94
- darkMode: resolveDarkMode(),
95
- onTileClick: (tile: TileMapTileEvent) => emit('tile-click', tile),
96
- onTileHover: (tile: TileMapTileEvent | null) => emit('tile-hover', tile),
97
- responsive: true,
98
- };
99
-
100
- instance = createTileMap(container, props.spec, options);
101
- prevSpec = JSON.stringify(props.spec);
102
- }
103
-
104
- function destroyTileMap() {
105
- instance?.destroy();
106
- instance = null;
107
- prevSpec = '';
108
- }
109
-
110
- // Expose imperative access to the instance
111
- expose({
112
- get instance() {
113
- return instance;
114
- },
115
- });
116
-
117
- onMounted(() => {
118
- mountTileMap();
119
- });
120
-
121
- onUnmounted(() => {
122
- destroyTileMap();
123
- });
124
-
125
- // Watch spec changes
126
- watch(
127
- () => JSON.stringify(props.spec),
128
- (newVal) => {
129
- if (!instance) return;
130
- if (newVal !== prevSpec) {
131
- prevSpec = newVal;
132
- instance.update(props.spec);
133
- }
134
- },
135
- );
136
-
137
- // Recreate tilemap when theme or darkMode change
138
- watch(
139
- [
140
- () => props.theme,
141
- () => props.darkMode,
142
- () => contextTheme?.value,
143
- () => contextDarkMode?.value,
144
- ],
145
- () => {
146
- if (!containerRef.value) return;
147
- destroyTileMap();
148
- mountTileMap();
149
- },
150
- );
151
-
152
- const rootClass = () => {
153
- const base = 'oc-tilemap-root';
154
- return props.class ? `${base} ${props.class}` : base;
155
- };
156
-
157
- return () =>
158
- h('div', {
159
- ref: containerRef,
160
- class: rootClass(),
161
- style: props.style,
162
- });
163
- },
164
- });