@antv/layout-gpu
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

@antv/layout-gpu

Accelerate some parallelizable algorithms such as Fruchterman with WebGPU which has a better performance under large amount of data.

Usage

NPM

# npm
$ npm install @antv/layout-gpu --save

# yarn
$ yarn add @antv/layout-gpu

Choose a layout algorithm from @antv/layout-gpu then.

import { Graph } from "@antv/graphlib";
import { FruchtermanLayout } from "@antv/layout-gpu";

const graph = new Graph({ nodes: [], edges: [] });

const fruchtermanLayout = new FruchtermanLayout();

(async () => {
  // Return positions of nodes & edges.
  const positions = await fruchtermanLayout.execute(graph);
  // Or to directly assign the positions to the nodes:
  await circularLayout.assign(graph);
})();

UMD

Import scripts in UMD version of @antv/graphlib, @antv/layout and @antv/layout-gpu.

<script
  src="https://unpkg.com/@antv/graphlib"
  type="application/javascript"
></script>
<script
  src="https://unpkg.com/@antv/layout"
  type="application/javascript"
></script>
<script
  src="https://unpkg.com/@antv/layout-gpu"
  type="application/javascript"
></script>

Use layouts under LayoutGPU namespace.

const { Graph } = window.GraphLib;
const { FruchtermanLayout } = window.LayoutGPU;

Documentation

We provide the following parallelizable layouts:

import { Graph } from "@antv/graphlib";
import { FruchtermanLayout } from "@antv/layout-gpu";

const graph = new Graph({ nodes: [], edges: [] });

const fruchtermanLayout = new FruchtermanLayout({
  center: [200, 200],
});
const positions = await fruchtermanLayout.execute(graph);

Fruchterman

Fruchterman is a kind of force-directed layout. The implementation is according to the paper Graph Drawing by Force-directed Placement.

fruchterman layout

Online Demo

LayoutOptions:

  • center [number, number] The center of the graph. e.g. [0, 0]
  • width number The width of the graph. The default value is 300.
  • height number The height of the graph. The default value is 300.
  • maxIteration number The default value is 1000.
  • gravity number The gravity, which will affect the compactness of the layout. The default value is 10.
  • speed number The moving speed of each iteraction. Large value of the speed might lead to violent swing. The default value is 5.

GForce

License

The scripts and documentation in this project are released under the MIT License.

Package Sidebar

Install

npm i @antv/layout-gpu

Weekly Downloads

492

Version

1.1.5

License

MIT

Unpacked Size

1.14 MB

Total Files

24

Last publish

Collaborators

  • xuying1027
  • lvisei
  • yisi.wang
  • basketduck
  • biupiubiupiu
  • flash1
  • dreammy23
  • laixingui.lxg
  • zhangjunjie-loki
  • rainy25ghz
  • zeyuwang
  • yanxiong
  • susiwen8
  • freestyle21
  • soundquiet
  • elaine.q.10
  • sturuby
  • sakuya223
  • serializedowen
  • xdzhao
  • yangzhanmei
  • wjgogogo
  • leungwensen
  • dori
  • iaaron
  • yard
  • simaq
  • dxq613
  • intchous
  • susan_ann
  • jinke.li
  • lzxue
  • army8735
  • atool
  • baizn
  • dengfuping
  • neoddish
  • jeffy2012
  • zqlu
  • afc163
  • pomelo-nwu
  • kopiluwaky
  • ccnuzindex
  • panyuqi
  • bubkoo
  • zengyue
  • kasmine
  • boyu.zlj
  • l1ud0ngq1
  • newbyvector
  • winniexing
  • chenluli
  • kn9117
  • xdddst
  • semious2020
  • esora
  • nadia_liu
  • bbsqq
  • mxz96102
  • openwayne
  • pearmini
  • pddpd
  • yiqianyao
  • zhanba
  • cxxxxxn