@samoramachel/netuniverse 1.0.0 → 1.1.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/README.md +119 -29
- package/dist/GraphScene.d.ts +8 -6
- package/dist/GraphScene.d.ts.map +1 -1
- package/dist/index.es.js +1891 -1843
- package/dist/index.umd.js +8 -8
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,54 +81,82 @@ export default function Page() {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
### Spatial API (Background Mode)
|
|
85
85
|
|
|
86
|
-
You can
|
|
86
|
+
You can turn the graph into an interactive spatial background by injecting your own 3D content and controlling the camera programmatically.
|
|
87
87
|
|
|
88
88
|
```tsx
|
|
89
|
-
import {
|
|
89
|
+
import { useRef } from 'react';
|
|
90
|
+
import { GraphScene, GraphRef } from 'netuniverse';
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
...defaultConfig,
|
|
94
|
-
graph: {
|
|
95
|
-
...defaultConfig.graph,
|
|
96
|
-
network_node_count: 5000,
|
|
97
|
-
connection_distance: 400,
|
|
98
|
-
},
|
|
99
|
-
controls: {
|
|
100
|
-
...defaultConfig.controls,
|
|
101
|
-
enablePan: true,
|
|
102
|
-
enableZoom: true,
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
```
|
|
92
|
+
function MySpatialPage() {
|
|
93
|
+
const graphRef = useRef<GraphRef>(null);
|
|
106
94
|
|
|
107
|
-
|
|
95
|
+
const handleScrollToFeature = () => {
|
|
96
|
+
// Fly to coordinates [x, y, z] to show a specific 3D feature
|
|
97
|
+
graphRef.current?.flyTo([50, 50, 50], 2);
|
|
98
|
+
};
|
|
108
99
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
return (
|
|
101
|
+
<div style={{ position: 'relative', width: '100vw', height: '100vh' }}>
|
|
102
|
+
{/* 1. Spatial Background */}
|
|
103
|
+
<GraphScene ref={graphRef} data={data}>
|
|
104
|
+
{/* 2. Inject Custom 3D Content */}
|
|
105
|
+
<mesh position={[50, 50, 50]}>
|
|
106
|
+
<boxGeometry args={[10, 10, 10]} />
|
|
107
|
+
<meshStandardMaterial color="orange" wireframe />
|
|
108
|
+
</mesh>
|
|
109
|
+
</GraphScene>
|
|
110
|
+
|
|
111
|
+
{/* 3. HTML Overlay */}
|
|
112
|
+
<div style={{ position: 'absolute', zIndex: 10 }}>
|
|
113
|
+
<button onClick={handleScrollToFeature}>Go to Feature</button>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
### GraphRef API
|
|
114
121
|
|
|
115
|
-
|
|
122
|
+
The `ref` passed to `GraphScene` exposes the following methods for programmatic control:
|
|
116
123
|
|
|
117
124
|
```typescript
|
|
118
|
-
interface
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
interface GraphRef {
|
|
126
|
+
/** The underlying Three.js camera instance */
|
|
127
|
+
camera: THREE.PerspectiveCamera;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Smoothly fly the camera to a specific 3D position.
|
|
131
|
+
* @param position [x, y, z] coordinates
|
|
132
|
+
* @param duration Animation duration in seconds (default: 1.5)
|
|
133
|
+
*/
|
|
134
|
+
flyTo: (position: [number, number, number], duration?: number) => void;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Smoothly rotate the camera to look at a specific target point.
|
|
138
|
+
* @param target [x, y, z] coordinates to look at
|
|
139
|
+
* @param duration Animation duration in seconds (default: 1.5)
|
|
140
|
+
*/
|
|
141
|
+
lookAt: (target: [number, number, number], duration?: number) => void;
|
|
122
142
|
}
|
|
123
143
|
```
|
|
124
144
|
|
|
125
145
|
### Types
|
|
126
146
|
|
|
127
147
|
```typescript
|
|
148
|
+
export enum ClusterId {
|
|
149
|
+
Core = 'CORE',
|
|
150
|
+
Finance = 'FINANCE',
|
|
151
|
+
Social = 'SOCIAL',
|
|
152
|
+
Infrastructure = 'INFRA',
|
|
153
|
+
Network = 'NETWORK'
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
interface NodeData {
|
|
129
157
|
id: string;
|
|
130
158
|
label: string;
|
|
131
|
-
cluster: string;
|
|
159
|
+
cluster: ClusterId | string;
|
|
132
160
|
x?: number;
|
|
133
161
|
y?: number;
|
|
134
162
|
z?: number;
|
|
@@ -148,6 +176,68 @@ interface GraphData {
|
|
|
148
176
|
}
|
|
149
177
|
```
|
|
150
178
|
|
|
179
|
+
## Advanced Usage
|
|
180
|
+
|
|
181
|
+
### Injecting 3D Content (Spatial Background)
|
|
182
|
+
|
|
183
|
+
`GraphScene` acts as a 3D container. specific 3D objects can be injected directly as children, allowing you to mix the graph visualization with other Three.js elements.
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
<GraphScene data={data}>
|
|
187
|
+
<mesh position={[50, 50, 50]}>
|
|
188
|
+
<boxGeometry args={[10, 10, 10]} />
|
|
189
|
+
<meshStandardMaterial color="orange" wireframe />
|
|
190
|
+
</mesh>
|
|
191
|
+
</GraphScene>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Custom Physics Hook
|
|
195
|
+
|
|
196
|
+
If you need access to the underlying d3-force simulation, you can use the exported `useGraphPhysics` hook, though standard usage handles this automatically within `GalaxyGraph`.
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
import { useGraphPhysics } from 'netuniverse';
|
|
200
|
+
|
|
201
|
+
// Inside a component within the <Canvas> context
|
|
202
|
+
useGraphPhysics({ nodes, links });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Configuration
|
|
206
|
+
|
|
207
|
+
You can customize the graph behavior by importing and modifying the default config.
|
|
208
|
+
|
|
209
|
+
### Full Options Reference
|
|
210
|
+
|
|
211
|
+
| Section | Key | Type | Default | Description |
|
|
212
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
213
|
+
| **Graph** | `network_node_count` | Int | `4000` | Number of background star particles. |
|
|
214
|
+
| | `network_spread` | Int | `1500` | Spatial spread of the background cloud. |
|
|
215
|
+
| | `connection_distance` | Int | `300` | Max distance for background lines. |
|
|
216
|
+
| | `grab_distance` | Int | `300` | Radius for mouse interaction grab effect. |
|
|
217
|
+
| **Colors** | `background` | Hex | `#FFFBF4` | Scene background & fog color. |
|
|
218
|
+
| | `network_node` | Hex | `#BDC3C7` | Color of background nodes. |
|
|
219
|
+
| | `click_active` | Hex | `#E47600` | Flash color on interaction. |
|
|
220
|
+
| **Controls** | `enableZoom` | Bool | `true` | Allow zooming. |
|
|
221
|
+
| | `enableRotate` | Bool | `true` | Allow rotation. |
|
|
222
|
+
| | `maxPolarAngle` | Float | `3.14159` | Vertical rotation limit. |
|
|
223
|
+
| **Animation** | `bounce.enabled` | Bool | `true` | Enable boundary bounce effect. |
|
|
224
|
+
| | `highlight.scale_hover` | Float | `1.5` | Scale factor on hover. |
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
import { defaultConfig } from 'netuniverse';
|
|
228
|
+
|
|
229
|
+
const myConfig = {
|
|
230
|
+
...defaultConfig,
|
|
231
|
+
graph: {
|
|
232
|
+
...defaultConfig.graph,
|
|
233
|
+
colors: {
|
|
234
|
+
...defaultConfig.graph.colors,
|
|
235
|
+
background: '#0f172a',
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
```
|
|
240
|
+
|
|
151
241
|
## Development
|
|
152
242
|
|
|
153
243
|
```bash
|
package/dist/GraphScene.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { GraphData, NodeData } from './types';
|
|
3
|
-
interface GraphSceneProps {
|
|
2
|
+
import { GraphData, NodeData, GraphRef } from './types';
|
|
3
|
+
export interface GraphSceneProps {
|
|
4
4
|
data: GraphData;
|
|
5
|
-
onNodeSelect
|
|
6
|
-
selectedNodeId
|
|
5
|
+
onNodeSelect?: (node: NodeData | null) => void;
|
|
6
|
+
selectedNodeId?: string | null;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
7
10
|
}
|
|
8
|
-
export declare const GraphScene: React.
|
|
9
|
-
export {};
|
|
11
|
+
export declare const GraphScene: React.ForwardRefExoticComponent<GraphSceneProps & React.RefAttributes<GraphRef>>;
|
|
10
12
|
//# sourceMappingURL=GraphScene.d.ts.map
|
package/dist/GraphScene.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphScene.d.ts","sourceRoot":"","sources":["../GraphScene.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"GraphScene.d.ts","sourceRoot":"","sources":["../GraphScene.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAMxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMxD,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC/B;AAED,eAAO,MAAM,UAAU,kFA4FrB,CAAC"}
|