egraph 6.0.0-alpha.2 → 6.0.0-alpha.5

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 CHANGED
@@ -1,161 +1,163 @@
1
1
  # egraph
2
2
 
3
- egraph is a fast graph drawing library implemented in Rust and WebAssembly.
3
+ Fast, strictly single-threaded graph drawing and layout library implemented in pure Rust and WebAssembly (`wasm-bindgen`), distributed as a pure ESM package sharing a single `.wasm` binary across browsers, bundlers, and Node.js 18+.
4
4
 
5
5
  ## Install
6
6
 
7
- ```shell-session
8
- $ npm install egraph
7
+ ```bash
8
+ npm install egraph
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Architecture Highlights (v6)
12
+
13
+ - **Pure ESM & Single `.wasm`**: Modern `"exports"` entrypoints for browsers/bundlers (`./pkg/index.js`) and Node.js 18+ (`./pkg/egraph_wasm.node.js`), sharing a single `wasm-opt -Oz` optimized `.wasm` binary.
14
+ - **Strictly Single-Threaded**: Pure CPU Rust with deterministic seeded execution (`seed = 42` default), zero `rayon`, zero `std::thread`, zero Web Workers, and zero `SharedArrayBuffer`.
15
+ - **Zero-Copy Linear Memory Views**: `Layout2d.coordsView()` returns a cached `Float32Array` view directly over WebAssembly linear memory and automatically refreshes when `memory.grow` detaches the underlying `ArrayBuffer`.
16
+ - **Cooperative `requestAnimationFrame` Execution**: All iterative solvers implement `step()`, `runSteps(layout, k)`, and `run(layout)`, plus `runProgressive(solver, layout, onFrame, options?)` for responsive 60fps browser rendering.
17
+
18
+ ## Quick Start (Browser / Bundler ESM)
19
+
20
+ ```js
21
+ import init, {
22
+ CsrGraph,
23
+ Layout2d,
24
+ TsNetSolver,
25
+ evaluateMetrics,
26
+ pivotMdsInit,
27
+ runProgressive,
28
+ } from "egraph";
29
+
30
+ await init();
31
+
32
+ // Build an undirected CSR graph (0 - 1 - 2 - 3 - 0)
33
+ const indptr = new Uint32Array([0, 2, 4, 6, 8]);
34
+ const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
35
+ const graph = CsrGraph.fromCsr(indptr, indices);
36
+
37
+ // Initialize with normalized PivotMDS (f32 Layout2d)
38
+ const layout = pivotMdsInit(graph, 4, 42);
39
+
40
+ // Run Track A Pure 1+2-Hop Adaptive tsNET progressively in requestAnimationFrame
41
+ const solver = TsNetSolver.pure2Hop(graph, {
42
+ backend: "fft",
43
+ seed: 42,
44
+ });
45
+
46
+ await runProgressive(
47
+ solver,
48
+ layout,
49
+ ({ iteration, totalIterations }) => {
50
+ const xy = layout.coordsView(); // Zero-copy Float32Array [x0, y0, x1, y1, ...]
51
+ console.log(`frame ${iteration}/${totalIterations}, node0=(${xy[0]}, ${xy[1]})`);
52
+ },
53
+ { frameBudgetMs: 10 },
54
+ );
55
+
56
+ // Selectively evaluate quality metrics
57
+ const report = evaluateMetrics(graph, layout, ["sns", "np2", "crossingNumber"]);
58
+ console.log(report.toRecord());
59
+ ```
12
60
 
13
- ```javascript
14
- import { Graph } from 'egraph'
15
- import {
16
- Simulation,
17
- ManyBodyForce,
18
- LinkForce,
19
- CenterForce
20
- } from 'egraph/layout/force-directed'
21
-
22
- // creating a graph
23
- const graph = new Graph()
24
-
25
- // adding vertices
26
- graph.addNode(0)
27
- graph.addNode(1)
28
- graph.addNode(2)
29
-
30
- // adding edges
31
- graph.addEdge(0, 1)
32
- graph.addEdge(0, 2)
33
- graph.addEdge(1, 2)
34
-
35
- // creating forces
36
- const manyBodyForce = new ManyBodyForce()
37
- const linkForce = new LinkForce()
38
- const centerForce = new CenterForce()
39
-
40
- // creating simulation
41
- const simulation = new Simulation()
42
- simulation.add(manyBodyForce)
43
- simulation.add(linkForce)
44
- simulation.add(centerForce)
45
-
46
- // position calculation
47
- const layout = simulation.start(graph)
48
-
49
- // printing result
50
- for (const u of graph.nodes()) {
51
- console.log(layout.nodes[u])
52
- }
61
+ ## Node.js 18+ ESM
62
+
63
+ The same `"egraph"` import automatically resolves to the Node ESM loader via `"exports"`:
64
+
65
+ ```js
66
+ import init, { CsrGraph, TFdpSolver, pivotMdsInit } from "egraph";
67
+
68
+ await init();
69
+
70
+ const graph = CsrGraph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
71
+ const layout = pivotMdsInit(graph, 4, 42);
72
+ const solver = new TFdpSolver(graph, { backend: "ibfft", totalIterations: 200, seed: 42 });
73
+ solver.run(layout);
74
+
75
+ const xy = layout.coordsView();
76
+ console.log(Array.from(xy));
53
77
  ```
54
78
 
55
- egraph-wasm is implemented using wasm-bindgen.
56
- For more detailed usage, please read [wasm-bindgen document](https://rustwasm.github.io/wasm-bindgen/).
79
+ ## Solver Examples
57
80
 
58
- ## Examples
81
+ ### Track A: `TsNetSolver.pure2Hop`
59
82
 
60
- ### Drawing SVG with React.js
83
+ ```js
84
+ const solver = TsNetSolver.pure2Hop(graph, {
85
+ backend: "fft",
86
+ perplexityC: 0.9,
87
+ seed: 42,
88
+ });
89
+ solver.run(layout);
90
+ ```
61
91
 
62
- ```javascript
63
- import React from 'react'
64
- import { render } from 'react-dom'
65
- import { Graph } from 'egraph'
92
+ ### Track B & Unified Force Models: `TFdpSolver`, `ForceAtlas2Solver`, `GuMapSolver`
93
+
94
+ ```js
66
95
  import {
67
- Simulation,
68
- ManyBodyForce,
69
- LinkForce,
70
- CenterForce
71
- } from 'egraph/layout/force-directed'
72
-
73
- const graph = new Graph()
74
- graph.addNode(0)
75
- graph.addNode(1)
76
- graph.addNode(2)
77
- graph.addEdge(0, 1)
78
- graph.addEdge(0, 2)
79
- graph.addEdge(1, 2)
80
-
81
- const manyBodyForce = new ManyBodyForce()
82
- const linkForce = new LinkForce()
83
- linkForce.distance = () => 200
84
- const centerForce = new CenterForce()
85
-
86
- const simulation = new Simulation()
87
- simulation.add(manyBodyForce)
88
- simulation.add(linkForce)
89
- simulation.add(centerForce)
90
-
91
- const layout = simulation.start(graph)
92
-
93
- const width = 600
94
- const height = 400
95
- render(
96
- <div>
97
- <svg width={width} height={height}>
98
- <g transform={`translate(${width / 2},${height / 2})`}>
99
- <g>
100
- {Array.from(graph.edges()).map(([u, v]) => {
101
- const { x: x0, y: y0 } = positions[u]
102
- const { x: x1, y: y1 } = positions[v]
103
- return (
104
- <g key={e}>
105
- <path d={`M ${x0} ${y0} L ${x1} ${y1}`} stroke='#000' />
106
- </g>
107
- )
108
- })}
109
- </g>
110
- <g>
111
- {Array.from(graph.nodes()).map((u) => {
112
- const { x, y } = positions[u]
113
- return (
114
- <g key={i} transform={`translate(${x},${y})`}>
115
- <circle r='10' fill='#000' />
116
- </g>
117
- )
118
- })}
119
- </g>
120
- </g>
121
- </svg>
122
- </div>,
123
- document.querySelector('#display')
124
- )
96
+ ForceAtlas2Solver,
97
+ GuMapSolver,
98
+ SgdSolver,
99
+ TFdpSolver,
100
+ } from "egraph";
101
+
102
+ // t-FDP with ibFFT repulsion
103
+ const tfdp = new TFdpSolver(graph, {
104
+ backend: "ibfft",
105
+ totalIterations: 200,
106
+ seed: 42,
107
+ });
108
+ tfdp.run(layout);
109
+
110
+ // ForceAtlas2 (Barnes-Hut)
111
+ const fa2 = new ForceAtlas2Solver(graph, {
112
+ iterations: 200,
113
+ useBarnesHut: true,
114
+ theta: 0.5,
115
+ seed: 42,
116
+ });
117
+ fa2.run(layout);
118
+
119
+ // GuMap from regularized Chebyshev DoG landmarks
120
+ const gumap = GuMapSolver.fromGraphDog(graph, {
121
+ nEpochs: 200,
122
+ minDist: 0.1,
123
+ spread: 1.0,
124
+ seed: 42,
125
+ });
126
+ gumap.run(layout);
127
+
128
+ // Regularized DoG 3-tier Sparse Barrier SGD
129
+ const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
130
+ barrierSgd.run(layout);
125
131
  ```
126
132
 
127
- ### Loading JSON
133
+ ### Overlap Removal (`PrismOverlapRemoval`)
128
134
 
129
- ```javascript
130
- import { Graph } from 'egraph'
131
- import {
132
- Simulation,
133
- ManyBodyForce,
134
- LinkForce,
135
- CenterForce
136
- } from 'egraph/layout/force-directed'
137
- ;(async () => {
138
- const request = await fetch('miserables.json')
139
- const data = await request.json()
140
-
141
- const { Graph } = mod
142
- const graph = new Graph()
143
- for (const node of data.nodes) {
144
- graph.addNode(node.id, node)
145
- }
146
- for (const link of data.links) {
147
- graph.addEdge(link.source, link.target, link)
148
- }
149
-
150
- for (const u of graph.nodes()) {
151
- console.log(graph.node(u))
152
- }
153
- for (const [u, v] of graph.edges()) {
154
- console.log(graph.edge(u, v))
155
- }
156
- })()
135
+ ```js
136
+ import { PrismOverlapRemoval, prismDistortion } from "egraph";
137
+
138
+ const original = Layout2d.fromCoords(layout.coordsView());
139
+ const radii = new Float32Array(graph.numNodes()).fill(0.25);
140
+ const prism = PrismOverlapRemoval.fromRadii(radii, {
141
+ maxIterations: 50,
142
+ padding: 0.05,
143
+ seed: 42,
144
+ });
145
+ prism.run(layout);
146
+
147
+ const distortion = prismDistortion(original, layout);
148
+ console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
157
149
  ```
158
150
 
151
+ ## Migration from v5 / Legacy Alpha
152
+
153
+ See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5/legacy-alpha to v6 migration guide, including:
154
+
155
+ 1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` and host-side arrays
156
+ 2. Migrating `OverwrapRemoval` to `PrismOverlapRemoval`
157
+ 3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver.pure2Hop`
158
+ 4. Replacing `stress` (`NS`) with Scale-Normalized Stress (`scaleNormalizedStress` / `evaluateMetrics`)
159
+ 5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, and `runProgressive`
160
+
159
161
  ## License
160
162
 
161
163
  MIT
package/package.json CHANGED
@@ -1,40 +1,56 @@
1
1
  {
2
2
  "name": "egraph",
3
+ "version": "6.0.0-alpha.5",
3
4
  "collaborators": [
4
5
  "Yosuke Onoue <onoue@likr-lab.com>"
5
6
  ],
6
- "description": "WebAssembly binding of egraph.",
7
- "version": "6.0.0-alpha.2",
7
+ "description": "Fast single-threaded graph drawing and layout library in Rust and WebAssembly.",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/likr/egraph-rs/tree/master/crates/wasm"
11
+ "url": "git+https://github.com/likr/egraph-rs.git",
12
+ "directory": "crates/wasm"
12
13
  },
14
+ "type": "module",
15
+ "sideEffects": false,
13
16
  "files": [
14
- "dist/bundler/egraph_wasm_bg.wasm",
15
- "dist/bundler/egraph_wasm.js",
16
- "dist/bundler/egraph_wasm.d.ts",
17
- "dist/no-modules/egraph_wasm_bg.wasm",
18
- "dist/no-modules/egraph_wasm.js",
19
- "dist/no-modules/egraph_wasm.d.ts",
20
- "dist/nodejs/egraph_wasm_bg.wasm",
21
- "dist/nodejs/egraph_wasm.js",
22
- "dist/nodejs/egraph_wasm.d.ts",
23
- "dist/web/egraph_wasm_bg.wasm",
24
- "dist/web/egraph_wasm.js",
25
- "dist/web/egraph_wasm.d.ts",
26
- "umd"
17
+ "pkg/index.js",
18
+ "pkg/index.d.ts",
19
+ "pkg/egraph_wasm.js",
20
+ "pkg/egraph_wasm.d.ts",
21
+ "pkg/egraph_wasm.node.js",
22
+ "pkg/egraph_wasm_bg.wasm",
23
+ "README.md",
24
+ "LICENSE"
27
25
  ],
28
- "main": "dist/nodejs/egraph_wasm.js",
29
- "module": "dist/bundler/egraph_wasm.js",
30
- "unpkg": "umd/egraph.js",
31
- "types": "dist/bundler/egraph_wasm.d.ts",
32
- "sideEffects": "false",
33
- "devDependencies": {
34
- "rollup": "^2.52.2"
26
+ "main": "./pkg/egraph_wasm.node.js",
27
+ "types": "./pkg/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "node": {
31
+ "types": "./pkg/index.d.ts",
32
+ "default": "./pkg/egraph_wasm.node.js"
33
+ },
34
+ "browser": {
35
+ "types": "./pkg/index.d.ts",
36
+ "default": "./pkg/index.js"
37
+ },
38
+ "default": {
39
+ "types": "./pkg/index.d.ts",
40
+ "default": "./pkg/index.js"
41
+ }
42
+ },
43
+ "./egraph_wasm_bg.wasm": "./pkg/egraph_wasm_bg.wasm"
35
44
  },
36
45
  "scripts": {
37
- "build-umd": "rollup -c && cp dist/web/egraph_wasm_bg.wasm umd/egraph_bg.wasm",
38
- "prepublish": "npm run build-umd"
46
+ "build": "wasm-pack build --no-opt --target web --profile wasm-release -d pkg . && node scripts/assemble_pkg.mjs && wasm-opt -Oz --enable-bulk-memory --enable-nontrapping-float-to-int pkg/egraph_wasm_bg.wasm -o pkg/egraph_wasm_bg.wasm",
47
+ "docs": "typedoc",
48
+ "test:smoke": "node tests/node_esm_smoke.mjs"
49
+ },
50
+ "devDependencies": {
51
+ "typedoc": "^0.28.20"
52
+ },
53
+ "engines": {
54
+ "node": ">=18.0.0"
39
55
  }
40
56
  }
package/pkg/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # egraph
2
+
3
+ Fast, strictly single-threaded graph drawing and layout library implemented in pure Rust and WebAssembly (`wasm-bindgen`), distributed as a pure ESM package sharing a single `.wasm` binary across browsers, bundlers, and Node.js 18+.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install egraph
9
+ ```
10
+
11
+ ## Architecture Highlights (v6)
12
+
13
+ - **Pure ESM & Single `.wasm`**: Modern `"exports"` entrypoints for browsers/bundlers (`./pkg/index.js`) and Node.js 18+ (`./pkg/egraph_wasm.node.js`), sharing a single `wasm-opt -Oz` optimized `.wasm` binary.
14
+ - **Strictly Single-Threaded**: Pure CPU Rust with deterministic seeded execution (`seed = 42` default), zero `rayon`, zero `std::thread`, zero Web Workers, and zero `SharedArrayBuffer`.
15
+ - **Zero-Copy Linear Memory Views**: `Layout2d.coordsView()` returns a cached `Float32Array` view directly over WebAssembly linear memory and automatically refreshes when `memory.grow` detaches the underlying `ArrayBuffer`.
16
+ - **Cooperative `requestAnimationFrame` Execution**: All iterative solvers implement `step()`, `runSteps(layout, k)`, and `run(layout)`, plus `runProgressive(solver, layout, onFrame, options?)` for responsive 60fps browser rendering.
17
+
18
+ ## Quick Start (Browser / Bundler ESM)
19
+
20
+ ```js
21
+ import init, {
22
+ CsrGraph,
23
+ Layout2d,
24
+ TsNetSolver,
25
+ evaluateMetrics,
26
+ pivotMdsInit,
27
+ runProgressive,
28
+ } from "egraph";
29
+
30
+ await init();
31
+
32
+ // Build an undirected CSR graph (0 - 1 - 2 - 3 - 0)
33
+ const indptr = new Uint32Array([0, 2, 4, 6, 8]);
34
+ const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
35
+ const graph = CsrGraph.fromCsr(indptr, indices);
36
+
37
+ // Initialize with normalized PivotMDS (f32 Layout2d)
38
+ const layout = pivotMdsInit(graph, 4, 42);
39
+
40
+ // Run Track A Pure 1+2-Hop Adaptive tsNET progressively in requestAnimationFrame
41
+ const solver = TsNetSolver.pure2Hop(graph, {
42
+ backend: "fft",
43
+ seed: 42,
44
+ });
45
+
46
+ await runProgressive(
47
+ solver,
48
+ layout,
49
+ ({ iteration, totalIterations }) => {
50
+ const xy = layout.coordsView(); // Zero-copy Float32Array [x0, y0, x1, y1, ...]
51
+ console.log(`frame ${iteration}/${totalIterations}, node0=(${xy[0]}, ${xy[1]})`);
52
+ },
53
+ { frameBudgetMs: 10 },
54
+ );
55
+
56
+ // Selectively evaluate quality metrics
57
+ const report = evaluateMetrics(graph, layout, ["sns", "np2", "crossingNumber"]);
58
+ console.log(report.toRecord());
59
+ ```
60
+
61
+ ## Node.js 18+ ESM
62
+
63
+ The same `"egraph"` import automatically resolves to the Node ESM loader via `"exports"`:
64
+
65
+ ```js
66
+ import init, { CsrGraph, TFdpSolver, pivotMdsInit } from "egraph";
67
+
68
+ await init();
69
+
70
+ const graph = CsrGraph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
71
+ const layout = pivotMdsInit(graph, 4, 42);
72
+ const solver = new TFdpSolver(graph, { backend: "ibfft", totalIterations: 200, seed: 42 });
73
+ solver.run(layout);
74
+
75
+ const xy = layout.coordsView();
76
+ console.log(Array.from(xy));
77
+ ```
78
+
79
+ ## Solver Examples
80
+
81
+ ### Track A: `TsNetSolver.pure2Hop`
82
+
83
+ ```js
84
+ const solver = TsNetSolver.pure2Hop(graph, {
85
+ backend: "fft",
86
+ perplexityC: 0.9,
87
+ seed: 42,
88
+ });
89
+ solver.run(layout);
90
+ ```
91
+
92
+ ### Track B & Unified Force Models: `TFdpSolver`, `ForceAtlas2Solver`, `GuMapSolver`
93
+
94
+ ```js
95
+ import {
96
+ ForceAtlas2Solver,
97
+ GuMapSolver,
98
+ SgdSolver,
99
+ TFdpSolver,
100
+ } from "egraph";
101
+
102
+ // t-FDP with ibFFT repulsion
103
+ const tfdp = new TFdpSolver(graph, {
104
+ backend: "ibfft",
105
+ totalIterations: 200,
106
+ seed: 42,
107
+ });
108
+ tfdp.run(layout);
109
+
110
+ // ForceAtlas2 (Barnes-Hut)
111
+ const fa2 = new ForceAtlas2Solver(graph, {
112
+ iterations: 200,
113
+ useBarnesHut: true,
114
+ theta: 0.5,
115
+ seed: 42,
116
+ });
117
+ fa2.run(layout);
118
+
119
+ // GuMap from regularized Chebyshev DoG landmarks
120
+ const gumap = GuMapSolver.fromGraphDog(graph, {
121
+ nEpochs: 200,
122
+ minDist: 0.1,
123
+ spread: 1.0,
124
+ seed: 42,
125
+ });
126
+ gumap.run(layout);
127
+
128
+ // Regularized DoG 3-tier Sparse Barrier SGD
129
+ const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
130
+ barrierSgd.run(layout);
131
+ ```
132
+
133
+ ### Overlap Removal (`PrismOverlapRemoval`)
134
+
135
+ ```js
136
+ import { PrismOverlapRemoval, prismDistortion } from "egraph";
137
+
138
+ const original = Layout2d.fromCoords(layout.coordsView());
139
+ const radii = new Float32Array(graph.numNodes()).fill(0.25);
140
+ const prism = PrismOverlapRemoval.fromRadii(radii, {
141
+ maxIterations: 50,
142
+ padding: 0.05,
143
+ seed: 42,
144
+ });
145
+ prism.run(layout);
146
+
147
+ const distortion = prismDistortion(original, layout);
148
+ console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
149
+ ```
150
+
151
+ ## Migration from v5 / Legacy Alpha
152
+
153
+ See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5/legacy-alpha to v6 migration guide, including:
154
+
155
+ 1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` and host-side arrays
156
+ 2. Migrating `OverwrapRemoval` to `PrismOverlapRemoval`
157
+ 3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver.pure2Hop`
158
+ 4. Replacing `stress` (`NS`) with Scale-Normalized Stress (`scaleNormalizedStress` / `evaluateMetrics`)
159
+ 5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, and `runProgressive`
160
+
161
+ ## License
162
+
163
+ MIT