@neo4j-nvl/base 1.2.0-ec8b9947 → 1.2.0-eea71f07
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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/base.mjs +1 -1
- package/dist/types/index.d.ts +6 -5
- package/dist/types/layouts/animatedlayout/AnimatedLayout.d.ts +2 -2
- package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +2 -2
- package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +123 -13
- package/dist/types/layouts/forcedirectedlayout/physlayout/clustering/ClusterByMerger.d.ts +61 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/clustering/SolarMerger.d.ts +56 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/clustering/clustering-utils.d.ts +143 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/clustering/clustering-utils.test.d.ts +1 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/{solarmerger → clustering}/types.d.ts +10 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +1 -1
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +1 -1
- package/dist/types/layouts/freeLayout/FreeLayout.d.ts +2 -4
- package/dist/types/layouts/gridLayout/GridLayout.d.ts +2 -6
- package/dist/types/modules/NvlController.d.ts +74 -4
- package/dist/types/modules/dataset.d.ts +3 -1
- package/dist/types/modules/state/types.d.ts +96 -20
- package/dist/types/modules/state/utils.d.ts +2 -2
- package/dist/types/renderers/ClusterOverlay.d.ts +80 -0
- package/dist/types/renderers/ClusterOverlay.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/canvasrenderer/arrowDrawing.d.ts +2 -16
- package/dist/types/renderers/domrenderer/shared/ImageCache.d.ts +1 -0
- package/dist/types/renderers/domrenderer/shared/arrows/arrows.d.ts +4 -6
- package/dist/types/renderers/webglrenderer/Controller.d.ts +27 -6
- package/dist/types/renderers/webglrenderer/IconLayerRegistry.d.ts +14 -0
- package/dist/types/renderers/webglrenderer/IconLayerRegistry.test.d.ts +1 -0
- package/dist/types/renderers/webglrenderer/Renderer.d.ts +43 -2
- package/dist/types/renderers/webglrenderer/node-animation-fragment.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/node-animation-vertex.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/node-fragment-point.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/node-vertex-point.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/rel-glsl-utils.d.ts +1 -0
- package/dist/types/renderers/webglrenderer/rel-vertex-arrow.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/viewport-box-fragment.d.ts +1 -1
- package/dist/types/renderers/webglrenderer/viewport-box-vertex.d.ts +1 -1
- package/dist/types/types/graph-element.d.ts +9 -1
- package/dist/types/types/nvl-window-functions.d.ts +2 -2
- package/dist/types/utils/clusterGeometry.d.ts +14 -0
- package/dist/types/utils/clusterGeometry.test.d.ts +1 -0
- package/dist/types/utils/constants.d.ts +1 -0
- package/dist/types/utils/geometry.d.ts +29 -0
- package/dist/types/utils/webWorkerUtils.d.ts +1 -1
- package/dist/types/utils/zoomFunctions.d.ts +9 -2
- package/package.json +5 -5
- package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +0 -22
- package/dist/types/layouts/forcedirectedlayout/cosebilkentlayout/CoseBilkentLayout.d.ts +0 -33
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +0 -21
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/solar-placer.d.ts +0 -2
- /package/dist/types/layouts/forcedirectedlayout/physlayout/{solarmerger/SolarMerger.bench.d.ts → clustering/ClusterByMerger.test.d.ts} +0 -0
- /package/dist/types/layouts/forcedirectedlayout/physlayout/{solarmerger/SolarMerger.test.d.ts → clustering/SolarMerger.bench.d.ts} +0 -0
- /package/dist/types/layouts/forcedirectedlayout/physlayout/{solarmerger/solar-placer.test.d.ts → clustering/SolarMerger.test.d.ts} +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ExternalCallbacks } from './modules/ExternalCallbackHandler';
|
|
2
|
-
import type { CircularOptions, ForceDirectedOptions, HierarchicalOptions, Renderer as InternalRenderer, Layout, LayoutOptions, NvlOptions, NvlState, ZoomOptions } from './modules/state/types';
|
|
2
|
+
import type { CircularOptions, ClusterByFn, ClusterId, ClusteringOptions, ForceDirectedOptions, HierarchicalOptions, Renderer as InternalRenderer, Layout, LayoutOptions, NvlOptions, NvlState, ZoomOptions } from './modules/state/types';
|
|
3
3
|
import { CanvasRendererType, CircularLayoutType, ForceDirectedLayoutType, FreeLayoutType, GridLayoutType, HierarchicalLayoutType, SvgRendererType, WebGLRendererType, d3ForceLayoutType } from './modules/state/types';
|
|
4
4
|
import { drawCircleBand } from './renderers/domrenderer/canvasrenderer/nodeDrawing';
|
|
5
5
|
import type { StyledCaption } from './renderers/domrenderer/shared/types';
|
|
6
|
-
import type { Node, PartialNode, PartialRelationship, Relationship } from './types/graph-element';
|
|
6
|
+
import type { Node, NodeWithClientPosition, PartialNode, PartialRelationship, Relationship } from './types/graph-element';
|
|
7
7
|
import { CompatibilityError } from './utils/errors';
|
|
8
8
|
import type { Point } from './utils/geometry';
|
|
9
9
|
import type { HitTargetNode, HitTargetRelationship, HitTargets } from './utils/hittest';
|
|
@@ -139,9 +139,10 @@ declare class NVL {
|
|
|
139
139
|
removeRelationshipsWithIds(relationshipIds: string[]): void;
|
|
140
140
|
/**
|
|
141
141
|
* Returns all nodes that is currently stored in the visualisation.
|
|
142
|
-
*
|
|
142
|
+
* Each node includes layout coordinates (`x`, `y`) and a `clientPosition` in screen space.
|
|
143
|
+
* @returns The array of {@link NodeWithClientPosition nodes}.
|
|
143
144
|
*/
|
|
144
|
-
getNodes():
|
|
145
|
+
getNodes(): NodeWithClientPosition[];
|
|
145
146
|
/**
|
|
146
147
|
* Returns the relationships that are currently in the visualization.
|
|
147
148
|
* @returns An array of the {@link Relationship relationships} in the visualization.
|
|
@@ -415,5 +416,5 @@ declare const colorMapperFunctions: {
|
|
|
415
416
|
*/
|
|
416
417
|
type Renderer = Exclude<InternalRenderer, typeof SvgRendererType>;
|
|
417
418
|
export default NVL;
|
|
418
|
-
export type { NvlOptions, Renderer, Node, Relationship, PartialNode, PartialRelationship, Layout, LayoutOptions, ForceDirectedOptions, HierarchicalOptions, CircularOptions, ExternalCallbacks, HitTargets, HitTargetNode, HitTargetRelationship, Point, NvlMouseEvent, ZoomOptions, StyledCaption, WebGLRendererType, CanvasRendererType };
|
|
419
|
+
export type { NvlOptions, Renderer, Node, NodeWithClientPosition, Relationship, PartialNode, PartialRelationship, Layout, LayoutOptions, ForceDirectedOptions, ClusteringOptions, ClusterByFn, ClusterId, HierarchicalOptions, CircularOptions, ExternalCallbacks, HitTargets, HitTargetNode, HitTargetRelationship, Point, NvlMouseEvent, ZoomOptions, StyledCaption, WebGLRendererType, CanvasRendererType };
|
|
419
420
|
export { NVL, colorMapperFunctions, CompatibilityError, ForceDirectedLayoutType, HierarchicalLayoutType, GridLayoutType, FreeLayoutType, d3ForceLayoutType, CircularLayoutType, drawCircleBand, nvlResultTransformer, getZoomTargetForNodePositions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NvlState } from '../../modules/state/types';
|
|
2
|
-
import type { Node } from '../../types/graph-element';
|
|
2
|
+
import type { Node, PartialNode } from '../../types/graph-element';
|
|
3
3
|
export default class AnimatedLayout {
|
|
4
4
|
positions: Record<string, Node>;
|
|
5
5
|
oldPositions: Record<string, Node>;
|
|
@@ -20,6 +20,6 @@ export default class AnimatedLayout {
|
|
|
20
20
|
updateOldPositionFromState(): void;
|
|
21
21
|
startAnimation(): void;
|
|
22
22
|
update(): void;
|
|
23
|
-
updateNodes(positionList:
|
|
23
|
+
updateNodes(positionList: PartialNode[]): void;
|
|
24
24
|
getNodePositions(nodeList: Node[]): Node[];
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Simulation, SimulationLinkDatum, SimulationNodeDatum } from 'd3-force';
|
|
2
2
|
import type { NvlState } from '../../modules/state/types';
|
|
3
|
-
import type { Node, Relationship } from '../../types/graph-element';
|
|
3
|
+
import type { Node, PartialNode, Relationship } from '../../types/graph-element';
|
|
4
4
|
import type { Point } from '../../utils/geometry';
|
|
5
5
|
import type { D3Node } from './types';
|
|
6
6
|
export declare class D3ForceLayout {
|
|
@@ -20,7 +20,7 @@ export declare class D3ForceLayout {
|
|
|
20
20
|
state: NvlState;
|
|
21
21
|
});
|
|
22
22
|
setOptions(options: any): void;
|
|
23
|
-
updateNodes(positionList:
|
|
23
|
+
updateNodes(positionList: PartialNode[]): void;
|
|
24
24
|
update(refreshPositions?: boolean): void;
|
|
25
25
|
layout(_nodes: Node[], _rels: Relationship[], firstTimeAddingNodes: boolean): void;
|
|
26
26
|
getNodePositions(nodeList: D3Node[]): any[];
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { ForceDirectedOptions, NvlState } from '../../../modules/state/types';
|
|
2
|
-
import type { Node, Relationship } from '../../../types/graph-element';
|
|
3
|
-
import type
|
|
2
|
+
import type { Node, PartialNode, Relationship } from '../../../types/graph-element';
|
|
3
|
+
import { type Point } from '../../../utils/geometry';
|
|
4
|
+
import type { CoarsenedGraph } from './clustering/types';
|
|
5
|
+
/**
|
|
6
|
+
* Collision multipliers below this are floored to 0, which makes the shader skip its
|
|
7
|
+
* all-pairs collision loop. Every fine-level force in that loop is scaled by the same
|
|
8
|
+
* multiplier, so at this strength they move nothing worth the O(n^2) cost.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CollisionMultiplierSkipThreshold = 0.05;
|
|
11
|
+
export declare const ConvergenceCheckInterval = 20;
|
|
12
|
+
/**
|
|
13
|
+
* Number of consecutive convergence checks that must report a below-threshold
|
|
14
|
+
* graph speed before the layout is considered settled. This debounces a single
|
|
15
|
+
* lucky-low reading so a still-moving graph isn't stopped prematurely.
|
|
16
|
+
*/
|
|
17
|
+
export declare const StableChecksToConverge = 3;
|
|
4
18
|
export declare class PhysLayout {
|
|
5
19
|
private physVbo;
|
|
6
20
|
private physSmallVbo;
|
|
@@ -10,14 +24,13 @@ export declare class PhysLayout {
|
|
|
10
24
|
private averageNodeSize;
|
|
11
25
|
private shouldUpdate;
|
|
12
26
|
private iterationCount;
|
|
13
|
-
private lastSpeedValues;
|
|
14
|
-
private rollingAvgGraphSpeed;
|
|
15
27
|
private nodeVariation;
|
|
16
28
|
private nodeCenterPoint;
|
|
17
29
|
private peakIterationMultiplier;
|
|
18
30
|
private stateDisposers;
|
|
19
31
|
private state;
|
|
20
32
|
private dpr;
|
|
33
|
+
private maxGlNodeSize;
|
|
21
34
|
private simulationStopVelocitySquared;
|
|
22
35
|
private gravity;
|
|
23
36
|
private force;
|
|
@@ -25,10 +38,11 @@ export declare class PhysLayout {
|
|
|
25
38
|
private nodeIndexToId;
|
|
26
39
|
private flatRelationshipKeys;
|
|
27
40
|
private numNodes;
|
|
28
|
-
private solarMerger;
|
|
29
41
|
private subGraphs;
|
|
30
|
-
private nodeSortMap;
|
|
31
42
|
private firstUpdate;
|
|
43
|
+
private precomputeMs;
|
|
44
|
+
private precomputeStarted;
|
|
45
|
+
private precomputing;
|
|
32
46
|
private curPhysData;
|
|
33
47
|
private apprxRepForceShader;
|
|
34
48
|
private levelsClusterTexture;
|
|
@@ -42,12 +56,24 @@ export declare class PhysLayout {
|
|
|
42
56
|
private updateData;
|
|
43
57
|
private updateShader;
|
|
44
58
|
private physPositions;
|
|
59
|
+
private physDirty;
|
|
60
|
+
private positionsCacheVersion;
|
|
61
|
+
private convergencePbo;
|
|
62
|
+
private convergenceFence;
|
|
63
|
+
private convergenceSnapshot;
|
|
64
|
+
private readonly cpuWritesSinceAsyncReadback;
|
|
65
|
+
private hadSyncReadback;
|
|
66
|
+
private graphIsStableCount;
|
|
45
67
|
private springTexture;
|
|
46
68
|
private sizeTexture;
|
|
47
69
|
private offsetTexture;
|
|
48
70
|
private pinTexture;
|
|
49
71
|
private addedNodes;
|
|
50
72
|
private seedingMethod;
|
|
73
|
+
private clusterBy?;
|
|
74
|
+
private crossClusterRelationshipMultiplier;
|
|
75
|
+
private lastClusterByAssignments;
|
|
76
|
+
private sunMap;
|
|
51
77
|
private updateTexture;
|
|
52
78
|
private physVao;
|
|
53
79
|
private physSmallVao;
|
|
@@ -62,6 +88,11 @@ export declare class PhysLayout {
|
|
|
62
88
|
* @param initial - Whether this is the first setting of options.
|
|
63
89
|
*/
|
|
64
90
|
setOptions(options?: ForceDirectedOptions, initial?: boolean): void;
|
|
91
|
+
private applyClusteringOptions;
|
|
92
|
+
private applyCrossClusterMultiplier;
|
|
93
|
+
private applyClusterBy;
|
|
94
|
+
private wakeLayout;
|
|
95
|
+
private coarsenGraph;
|
|
65
96
|
/**
|
|
66
97
|
* Sets graph data to be used
|
|
67
98
|
* @param {{ nodes: Node[]; rels: Relationship[] }} data the graph object
|
|
@@ -70,7 +101,18 @@ export declare class PhysLayout {
|
|
|
70
101
|
setData(data: {
|
|
71
102
|
nodes: Node[];
|
|
72
103
|
rels: Relationship[];
|
|
73
|
-
}):
|
|
104
|
+
}): CoarsenedGraph;
|
|
105
|
+
/**
|
|
106
|
+
* Synchronously runs physics simulation for the configured time budget before
|
|
107
|
+
* the layout is first rendered.
|
|
108
|
+
* Sets `getComputing()` to `true` while running and clears
|
|
109
|
+
* it when precompute finishes (including early exit when the layout halts).
|
|
110
|
+
*/
|
|
111
|
+
private runPrecompute;
|
|
112
|
+
private isPrecomputeEnabled;
|
|
113
|
+
private hasPendingPrecompute;
|
|
114
|
+
private hasInteractingNodes;
|
|
115
|
+
private shouldRunPrecompute;
|
|
74
116
|
/**
|
|
75
117
|
* Updates the node's positions for the next step in the physics layout iterations if the layout needs to update
|
|
76
118
|
* @param refreshPositions whether the entire layout should be reheated
|
|
@@ -81,23 +123,87 @@ export declare class PhysLayout {
|
|
|
81
123
|
* Stops the layout
|
|
82
124
|
*/
|
|
83
125
|
terminateUpdate(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Synchronously reads the latest node positions/velocities from the GPU into
|
|
128
|
+
* this.physPositions.
|
|
129
|
+
*/
|
|
130
|
+
private readbackPositions;
|
|
131
|
+
/**
|
|
132
|
+
* Drives the convergence-readback state machine for the current iteration:
|
|
133
|
+
* consumes a pending fence if one is ready, otherwise starts a new readback
|
|
134
|
+
* when a convergence check is due.
|
|
135
|
+
* @returns Whether fresh velocity data is available.
|
|
136
|
+
*/
|
|
137
|
+
private tryConsumeConvergenceReadback;
|
|
138
|
+
/**
|
|
139
|
+
* The GPU texture holding the latest node positions (xy) and velocities (zw).
|
|
140
|
+
* @returns The RGBA32F position texture.
|
|
141
|
+
*
|
|
142
|
+
* @note Texel layout matches the WebGL renderer's `u_positions` sampler, so it
|
|
143
|
+
* can be bound directly to webgl renderer.
|
|
144
|
+
*/
|
|
145
|
+
getPositionTexture(): WebGLTexture;
|
|
146
|
+
/**
|
|
147
|
+
* Maps node id to its texel index in the position texture.
|
|
148
|
+
* @returns The node-id-to-texel-index map.
|
|
149
|
+
*
|
|
150
|
+
* @note This is the coarsening / solar-hierarchy order (re-derived on add/remove), which
|
|
151
|
+
* differs from the renderer's insertion order. Consumers rendering from {@link getPositionTexture}
|
|
152
|
+
* must build their sampling indices from this.
|
|
153
|
+
*/
|
|
154
|
+
getNodeTexelIndices(): Readonly<Record<Node['id'], number>>;
|
|
155
|
+
/**
|
|
156
|
+
* Multilevel coarsening hierarchy produced by {@link SolarMerger} / {@link ClusterByMerger}.
|
|
157
|
+
* @returns The coarsened graph hierarchy.
|
|
158
|
+
* @see {@link CoarsenedGraph}
|
|
159
|
+
*/
|
|
160
|
+
getSubGraphs(): CoarsenedGraph[];
|
|
161
|
+
private shouldCheckConvergence;
|
|
162
|
+
/** Allocates the pixel-pack buffer used for the async convergence readback. */
|
|
163
|
+
private setupConvergencePbo;
|
|
164
|
+
/**
|
|
165
|
+
* Kicks off an async copy of the position texture into the pixel-pack buffer
|
|
166
|
+
* and fences it. Only issued when no readback is already in flight.
|
|
167
|
+
*/
|
|
168
|
+
private issueConvergenceReadback;
|
|
169
|
+
/**
|
|
170
|
+
* Polls the in-flight fence without blocking; if the readback is ready,
|
|
171
|
+
* copies it into physPositions and clears the fence.
|
|
172
|
+
* @returns Whether fresh velocity data was consumed this call.
|
|
173
|
+
*/
|
|
174
|
+
private consumeConvergenceReadback;
|
|
175
|
+
private restoreCpuWrittenPositions;
|
|
176
|
+
/** Drops any in-flight readback fence (on stop, reset, or destroy). */
|
|
177
|
+
private cancelConvergenceReadback;
|
|
84
178
|
/**
|
|
85
179
|
* Returns whether the current layout needs to be updated in the next iteration step.
|
|
86
180
|
* @returns Whether the layout should update in the following step.
|
|
87
181
|
*/
|
|
88
182
|
getShouldUpdate(): boolean;
|
|
89
183
|
/**
|
|
90
|
-
*
|
|
91
|
-
* Always returns false because the force-directed layout has no computing step
|
|
92
|
-
* @returns Whether the layout is computing.
|
|
184
|
+
* @returns Whether the layout is running the precompute step.
|
|
93
185
|
*/
|
|
94
186
|
getComputing(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Version of the CPU position cache. Advances on GPU readback, CPU-mirror
|
|
189
|
+
* writes, and physics buffer reset.
|
|
190
|
+
* @returns The current cache version.
|
|
191
|
+
*/
|
|
192
|
+
getPositionsCacheVersion(): number;
|
|
95
193
|
/**
|
|
96
194
|
* Adds the current x,y coordinates for each node to a given list of nodes.
|
|
195
|
+
* Forces a synchronous GPU readback when the cache is dirty.
|
|
97
196
|
* @param nodeList - The list of nodes to get positions for.
|
|
98
197
|
* @returns The list of nodes containing the x,y coordinates on each node object.
|
|
99
198
|
*/
|
|
100
199
|
getNodePositions(nodeList: Node[]): (Node & Point)[];
|
|
200
|
+
/**
|
|
201
|
+
* Maps {@link physPositions} onto a node list without forcing a GPU readback.
|
|
202
|
+
* Positions may lag behind the live GPU texture until the next sync/async refresh.
|
|
203
|
+
* @param nodeList - The list of nodes to get positions for.
|
|
204
|
+
* @returns The list of nodes containing the cached x,y coordinates.
|
|
205
|
+
*/
|
|
206
|
+
getCachedNodePositions(nodeList: Node[]): (Node & Point)[];
|
|
101
207
|
/**
|
|
102
208
|
* Reheats the layout
|
|
103
209
|
* @param fullData - The entire graph object.
|
|
@@ -110,7 +216,12 @@ export declare class PhysLayout {
|
|
|
110
216
|
* Updates the existing nodes of a graph with a given list of updates
|
|
111
217
|
* @param nodeList - The list of updates.
|
|
112
218
|
*/
|
|
113
|
-
updateNodes(nodeList:
|
|
219
|
+
updateNodes(nodeList: PartialNode[]): void;
|
|
220
|
+
/**
|
|
221
|
+
* Writes a node position into the current phys position texture and CPU mirror.
|
|
222
|
+
* Caller must bind {@link getPositionTexture} first.
|
|
223
|
+
*/
|
|
224
|
+
private writePhysPosition;
|
|
114
225
|
/**
|
|
115
226
|
* Adds and removes nodes from the graph based on given updates
|
|
116
227
|
* @param fullData - The entire graph object.
|
|
@@ -129,7 +240,7 @@ export declare class PhysLayout {
|
|
|
129
240
|
}, relationshipChanges: {
|
|
130
241
|
adds: Record<string, Relationship>;
|
|
131
242
|
removes: Record<string, Relationship>;
|
|
132
|
-
}):
|
|
243
|
+
}): CoarsenedGraph;
|
|
133
244
|
/**
|
|
134
245
|
* Destroys the class and all buffers and textures.
|
|
135
246
|
*/
|
|
@@ -149,7 +260,6 @@ export declare class PhysLayout {
|
|
|
149
260
|
private checkForUpdates;
|
|
150
261
|
private getNodePosition;
|
|
151
262
|
private getMaxSpeedSquared;
|
|
152
|
-
private getMedianSpeedSquared;
|
|
153
263
|
private getPhysData;
|
|
154
264
|
private newTexture;
|
|
155
265
|
private newFramebuffer;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ClusterByFn, ClusterId } from '../../../../modules/state/types';
|
|
2
|
+
import type { Node, Relationship } from '../../../../types/graph-element';
|
|
3
|
+
import type { CoarsenedGraph } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Default value for {@link ForceDirectedOptions.crossClusterRelationshipMultiplier}.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_CROSS_CLUSTER_RELATIONSHIP_MULTIPLIER = 0;
|
|
8
|
+
/**
|
|
9
|
+
* Builds a two-level Sun/Planet hierarchy from semantic cluster identifiers.
|
|
10
|
+
* Nodes sharing the same cluster id become planets orbiting a new synthetic cluster sun.
|
|
11
|
+
* Nodes without a cluster id remain independent suns.
|
|
12
|
+
*/
|
|
13
|
+
export default class ClusterByMerger {
|
|
14
|
+
subGraphs: CoarsenedGraph[];
|
|
15
|
+
sunMap: Record<string, string>;
|
|
16
|
+
memberMap: Record<string, string[]>;
|
|
17
|
+
relIdMap: string[][];
|
|
18
|
+
clusterAssignments: Map<string, ClusterId | undefined>;
|
|
19
|
+
private nodeSortMap;
|
|
20
|
+
/**
|
|
21
|
+
* Coarsens the input graph into a property-based solar hierarchy.
|
|
22
|
+
* @param inputGraph - The nodes and relationships to coarsen.
|
|
23
|
+
* @param nodeIdToIndex - Maps node ids to contiguous array indices.
|
|
24
|
+
* @param clusterBy - Returns a cluster id for each node, or undefined for independent nodes.
|
|
25
|
+
*/
|
|
26
|
+
constructor(inputGraph: {
|
|
27
|
+
nodes: Node[];
|
|
28
|
+
rels: Relationship[];
|
|
29
|
+
}, nodeIdToIndex: Record<string, number>, clusterBy: ClusterByFn);
|
|
30
|
+
/**
|
|
31
|
+
* Clones the finest adjacency and adds an undirected "star" edge from each cluster member to its
|
|
32
|
+
* Sun, skipping any pair already connected by a real edge.
|
|
33
|
+
* Layout-only: fed to the spring solver, never written back into the real
|
|
34
|
+
* adjacency and never rendered.
|
|
35
|
+
* @param suns - The cluster suns, each with its planets, post-sort.
|
|
36
|
+
* @param finestRelationships - The finest-level real adjacency (sorted index space).
|
|
37
|
+
* @returns A cloned adjacency augmented with intra-cluster star edges.
|
|
38
|
+
*/
|
|
39
|
+
private buildClusterSpringRelationships;
|
|
40
|
+
/**
|
|
41
|
+
* Groups node indices into buckets by cluster id, preserving first-seen order.
|
|
42
|
+
* Nodes without a cluster id each get their own single-node bucket.
|
|
43
|
+
* @param nodes - Input graph nodes indexed by position.
|
|
44
|
+
* @param clusterBy - Returns a cluster id for each node, or undefined for independent nodes.
|
|
45
|
+
* @returns Arrays of node indices, one bucket per cluster or independent node.
|
|
46
|
+
*/
|
|
47
|
+
private groupNodesByCluster;
|
|
48
|
+
/**
|
|
49
|
+
* Converts cluster buckets into a Sun/Planet hierarchy for the first coarsening level.
|
|
50
|
+
* Each bucket with more than one node gets a synthetic Sun and the members become its planets.
|
|
51
|
+
* Single-member buckets keep the real node as Sun.
|
|
52
|
+
* @param buckets - Node index groups produced by {@link groupNodesByCluster}.
|
|
53
|
+
* @param nodes - Input graph nodes indexed by position.
|
|
54
|
+
* @param solarNodes - Solar nodes to extend with synth suns.
|
|
55
|
+
* @param relationships - Adjacency lists to extend with rows for synth suns.
|
|
56
|
+
* @param relIdMap - Relationship id lists to extend with rows for synth suns.
|
|
57
|
+
* @returns Cluster suns, index maps for node-sun and relationship ids and
|
|
58
|
+
* copies of solar nodes / adjacency / rel id lists with synth suns appended.
|
|
59
|
+
*/
|
|
60
|
+
private buildPropertyHierarchy;
|
|
61
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Node, Relationship } from '../../../../types/graph-element';
|
|
2
|
+
import type { CoarsenedGraph, SolarRelationship } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Coarsens a graph into a hierarchy of "solar systems", following the sun/planet/moon partitioning scheme from
|
|
5
|
+
* Hachul and Jünger, "Drawing Large Graphs with a Potential-Field-Based Multilevel Algorithm".
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://kups.ub.uni-koeln.de/1409/ Drawing Large Graphs with a Potential-Field-Based Multilevel Algorithm}
|
|
8
|
+
*/
|
|
9
|
+
export default class SolarMerger {
|
|
10
|
+
graph: {
|
|
11
|
+
nodes: Node[];
|
|
12
|
+
relationships: number[][];
|
|
13
|
+
idToRel: Record<string, SolarRelationship>;
|
|
14
|
+
};
|
|
15
|
+
subGraphs: CoarsenedGraph[];
|
|
16
|
+
sunMap: Record<string, string>;
|
|
17
|
+
memberMap: Record<string, string[]>;
|
|
18
|
+
relIdMap: string[][];
|
|
19
|
+
nodeSortMap?: Record<number, number>;
|
|
20
|
+
constructor(inputGraph: {
|
|
21
|
+
nodes: Node[];
|
|
22
|
+
rels: Relationship[];
|
|
23
|
+
}, nodeIdToIndex: Record<string, number>);
|
|
24
|
+
/**
|
|
25
|
+
* Repeatedly coarsens the graph, one solar-system level at a time, until it has at most `targetSize` nodes or
|
|
26
|
+
* cannot be coarsened further. Each level's result is recorded in {@link SolarMerger.subGraphs}.
|
|
27
|
+
*
|
|
28
|
+
* @param targetSize - The node count to coarsen down to.
|
|
29
|
+
* @returns The coarsest graph reached.
|
|
30
|
+
*/
|
|
31
|
+
coarsenTo(targetSize: number): CoarsenedGraph;
|
|
32
|
+
/**
|
|
33
|
+
* Repeatedly coarsens the graph by exactly `levelToCoarsenBy` solar-system levels, regardless of the resulting
|
|
34
|
+
* node count. Each level's result is recorded in {@link SolarMerger.subGraphs}.
|
|
35
|
+
*
|
|
36
|
+
* @param levelToCoarsenBy - The number of levels to coarsen by.
|
|
37
|
+
* @returns The coarsest graph reached.
|
|
38
|
+
*/
|
|
39
|
+
coarsenBy(levelToCoarsenBy: number): CoarsenedGraph;
|
|
40
|
+
/**
|
|
41
|
+
* Partitions `graph` into one level of solar systems and collapses each into a single node, producing the next
|
|
42
|
+
* coarser graph.
|
|
43
|
+
*
|
|
44
|
+
* Follows the three-step solar-system construction from Hachul and Jünger, "Drawing Large Graphs with a
|
|
45
|
+
* Potential-Field-Based Multilevel Algorithm" (create suns, label their neighbors as planets, assign
|
|
46
|
+
* remaining nodes as moons of their nearest planet).
|
|
47
|
+
*
|
|
48
|
+
* @param graph - The graph to coarsen by one level.
|
|
49
|
+
* @param firstIteration - Whether `graph` is the original, uncoarsened input graph.
|
|
50
|
+
* @returns The collapsed graph (`output`), the input graph with nodes reordered by solar system (`sortedInput`),
|
|
51
|
+
* and a map from the input graph's node ids to their position in `sortedInput` (`nodeSortMap`).
|
|
52
|
+
* @see {@link https://kups.ub.uni-koeln.de/1409/ Drawing Large Graphs with a Potential-Field-Based Multilevel Algorithm}
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
private coarsen;
|
|
56
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Node, Relationship } from '../../../../types/graph-element';
|
|
2
|
+
import type { CoarsenedGraph, PartialPlanet, PartialSun, SolarNode, SolarRelationship, Sun } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the original node ids belonging to a sun and its planets and moons.
|
|
5
|
+
* @param sun - The sun to get the original node ids for.
|
|
6
|
+
* @returns The original node ids belonging to the sun system.
|
|
7
|
+
*
|
|
8
|
+
* @note Synthetic suns are not included in the returned array.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getSunSystemOriginalIds: (sun: Sun) => string[];
|
|
11
|
+
/**
|
|
12
|
+
* How many times a node's degree must exceed the graph's average degree before it is treated as a hub, see
|
|
13
|
+
* {@link isHub}.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Mi et al., "Interactive Graph Layout of a Million Nodes", Sec. 4.3, proposes capping cluster *size* to avoid
|
|
17
|
+
* the outlier clusters this multiplier targets. `HubDegreeMultiplier` targets this problem by checking a node's
|
|
18
|
+
* own degree at claim time, before moon-matching runs.
|
|
19
|
+
* @see {@link https://www.mdpi.com/2227-9709/3/4/23 Interactive Graph Layout of a Million Nodes} Sec. 4.3
|
|
20
|
+
*/
|
|
21
|
+
export declare const HubDegreeMultiplier = 3;
|
|
22
|
+
/**
|
|
23
|
+
* @param relationships - The graph's adjacency list, indexed by node id.
|
|
24
|
+
* @returns The degree a node must exceed to be treated as a hub by {@link isHub}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const getHubDegreeThreshold: (relationships: number[][]) => number;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a node's degree is enough of an outlier that it must become its own sun rather than being absorbed as
|
|
29
|
+
* a planet/moon of another sun.
|
|
30
|
+
*
|
|
31
|
+
* @param index - The node id to check.
|
|
32
|
+
* @param relationships - The graph's adjacency list, indexed by node id.
|
|
33
|
+
* @param hubDegreeThreshold - The threshold from {@link getHubDegreeThreshold}.
|
|
34
|
+
* @see {@link HubDegreeMultiplier}
|
|
35
|
+
*/
|
|
36
|
+
export declare const isHub: (index: number, relationships: number[][], hubDegreeThreshold: number) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Builds adjacency lists and relationship id maps from the input graph.
|
|
39
|
+
* @param inputGraph - The nodes and relationships to convert.
|
|
40
|
+
* @param nodeIdToIndex - Maps node ids to contiguous array indices.
|
|
41
|
+
* @returns Parsed adjacency data for coarsening.
|
|
42
|
+
*/
|
|
43
|
+
export declare const buildAdjacencyGraph: (inputGraph: {
|
|
44
|
+
nodes: Node[];
|
|
45
|
+
rels: Relationship[];
|
|
46
|
+
}, nodeIdToIndex: Record<string, number>) => {
|
|
47
|
+
nodes: Node[];
|
|
48
|
+
relationships: number[][];
|
|
49
|
+
relIdMap: string[][];
|
|
50
|
+
idToRel: Record<string, SolarRelationship>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Wraps input nodes as {@link SolarNode}s indexed by their original position.
|
|
54
|
+
* @param nodes - The input graph nodes.
|
|
55
|
+
* @returns {SolarNode[]} Solar nodes with positional ids and original ids preserved.
|
|
56
|
+
*/
|
|
57
|
+
export declare const createSolarNodesFromInput: (nodes: Node[]) => SolarNode[];
|
|
58
|
+
/**
|
|
59
|
+
* Creates a Planet with an unsettled parent link (caller must attach via {@link attachPlanetsToSun}).
|
|
60
|
+
*/
|
|
61
|
+
export declare const createPlanet: (params: {
|
|
62
|
+
id: number;
|
|
63
|
+
sunId: number;
|
|
64
|
+
weight: number;
|
|
65
|
+
originalId: string;
|
|
66
|
+
finestIndex?: number;
|
|
67
|
+
size?: () => number;
|
|
68
|
+
}) => PartialPlanet;
|
|
69
|
+
/**
|
|
70
|
+
* Finalises a sun's planets list, weight/size/children closures, and back-links parent on each planet.
|
|
71
|
+
* @param partialSun - The sun under construction (planets/size/children/weight not yet set).
|
|
72
|
+
* @param planets - The planets to attach to the sun (parent not yet set).
|
|
73
|
+
* @param centreWeight - The weight of the sun itself, added to the sum of its planets' weights.
|
|
74
|
+
* @param centreSize - The size of the sun itself, added to the sum of its planets' sizes.
|
|
75
|
+
* @returns A new sun object with planets attached. `previousIndex` is a placeholder until
|
|
76
|
+
* {@link sortHierarchyForShaderLayout} assigns the real value.
|
|
77
|
+
*/
|
|
78
|
+
export declare const attachPlanetsToSun: (partialSun: PartialSun, planets: PartialPlanet[], centreWeight: number, centreSize: number) => Sun;
|
|
79
|
+
/**
|
|
80
|
+
* Appends a synthetic sun node to the finest-level arrays for a multi-member clusterBy cluster.
|
|
81
|
+
* Uses a reserved {@link SolarNode.originalId} (`synth-sun:${clusterId}`) so it cannot collide with
|
|
82
|
+
* real node ids; {@link SolarNode.synthetic} marks it for detection.
|
|
83
|
+
* @param params.clusterId - Semantic cluster id embedded in the synth sun's stable originalId.
|
|
84
|
+
* @param params.solarNodesWithSynths - Finest solar nodes; the synth sun is appended here.
|
|
85
|
+
* @param params.relationshipsWithSynths - Finest adjacency lists; an empty row is appended for the synth sun.
|
|
86
|
+
* @param params.relIdMapWithSynths - Finest relationship id lists; an empty row is appended for the synth sun.
|
|
87
|
+
* @returns A sun under construction, ready for {@link attachPlanetsToSun} (separate from the finest SolarNode).
|
|
88
|
+
*/
|
|
89
|
+
export declare const createSynthClusterSun: (params: {
|
|
90
|
+
clusterId: string | number;
|
|
91
|
+
solarNodesWithSynths: SolarNode[];
|
|
92
|
+
relationshipsWithSynths: number[][];
|
|
93
|
+
relIdMapWithSynths: string[][];
|
|
94
|
+
}) => PartialSun;
|
|
95
|
+
/**
|
|
96
|
+
* Rolls node-level adjacency up to sun-level adjacency between clusters.
|
|
97
|
+
* When `weakLinkSunIds` is provided, edges where either endpoint is a Sun are skipped.
|
|
98
|
+
* @param relationships - Node adjacency lists indexed by node position.
|
|
99
|
+
* @param nodeIndexToSunIndex - Maps each node index to its sun index.
|
|
100
|
+
* @param sunCount - Number of suns in the coarse graph.
|
|
101
|
+
* @param weakLinkSunIds - Optional set of node indices that are Suns. When set, Sun-leaf and Sun-Sun edges are ignored.
|
|
102
|
+
* @returns {number[][]} Sun-level adjacency lists without duplicate edges.
|
|
103
|
+
*/
|
|
104
|
+
export declare const rollupInterSunRelationships: (relationships: number[][], nodeIndexToSunIndex: Record<number, number>, sunCount: number, weakLinkSunIds?: Set<number>) => number[][];
|
|
105
|
+
/**
|
|
106
|
+
* Remaps adjacency lists to a sorted node order.
|
|
107
|
+
* @param relationships - Node adjacency lists in the pre-sort index order.
|
|
108
|
+
* @param nodeSortMap - Maps old node indices to sorted indices.
|
|
109
|
+
* @param relIdMap - Relationship ids aligned with adjacency lists.
|
|
110
|
+
* @param remapRelIds - Whether relationship ids should be remapped as well.
|
|
111
|
+
* @returns {{ relationships: number[][]; relIdMap: string[][] }} Remapped adjacency data.
|
|
112
|
+
*/
|
|
113
|
+
export declare const remapAdjacencyWithSortMap: (relationships: number[][], nodeSortMap: Record<number, number>, relIdMap: string[][], remapRelIds?: boolean) => {
|
|
114
|
+
relationships: number[][];
|
|
115
|
+
relIdMap: string[][];
|
|
116
|
+
};
|
|
117
|
+
/** Input nodes that may receive a layout `finestIndex` during sorting (plain Node on first pass). */
|
|
118
|
+
type SourceNode = (Node | SolarNode) & {
|
|
119
|
+
finestIndex?: number;
|
|
120
|
+
};
|
|
121
|
+
export type SortHierarchyOptions = {
|
|
122
|
+
suns: Sun[];
|
|
123
|
+
solarNodes: SolarNode[];
|
|
124
|
+
sourceNodes?: SourceNode[];
|
|
125
|
+
relationships: number[][];
|
|
126
|
+
relIdMap: string[][];
|
|
127
|
+
idToRel: Record<string, SolarRelationship>;
|
|
128
|
+
firstIteration?: boolean;
|
|
129
|
+
includeMoons?: boolean;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Sorts suns, planets, and optionally moons into shader layout order and builds the finest subgraph.
|
|
133
|
+
* @param options - Hierarchy members and adjacency data to sort.
|
|
134
|
+
* @returns The finest subgraph, sort map, member-sun maps, and remapped relationship ids.
|
|
135
|
+
*/
|
|
136
|
+
export declare const sortHierarchyForShaderLayout: ({ suns, solarNodes, sourceNodes, relationships, relIdMap, idToRel, firstIteration, includeMoons }: SortHierarchyOptions) => {
|
|
137
|
+
sortedInput: CoarsenedGraph;
|
|
138
|
+
nodeSortMap: Record<number, number>;
|
|
139
|
+
sunMap: Record<string, string>;
|
|
140
|
+
memberMap: Record<string, string[]>;
|
|
141
|
+
relIdMap: string[][];
|
|
142
|
+
};
|
|
143
|
+
export {};
|
package/dist/types/layouts/forcedirectedlayout/physlayout/clustering/clustering-utils.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/layouts/forcedirectedlayout/physlayout/{solarmerger → clustering}/types.d.ts
RENAMED
|
@@ -13,6 +13,7 @@ export interface SolarNode extends Omit<Node, 'id' | 'size'> {
|
|
|
13
13
|
y: number;
|
|
14
14
|
};
|
|
15
15
|
size?: number | (() => number);
|
|
16
|
+
synthetic?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export interface SolarRelationship {
|
|
18
19
|
id: string;
|
|
@@ -23,6 +24,11 @@ export interface CoarsenedGraph {
|
|
|
23
24
|
nodes: SolarNode[];
|
|
24
25
|
relationships: number[][];
|
|
25
26
|
idToRel: Record<string, SolarRelationship>;
|
|
27
|
+
/**
|
|
28
|
+
* Contains the "real" {@link relationships} plus any synthetic edges purely for layout purposes.
|
|
29
|
+
* Undefined when there are no synthetic edges (e.g. SolarMerger).
|
|
30
|
+
*/
|
|
31
|
+
springRelationships?: number[][];
|
|
26
32
|
}
|
|
27
33
|
export interface Sun extends SolarNode {
|
|
28
34
|
planets: Planet[];
|
|
@@ -30,6 +36,8 @@ export interface Sun extends SolarNode {
|
|
|
30
36
|
children: () => Planet[];
|
|
31
37
|
previousIndex: number;
|
|
32
38
|
}
|
|
39
|
+
/** Sun fields known before {@link attachPlanetsToSun} fills planets/size/children/weight. */
|
|
40
|
+
export type PartialSun = Omit<Sun, 'planets' | 'size' | 'children' | 'previousIndex' | 'weight'>;
|
|
33
41
|
export interface Planet extends SolarNode {
|
|
34
42
|
parent: Sun;
|
|
35
43
|
sunId: number;
|
|
@@ -37,6 +45,8 @@ export interface Planet extends SolarNode {
|
|
|
37
45
|
size: () => number;
|
|
38
46
|
children: () => Moon[];
|
|
39
47
|
}
|
|
48
|
+
/** Planet fields known before {@link attachPlanetsToSun} sets parent. */
|
|
49
|
+
export type PartialPlanet = Omit<Planet, 'parent'>;
|
|
40
50
|
export interface Moon extends SolarNode {
|
|
41
51
|
parent: Planet;
|
|
42
52
|
sunId: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_physData;\nuniform sampler2D u_connections;\nuniform sampler2D u_connectionOffsets;\nuniform sampler2D u_pinnedNodes;\nuniform sampler2D u_sizeTexture;\nuniform float u_baseLength;\nuniform float u_curIteration;\nuniform float u_iterationMultiplier;\nuniform vec2 u_gravityCenter;\nuniform float u_numNodes;\nuniform float u_gravity;\n\nuniform sampler2D u_clusterData;\nuniform sampler2D u_prevForce;\nuniform float u_collisionMultiplier;\n\nout vec4 fragColor;\n\nfloat DAMP = 0.6;\nfloat COOL = 0.99998;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 0.6;\nfloat accLimitLow = 500000.0;\nfloat accLimitHigh = 750000.0;\nfloat accLimitPosHigh = 10000000.0;\n\nconst float denseNodeThreshold = 1000.0;\nconst float MIN_DISTANCE = 0.00000001;\nconst float MAX_DISTANCE = 1000000000.0;\nconst float MAX_ACCELERATION = 50000.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nbool isNan(float val) {\n return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n}\n\nconst float BIG_NUMBER = 999999999999999999.0;\nbool isInf(float val) {\n return val > BIG_NUMBER || val < -BIG_NUMBER;\n}\n\nvec2 getDelta(vec2 v1, vec2 v2) {\n vec2 delta = v1 - v2;\n float dist = length(delta);\n if (dist < MIN_DISTANCE || isNan(dist)) {\n return vec2(MIN_DISTANCE, MIN_DISTANCE);\n }\n if (dist > MAX_DISTANCE) {\n vec2 normDelta = delta / dist;\n return normDelta * MAX_DISTANCE;\n }\n return delta;\n}\n\nvec4 getOtherNodePosition(float i) {\n return getTextureData(u_physData, i, 256.0);\n}\n\nfloat getCombinedNodeSize(float i, float nodeSize) {\n float otherNodeSize = getTextureData(u_sizeTexture, i, 256.0).r;\n return nodeSize + otherNodeSize;\n}\n\nvec2 getSpringForce(float curConnection, float numConnections, float springFScale, vec4 myPosition, float i) {\n float curSpring = getTextureData(u_connections, curConnection + i, 4096.0).r;\n\n vec4 otherPosition = getTextureData(u_physData, curSpring, 256.0);\n float otherDataPosition = getTextureData(u_connectionOffsets, curSpring, 256.0).r;\n float otherNumConnections = getTextureData(u_connections, otherDataPosition, 4096.0).r;\n float avgDegree = max((otherNumConnections + numConnections * 3.0) / 4.0, 4.0);\n\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n\n float F = (dist * dist * springFScale) / (u_baseLength * avgDegree);\n if (
|
|
1
|
+
declare const _default: "#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_physData;\nuniform sampler2D u_connections;\nuniform sampler2D u_connectionOffsets;\nuniform sampler2D u_pinnedNodes;\nuniform sampler2D u_sizeTexture;\nuniform float u_baseLength;\nuniform float u_curIteration;\nuniform float u_iterationMultiplier;\nuniform vec2 u_gravityCenter;\nuniform float u_numNodes;\nuniform float u_gravity;\n\nuniform sampler2D u_clusterData;\nuniform sampler2D u_prevForce;\nuniform float u_collisionMultiplier;\nuniform float u_maxNodeSize;\nuniform float u_crossClusterRelationshipMultiplier;\n\nout vec4 fragColor;\n\nfloat DAMP = 0.6;\nfloat COOL = 0.99998;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 0.6;\nfloat accLimitLow = 500000.0;\nfloat accLimitHigh = 750000.0;\nfloat accLimitPosHigh = 10000000.0;\n\nconst float denseNodeThreshold = 1000.0;\nconst float MIN_DISTANCE = 0.00000001;\nconst float MAX_DISTANCE = 1000000000.0;\nconst float MAX_ACCELERATION = 50000.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nbool isNan(float val) {\n return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n}\n\nconst float BIG_NUMBER = 999999999999999999.0;\nbool isInf(float val) {\n return val > BIG_NUMBER || val < -BIG_NUMBER;\n}\n\nvec2 getDelta(vec2 v1, vec2 v2) {\n vec2 delta = v1 - v2;\n float dist = length(delta);\n if (dist < MIN_DISTANCE || isNan(dist)) {\n return vec2(MIN_DISTANCE, MIN_DISTANCE);\n }\n if (dist > MAX_DISTANCE) {\n vec2 normDelta = delta / dist;\n return normDelta * MAX_DISTANCE;\n }\n return delta;\n}\n\nvec4 getOtherNodePosition(float i) {\n return getTextureData(u_physData, i, 256.0);\n}\n\nfloat getCombinedNodeSize(float i, float nodeSize) {\n float otherNodeSize = getTextureData(u_sizeTexture, i, 256.0).r;\n return nodeSize + otherNodeSize;\n}\n\nvec2 getSpringForce(float curConnection, float numConnections, float springFScale, vec4 myPosition, float i, float myClusterStartIndex) {\n float curSpring = getTextureData(u_connections, curConnection + i, 4096.0).r;\n\n vec4 otherPosition = getTextureData(u_physData, curSpring, 256.0);\n float otherDataPosition = getTextureData(u_connectionOffsets, curSpring, 256.0).r;\n float otherNumConnections = getTextureData(u_connections, otherDataPosition, 4096.0).r;\n float avgDegree = max((otherNumConnections + numConnections * 3.0) / 4.0, 4.0);\n\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n\n float F = (dist * dist * springFScale) / (u_baseLength * avgDegree) * u_collisionMultiplier;\n\n // u_crossClusterRelationshipMultiplier only damps edges that cross a cluster boundary\n if (u_crossClusterRelationshipMultiplier < 1.0) {\n float otherClusterStartIndex = getTextureData(u_clusterData, curSpring, 256.0).y;\n F *= otherClusterStartIndex == myClusterStartIndex ? 1.0 : u_crossClusterRelationshipMultiplier;\n }\n\n return (-delta / dist) * F;\n}\n\nvec2 getCollisionForce(float combinedNodeSize, float dist, float fScale, vec2 delta) {\n float collisionForce = (combinedNodeSize - dist) / (dist) * u_collisionMultiplier;\n return (delta * collisionForce * fScale * combinedNodeSize) / (combinedNodeSize + 1.0);\n}\n\nvec2 getRepulsionForce(float dist, float fScale, vec2 delta) {\n float F = (u_baseLength * u_baseLength * fScale) / (dist) * u_collisionMultiplier;\n return (delta / dist) * F * 0.05;\n}\n\nvoid main(void) {\n float textureSide = 256.0; //#TEXTURE_SIDE#;\n float index = (gl_FragCoord.x - 0.5) + (gl_FragCoord.y - 0.5) * textureSide;\n\n if (index >= u_numNodes) {\n discard;\n }\n\n vec4 clusterData = getTextureData(u_clusterData, index, 256.0);\n\n float clusterIndex = clusterData.x;\n float clusterStartIndex = clusterData.y;\n float clusterSize = clusterData.z;\n\n vec4 myPosition = getTextureData(u_physData, index, 256.0);\n vec4 previousForce = getTextureData(u_prevForce, clusterIndex, 256.0);\n\n vec2 acceleration = previousForce.xy;\n\n float isPinned = getTextureData(u_pinnedNodes, index, 256.0).r;\n float nodeSize = getTextureData(u_sizeTexture, index, 256.0).r;\n\n if (isPinned > 0.5) {\n fragColor = vec4(myPosition.xy, 0.0, 0.0);\n return;\n }\n\n // Prime the second ping-pong texture with the initial state without calculating forces\n // that would otherwise be discarded at the end of this first iteration.\n if (u_curIteration == 0.0) {\n fragColor = vec4(myPosition.xy, myPosition.zw);\n return;\n }\n\n float curConnection = getTextureData(u_connectionOffsets, index, 256.0).r;\n float numConnections = getTextureData(u_connections, curConnection, 4096.0).r;\n\n float fScale = 1.0 + sqrt(u_iterationMultiplier);\n float springFScale = fScale;\n\n if (numConnections > denseNodeThreshold) {\n springFScale = sqrt(fScale);\n }\n\n float numOfRels = 0.0;\n\n // Springs\n for (float i = 1.0; i <= 256.0 * 256.0; i++) {\n if (numOfRels >= numConnections) {\n break;\n }\n acceleration += getSpringForce(curConnection, numConnections, springFScale, myPosition, i, clusterStartIndex);\n numOfRels += 1.0;\n }\n\n // Repulsion && collision detection.\n if (u_collisionMultiplier > 0.0) {\n float number_of_collisions = 0.0;\n for (float i = 0.0; i < 256.0 * 256.0; i++) {\n if (i >= u_numNodes) {\n break;\n }\n\n if (i == index) {\n continue;\n }\n\n vec4 otherPosition = getOtherNodePosition(i);\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n\n if (number_of_collisions < 40.0 && dist < (nodeSize + u_maxNodeSize) * 2.0) {\n float combinedNodeSize = getCombinedNodeSize(i, nodeSize) * 2.0;\n if (dist < combinedNodeSize) {\n number_of_collisions++;\n acceleration += getCollisionForce(combinedNodeSize, dist, fScale, delta);\n }\n }\n\n if (i >= clusterStartIndex && i < clusterStartIndex + clusterSize) {\n acceleration += getRepulsionForce(dist, fScale, delta);\n }\n }\n }\n\n // Gravity\n vec2 delta = getDelta(u_gravityCenter, myPosition.xy);\n float dist = length(delta);\n\n vec2 grav = (delta / dist) * u_gravity * fScale * (dist / 1000.0);\n acceleration += grav;\n\n float accMagnitude = length(acceleration);\n acceleration *= min(MAX_ACCELERATION, accMagnitude) / accMagnitude;\n\n float iterationFrictionThreshold = 1000.0;\n\n if (u_curIteration > iterationFrictionThreshold) {\n float friction = 1.0 + pow((u_curIteration - iterationFrictionThreshold), 2.0) / 100.0;\n acceleration *= 1.0 / friction;\n }\n\n float TEMP = max(0.02, pow(COOL, u_curIteration));\n vec2 prevVelocity = myPosition.zw;\n vec2 currentPos = myPosition.xy;\n\n vec2 newPos = currentPos + TEMP * ( DAMP * (prevVelocity) + acceleration * TIMESTEP * TIMESTEP);\n vec2 newVelocity = newPos - currentPos;\n fragColor = vec4(newPos, newVelocity);\n}";
|
|
2
2
|
export default _default;
|
package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "#version 300 es\nprecision mediump float;\nuniform sampler2D u_physData;\nuniform sampler2D u_clusterData;\nuniform sampler2D u_finestIndexes;\nuniform sampler2D u_prevForce;\n\nuniform float u_baseLength;\nuniform float u_numNodes;\nuniform float u_iterationMultiplier;\nuniform float u_isTopLevel;\n\nout vec4 fragColor;\n\nfloat PI = 3.1415926535897932384626433832795;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 1.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nfloat
|
|
1
|
+
declare const _default: "#version 300 es\nprecision mediump float;\nuniform sampler2D u_physData;\nuniform sampler2D u_clusterData;\nuniform sampler2D u_finestIndexes;\nuniform sampler2D u_prevForce;\n\nuniform float u_baseLength;\nuniform float u_numNodes;\nuniform float u_iterationMultiplier;\nuniform float u_isTopLevel;\n\nout vec4 fragColor;\n\nfloat PI = 3.1415926535897932384626433832795;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 1.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nfloat getAdjustedClusterWeight(float clusterWeight) {\n return (clusterWeight * clusterWeight) / (clusterWeight + 1.0);\n}\n\n// Repulsion area from peer mass (weight). .z size is only for mid-level loop bounds.\nfloat getPeerFootprintArea(float peerWeight) {\n return pow(sqrt(peerWeight) * 4.0 + u_baseLength * 2.0, 2.0);\n}\n\nvoid main(void) {\n float index = (gl_FragCoord.x - 0.5) + (gl_FragCoord.y - 0.5) * 256.0;\n\n if (index >= u_numNodes) {\n discard;\n }\n\n vec4 clusterData = getTextureData(u_clusterData, index, 256.0);\n bool isTopLevel = u_isTopLevel == 1.0;\n\n float clusterIndex = clusterData.x;\n float clusterStartIndex = clusterData.y;\n float clusterSize = clusterData.z;\n float singleNodeRepulsionScale = isTopLevel && clusterSize == 1.0 ? 0.5 : 1.0;\n\n float finestIndex = getTextureData(u_finestIndexes, index, 256.0).r;\n vec4 myPosition = getTextureData(u_physData, finestIndex, 256.0);\n vec4 previousForce = getTextureData(u_prevForce, clusterIndex, 256.0);\n float fScale = 1.0 + sqrt(u_iterationMultiplier);\n\n vec2 acceleration = previousForce.xy;\n\n float loopEnd = isTopLevel ? u_numNodes : (clusterStartIndex + clusterSize);\n\n // Repulsion & Collision Detection\n for (float i = 0.0; i < 256.0 * 256.0; i++) {\n if (i >= loopEnd || i >= u_numNodes) {\n break;\n }\n if ((!isTopLevel && i < clusterStartIndex) || i == index) {\n continue;\n }\n\n vec4 otherClusterData = getTextureData(u_clusterData, i, 256.0);\n float otherClusterWeight = getAdjustedClusterWeight(otherClusterData.w);\n\n float otherFinestIndex = getTextureData(u_finestIndexes, i, 256.0).r;\n vec4 otherPosition = getTextureData(u_physData, otherFinestIndex, 256.0);\n\n vec2 delta = myPosition.xy - otherPosition.xy;\n float dist = max(length(delta), 0.0000001);\n float maxDist = 25.0;\n float repulsionForceScale = 0.1;\n\n float area = getPeerFootprintArea(otherClusterData.w);\n float F = (area * fScale) / (dist * dist);\n\n if (isTopLevel) {\n repulsionForceScale = 0.2;\n }\n\n acceleration += ((delta / sqrt(dist)) * F) * repulsionForceScale * otherClusterWeight * singleNodeRepulsionScale;\n\n if (dist < maxDist) {\n float collide = (maxDist - dist) / (dist * dist);\n acceleration += delta * collide * fScale * maxDist / (maxDist + 1.0);\n }\n }\n\n fragColor = vec4(acceleration, vec2(finestIndex, 0));\n}";
|
|
2
2
|
export default _default;
|