@antv/layout 0.3.11 → 1.0.0-alpha.0
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 +3 -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 +9 -4
- 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 -348
- 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 -43
- package/es/util/math.js +0 -253
- 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 -384
- 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 -266
- 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 -391
- 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 -272
- package/src/util/number.ts +0 -8
- package/src/util/object.ts +0 -28
- package/src/util/string.ts +0 -18
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @fileOverview fruchterman layout
|
|
4
|
-
* @author shiwu.wyy@antfin.com
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
OutNode,
|
|
9
|
-
Edge,
|
|
10
|
-
PointTuple,
|
|
11
|
-
IndexMap,
|
|
12
|
-
FruchtermanGPULayoutOptions
|
|
13
|
-
} from "../types";
|
|
14
|
-
import { Base } from "../base";
|
|
15
|
-
import { isNumber } from "../../util";
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
import { World } from "@antv/g-webgpu";
|
|
18
|
-
// compile at runtime in dev mode
|
|
19
|
-
import { buildTextureData, attributesToTextureData } from "../../util/gpu";
|
|
20
|
-
// use compiled bundle in prod mode
|
|
21
|
-
import { fruchtermanBundle, clusterBundle } from "./fruchtermanShader";
|
|
22
|
-
import { LAYOUT_MESSAGE } from "../constants";
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
// import { Compiler } from '@antv/g-webgpu-compiler'
|
|
25
|
-
// import { fruchtermanCode, clusterCode } from './fruchtermanShader'
|
|
26
|
-
|
|
27
|
-
type INode = OutNode & {
|
|
28
|
-
cluster: string | number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type NodeMap = {
|
|
32
|
-
[key: string]: INode;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* fruchterman 布局
|
|
37
|
-
*/
|
|
38
|
-
export class FruchtermanGPULayout extends Base {
|
|
39
|
-
/** 布局中心 */
|
|
40
|
-
public center: PointTuple;
|
|
41
|
-
|
|
42
|
-
/** 停止迭代的最大迭代数 */
|
|
43
|
-
public maxIteration: number = 1000;
|
|
44
|
-
|
|
45
|
-
/** 重力大小,影响图的紧凑程度 */
|
|
46
|
-
public gravity: number = 10;
|
|
47
|
-
|
|
48
|
-
/** 速度 */
|
|
49
|
-
public speed: number = 1;
|
|
50
|
-
|
|
51
|
-
/** 是否产生聚类力 */
|
|
52
|
-
public clustering: boolean = false;
|
|
53
|
-
|
|
54
|
-
/** 根据哪个字段聚类 */
|
|
55
|
-
public clusterField: string = "cluster";
|
|
56
|
-
|
|
57
|
-
/** 聚类力大小 */
|
|
58
|
-
public clusterGravity: number = 10;
|
|
59
|
-
|
|
60
|
-
/** 是否启用web worker。前提是在web worker里执行布局,否则无效 */
|
|
61
|
-
public workerEnabled: boolean = false;
|
|
62
|
-
|
|
63
|
-
public nodes: INode[] = [];
|
|
64
|
-
|
|
65
|
-
public edges: Edge[] = [];
|
|
66
|
-
|
|
67
|
-
public width: number = 300;
|
|
68
|
-
|
|
69
|
-
public height: number = 300;
|
|
70
|
-
|
|
71
|
-
public nodeMap: NodeMap = {};
|
|
72
|
-
|
|
73
|
-
public nodeIdxMap: IndexMap = {};
|
|
74
|
-
|
|
75
|
-
public canvasEl: HTMLCanvasElement;
|
|
76
|
-
|
|
77
|
-
public onLayoutEnd: () => void;
|
|
78
|
-
|
|
79
|
-
constructor(options?: FruchtermanGPULayoutOptions) {
|
|
80
|
-
super();
|
|
81
|
-
this.updateCfg(options);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public getDefaultCfg() {
|
|
85
|
-
return {
|
|
86
|
-
maxIteration: 1000,
|
|
87
|
-
gravity: 10,
|
|
88
|
-
speed: 1,
|
|
89
|
-
clustering: false,
|
|
90
|
-
clusterGravity: 10
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 执行布局
|
|
96
|
-
*/
|
|
97
|
-
public async execute() {
|
|
98
|
-
const self = this;
|
|
99
|
-
const nodes = self.nodes;
|
|
100
|
-
|
|
101
|
-
if (!nodes || nodes.length === 0) {
|
|
102
|
-
if (self.onLayoutEnd) self.onLayoutEnd();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (!self.width && typeof window !== "undefined") {
|
|
106
|
-
self.width = window.innerWidth;
|
|
107
|
-
}
|
|
108
|
-
if (!self.height && typeof window !== "undefined") {
|
|
109
|
-
self.height = window.innerHeight;
|
|
110
|
-
}
|
|
111
|
-
if (!self.center) {
|
|
112
|
-
self.center = [self.width / 2, self.height / 2];
|
|
113
|
-
}
|
|
114
|
-
const center = self.center;
|
|
115
|
-
if (nodes.length === 1) {
|
|
116
|
-
nodes[0].x = center[0];
|
|
117
|
-
nodes[0].y = center[1];
|
|
118
|
-
if (self.onLayoutEnd) self.onLayoutEnd();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const nodeMap: NodeMap = {};
|
|
122
|
-
const nodeIdxMap: IndexMap = {};
|
|
123
|
-
nodes.forEach((node, i) => {
|
|
124
|
-
if (!isNumber(node.x)) node.x = Math.random() * this.width;
|
|
125
|
-
if (!isNumber(node.y)) 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
|
-
await self.run();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public async executeWithWorker(canvas?: HTMLCanvasElement, ctx?: any) {
|
|
136
|
-
const self = this;
|
|
137
|
-
const nodes = self.nodes;
|
|
138
|
-
const center = self.center;
|
|
139
|
-
|
|
140
|
-
if (!nodes || nodes.length === 0) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (nodes.length === 1) {
|
|
144
|
-
nodes[0].x = center[0];
|
|
145
|
-
nodes[0].y = center[1];
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const nodeMap: NodeMap = {};
|
|
149
|
-
const nodeIdxMap: IndexMap = {};
|
|
150
|
-
nodes.forEach((node, i) => {
|
|
151
|
-
if (!isNumber(node.x)) node.x = Math.random() * this.width;
|
|
152
|
-
if (!isNumber(node.y)) node.y = Math.random() * this.height;
|
|
153
|
-
nodeMap[node.id] = node;
|
|
154
|
-
nodeIdxMap[node.id] = i;
|
|
155
|
-
});
|
|
156
|
-
self.nodeMap = nodeMap;
|
|
157
|
-
self.nodeIdxMap = nodeIdxMap;
|
|
158
|
-
// layout
|
|
159
|
-
await self.run(canvas, ctx);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public async run(canvas?: HTMLCanvasElement, ctx?: any) {
|
|
163
|
-
const self = this;
|
|
164
|
-
const nodes = self.nodes;
|
|
165
|
-
const edges = self.edges;
|
|
166
|
-
const maxIteration = self.maxIteration;
|
|
167
|
-
const center = self.center;
|
|
168
|
-
const area = self.height * self.width;
|
|
169
|
-
let maxDisplace = Math.sqrt(area) / 10;
|
|
170
|
-
const k2 = area / (nodes.length + 1);
|
|
171
|
-
const k = Math.sqrt(k2);
|
|
172
|
-
const speed = self.speed;
|
|
173
|
-
const clustering = self.clustering;
|
|
174
|
-
|
|
175
|
-
const {
|
|
176
|
-
array: attributeArray,
|
|
177
|
-
count: clusterCount
|
|
178
|
-
} = attributesToTextureData([self.clusterField], nodes);
|
|
179
|
-
|
|
180
|
-
// pushing the fx and fy
|
|
181
|
-
nodes.forEach((node, i) => {
|
|
182
|
-
let fx = 0;
|
|
183
|
-
let fy = 0;
|
|
184
|
-
if (isNumber(node.fx) && isNumber(node.fy)) {
|
|
185
|
-
fx = node.fx || 0.001;
|
|
186
|
-
fy = node.fy || 0.001;
|
|
187
|
-
}
|
|
188
|
-
attributeArray[4 * i + 1] = fx;
|
|
189
|
-
attributeArray[4 * i + 2] = fy;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const numParticles = nodes.length;
|
|
194
|
-
const { maxEdgePerVetex, array: nodesEdgesArray } = buildTextureData(
|
|
195
|
-
nodes,
|
|
196
|
-
edges
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
const workerEnabled = self.workerEnabled;
|
|
200
|
-
|
|
201
|
-
let world;
|
|
202
|
-
|
|
203
|
-
if (workerEnabled) {
|
|
204
|
-
world = World.create({
|
|
205
|
-
canvas,
|
|
206
|
-
engineOptions: {
|
|
207
|
-
supportCompute: true
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
} else {
|
|
211
|
-
world = World.create({
|
|
212
|
-
engineOptions: {
|
|
213
|
-
supportCompute: true
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// compile at runtime in dev mode
|
|
219
|
-
// const compiler = new Compiler()
|
|
220
|
-
// const fruchtermanBundle = compiler.compileBundle(fruchtermanCode)
|
|
221
|
-
// const clusterBundle = compiler.compileBundle(clusterCode)
|
|
222
|
-
|
|
223
|
-
// use compiled bundle in prod mode
|
|
224
|
-
// console.log(fruchtermanBundle.toString())
|
|
225
|
-
// console.log(clusterBundle.toString())
|
|
226
|
-
|
|
227
|
-
const onLayoutEnd = self.onLayoutEnd;
|
|
228
|
-
|
|
229
|
-
const clusterCenters = [];
|
|
230
|
-
for (let i = 0; i < clusterCount; i++) {
|
|
231
|
-
clusterCenters.push(0, 0, 0, 0);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const kernelFruchterman = world
|
|
235
|
-
.createKernel(fruchtermanBundle)
|
|
236
|
-
.setDispatch([numParticles, 1, 1])
|
|
237
|
-
.setBinding({
|
|
238
|
-
u_Data: nodesEdgesArray,
|
|
239
|
-
u_K: k,
|
|
240
|
-
u_K2: k2,
|
|
241
|
-
u_Gravity: self.gravity,
|
|
242
|
-
u_ClusterGravity: self.clusterGravity || self.gravity || 1,
|
|
243
|
-
u_Speed: speed,
|
|
244
|
-
u_MaxDisplace: maxDisplace,
|
|
245
|
-
u_Clustering: clustering ? 1 : 0,
|
|
246
|
-
u_Center: center,
|
|
247
|
-
u_AttributeArray: attributeArray,
|
|
248
|
-
u_ClusterCenters: clusterCenters,
|
|
249
|
-
MAX_EDGE_PER_VERTEX: maxEdgePerVetex,
|
|
250
|
-
VERTEX_COUNT: numParticles
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
let kernelCluster: any;
|
|
254
|
-
if (clustering) {
|
|
255
|
-
kernelCluster = world
|
|
256
|
-
.createKernel(clusterBundle)
|
|
257
|
-
.setDispatch([clusterCount, 1, 1])
|
|
258
|
-
.setBinding({
|
|
259
|
-
u_Data: nodesEdgesArray,
|
|
260
|
-
u_NodeAttributes: attributeArray,
|
|
261
|
-
u_ClusterCenters: clusterCenters,
|
|
262
|
-
VERTEX_COUNT: numParticles,
|
|
263
|
-
CLUSTER_COUNT: clusterCount
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const execute = async () => {
|
|
268
|
-
for (let i = 0; i < maxIteration; i++) {
|
|
269
|
-
// eslint-disable-next-line no-await-in-loop
|
|
270
|
-
await kernelFruchterman.execute();
|
|
271
|
-
|
|
272
|
-
if (clustering) {
|
|
273
|
-
kernelCluster.setBinding({
|
|
274
|
-
u_Data: kernelFruchterman
|
|
275
|
-
});
|
|
276
|
-
// eslint-disable-next-line no-await-in-loop
|
|
277
|
-
await kernelCluster.execute();
|
|
278
|
-
kernelFruchterman.setBinding({
|
|
279
|
-
u_ClusterCenters: kernelCluster
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
kernelFruchterman.setBinding({
|
|
284
|
-
u_MaxDisplace: maxDisplace *= 0.99
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const finalParticleData = await kernelFruchterman.getOutput();
|
|
289
|
-
|
|
290
|
-
if (canvas) {
|
|
291
|
-
// 传递数据给主线程
|
|
292
|
-
ctx.postMessage({
|
|
293
|
-
type: LAYOUT_MESSAGE.GPUEND,
|
|
294
|
-
vertexEdgeData: finalParticleData
|
|
295
|
-
// edgeIndexBufferData,
|
|
296
|
-
});
|
|
297
|
-
} else {
|
|
298
|
-
nodes.forEach((node, i) => {
|
|
299
|
-
const x = finalParticleData[4 * i];
|
|
300
|
-
const y = finalParticleData[4 * i + 1];
|
|
301
|
-
node.x = x;
|
|
302
|
-
node.y = y;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
if (onLayoutEnd) onLayoutEnd();
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
await execute();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
public getType() {
|
|
312
|
-
return "fruchterman-gpu";
|
|
313
|
-
}
|
|
314
|
-
}
|
|
@@ -1,203 +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
|
-
|
|
162
|
-
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}}`;
|
|
163
|
-
|
|
164
|
-
export const clusterCode = `
|
|
165
|
-
import { globalInvocationID } from 'g-webgpu';
|
|
166
|
-
const VERTEX_COUNT;
|
|
167
|
-
const CLUSTER_COUNT;
|
|
168
|
-
@numthreads(1, 1, 1)
|
|
169
|
-
class CalcCenter {
|
|
170
|
-
@in
|
|
171
|
-
u_Data: vec4[];
|
|
172
|
-
@in
|
|
173
|
-
u_NodeAttributes: vec4[]; // [[clusterIdx, 0, 0, 0], ...]
|
|
174
|
-
@in @out
|
|
175
|
-
u_ClusterCenters: vec4[]; // [[cx, cy, nodeCount, clusterIdx], ...]
|
|
176
|
-
@main
|
|
177
|
-
compute() {
|
|
178
|
-
const i = globalInvocationID.x;
|
|
179
|
-
const center = this.u_ClusterCenters[i];
|
|
180
|
-
let sumx = 0;
|
|
181
|
-
let sumy = 0;
|
|
182
|
-
let count = 0;
|
|
183
|
-
for (let j = 0; j < VERTEX_COUNT; j++) {
|
|
184
|
-
const attributes = this.u_NodeAttributes[j];
|
|
185
|
-
const clusterIdx = int(attributes[0]);
|
|
186
|
-
const vertex = this.u_Data[j];
|
|
187
|
-
if (clusterIdx == i) {
|
|
188
|
-
sumx += vertex.x;
|
|
189
|
-
sumy += vertex.y;
|
|
190
|
-
count += 1;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
this.u_ClusterCenters[i] = [
|
|
194
|
-
sumx / count,
|
|
195
|
-
sumy / count,
|
|
196
|
-
count,
|
|
197
|
-
i
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
`;
|
|
202
|
-
|
|
203
|
-
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}}`;
|