@antv/layout 0.3.12 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -32
- package/dist/3a54d760230d1933f953.worker.js +2 -0
- package/dist/3a54d760230d1933f953.worker.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/lib/Circular.d.ts +40 -0
- package/lib/Supervisor.d.ts +65 -0
- package/lib/index.d.ts +4 -3
- package/lib/registry.d.ts +3 -0
- package/lib/types.d.ts +128 -0
- package/lib/util/gpu.d.ts +22 -22
- package/lib/util/index.d.ts +6 -6
- package/lib/util/math.d.ts +3 -3
- package/lib/worker.d.ts +3 -0
- package/package.json +21 -95
- package/dist/layout.min.js +0 -3
- package/dist/layout.min.js.LICENSE.txt +0 -1
- package/dist/layout.min.js.map +0 -1
- package/es/index.d.ts +0 -3
- package/es/index.js +0 -6
- package/es/index.js.map +0 -1
- package/es/layout/base.d.ts +0 -22
- package/es/layout/base.js +0 -51
- package/es/layout/base.js.map +0 -1
- package/es/layout/circular.d.ts +0 -80
- package/es/layout/circular.js +0 -314
- package/es/layout/circular.js.map +0 -1
- package/es/layout/comboCombined.d.ts +0 -54
- package/es/layout/comboCombined.js +0 -354
- package/es/layout/comboCombined.js.map +0 -1
- package/es/layout/comboForce.d.ts +0 -134
- package/es/layout/comboForce.js +0 -801
- package/es/layout/comboForce.js.map +0 -1
- package/es/layout/concentric.d.ts +0 -67
- package/es/layout/concentric.js +0 -219
- package/es/layout/concentric.js.map +0 -1
- package/es/layout/constants.d.ts +0 -12
- package/es/layout/constants.js +0 -22
- package/es/layout/constants.js.map +0 -1
- package/es/layout/dagre/graph.d.ts +0 -91
- package/es/layout/dagre/graph.js +0 -4
- package/es/layout/dagre/graph.js.map +0 -1
- package/es/layout/dagre/index.d.ts +0 -8
- package/es/layout/dagre/index.js +0 -31
- package/es/layout/dagre/index.js.map +0 -1
- package/es/layout/dagre/src/acyclic.d.ts +0 -6
- package/es/layout/dagre/src/acyclic.js +0 -52
- package/es/layout/dagre/src/acyclic.js.map +0 -1
- package/es/layout/dagre/src/add-border-segments.d.ts +0 -3
- package/es/layout/dagre/src/add-border-segments.js +0 -32
- package/es/layout/dagre/src/add-border-segments.js.map +0 -1
- package/es/layout/dagre/src/coordinate-system.d.ts +0 -6
- package/es/layout/dagre/src/coordinate-system.js +0 -69
- package/es/layout/dagre/src/coordinate-system.js.map +0 -1
- package/es/layout/dagre/src/data/list.d.ts +0 -12
- package/es/layout/dagre/src/data/list.js +0 -48
- package/es/layout/dagre/src/data/list.js.map +0 -1
- package/es/layout/dagre/src/debug.d.ts +0 -3
- package/es/layout/dagre/src/debug.js +0 -24
- package/es/layout/dagre/src/debug.js.map +0 -1
- package/es/layout/dagre/src/greedy-fas.d.ts +0 -3
- package/es/layout/dagre/src/greedy-fas.js +0 -114
- package/es/layout/dagre/src/greedy-fas.js.map +0 -1
- package/es/layout/dagre/src/layout.d.ts +0 -3
- package/es/layout/dagre/src/layout.js +0 -518
- package/es/layout/dagre/src/layout.js.map +0 -1
- package/es/layout/dagre/src/nesting-graph.d.ts +0 -6
- package/es/layout/dagre/src/nesting-graph.js +0 -117
- package/es/layout/dagre/src/nesting-graph.js.map +0 -1
- package/es/layout/dagre/src/normalize.d.ts +0 -6
- package/es/layout/dagre/src/normalize.js +0 -89
- package/es/layout/dagre/src/normalize.js.map +0 -1
- package/es/layout/dagre/src/order/add-subgraph-constraints.d.ts +0 -3
- package/es/layout/dagre/src/order/add-subgraph-constraints.js +0 -27
- package/es/layout/dagre/src/order/add-subgraph-constraints.js.map +0 -1
- package/es/layout/dagre/src/order/barycenter.d.ts +0 -11
- package/es/layout/dagre/src/order/barycenter.js +0 -24
- package/es/layout/dagre/src/order/barycenter.js.map +0 -1
- package/es/layout/dagre/src/order/build-layer-graph.d.ts +0 -3
- package/es/layout/dagre/src/order/build-layer-graph.js +0 -71
- package/es/layout/dagre/src/order/build-layer-graph.js.map +0 -1
- package/es/layout/dagre/src/order/cross-count.d.ts +0 -3
- package/es/layout/dagre/src/order/cross-count.js +0 -65
- package/es/layout/dagre/src/order/cross-count.js.map +0 -1
- package/es/layout/dagre/src/order/index.d.ts +0 -3
- package/es/layout/dagre/src/order/index.js +0 -91
- package/es/layout/dagre/src/order/index.js.map +0 -1
- package/es/layout/dagre/src/order/init-data-order.d.ts +0 -6
- package/es/layout/dagre/src/order/init-data-order.js +0 -25
- package/es/layout/dagre/src/order/init-data-order.js.map +0 -1
- package/es/layout/dagre/src/order/init-order.d.ts +0 -3
- package/es/layout/dagre/src/order/init-order.js +0 -52
- package/es/layout/dagre/src/order/init-order.js.map +0 -1
- package/es/layout/dagre/src/order/resolve-conflicts.d.ts +0 -19
- package/es/layout/dagre/src/order/resolve-conflicts.js +0 -93
- package/es/layout/dagre/src/order/resolve-conflicts.js.map +0 -1
- package/es/layout/dagre/src/order/sort-subgraph.d.ts +0 -7
- package/es/layout/dagre/src/order/sort-subgraph.js +0 -85
- package/es/layout/dagre/src/order/sort-subgraph.js.map +0 -1
- package/es/layout/dagre/src/order/sort.d.ts +0 -7
- package/es/layout/dagre/src/order/sort.js +0 -68
- package/es/layout/dagre/src/order/sort.js.map +0 -1
- package/es/layout/dagre/src/parent-dummy-chains.d.ts +0 -3
- package/es/layout/dagre/src/parent-dummy-chains.js +0 -81
- package/es/layout/dagre/src/parent-dummy-chains.js.map +0 -1
- package/es/layout/dagre/src/position/bk.d.ts +0 -23
- package/es/layout/dagre/src/position/bk.js +0 -370
- package/es/layout/dagre/src/position/bk.js.map +0 -1
- package/es/layout/dagre/src/position/index.d.ts +0 -3
- package/es/layout/dagre/src/position/index.js +0 -51
- package/es/layout/dagre/src/position/index.js.map +0 -1
- package/es/layout/dagre/src/rank/feasible-tree.d.ts +0 -9
- package/es/layout/dagre/src/rank/feasible-tree.js +0 -148
- package/es/layout/dagre/src/rank/feasible-tree.js.map +0 -1
- package/es/layout/dagre/src/rank/index.d.ts +0 -3
- package/es/layout/dagre/src/rank/index.js +0 -53
- package/es/layout/dagre/src/rank/index.js.map +0 -1
- package/es/layout/dagre/src/rank/network-simplex.d.ts +0 -9
- package/es/layout/dagre/src/rank/network-simplex.js +0 -195
- package/es/layout/dagre/src/rank/network-simplex.js.map +0 -1
- package/es/layout/dagre/src/rank/util.d.ts +0 -11
- package/es/layout/dagre/src/rank/util.js +0 -141
- package/es/layout/dagre/src/rank/util.js.map +0 -1
- package/es/layout/dagre/src/util.d.ts +0 -31
- package/es/layout/dagre/src/util.js +0 -261
- package/es/layout/dagre/src/util.js.map +0 -1
- package/es/layout/dagre.d.ts +0 -71
- package/es/layout/dagre.js +0 -433
- package/es/layout/dagre.js.map +0 -1
- package/es/layout/dagreCompound.d.ts +0 -121
- package/es/layout/dagreCompound.js +0 -391
- package/es/layout/dagreCompound.js.map +0 -1
- package/es/layout/er/core.d.ts +0 -1
- package/es/layout/er/core.js +0 -107
- package/es/layout/er/core.js.map +0 -1
- package/es/layout/er/forceGrid.d.ts +0 -8
- package/es/layout/er/forceGrid.js +0 -88
- package/es/layout/er/forceGrid.js.map +0 -1
- package/es/layout/er/grid.d.ts +0 -26
- package/es/layout/er/grid.js +0 -162
- package/es/layout/er/grid.js.map +0 -1
- package/es/layout/er/index.d.ts +0 -29
- package/es/layout/er/index.js +0 -54
- package/es/layout/er/index.js.map +0 -1
- package/es/layout/er/mysqlWorkbench.d.ts +0 -6
- package/es/layout/er/mysqlWorkbench.js +0 -324
- package/es/layout/er/mysqlWorkbench.js.map +0 -1
- package/es/layout/er/type.d.ts +0 -35
- package/es/layout/er/type.js +0 -2
- package/es/layout/er/type.js.map +0 -1
- package/es/layout/force/force-in-a-box.d.ts +0 -28
- package/es/layout/force/force-in-a-box.js +0 -330
- package/es/layout/force/force-in-a-box.js.map +0 -1
- package/es/layout/force/force.d.ts +0 -100
- package/es/layout/force/force.js +0 -340
- package/es/layout/force/force.js.map +0 -1
- package/es/layout/force/index.d.ts +0 -1
- package/es/layout/force/index.js +0 -2
- package/es/layout/force/index.js.map +0 -1
- package/es/layout/force2/ForceNBody.d.ts +0 -7
- package/es/layout/force2/ForceNBody.js +0 -94
- package/es/layout/force2/ForceNBody.js.map +0 -1
- package/es/layout/force2/index.d.ts +0 -119
- package/es/layout/force2/index.js +0 -608
- package/es/layout/force2/index.js.map +0 -1
- package/es/layout/forceAtlas2/body.d.ts +0 -33
- package/es/layout/forceAtlas2/body.js +0 -89
- package/es/layout/forceAtlas2/body.js.map +0 -1
- package/es/layout/forceAtlas2/index.d.ts +0 -115
- package/es/layout/forceAtlas2/index.js +0 -484
- package/es/layout/forceAtlas2/index.js.map +0 -1
- package/es/layout/forceAtlas2/quad.d.ts +0 -27
- package/es/layout/forceAtlas2/quad.js +0 -96
- package/es/layout/forceAtlas2/quad.js.map +0 -1
- package/es/layout/forceAtlas2/quadTree.d.ts +0 -20
- package/es/layout/forceAtlas2/quadTree.js +0 -103
- package/es/layout/forceAtlas2/quadTree.js.map +0 -1
- package/es/layout/fruchterman.d.ts +0 -73
- package/es/layout/fruchterman.js +0 -296
- package/es/layout/fruchterman.js.map +0 -1
- package/es/layout/gForce.d.ts +0 -96
- package/es/layout/gForce.js +0 -399
- package/es/layout/gForce.js.map +0 -1
- package/es/layout/gpu/fruchterman.d.ts +0 -57
- package/es/layout/gpu/fruchterman.js +0 -267
- package/es/layout/gpu/fruchterman.js.map +0 -1
- package/es/layout/gpu/fruchtermanShader.d.ts +0 -4
- package/es/layout/gpu/fruchtermanShader.js +0 -201
- package/es/layout/gpu/fruchtermanShader.js.map +0 -1
- package/es/layout/gpu/gForce.d.ts +0 -68
- package/es/layout/gpu/gForce.js +0 -330
- package/es/layout/gpu/gForce.js.map +0 -1
- package/es/layout/gpu/gForceShader.d.ts +0 -4
- package/es/layout/gpu/gForceShader.js +0 -218
- package/es/layout/gpu/gForceShader.js.map +0 -1
- package/es/layout/grid.d.ts +0 -83
- package/es/layout/grid.js +0 -317
- package/es/layout/grid.js.map +0 -1
- package/es/layout/index.d.ts +0 -22
- package/es/layout/index.js +0 -25
- package/es/layout/index.js.map +0 -1
- package/es/layout/layout.d.ts +0 -26
- package/es/layout/layout.js +0 -97
- package/es/layout/layout.js.map +0 -1
- package/es/layout/mds.d.ts +0 -39
- package/es/layout/mds.js +0 -122
- package/es/layout/mds.js.map +0 -1
- package/es/layout/radial/index.d.ts +0 -1
- package/es/layout/radial/index.js +0 -2
- package/es/layout/radial/index.js.map +0 -1
- package/es/layout/radial/mds.d.ts +0 -15
- package/es/layout/radial/mds.js +0 -38
- package/es/layout/radial/mds.js.map +0 -1
- package/es/layout/radial/radial.d.ts +0 -74
- package/es/layout/radial/radial.js +0 -420
- package/es/layout/radial/radial.js.map +0 -1
- package/es/layout/radial/radialNonoverlapForce.d.ts +0 -50
- package/es/layout/radial/radialNonoverlapForce.js +0 -123
- package/es/layout/radial/radialNonoverlapForce.js.map +0 -1
- package/es/layout/random.d.ts +0 -35
- package/es/layout/random.js +0 -62
- package/es/layout/random.js.map +0 -1
- package/es/layout/types.d.ts +0 -432
- package/es/layout/types.js +0 -2
- package/es/layout/types.js.map +0 -1
- package/es/registy/index.d.ts +0 -3
- package/es/registy/index.js +0 -41
- package/es/registy/index.js.map +0 -1
- package/es/util/array.d.ts +0 -1
- package/es/util/array.js +0 -2
- package/es/util/array.js.map +0 -1
- package/es/util/function.d.ts +0 -6
- package/es/util/function.js +0 -56
- package/es/util/function.js.map +0 -1
- package/es/util/gpu.d.ts +0 -52
- package/es/util/gpu.js +0 -239
- package/es/util/gpu.js.map +0 -1
- package/es/util/index.d.ts +0 -6
- package/es/util/index.js +0 -7
- package/es/util/index.js.map +0 -1
- package/es/util/math.d.ts +0 -48
- package/es/util/math.js +0 -276
- package/es/util/math.js.map +0 -1
- package/es/util/number.d.ts +0 -3
- package/es/util/number.js +0 -7
- package/es/util/number.js.map +0 -1
- package/es/util/object.d.ts +0 -2
- package/es/util/object.js +0 -25
- package/es/util/object.js.map +0 -1
- package/es/util/string.d.ts +0 -2
- package/es/util/string.js +0 -16
- package/es/util/string.js.map +0 -1
- package/lib/index.js +0 -24
- package/lib/index.js.map +0 -1
- package/lib/layout/base.d.ts +0 -22
- package/lib/layout/base.js +0 -56
- package/lib/layout/base.js.map +0 -1
- package/lib/layout/circular.d.ts +0 -80
- package/lib/layout/circular.js +0 -337
- package/lib/layout/circular.js.map +0 -1
- package/lib/layout/comboCombined.d.ts +0 -54
- package/lib/layout/comboCombined.js +0 -390
- package/lib/layout/comboCombined.js.map +0 -1
- package/lib/layout/comboForce.d.ts +0 -134
- package/lib/layout/comboForce.js +0 -826
- package/lib/layout/comboForce.js.map +0 -1
- package/lib/layout/concentric.d.ts +0 -67
- package/lib/layout/concentric.js +0 -243
- package/lib/layout/concentric.js.map +0 -1
- package/lib/layout/constants.d.ts +0 -12
- package/lib/layout/constants.js +0 -25
- package/lib/layout/constants.js.map +0 -1
- package/lib/layout/dagre/graph.d.ts +0 -91
- package/lib/layout/dagre/graph.js +0 -28
- package/lib/layout/dagre/graph.js.map +0 -1
- package/lib/layout/dagre/index.d.ts +0 -8
- package/lib/layout/dagre/index.js +0 -36
- package/lib/layout/dagre/index.js.map +0 -1
- package/lib/layout/dagre/src/acyclic.d.ts +0 -6
- package/lib/layout/dagre/src/acyclic.js +0 -57
- package/lib/layout/dagre/src/acyclic.js.map +0 -1
- package/lib/layout/dagre/src/add-border-segments.d.ts +0 -3
- package/lib/layout/dagre/src/add-border-segments.js +0 -34
- package/lib/layout/dagre/src/add-border-segments.js.map +0 -1
- package/lib/layout/dagre/src/coordinate-system.d.ts +0 -6
- package/lib/layout/dagre/src/coordinate-system.js +0 -71
- package/lib/layout/dagre/src/coordinate-system.js.map +0 -1
- package/lib/layout/dagre/src/data/list.d.ts +0 -12
- package/lib/layout/dagre/src/data/list.js +0 -52
- package/lib/layout/dagre/src/data/list.js.map +0 -1
- package/lib/layout/dagre/src/debug.d.ts +0 -3
- package/lib/layout/dagre/src/debug.js +0 -26
- package/lib/layout/dagre/src/debug.js.map +0 -1
- package/lib/layout/dagre/src/greedy-fas.d.ts +0 -3
- package/lib/layout/dagre/src/greedy-fas.js +0 -144
- package/lib/layout/dagre/src/greedy-fas.js.map +0 -1
- package/lib/layout/dagre/src/layout.d.ts +0 -3
- package/lib/layout/dagre/src/layout.js +0 -535
- package/lib/layout/dagre/src/layout.js.map +0 -1
- package/lib/layout/dagre/src/nesting-graph.d.ts +0 -6
- package/lib/layout/dagre/src/nesting-graph.js +0 -119
- package/lib/layout/dagre/src/nesting-graph.js.map +0 -1
- package/lib/layout/dagre/src/normalize.d.ts +0 -6
- package/lib/layout/dagre/src/normalize.js +0 -91
- package/lib/layout/dagre/src/normalize.js.map +0 -1
- package/lib/layout/dagre/src/order/add-subgraph-constraints.d.ts +0 -3
- package/lib/layout/dagre/src/order/add-subgraph-constraints.js +0 -29
- package/lib/layout/dagre/src/order/add-subgraph-constraints.js.map +0 -1
- package/lib/layout/dagre/src/order/barycenter.d.ts +0 -11
- package/lib/layout/dagre/src/order/barycenter.js +0 -26
- package/lib/layout/dagre/src/order/barycenter.js.map +0 -1
- package/lib/layout/dagre/src/order/build-layer-graph.d.ts +0 -3
- package/lib/layout/dagre/src/order/build-layer-graph.js +0 -73
- package/lib/layout/dagre/src/order/build-layer-graph.js.map +0 -1
- package/lib/layout/dagre/src/order/cross-count.d.ts +0 -3
- package/lib/layout/dagre/src/order/cross-count.js +0 -67
- package/lib/layout/dagre/src/order/cross-count.js.map +0 -1
- package/lib/layout/dagre/src/order/index.d.ts +0 -3
- package/lib/layout/dagre/src/order/index.js +0 -96
- package/lib/layout/dagre/src/order/index.js.map +0 -1
- package/lib/layout/dagre/src/order/init-data-order.d.ts +0 -6
- package/lib/layout/dagre/src/order/init-data-order.js +0 -27
- package/lib/layout/dagre/src/order/init-data-order.js.map +0 -1
- package/lib/layout/dagre/src/order/init-order.d.ts +0 -3
- package/lib/layout/dagre/src/order/init-order.js +0 -54
- package/lib/layout/dagre/src/order/init-order.js.map +0 -1
- package/lib/layout/dagre/src/order/resolve-conflicts.d.ts +0 -19
- package/lib/layout/dagre/src/order/resolve-conflicts.js +0 -98
- package/lib/layout/dagre/src/order/resolve-conflicts.js.map +0 -1
- package/lib/layout/dagre/src/order/sort-subgraph.d.ts +0 -7
- package/lib/layout/dagre/src/order/sort-subgraph.js +0 -90
- package/lib/layout/dagre/src/order/sort-subgraph.js.map +0 -1
- package/lib/layout/dagre/src/order/sort.d.ts +0 -7
- package/lib/layout/dagre/src/order/sort.js +0 -70
- package/lib/layout/dagre/src/order/sort.js.map +0 -1
- package/lib/layout/dagre/src/parent-dummy-chains.d.ts +0 -3
- package/lib/layout/dagre/src/parent-dummy-chains.js +0 -83
- package/lib/layout/dagre/src/parent-dummy-chains.js.map +0 -1
- package/lib/layout/dagre/src/position/bk.d.ts +0 -23
- package/lib/layout/dagre/src/position/bk.js +0 -409
- package/lib/layout/dagre/src/position/bk.js.map +0 -1
- package/lib/layout/dagre/src/position/index.d.ts +0 -3
- package/lib/layout/dagre/src/position/index.js +0 -64
- package/lib/layout/dagre/src/position/index.js.map +0 -1
- package/lib/layout/dagre/src/rank/feasible-tree.d.ts +0 -9
- package/lib/layout/dagre/src/rank/feasible-tree.js +0 -152
- package/lib/layout/dagre/src/rank/feasible-tree.js.map +0 -1
- package/lib/layout/dagre/src/rank/index.d.ts +0 -3
- package/lib/layout/dagre/src/rank/index.js +0 -58
- package/lib/layout/dagre/src/rank/index.js.map +0 -1
- package/lib/layout/dagre/src/rank/network-simplex.d.ts +0 -9
- package/lib/layout/dagre/src/rank/network-simplex.js +0 -205
- package/lib/layout/dagre/src/rank/network-simplex.js.map +0 -1
- package/lib/layout/dagre/src/rank/util.d.ts +0 -11
- package/lib/layout/dagre/src/rank/util.js +0 -146
- package/lib/layout/dagre/src/rank/util.js.map +0 -1
- package/lib/layout/dagre/src/util.d.ts +0 -31
- package/lib/layout/dagre/src/util.js +0 -280
- package/lib/layout/dagre/src/util.js.map +0 -1
- package/lib/layout/dagre.d.ts +0 -71
- package/lib/layout/dagre.js +0 -462
- package/lib/layout/dagre.js.map +0 -1
- package/lib/layout/dagreCompound.d.ts +0 -121
- package/lib/layout/dagreCompound.js +0 -429
- package/lib/layout/dagreCompound.js.map +0 -1
- package/lib/layout/er/core.d.ts +0 -1
- package/lib/layout/er/core.js +0 -147
- package/lib/layout/er/core.js.map +0 -1
- package/lib/layout/er/forceGrid.d.ts +0 -8
- package/lib/layout/er/forceGrid.js +0 -97
- package/lib/layout/er/forceGrid.js.map +0 -1
- package/lib/layout/er/grid.d.ts +0 -26
- package/lib/layout/er/grid.js +0 -177
- package/lib/layout/er/grid.js.map +0 -1
- package/lib/layout/er/index.d.ts +0 -29
- package/lib/layout/er/index.js +0 -80
- package/lib/layout/er/index.js.map +0 -1
- package/lib/layout/er/mysqlWorkbench.d.ts +0 -6
- package/lib/layout/er/mysqlWorkbench.js +0 -326
- package/lib/layout/er/mysqlWorkbench.js.map +0 -1
- package/lib/layout/er/type.d.ts +0 -35
- package/lib/layout/er/type.js +0 -3
- package/lib/layout/er/type.js.map +0 -1
- package/lib/layout/force/force-in-a-box.d.ts +0 -28
- package/lib/layout/force/force-in-a-box.js +0 -357
- package/lib/layout/force/force-in-a-box.js.map +0 -1
- package/lib/layout/force/force.d.ts +0 -100
- package/lib/layout/force/force.js +0 -388
- package/lib/layout/force/force.js.map +0 -1
- package/lib/layout/force/index.d.ts +0 -1
- package/lib/layout/force/index.js +0 -18
- package/lib/layout/force/index.js.map +0 -1
- package/lib/layout/force2/ForceNBody.d.ts +0 -7
- package/lib/layout/force2/ForceNBody.js +0 -98
- package/lib/layout/force2/ForceNBody.js.map +0 -1
- package/lib/layout/force2/index.d.ts +0 -119
- package/lib/layout/force2/index.js +0 -643
- package/lib/layout/force2/index.js.map +0 -1
- package/lib/layout/forceAtlas2/body.d.ts +0 -33
- package/lib/layout/forceAtlas2/body.js +0 -93
- package/lib/layout/forceAtlas2/body.js.map +0 -1
- package/lib/layout/forceAtlas2/index.d.ts +0 -115
- package/lib/layout/forceAtlas2/index.js +0 -509
- package/lib/layout/forceAtlas2/index.js.map +0 -1
- package/lib/layout/forceAtlas2/quad.d.ts +0 -27
- package/lib/layout/forceAtlas2/quad.js +0 -100
- package/lib/layout/forceAtlas2/quad.js.map +0 -1
- package/lib/layout/forceAtlas2/quadTree.d.ts +0 -20
- package/lib/layout/forceAtlas2/quadTree.js +0 -107
- package/lib/layout/forceAtlas2/quadTree.js.map +0 -1
- package/lib/layout/fruchterman.d.ts +0 -73
- package/lib/layout/fruchterman.js +0 -320
- package/lib/layout/fruchterman.js.map +0 -1
- package/lib/layout/gForce.d.ts +0 -96
- package/lib/layout/gForce.js +0 -421
- package/lib/layout/gForce.js.map +0 -1
- package/lib/layout/gpu/fruchterman.d.ts +0 -57
- package/lib/layout/gpu/fruchterman.js +0 -361
- package/lib/layout/gpu/fruchterman.js.map +0 -1
- package/lib/layout/gpu/fruchtermanShader.d.ts +0 -4
- package/lib/layout/gpu/fruchtermanShader.js +0 -8
- package/lib/layout/gpu/fruchtermanShader.js.map +0 -1
- package/lib/layout/gpu/gForce.d.ts +0 -68
- package/lib/layout/gpu/gForce.js +0 -415
- package/lib/layout/gpu/gForce.js.map +0 -1
- package/lib/layout/gpu/gForceShader.d.ts +0 -4
- package/lib/layout/gpu/gForceShader.js +0 -8
- package/lib/layout/gpu/gForceShader.js.map +0 -1
- package/lib/layout/grid.d.ts +0 -83
- package/lib/layout/grid.js +0 -339
- package/lib/layout/grid.js.map +0 -1
- package/lib/layout/index.d.ts +0 -22
- package/lib/layout/index.js +0 -59
- package/lib/layout/index.js.map +0 -1
- package/lib/layout/layout.d.ts +0 -26
- package/lib/layout/layout.js +0 -102
- package/lib/layout/layout.js.map +0 -1
- package/lib/layout/mds.d.ts +0 -39
- package/lib/layout/mds.js +0 -144
- package/lib/layout/mds.js.map +0 -1
- package/lib/layout/radial/index.d.ts +0 -1
- package/lib/layout/radial/index.js +0 -18
- package/lib/layout/radial/index.js.map +0 -1
- package/lib/layout/radial/mds.d.ts +0 -15
- package/lib/layout/radial/mds.js +0 -42
- package/lib/layout/radial/mds.js.map +0 -1
- package/lib/layout/radial/radial.d.ts +0 -74
- package/lib/layout/radial/radial.js +0 -445
- package/lib/layout/radial/radial.js.map +0 -1
- package/lib/layout/radial/radialNonoverlapForce.d.ts +0 -50
- package/lib/layout/radial/radialNonoverlapForce.js +0 -127
- package/lib/layout/radial/radialNonoverlapForce.js.map +0 -1
- package/lib/layout/random.d.ts +0 -35
- package/lib/layout/random.js +0 -84
- package/lib/layout/random.js.map +0 -1
- package/lib/layout/types.d.ts +0 -432
- package/lib/layout/types.js +0 -3
- package/lib/layout/types.js.map +0 -1
- package/lib/registy/index.d.ts +0 -3
- package/lib/registy/index.js +0 -65
- package/lib/registy/index.js.map +0 -1
- package/lib/util/array.js +0 -5
- package/lib/util/array.js.map +0 -1
- package/lib/util/function.js +0 -65
- package/lib/util/function.js.map +0 -1
- package/lib/util/gpu.js +0 -250
- package/lib/util/gpu.js.map +0 -1
- package/lib/util/index.js +0 -23
- package/lib/util/index.js.map +0 -1
- package/lib/util/math.js +0 -289
- package/lib/util/math.js.map +0 -1
- package/lib/util/number.js +0 -13
- package/lib/util/number.js.map +0 -1
- package/lib/util/object.js +0 -43
- package/lib/util/object.js.map +0 -1
- package/lib/util/string.js +0 -20
- package/lib/util/string.js.map +0 -1
- package/src/index.ts +0 -7
- package/src/layout/base.ts +0 -57
- package/src/layout/circular.ts +0 -370
- package/src/layout/comboCombined.ts +0 -397
- package/src/layout/comboForce.ts +0 -873
- package/src/layout/concentric.ts +0 -289
- package/src/layout/constants.ts +0 -22
- package/src/layout/dagre/graph.ts +0 -104
- package/src/layout/dagre/index.ts +0 -31
- package/src/layout/dagre/src/acyclic.ts +0 -58
- package/src/layout/dagre/src/add-border-segments.ts +0 -47
- package/src/layout/dagre/src/coordinate-system.ts +0 -77
- package/src/layout/dagre/src/data/list.ts +0 -60
- package/src/layout/dagre/src/debug.ts +0 -30
- package/src/layout/dagre/src/greedy-fas.ts +0 -144
- package/src/layout/dagre/src/layout.ts +0 -579
- package/src/layout/dagre/src/nesting-graph.ts +0 -143
- package/src/layout/dagre/src/normalize.ts +0 -96
- package/src/layout/dagre/src/order/add-subgraph-constraints.ts +0 -29
- package/src/layout/dagre/src/order/barycenter.ts +0 -26
- package/src/layout/dagre/src/order/build-layer-graph.ts +0 -82
- package/src/layout/dagre/src/order/cross-count.ts +0 -77
- package/src/layout/dagre/src/order/index.ts +0 -105
- package/src/layout/dagre/src/order/init-data-order.ts +0 -27
- package/src/layout/dagre/src/order/init-order.ts +0 -56
- package/src/layout/dagre/src/order/resolve-conflicts.ts +0 -152
- package/src/layout/dagre/src/order/sort-subgraph.ts +0 -105
- package/src/layout/dagre/src/order/sort.ts +0 -76
- package/src/layout/dagre/src/parent-dummy-chains.ts +0 -102
- package/src/layout/dagre/src/position/bk.ts +0 -493
- package/src/layout/dagre/src/position/index.ts +0 -82
- package/src/layout/dagre/src/rank/feasible-tree.ts +0 -165
- package/src/layout/dagre/src/rank/index.ts +0 -54
- package/src/layout/dagre/src/rank/network-simplex.ts +0 -225
- package/src/layout/dagre/src/rank/util.ts +0 -166
- package/src/layout/dagre/src/util.ts +0 -309
- package/src/layout/dagre.ts +0 -460
- package/src/layout/dagreCompound.ts +0 -518
- package/src/layout/er/core.ts +0 -117
- package/src/layout/er/forceGrid.ts +0 -95
- package/src/layout/er/grid.ts +0 -185
- package/src/layout/er/index.ts +0 -68
- package/src/layout/er/mysqlWorkbench.ts +0 -345
- package/src/layout/er/type.ts +0 -39
- package/src/layout/force/force-in-a-box.ts +0 -400
- package/src/layout/force/force.ts +0 -391
- package/src/layout/force/index.ts +0 -1
- package/src/layout/force2/ForceNBody.ts +0 -128
- package/src/layout/force2/index.ts +0 -741
- package/src/layout/forceAtlas2/body.ts +0 -115
- package/src/layout/forceAtlas2/index.ts +0 -556
- package/src/layout/forceAtlas2/quad.ts +0 -115
- package/src/layout/forceAtlas2/quadTree.ts +0 -107
- package/src/layout/fruchterman.ts +0 -361
- package/src/layout/gForce.ts +0 -488
- package/src/layout/gpu/fruchterman.ts +0 -314
- package/src/layout/gpu/fruchtermanShader.ts +0 -203
- package/src/layout/gpu/gForce.ts +0 -407
- package/src/layout/gpu/gForceShader.ts +0 -220
- package/src/layout/grid.ts +0 -404
- package/src/layout/index.ts +0 -47
- package/src/layout/layout.ts +0 -110
- package/src/layout/mds.ts +0 -140
- package/src/layout/radial/index.ts +0 -1
- package/src/layout/radial/mds.ts +0 -51
- package/src/layout/radial/radial.ts +0 -500
- package/src/layout/radial/radialNonoverlapForce.ts +0 -189
- package/src/layout/random.ts +0 -75
- package/src/layout/types.ts +0 -496
- package/src/registy/index.ts +0 -43
- package/src/util/array.ts +0 -1
- package/src/util/function.ts +0 -64
- package/src/util/gpu.ts +0 -256
- package/src/util/index.ts +0 -6
- package/src/util/math.ts +0 -294
- package/src/util/number.ts +0 -8
- package/src/util/object.ts +0 -28
- package/src/util/string.ts +0 -18
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @fileOverview fruchterman layout
|
|
4
|
-
* @author shiwu.wyy@antfin.com
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
import { Base } from "../base";
|
|
16
|
-
import { isNumber } from "../../util";
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import { World } from "@antv/g-webgpu";
|
|
19
|
-
// compile at runtime in dev mode
|
|
20
|
-
import { buildTextureData, attributesToTextureData } from "../../util/gpu";
|
|
21
|
-
// use compiled bundle in prod mode
|
|
22
|
-
import { fruchtermanBundle, clusterBundle } from "./fruchtermanShader";
|
|
23
|
-
import { LAYOUT_MESSAGE } from "../constants";
|
|
24
|
-
/**
|
|
25
|
-
* fruchterman 布局
|
|
26
|
-
*/
|
|
27
|
-
export class FruchtermanGPULayout extends Base {
|
|
28
|
-
constructor(options) {
|
|
29
|
-
super();
|
|
30
|
-
/** 停止迭代的最大迭代数 */
|
|
31
|
-
this.maxIteration = 1000;
|
|
32
|
-
/** 重力大小,影响图的紧凑程度 */
|
|
33
|
-
this.gravity = 10;
|
|
34
|
-
/** 速度 */
|
|
35
|
-
this.speed = 1;
|
|
36
|
-
/** 是否产生聚类力 */
|
|
37
|
-
this.clustering = false;
|
|
38
|
-
/** 根据哪个字段聚类 */
|
|
39
|
-
this.clusterField = "cluster";
|
|
40
|
-
/** 聚类力大小 */
|
|
41
|
-
this.clusterGravity = 10;
|
|
42
|
-
/** 是否启用web worker。前提是在web worker里执行布局,否则无效 */
|
|
43
|
-
this.workerEnabled = false;
|
|
44
|
-
this.nodes = [];
|
|
45
|
-
this.edges = [];
|
|
46
|
-
this.width = 300;
|
|
47
|
-
this.height = 300;
|
|
48
|
-
this.nodeMap = {};
|
|
49
|
-
this.nodeIdxMap = {};
|
|
50
|
-
this.updateCfg(options);
|
|
51
|
-
}
|
|
52
|
-
getDefaultCfg() {
|
|
53
|
-
return {
|
|
54
|
-
maxIteration: 1000,
|
|
55
|
-
gravity: 10,
|
|
56
|
-
speed: 1,
|
|
57
|
-
clustering: false,
|
|
58
|
-
clusterGravity: 10
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 执行布局
|
|
63
|
-
*/
|
|
64
|
-
execute() {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const self = this;
|
|
67
|
-
const nodes = self.nodes;
|
|
68
|
-
if (!nodes || nodes.length === 0) {
|
|
69
|
-
if (self.onLayoutEnd)
|
|
70
|
-
self.onLayoutEnd();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (!self.width && typeof window !== "undefined") {
|
|
74
|
-
self.width = window.innerWidth;
|
|
75
|
-
}
|
|
76
|
-
if (!self.height && typeof window !== "undefined") {
|
|
77
|
-
self.height = window.innerHeight;
|
|
78
|
-
}
|
|
79
|
-
if (!self.center) {
|
|
80
|
-
self.center = [self.width / 2, self.height / 2];
|
|
81
|
-
}
|
|
82
|
-
const center = self.center;
|
|
83
|
-
if (nodes.length === 1) {
|
|
84
|
-
nodes[0].x = center[0];
|
|
85
|
-
nodes[0].y = center[1];
|
|
86
|
-
if (self.onLayoutEnd)
|
|
87
|
-
self.onLayoutEnd();
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const nodeMap = {};
|
|
91
|
-
const nodeIdxMap = {};
|
|
92
|
-
nodes.forEach((node, i) => {
|
|
93
|
-
if (!isNumber(node.x))
|
|
94
|
-
node.x = Math.random() * this.width;
|
|
95
|
-
if (!isNumber(node.y))
|
|
96
|
-
node.y = Math.random() * this.height;
|
|
97
|
-
nodeMap[node.id] = node;
|
|
98
|
-
nodeIdxMap[node.id] = i;
|
|
99
|
-
});
|
|
100
|
-
self.nodeMap = nodeMap;
|
|
101
|
-
self.nodeIdxMap = nodeIdxMap;
|
|
102
|
-
// layout
|
|
103
|
-
yield self.run();
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
executeWithWorker(canvas, ctx) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const self = this;
|
|
109
|
-
const nodes = self.nodes;
|
|
110
|
-
const center = self.center;
|
|
111
|
-
if (!nodes || nodes.length === 0) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (nodes.length === 1) {
|
|
115
|
-
nodes[0].x = center[0];
|
|
116
|
-
nodes[0].y = center[1];
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const nodeMap = {};
|
|
120
|
-
const nodeIdxMap = {};
|
|
121
|
-
nodes.forEach((node, i) => {
|
|
122
|
-
if (!isNumber(node.x))
|
|
123
|
-
node.x = Math.random() * this.width;
|
|
124
|
-
if (!isNumber(node.y))
|
|
125
|
-
node.y = Math.random() * this.height;
|
|
126
|
-
nodeMap[node.id] = node;
|
|
127
|
-
nodeIdxMap[node.id] = i;
|
|
128
|
-
});
|
|
129
|
-
self.nodeMap = nodeMap;
|
|
130
|
-
self.nodeIdxMap = nodeIdxMap;
|
|
131
|
-
// layout
|
|
132
|
-
yield self.run(canvas, ctx);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
run(canvas, ctx) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const self = this;
|
|
138
|
-
const nodes = self.nodes;
|
|
139
|
-
const edges = self.edges;
|
|
140
|
-
const maxIteration = self.maxIteration;
|
|
141
|
-
const center = self.center;
|
|
142
|
-
const area = self.height * self.width;
|
|
143
|
-
let maxDisplace = Math.sqrt(area) / 10;
|
|
144
|
-
const k2 = area / (nodes.length + 1);
|
|
145
|
-
const k = Math.sqrt(k2);
|
|
146
|
-
const speed = self.speed;
|
|
147
|
-
const clustering = self.clustering;
|
|
148
|
-
const { array: attributeArray, count: clusterCount } = attributesToTextureData([self.clusterField], nodes);
|
|
149
|
-
// pushing the fx and fy
|
|
150
|
-
nodes.forEach((node, i) => {
|
|
151
|
-
let fx = 0;
|
|
152
|
-
let fy = 0;
|
|
153
|
-
if (isNumber(node.fx) && isNumber(node.fy)) {
|
|
154
|
-
fx = node.fx || 0.001;
|
|
155
|
-
fy = node.fy || 0.001;
|
|
156
|
-
}
|
|
157
|
-
attributeArray[4 * i + 1] = fx;
|
|
158
|
-
attributeArray[4 * i + 2] = fy;
|
|
159
|
-
});
|
|
160
|
-
const numParticles = nodes.length;
|
|
161
|
-
const { maxEdgePerVetex, array: nodesEdgesArray } = buildTextureData(nodes, edges);
|
|
162
|
-
const workerEnabled = self.workerEnabled;
|
|
163
|
-
let world;
|
|
164
|
-
if (workerEnabled) {
|
|
165
|
-
world = World.create({
|
|
166
|
-
canvas,
|
|
167
|
-
engineOptions: {
|
|
168
|
-
supportCompute: true
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
world = World.create({
|
|
174
|
-
engineOptions: {
|
|
175
|
-
supportCompute: true
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
// compile at runtime in dev mode
|
|
180
|
-
// const compiler = new Compiler()
|
|
181
|
-
// const fruchtermanBundle = compiler.compileBundle(fruchtermanCode)
|
|
182
|
-
// const clusterBundle = compiler.compileBundle(clusterCode)
|
|
183
|
-
// use compiled bundle in prod mode
|
|
184
|
-
// console.log(fruchtermanBundle.toString())
|
|
185
|
-
// console.log(clusterBundle.toString())
|
|
186
|
-
const onLayoutEnd = self.onLayoutEnd;
|
|
187
|
-
const clusterCenters = [];
|
|
188
|
-
for (let i = 0; i < clusterCount; i++) {
|
|
189
|
-
clusterCenters.push(0, 0, 0, 0);
|
|
190
|
-
}
|
|
191
|
-
const kernelFruchterman = world
|
|
192
|
-
.createKernel(fruchtermanBundle)
|
|
193
|
-
.setDispatch([numParticles, 1, 1])
|
|
194
|
-
.setBinding({
|
|
195
|
-
u_Data: nodesEdgesArray,
|
|
196
|
-
u_K: k,
|
|
197
|
-
u_K2: k2,
|
|
198
|
-
u_Gravity: self.gravity,
|
|
199
|
-
u_ClusterGravity: self.clusterGravity || self.gravity || 1,
|
|
200
|
-
u_Speed: speed,
|
|
201
|
-
u_MaxDisplace: maxDisplace,
|
|
202
|
-
u_Clustering: clustering ? 1 : 0,
|
|
203
|
-
u_Center: center,
|
|
204
|
-
u_AttributeArray: attributeArray,
|
|
205
|
-
u_ClusterCenters: clusterCenters,
|
|
206
|
-
MAX_EDGE_PER_VERTEX: maxEdgePerVetex,
|
|
207
|
-
VERTEX_COUNT: numParticles
|
|
208
|
-
});
|
|
209
|
-
let kernelCluster;
|
|
210
|
-
if (clustering) {
|
|
211
|
-
kernelCluster = world
|
|
212
|
-
.createKernel(clusterBundle)
|
|
213
|
-
.setDispatch([clusterCount, 1, 1])
|
|
214
|
-
.setBinding({
|
|
215
|
-
u_Data: nodesEdgesArray,
|
|
216
|
-
u_NodeAttributes: attributeArray,
|
|
217
|
-
u_ClusterCenters: clusterCenters,
|
|
218
|
-
VERTEX_COUNT: numParticles,
|
|
219
|
-
CLUSTER_COUNT: clusterCount
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
const execute = () => __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
for (let i = 0; i < maxIteration; i++) {
|
|
224
|
-
// eslint-disable-next-line no-await-in-loop
|
|
225
|
-
yield kernelFruchterman.execute();
|
|
226
|
-
if (clustering) {
|
|
227
|
-
kernelCluster.setBinding({
|
|
228
|
-
u_Data: kernelFruchterman
|
|
229
|
-
});
|
|
230
|
-
// eslint-disable-next-line no-await-in-loop
|
|
231
|
-
yield kernelCluster.execute();
|
|
232
|
-
kernelFruchterman.setBinding({
|
|
233
|
-
u_ClusterCenters: kernelCluster
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
kernelFruchterman.setBinding({
|
|
237
|
-
u_MaxDisplace: maxDisplace *= 0.99
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const finalParticleData = yield kernelFruchterman.getOutput();
|
|
241
|
-
if (canvas) {
|
|
242
|
-
// 传递数据给主线程
|
|
243
|
-
ctx.postMessage({
|
|
244
|
-
type: LAYOUT_MESSAGE.GPUEND,
|
|
245
|
-
vertexEdgeData: finalParticleData
|
|
246
|
-
// edgeIndexBufferData,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
nodes.forEach((node, i) => {
|
|
251
|
-
const x = finalParticleData[4 * i];
|
|
252
|
-
const y = finalParticleData[4 * i + 1];
|
|
253
|
-
node.x = x;
|
|
254
|
-
node.y = y;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (onLayoutEnd)
|
|
258
|
-
onLayoutEnd();
|
|
259
|
-
});
|
|
260
|
-
yield execute();
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
getType() {
|
|
264
|
-
return "fruchterman-gpu";
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
//# sourceMappingURL=fruchterman.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fruchterman.js","sourceRoot":"","sources":["../../../src/layout/gpu/fruchterman.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;GAGG;;;;;;;;;;AASH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,aAAa;AACb,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,iCAAiC;AACjC,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,mCAAmC;AACnC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAa9C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,IAAI;IAyC5C,YAAY,OAAqC;QAC/C,KAAK,EAAE,CAAC;QAtCV,iBAAiB;QACV,iBAAY,GAAW,IAAI,CAAC;QAEnC,oBAAoB;QACb,YAAO,GAAW,EAAE,CAAC;QAE5B,SAAS;QACF,UAAK,GAAW,CAAC,CAAC;QAEzB,cAAc;QACP,eAAU,GAAY,KAAK,CAAC;QAEnC,eAAe;QACR,iBAAY,GAAW,SAAS,CAAC;QAExC,YAAY;QACL,mBAAc,GA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,uBAAuB;qBACxB,CAAC,CAAC;iBACJ;qBAAM;oBACL,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;wBACxB,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;wBACnC,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;wBACvC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;wBACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC,CAAC,CAAC;iBACJ;gBACD,IAAI,WAAW;oBAAE,WAAW,EAAE,CAAC;YACjC,CAAC,CAAA,CAAC;YAEF,MAAM,OAAO,EAAE,CAAC;QAClB,CAAC;KAAA;IAEM,OAAO;QACZ,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const fruchtermanCode = "\nimport { globalInvocationID } from 'g-webgpu';\nconst MAX_EDGE_PER_VERTEX;\nconst VERTEX_COUNT;\n@numthreads(1, 1, 1)\nclass Fruchterman {\n @in @out\n u_Data: vec4[];\n @in\n u_K: float;\n @in\n u_K2: float;\n \n @in\n u_Center: vec2;\n @in\n u_Gravity: float;\n @in\n u_ClusterGravity: float;\n @in\n u_Speed: float;\n @in\n u_MaxDisplace: float;\n @in\n u_Clustering: float;\n @in\n u_AttributeArray: vec4[];\n @in\n u_ClusterCenters: vec4[];\n calcRepulsive(i: int, currentNode: vec4): vec2 {\n let dx = 0, dy = 0;\n for (let j = 0; j < VERTEX_COUNT; j++) {\n if (i != j) {\n const nextNode = this.u_Data[j];\n const xDist = currentNode[0] - nextNode[0];\n const yDist = currentNode[1] - nextNode[1];\n const dist = (xDist * xDist + yDist * yDist) + 0.01;\n let param = this.u_K2 / dist;\n \n if (dist > 0.0) {\n dx += param * xDist;\n dy += param * yDist;\n if (xDist == 0 && yDist == 0) {\n const sign = i < j ? 1 : -1;\n dx += param * sign;\n dy += param * sign;\n }\n }\n }\n }\n return [dx, dy];\n }\n calcGravity(currentNode: vec4, nodeAttributes: vec4): vec2 { // \n let dx = 0, dy = 0;\n const vx = currentNode[0] - this.u_Center[0];\n const vy = currentNode[1] - this.u_Center[1];\n const gf = 0.01 * this.u_K * this.u_Gravity;\n dx = gf * vx;\n dy = gf * vy;\n if (this.u_Clustering == 1) {\n const clusterIdx = int(nodeAttributes[0]);\n const center = this.u_ClusterCenters[clusterIdx];\n const cvx = currentNode[0] - center[0];\n const cvy = currentNode[1] - center[1];\n const dist = sqrt(cvx * cvx + cvy * cvy) + 0.01;\n const parma = this.u_K * this.u_ClusterGravity / dist;\n dx += parma * cvx;\n dy += parma * cvy;\n }\n return [dx, dy];\n }\n calcAttractive(i: int, currentNode: vec4): vec2 {\n let dx = 0, dy = 0;\n const arr_offset = int(floor(currentNode[2] + 0.5));\n const length = int(floor(currentNode[3] + 0.5));\n const node_buffer: vec4;\n for (let p = 0; p < MAX_EDGE_PER_VERTEX; p++) {\n if (p >= length) break;\n const arr_idx = arr_offset + p;\n // when arr_idx % 4 == 0 update currentNodedx_buffer\n const buf_offset = arr_idx - arr_idx / 4 * 4;\n if (p == 0 || buf_offset == 0) {\n node_buffer = this.u_Data[int(arr_idx / 4)];\n }\n const float_j = buf_offset == 0 ? node_buffer[0] :\n buf_offset == 1 ? node_buffer[1] :\n buf_offset == 2 ? node_buffer[2] :\n node_buffer[3];\n const nextNode = this.u_Data[int(float_j)];\n const xDist = currentNode[0] - nextNode[0];\n const yDist = currentNode[1] - nextNode[1];\n const dist = sqrt(xDist * xDist + yDist * yDist) + 0.01;\n let attractiveF = dist / this.u_K;\n \n if (dist > 0.0) {\n dx -= xDist * attractiveF;\n dy -= yDist * attractiveF;\n if (xDist == 0 && yDist == 0) {\n const sign = i < int(float_j) ? 1 : -1;\n dx -= sign * attractiveF;\n dy -= sign * attractiveF;\n }\n }\n }\n return [dx, dy];\n }\n @main\n compute() {\n const i = globalInvocationID.x;\n const currentNode = this.u_Data[i];\n let dx = 0, dy = 0;\n if (i >= VERTEX_COUNT) {\n this.u_Data[i] = currentNode;\n return;\n }\n\n // [gravity, fx, fy, 0]\n const nodeAttributes = this.u_AttributeArray[i];\n\n if (nodeAttributes[1] != 0 && nodeAttributes[2] != 0) {\n // the node is fixed\n this.u_Data[i] = [\n nodeAttributes[1],\n nodeAttributes[2],\n currentNode[2],\n currentNode[3]\n ];\n return;\n }\n\n // repulsive\n const repulsive = this.calcRepulsive(i, currentNode);\n dx += repulsive[0];\n dy += repulsive[1];\n // attractive\n const attractive = this.calcAttractive(i, currentNode);\n dx += attractive[0];\n dy += attractive[1];\n // gravity\n const gravity = this.calcGravity(currentNode, nodeAttributes);\n dx -= gravity[0];\n dy -= gravity[1];\n // speed\n dx *= this.u_Speed;\n dy *= this.u_Speed;\n\n // move\n const distLength = sqrt(dx * dx + dy * dy);\n if (distLength > 0.0) {\n const limitedDist = min(this.u_MaxDisplace * this.u_Speed, distLength);\n this.u_Data[i] = [\n currentNode[0] + dx / distLength * limitedDist,\n currentNode[1] + dy / distLength * limitedDist,\n currentNode[2],\n currentNode[3]\n ];\n }\n }\n}\n";
|
|
2
|
-
export declare const fruchtermanBundle = "{\"shaders\":{\"WGSL\":\"\",\"GLSL450\":\"\",\"GLSL100\":\"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define MAX_EDGE_PER_VERTEX __DefineValuePlaceholder__MAX_EDGE_PER_VERTEX\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_K;\\nuniform float u_K2;\\nuniform vec2 u_Center;\\nuniform float u_Gravity;\\nuniform float u_ClusterGravity;\\nuniform float u_Speed;\\nuniform float u_MaxDisplace;\\nuniform float u_Clustering;\\nuniform sampler2D u_AttributeArray;\\nuniform vec2 u_AttributeArraySize;\\nvec4 getDatau_AttributeArray(vec2 address2D) {\\n return vec4(texture2D(u_AttributeArray, address2D).rgba);\\n}\\nvec4 getDatau_AttributeArray(float address1D) {\\n return getDatau_AttributeArray(addrTranslation_1Dto2D(address1D, u_AttributeArraySize));\\n}\\nvec4 getDatau_AttributeArray(int address1D) {\\n return getDatau_AttributeArray(float(address1D));\\n}\\nuniform sampler2D u_ClusterCenters;\\nuniform vec2 u_ClusterCentersSize;\\nvec4 getDatau_ClusterCenters(vec2 address2D) {\\n return vec4(texture2D(u_ClusterCenters, address2D).rgba);\\n}\\nvec4 getDatau_ClusterCenters(float address1D) {\\n return getDatau_ClusterCenters(addrTranslation_1Dto2D(address1D, u_ClusterCentersSize));\\n}\\nvec4 getDatau_ClusterCenters(int address1D) {\\n return getDatau_ClusterCenters(float(address1D));\\n}\\nvec2 calcRepulsive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {if (i != j) {vec4 nextNode = getDatau_Data(j);\\nfloat xDist = currentNode.x - nextNode.x;\\nfloat yDist = currentNode.y - nextNode.y;\\nfloat dist = ((xDist * xDist) + (yDist * yDist)) + 0.01;\\nfloat param = u_K2 / dist;\\nif (dist > 0.0) {dx += param * xDist;\\ndy += param * yDist;\\nif ((xDist == 0.0) && (yDist == 0.0)) {float sign = (i < j) ? (1.0) : (-1.0);\\ndx += param * sign;\\ndy += param * sign;}}}}\\nreturn vec2(dx, dy);}\\nvec2 calcGravity(vec4 currentNode, vec4 nodeAttributes) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nfloat vx = currentNode.x - u_Center.x;\\nfloat vy = currentNode.y - u_Center.y;\\nfloat gf = (0.01 * u_K) * u_Gravity;\\ndx = gf * vx;\\ndy = gf * vy;\\nif (u_Clustering == 1.0) {int clusterIdx = int(nodeAttributes.x);\\nvec4 center = getDatau_ClusterCenters(clusterIdx);\\nfloat cvx = currentNode.x - center.x;\\nfloat cvy = currentNode.y - center.y;\\nfloat dist = sqrt((cvx * cvx) + (cvy * cvy)) + 0.01;\\nfloat parma = (u_K * u_ClusterGravity) / dist;\\ndx += parma * cvx;\\ndy += parma * cvy;}\\nreturn vec2(dx, dy);}\\nvec2 calcAttractive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nint arr_offset = int(floor(currentNode.z + 0.5));\\nint length = int(floor(currentNode.w + 0.5));\\nvec4 node_buffer;\\nfor (int p = 0; p < MAX_EDGE_PER_VERTEX; p++) {if (p >= length) {break;}\\nint arr_idx = arr_offset + int(p);\\nint buf_offset = arr_idx - ((arr_idx / 4) * 4);\\nif ((p == 0) || (buf_offset == 0)) {node_buffer = getDatau_Data(int(arr_idx / 4));}\\nfloat float_j = (buf_offset == 0) ? (node_buffer.x) : ((buf_offset == 1) ? (node_buffer.y) : ((buf_offset == 2) ? (node_buffer.z) : (node_buffer.w)));\\nvec4 nextNode = getDatau_Data(int(float_j));\\nfloat xDist = currentNode.x - nextNode.x;\\nfloat yDist = currentNode.y - nextNode.y;\\nfloat dist = sqrt((xDist * xDist) + (yDist * yDist)) + 0.01;\\nfloat attractiveF = dist / u_K;\\nif (dist > 0.0) {dx -= xDist * attractiveF;\\ndy -= yDist * attractiveF;\\nif ((xDist == 0.0) && (yDist == 0.0)) {float sign = (i < int(float_j)) ? (1.0) : (-1.0);\\ndx -= sign * attractiveF;\\ndy -= sign * attractiveF;}}}\\nreturn vec2(dx, dy);}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 currentNode = getDatau_Data(i);\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nif (i >= VERTEX_COUNT) {gl_FragColor = vec4(currentNode);\\nreturn ;}\\nvec4 nodeAttributes = getDatau_AttributeArray(i);\\nif ((nodeAttributes.y != 0.0) && (nodeAttributes.z != 0.0)) {gl_FragColor = vec4(vec4(nodeAttributes.y, nodeAttributes.z, currentNode.z, currentNode.w));\\nreturn ;}\\nvec2 repulsive = calcRepulsive(i, currentNode);\\ndx += repulsive.x;\\ndy += repulsive.y;\\nvec2 attractive = calcAttractive(i, currentNode);\\ndx += attractive.x;\\ndy += attractive.y;\\nvec2 gravity = calcGravity(currentNode, nodeAttributes);\\ndx -= gravity.x;\\ndy -= gravity.y;\\ndx *= u_Speed;\\ndy *= u_Speed;\\nfloat distLength = sqrt((dx * dx) + (dy * dy));\\nif (distLength > 0.0) {float limitedDist = min(u_MaxDisplace * u_Speed, distLength);\\ngl_FragColor = vec4(vec4(currentNode.x + ((dx / distLength) * limitedDist), currentNode.y + ((dy / distLength) * limitedDist), currentNode.z, currentNode.w));}if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n\"},\"context\":{\"name\":\"\",\"dispatch\":[1,1,1],\"threadGroupSize\":[1,1,1],\"maxIteration\":1,\"defines\":[{\"name\":\"MAX_EDGE_PER_VERTEX\",\"type\":\"Float\",\"runtime\":true},{\"name\":\"VERTEX_COUNT\",\"type\":\"Float\",\"runtime\":true}],\"uniforms\":[{\"name\":\"u_Data\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":false,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_K\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_K2\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_Center\",\"type\":\"vec2<f32>\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_Gravity\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_ClusterGravity\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_Speed\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_MaxDisplace\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_Clustering\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_AttributeArray\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_ClusterCenters\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]}],\"globalDeclarations\":[],\"output\":{\"name\":\"u_Data\",\"size\":[1,1],\"length\":1},\"needPingpong\":true}}";
|
|
3
|
-
export declare const clusterCode = "\nimport { globalInvocationID } from 'g-webgpu';\nconst VERTEX_COUNT;\nconst CLUSTER_COUNT;\n@numthreads(1, 1, 1)\nclass CalcCenter {\n @in\n u_Data: vec4[];\n @in\n u_NodeAttributes: vec4[]; // [[clusterIdx, 0, 0, 0], ...]\n @in @out\n u_ClusterCenters: vec4[]; // [[cx, cy, nodeCount, clusterIdx], ...]\n @main\n compute() {\n const i = globalInvocationID.x;\n const center = this.u_ClusterCenters[i];\n let sumx = 0;\n let sumy = 0;\n let count = 0;\n for (let j = 0; j < VERTEX_COUNT; j++) {\n const attributes = this.u_NodeAttributes[j];\n const clusterIdx = int(attributes[0]);\n const vertex = this.u_Data[j];\n if (clusterIdx == i) {\n sumx += vertex.x;\n sumy += vertex.y;\n count += 1;\n }\n }\n this.u_ClusterCenters[i] = [\n sumx / count,\n sumy / count,\n count,\n i\n ];\n }\n}\n";
|
|
4
|
-
export declare const clusterBundle = "{\"shaders\":{\"WGSL\":\"\",\"GLSL450\":\"\",\"GLSL100\":\"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n#define CLUSTER_COUNT __DefineValuePlaceholder__CLUSTER_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform sampler2D u_NodeAttributes;\\nuniform vec2 u_NodeAttributesSize;\\nvec4 getDatau_NodeAttributes(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributes, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributes(float address1D) {\\n return getDatau_NodeAttributes(addrTranslation_1Dto2D(address1D, u_NodeAttributesSize));\\n}\\nvec4 getDatau_NodeAttributes(int address1D) {\\n return getDatau_NodeAttributes(float(address1D));\\n}\\nuniform sampler2D u_ClusterCenters;\\nuniform vec2 u_ClusterCentersSize;\\nvec4 getDatau_ClusterCenters(vec2 address2D) {\\n return vec4(texture2D(u_ClusterCenters, address2D).rgba);\\n}\\nvec4 getDatau_ClusterCenters(float address1D) {\\n return getDatau_ClusterCenters(addrTranslation_1Dto2D(address1D, u_ClusterCentersSize));\\n}\\nvec4 getDatau_ClusterCenters(int address1D) {\\n return getDatau_ClusterCenters(float(address1D));\\n}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 center = getDatau_ClusterCenters(i);\\nfloat sumx = 0.0;\\nfloat sumy = 0.0;\\nfloat count = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {vec4 attributes = getDatau_NodeAttributes(j);\\nint clusterIdx = int(attributes.x);\\nvec4 vertex = getDatau_Data(j);\\nif (clusterIdx == i) {sumx += vertex.x;\\nsumy += vertex.y;\\ncount += 1.0;}}\\ngl_FragColor = vec4(vec4(sumx / count, sumy / count, count, i));if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n\"},\"context\":{\"name\":\"\",\"dispatch\":[1,1,1],\"threadGroupSize\":[1,1,1],\"maxIteration\":1,\"defines\":[{\"name\":\"VERTEX_COUNT\",\"type\":\"Float\",\"runtime\":true},{\"name\":\"CLUSTER_COUNT\",\"type\":\"Float\",\"runtime\":true}],\"uniforms\":[{\"name\":\"u_Data\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_NodeAttributes\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_ClusterCenters\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":false,\"writeonly\":false,\"size\":[1,1]}],\"globalDeclarations\":[],\"output\":{\"name\":\"u_ClusterCenters\",\"size\":[1,1],\"length\":1},\"needPingpong\":true}}";
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
export const fruchtermanCode = `
|
|
2
|
-
import { globalInvocationID } from 'g-webgpu';
|
|
3
|
-
const MAX_EDGE_PER_VERTEX;
|
|
4
|
-
const VERTEX_COUNT;
|
|
5
|
-
@numthreads(1, 1, 1)
|
|
6
|
-
class Fruchterman {
|
|
7
|
-
@in @out
|
|
8
|
-
u_Data: vec4[];
|
|
9
|
-
@in
|
|
10
|
-
u_K: float;
|
|
11
|
-
@in
|
|
12
|
-
u_K2: float;
|
|
13
|
-
|
|
14
|
-
@in
|
|
15
|
-
u_Center: vec2;
|
|
16
|
-
@in
|
|
17
|
-
u_Gravity: float;
|
|
18
|
-
@in
|
|
19
|
-
u_ClusterGravity: float;
|
|
20
|
-
@in
|
|
21
|
-
u_Speed: float;
|
|
22
|
-
@in
|
|
23
|
-
u_MaxDisplace: float;
|
|
24
|
-
@in
|
|
25
|
-
u_Clustering: float;
|
|
26
|
-
@in
|
|
27
|
-
u_AttributeArray: vec4[];
|
|
28
|
-
@in
|
|
29
|
-
u_ClusterCenters: vec4[];
|
|
30
|
-
calcRepulsive(i: int, currentNode: vec4): vec2 {
|
|
31
|
-
let dx = 0, dy = 0;
|
|
32
|
-
for (let j = 0; j < VERTEX_COUNT; j++) {
|
|
33
|
-
if (i != j) {
|
|
34
|
-
const nextNode = this.u_Data[j];
|
|
35
|
-
const xDist = currentNode[0] - nextNode[0];
|
|
36
|
-
const yDist = currentNode[1] - nextNode[1];
|
|
37
|
-
const dist = (xDist * xDist + yDist * yDist) + 0.01;
|
|
38
|
-
let param = this.u_K2 / dist;
|
|
39
|
-
|
|
40
|
-
if (dist > 0.0) {
|
|
41
|
-
dx += param * xDist;
|
|
42
|
-
dy += param * yDist;
|
|
43
|
-
if (xDist == 0 && yDist == 0) {
|
|
44
|
-
const sign = i < j ? 1 : -1;
|
|
45
|
-
dx += param * sign;
|
|
46
|
-
dy += param * sign;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return [dx, dy];
|
|
52
|
-
}
|
|
53
|
-
calcGravity(currentNode: vec4, nodeAttributes: vec4): vec2 { //
|
|
54
|
-
let dx = 0, dy = 0;
|
|
55
|
-
const vx = currentNode[0] - this.u_Center[0];
|
|
56
|
-
const vy = currentNode[1] - this.u_Center[1];
|
|
57
|
-
const gf = 0.01 * this.u_K * this.u_Gravity;
|
|
58
|
-
dx = gf * vx;
|
|
59
|
-
dy = gf * vy;
|
|
60
|
-
if (this.u_Clustering == 1) {
|
|
61
|
-
const clusterIdx = int(nodeAttributes[0]);
|
|
62
|
-
const center = this.u_ClusterCenters[clusterIdx];
|
|
63
|
-
const cvx = currentNode[0] - center[0];
|
|
64
|
-
const cvy = currentNode[1] - center[1];
|
|
65
|
-
const dist = sqrt(cvx * cvx + cvy * cvy) + 0.01;
|
|
66
|
-
const parma = this.u_K * this.u_ClusterGravity / dist;
|
|
67
|
-
dx += parma * cvx;
|
|
68
|
-
dy += parma * cvy;
|
|
69
|
-
}
|
|
70
|
-
return [dx, dy];
|
|
71
|
-
}
|
|
72
|
-
calcAttractive(i: int, currentNode: vec4): vec2 {
|
|
73
|
-
let dx = 0, dy = 0;
|
|
74
|
-
const arr_offset = int(floor(currentNode[2] + 0.5));
|
|
75
|
-
const length = int(floor(currentNode[3] + 0.5));
|
|
76
|
-
const node_buffer: vec4;
|
|
77
|
-
for (let p = 0; p < MAX_EDGE_PER_VERTEX; p++) {
|
|
78
|
-
if (p >= length) break;
|
|
79
|
-
const arr_idx = arr_offset + p;
|
|
80
|
-
// when arr_idx % 4 == 0 update currentNodedx_buffer
|
|
81
|
-
const buf_offset = arr_idx - arr_idx / 4 * 4;
|
|
82
|
-
if (p == 0 || buf_offset == 0) {
|
|
83
|
-
node_buffer = this.u_Data[int(arr_idx / 4)];
|
|
84
|
-
}
|
|
85
|
-
const float_j = buf_offset == 0 ? node_buffer[0] :
|
|
86
|
-
buf_offset == 1 ? node_buffer[1] :
|
|
87
|
-
buf_offset == 2 ? node_buffer[2] :
|
|
88
|
-
node_buffer[3];
|
|
89
|
-
const nextNode = this.u_Data[int(float_j)];
|
|
90
|
-
const xDist = currentNode[0] - nextNode[0];
|
|
91
|
-
const yDist = currentNode[1] - nextNode[1];
|
|
92
|
-
const dist = sqrt(xDist * xDist + yDist * yDist) + 0.01;
|
|
93
|
-
let attractiveF = dist / this.u_K;
|
|
94
|
-
|
|
95
|
-
if (dist > 0.0) {
|
|
96
|
-
dx -= xDist * attractiveF;
|
|
97
|
-
dy -= yDist * attractiveF;
|
|
98
|
-
if (xDist == 0 && yDist == 0) {
|
|
99
|
-
const sign = i < int(float_j) ? 1 : -1;
|
|
100
|
-
dx -= sign * attractiveF;
|
|
101
|
-
dy -= sign * attractiveF;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return [dx, dy];
|
|
106
|
-
}
|
|
107
|
-
@main
|
|
108
|
-
compute() {
|
|
109
|
-
const i = globalInvocationID.x;
|
|
110
|
-
const currentNode = this.u_Data[i];
|
|
111
|
-
let dx = 0, dy = 0;
|
|
112
|
-
if (i >= VERTEX_COUNT) {
|
|
113
|
-
this.u_Data[i] = currentNode;
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// [gravity, fx, fy, 0]
|
|
118
|
-
const nodeAttributes = this.u_AttributeArray[i];
|
|
119
|
-
|
|
120
|
-
if (nodeAttributes[1] != 0 && nodeAttributes[2] != 0) {
|
|
121
|
-
// the node is fixed
|
|
122
|
-
this.u_Data[i] = [
|
|
123
|
-
nodeAttributes[1],
|
|
124
|
-
nodeAttributes[2],
|
|
125
|
-
currentNode[2],
|
|
126
|
-
currentNode[3]
|
|
127
|
-
];
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// repulsive
|
|
132
|
-
const repulsive = this.calcRepulsive(i, currentNode);
|
|
133
|
-
dx += repulsive[0];
|
|
134
|
-
dy += repulsive[1];
|
|
135
|
-
// attractive
|
|
136
|
-
const attractive = this.calcAttractive(i, currentNode);
|
|
137
|
-
dx += attractive[0];
|
|
138
|
-
dy += attractive[1];
|
|
139
|
-
// gravity
|
|
140
|
-
const gravity = this.calcGravity(currentNode, nodeAttributes);
|
|
141
|
-
dx -= gravity[0];
|
|
142
|
-
dy -= gravity[1];
|
|
143
|
-
// speed
|
|
144
|
-
dx *= this.u_Speed;
|
|
145
|
-
dy *= this.u_Speed;
|
|
146
|
-
|
|
147
|
-
// move
|
|
148
|
-
const distLength = sqrt(dx * dx + dy * dy);
|
|
149
|
-
if (distLength > 0.0) {
|
|
150
|
-
const limitedDist = min(this.u_MaxDisplace * this.u_Speed, distLength);
|
|
151
|
-
this.u_Data[i] = [
|
|
152
|
-
currentNode[0] + dx / distLength * limitedDist,
|
|
153
|
-
currentNode[1] + dy / distLength * limitedDist,
|
|
154
|
-
currentNode[2],
|
|
155
|
-
currentNode[3]
|
|
156
|
-
];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
`;
|
|
161
|
-
export const fruchtermanBundle = `{"shaders":{"WGSL":"","GLSL450":"","GLSL100":"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define MAX_EDGE_PER_VERTEX __DefineValuePlaceholder__MAX_EDGE_PER_VERTEX\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_K;\\nuniform float u_K2;\\nuniform vec2 u_Center;\\nuniform float u_Gravity;\\nuniform float u_ClusterGravity;\\nuniform float u_Speed;\\nuniform float u_MaxDisplace;\\nuniform float u_Clustering;\\nuniform sampler2D u_AttributeArray;\\nuniform vec2 u_AttributeArraySize;\\nvec4 getDatau_AttributeArray(vec2 address2D) {\\n return vec4(texture2D(u_AttributeArray, address2D).rgba);\\n}\\nvec4 getDatau_AttributeArray(float address1D) {\\n return getDatau_AttributeArray(addrTranslation_1Dto2D(address1D, u_AttributeArraySize));\\n}\\nvec4 getDatau_AttributeArray(int address1D) {\\n return getDatau_AttributeArray(float(address1D));\\n}\\nuniform sampler2D u_ClusterCenters;\\nuniform vec2 u_ClusterCentersSize;\\nvec4 getDatau_ClusterCenters(vec2 address2D) {\\n return vec4(texture2D(u_ClusterCenters, address2D).rgba);\\n}\\nvec4 getDatau_ClusterCenters(float address1D) {\\n return getDatau_ClusterCenters(addrTranslation_1Dto2D(address1D, u_ClusterCentersSize));\\n}\\nvec4 getDatau_ClusterCenters(int address1D) {\\n return getDatau_ClusterCenters(float(address1D));\\n}\\nvec2 calcRepulsive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {if (i != j) {vec4 nextNode = getDatau_Data(j);\\nfloat xDist = currentNode.x - nextNode.x;\\nfloat yDist = currentNode.y - nextNode.y;\\nfloat dist = ((xDist * xDist) + (yDist * yDist)) + 0.01;\\nfloat param = u_K2 / dist;\\nif (dist > 0.0) {dx += param * xDist;\\ndy += param * yDist;\\nif ((xDist == 0.0) && (yDist == 0.0)) {float sign = (i < j) ? (1.0) : (-1.0);\\ndx += param * sign;\\ndy += param * sign;}}}}\\nreturn vec2(dx, dy);}\\nvec2 calcGravity(vec4 currentNode, vec4 nodeAttributes) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nfloat vx = currentNode.x - u_Center.x;\\nfloat vy = currentNode.y - u_Center.y;\\nfloat gf = (0.01 * u_K) * u_Gravity;\\ndx = gf * vx;\\ndy = gf * vy;\\nif (u_Clustering == 1.0) {int clusterIdx = int(nodeAttributes.x);\\nvec4 center = getDatau_ClusterCenters(clusterIdx);\\nfloat cvx = currentNode.x - center.x;\\nfloat cvy = currentNode.y - center.y;\\nfloat dist = sqrt((cvx * cvx) + (cvy * cvy)) + 0.01;\\nfloat parma = (u_K * u_ClusterGravity) / dist;\\ndx += parma * cvx;\\ndy += parma * cvy;}\\nreturn vec2(dx, dy);}\\nvec2 calcAttractive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nint arr_offset = int(floor(currentNode.z + 0.5));\\nint length = int(floor(currentNode.w + 0.5));\\nvec4 node_buffer;\\nfor (int p = 0; p < MAX_EDGE_PER_VERTEX; p++) {if (p >= length) {break;}\\nint arr_idx = arr_offset + int(p);\\nint buf_offset = arr_idx - ((arr_idx / 4) * 4);\\nif ((p == 0) || (buf_offset == 0)) {node_buffer = getDatau_Data(int(arr_idx / 4));}\\nfloat float_j = (buf_offset == 0) ? (node_buffer.x) : ((buf_offset == 1) ? (node_buffer.y) : ((buf_offset == 2) ? (node_buffer.z) : (node_buffer.w)));\\nvec4 nextNode = getDatau_Data(int(float_j));\\nfloat xDist = currentNode.x - nextNode.x;\\nfloat yDist = currentNode.y - nextNode.y;\\nfloat dist = sqrt((xDist * xDist) + (yDist * yDist)) + 0.01;\\nfloat attractiveF = dist / u_K;\\nif (dist > 0.0) {dx -= xDist * attractiveF;\\ndy -= yDist * attractiveF;\\nif ((xDist == 0.0) && (yDist == 0.0)) {float sign = (i < int(float_j)) ? (1.0) : (-1.0);\\ndx -= sign * attractiveF;\\ndy -= sign * attractiveF;}}}\\nreturn vec2(dx, dy);}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 currentNode = getDatau_Data(i);\\nfloat dx = 0.0;\\nfloat dy = 0.0;\\nif (i >= VERTEX_COUNT) {gl_FragColor = vec4(currentNode);\\nreturn ;}\\nvec4 nodeAttributes = getDatau_AttributeArray(i);\\nif ((nodeAttributes.y != 0.0) && (nodeAttributes.z != 0.0)) {gl_FragColor = vec4(vec4(nodeAttributes.y, nodeAttributes.z, currentNode.z, currentNode.w));\\nreturn ;}\\nvec2 repulsive = calcRepulsive(i, currentNode);\\ndx += repulsive.x;\\ndy += repulsive.y;\\nvec2 attractive = calcAttractive(i, currentNode);\\ndx += attractive.x;\\ndy += attractive.y;\\nvec2 gravity = calcGravity(currentNode, nodeAttributes);\\ndx -= gravity.x;\\ndy -= gravity.y;\\ndx *= u_Speed;\\ndy *= u_Speed;\\nfloat distLength = sqrt((dx * dx) + (dy * dy));\\nif (distLength > 0.0) {float limitedDist = min(u_MaxDisplace * u_Speed, distLength);\\ngl_FragColor = vec4(vec4(currentNode.x + ((dx / distLength) * limitedDist), currentNode.y + ((dy / distLength) * limitedDist), currentNode.z, currentNode.w));}if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n"},"context":{"name":"","dispatch":[1,1,1],"threadGroupSize":[1,1,1],"maxIteration":1,"defines":[{"name":"MAX_EDGE_PER_VERTEX","type":"Float","runtime":true},{"name":"VERTEX_COUNT","type":"Float","runtime":true}],"uniforms":[{"name":"u_Data","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":false,"writeonly":false,"size":[1,1]},{"name":"u_K","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_K2","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_Center","type":"vec2<f32>","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_Gravity","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_ClusterGravity","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_Speed","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_MaxDisplace","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_Clustering","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_AttributeArray","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_ClusterCenters","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]}],"globalDeclarations":[],"output":{"name":"u_Data","size":[1,1],"length":1},"needPingpong":true}}`;
|
|
162
|
-
export const clusterCode = `
|
|
163
|
-
import { globalInvocationID } from 'g-webgpu';
|
|
164
|
-
const VERTEX_COUNT;
|
|
165
|
-
const CLUSTER_COUNT;
|
|
166
|
-
@numthreads(1, 1, 1)
|
|
167
|
-
class CalcCenter {
|
|
168
|
-
@in
|
|
169
|
-
u_Data: vec4[];
|
|
170
|
-
@in
|
|
171
|
-
u_NodeAttributes: vec4[]; // [[clusterIdx, 0, 0, 0], ...]
|
|
172
|
-
@in @out
|
|
173
|
-
u_ClusterCenters: vec4[]; // [[cx, cy, nodeCount, clusterIdx], ...]
|
|
174
|
-
@main
|
|
175
|
-
compute() {
|
|
176
|
-
const i = globalInvocationID.x;
|
|
177
|
-
const center = this.u_ClusterCenters[i];
|
|
178
|
-
let sumx = 0;
|
|
179
|
-
let sumy = 0;
|
|
180
|
-
let count = 0;
|
|
181
|
-
for (let j = 0; j < VERTEX_COUNT; j++) {
|
|
182
|
-
const attributes = this.u_NodeAttributes[j];
|
|
183
|
-
const clusterIdx = int(attributes[0]);
|
|
184
|
-
const vertex = this.u_Data[j];
|
|
185
|
-
if (clusterIdx == i) {
|
|
186
|
-
sumx += vertex.x;
|
|
187
|
-
sumy += vertex.y;
|
|
188
|
-
count += 1;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
this.u_ClusterCenters[i] = [
|
|
192
|
-
sumx / count,
|
|
193
|
-
sumy / count,
|
|
194
|
-
count,
|
|
195
|
-
i
|
|
196
|
-
];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
`;
|
|
200
|
-
export const clusterBundle = `{"shaders":{"WGSL":"","GLSL450":"","GLSL100":"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n#define CLUSTER_COUNT __DefineValuePlaceholder__CLUSTER_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform sampler2D u_NodeAttributes;\\nuniform vec2 u_NodeAttributesSize;\\nvec4 getDatau_NodeAttributes(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributes, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributes(float address1D) {\\n return getDatau_NodeAttributes(addrTranslation_1Dto2D(address1D, u_NodeAttributesSize));\\n}\\nvec4 getDatau_NodeAttributes(int address1D) {\\n return getDatau_NodeAttributes(float(address1D));\\n}\\nuniform sampler2D u_ClusterCenters;\\nuniform vec2 u_ClusterCentersSize;\\nvec4 getDatau_ClusterCenters(vec2 address2D) {\\n return vec4(texture2D(u_ClusterCenters, address2D).rgba);\\n}\\nvec4 getDatau_ClusterCenters(float address1D) {\\n return getDatau_ClusterCenters(addrTranslation_1Dto2D(address1D, u_ClusterCentersSize));\\n}\\nvec4 getDatau_ClusterCenters(int address1D) {\\n return getDatau_ClusterCenters(float(address1D));\\n}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 center = getDatau_ClusterCenters(i);\\nfloat sumx = 0.0;\\nfloat sumy = 0.0;\\nfloat count = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {vec4 attributes = getDatau_NodeAttributes(j);\\nint clusterIdx = int(attributes.x);\\nvec4 vertex = getDatau_Data(j);\\nif (clusterIdx == i) {sumx += vertex.x;\\nsumy += vertex.y;\\ncount += 1.0;}}\\ngl_FragColor = vec4(vec4(sumx / count, sumy / count, count, i));if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n"},"context":{"name":"","dispatch":[1,1,1],"threadGroupSize":[1,1,1],"maxIteration":1,"defines":[{"name":"VERTEX_COUNT","type":"Float","runtime":true},{"name":"CLUSTER_COUNT","type":"Float","runtime":true}],"uniforms":[{"name":"u_Data","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_NodeAttributes","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_ClusterCenters","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":false,"writeonly":false,"size":[1,1]}],"globalDeclarations":[],"output":{"name":"u_ClusterCenters","size":[1,1],"length":1},"needPingpong":true}}`;
|
|
201
|
-
//# sourceMappingURL=fruchtermanShader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fruchtermanShader.js","sourceRoot":"","sources":["../../../src/layout/gpu/fruchtermanShader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+J9B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,0xXAA0xX,CAAC;AAE5zX,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC1B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,0xIAA0xI,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileOverview fruchterman layout
|
|
3
|
-
* @author shiwu.wyy@antfin.com
|
|
4
|
-
*/
|
|
5
|
-
import { IndexMap, OutNode, PointTuple, Edge, GForceGPULayoutOptions } from "../types";
|
|
6
|
-
import { Base } from "../base";
|
|
7
|
-
type NodeMap = {
|
|
8
|
-
[key: string]: OutNode;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* graphin 中的 force 布局
|
|
12
|
-
*/
|
|
13
|
-
export declare class GForceGPULayout extends Base {
|
|
14
|
-
/** 布局中心 */
|
|
15
|
-
center: PointTuple;
|
|
16
|
-
/** 停止迭代的最大迭代数 */
|
|
17
|
-
maxIteration: number;
|
|
18
|
-
/** 弹簧引力系数 */
|
|
19
|
-
edgeStrength: number | ((d?: any) => number) | undefined;
|
|
20
|
-
/** 斥力系数 */
|
|
21
|
-
nodeStrength: number | ((d?: any) => number) | undefined;
|
|
22
|
-
/** 库伦系数 */
|
|
23
|
-
coulombDisScale: number;
|
|
24
|
-
/** 阻尼系数 */
|
|
25
|
-
damping: number;
|
|
26
|
-
/** 最大速度 */
|
|
27
|
-
maxSpeed: number;
|
|
28
|
-
/** 一次迭代的平均移动距离小于该值时停止迭代 */
|
|
29
|
-
minMovement: number;
|
|
30
|
-
/** 迭代中衰减 */
|
|
31
|
-
interval: number;
|
|
32
|
-
/** 斥力的一个系数 */
|
|
33
|
-
factor: number;
|
|
34
|
-
/** 每个节点质量的回调函数,若不指定,则默认使用度数作为节点质量 */
|
|
35
|
-
getMass: ((d?: any) => number) | undefined;
|
|
36
|
-
/** 理想边长 */
|
|
37
|
-
linkDistance: number | ((d?: any) => number) | undefined;
|
|
38
|
-
/** 重力大小 */
|
|
39
|
-
gravity: number;
|
|
40
|
-
/** 每个节点中心力的 x、y、强度的回调函数,若不指定,则没有额外中心力 */
|
|
41
|
-
getCenter: ((d?: any, degree?: number) => number[]) | undefined;
|
|
42
|
-
/** 是否启用web worker。前提是在web worker里执行布局,否则无效 */
|
|
43
|
-
workerEnabled: boolean;
|
|
44
|
-
nodes: OutNode[];
|
|
45
|
-
edges: Edge[];
|
|
46
|
-
width: number;
|
|
47
|
-
height: number;
|
|
48
|
-
nodeMap: NodeMap;
|
|
49
|
-
nodeIdxMap: IndexMap;
|
|
50
|
-
onLayoutEnd: () => void;
|
|
51
|
-
/** 存储节点度数 */
|
|
52
|
-
private degrees;
|
|
53
|
-
constructor(options?: GForceGPULayoutOptions);
|
|
54
|
-
getDefaultCfg(): {
|
|
55
|
-
maxIteration: number;
|
|
56
|
-
gravity: number;
|
|
57
|
-
clustering: boolean;
|
|
58
|
-
clusterGravity: number;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* 执行布局
|
|
62
|
-
*/
|
|
63
|
-
execute(): Promise<void>;
|
|
64
|
-
executeWithWorker(canvas?: HTMLCanvasElement, ctx?: any): void;
|
|
65
|
-
run(canvas?: HTMLCanvasElement, ctx?: any): Promise<void>;
|
|
66
|
-
getType(): string;
|
|
67
|
-
}
|
|
68
|
-
export {};
|