@sqlrooms/cosmos 0.4.2 → 0.5.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 (56) hide show
  1. package/dist/CosmosGraph.d.ts +3 -3
  2. package/dist/CosmosGraph.d.ts.map +1 -1
  3. package/dist/CosmosGraph.js +51 -13
  4. package/dist/CosmosGraph.js.map +1 -1
  5. package/dist/CosmosGraphControls.d.ts +1 -1
  6. package/dist/CosmosGraphControls.js +4 -4
  7. package/dist/CosmosGraphControls.js.map +1 -1
  8. package/dist/CosmosSimulationControls.d.ts +1 -5
  9. package/dist/CosmosSimulationControls.d.ts.map +1 -1
  10. package/dist/CosmosSimulationControls.js +7 -28
  11. package/dist/CosmosSimulationControls.js.map +1 -1
  12. package/dist/CosmosSlice.d.ts +75 -0
  13. package/dist/CosmosSlice.d.ts.map +1 -0
  14. package/dist/CosmosSlice.js +153 -0
  15. package/dist/CosmosSlice.js.map +1 -0
  16. package/dist/CosmosSliceConfig.d.ts +209 -0
  17. package/dist/CosmosSliceConfig.d.ts.map +1 -0
  18. package/dist/CosmosSliceConfig.js +187 -0
  19. package/dist/CosmosSliceConfig.js.map +1 -0
  20. package/dist/hooks/useHoverState.d.ts +11 -8
  21. package/dist/hooks/useHoverState.d.ts.map +1 -1
  22. package/dist/hooks/useHoverState.js +13 -9
  23. package/dist/hooks/useHoverState.js.map +1 -1
  24. package/dist/index.d.ts +61 -27
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +62 -26
  27. package/dist/index.js.map +1 -1
  28. package/package.json +8 -4
  29. package/dist/CosmosGraphContext.d.ts +0 -76
  30. package/dist/CosmosGraphContext.d.ts.map +0 -1
  31. package/dist/CosmosGraphContext.js +0 -95
  32. package/dist/CosmosGraphContext.js.map +0 -1
  33. package/dist/components/CosmosGraph.d.ts +0 -14
  34. package/dist/components/CosmosGraph.d.ts.map +0 -1
  35. package/dist/components/CosmosGraph.js +0 -130
  36. package/dist/components/CosmosGraph.js.map +0 -1
  37. package/dist/config.d.ts +0 -24
  38. package/dist/config.d.ts.map +0 -1
  39. package/dist/config.js +0 -18
  40. package/dist/config.js.map +0 -1
  41. package/dist/hooks/index.d.ts +0 -29
  42. package/dist/hooks/index.d.ts.map +0 -1
  43. package/dist/hooks/index.js +0 -29
  44. package/dist/hooks/index.js.map +0 -1
  45. package/dist/hooks/useGraph.d.ts +0 -49
  46. package/dist/hooks/useGraph.d.ts.map +0 -1
  47. package/dist/hooks/useGraph.js +0 -93
  48. package/dist/hooks/useGraph.js.map +0 -1
  49. package/dist/hooks/useGraphConfig.d.ts +0 -101
  50. package/dist/hooks/useGraphConfig.d.ts.map +0 -1
  51. package/dist/hooks/useGraphConfig.js +0 -53
  52. package/dist/hooks/useGraphConfig.js.map +0 -1
  53. package/dist/hooks/useRelativeCoordinates.d.ts +0 -2
  54. package/dist/hooks/useRelativeCoordinates.d.ts.map +0 -1
  55. package/dist/hooks/useRelativeCoordinates.js +0 -10
  56. package/dist/hooks/useRelativeCoordinates.js.map +0 -1
@@ -0,0 +1,209 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Zod schema for validating and configuring the Cosmos graph visualization.
4
+ * This schema defines all available configuration options and their types.
5
+ *
6
+ * The configuration is divided into several categories:
7
+ *
8
+ * Node Appearance:
9
+ * - `pointSizeScale`: Controls the size of nodes
10
+ * - `scalePointsOnZoom`: Enables dynamic node sizing based on zoom level
11
+ *
12
+ * Link Appearance:
13
+ * - `renderLinks`: Toggles link visibility
14
+ * - `linkWidthScale`: Controls link thickness
15
+ * - `linkArrows`: Toggles directional arrows
16
+ * - `linkArrowsSizeScale`: Controls arrow size
17
+ * - `curvedLinks`: Toggles curved/straight links
18
+ *
19
+ * Physics Simulation:
20
+ * - `simulationGravity`: Central gravitational force (0.25)
21
+ * - `simulationRepulsion`: Node repulsion force (1.0)
22
+ * - `simulationLinkSpring`: Link spring force (1.0)
23
+ * - `simulationLinkDistance`: Natural link length (10)
24
+ * - `simulationFriction`: Movement damping (0.85)
25
+ * - `simulationDecay`: Simulation cooling rate (1000)
26
+ *
27
+ * @example Basic configuration
28
+ * ```typescript
29
+ * const config: CosmosSliceConfig = {
30
+ * cosmos: {
31
+ * pointSizeScale: 1.2,
32
+ * scalePointsOnZoom: true,
33
+ * renderLinks: true,
34
+ * linkWidthScale: 1.5,
35
+ * simulationGravity: 0.25
36
+ * }
37
+ * };
38
+ * ```
39
+ *
40
+ * @example Directed graph with curved links
41
+ * ```typescript
42
+ * const directedGraphConfig: CosmosSliceConfig = {
43
+ * cosmos: {
44
+ * linkArrows: true,
45
+ * linkArrowsSizeScale: 1.2,
46
+ * curvedLinks: true,
47
+ * simulationLinkDistance: 15,
48
+ * simulationLinkSpring: 1.2
49
+ * }
50
+ * };
51
+ * ```
52
+ *
53
+ * @example High-performance configuration for large graphs
54
+ * ```typescript
55
+ * const largeGraphConfig: CosmosSliceConfig = {
56
+ * cosmos: {
57
+ * simulationGravity: 0.1,
58
+ * simulationRepulsion: 0.8,
59
+ * simulationFriction: 0.9,
60
+ * simulationDecay: 2000,
61
+ * scalePointsOnZoom: false
62
+ * }
63
+ * };
64
+ * ```
65
+ */
66
+ export declare const CosmosSliceConfig: z.ZodObject<{
67
+ cosmos: z.ZodObject<{
68
+ /**
69
+ * Scale factor for point (node) sizes in the graph.
70
+ * Values > 1 make nodes larger, values < 1 make them smaller.
71
+ * @default 1.1
72
+ */
73
+ pointSizeScale: z.ZodNumber;
74
+ /**
75
+ * When true, nodes will dynamically resize based on the current zoom level.
76
+ * This helps maintain visual clarity at different zoom levels.
77
+ * @default true
78
+ */
79
+ scalePointsOnZoom: z.ZodBoolean;
80
+ /**
81
+ * Controls whether links (edges) between nodes are displayed.
82
+ * @default true
83
+ */
84
+ renderLinks: z.ZodBoolean;
85
+ /**
86
+ * Scale factor for link (edge) width.
87
+ * Values > 1 make links thicker, values < 1 make them thinner.
88
+ * @default 1
89
+ */
90
+ linkWidthScale: z.ZodNumber;
91
+ /**
92
+ * Scale factor for the size of directional arrows on links.
93
+ * Only applies when linkArrows is true.
94
+ * @default 1
95
+ */
96
+ linkArrowsSizeScale: z.ZodNumber;
97
+ /**
98
+ * When true, displays arrows indicating link direction.
99
+ * Useful for directed graphs.
100
+ * @default false
101
+ */
102
+ linkArrows: z.ZodBoolean;
103
+ /**
104
+ * When true, links are rendered as curved Bezier paths.
105
+ * When false, links are straight lines.
106
+ * @default false
107
+ */
108
+ curvedLinks: z.ZodBoolean;
109
+ /**
110
+ * Controls the strength of the central gravitational force.
111
+ * Higher values pull nodes more strongly toward the center.
112
+ * @default 0.25
113
+ */
114
+ simulationGravity: z.ZodNumber;
115
+ /**
116
+ * Controls how strongly nodes repel each other.
117
+ * Higher values create more space between unconnected nodes.
118
+ * @default 1.0
119
+ */
120
+ simulationRepulsion: z.ZodNumber;
121
+ /**
122
+ * Controls the strength of the spring force between linked nodes.
123
+ * Higher values pull connected nodes more tightly together.
124
+ * @default 1.0
125
+ */
126
+ simulationLinkSpring: z.ZodNumber;
127
+ /**
128
+ * The natural or resting length of links between nodes.
129
+ * Higher values create more spacing between connected nodes.
130
+ * @default 10
131
+ */
132
+ simulationLinkDistance: z.ZodNumber;
133
+ /**
134
+ * Controls how quickly node movement decays.
135
+ * Higher values (closer to 1) create more damped movement.
136
+ * @default 0.85
137
+ */
138
+ simulationFriction: z.ZodNumber;
139
+ /**
140
+ * Controls how quickly the simulation stabilizes.
141
+ * Lower values result in longer, smoother transitions.
142
+ * @default 1000
143
+ */
144
+ simulationDecay: z.ZodNumber;
145
+ }, "strip", z.ZodTypeAny, {
146
+ pointSizeScale: number;
147
+ renderLinks: boolean;
148
+ linkWidthScale: number;
149
+ curvedLinks: boolean;
150
+ linkArrows: boolean;
151
+ linkArrowsSizeScale: number;
152
+ simulationDecay: number;
153
+ simulationGravity: number;
154
+ simulationRepulsion: number;
155
+ simulationLinkSpring: number;
156
+ simulationLinkDistance: number;
157
+ simulationFriction: number;
158
+ scalePointsOnZoom: boolean;
159
+ }, {
160
+ pointSizeScale: number;
161
+ renderLinks: boolean;
162
+ linkWidthScale: number;
163
+ curvedLinks: boolean;
164
+ linkArrows: boolean;
165
+ linkArrowsSizeScale: number;
166
+ simulationDecay: number;
167
+ simulationGravity: number;
168
+ simulationRepulsion: number;
169
+ simulationLinkSpring: number;
170
+ simulationLinkDistance: number;
171
+ simulationFriction: number;
172
+ scalePointsOnZoom: boolean;
173
+ }>;
174
+ }, "strip", z.ZodTypeAny, {
175
+ cosmos: {
176
+ pointSizeScale: number;
177
+ renderLinks: boolean;
178
+ linkWidthScale: number;
179
+ curvedLinks: boolean;
180
+ linkArrows: boolean;
181
+ linkArrowsSizeScale: number;
182
+ simulationDecay: number;
183
+ simulationGravity: number;
184
+ simulationRepulsion: number;
185
+ simulationLinkSpring: number;
186
+ simulationLinkDistance: number;
187
+ simulationFriction: number;
188
+ scalePointsOnZoom: boolean;
189
+ };
190
+ }, {
191
+ cosmos: {
192
+ pointSizeScale: number;
193
+ renderLinks: boolean;
194
+ linkWidthScale: number;
195
+ curvedLinks: boolean;
196
+ linkArrows: boolean;
197
+ linkArrowsSizeScale: number;
198
+ simulationDecay: number;
199
+ simulationGravity: number;
200
+ simulationRepulsion: number;
201
+ simulationLinkSpring: number;
202
+ simulationLinkDistance: number;
203
+ simulationFriction: number;
204
+ scalePointsOnZoom: boolean;
205
+ };
206
+ }>;
207
+ export type CosmosSliceConfig = z.infer<typeof CosmosSliceConfig>;
208
+ export declare function createDefaultCosmosConfig(): CosmosSliceConfig;
209
+ //# sourceMappingURL=CosmosSliceConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CosmosSliceConfig.d.ts","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAuBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,iBAAiB;;QAE1B;;;;WAIG;;QAGH;;;;WAIG;;QAKH;;;WAGG;;QAGH;;;;WAIG;;QAGH;;;;WAIG;;QAKH;;;;WAIG;;QAKH;;;;WAIG;;QAOH;;;;WAIG;;QAGH;;;;WAIG;;QAGH;;;;WAIG;;QAKH;;;;WAIG;;QAKH;;;;WAIG;;QAKH;;;;WAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOL,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,wBAAgB,yBAAyB,IAAI,iBAAiB,CAI7D"}
@@ -0,0 +1,187 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Default configuration values for the Cosmos graph visualization.
4
+ * These values provide a balanced starting point for most graph visualizations.
5
+ */
6
+ const DEFAULT_COSMOS_CONFIG = {
7
+ pointSizeScale: 1.1,
8
+ scalePointsOnZoom: true,
9
+ simulationGravity: 0.25,
10
+ simulationRepulsion: 1.0,
11
+ simulationLinkSpring: 1.0,
12
+ simulationLinkDistance: 10,
13
+ simulationFriction: 0.85,
14
+ simulationDecay: 1000,
15
+ renderLinks: true,
16
+ linkArrows: false,
17
+ curvedLinks: false,
18
+ linkWidthScale: 1,
19
+ linkArrowsSizeScale: 1,
20
+ };
21
+ /**
22
+ * Zod schema for validating and configuring the Cosmos graph visualization.
23
+ * This schema defines all available configuration options and their types.
24
+ *
25
+ * The configuration is divided into several categories:
26
+ *
27
+ * Node Appearance:
28
+ * - `pointSizeScale`: Controls the size of nodes
29
+ * - `scalePointsOnZoom`: Enables dynamic node sizing based on zoom level
30
+ *
31
+ * Link Appearance:
32
+ * - `renderLinks`: Toggles link visibility
33
+ * - `linkWidthScale`: Controls link thickness
34
+ * - `linkArrows`: Toggles directional arrows
35
+ * - `linkArrowsSizeScale`: Controls arrow size
36
+ * - `curvedLinks`: Toggles curved/straight links
37
+ *
38
+ * Physics Simulation:
39
+ * - `simulationGravity`: Central gravitational force (0.25)
40
+ * - `simulationRepulsion`: Node repulsion force (1.0)
41
+ * - `simulationLinkSpring`: Link spring force (1.0)
42
+ * - `simulationLinkDistance`: Natural link length (10)
43
+ * - `simulationFriction`: Movement damping (0.85)
44
+ * - `simulationDecay`: Simulation cooling rate (1000)
45
+ *
46
+ * @example Basic configuration
47
+ * ```typescript
48
+ * const config: CosmosSliceConfig = {
49
+ * cosmos: {
50
+ * pointSizeScale: 1.2,
51
+ * scalePointsOnZoom: true,
52
+ * renderLinks: true,
53
+ * linkWidthScale: 1.5,
54
+ * simulationGravity: 0.25
55
+ * }
56
+ * };
57
+ * ```
58
+ *
59
+ * @example Directed graph with curved links
60
+ * ```typescript
61
+ * const directedGraphConfig: CosmosSliceConfig = {
62
+ * cosmos: {
63
+ * linkArrows: true,
64
+ * linkArrowsSizeScale: 1.2,
65
+ * curvedLinks: true,
66
+ * simulationLinkDistance: 15,
67
+ * simulationLinkSpring: 1.2
68
+ * }
69
+ * };
70
+ * ```
71
+ *
72
+ * @example High-performance configuration for large graphs
73
+ * ```typescript
74
+ * const largeGraphConfig: CosmosSliceConfig = {
75
+ * cosmos: {
76
+ * simulationGravity: 0.1,
77
+ * simulationRepulsion: 0.8,
78
+ * simulationFriction: 0.9,
79
+ * simulationDecay: 2000,
80
+ * scalePointsOnZoom: false
81
+ * }
82
+ * };
83
+ * ```
84
+ */
85
+ export const CosmosSliceConfig = z.object({
86
+ cosmos: z.object({
87
+ /**
88
+ * Scale factor for point (node) sizes in the graph.
89
+ * Values > 1 make nodes larger, values < 1 make them smaller.
90
+ * @default 1.1
91
+ */
92
+ pointSizeScale: z.number().describe('Scale factor for point sizes'),
93
+ /**
94
+ * When true, nodes will dynamically resize based on the current zoom level.
95
+ * This helps maintain visual clarity at different zoom levels.
96
+ * @default true
97
+ */
98
+ scalePointsOnZoom: z
99
+ .boolean()
100
+ .describe('Dynamically resize points based on zoom level'),
101
+ /**
102
+ * Controls whether links (edges) between nodes are displayed.
103
+ * @default true
104
+ */
105
+ renderLinks: z.boolean().describe('Control links displaying'),
106
+ /**
107
+ * Scale factor for link (edge) width.
108
+ * Values > 1 make links thicker, values < 1 make them thinner.
109
+ * @default 1
110
+ */
111
+ linkWidthScale: z.number().describe('Scale factor for link width'),
112
+ /**
113
+ * Scale factor for the size of directional arrows on links.
114
+ * Only applies when linkArrows is true.
115
+ * @default 1
116
+ */
117
+ linkArrowsSizeScale: z
118
+ .number()
119
+ .describe('Scale factor for link arrows size'),
120
+ /**
121
+ * When true, displays arrows indicating link direction.
122
+ * Useful for directed graphs.
123
+ * @default false
124
+ */
125
+ linkArrows: z
126
+ .boolean()
127
+ .describe('Control displaying link direction arrows'),
128
+ /**
129
+ * When true, links are rendered as curved Bezier paths.
130
+ * When false, links are straight lines.
131
+ * @default false
132
+ */
133
+ curvedLinks: z
134
+ .boolean()
135
+ .describe('Render links as curved bezier paths instead of straight lines'),
136
+ /**
137
+ * Controls the strength of the central gravitational force.
138
+ * Higher values pull nodes more strongly toward the center.
139
+ * @default 0.25
140
+ */
141
+ simulationGravity: z.number().describe('Gravity force in the simulation'),
142
+ /**
143
+ * Controls how strongly nodes repel each other.
144
+ * Higher values create more space between unconnected nodes.
145
+ * @default 1.0
146
+ */
147
+ simulationRepulsion: z.number().describe('Repulsion force between nodes'),
148
+ /**
149
+ * Controls the strength of the spring force between linked nodes.
150
+ * Higher values pull connected nodes more tightly together.
151
+ * @default 1.0
152
+ */
153
+ simulationLinkSpring: z
154
+ .number()
155
+ .describe('Spring force for links between nodes'),
156
+ /**
157
+ * The natural or resting length of links between nodes.
158
+ * Higher values create more spacing between connected nodes.
159
+ * @default 10
160
+ */
161
+ simulationLinkDistance: z
162
+ .number()
163
+ .describe('Target distance between linked nodes'),
164
+ /**
165
+ * Controls how quickly node movement decays.
166
+ * Higher values (closer to 1) create more damped movement.
167
+ * @default 0.85
168
+ */
169
+ simulationFriction: z
170
+ .number()
171
+ .describe('Friction coefficient in the simulation'),
172
+ /**
173
+ * Controls how quickly the simulation stabilizes.
174
+ * Lower values result in longer, smoother transitions.
175
+ * @default 1000
176
+ */
177
+ simulationDecay: z
178
+ .number()
179
+ .describe('Decay coefficient in the simulation. Use smaller values if you want the simulation to "cool down" slower.'),
180
+ }),
181
+ });
182
+ export function createDefaultCosmosConfig() {
183
+ return {
184
+ cosmos: DEFAULT_COSMOS_CONFIG,
185
+ };
186
+ }
187
+ //# sourceMappingURL=CosmosSliceConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CosmosSliceConfig.js","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB;;;GAGG;AACH,MAAM,qBAAqB,GAAgC;IACzD,cAAc,EAAE,GAAG;IACnB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,mBAAmB,EAAE,GAAG;IACxB,oBAAoB,EAAE,GAAG;IACzB,sBAAsB,EAAE,EAAE;IAC1B,kBAAkB,EAAE,IAAI;IACxB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,KAAK;IAClB,cAAc,EAAE,CAAC;IACjB,mBAAmB,EAAE,CAAC;CAC0B,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf;;;;WAIG;QACH,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QAEnE;;;;WAIG;QACH,iBAAiB,EAAE,CAAC;aACjB,OAAO,EAAE;aACT,QAAQ,CAAC,+CAA+C,CAAC;QAE5D;;;WAGG;QACH,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC;QAE7D;;;;WAIG;QACH,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;QAElE;;;;WAIG;QACH,mBAAmB,EAAE,CAAC;aACnB,MAAM,EAAE;aACR,QAAQ,CAAC,mCAAmC,CAAC;QAEhD;;;;WAIG;QACH,UAAU,EAAE,CAAC;aACV,OAAO,EAAE;aACT,QAAQ,CAAC,0CAA0C,CAAC;QAEvD;;;;WAIG;QACH,WAAW,EAAE,CAAC;aACX,OAAO,EAAE;aACT,QAAQ,CACP,+DAA+D,CAChE;QAEH;;;;WAIG;QACH,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QAEzE;;;;WAIG;QACH,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QAEzE;;;;WAIG;QACH,oBAAoB,EAAE,CAAC;aACpB,MAAM,EAAE;aACR,QAAQ,CAAC,sCAAsC,CAAC;QAEnD;;;;WAIG;QACH,sBAAsB,EAAE,CAAC;aACtB,MAAM,EAAE;aACR,QAAQ,CAAC,sCAAsC,CAAC;QAEnD;;;;WAIG;QACH,kBAAkB,EAAE,CAAC;aAClB,MAAM,EAAE;aACR,QAAQ,CAAC,wCAAwC,CAAC;QAErD;;;;WAIG;QACH,eAAe,EAAE,CAAC;aACf,MAAM,EAAE;aACR,QAAQ,CACP,2GAA2G,CAC5G;KAC2D,CAAC;CAClE,CAAC,CAAC;AAGH,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,MAAM,EAAE,qBAAqB;KAC9B,CAAC;AACJ,CAAC"}
@@ -17,18 +17,18 @@ export type HoverState = {
17
17
  * - Track which point is currently being hovered
18
18
  * - Store the hover position coordinates
19
19
  * - Clear the hover state
20
+ * - Provide event handlers for hover-related graph interactions
20
21
  *
21
22
  * @example
22
23
  * ```tsx
23
24
  * const Graph = () => {
24
25
  * const calcRelativeCoords = useRelativeCoordinates(containerRef);
25
- * const { hoveredPoint, onPointMouseOver, clearHoverState } = useHoverState(calcRelativeCoords);
26
+ * const { hoveredPoint, eventHandlers } = useHoverState(calcRelativeCoords);
26
27
  *
27
28
  * return (
28
29
  * <div ref={containerRef}>
29
30
  * <CosmosGraph
30
- * onPointMouseOver={onPointMouseOver}
31
- * onPointMouseOut={clearHoverState}
31
+ * config={eventHandlers}
32
32
  * />
33
33
  * {hoveredPoint && (
34
34
  * <Tooltip
@@ -42,14 +42,17 @@ export type HoverState = {
42
42
  * ```
43
43
  *
44
44
  * @param calcRelativeCoordinates - A function that converts client coordinates to container-relative coordinates
45
- * @returns An object containing the hover state and handlers
45
+ * @returns An object containing the hover state and event handlers for the graph
46
46
  */
47
47
  export declare const useHoverState: (calcRelativeCoordinates: ReturnType<typeof useRelativeCoordinates>) => {
48
48
  /** The current hover state, containing the index and position of the hovered point, or null if no point is hovered */
49
49
  hoveredPoint: HoverState;
50
- /** Handler to be called when a point is hovered. Updates the hover state with the point's index and position */
51
- onPointMouseOver: (index: number, pointPosition: [number, number], event: MouseEvent | D3DragEvent<HTMLCanvasElement, undefined, import("@cosmograph/cosmos/dist/modules/Store").Hovered> | D3ZoomEvent<HTMLCanvasElement, undefined> | undefined) => void;
52
- /** Handler to clear the hover state, typically called when the mouse leaves a point */
53
- clearHoverState: () => void;
50
+ /** Event handlers for hover-related graph interactions */
51
+ eventHandlers: {
52
+ onPointMouseOver: (index: number, pointPosition: [number, number], event: MouseEvent | D3DragEvent<HTMLCanvasElement, undefined, import("@cosmograph/cosmos/dist/modules/Store").Hovered> | D3ZoomEvent<HTMLCanvasElement, undefined> | undefined) => void;
53
+ onPointMouseOut: () => void;
54
+ onZoomStart: () => void;
55
+ onDragStart: () => void;
56
+ };
54
57
  };
55
58
  //# sourceMappingURL=useHoverState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHoverState.d.ts","sourceRoot":"","sources":["../../src/hooks/useHoverState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,cAAc,CAAC;AAKpD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B,GAAG,IAAI,CAAC;AAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,aAAa,4BACC,UAAU,CAAC,OAAO,sBAAsB,CAAC;IAwBhE,sHAAsH;;IAEtH,gHAAgH;;IAEhH,uFAAuF;;CAG1F,CAAC"}
1
+ {"version":3,"file":"useHoverState.d.ts","sourceRoot":"","sources":["../../src/hooks/useHoverState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,cAAc,CAAC;AAKpD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B,GAAG,IAAI,CAAC;AAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,aAAa,4BACC,UAAU,CAAC,OAAO,sBAAsB,CAAC;IAkChE,sHAAsH;;IAEtH,0DAA0D;;;;;;;CAG7D,CAAC"}
@@ -1,4 +1,4 @@
1
- import { useState, useCallback } from 'react';
1
+ import { useState, useCallback, useMemo } from 'react';
2
2
  import { hasClientCoordinates } from '../utils/coordinates';
3
3
  /**
4
4
  * A custom hook that manages hover state for graph points.
@@ -7,18 +7,18 @@ import { hasClientCoordinates } from '../utils/coordinates';
7
7
  * - Track which point is currently being hovered
8
8
  * - Store the hover position coordinates
9
9
  * - Clear the hover state
10
+ * - Provide event handlers for hover-related graph interactions
10
11
  *
11
12
  * @example
12
13
  * ```tsx
13
14
  * const Graph = () => {
14
15
  * const calcRelativeCoords = useRelativeCoordinates(containerRef);
15
- * const { hoveredPoint, onPointMouseOver, clearHoverState } = useHoverState(calcRelativeCoords);
16
+ * const { hoveredPoint, eventHandlers } = useHoverState(calcRelativeCoords);
16
17
  *
17
18
  * return (
18
19
  * <div ref={containerRef}>
19
20
  * <CosmosGraph
20
- * onPointMouseOver={onPointMouseOver}
21
- * onPointMouseOut={clearHoverState}
21
+ * config={eventHandlers}
22
22
  * />
23
23
  * {hoveredPoint && (
24
24
  * <Tooltip
@@ -32,7 +32,7 @@ import { hasClientCoordinates } from '../utils/coordinates';
32
32
  * ```
33
33
  *
34
34
  * @param calcRelativeCoordinates - A function that converts client coordinates to container-relative coordinates
35
- * @returns An object containing the hover state and handlers
35
+ * @returns An object containing the hover state and event handlers for the graph
36
36
  */
37
37
  export const useHoverState = (calcRelativeCoordinates) => {
38
38
  const [hoveredPoint, setHoveredPoint] = useState(null);
@@ -45,13 +45,17 @@ export const useHoverState = (calcRelativeCoordinates) => {
45
45
  }
46
46
  }, [calcRelativeCoordinates]);
47
47
  const clearHoverState = useCallback(() => setHoveredPoint(null), []);
48
+ const eventHandlers = useMemo(() => ({
49
+ onPointMouseOver,
50
+ onPointMouseOut: clearHoverState,
51
+ onZoomStart: clearHoverState,
52
+ onDragStart: clearHoverState,
53
+ }), [onPointMouseOver, clearHoverState]);
48
54
  return {
49
55
  /** The current hover state, containing the index and position of the hovered point, or null if no point is hovered */
50
56
  hoveredPoint,
51
- /** Handler to be called when a point is hovered. Updates the hover state with the point's index and position */
52
- onPointMouseOver,
53
- /** Handler to clear the hover state, typically called when the mouse leaves a point */
54
- clearHoverState,
57
+ /** Event handlers for hover-related graph interactions */
58
+ eventHandlers,
55
59
  };
56
60
  };
57
61
  //# sourceMappingURL=useHoverState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHoverState.js","sourceRoot":"","sources":["../../src/hooks/useHoverState.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAe1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,uBAAkE,EAClE,EAAE;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAa,IAAI,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GACpB,WAAW,CACT,CACE,KAAa,EACb,cAAgC,EAChC,KAA8B,EAC9B,EAAE;QACF,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,eAAe,CAAC;gBACd,KAAK;gBACL,QAAQ,EAAE,uBAAuB,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EACD,CAAC,uBAAuB,CAAC,CAC1B,CAAC;IAEJ,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAErE,OAAO;QACL,sHAAsH;QACtH,YAAY;QACZ,gHAAgH;QAChH,gBAAgB;QAChB,uFAAuF;QACvF,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"useHoverState.js","sourceRoot":"","sources":["../../src/hooks/useHoverState.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAe1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,uBAAkE,EAClE,EAAE;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAa,IAAI,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GACpB,WAAW,CACT,CACE,KAAa,EACb,cAAgC,EAChC,KAA8B,EAC9B,EAAE;QACF,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,eAAe,CAAC;gBACd,KAAK;gBACL,QAAQ,EAAE,uBAAuB,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EACD,CAAC,uBAAuB,CAAC,CAC1B,CAAC;IAEJ,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAErE,MAAM,aAAa,GAAG,OAAO,CAC3B,GAAG,EAAE,CAAC,CAAC;QACL,gBAAgB;QAChB,eAAe,EAAE,eAAe;QAChC,WAAW,EAAE,eAAe;QAC5B,WAAW,EAAE,eAAe;KAC7B,CAAC,EACF,CAAC,gBAAgB,EAAE,eAAe,CAAC,CACpC,CAAC;IAEF,OAAO;QACL,sHAAsH;QACtH,YAAY;QACZ,0DAA0D;QAC1D,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * This package provides React components and hooks for creating interactive graph visualizations
5
5
  * using the Cosmograph WebGL-based graph visualization library. It includes components for
6
- * rendering graphs, managing graph state, and controlling graph interactions.
6
+ * rendering graphs, managing graph state through zustand, and controlling graph interactions.
7
7
  *
8
8
  * @example Basic usage
9
9
  * ```tsx
@@ -31,7 +31,7 @@ export { CosmosGraph } from './CosmosGraph';
31
31
  export { CosmosGraphControls } from './CosmosGraphControls';
32
32
  /**
33
33
  * A component that provides fine-grained controls for the graph simulation parameters.
34
- * Must be used within a CosmosGraph component as it relies on the CosmosGraphContext.
34
+ * Uses the zustand store to access and control the graph state.
35
35
  *
36
36
  * Features:
37
37
  * - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
@@ -55,38 +55,72 @@ export { CosmosGraphControls } from './CosmosGraphControls';
55
55
  */
56
56
  export { CosmosSimulationControls } from './CosmosSimulationControls';
57
57
  export type { CosmosGraphProps } from './CosmosGraph';
58
- export { useCosmosGraph } from './CosmosGraphContext';
59
- export { useGraph, useHoverState, useGraphConfig } from './hooks';
60
- export type { HoverState } from './hooks/useHoverState';
61
- export type { WithClientCoordinates } from './utils/coordinates';
62
- export { hasClientCoordinates } from './utils/coordinates';
58
+ export { useHoverState } from './hooks/useHoverState';
59
+ export { createCosmosSlice, useStoreWithCosmos, type CosmosSliceState, type ProjectStateWithCosmos, } from './CosmosSlice';
60
+ export { CosmosSliceConfig, createDefaultCosmosConfig, type CosmosSliceConfig as CosmosSliceConfigType, } from './CosmosSliceConfig';
63
61
  /**
64
- * Zod schema for validating and describing graph simulation configuration parameters.
62
+ * Configuration schema for the Cosmos graph visualization system.
63
+ * Provides type-safe validation and configuration options for both visual and physics aspects of the graph.
65
64
  *
66
- * Available parameters:
67
- * - `simulationGravity` (number): Gravity force in the simulation. Controls how strongly nodes are pulled toward the center.
68
- * - `simulationRepulsion` (number): Repulsion force between nodes. Higher values make nodes push away from each other more strongly.
69
- * - `simulationLinkSpring` (number): Spring force for links between nodes. Higher values make connected nodes pull together more strongly.
70
- * - `simulationLinkDistance` (number): Target distance between linked nodes. Defines the natural length of links in the simulation.
71
- * - `simulationFriction` (number): Friction coefficient in the simulation. Higher values make node movement more damped.
72
- * - `simulationDecay` (number): Decay coefficient in the simulation. Lower values make the simulation "cool down" more slowly.
65
+ * Configuration Categories:
73
66
  *
74
- * @example
67
+ * 1. Visual Appearance
68
+ * - Node styling: size scaling and zoom behavior
69
+ * - Link styling: visibility, width, arrows, and curve options
70
+ *
71
+ * 2. Physics Simulation
72
+ * - Gravity: Central force pulling nodes toward center
73
+ * - Repulsion: Force pushing nodes apart
74
+ * - Link Forces: Spring forces and distances between connected nodes
75
+ * - Dynamics: Friction and decay rates for movement
76
+ *
77
+ * Key Parameters:
78
+ * - `pointSizeScale` (number): Base scale for node sizes (default: 1.1)
79
+ * - `scalePointsOnZoom` (boolean): Dynamic node sizing with zoom (default: true)
80
+ * - `renderLinks` (boolean): Toggle link visibility (default: true)
81
+ * - `linkArrows` (boolean): Show directional arrows (default: false)
82
+ * - `curvedLinks` (boolean): Use curved or straight links (default: false)
83
+ * - `simulationGravity` (number): Center attraction strength (default: 0.25)
84
+ * - `simulationRepulsion` (number): Node repulsion strength (default: 1.0)
85
+ * - `simulationLinkSpring` (number): Link elasticity (default: 1.0)
86
+ * - `simulationFriction` (number): Movement damping (default: 0.85)
87
+ * - `simulationDecay` (number): Simulation cooling rate (default: 1000)
88
+ *
89
+ * @example Typical usage with default-like values
75
90
  * ```tsx
76
- * import { CosmosSimulationConfigSchema } from '@sqlrooms/cosmos';
91
+ * import { CosmosGraph, createDefaultCosmosConfig } from '@sqlrooms/cosmos';
92
+ *
93
+ * const config = createDefaultCosmosConfig();
94
+ *
95
+ * function MyGraph() {
96
+ * return (
97
+ * <CosmosGraph
98
+ * config={config}
99
+ * data={graphData}
100
+ * />
101
+ * );
102
+ * }
103
+ * ```
77
104
  *
105
+ * @example Custom configuration for directed graph
106
+ * ```tsx
78
107
  * const config = {
79
- * simulationGravity: 0.1,
80
- * simulationRepulsion: 1.0,
81
- * simulationLinkSpring: 1.0,
82
- * simulationLinkDistance: 10,
83
- * simulationFriction: 0.85,
84
- * simulationDecay: 1000
85
- * };
108
+ * cosmos: {
109
+ * // Visual settings
110
+ * pointSizeScale: 1.2,
111
+ * linkArrows: true,
112
+ * curvedLinks: true,
86
113
  *
87
- * // Validate the config
88
- * const validConfig = CosmosSimulationConfigSchema.parse(config);
114
+ * // Physics settings
115
+ * simulationGravity: 0.2,
116
+ * simulationLinkDistance: 15,
117
+ * simulationLinkSpring: 1.2
118
+ * }
119
+ * };
89
120
  * ```
121
+ *
122
+ * @see {@link CosmosGraph} For the main graph component
123
+ * @see {@link CosmosSimulationControls} For runtime control of simulation parameters
90
124
  */
91
- export { CosmosSimulationConfigSchema } from './config';
125
+ export * from './CosmosSliceConfig';
92
126
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AACpE,YAAY,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAChE,YAAY,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAGtD,YAAY,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAC,4BAA4B,EAAC,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AACpE,YAAY,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,KAAK,iBAAiB,IAAI,qBAAqB,GAChD,MAAM,qBAAqB,CAAC;AAG7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,cAAc,qBAAqB,CAAC"}