vortx-gl 1.0.30 → 1.0.32
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 +453 -198
- package/dist/components/GraphCanvas.d.ts +5 -0
- package/dist/engine/types.d.ts +21 -6
- package/dist/index.d.ts +1 -2
- package/dist/vortx-gl.css +47 -47
- package/dist/vortx-gl.es.js +3519 -3513
- package/dist/vortx-gl.umd.js +3603 -3597
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,305 +1,560 @@
|
|
|
1
|
-
# 🎨
|
|
1
|
+
# VortxGL 🎨
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://vuejs.org/)
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
|
-
[](#-performance-benchmarks)
|
|
7
|
-
[](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
|
|
8
|
-
[](LICENSE)
|
|
9
|
-
|
|
10
|
-
VortxGL is a world-class, ultra-high-performance graph visualization library built with **WebGL2**, **Vue 3 (Composition API)**, and **TypeScript**.
|
|
11
|
-
|
|
12
|
-
It was engineered from the ground up to address the limitations of traditional SVG and Canvas-based graph visualizers. While libraries like D3 or Cytoscape choke when handling more than 5,000 nodes due to DOM bloat and main-thread computation bottlenecks, VortxGL easily renders **100,000+ nodes and edges** at a locked **60 FPS**.
|
|
3
|
+
A world-class, high-performance graph visualization engine built with **Vue 3**, **WebGL2**, and **TypeScript**. Engineered for extreme scale and architectural flexibility, VortxGL effortlessly handles **100,000+ nodes and edges** while maintaining a locked 60 FPS.
|
|
13
4
|
|
|
14
5
|
---
|
|
15
6
|
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
🚀 **Experience the Speed**: [VortxGL Live Interactive Sandbox](https://webgl-graph.vercel.app)
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## ⚡ Performance Benchmarks
|
|
23
|
-
|
|
24
|
-
| Metric / Graph Size | 1,000 Nodes | 10,000 Nodes | 50,000 Nodes | 100,000 Nodes |
|
|
25
|
-
| :---------------------- | :---------: | :----------: | :----------: | :------------------: |
|
|
26
|
-
| **VortxGL FPS** | **60 FPS** | **60 FPS** | **60 FPS** | **60 FPS** |
|
|
27
|
-
| **Standard Canvas FPS** | 60 FPS | 24 FPS | 5 FPS | Crashed/Unresponsive |
|
|
28
|
-
| **Standard SVG FPS** | 30 FPS | 2 FPS | Unresponsive | Unresponsive |
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## 🏎️ The Tech Behind the Speed (Architectural Highlights)
|
|
33
|
-
|
|
34
|
-
VortxGL achieves locked 60 FPS at scale by replacing common browser render bottlenecks with low-level graphics techniques:
|
|
35
|
-
|
|
36
|
-
### 1. Hybrid WebGL2 + Canvas2D Pipeline
|
|
37
|
-
|
|
38
|
-
WebGL2 excels at instanced rendering of millions of points and lines, but rendering anti-aliased text (labels), curved hulls, and vector badges in pure shaders is notoriously complex and slow. VortxGL uses a **dual-canvas architecture**:
|
|
7
|
+
## 🚀 Key Evolutionary Features
|
|
39
8
|
|
|
40
|
-
|
|
41
|
-
- High-definition labels, badges, and selections are painted on a 2D HTML5 Canvas overlay.
|
|
42
|
-
- **The "Punch-Out" Technique**: To keep edge lines visual beneath nodes, the overlay draws connections behind, then uses a `destination-out` blending operation to "punch" circular holes in the overlay exactly where the GPU nodes sit. Text and selection rings are then drawn on top.
|
|
9
|
+
### 🎬 Energy Flow Visualization
|
|
43
10
|
|
|
44
|
-
|
|
11
|
+
Bring your data to life with real-time particle animations along graph edges.
|
|
45
12
|
|
|
46
|
-
|
|
13
|
+
- **Dynamic Velocity**: Adjust stream speed in real-time.
|
|
14
|
+
- **Precision Filtering**: Target specific data flows by property and value (e.g., animate only `type: "transaction"`).
|
|
15
|
+
- **GPU-Ready**: Performance-optimized rendering that scales with your dataset.
|
|
47
16
|
|
|
48
|
-
|
|
49
|
-
- When clicking or hovering, the engine queries the exact pixel color under the mouse in $O(1)$ time, providing instantaneous selection feedback even on 100k+ elements.
|
|
17
|
+
### 📁 Advanced Combo (Grouping) System
|
|
50
18
|
|
|
51
|
-
|
|
19
|
+
Full support for hierarchical data structures and interactive clustering.
|
|
52
20
|
|
|
53
|
-
|
|
21
|
+
- **Smart Hulls**: Automatically generated convex hulls for expanded groups.
|
|
22
|
+
- **Interactive Collapsing**: Swap complex clusters for intuitive summary nodes.
|
|
23
|
+
- **Cluster Translation**: Drag entire groups while preserving internal layouts.
|
|
54
24
|
|
|
55
|
-
|
|
56
|
-
- The worker and main thread exchange coordinate data using **Transferable Objects** (`Float32Array` buffers). This allows memory ownership to be passed back and forth instantly with zero copy overhead, completely eliminating Garbage Collection frame drops.
|
|
57
|
-
|
|
58
|
-
### 4. Incremental Spatial Indexing
|
|
59
|
-
|
|
60
|
-
To support spatial actions (like zoom-to-fit, group boundary calculations, and camera culling), VortxGL maintains an internal coordinate search index.
|
|
61
|
-
|
|
62
|
-
- Rather than rebuilding the index on every single tick or position change (an $O(N)$ operation), the engine updates the spatial index incrementally in $O(1)$ time per node mutation.
|
|
63
|
-
|
|
64
|
-
### 5. Screen-Space Projection Caching
|
|
65
|
-
|
|
66
|
-
The engine projects world coordinates into screen coordinates to position overlay text. The projection calculations are cached in memory and marked dirty only when the Camera moves or Node positions change. This saves millions of redundant matrix-multiplication operations per second.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## 🚀 Key Features
|
|
71
|
-
|
|
72
|
-
### 🎬 Energy Flow Animation
|
|
73
|
-
|
|
74
|
-
- Highlight data pathways (e.g. tracking transactions or packet routing) via hardware-accelerated particle flow along edges.
|
|
75
|
-
- Real-time controls for velocity, particle size, and opacity.
|
|
76
|
-
- Target flows dynamically by attributes (e.g. only animate edges matching `type === "transaction"`).
|
|
77
|
-
|
|
78
|
-
### 📁 Collapsible Combos (Groups)
|
|
25
|
+
### ⛓️ Interactive Relation Builder
|
|
79
26
|
|
|
80
|
-
|
|
81
|
-
- **Smart Hulls**: Automatically draws bounding convex hulls around expanded groups.
|
|
82
|
-
- **Smart Collapsing**: Collapses groups into single representative nodes, calculating the group centroid.
|
|
83
|
-
- **Cluster Translation**: Dragging a group moves all internal member nodes in sync.
|
|
27
|
+
Engineered for semantic graph creation with real-time visual feedback.
|
|
84
28
|
|
|
85
|
-
|
|
29
|
+
- **Phantom Edges**: Real-time dashed preview line that follows the cursor during connection.
|
|
30
|
+
- **On-the-Fly Configuration**: Set labels, colors, and thickness via an interactive toast before finalizing.
|
|
31
|
+
- **Adaptive Labels**: Screen-space edge labels that automatically render for high-zoom clarity.
|
|
86
32
|
|
|
87
|
-
|
|
88
|
-
- **Phantom Edges**: Dashed preview line that tracks the mouse pointer during node-to-node connection.
|
|
89
|
-
- **On-the-fly Config**: Instantly modify connection weights, colors, and metadata before finalizing.
|
|
33
|
+
### 🏎️ Tactical Optimization
|
|
90
34
|
|
|
91
|
-
|
|
35
|
+
Built with a performance-first mindset:
|
|
92
36
|
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
- Built-in Dark and Light themes with automatic contrast shifts.
|
|
37
|
+
- **Screen-Space Projection Cache**: Eliminates redundant O(NodeCount) matrix operations for labels and effects.
|
|
38
|
+
- **Zero-Allocation Loops**: Uses specialized scratch buffers to minimize Garbage Collection impact.
|
|
96
39
|
|
|
97
40
|
---
|
|
98
41
|
|
|
99
|
-
##
|
|
42
|
+
## ⚡ Quick Start
|
|
100
43
|
|
|
101
|
-
### 1.
|
|
44
|
+
### 1. Installation
|
|
102
45
|
|
|
103
46
|
```bash
|
|
104
47
|
npm install vortx-gl
|
|
105
48
|
```
|
|
106
49
|
|
|
107
|
-
### 2.
|
|
108
|
-
|
|
109
|
-
Initialize the visualizer using the Vue 3 component. Simply provide a list of nodes and edges formatted with clean metadata.
|
|
50
|
+
### 2. Basic Usage (Vue 3)
|
|
110
51
|
|
|
111
52
|
```vue
|
|
112
53
|
<script setup lang="ts">
|
|
113
|
-
import { ref } from "vue";
|
|
114
54
|
import { GraphCanvas } from "vortx-gl";
|
|
115
55
|
import "vortx-gl/dist/vortx-gl.css";
|
|
116
56
|
|
|
117
|
-
const graphData =
|
|
57
|
+
const graphData = {
|
|
118
58
|
nodes: [
|
|
119
59
|
{
|
|
120
60
|
data: {
|
|
121
|
-
id: "
|
|
122
|
-
label: "
|
|
123
|
-
color: "#
|
|
124
|
-
|
|
125
|
-
icon: "🖥️",
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
data: {
|
|
130
|
-
id: "node-2",
|
|
131
|
-
label: "API Gateway",
|
|
132
|
-
color: "#4FC08D",
|
|
133
|
-
size: 50,
|
|
134
|
-
icon: "🌐",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
data: {
|
|
139
|
-
id: "node-3",
|
|
140
|
-
label: "Client App",
|
|
141
|
-
color: "#ff4757",
|
|
142
|
-
size: 40,
|
|
143
|
-
icon: "📱",
|
|
61
|
+
id: "1",
|
|
62
|
+
label: "Node 1",
|
|
63
|
+
color: "#00ffcc",
|
|
64
|
+
backgroundImage: "https://example.com/icon.png",
|
|
144
65
|
},
|
|
145
66
|
},
|
|
146
67
|
],
|
|
147
68
|
edges: [
|
|
148
69
|
{
|
|
149
|
-
data: {
|
|
150
|
-
id: "edge-1",
|
|
151
|
-
source: "node-3",
|
|
152
|
-
target: "node-2",
|
|
153
|
-
label: "HTTPS Request",
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
data: {
|
|
158
|
-
id: "edge-2",
|
|
159
|
-
source: "node-2",
|
|
160
|
-
target: "node-1",
|
|
161
|
-
label: "SQL Query",
|
|
162
|
-
},
|
|
70
|
+
data: { source: "1", target: "2", type: "transfer" },
|
|
163
71
|
},
|
|
164
72
|
],
|
|
165
|
-
}
|
|
73
|
+
};
|
|
166
74
|
</script>
|
|
167
75
|
|
|
168
76
|
<template>
|
|
169
|
-
<div
|
|
77
|
+
<div style="width: 100vw; height: 100vh;">
|
|
170
78
|
<GraphCanvas :data="graphData" />
|
|
171
79
|
</div>
|
|
172
80
|
</template>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🌐 Live Demo & Docs
|
|
86
|
+
|
|
87
|
+
🚀 **Experience the Speed**: [View the Live Demo](https://webgl-graph.vercel.app)
|
|
88
|
+
|
|
89
|
+
---
|
|
173
90
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
91
|
+
## 📊 Data Schema & Types
|
|
92
|
+
|
|
93
|
+
VortxGL uses a robust, TypeScript-first schema. All element metadata is stored in a dedicated `data` record for application use.
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"nodes": [
|
|
98
|
+
{
|
|
99
|
+
"data": {
|
|
100
|
+
"id": "node-1",
|
|
101
|
+
"label": "Engineering",
|
|
102
|
+
"color": "#ff4757",
|
|
103
|
+
"backgroundImage": "data:image/png;base64,...",
|
|
104
|
+
"metadata": { "status": "active" }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"edges": [
|
|
109
|
+
{
|
|
110
|
+
"data": {
|
|
111
|
+
"id": "edge-1",
|
|
112
|
+
"source": "node-1",
|
|
113
|
+
"target": "node-2",
|
|
114
|
+
"label": "Data Link"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
179
118
|
}
|
|
180
|
-
</style>
|
|
181
119
|
```
|
|
182
120
|
|
|
183
121
|
---
|
|
184
122
|
|
|
185
|
-
##
|
|
123
|
+
## 🎨 Visual Polish
|
|
186
124
|
|
|
187
|
-
VortxGL provides
|
|
125
|
+
VortxGL provides rich options for making your graph look premium and intuitive.
|
|
188
126
|
|
|
189
|
-
###
|
|
127
|
+
### 1. Icons & Images
|
|
128
|
+
Nodes can render text-based icons (emojis) or high-resolution images.
|
|
190
129
|
|
|
191
|
-
|
|
130
|
+
```typescript
|
|
131
|
+
engine.addNode({
|
|
132
|
+
id: "node-1",
|
|
133
|
+
icon: "📂", // Renders text/emoji in center
|
|
134
|
+
image: "url...", // Renders rounded image inside
|
|
135
|
+
size: 60
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. Color Formats
|
|
140
|
+
Colors accept standard CSS hex strings or precision arrays for hardware-level control.
|
|
192
141
|
|
|
193
142
|
```typescript
|
|
194
|
-
|
|
143
|
+
// CSS Hex
|
|
144
|
+
color: "#ff4757"
|
|
145
|
+
|
|
146
|
+
// RGBA Array (0-1 range)
|
|
147
|
+
color: [1.0, 0.28, 0.34, 1.0]
|
|
148
|
+
|
|
149
|
+
// Transparent
|
|
150
|
+
color: [0, 0, 0, 0] // Useful for "ghost" nodes
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 3. Theme Switching
|
|
154
|
+
The engine supports built-in Dark and Light mode, affecting the background clear color and label contrast automatically.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
engine.setTheme("light"); // Switches to light background
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 📁 Combo Management
|
|
163
|
+
|
|
164
|
+
Combos (Groups) allow you to cluster related nodes into logical units. They support two modes: **Expanded** (showing a bounding hull) and **Collapsed** (showing a summary representative node).
|
|
165
|
+
|
|
166
|
+
### 1. Creating a Group
|
|
167
|
+
Groups are created by specifying a unique ID and a list of node IDs to include.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
engine.createGroup("group-alpha", "Engineers", ["node-1", "node-2", "node-3"]);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 2. Collapsing & Expanding
|
|
174
|
+
Collapsing a group hides all member nodes except for one **representative**, which snaps to the centroid of the group.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Programmatically toggle state
|
|
178
|
+
engine.toggleComboCollapse("group-alpha");
|
|
179
|
+
|
|
180
|
+
// Listen for collapse events
|
|
181
|
+
engine.on('combo:update', (data) => {
|
|
182
|
+
console.log(`Group ${data.id} is now ${data.state ? 'collapsed' : 'expanded'}`);
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 3. Interaction Logic
|
|
187
|
+
- **Dragging**: When a group is collapsed, dragging its representative moves all hidden members in sync.
|
|
188
|
+
- **Hulls**: When expanded, a convex hull is automatically rendered around the members with customizable padding and color.
|
|
189
|
+
- **Picking**: You can select a group by clicking on its hull (expanded) or its representative node (collapsed).
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## ⌨️ Pro Shortcuts
|
|
194
|
+
|
|
195
|
+
| Command | Action |
|
|
196
|
+
| :--------------- | :------------------------- |
|
|
197
|
+
| **Left Click** | Select Node / Edge / Combo |
|
|
198
|
+
| **Drag** | Pan the world |
|
|
199
|
+
| **Scroll** | Zoom at mouse focal point |
|
|
200
|
+
| **Shift + Drag** | Precise Box Selection |
|
|
201
|
+
| **Radial Right Click** | Contextual Command Menu |
|
|
202
|
+
| **F** | Snap to Fit View |
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 🔘 Context Menus
|
|
207
|
+
|
|
208
|
+
VortxGL is designed to work seamlessly with domestic UI frameworks (Vue, React). Instead of drawing menus on the WebGL canvas, it is recommended to use standard DOM components positioned over the canvas.
|
|
209
|
+
|
|
210
|
+
### 1. Triggering Menus
|
|
211
|
+
Listen for the `contextmenu` event on the canvas. Use `engine.pick()` or `engine.getEdgeAt()` to identify the element under the cursor.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
canvas.addEventListener('contextmenu', (e) => {
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
const rect = canvas.getBoundingClientRect();
|
|
217
|
+
const x = e.clientX - rect.left;
|
|
218
|
+
const y = e.clientY - rect.top;
|
|
219
|
+
|
|
220
|
+
// Identify target
|
|
221
|
+
const nodeId = engine.pick(x, y);
|
|
222
|
+
const edgeId = engine.getEdgeAt(x, y);
|
|
223
|
+
|
|
224
|
+
// Show your Vue/React menu at e.clientX/Y
|
|
225
|
+
showMenu({ x: e.clientX, y: e.clientY, target: nodeId || edgeId });
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 2. Customizing Menu Items
|
|
230
|
+
You can configure the segments of the circular menu for nodes, edges, and combos through the engine instance.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
engine.setRadialMenu('node', [
|
|
234
|
+
{ label: 'Inspect', icon: 'search', action: 'inspect' },
|
|
235
|
+
{ label: 'Delete', icon: 'trash-2', action: 'delete' },
|
|
236
|
+
{ label: 'Highlight', icon: 'zap', action: 'highlight' }
|
|
237
|
+
]);
|
|
238
|
+
```
|
|
195
239
|
|
|
196
|
-
|
|
240
|
+
### 3. Group HUD (Heads-Up Display)
|
|
241
|
+
For combos (groups), the engine draws a built-in HUD with an expand/collapse button. You can detect clicks on these HUD elements using `pickHUD()`.
|
|
197
242
|
|
|
198
|
-
|
|
243
|
+
```typescript
|
|
244
|
+
engine.on('node:mousedown', (e) => {
|
|
245
|
+
const hudAction = engine.pickHUD(e.x, e.y);
|
|
246
|
+
if (hudAction) {
|
|
247
|
+
if (hudAction.action === 'expand') {
|
|
248
|
+
engine.toggleComboCollapse(hudAction.comboId);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 4. Interactive Connection Workflow
|
|
255
|
+
|
|
256
|
+
VortxGL includes a built-in workflow for creating new relations between nodes with real-time feedback.
|
|
257
|
+
|
|
258
|
+
1. **Trigger**: Call `engine.startConnect(sourceNodeId)` to enter connection mode.
|
|
259
|
+
2. **Preview**: A "Phantom Edge" (dashed line) will follow the cursor from the source node to the mouse position.
|
|
260
|
+
3. **Configure**: Users can set properties like `label` and `color` during the preview phase.
|
|
261
|
+
4. **Complete**: Clicking a target node finalizes the connection and creates a permanent "Styled Edge".
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## 🏗️ Graph Mutation
|
|
267
|
+
|
|
268
|
+
VortxGL provides a high-performance imperative API for modifying the graph in real-time. Changes are immediately synced to GPU buffers using minimal memory copies.
|
|
269
|
+
|
|
270
|
+
### 1. Adding Elements
|
|
271
|
+
```typescript
|
|
272
|
+
// Add a node
|
|
199
273
|
engine.addNode({
|
|
200
|
-
id: "node-
|
|
201
|
-
label: "
|
|
202
|
-
position: { x:
|
|
203
|
-
color: "#
|
|
204
|
-
size: 55,
|
|
274
|
+
id: "node-1",
|
|
275
|
+
label: "New Node",
|
|
276
|
+
position: { x: 100, y: 100 },
|
|
277
|
+
color: "#ff00ff"
|
|
205
278
|
});
|
|
206
279
|
|
|
207
|
-
//
|
|
280
|
+
// Add an edge
|
|
281
|
+
engine.addEdge({
|
|
282
|
+
source: "node-1",
|
|
283
|
+
target: "node-2",
|
|
284
|
+
label: "Connected"
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### 2. Updating Elements
|
|
289
|
+
Updates are partial; you only need to provide the fields you want to change.
|
|
290
|
+
```typescript
|
|
208
291
|
engine.updateNode({
|
|
209
|
-
id: "node-
|
|
210
|
-
color: "#
|
|
211
|
-
label: "
|
|
292
|
+
id: "node-1",
|
|
293
|
+
color: "#00ff00", // Change color
|
|
294
|
+
label: "Updated Name"
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
engine.updateEdge({
|
|
298
|
+
id: "edge-1",
|
|
299
|
+
label: "New Relationship"
|
|
212
300
|
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 3. Removing Elements
|
|
304
|
+
```typescript
|
|
305
|
+
// Removes node and all connected edges
|
|
306
|
+
engine.removeNode("node-1");
|
|
213
307
|
|
|
214
|
-
//
|
|
215
|
-
engine.
|
|
308
|
+
// Removes a single edge
|
|
309
|
+
engine.removeEdge("edge-1");
|
|
310
|
+
|
|
311
|
+
// Complete reset
|
|
312
|
+
engine.clear();
|
|
216
313
|
```
|
|
217
314
|
|
|
218
|
-
###
|
|
315
|
+
### 3. Visual Properties Reference
|
|
316
|
+
|
|
317
|
+
| Property | Type | Target | Description |
|
|
318
|
+
|---|---|---|---|
|
|
319
|
+
| `label` | string | Both | Primary text label (Edges show at >30% zoom) |
|
|
320
|
+
| `size` | number | Node | Diameter of the node circle |
|
|
321
|
+
| `width` | number | Both | Bounding width for node labels |
|
|
322
|
+
| `customSize` | number | Edge | Precision line thickness (supports <1 and >10) |
|
|
323
|
+
| `customColor`| string | Edge | Per-edge override color (HEX/RGBA) |
|
|
324
|
+
| `color` | string | Node | CSS Hex or RGBA value |
|
|
325
|
+
| `icon` | string | Node | Lucide icon name or Emoji |
|
|
326
|
+
| `image` | string | Node | URL for an image shown inside the node |
|
|
327
|
+
| `opacity`| number | Both | Global transparency (0-1) |
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
// Style a large node
|
|
331
|
+
engine.updateNode({
|
|
332
|
+
id: "node-1",
|
|
333
|
+
label: "Large Server",
|
|
334
|
+
size: 80, // Diameter
|
|
335
|
+
width: 120, // Label boundary width
|
|
336
|
+
color: "#ff3300"
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Create a premium styled connection
|
|
340
|
+
engine.addEdge({
|
|
341
|
+
source: "node-1",
|
|
342
|
+
target: "node-2",
|
|
343
|
+
label: "Critical Link",
|
|
344
|
+
data: {
|
|
345
|
+
customColor: "#ff00ff", // Override WebGL global color
|
|
346
|
+
customSize: 4.5 // Precise thickness in pixels
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 🔍 Querying Elements
|
|
354
|
+
|
|
355
|
+
Retrieve element data from the engine for inspection or state management.
|
|
356
|
+
|
|
357
|
+
### 1. Selection by ID
|
|
358
|
+
```typescript
|
|
359
|
+
const node = engine.getNode("node-1");
|
|
360
|
+
console.log(node.position, node.label);
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### 2. Selection by Class
|
|
364
|
+
Retrieve groups of elements that share a specific class.
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
// Get all critical servers
|
|
368
|
+
const criticalNodes = engine.getNodesByClass("critical");
|
|
369
|
+
|
|
370
|
+
// Get all standard cables
|
|
371
|
+
const standardEdges = engine.getEdgesByClass("standard-link");
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### 3. Global Retrieval
|
|
375
|
+
```typescript
|
|
376
|
+
const allNodes = engine.getAllNodes();
|
|
377
|
+
const allEdges = engine.getAllEdges();
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## 🎨 Styling with Classes
|
|
383
|
+
|
|
384
|
+
VortxGL supports a high-performance stylesheet system, allowing you to define visual presets and apply them via class names, similar to CSS or Cytoscape.
|
|
385
|
+
|
|
386
|
+
### 1. Defining a Stylesheet
|
|
387
|
+
A stylesheet is a dictionary where keys are class names and values are style objects. Use `engine.setStylesheet()` to apply it globally.
|
|
219
388
|
|
|
220
389
|
```typescript
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
390
|
+
const theme = {
|
|
391
|
+
'critical': { color: '#ff4757', size: 60, icon: '⚠️' } ,
|
|
392
|
+
'server': { color: '#2f3542', size: 45, icon: '🖥️' },
|
|
393
|
+
'standard-link': { color: 'rgba(255,255,255,0.2)' }
|
|
225
394
|
};
|
|
226
395
|
|
|
227
|
-
engine.setStylesheet(
|
|
396
|
+
engine.setStylesheet(theme);
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 2. Applying Classes
|
|
400
|
+
Apply classes when adding or updating elements. Multiple classes can be applied as an array; later classes override previous ones.
|
|
228
401
|
|
|
229
|
-
|
|
402
|
+
```typescript
|
|
230
403
|
engine.addNode({
|
|
231
|
-
id: "
|
|
232
|
-
classes: ["
|
|
233
|
-
label: "
|
|
404
|
+
id: "node-1",
|
|
405
|
+
classes: ["server", "critical"],
|
|
406
|
+
label: "Database 01"
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
engine.addEdge({
|
|
410
|
+
source: "node-1",
|
|
411
|
+
target: "node-2",
|
|
412
|
+
classes: ["standard-link"]
|
|
234
413
|
});
|
|
235
414
|
```
|
|
236
415
|
|
|
237
|
-
###
|
|
416
|
+
### 3. Priority Rules
|
|
417
|
+
Visual properties are applied in the following order of precedence:
|
|
418
|
+
1. **Explicit Properties**: Properties set directly on the node (e.g., `color: '#fff'`) always win.
|
|
419
|
+
2. **Class Styles**: Properties defined in the stylesheet for the applied classes.
|
|
420
|
+
3. **Engine Defaults**: Hardcoded fallback values.
|
|
238
421
|
|
|
239
|
-
|
|
422
|
+
---
|
|
240
423
|
|
|
241
|
-
|
|
242
|
-
// Circular layout
|
|
243
|
-
engine.runLayout("circle");
|
|
424
|
+
## ⚡ Energy Flow Animation
|
|
244
425
|
|
|
245
|
-
|
|
246
|
-
engine.runLayout("concentric", { spacing: 2 });
|
|
426
|
+
VortxGL includes a custom, hardware-accelerated "Energy Flow" animation for highlighting data movements along edges.
|
|
247
427
|
|
|
248
|
-
|
|
249
|
-
|
|
428
|
+
### 1. Basic Configuration
|
|
429
|
+
```typescript
|
|
430
|
+
engine.setFlowConfig({
|
|
431
|
+
enabled: true,
|
|
432
|
+
velocity: 0.005,
|
|
433
|
+
size: 2,
|
|
434
|
+
color: "#00ffcc"
|
|
435
|
+
});
|
|
250
436
|
```
|
|
251
437
|
|
|
252
|
-
###
|
|
438
|
+
### 2. Selective Flow (Advanced)
|
|
439
|
+
You can restrict the animation to only run on edges connected to the currently selected nodes. This is extremely useful for tracing paths or focusing on specific network segments.
|
|
253
440
|
|
|
254
441
|
```typescript
|
|
255
442
|
engine.setFlowConfig({
|
|
256
443
|
enabled: true,
|
|
257
|
-
|
|
258
|
-
size: 2.5, // Particle radius in pixels
|
|
259
|
-
color: "#ffd32a", // Glowing yellow particle streams
|
|
444
|
+
selectedOnly: true
|
|
260
445
|
});
|
|
261
446
|
```
|
|
262
447
|
|
|
448
|
+
### 3. All Options
|
|
449
|
+
| Property | Type | Description |
|
|
450
|
+
|---|---|---|
|
|
451
|
+
| `enabled` | boolean | Toggle the animation |
|
|
452
|
+
| `velocity` | number | Speed of particles (0.001 - 0.01 recommended) |
|
|
453
|
+
| `size` | number | Radius of particles in pixels |
|
|
454
|
+
| `opacity` | number | Transparency (0 - 1) |
|
|
455
|
+
| `pulse` | boolean | Adds a subtle breathing effect to particles |
|
|
456
|
+
| `selectedOnly`| boolean | Show only on edges of selected nodes |
|
|
457
|
+
|
|
263
458
|
---
|
|
264
459
|
|
|
265
|
-
##
|
|
460
|
+
## 🏗️ Events & Interactivity
|
|
461
|
+
|
|
462
|
+
VortxGL features a powerful, Cytoscape-inspired event system for deep integration with your application logic.
|
|
463
|
+
|
|
464
|
+
### 1. Subscribing to Events
|
|
465
|
+
Use the `on()` API to listen for interactions. Use the returned function to unsubscribe.
|
|
466
|
+
|
|
467
|
+
```typescript
|
|
468
|
+
// Subscribe
|
|
469
|
+
const unsub = engine.on('node:click', ({ id }) => {
|
|
470
|
+
console.log('Clicked node:', id);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// Unsubscribe when component is destroyed
|
|
474
|
+
unsub();
|
|
475
|
+
```
|
|
266
476
|
|
|
267
|
-
|
|
268
|
-
|
|
|
269
|
-
|
|
|
270
|
-
| **
|
|
271
|
-
| **
|
|
272
|
-
| **
|
|
273
|
-
| **
|
|
274
|
-
| **
|
|
477
|
+
### 2. Available Events
|
|
478
|
+
| Category | Event Keys | Description |
|
|
479
|
+
| :--- | :--- | :--- |
|
|
480
|
+
| **Nodes** | `node:click`, `node:hover`, `node:drag`, `node:select` | Individual element interactions |
|
|
481
|
+
| **Edges** | `edge:click`, `edge:hover`, `edge:select` | Edge-specific interactions |
|
|
482
|
+
| **Combos** | `combo:click`, `combo:hover`, `combo:select` | Group-specific interactions |
|
|
483
|
+
| **Viewport** | `graph:click`, `graph:pan`, `graph:zoom`, `viewport` | Global camera movement |
|
|
484
|
+
| **Selection**| `boxstart`, `boxselect`, `boxend` | Marquee/Box selection lifecycle |
|
|
275
485
|
|
|
276
486
|
---
|
|
277
487
|
|
|
278
|
-
##
|
|
488
|
+
## 📸 Viewport & Camera
|
|
279
489
|
|
|
280
|
-
|
|
490
|
+
Control the view programmatically to create cinematic transitions or automated "focus" actions.
|
|
281
491
|
|
|
492
|
+
### 1. Focus & Fit
|
|
282
493
|
```typescript
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
console.log(`User selected node ID: ${id}`);
|
|
286
|
-
});
|
|
494
|
+
// Auto-scale and center to show the entire graph
|
|
495
|
+
engine.fitToView();
|
|
287
496
|
|
|
288
|
-
//
|
|
289
|
-
|
|
497
|
+
// Move camera to a specific world coordinate
|
|
498
|
+
engine.setCameraCenter(0, 0);
|
|
290
499
|
```
|
|
291
500
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
501
|
+
### 2. Zoom Controls
|
|
502
|
+
```typescript
|
|
503
|
+
engine.zoomIn();
|
|
504
|
+
engine.zoomOut();
|
|
505
|
+
|
|
506
|
+
// Precise focal zoom (screen coordinates)
|
|
507
|
+
engine.zoomAt(mouseX, mouseY, delta);
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## 🧬 Layouts & Batch Updates
|
|
513
|
+
|
|
514
|
+
VortxGL provides built-in geometric layouts and supports seamless integration with external layout engines (like Cytoscape.js or d3-force).
|
|
515
|
+
|
|
516
|
+
### 1. Built-in Geometric Layouts
|
|
517
|
+
Trigger fast, animated layouts directly from the engine instance.
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
// Arrange all nodes in a circle
|
|
521
|
+
engine.runLayout('circle');
|
|
522
|
+
|
|
523
|
+
// Arrange nodes in a grid
|
|
524
|
+
engine.runLayout('grid');
|
|
525
|
+
|
|
526
|
+
// Random scatter
|
|
527
|
+
engine.runLayout('random');
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### 2. Layouts on Selection
|
|
531
|
+
You can restrict any built-in layout to only affect currently selected elements, keeping the rest of the graph anchored.
|
|
532
|
+
|
|
533
|
+
```typescript
|
|
534
|
+
engine.runLayout('circle', { selectedOnly: true });
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### 3. External Layouts (e.g. Cytoscape)
|
|
538
|
+
For complex force-directed or hierarchical layouts, calculate positions externally and sync them:
|
|
539
|
+
|
|
540
|
+
#### Batch Sync (Most Efficient)
|
|
541
|
+
Use `setData` for an O(1) buffer swap when a layout finishes.
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
engine.setData(newPositions, newColors, newIds, metadata, edgeIndices);
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
#### Incremental Sync (Real-time Animation)
|
|
548
|
+
For live layout animations, use `updateNode` in your layout's tick function.
|
|
549
|
+
|
|
550
|
+
```typescript
|
|
551
|
+
nodes.forEach(n => {
|
|
552
|
+
engine.updateNode({ id: n.id, position: { x: n.x, y: n.y } });
|
|
553
|
+
});
|
|
554
|
+
```
|
|
300
555
|
|
|
301
556
|
---
|
|
302
557
|
|
|
303
558
|
## 📜 License
|
|
304
559
|
|
|
305
|
-
|
|
560
|
+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
|