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 +141 -139
- package/package.json +41 -25
- package/pkg/README.md +163 -0
- package/pkg/egraph_wasm.d.ts +2807 -0
- package/pkg/egraph_wasm.js +9791 -0
- package/pkg/egraph_wasm.node.js +12 -0
- package/pkg/egraph_wasm_bg.wasm +0 -0
- package/pkg/index.d.ts +3199 -0
- package/pkg/index.js +407 -0
- package/dist/bundler/README.md +0 -161
- package/dist/no-modules/LICENSE +0 -21
- package/dist/no-modules/README.md +0 -161
- package/dist/nodejs/LICENSE +0 -21
- package/dist/nodejs/README.md +0 -161
- package/dist/web/LICENSE +0 -21
- package/dist/web/README.md +0 -161
- package/umd/egraph.js +0 -840
- package/umd/egraph_bg.wasm +0 -0
- /package/{dist/bundler → pkg}/LICENSE +0 -0
package/pkg/index.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
import init, {
|
|
3
|
+
Layout2d as _Layout2d,
|
|
4
|
+
LayoutNd as _LayoutNd,
|
|
5
|
+
CoarsenedGraphResult,
|
|
6
|
+
CrossingPair,
|
|
7
|
+
CrossingSummary,
|
|
8
|
+
CsrGraph,
|
|
9
|
+
DelaunayResult,
|
|
10
|
+
DogStats,
|
|
11
|
+
DogVaradhanLandmarks,
|
|
12
|
+
EigenResult,
|
|
13
|
+
FdebSolver,
|
|
14
|
+
FitFieldStats,
|
|
15
|
+
ForceAtlas2Solver,
|
|
16
|
+
GuMapSolver,
|
|
17
|
+
HybridKnnResult,
|
|
18
|
+
IbUmapSolver,
|
|
19
|
+
KMeansResult,
|
|
20
|
+
KamadaKawaiSolver,
|
|
21
|
+
KnnGraph,
|
|
22
|
+
LargestConnectedComponentResult,
|
|
23
|
+
LouvainResult,
|
|
24
|
+
ManifoldLayout2d,
|
|
25
|
+
MetricReport,
|
|
26
|
+
PrismDistortion,
|
|
27
|
+
PrismOverlapRemoval,
|
|
28
|
+
SeparationConstraint,
|
|
29
|
+
SgdSolver,
|
|
30
|
+
SparseBarrierStats,
|
|
31
|
+
SparseProbabilities,
|
|
32
|
+
SpatialIntruderRefiner,
|
|
33
|
+
SpatialRefinerRoundStats,
|
|
34
|
+
SpatialRefinerStats,
|
|
35
|
+
SpectralEmbeddingResult,
|
|
36
|
+
SpectralMomentStats,
|
|
37
|
+
StressMajorizationSolver,
|
|
38
|
+
TFdpSolver,
|
|
39
|
+
TorusCrossing,
|
|
40
|
+
TsNetSolver,
|
|
41
|
+
TwoHopCsr,
|
|
42
|
+
TwoHopKnnResult,
|
|
43
|
+
YifanHuSolver,
|
|
44
|
+
allPairsBfs,
|
|
45
|
+
angularResolutionV6,
|
|
46
|
+
applyRelativeDistanceFloor,
|
|
47
|
+
aspectRatioV6,
|
|
48
|
+
assignLayers,
|
|
49
|
+
bfsSingleSource,
|
|
50
|
+
buildGumap12hopPriorityCsr,
|
|
51
|
+
buildHybridAdaptiveKnn,
|
|
52
|
+
buildPure2hopKnn,
|
|
53
|
+
buildRerankKnn,
|
|
54
|
+
chebyshevDogJlEmbedding,
|
|
55
|
+
chebyshevHeatSpmv,
|
|
56
|
+
classicalMds2d,
|
|
57
|
+
coarsenGraph,
|
|
58
|
+
compute2hopNeighborhoodSizes,
|
|
59
|
+
computeDiffusionEmbedding,
|
|
60
|
+
computeFuzzySimplicialSet,
|
|
61
|
+
computeHorvitzThompsonGamma,
|
|
62
|
+
computeKnnProbabilities,
|
|
63
|
+
computeMedian2hopPerplexity,
|
|
64
|
+
computeNodewise2hopPerplexities,
|
|
65
|
+
computeRegularizedDogVaradhanLandmarks,
|
|
66
|
+
computeResistanceEmbedding,
|
|
67
|
+
crossingEdges,
|
|
68
|
+
crossingEdgesTorus,
|
|
69
|
+
crossingSummary,
|
|
70
|
+
cycleEdges,
|
|
71
|
+
delaunayToCsr,
|
|
72
|
+
delaunayTriangulation,
|
|
73
|
+
dggPreservation,
|
|
74
|
+
drngPreservation,
|
|
75
|
+
edgeAngle,
|
|
76
|
+
evaluateMetrics,
|
|
77
|
+
extract1hop2hopCsr,
|
|
78
|
+
findAbParams,
|
|
79
|
+
gabrielGraphEdges,
|
|
80
|
+
gabrielGraphPropertyV6,
|
|
81
|
+
generateLayeredConstraints,
|
|
82
|
+
graphRowNormalizedProbabilities,
|
|
83
|
+
idealEdgeLengthsV6,
|
|
84
|
+
idealEdgeLengthsWithUnit,
|
|
85
|
+
initSync,
|
|
86
|
+
kmeansPlusPlus,
|
|
87
|
+
korenSpectralInit,
|
|
88
|
+
labelPropagation,
|
|
89
|
+
loadDataset,
|
|
90
|
+
louvainCommunities,
|
|
91
|
+
neighborhoodPreservation1Hop,
|
|
92
|
+
neighborhoodPreservation2HopV6,
|
|
93
|
+
nodeResolutionV6,
|
|
94
|
+
normalizeLayout2d,
|
|
95
|
+
parseCsrCsv,
|
|
96
|
+
partialBfsKnn,
|
|
97
|
+
pivotMdsInit,
|
|
98
|
+
poincareDistance,
|
|
99
|
+
prismDistortion,
|
|
100
|
+
prismDistortionWithEdges,
|
|
101
|
+
project1d,
|
|
102
|
+
projectClusteredLayout,
|
|
103
|
+
projectClusteredRectangleNoOverlap2d,
|
|
104
|
+
projectLayoutAxis,
|
|
105
|
+
projectRectangleNoOverlap2d,
|
|
106
|
+
rdMds,
|
|
107
|
+
rectangleOverlaps,
|
|
108
|
+
relativeNeighborhoodEdges,
|
|
109
|
+
removeCycles,
|
|
110
|
+
representativeMds,
|
|
111
|
+
sampledCrossingNumber,
|
|
112
|
+
sampledScaleNormalizedStress,
|
|
113
|
+
scaleNormalizedStress,
|
|
114
|
+
scaleNormalizedStressFromDistances,
|
|
115
|
+
selectMaxminSpPivots,
|
|
116
|
+
setPanicHook,
|
|
117
|
+
smallestLaplacianEigenpairs,
|
|
118
|
+
spectralClustering,
|
|
119
|
+
spectralMomentStats,
|
|
120
|
+
sphericalDistance,
|
|
121
|
+
sweepCrossingAngle,
|
|
122
|
+
sweepCrossingNumber,
|
|
123
|
+
symmetrizeRowNormalized,
|
|
124
|
+
torusCrossingNumber,
|
|
125
|
+
torusDistance,
|
|
126
|
+
wasmMemory,
|
|
127
|
+
wasm_start,
|
|
128
|
+
wrapTorusPoint,
|
|
129
|
+
} from "./egraph_wasm.js";
|
|
130
|
+
|
|
131
|
+
function attachCoordsView(LayoutClass) {
|
|
132
|
+
if (typeof LayoutClass.prototype.coordsView !== "function") {
|
|
133
|
+
LayoutClass.prototype.coordsView = function coordsView() {
|
|
134
|
+
const buf = wasmMemory().buffer;
|
|
135
|
+
const ptr = this.coordsPtr();
|
|
136
|
+
const len = this.coordsLen();
|
|
137
|
+
if (
|
|
138
|
+
!this._coordsView ||
|
|
139
|
+
this._coordsViewBuf !== buf ||
|
|
140
|
+
this._coordsView.byteOffset !== ptr ||
|
|
141
|
+
this._coordsView.length !== len
|
|
142
|
+
) {
|
|
143
|
+
this._coordsView = new Float32Array(buf, ptr, len);
|
|
144
|
+
this._coordsViewBuf = buf;
|
|
145
|
+
}
|
|
146
|
+
return this._coordsView;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return LayoutClass;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Runs a cooperative iterative solver progressively within a per-frame time budget,
|
|
154
|
+
* yielding back to the browser event loop via `requestAnimationFrame` (or `setTimeout`
|
|
155
|
+
* in Node.js) between batches.
|
|
156
|
+
*/
|
|
157
|
+
export function runProgressive(solver, layout, onFrame, options = {}) {
|
|
158
|
+
const {
|
|
159
|
+
frameBudgetMs = 10,
|
|
160
|
+
maxStepsPerFrame = 64,
|
|
161
|
+
stepsPerYield = 1,
|
|
162
|
+
signal,
|
|
163
|
+
} = options ?? {};
|
|
164
|
+
|
|
165
|
+
const scheduleNext =
|
|
166
|
+
typeof globalThis.requestAnimationFrame === "function"
|
|
167
|
+
? (cb) => globalThis.requestAnimationFrame(() => cb())
|
|
168
|
+
: (cb) => globalThis.setTimeout(cb, 0);
|
|
169
|
+
const cancelNext =
|
|
170
|
+
typeof globalThis.cancelAnimationFrame === "function"
|
|
171
|
+
? (id) => globalThis.cancelAnimationFrame(id)
|
|
172
|
+
: (id) => globalThis.clearTimeout(id);
|
|
173
|
+
|
|
174
|
+
const makeAbortError = () => {
|
|
175
|
+
if (typeof globalThis.DOMException === "function") {
|
|
176
|
+
return new globalThis.DOMException("runProgressive aborted", "AbortError");
|
|
177
|
+
}
|
|
178
|
+
const err = new Error("runProgressive aborted");
|
|
179
|
+
err.name = "AbortError";
|
|
180
|
+
return err;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
if (signal?.aborted) {
|
|
185
|
+
reject(signal.reason ?? makeAbortError());
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (solver.isFinished) {
|
|
189
|
+
const doneCtx = {
|
|
190
|
+
iteration: solver.iteration,
|
|
191
|
+
totalIterations: solver.totalIterations,
|
|
192
|
+
status: solver.status,
|
|
193
|
+
layout,
|
|
194
|
+
};
|
|
195
|
+
if (typeof onFrame === "function") {
|
|
196
|
+
onFrame(doneCtx);
|
|
197
|
+
}
|
|
198
|
+
resolve(doneCtx);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let handle = null;
|
|
203
|
+
let settled = false;
|
|
204
|
+
|
|
205
|
+
const onAbort = () => {
|
|
206
|
+
if (settled) return;
|
|
207
|
+
settled = true;
|
|
208
|
+
if (handle !== null) {
|
|
209
|
+
cancelNext(handle);
|
|
210
|
+
handle = null;
|
|
211
|
+
}
|
|
212
|
+
reject(signal?.reason ?? makeAbortError());
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
if (signal && typeof signal.addEventListener === "function") {
|
|
216
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const finish = (fn, value) => {
|
|
220
|
+
if (settled) return;
|
|
221
|
+
settled = true;
|
|
222
|
+
if (signal && typeof signal.removeEventListener === "function") {
|
|
223
|
+
signal.removeEventListener("abort", onAbort);
|
|
224
|
+
}
|
|
225
|
+
fn(value);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const tick = () => {
|
|
229
|
+
if (settled) return;
|
|
230
|
+
if (signal?.aborted) {
|
|
231
|
+
finish(reject, signal.reason ?? makeAbortError());
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const t0 = globalThis.performance.now();
|
|
236
|
+
let stepsThisFrame = 0;
|
|
237
|
+
let status = solver.status;
|
|
238
|
+
const batch = Math.max(1, Math.floor(stepsPerYield));
|
|
239
|
+
|
|
240
|
+
while (!solver.isFinished && stepsThisFrame < maxStepsPerFrame) {
|
|
241
|
+
if (batch > 1 && typeof solver.runSteps === "function") {
|
|
242
|
+
status = solver.runSteps(layout, batch);
|
|
243
|
+
stepsThisFrame += batch;
|
|
244
|
+
} else {
|
|
245
|
+
status = solver.step(layout);
|
|
246
|
+
stepsThisFrame += 1;
|
|
247
|
+
}
|
|
248
|
+
if (globalThis.performance.now() - t0 >= frameBudgetMs) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const ctx = {
|
|
254
|
+
iteration: solver.iteration,
|
|
255
|
+
totalIterations: solver.totalIterations,
|
|
256
|
+
status,
|
|
257
|
+
layout,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
if (typeof onFrame === "function") {
|
|
261
|
+
onFrame(ctx);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (solver.isFinished) {
|
|
265
|
+
finish(resolve, ctx);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
handle = scheduleNext(tick);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
finish(reject, err);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
handle = scheduleNext(tick);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export const Layout2d = attachCoordsView(_Layout2d);
|
|
280
|
+
export const LayoutNd = attachCoordsView(_LayoutNd);
|
|
281
|
+
export {
|
|
282
|
+
CoarsenedGraphResult,
|
|
283
|
+
CrossingPair,
|
|
284
|
+
CrossingSummary,
|
|
285
|
+
CsrGraph,
|
|
286
|
+
DelaunayResult,
|
|
287
|
+
DogStats,
|
|
288
|
+
DogVaradhanLandmarks,
|
|
289
|
+
EigenResult,
|
|
290
|
+
FdebSolver,
|
|
291
|
+
FitFieldStats,
|
|
292
|
+
ForceAtlas2Solver,
|
|
293
|
+
GuMapSolver,
|
|
294
|
+
HybridKnnResult,
|
|
295
|
+
IbUmapSolver,
|
|
296
|
+
KMeansResult,
|
|
297
|
+
KamadaKawaiSolver,
|
|
298
|
+
KnnGraph,
|
|
299
|
+
LargestConnectedComponentResult,
|
|
300
|
+
LouvainResult,
|
|
301
|
+
ManifoldLayout2d,
|
|
302
|
+
MetricReport,
|
|
303
|
+
PrismDistortion,
|
|
304
|
+
PrismOverlapRemoval,
|
|
305
|
+
SeparationConstraint,
|
|
306
|
+
SgdSolver,
|
|
307
|
+
SparseBarrierStats,
|
|
308
|
+
SparseProbabilities,
|
|
309
|
+
SpatialIntruderRefiner,
|
|
310
|
+
SpatialRefinerRoundStats,
|
|
311
|
+
SpatialRefinerStats,
|
|
312
|
+
SpectralEmbeddingResult,
|
|
313
|
+
SpectralMomentStats,
|
|
314
|
+
StressMajorizationSolver,
|
|
315
|
+
TFdpSolver,
|
|
316
|
+
TorusCrossing,
|
|
317
|
+
TsNetSolver,
|
|
318
|
+
TwoHopCsr,
|
|
319
|
+
TwoHopKnnResult,
|
|
320
|
+
YifanHuSolver,
|
|
321
|
+
allPairsBfs,
|
|
322
|
+
angularResolutionV6,
|
|
323
|
+
applyRelativeDistanceFloor,
|
|
324
|
+
aspectRatioV6,
|
|
325
|
+
assignLayers,
|
|
326
|
+
bfsSingleSource,
|
|
327
|
+
buildGumap12hopPriorityCsr,
|
|
328
|
+
buildHybridAdaptiveKnn,
|
|
329
|
+
buildPure2hopKnn,
|
|
330
|
+
buildRerankKnn,
|
|
331
|
+
chebyshevDogJlEmbedding,
|
|
332
|
+
chebyshevHeatSpmv,
|
|
333
|
+
classicalMds2d,
|
|
334
|
+
coarsenGraph,
|
|
335
|
+
compute2hopNeighborhoodSizes,
|
|
336
|
+
computeDiffusionEmbedding,
|
|
337
|
+
computeFuzzySimplicialSet,
|
|
338
|
+
computeHorvitzThompsonGamma,
|
|
339
|
+
computeKnnProbabilities,
|
|
340
|
+
computeMedian2hopPerplexity,
|
|
341
|
+
computeNodewise2hopPerplexities,
|
|
342
|
+
computeRegularizedDogVaradhanLandmarks,
|
|
343
|
+
computeResistanceEmbedding,
|
|
344
|
+
crossingEdges,
|
|
345
|
+
crossingEdgesTorus,
|
|
346
|
+
crossingSummary,
|
|
347
|
+
cycleEdges,
|
|
348
|
+
delaunayToCsr,
|
|
349
|
+
delaunayTriangulation,
|
|
350
|
+
dggPreservation,
|
|
351
|
+
drngPreservation,
|
|
352
|
+
edgeAngle,
|
|
353
|
+
evaluateMetrics,
|
|
354
|
+
extract1hop2hopCsr,
|
|
355
|
+
findAbParams,
|
|
356
|
+
gabrielGraphEdges,
|
|
357
|
+
gabrielGraphPropertyV6,
|
|
358
|
+
generateLayeredConstraints,
|
|
359
|
+
graphRowNormalizedProbabilities,
|
|
360
|
+
idealEdgeLengthsV6,
|
|
361
|
+
idealEdgeLengthsWithUnit,
|
|
362
|
+
initSync,
|
|
363
|
+
kmeansPlusPlus,
|
|
364
|
+
korenSpectralInit,
|
|
365
|
+
labelPropagation,
|
|
366
|
+
loadDataset,
|
|
367
|
+
louvainCommunities,
|
|
368
|
+
neighborhoodPreservation1Hop,
|
|
369
|
+
neighborhoodPreservation2HopV6,
|
|
370
|
+
nodeResolutionV6,
|
|
371
|
+
normalizeLayout2d,
|
|
372
|
+
parseCsrCsv,
|
|
373
|
+
partialBfsKnn,
|
|
374
|
+
pivotMdsInit,
|
|
375
|
+
poincareDistance,
|
|
376
|
+
prismDistortion,
|
|
377
|
+
prismDistortionWithEdges,
|
|
378
|
+
project1d,
|
|
379
|
+
projectClusteredLayout,
|
|
380
|
+
projectClusteredRectangleNoOverlap2d,
|
|
381
|
+
projectLayoutAxis,
|
|
382
|
+
projectRectangleNoOverlap2d,
|
|
383
|
+
rdMds,
|
|
384
|
+
rectangleOverlaps,
|
|
385
|
+
relativeNeighborhoodEdges,
|
|
386
|
+
removeCycles,
|
|
387
|
+
representativeMds,
|
|
388
|
+
sampledCrossingNumber,
|
|
389
|
+
sampledScaleNormalizedStress,
|
|
390
|
+
scaleNormalizedStress,
|
|
391
|
+
scaleNormalizedStressFromDistances,
|
|
392
|
+
selectMaxminSpPivots,
|
|
393
|
+
setPanicHook,
|
|
394
|
+
smallestLaplacianEigenpairs,
|
|
395
|
+
spectralClustering,
|
|
396
|
+
spectralMomentStats,
|
|
397
|
+
sphericalDistance,
|
|
398
|
+
sweepCrossingAngle,
|
|
399
|
+
sweepCrossingNumber,
|
|
400
|
+
symmetrizeRowNormalized,
|
|
401
|
+
torusCrossingNumber,
|
|
402
|
+
torusDistance,
|
|
403
|
+
wasmMemory,
|
|
404
|
+
wasm_start,
|
|
405
|
+
wrapTorusPoint,
|
|
406
|
+
};
|
|
407
|
+
export default init;
|
package/dist/bundler/README.md
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# egraph
|
|
2
|
-
|
|
3
|
-
egraph is a fast graph drawing library implemented in Rust and WebAssembly.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```shell-session
|
|
8
|
-
$ npm install egraph
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
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
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
egraph-wasm is implemented using wasm-bindgen.
|
|
56
|
-
For more detailed usage, please read [wasm-bindgen document](https://rustwasm.github.io/wasm-bindgen/).
|
|
57
|
-
|
|
58
|
-
## Examples
|
|
59
|
-
|
|
60
|
-
### Drawing SVG with React.js
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
import React from 'react'
|
|
64
|
-
import { render } from 'react-dom'
|
|
65
|
-
import { Graph } from 'egraph'
|
|
66
|
-
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
|
-
)
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Loading JSON
|
|
128
|
-
|
|
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
|
-
})()
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## License
|
|
160
|
-
|
|
161
|
-
MIT
|
package/dist/no-modules/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Yosuke Onoue
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|