@sqlrooms/cosmos 0.4.2 → 0.5.1
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/CosmosGraph.d.ts +3 -3
- package/dist/CosmosGraph.d.ts.map +1 -1
- package/dist/CosmosGraph.js +51 -13
- package/dist/CosmosGraph.js.map +1 -1
- package/dist/CosmosGraphControls.d.ts +1 -1
- package/dist/CosmosGraphControls.js +4 -4
- package/dist/CosmosGraphControls.js.map +1 -1
- package/dist/CosmosSimulationControls.d.ts +1 -5
- package/dist/CosmosSimulationControls.d.ts.map +1 -1
- package/dist/CosmosSimulationControls.js +7 -28
- package/dist/CosmosSimulationControls.js.map +1 -1
- package/dist/CosmosSlice.d.ts +75 -0
- package/dist/CosmosSlice.d.ts.map +1 -0
- package/dist/CosmosSlice.js +153 -0
- package/dist/CosmosSlice.js.map +1 -0
- package/dist/CosmosSliceConfig.d.ts +209 -0
- package/dist/CosmosSliceConfig.d.ts.map +1 -0
- package/dist/CosmosSliceConfig.js +187 -0
- package/dist/CosmosSliceConfig.js.map +1 -0
- package/dist/hooks/useHoverState.d.ts +11 -8
- package/dist/hooks/useHoverState.d.ts.map +1 -1
- package/dist/hooks/useHoverState.js +13 -9
- package/dist/hooks/useHoverState.js.map +1 -1
- package/dist/index.d.ts +61 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -26
- package/dist/index.js.map +1 -1
- package/dist/utils/coordinates.js.map +1 -1
- package/package.json +8 -4
- package/dist/CosmosGraphContext.d.ts +0 -76
- package/dist/CosmosGraphContext.d.ts.map +0 -1
- package/dist/CosmosGraphContext.js +0 -95
- package/dist/CosmosGraphContext.js.map +0 -1
- package/dist/components/CosmosGraph.d.ts +0 -14
- package/dist/components/CosmosGraph.d.ts.map +0 -1
- package/dist/components/CosmosGraph.js +0 -130
- package/dist/components/CosmosGraph.js.map +0 -1
- package/dist/config.d.ts +0 -24
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -18
- package/dist/config.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -29
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -29
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useGraph.d.ts +0 -49
- package/dist/hooks/useGraph.d.ts.map +0 -1
- package/dist/hooks/useGraph.js +0 -93
- package/dist/hooks/useGraph.js.map +0 -1
- package/dist/hooks/useGraphConfig.d.ts +0 -101
- package/dist/hooks/useGraphConfig.d.ts.map +0 -1
- package/dist/hooks/useGraphConfig.js +0 -53
- package/dist/hooks/useGraphConfig.js.map +0 -1
- package/dist/hooks/useRelativeCoordinates.d.ts +0 -2
- package/dist/hooks/useRelativeCoordinates.d.ts.map +0 -1
- package/dist/hooks/useRelativeCoordinates.js +0 -10
- package/dist/hooks/useRelativeCoordinates.js.map +0 -1
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
|
-
*
|
|
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 {
|
|
59
|
-
export {
|
|
60
|
-
export type
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
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
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* simulationDecay: 1000
|
|
85
|
-
* };
|
|
108
|
+
* cosmos: {
|
|
109
|
+
* // Visual settings
|
|
110
|
+
* pointSizeScale: 1.2,
|
|
111
|
+
* linkArrows: true,
|
|
112
|
+
* curvedLinks: true,
|
|
86
113
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
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
|
|
125
|
+
export * from './CosmosSliceConfig';
|
|
92
126
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/index.js
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
|
|
@@ -32,7 +32,7 @@ export { CosmosGraph } from './CosmosGraph';
|
|
|
32
32
|
export { CosmosGraphControls } from './CosmosGraphControls';
|
|
33
33
|
/**
|
|
34
34
|
* A component that provides fine-grained controls for the graph simulation parameters.
|
|
35
|
-
*
|
|
35
|
+
* Uses the zustand store to access and control the graph state.
|
|
36
36
|
*
|
|
37
37
|
* Features:
|
|
38
38
|
* - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
|
|
@@ -55,38 +55,74 @@ export { CosmosGraphControls } from './CosmosGraphControls';
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
export { CosmosSimulationControls } from './CosmosSimulationControls';
|
|
58
|
-
//
|
|
59
|
-
export {
|
|
60
|
-
export {
|
|
61
|
-
export {
|
|
58
|
+
// State management
|
|
59
|
+
export { useHoverState } from './hooks/useHoverState';
|
|
60
|
+
export { createCosmosSlice, useStoreWithCosmos, } from './CosmosSlice';
|
|
61
|
+
export { CosmosSliceConfig, createDefaultCosmosConfig, } from './CosmosSliceConfig';
|
|
62
62
|
// Configuration
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Configuration schema for the Cosmos graph visualization system.
|
|
65
|
+
* Provides type-safe validation and configuration options for both visual and physics aspects of the graph.
|
|
65
66
|
*
|
|
66
|
-
*
|
|
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.
|
|
67
|
+
* Configuration Categories:
|
|
73
68
|
*
|
|
74
|
-
*
|
|
69
|
+
* 1. Visual Appearance
|
|
70
|
+
* - Node styling: size scaling and zoom behavior
|
|
71
|
+
* - Link styling: visibility, width, arrows, and curve options
|
|
72
|
+
*
|
|
73
|
+
* 2. Physics Simulation
|
|
74
|
+
* - Gravity: Central force pulling nodes toward center
|
|
75
|
+
* - Repulsion: Force pushing nodes apart
|
|
76
|
+
* - Link Forces: Spring forces and distances between connected nodes
|
|
77
|
+
* - Dynamics: Friction and decay rates for movement
|
|
78
|
+
*
|
|
79
|
+
* Key Parameters:
|
|
80
|
+
* - `pointSizeScale` (number): Base scale for node sizes (default: 1.1)
|
|
81
|
+
* - `scalePointsOnZoom` (boolean): Dynamic node sizing with zoom (default: true)
|
|
82
|
+
* - `renderLinks` (boolean): Toggle link visibility (default: true)
|
|
83
|
+
* - `linkArrows` (boolean): Show directional arrows (default: false)
|
|
84
|
+
* - `curvedLinks` (boolean): Use curved or straight links (default: false)
|
|
85
|
+
* - `simulationGravity` (number): Center attraction strength (default: 0.25)
|
|
86
|
+
* - `simulationRepulsion` (number): Node repulsion strength (default: 1.0)
|
|
87
|
+
* - `simulationLinkSpring` (number): Link elasticity (default: 1.0)
|
|
88
|
+
* - `simulationFriction` (number): Movement damping (default: 0.85)
|
|
89
|
+
* - `simulationDecay` (number): Simulation cooling rate (default: 1000)
|
|
90
|
+
*
|
|
91
|
+
* @example Typical usage with default-like values
|
|
75
92
|
* ```tsx
|
|
76
|
-
* import {
|
|
93
|
+
* import { CosmosGraph, createDefaultCosmosConfig } from '@sqlrooms/cosmos';
|
|
94
|
+
*
|
|
95
|
+
* const config = createDefaultCosmosConfig();
|
|
96
|
+
*
|
|
97
|
+
* function MyGraph() {
|
|
98
|
+
* return (
|
|
99
|
+
* <CosmosGraph
|
|
100
|
+
* config={config}
|
|
101
|
+
* data={graphData}
|
|
102
|
+
* />
|
|
103
|
+
* );
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
77
106
|
*
|
|
107
|
+
* @example Custom configuration for directed graph
|
|
108
|
+
* ```tsx
|
|
78
109
|
* const config = {
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* simulationDecay: 1000
|
|
85
|
-
* };
|
|
110
|
+
* cosmos: {
|
|
111
|
+
* // Visual settings
|
|
112
|
+
* pointSizeScale: 1.2,
|
|
113
|
+
* linkArrows: true,
|
|
114
|
+
* curvedLinks: true,
|
|
86
115
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
116
|
+
* // Physics settings
|
|
117
|
+
* simulationGravity: 0.2,
|
|
118
|
+
* simulationLinkDistance: 15,
|
|
119
|
+
* simulationLinkSpring: 1.2
|
|
120
|
+
* }
|
|
121
|
+
* };
|
|
89
122
|
* ```
|
|
123
|
+
*
|
|
124
|
+
* @see {@link CosmosGraph} For the main graph component
|
|
125
|
+
* @see {@link CosmosSimulationControls} For runtime control of simulation parameters
|
|
90
126
|
*/
|
|
91
|
-
export
|
|
127
|
+
export * from './CosmosSliceConfig';
|
|
92
128
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,aAAa;AACb,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;AAGpE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,aAAa;AACb,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;AAGpE,mBAAmB;AACnB,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,yBAAyB,GAE1B,MAAM,qBAAqB,CAAC;AAE7B,gBAAgB;AAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,cAAc,qBAAqB,CAAC","sourcesContent":["/**\n * @sqlrooms/cosmos - A React wrapper for the Cosmograph visualization library\n *\n * This package provides React components and hooks for creating interactive graph visualizations\n * using the Cosmograph WebGL-based graph visualization library. It includes components for\n * rendering graphs, managing graph state through zustand, and controlling graph interactions.\n *\n * @example Basic usage\n * ```tsx\n * import { CosmosGraph, CosmosGraphControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <div style={{ width: '800px', height: '600px' }}>\n * <CosmosGraph\n * config={graphConfig}\n * pointPositions={positions}\n * pointColors={colors}\n * pointSizes={sizes}\n * >\n * <CosmosGraphControls />\n * </CosmosGraph>\n * </div>\n * );\n * };\n * ```\n *\n * @packageDocumentation\n */\n\n// Components\nexport {CosmosGraph} from './CosmosGraph';\nexport {CosmosGraphControls} from './CosmosGraphControls';\n\n/**\n * A component that provides fine-grained controls for the graph simulation parameters.\n * Uses the zustand store to access and control the graph state.\n *\n * Features:\n * - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay\n * - Real-time parameter adjustment with immediate visual feedback\n * - Tooltips with parameter descriptions\n * - Customizable positioning\n *\n * @example Basic usage\n * ```tsx\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls />\n * </CosmosGraph>\n * ```\n *\n * @example Custom positioning\n * ```tsx\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls className=\"absolute bottom-4 left-4\" />\n * </CosmosGraph>\n * ```\n */\nexport {CosmosSimulationControls} from './CosmosSimulationControls';\nexport type {CosmosGraphProps} from './CosmosGraph';\n\n// State management\nexport {useHoverState} from './hooks/useHoverState';\nexport {\n createCosmosSlice,\n useStoreWithCosmos,\n type CosmosSliceState,\n type ProjectStateWithCosmos,\n} from './CosmosSlice';\nexport {\n CosmosSliceConfig,\n createDefaultCosmosConfig,\n type CosmosSliceConfig as CosmosSliceConfigType,\n} from './CosmosSliceConfig';\n\n// Configuration\n/**\n * Configuration schema for the Cosmos graph visualization system.\n * Provides type-safe validation and configuration options for both visual and physics aspects of the graph.\n *\n * Configuration Categories:\n *\n * 1. Visual Appearance\n * - Node styling: size scaling and zoom behavior\n * - Link styling: visibility, width, arrows, and curve options\n *\n * 2. Physics Simulation\n * - Gravity: Central force pulling nodes toward center\n * - Repulsion: Force pushing nodes apart\n * - Link Forces: Spring forces and distances between connected nodes\n * - Dynamics: Friction and decay rates for movement\n *\n * Key Parameters:\n * - `pointSizeScale` (number): Base scale for node sizes (default: 1.1)\n * - `scalePointsOnZoom` (boolean): Dynamic node sizing with zoom (default: true)\n * - `renderLinks` (boolean): Toggle link visibility (default: true)\n * - `linkArrows` (boolean): Show directional arrows (default: false)\n * - `curvedLinks` (boolean): Use curved or straight links (default: false)\n * - `simulationGravity` (number): Center attraction strength (default: 0.25)\n * - `simulationRepulsion` (number): Node repulsion strength (default: 1.0)\n * - `simulationLinkSpring` (number): Link elasticity (default: 1.0)\n * - `simulationFriction` (number): Movement damping (default: 0.85)\n * - `simulationDecay` (number): Simulation cooling rate (default: 1000)\n *\n * @example Typical usage with default-like values\n * ```tsx\n * import { CosmosGraph, createDefaultCosmosConfig } from '@sqlrooms/cosmos';\n *\n * const config = createDefaultCosmosConfig();\n *\n * function MyGraph() {\n * return (\n * <CosmosGraph\n * config={config}\n * data={graphData}\n * />\n * );\n * }\n * ```\n *\n * @example Custom configuration for directed graph\n * ```tsx\n * const config = {\n * cosmos: {\n * // Visual settings\n * pointSizeScale: 1.2,\n * linkArrows: true,\n * curvedLinks: true,\n *\n * // Physics settings\n * simulationGravity: 0.2,\n * simulationLinkDistance: 15,\n * simulationLinkSpring: 1.2\n * }\n * };\n * ```\n *\n * @see {@link CosmosGraph} For the main graph component\n * @see {@link CosmosSimulationControls} For runtime control of simulation parameters\n */\nexport * from './CosmosSliceConfig';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAc,EACkB,EAAE;IAClC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAClC,CAAC;AACJ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAc,EACkB,EAAE;IAClC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAClC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * Interface for objects that contain client coordinates.\n * Typically used with mouse or pointer events.\n */\nexport type WithClientCoordinates = {\n /** The horizontal coordinate relative to the client area */\n clientX: number;\n /** The vertical coordinate relative to the client area */\n clientY: number;\n};\n\n/**\n * Type guard that checks if an unknown value has client coordinates.\n *\n * This function performs a runtime check to ensure that an object has valid\n * clientX and clientY number properties. It's useful for handling events\n * that may or may not include coordinate information.\n *\n * @example\n * ```ts\n * const handleEvent = (event: unknown) => {\n * if (hasClientCoordinates(event)) {\n * // TypeScript now knows event has clientX and clientY\n * console.log(event.clientX, event.clientY);\n * }\n * };\n * ```\n *\n * @param event - The value to check for client coordinates\n * @returns A type predicate indicating if the value has client coordinates\n */\nexport const hasClientCoordinates = (\n event: unknown,\n): event is WithClientCoordinates => {\n return (\n typeof event === 'object' &&\n event !== null &&\n 'clientX' in event &&\n 'clientY' in event &&\n typeof event.clientX === 'number' &&\n typeof event.clientY === 'number'\n );\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/cosmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,9 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@cosmograph/cosmos": "2.0.0-beta.22",
|
|
23
|
-
"@sqlrooms/
|
|
23
|
+
"@sqlrooms/project-builder": "0.5.1",
|
|
24
|
+
"@sqlrooms/project-config": "0.5.1",
|
|
25
|
+
"@sqlrooms/ui": "0.5.1",
|
|
26
|
+
"immer": "^10.1.1",
|
|
24
27
|
"lucide-react": "^0.474.0",
|
|
25
|
-
"zod": "^3.24.1"
|
|
28
|
+
"zod": "^3.24.1",
|
|
29
|
+
"zustand": "^5.0.3"
|
|
26
30
|
},
|
|
27
31
|
"peerDependencies": {
|
|
28
32
|
"react": "*",
|
|
@@ -34,5 +38,5 @@
|
|
|
34
38
|
"lint": "eslint .",
|
|
35
39
|
"typedoc": "typedoc"
|
|
36
40
|
},
|
|
37
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5e41362f1552ee1f8a661c487fe7cdb606cc6d23"
|
|
38
42
|
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Graph } from '@cosmograph/cosmos';
|
|
2
|
-
/**
|
|
3
|
-
* The shape of the context value provided by CosmosGraphContext.
|
|
4
|
-
*/
|
|
5
|
-
interface CosmosGraphContextValue {
|
|
6
|
-
/** Whether the graph simulation is currently running */
|
|
7
|
-
isSimulationRunning: boolean;
|
|
8
|
-
/** Reference to the Cosmos Graph instance */
|
|
9
|
-
graphRef: React.MutableRefObject<Graph | null> | null;
|
|
10
|
-
/** Function to toggle the simulation state between running and paused */
|
|
11
|
-
handleToggleSimulation: () => void;
|
|
12
|
-
/** Function to fit the graph view to show all nodes */
|
|
13
|
-
handleFitView: () => void;
|
|
14
|
-
/** Function to start simulation with an energy push */
|
|
15
|
-
handleStartWithEnergy: () => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Hook to access the CosmosGraph context.
|
|
19
|
-
*
|
|
20
|
-
* Provides access to:
|
|
21
|
-
* - Graph simulation state
|
|
22
|
-
* - Graph instance reference
|
|
23
|
-
* - Control functions for simulation and view
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```tsx
|
|
27
|
-
* const CustomControl = () => {
|
|
28
|
-
* const { isSimulationRunning, handleToggleSimulation } = useCosmosGraph();
|
|
29
|
-
*
|
|
30
|
-
* return (
|
|
31
|
-
* <button onClick={handleToggleSimulation}>
|
|
32
|
-
* {isSimulationRunning ? 'Pause' : 'Start'}
|
|
33
|
-
* </button>
|
|
34
|
-
* );
|
|
35
|
-
* };
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @throws {Error} If used outside of a CosmosGraphProvider
|
|
39
|
-
* @returns The graph context value
|
|
40
|
-
*/
|
|
41
|
-
export declare const useCosmosGraph: () => CosmosGraphContextValue;
|
|
42
|
-
/**
|
|
43
|
-
* Props for the CosmosGraphProvider component.
|
|
44
|
-
*/
|
|
45
|
-
interface CosmosGraphProviderProps {
|
|
46
|
-
/** Child components that will have access to the graph context */
|
|
47
|
-
children: React.ReactNode;
|
|
48
|
-
/** Reference to the Cosmos Graph instance */
|
|
49
|
-
graphRef: React.MutableRefObject<Graph | null>;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Provider component that makes graph state and controls available to its children.
|
|
53
|
-
*
|
|
54
|
-
* Manages:
|
|
55
|
-
* - Simulation running state
|
|
56
|
-
* - Graph instance reference
|
|
57
|
-
* - Control functions for simulation and view
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* const MyGraph = () => {
|
|
62
|
-
* const graphRef = useRef<Graph | null>(null);
|
|
63
|
-
*
|
|
64
|
-
* return (
|
|
65
|
-
* <CosmosGraphProvider graphRef={graphRef}>
|
|
66
|
-
* <CosmosGraph {...graphProps} />
|
|
67
|
-
* <CosmosGraphControls />
|
|
68
|
-
* <CustomControls />
|
|
69
|
-
* </CosmosGraphProvider>
|
|
70
|
-
* );
|
|
71
|
-
* };
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare const CosmosGraphProvider: React.FC<CosmosGraphProviderProps>;
|
|
75
|
-
export {};
|
|
76
|
-
//# sourceMappingURL=CosmosGraphContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosGraphContext.d.ts","sourceRoot":"","sources":["../src/CosmosGraphContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAGzC;;GAEG;AACH,UAAU,uBAAuB;IAC/B,wDAAwD;IACxD,mBAAmB,EAAE,OAAO,CAAC;IAC7B,6CAA6C;IAC7C,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,yEAAyE;IACzE,sBAAsB,EAAE,MAAM,IAAI,CAAC;IACnC,uDAAuD;IACvD,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,uDAAuD;IACvD,qBAAqB,EAAE,MAAM,IAAI,CAAC;CACnC;AAQD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC;AAEF;;GAEG;AACH,UAAU,wBAAwB;IAChC,kEAAkE;IAClE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAyClE,CAAC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useState } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Context for sharing graph state and controls across components.
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
const CosmosGraphContext = createContext(null);
|
|
8
|
-
/**
|
|
9
|
-
* Hook to access the CosmosGraph context.
|
|
10
|
-
*
|
|
11
|
-
* Provides access to:
|
|
12
|
-
* - Graph simulation state
|
|
13
|
-
* - Graph instance reference
|
|
14
|
-
* - Control functions for simulation and view
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const CustomControl = () => {
|
|
19
|
-
* const { isSimulationRunning, handleToggleSimulation } = useCosmosGraph();
|
|
20
|
-
*
|
|
21
|
-
* return (
|
|
22
|
-
* <button onClick={handleToggleSimulation}>
|
|
23
|
-
* {isSimulationRunning ? 'Pause' : 'Start'}
|
|
24
|
-
* </button>
|
|
25
|
-
* );
|
|
26
|
-
* };
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @throws {Error} If used outside of a CosmosGraphProvider
|
|
30
|
-
* @returns The graph context value
|
|
31
|
-
*/
|
|
32
|
-
export const useCosmosGraph = () => {
|
|
33
|
-
const context = useContext(CosmosGraphContext);
|
|
34
|
-
if (!context) {
|
|
35
|
-
throw new Error('useCosmosGraph must be used within a CosmosGraphProvider');
|
|
36
|
-
}
|
|
37
|
-
return context;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Provider component that makes graph state and controls available to its children.
|
|
41
|
-
*
|
|
42
|
-
* Manages:
|
|
43
|
-
* - Simulation running state
|
|
44
|
-
* - Graph instance reference
|
|
45
|
-
* - Control functions for simulation and view
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```tsx
|
|
49
|
-
* const MyGraph = () => {
|
|
50
|
-
* const graphRef = useRef<Graph | null>(null);
|
|
51
|
-
*
|
|
52
|
-
* return (
|
|
53
|
-
* <CosmosGraphProvider graphRef={graphRef}>
|
|
54
|
-
* <CosmosGraph {...graphProps} />
|
|
55
|
-
* <CosmosGraphControls />
|
|
56
|
-
* <CustomControls />
|
|
57
|
-
* </CosmosGraphProvider>
|
|
58
|
-
* );
|
|
59
|
-
* };
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export const CosmosGraphProvider = ({ children, graphRef, }) => {
|
|
63
|
-
const [isSimulationRunning, setIsSimulationRunning] = useState(true);
|
|
64
|
-
const handleStartWithEnergy = useCallback(() => {
|
|
65
|
-
if (!graphRef.current)
|
|
66
|
-
return;
|
|
67
|
-
graphRef.current.start(1);
|
|
68
|
-
setIsSimulationRunning(true);
|
|
69
|
-
}, [graphRef]);
|
|
70
|
-
const handleToggleSimulation = useCallback(() => {
|
|
71
|
-
if (!graphRef.current)
|
|
72
|
-
return;
|
|
73
|
-
if (graphRef.current.isSimulationRunning) {
|
|
74
|
-
graphRef.current.pause();
|
|
75
|
-
setIsSimulationRunning(false);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
graphRef.current.restart();
|
|
79
|
-
setIsSimulationRunning(true);
|
|
80
|
-
}
|
|
81
|
-
}, [graphRef]);
|
|
82
|
-
const handleFitView = useCallback(() => {
|
|
83
|
-
if (!graphRef.current)
|
|
84
|
-
return;
|
|
85
|
-
graphRef.current.fitView();
|
|
86
|
-
}, [graphRef]);
|
|
87
|
-
return (_jsx(CosmosGraphContext.Provider, { value: {
|
|
88
|
-
isSimulationRunning,
|
|
89
|
-
graphRef,
|
|
90
|
-
handleToggleSimulation,
|
|
91
|
-
handleFitView,
|
|
92
|
-
handleStartWithEnergy,
|
|
93
|
-
}, children: children }));
|
|
94
|
-
};
|
|
95
|
-
//# sourceMappingURL=CosmosGraphContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosGraphContext.js","sourceRoot":"","sources":["../src/CosmosGraphContext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,EAAE,CAAC;YAC3B,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,IAAI,CAAC,QAAQ,CAAC,OAAO;YAAE,OAAO;QAC9B,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,mBAAmB;YACnB,QAAQ;YACR,sBAAsB;YACtB,aAAa;YACb,qBAAqB;SACtB,YAEA,QAAQ,GACmB,CAC/B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { GraphConfigInterface } from '@cosmograph/cosmos';
|
|
2
|
-
import { FC } from 'react';
|
|
3
|
-
export type CosmosGraphProps = {
|
|
4
|
-
config: GraphConfigInterface;
|
|
5
|
-
pointPositions: Float32Array;
|
|
6
|
-
pointSizes: Float32Array;
|
|
7
|
-
pointColors: Float32Array;
|
|
8
|
-
linkIndexes?: Float32Array;
|
|
9
|
-
linkColors?: Float32Array;
|
|
10
|
-
focusedPointIndex?: number | undefined;
|
|
11
|
-
getPointTooltip?: (index: number) => React.ReactNode;
|
|
12
|
-
};
|
|
13
|
-
export declare const CosmosGraph: FC<CosmosGraphProps>;
|
|
14
|
-
//# sourceMappingURL=CosmosGraph.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosGraph.d.ts","sourceRoot":"","sources":["../../src/components/CosmosGraph.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AAG/D,OAAO,EAAC,EAAE,EAAoD,MAAM,OAAO,CAAC;AA+B5E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,cAAc,EAAE,YAAY,CAAC;IAC7B,UAAU,EAAE,YAAY,CAAC;IACzB,WAAW,EAAE,YAAY,CAAC;IAC1B,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;CACtD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAoK5C,CAAC"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Graph } from '@cosmograph/cosmos';
|
|
3
|
-
import { Button, cn } from '@sqlrooms/ui';
|
|
4
|
-
import { Maximize2, Pause, Play } from 'lucide-react';
|
|
5
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
-
const useRelativeCoordinates = (containerRef) => {
|
|
7
|
-
return useCallback((x, y) => {
|
|
8
|
-
if (!containerRef.current)
|
|
9
|
-
return [0, 0];
|
|
10
|
-
const rect = containerRef.current.getBoundingClientRect();
|
|
11
|
-
return [x - rect.left, y - rect.top];
|
|
12
|
-
}, [containerRef]);
|
|
13
|
-
};
|
|
14
|
-
const hasClientCoordinates = (event) => {
|
|
15
|
-
return (typeof event === 'object' &&
|
|
16
|
-
event !== null &&
|
|
17
|
-
'clientX' in event &&
|
|
18
|
-
'clientY' in event &&
|
|
19
|
-
typeof event.clientX === 'number' &&
|
|
20
|
-
typeof event.clientY === 'number');
|
|
21
|
-
};
|
|
22
|
-
export const CosmosGraph = ({ config, pointPositions, pointSizes, pointColors, linkIndexes, linkColors, focusedPointIndex, getPointTooltip, }) => {
|
|
23
|
-
const containerRef = useRef(null);
|
|
24
|
-
const graphRef = useRef(null);
|
|
25
|
-
const [isSimulationRunning, setIsSimulationRunning] = useState(true);
|
|
26
|
-
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
27
|
-
const calcRelativeCoordinates = useRelativeCoordinates(containerRef);
|
|
28
|
-
const configWithCallbacks = useMemo(() => {
|
|
29
|
-
return {
|
|
30
|
-
...config,
|
|
31
|
-
onSimulationStart: () => {
|
|
32
|
-
setIsSimulationRunning(true);
|
|
33
|
-
config.onSimulationStart?.();
|
|
34
|
-
},
|
|
35
|
-
onSimulationPause: () => {
|
|
36
|
-
setIsSimulationRunning(false);
|
|
37
|
-
config.onSimulationPause?.();
|
|
38
|
-
},
|
|
39
|
-
onSimulationEnd: () => {
|
|
40
|
-
setIsSimulationRunning(false);
|
|
41
|
-
config.onSimulationEnd?.();
|
|
42
|
-
},
|
|
43
|
-
onSimulationRestart: () => {
|
|
44
|
-
setIsSimulationRunning(true);
|
|
45
|
-
config.onSimulationRestart?.();
|
|
46
|
-
},
|
|
47
|
-
onPointMouseOver: (index, _pointPosition, event) => {
|
|
48
|
-
if (hasClientCoordinates(event)) {
|
|
49
|
-
setHoveredPoint({
|
|
50
|
-
index,
|
|
51
|
-
position: calcRelativeCoordinates(event.clientX, event.clientY),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
onPointMouseOut: () => {
|
|
56
|
-
setHoveredPoint(null);
|
|
57
|
-
},
|
|
58
|
-
onZoomStart: () => {
|
|
59
|
-
setHoveredPoint(null);
|
|
60
|
-
},
|
|
61
|
-
onDragStart: () => {
|
|
62
|
-
setHoveredPoint(null);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}, [config, calcRelativeCoordinates]);
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
if (!graphRef.current)
|
|
68
|
-
return;
|
|
69
|
-
console.log({ focusedPointIndex });
|
|
70
|
-
graphRef.current.setFocusedPointByIndex(focusedPointIndex);
|
|
71
|
-
}, [focusedPointIndex]);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (!containerRef.current)
|
|
74
|
-
return;
|
|
75
|
-
if (!graphRef.current) {
|
|
76
|
-
graphRef.current = new Graph(containerRef.current);
|
|
77
|
-
}
|
|
78
|
-
const graph = graphRef.current;
|
|
79
|
-
graph.setPointPositions(pointPositions);
|
|
80
|
-
graph.setPointColors(pointColors);
|
|
81
|
-
graph.setPointSizes(pointSizes);
|
|
82
|
-
if (linkIndexes && linkColors) {
|
|
83
|
-
graph.setLinks(linkIndexes);
|
|
84
|
-
graph.setLinkColors(linkColors);
|
|
85
|
-
}
|
|
86
|
-
graph.setConfig(configWithCallbacks);
|
|
87
|
-
graph.render();
|
|
88
|
-
graph.start();
|
|
89
|
-
setIsSimulationRunning(true);
|
|
90
|
-
graph.setZoomLevel(0.6);
|
|
91
|
-
return () => {
|
|
92
|
-
graph.pause();
|
|
93
|
-
setIsSimulationRunning(false);
|
|
94
|
-
};
|
|
95
|
-
}, [
|
|
96
|
-
pointPositions,
|
|
97
|
-
pointColors,
|
|
98
|
-
pointSizes,
|
|
99
|
-
linkIndexes,
|
|
100
|
-
linkColors,
|
|
101
|
-
configWithCallbacks,
|
|
102
|
-
]);
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (!graphRef.current)
|
|
105
|
-
return;
|
|
106
|
-
graphRef.current.setConfig(configWithCallbacks);
|
|
107
|
-
}, [configWithCallbacks]);
|
|
108
|
-
const handleFitView = useCallback(() => {
|
|
109
|
-
if (!graphRef.current)
|
|
110
|
-
return;
|
|
111
|
-
graphRef.current.fitView();
|
|
112
|
-
}, []);
|
|
113
|
-
const handleToggleSimulation = useCallback(() => {
|
|
114
|
-
if (!graphRef.current)
|
|
115
|
-
return;
|
|
116
|
-
if (graphRef.current.isSimulationRunning) {
|
|
117
|
-
graphRef.current.pause();
|
|
118
|
-
setIsSimulationRunning(false);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
graphRef.current.start();
|
|
122
|
-
setIsSimulationRunning(true);
|
|
123
|
-
}
|
|
124
|
-
}, []);
|
|
125
|
-
return (_jsxs("div", { className: "relative w-full h-full", children: [_jsx("div", { ref: containerRef, className: "absolute w-full h-full" }), getPointTooltip ? (_jsx("div", { className: cn('absolute z-50 max-w-xs', 'bg-white/90 dark:bg-gray-800/90 rounded-md shadow-lg p-2', 'text-xs flex gap-2 items-center pointer-events-none transition-opacity duration-150', hoveredPoint ? 'opacity-100' : 'opacity-0'), style: {
|
|
126
|
-
transform: `translate(${hoveredPoint?.position?.[0] ?? 0}px, ${hoveredPoint?.position?.[1] ?? 0}px) translate(-50%, 5px)`,
|
|
127
|
-
visibility: hoveredPoint ? 'visible' : 'hidden',
|
|
128
|
-
}, children: _jsx("div", { children: getPointTooltip?.(hoveredPoint?.index ?? 0) }) })) : null, _jsxs("div", { className: "absolute top-1 left-1 flex gap-2", children: [!config.disableSimulation && (_jsx(_Fragment, { children: _jsx(Button, { onClick: handleToggleSimulation, variant: "outline", size: "sm", children: isSimulationRunning ? (_jsx(Pause, { className: "h-4 w-4" })) : (_jsx(Play, { className: "h-4 w-4" })) }) })), _jsx(Button, { onClick: handleFitView, variant: "outline", size: "sm", children: _jsx(Maximize2, { className: "h-4 w-4" }) })] })] }));
|
|
129
|
-
};
|
|
130
|
-
//# sourceMappingURL=CosmosGraph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosGraph.js","sourceRoot":"","sources":["../../src/components/CosmosGraph.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAuB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAE,EAAE,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAK,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE5E,MAAM,sBAAsB,GAAG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