@sqlrooms/cosmos 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -0
- package/dist/CosmosSimulationControls.js +1 -1
- package/dist/CosmosSimulationControls.js.map +1 -1
- package/dist/CosmosSlice.js +5 -5
- package/dist/CosmosSlice.js.map +1 -1
- package/dist/hooks/useHoverState.d.ts.map +1 -1
- package/dist/index.d.ts +1 -111
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -111
- package/dist/index.js.map +1 -1
- package/dist/utils/coordinates.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
A powerful graph visualization package for SQLRooms applications. This package provides React components and hooks for creating interactive graph visualizations using a WebGL-based graph rendering engine, with state management through Zustand.
|
|
2
|
+
|
|
3
|
+
This package is built on top of the [Cosmos library](https://github.com/cosmograph-org/cosmos), a GPU-accelerated force graph layout and rendering library.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌐 **Interactive Graphs**: Create dynamic, interactive graph visualizations
|
|
8
|
+
- 🚀 **WebGL Rendering**: High-performance rendering for large graphs
|
|
9
|
+
- 🧩 **React Components**: Ready-to-use components for graph visualization
|
|
10
|
+
- 🔄 **State Management**: Zustand-based state management for graph state
|
|
11
|
+
- 🎛️ **Simulation Controls**: Fine-grained control over physics simulation
|
|
12
|
+
- 🎨 **Customizable Styling**: Extensive options for visual customization
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @sqlrooms/cosmos
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic Usage
|
|
21
|
+
|
|
22
|
+
### Simple Graph Visualization
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import {
|
|
26
|
+
CosmosGraph,
|
|
27
|
+
CosmosGraphControls,
|
|
28
|
+
createDefaultCosmosConfig,
|
|
29
|
+
} from '@sqlrooms/cosmos';
|
|
30
|
+
|
|
31
|
+
function MyGraph() {
|
|
32
|
+
const graphData = {
|
|
33
|
+
nodes: [
|
|
34
|
+
{id: 'node1', label: 'Node 1'},
|
|
35
|
+
{id: 'node2', label: 'Node 2'},
|
|
36
|
+
{id: 'node3', label: 'Node 3'},
|
|
37
|
+
],
|
|
38
|
+
links: [
|
|
39
|
+
{source: 'node1', target: 'node2'},
|
|
40
|
+
{source: 'node2', target: 'node3'},
|
|
41
|
+
{source: 'node3', target: 'node1'},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div style={{width: '800px', height: '600px'}}>
|
|
47
|
+
<CosmosGraph config={createDefaultCosmosConfig()} data={graphData}>
|
|
48
|
+
<CosmosGraphControls />
|
|
49
|
+
</CosmosGraph>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With Simulation Controls
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import {
|
|
59
|
+
CosmosGraph,
|
|
60
|
+
CosmosGraphControls,
|
|
61
|
+
CosmosSimulationControls,
|
|
62
|
+
createDefaultCosmosConfig,
|
|
63
|
+
} from '@sqlrooms/cosmos';
|
|
64
|
+
|
|
65
|
+
function AdvancedGraph() {
|
|
66
|
+
return (
|
|
67
|
+
<div style={{width: '800px', height: '600px', position: 'relative'}}>
|
|
68
|
+
<CosmosGraph config={createDefaultCosmosConfig()} data={graphData}>
|
|
69
|
+
<CosmosGraphControls />
|
|
70
|
+
<CosmosSimulationControls className="absolute bottom-4 left-4" />
|
|
71
|
+
</CosmosGraph>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Using with Zustand Store
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import {
|
|
81
|
+
createCosmosSlice,
|
|
82
|
+
useStoreWithCosmos,
|
|
83
|
+
createDefaultCosmosConfig,
|
|
84
|
+
} from '@sqlrooms/cosmos';
|
|
85
|
+
import {createProjectStore} from '@sqlrooms/project-builder';
|
|
86
|
+
|
|
87
|
+
// Create a project store with cosmos capabilities
|
|
88
|
+
const useStore = createProjectStore({
|
|
89
|
+
cosmos: createCosmosSlice(createDefaultCosmosConfig()),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function GraphWithState() {
|
|
93
|
+
const {setGraphData, toggleSimulation, isSimulationRunning, zoomToFit} =
|
|
94
|
+
useStoreWithCosmos(useStore);
|
|
95
|
+
|
|
96
|
+
// Load graph data
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
setGraphData(myGraphData);
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div>
|
|
103
|
+
<button onClick={toggleSimulation}>
|
|
104
|
+
{isSimulationRunning ? 'Pause' : 'Resume'} Simulation
|
|
105
|
+
</button>
|
|
106
|
+
<button onClick={zoomToFit}>Zoom to Fit</button>
|
|
107
|
+
|
|
108
|
+
<CosmosGraph store={useStore}>
|
|
109
|
+
<CosmosGraphControls />
|
|
110
|
+
</CosmosGraph>
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
The Cosmos graph visualization system provides extensive configuration options for both visual appearance and physics simulation.
|
|
119
|
+
|
|
120
|
+
### Visual Configuration
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
const config = {
|
|
124
|
+
pointSizeScale: 1.2, // Base scale for node sizes
|
|
125
|
+
scalePointsOnZoom: true, // Dynamic node sizing with zoom
|
|
126
|
+
renderLinks: true, // Toggle link visibility
|
|
127
|
+
linkArrows: true, // Show directional arrows
|
|
128
|
+
curvedLinks: true, // Use curved links
|
|
129
|
+
linkWidth: 1.5, // Width of links
|
|
130
|
+
linkOpacity: 0.8, // Opacity of links
|
|
131
|
+
// ... other visual options
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Physics Simulation Configuration
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
const config = {
|
|
139
|
+
simulationGravity: 0.2, // Center attraction strength
|
|
140
|
+
simulationRepulsion: 1.0, // Node repulsion strength
|
|
141
|
+
simulationLinkSpring: 1.2, // Link elasticity
|
|
142
|
+
simulationLinkDistance: 15, // Preferred link distance
|
|
143
|
+
simulationFriction: 0.85, // Movement damping
|
|
144
|
+
simulationDecay: 1000, // Simulation cooling rate
|
|
145
|
+
// ... other physics options
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Advanced Features
|
|
150
|
+
|
|
151
|
+
- **Custom Node Rendering**: Define custom renderers for nodes
|
|
152
|
+
- **Interactive Events**: Handle click, hover, and drag events
|
|
153
|
+
- **Data Binding**: Connect graph data to your application state
|
|
154
|
+
- **Layout Algorithms**: Apply different layout algorithms
|
|
155
|
+
- **Performance Optimization**: Options for handling large graphs
|
|
156
|
+
|
|
157
|
+
For more information, visit the SQLRooms documentation.
|
|
158
|
+
|
|
159
|
+
## About Cosmograph Cosmos
|
|
160
|
+
|
|
161
|
+
This package is built on top of [Cosmograph Cosmos](https://github.com/cosmograph-org/cosmos), a GPU-accelerated force graph layout and rendering library. Cosmograph Cosmos offers:
|
|
162
|
+
|
|
163
|
+
- **GPU Acceleration**: All computations and rendering happen on the GPU in fragment and vertex shaders
|
|
164
|
+
- **High Performance**: Capable of rendering hundreds of thousands of nodes and links in real-time
|
|
165
|
+
- **WebGL-based**: Utilizes WebGL for efficient graph visualization
|
|
166
|
+
- **Advanced Physics**: Sophisticated force-directed layout algorithms
|
|
167
|
+
|
|
168
|
+
For more information about the underlying library, visit the [Cosmograph Cosmos GitHub repository](https://github.com/cosmograph-org/cosmos) or the [official documentation](https://cosmograph-org.github.io/cosmos/).
|
|
@@ -110,7 +110,7 @@ const simulationSliders = [
|
|
|
110
110
|
*/
|
|
111
111
|
export const CosmosSimulationControls = ({ className, }) => {
|
|
112
112
|
const { isSimulationRunning, toggleSimulation, startWithEnergy, updateSimulationConfig, } = useStoreWithCosmos((s) => s.cosmos);
|
|
113
|
-
const config = useStoreWithCosmos((s) => s.
|
|
113
|
+
const config = useStoreWithCosmos((s) => s.config.cosmos);
|
|
114
114
|
const handleParameterChange = (paramKey, value) => {
|
|
115
115
|
updateSimulationConfig({ [paramKey]: value[0] });
|
|
116
116
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosSimulationControls.js","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,EAAE,EACF,MAAM,EACN,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,MAAM,GACP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAmBtD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG;IACxB;QACE,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;QACR,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,qBAAqB;QAC1B,KAAK,EAAE,WAAW;QAClB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,sBAAsB;QAC3B,KAAK,EAAE,eAAe;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,wBAAwB;QAC7B,KAAK,EAAE,eAAe;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,CAAC;KACR;IACD;QACE,GAAG,EAAE,oBAAoB;QACzB,KAAK,EAAE,UAAU;QACjB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,iBAAiB;QACtB,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,GAAG;KACV;CACO,CAAC;AAIX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsC,CAAC,EAC1E,SAAS,GACV,EAAE,EAAE;IACH,MAAM,EACJ,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,GACvB,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,MAAM,GAAG,kBAAkB,CAC/B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"CosmosSimulationControls.js","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,EAAE,EACF,MAAM,EACN,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,MAAM,GACP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAmBtD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG;IACxB;QACE,GAAG,EAAE,mBAAmB;QACxB,KAAK,EA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DAAyD,aAEnE,KAAC,IAAI,IAAC,SAAS,EAAC,kCAAkC,GAAG,EACpD,KAAK,IACA,GACO,EACjB,KAAC,cAAc,IAAC,IAAI,EAAC,MAAM,EAAC,SAAS,EAAC,eAAe,YAClD,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,GACvC,IACT,EACV,eAAM,SAAS,EAAC,4CAA4C,YACzD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAClB,IACH,EACN,KAAC,MAAM,IACL,EAAE,EAAE,GAAG,EACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EACpB,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,KAAK,CAAC,EAC3D,SAAS,EAAC,QAAQ,GAClB,KA5BM,GAAG,CA6BP,CACP,CAAC,IACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n cn,\n Slider,\n Label,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n Button,\n} from '@sqlrooms/ui';\nimport {FC} from 'react';\nimport {Info, Pause, Play, Wind} from 'lucide-react';\nimport {useStoreWithCosmos} from './CosmosSlice';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\n\n/**\n * Props for the CosmosSimulationControls component.\n */\ninterface CosmosSimulationControlsProps {\n /**\n * Optional className to override the default positioning and styling of the controls container.\n * By default, controls are positioned at the top-right corner.\n *\n * @example\n * ```tsx\n * // Position controls at the bottom-right\n * <CosmosSimulationControls className=\"absolute bottom-4 right-4\" />\n * ```\n */\n className?: string;\n}\n\n/**\n * Configuration for each simulation parameter slider.\n * These values define the range and step size for each parameter.\n *\n * @internal\n */\nconst simulationSliders = [\n {\n key: 'simulationGravity',\n label: 'Gravity',\n min: 0,\n max: 0.5,\n step: 0.01,\n },\n {\n key: 'simulationRepulsion',\n label: 'Repulsion',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkSpring',\n label: 'Link Strength',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkDistance',\n label: 'Link Distance',\n min: 1,\n max: 20,\n step: 1,\n },\n {\n key: 'simulationFriction',\n label: 'Friction',\n min: 0,\n max: 1,\n step: 0.01,\n },\n {\n key: 'simulationDecay',\n label: 'Decay',\n min: 100,\n max: 10000,\n step: 100,\n },\n] as const;\n\ntype SimulationKey = (typeof simulationSliders)[number]['key'];\n\n/**\n * A component that provides fine-grained controls for adjusting graph simulation parameters.\n * Uses the zustand store to access and control the graph state.\n *\n * Features:\n * - Slider controls for all simulation parameters\n * - Real-time parameter adjustment\n * - Tooltips with parameter descriptions\n * - Customizable positioning\n * - Default values optimized for common use cases\n *\n * Available parameters:\n * - Gravity (0-0.5): Controls how strongly nodes are pulled toward the center\n * - Repulsion (0-2): Controls how strongly nodes push away from each other\n * - Link Strength (0-2): Controls the spring force between connected nodes\n * - Link Distance (1-20): Sets the natural length of links between nodes\n * - Friction (0-1): Controls how quickly node movement decays\n * - Decay (100-10000): Controls how quickly the simulation \"cools down\"\n *\n * @example Basic usage\n * ```tsx\n * import { CosmosGraph, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example Custom positioning with other controls\n * ```tsx\n * import { CosmosGraph, CosmosGraphControls, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosGraphControls className=\"absolute top-4 left-4\" />\n * <CosmosSimulationControls className=\"absolute top-4 right-4\" />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example With custom styling\n * ```tsx\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls\n * className=\"absolute bottom-4 right-4 bg-opacity-75 backdrop-blur-sm\"\n * />\n * </CosmosGraph>\n * ```\n */\nexport const CosmosSimulationControls: FC<CosmosSimulationControlsProps> = ({\n className,\n}) => {\n const {\n isSimulationRunning,\n toggleSimulation,\n startWithEnergy,\n updateSimulationConfig,\n } = useStoreWithCosmos((s) => s.cosmos);\n\n const config = useStoreWithCosmos(\n (s) => s.config.cosmos,\n ) as CosmosSliceConfig['cosmos'];\n\n const handleParameterChange = (paramKey: SimulationKey, value: number[]) => {\n updateSimulationConfig({[paramKey]: value[0]});\n };\n\n return (\n <div\n className={cn(\n 'w-48 bg-card/90 dark:bg-card/90 rounded-lg shadow-lg p-3 space-y-4',\n className,\n )}\n >\n <div className=\"flex gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={toggleSimulation}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n {isSimulationRunning ? (\n <Pause className=\"h-4 w-4\" />\n ) : (\n <Play className=\"h-4 w-4\" />\n )}\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n {isSimulationRunning ? 'Pause simulation' : 'Start simulation'}\n </TooltipContent>\n </Tooltip>\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={startWithEnergy}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n <Wind className=\"h-4 w-4\" />\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n Push energy into simulation\n </TooltipContent>\n </Tooltip>\n </div>\n {simulationSliders.map(({key, label, min, max, step}) => (\n <div key={key} className=\"space-y-2\">\n <div className=\"flex items-center justify-between\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Label\n htmlFor={key}\n className=\"text-xs font-medium flex items-center gap-1 cursor-help\"\n >\n <Info className=\"w-3 h-3 text-muted-foreground/50\" />\n {label}\n </Label>\n </TooltipTrigger>\n <TooltipContent side=\"left\" className=\"max-w-[200px]\">\n {CosmosSliceConfig.shape.cosmos.shape[key].description}\n </TooltipContent>\n </Tooltip>\n <span className=\"text-xs tabular-nums text-muted-foreground\">\n {config[key].toFixed(2)}\n </span>\n </div>\n <Slider\n id={key}\n min={min}\n max={max}\n step={step}\n value={[config[key]]}\n onValueChange={(value) => handleParameterChange(key, value)}\n className=\"w-full\"\n />\n </div>\n ))}\n </div>\n );\n};\n"]}
|
package/dist/CosmosSlice.js
CHANGED
|
@@ -25,7 +25,7 @@ export function createCosmosSlice() {
|
|
|
25
25
|
}
|
|
26
26
|
// Create and configure new graph
|
|
27
27
|
const graph = new Graph(container);
|
|
28
|
-
const config = get().
|
|
28
|
+
const config = get().config.cosmos;
|
|
29
29
|
graph.setConfig(config);
|
|
30
30
|
graph.start();
|
|
31
31
|
set((state) => produce(state, (draft) => {
|
|
@@ -67,18 +67,18 @@ export function createCosmosSlice() {
|
|
|
67
67
|
updateSimulationConfig: (config) => {
|
|
68
68
|
const { graph } = get().cosmos;
|
|
69
69
|
set((state) => produce(state, (draft) => {
|
|
70
|
-
Object.assign(draft.
|
|
70
|
+
Object.assign(draft.config.cosmos, config);
|
|
71
71
|
if (graph) {
|
|
72
|
-
graph.setConfig(draft.
|
|
72
|
+
graph.setConfig(draft.config.cosmos);
|
|
73
73
|
}
|
|
74
74
|
}));
|
|
75
75
|
},
|
|
76
76
|
updateGraphConfig: (config) => {
|
|
77
77
|
const { graph } = get().cosmos;
|
|
78
78
|
set((state) => produce(state, (draft) => {
|
|
79
|
-
Object.assign(draft.
|
|
79
|
+
Object.assign(draft.config.cosmos, config);
|
|
80
80
|
if (graph) {
|
|
81
|
-
graph.setConfig(draft.
|
|
81
|
+
graph.setConfig(draft.config.cosmos);
|
|
82
82
|
}
|
|
83
83
|
}));
|
|
84
84
|
},
|
package/dist/CosmosSlice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosSlice.js","sourceRoot":"","sources":["../src/CosmosSlice.ts"],"names":[],"mappings":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K,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;oBAC1B,KAAK,CAAC,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAC;gBAC3C,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8C;IAE9C,OAAO,mBAAmB,CAIxB,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAA+B,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * @fileoverview Cosmos graph visualization state management using Zustand.\n * This module provides state management and control functions for the Cosmos graph visualization.\n */\n\nimport {Graph, GraphConfigInterface} from '@cosmograph/cosmos';\nimport {\n createSlice,\n useBaseProjectStore,\n type ProjectState,\n} from '@sqlrooms/project-builder';\nimport type {BaseProjectConfig} from '@sqlrooms/project-config';\nimport type {StateCreator} from 'zustand';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\nimport {produce} from 'immer';\n\n/**\n * Core state interface for the Cosmos graph visualization.\n * Contains the graph instance, simulation state, and all control functions.\n */\nexport type CosmosSliceState = {\n cosmos: {\n /** The current graph instance */\n graph: Graph | null;\n /** Whether the physics simulation is currently running */\n isSimulationRunning: boolean;\n /** Creates a new graph instance in the specified container */\n createGraph: (container: HTMLDivElement) => void;\n /** Toggles the physics simulation on/off */\n toggleSimulation: () => void;\n /** Adjusts the view to fit all nodes */\n fitView: () => void;\n /** Starts the simulation with initial energy */\n startWithEnergy: () => void;\n /** Cleans up and removes the current graph */\n destroyGraph: () => void;\n /** Updates the simulation configuration parameters */\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => void;\n /** Updates the graph's visual configuration */\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => void;\n /** Updates the graph's data (points, links, colors, etc.) */\n updateGraphData: (data: {\n pointPositions?: Float32Array;\n pointColors?: Float32Array;\n pointSizes?: Float32Array;\n linkIndexes?: Float32Array;\n linkColors?: Float32Array;\n }) => void;\n /** Sets the currently focused point by its index */\n setFocusedPoint: (index: number | undefined) => void;\n /** Sets the zoom level of the graph view */\n setZoomLevel: (level: number) => void;\n };\n};\n\n/**\n * Combined type representing the full project state including Cosmos functionality.\n * Merges the base project state with Cosmos-specific state and configuration.\n */\nexport type ProjectStateWithCosmos = ProjectState<\n BaseProjectConfig & CosmosSliceConfig\n> &\n CosmosSliceState;\n\n/**\n * Creates a Zustand slice for managing Cosmos graph state.\n * This slice handles graph creation, destruction, configuration, and data updates.\n *\n * @returns A state creator function for the Cosmos slice\n */\nexport function createCosmosSlice(): StateCreator<CosmosSliceState> {\n return createSlice<BaseProjectConfig & CosmosSliceConfig, CosmosSliceState>(\n (set, get) => ({\n cosmos: {\n graph: null,\n isSimulationRunning: true,\n\n createGraph: (container: HTMLDivElement) => {\n // Clean up old graph if it exists\n const oldGraph = get().cosmos.graph;\n if (oldGraph) {\n oldGraph.pause();\n oldGraph.destroy();\n }\n\n // Create and configure new graph\n const graph = new Graph(container);\n const config = get().project.config.cosmos;\n graph.setConfig(config);\n graph.start();\n\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = graph;\n }),\n );\n },\n\n toggleSimulation: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (graph.isSimulationRunning) {\n graph.pause();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n } else {\n graph.restart();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n }\n },\n\n fitView: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.fitView();\n },\n\n startWithEnergy: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.start(1);\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n },\n\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.project.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.project.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.project.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.project.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphData: (data) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (data.pointPositions) {\n graph.setPointPositions(data.pointPositions);\n }\n if (data.pointColors) {\n graph.setPointColors(data.pointColors);\n }\n if (data.pointSizes) {\n graph.setPointSizes(data.pointSizes);\n }\n if (data.linkIndexes) {\n graph.setLinks(data.linkIndexes);\n }\n if (data.linkColors) {\n graph.setLinkColors(data.linkColors);\n }\n\n graph.render();\n },\n\n setFocusedPoint: (index) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setFocusedPointByIndex(index);\n },\n\n setZoomLevel: (level) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setZoomLevel(level);\n },\n\n destroyGraph: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n // TODO: this should be happening in cosmos\n if ((graph as any).store.div?.firstChild) {\n (graph as any).store.div.innerHTML = '';\n }\n graph.pause();\n graph.destroy();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = null;\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n },\n },\n }),\n );\n}\n\n/**\n * Hook to access the Cosmos store with proper typing.\n * Provides type-safe access to the combined project and Cosmos state.\n *\n * @template T The type of the selected state slice\n * @param selector A function that selects a portion of the state\n * @returns The selected state portion\n *\n * @example\n * ```typescript\n * const graph = useStoreWithCosmos(state => state.cosmos.graph);\n * const isRunning = useStoreWithCosmos(state => state.cosmos.isSimulationRunning);\n * ```\n */\nexport function useStoreWithCosmos<T>(\n selector: (state: ProjectStateWithCosmos) => T,\n): T {\n return useBaseProjectStore<\n BaseProjectConfig & CosmosSliceConfig,\n ProjectStateWithCosmos,\n T\n >((state) => selector(state as ProjectStateWithCosmos));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CosmosSlice.js","sourceRoot":"","sources":["../src/CosmosSlice.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,KAAK,EAAuB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAoD9B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,WAAW,CAChB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACb,MAAM,EAAE;YACN,KAAK,EAAE,IAAI;YACX,mBAAmB,EAAE,IAAI;YAEzB,WAAW,EAAE,CAAC,SAAyB,EAAE,EAAE;gBACzC,kCAAkC;gBAClC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;gBACpC,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,KAAK,EAAE,CAAC;oBACjB,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACrB,CAAC;gBAED,iCAAiC;gBACjC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;gBACnC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;gBACnC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxB,KAAK,CAAC,KAAK,EAAE,CAAC;gBAEd,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;gBAC7B,CAAC,CAAC,C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ACD,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,KAAK,CAAC,OAAO,EAAE,CAAC;gBAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;oBAC1B,KAAK,CAAC,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAC;gBAC3C,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8C;IAE9C,OAAO,mBAAmB,CAIxB,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAA+B,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * @fileoverview Cosmos graph visualization state management using Zustand.\n * This module provides state management and control functions for the Cosmos graph visualization.\n */\n\nimport {Graph, GraphConfigInterface} from '@cosmograph/cosmos';\nimport {\n createSlice,\n useBaseProjectStore,\n type ProjectState,\n} from '@sqlrooms/project-builder';\nimport type {BaseProjectConfig} from '@sqlrooms/project-config';\nimport type {StateCreator} from 'zustand';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\nimport {produce} from 'immer';\n\n/**\n * Core state interface for the Cosmos graph visualization.\n * Contains the graph instance, simulation state, and all control functions.\n */\nexport type CosmosSliceState = {\n cosmos: {\n /** The current graph instance */\n graph: Graph | null;\n /** Whether the physics simulation is currently running */\n isSimulationRunning: boolean;\n /** Creates a new graph instance in the specified container */\n createGraph: (container: HTMLDivElement) => void;\n /** Toggles the physics simulation on/off */\n toggleSimulation: () => void;\n /** Adjusts the view to fit all nodes */\n fitView: () => void;\n /** Starts the simulation with initial energy */\n startWithEnergy: () => void;\n /** Cleans up and removes the current graph */\n destroyGraph: () => void;\n /** Updates the simulation configuration parameters */\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => void;\n /** Updates the graph's visual configuration */\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => void;\n /** Updates the graph's data (points, links, colors, etc.) */\n updateGraphData: (data: {\n pointPositions?: Float32Array;\n pointColors?: Float32Array;\n pointSizes?: Float32Array;\n linkIndexes?: Float32Array;\n linkColors?: Float32Array;\n }) => void;\n /** Sets the currently focused point by its index */\n setFocusedPoint: (index: number | undefined) => void;\n /** Sets the zoom level of the graph view */\n setZoomLevel: (level: number) => void;\n };\n};\n\n/**\n * Combined type representing the full project state including Cosmos functionality.\n * Merges the base project state with Cosmos-specific state and configuration.\n */\nexport type ProjectStateWithCosmos = ProjectState<\n BaseProjectConfig & CosmosSliceConfig\n> &\n CosmosSliceState;\n\n/**\n * Creates a Zustand slice for managing Cosmos graph state.\n * This slice handles graph creation, destruction, configuration, and data updates.\n *\n * @returns A state creator function for the Cosmos slice\n */\nexport function createCosmosSlice(): StateCreator<CosmosSliceState> {\n return createSlice<BaseProjectConfig & CosmosSliceConfig, CosmosSliceState>(\n (set, get) => ({\n cosmos: {\n graph: null,\n isSimulationRunning: true,\n\n createGraph: (container: HTMLDivElement) => {\n // Clean up old graph if it exists\n const oldGraph = get().cosmos.graph;\n if (oldGraph) {\n oldGraph.pause();\n oldGraph.destroy();\n }\n\n // Create and configure new graph\n const graph = new Graph(container);\n const config = get().config.cosmos;\n graph.setConfig(config);\n graph.start();\n\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = graph;\n }),\n );\n },\n\n toggleSimulation: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (graph.isSimulationRunning) {\n graph.pause();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n } else {\n graph.restart();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n }\n },\n\n fitView: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.fitView();\n },\n\n startWithEnergy: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.start(1);\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n },\n\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphData: (data) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (data.pointPositions) {\n graph.setPointPositions(data.pointPositions);\n }\n if (data.pointColors) {\n graph.setPointColors(data.pointColors);\n }\n if (data.pointSizes) {\n graph.setPointSizes(data.pointSizes);\n }\n if (data.linkIndexes) {\n graph.setLinks(data.linkIndexes);\n }\n if (data.linkColors) {\n graph.setLinkColors(data.linkColors);\n }\n\n graph.render();\n },\n\n setFocusedPoint: (index) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setFocusedPointByIndex(index);\n },\n\n setZoomLevel: (level) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setZoomLevel(level);\n },\n\n destroyGraph: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n // TODO: this should be happening in cosmos\n if ((graph as any).store.div?.firstChild) {\n (graph as any).store.div.innerHTML = '';\n }\n graph.pause();\n graph.destroy();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = null;\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n },\n },\n }),\n );\n}\n\n/**\n * Hook to access the Cosmos store with proper typing.\n * Provides type-safe access to the combined project and Cosmos state.\n *\n * @template T The type of the selected state slice\n * @param selector A function that selects a portion of the state\n * @returns The selected state portion\n *\n * @example\n * ```typescript\n * const graph = useStoreWithCosmos(state => state.cosmos.graph);\n * const isRunning = useStoreWithCosmos(state => state.cosmos.isSimulationRunning);\n * ```\n */\nexport function useStoreWithCosmos<T>(\n selector: (state: ProjectStateWithCosmos) => T,\n): T {\n return useBaseProjectStore<\n BaseProjectConfig & CosmosSliceConfig,\n ProjectStateWithCosmos,\n T\n >((state) => selector(state as ProjectStateWithCosmos));\n}\n"]}
|
|
@@ -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,
|
|
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,GACxB,yBAAyB,UAAU,CAAC,OAAO,sBAAsB,CAAC;IAkChE,sHAAsH;;IAEtH,0DAA0D;;;;;;;CAG7D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,126 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
* This package provides React components and hooks for creating interactive graph visualizations
|
|
5
|
-
* using the Cosmograph WebGL-based graph visualization library. It includes components for
|
|
6
|
-
* rendering graphs, managing graph state through zustand, and controlling graph interactions.
|
|
7
|
-
*
|
|
8
|
-
* @example Basic usage
|
|
9
|
-
* ```tsx
|
|
10
|
-
* import { CosmosGraph, CosmosGraphControls } from '@sqlrooms/cosmos';
|
|
11
|
-
*
|
|
12
|
-
* const MyGraph = () => {
|
|
13
|
-
* return (
|
|
14
|
-
* <div style={{ width: '800px', height: '600px' }}>
|
|
15
|
-
* <CosmosGraph
|
|
16
|
-
* config={graphConfig}
|
|
17
|
-
* pointPositions={positions}
|
|
18
|
-
* pointColors={colors}
|
|
19
|
-
* pointSizes={sizes}
|
|
20
|
-
* >
|
|
21
|
-
* <CosmosGraphControls />
|
|
22
|
-
* </CosmosGraph>
|
|
23
|
-
* </div>
|
|
24
|
-
* );
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
2
|
+
* {@include ../README.md}
|
|
28
3
|
* @packageDocumentation
|
|
29
4
|
*/
|
|
30
5
|
export { CosmosGraph } from './CosmosGraph';
|
|
31
6
|
export { CosmosGraphControls } from './CosmosGraphControls';
|
|
32
7
|
/**
|
|
33
8
|
* A component that provides fine-grained controls for the graph simulation parameters.
|
|
34
|
-
* Uses the zustand store to access and control the graph state.
|
|
35
|
-
*
|
|
36
|
-
* Features:
|
|
37
|
-
* - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
|
|
38
|
-
* - Real-time parameter adjustment with immediate visual feedback
|
|
39
|
-
* - Tooltips with parameter descriptions
|
|
40
|
-
* - Customizable positioning
|
|
41
|
-
*
|
|
42
|
-
* @example Basic usage
|
|
43
|
-
* ```tsx
|
|
44
|
-
* <CosmosGraph {...graphProps}>
|
|
45
|
-
* <CosmosSimulationControls />
|
|
46
|
-
* </CosmosGraph>
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example Custom positioning
|
|
50
|
-
* ```tsx
|
|
51
|
-
* <CosmosGraph {...graphProps}>
|
|
52
|
-
* <CosmosSimulationControls className="absolute bottom-4 left-4" />
|
|
53
|
-
* </CosmosGraph>
|
|
54
|
-
* ```
|
|
55
9
|
*/
|
|
56
10
|
export { CosmosSimulationControls } from './CosmosSimulationControls';
|
|
57
11
|
export type { CosmosGraphProps } from './CosmosGraph';
|
|
58
12
|
export { useHoverState } from './hooks/useHoverState';
|
|
59
13
|
export { createCosmosSlice, useStoreWithCosmos, type CosmosSliceState, type ProjectStateWithCosmos, } from './CosmosSlice';
|
|
60
14
|
export { CosmosSliceConfig, createDefaultCosmosConfig, type CosmosSliceConfig as CosmosSliceConfigType, } from './CosmosSliceConfig';
|
|
61
|
-
/**
|
|
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.
|
|
64
|
-
*
|
|
65
|
-
* Configuration Categories:
|
|
66
|
-
*
|
|
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
|
|
90
|
-
* ```tsx
|
|
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
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @example Custom configuration for directed graph
|
|
106
|
-
* ```tsx
|
|
107
|
-
* const config = {
|
|
108
|
-
* cosmos: {
|
|
109
|
-
* // Visual settings
|
|
110
|
-
* pointSizeScale: 1.2,
|
|
111
|
-
* linkArrows: true,
|
|
112
|
-
* curvedLinks: true,
|
|
113
|
-
*
|
|
114
|
-
* // Physics settings
|
|
115
|
-
* simulationGravity: 0.2,
|
|
116
|
-
* simulationLinkDistance: 15,
|
|
117
|
-
* simulationLinkSpring: 1.2
|
|
118
|
-
* }
|
|
119
|
-
* };
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* @see {@link CosmosGraph} For the main graph component
|
|
123
|
-
* @see {@link CosmosSimulationControls} For runtime control of simulation parameters
|
|
124
|
-
*/
|
|
125
15
|
export * from './CosmosSliceConfig';
|
|
126
16
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;GAEG;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,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
* This package provides React components and hooks for creating interactive graph visualizations
|
|
5
|
-
* using the Cosmograph WebGL-based graph visualization library. It includes components for
|
|
6
|
-
* rendering graphs, managing graph state through zustand, and controlling graph interactions.
|
|
7
|
-
*
|
|
8
|
-
* @example Basic usage
|
|
9
|
-
* ```tsx
|
|
10
|
-
* import { CosmosGraph, CosmosGraphControls } from '@sqlrooms/cosmos';
|
|
11
|
-
*
|
|
12
|
-
* const MyGraph = () => {
|
|
13
|
-
* return (
|
|
14
|
-
* <div style={{ width: '800px', height: '600px' }}>
|
|
15
|
-
* <CosmosGraph
|
|
16
|
-
* config={graphConfig}
|
|
17
|
-
* pointPositions={positions}
|
|
18
|
-
* pointColors={colors}
|
|
19
|
-
* pointSizes={sizes}
|
|
20
|
-
* >
|
|
21
|
-
* <CosmosGraphControls />
|
|
22
|
-
* </CosmosGraph>
|
|
23
|
-
* </div>
|
|
24
|
-
* );
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
2
|
+
* {@include ../README.md}
|
|
28
3
|
* @packageDocumentation
|
|
29
4
|
*/
|
|
30
5
|
// Components
|
|
@@ -32,27 +7,6 @@ export { CosmosGraph } from './CosmosGraph';
|
|
|
32
7
|
export { CosmosGraphControls } from './CosmosGraphControls';
|
|
33
8
|
/**
|
|
34
9
|
* A component that provides fine-grained controls for the graph simulation parameters.
|
|
35
|
-
* Uses the zustand store to access and control the graph state.
|
|
36
|
-
*
|
|
37
|
-
* Features:
|
|
38
|
-
* - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
|
|
39
|
-
* - Real-time parameter adjustment with immediate visual feedback
|
|
40
|
-
* - Tooltips with parameter descriptions
|
|
41
|
-
* - Customizable positioning
|
|
42
|
-
*
|
|
43
|
-
* @example Basic usage
|
|
44
|
-
* ```tsx
|
|
45
|
-
* <CosmosGraph {...graphProps}>
|
|
46
|
-
* <CosmosSimulationControls />
|
|
47
|
-
* </CosmosGraph>
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @example Custom positioning
|
|
51
|
-
* ```tsx
|
|
52
|
-
* <CosmosGraph {...graphProps}>
|
|
53
|
-
* <CosmosSimulationControls className="absolute bottom-4 left-4" />
|
|
54
|
-
* </CosmosGraph>
|
|
55
|
-
* ```
|
|
56
10
|
*/
|
|
57
11
|
export { CosmosSimulationControls } from './CosmosSimulationControls';
|
|
58
12
|
// State management
|
|
@@ -60,69 +14,5 @@ export { useHoverState } from './hooks/useHoverState';
|
|
|
60
14
|
export { createCosmosSlice, useStoreWithCosmos, } from './CosmosSlice';
|
|
61
15
|
export { CosmosSliceConfig, createDefaultCosmosConfig, } from './CosmosSliceConfig';
|
|
62
16
|
// Configuration
|
|
63
|
-
/**
|
|
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.
|
|
66
|
-
*
|
|
67
|
-
* Configuration Categories:
|
|
68
|
-
*
|
|
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
|
|
92
|
-
* ```tsx
|
|
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
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* @example Custom configuration for directed graph
|
|
108
|
-
* ```tsx
|
|
109
|
-
* const config = {
|
|
110
|
-
* cosmos: {
|
|
111
|
-
* // Visual settings
|
|
112
|
-
* pointSizeScale: 1.2,
|
|
113
|
-
* linkArrows: true,
|
|
114
|
-
* curvedLinks: true,
|
|
115
|
-
*
|
|
116
|
-
* // Physics settings
|
|
117
|
-
* simulationGravity: 0.2,
|
|
118
|
-
* simulationLinkDistance: 15,
|
|
119
|
-
* simulationLinkSpring: 1.2
|
|
120
|
-
* }
|
|
121
|
-
* };
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @see {@link CosmosGraph} For the main graph component
|
|
125
|
-
* @see {@link CosmosSimulationControls} For runtime control of simulation parameters
|
|
126
|
-
*/
|
|
127
17
|
export * from './CosmosSliceConfig';
|
|
128
18
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,aAAa;AACb,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;GAEG;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,cAAc,qBAAqB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\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 */\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\nexport * from './CosmosSliceConfig';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinates.d.ts","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"coordinates.d.ts","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,OAAO,KACb,KAAK,IAAI,qBASX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/cosmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@cosmograph/cosmos": "2.0.0-beta.22",
|
|
23
|
-
"@sqlrooms/project-builder": "0.
|
|
24
|
-
"@sqlrooms/project-config": "0.
|
|
25
|
-
"@sqlrooms/ui": "0.
|
|
23
|
+
"@sqlrooms/project-builder": "0.8.0",
|
|
24
|
+
"@sqlrooms/project-config": "0.8.0",
|
|
25
|
+
"@sqlrooms/ui": "0.8.0",
|
|
26
26
|
"immer": "^10.1.1",
|
|
27
27
|
"lucide-react": "^0.474.0",
|
|
28
28
|
"zod": "^3.24.1",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"lint": "eslint .",
|
|
39
39
|
"typedoc": "typedoc"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "99b46a96ab900e6b005bcd30cfbfe7b3c9d51f8d"
|
|
42
42
|
}
|