Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@antv/layout-gpu

antvis697MIT1.1.7TypeScript support: included

graph layout algorithm implemented with GPGPU

graph, layout, algorithm, antv

readme

@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.

changelog

ChangeLog

0.3.23

  • fix: comboCombined node size problem;

0.3.22

  • feat: force2 supports attractive forces to the top and bottom;

0.3.21

  • chore: replace the latest version;

0.3.20

  • fix: wrong controlPoint positions for dagre with begin;
  • fix: wrong layout order for dagre with nodeOrder;

0.3.19

  • fix: registerLayout with getDefaultCfg;

0.3.17

  • fix: controlPoints problem in dagre with layer in data;

0.3.16

  • fix: fix node order problem of dagre;

0.3.14

  • fix: error edge controlPoints in dagre with layer assignment;

0.3.12

  • perf: comboCombined with more accurate combined layout;

0.3.11

  • fix: dagre with complex combos;

0.3.10

  • chore: upgrade g-webgpu-core;

0.3.9

  • chore: upgrade g-webgpu-core;

0.3.8

  • chore: upgrade g-webgpu and regenerate shader code for gpu layouts, closes: #43;

0.3.7

  • fix: dagre layout for collapsed combos;

0.3.6

  • fix: add virtual edges for comboEdges in dagre to make combos be placed in correct layers;

0.3.5

  • perf: adjust maxSpeed for force2;

0.3.4

  • perf: improve the performance of dagre with layers;

0.3.3

  • fix: dagre layer failed when the layer number begin with 0;
  • fix: dagre with combo failed with some specified datasets;
  • perf: reduce the maxSpeed of force2 to improve the swing problem;

0.3.2

  • fix: getAdjMatrix with inexistent source or target of edge;

0.3.1

  • perf: force2 with updated node mass;

0.3.0

  • feat: forceAtlas2 supports fx and fy to fix position for a node;
  • fix: node overlaps in dagre with layer configs and default align;

0.3.0-beta.5

  • feat: force2 from graphin-force and better performance;
  • chore: use Degree including in, out, all, instead of degree number in layouts;

0.2.5

  • fix: comboCombined innerLayout with original node infos;
  • fix: DagreLayoutOptions with preset field;

0.2.4

  • fix: small width and height values for grid lead to 0 rows or cols;

0.2.3

  • perf: combo and node info should be transfered to outerLayout in comboCombined;

0.2.2

  • feat: replace @dagrejs/graphlib with @antv/graphlib
  • types: reduce ant usage as much as possible
  • chore: dagre type and some test fix

0.2.1

  • fix: gForce with same node positions;

0.2.0

  • chore: the beta features;

0.2.0-beta.4

  • feat: dagre layout support radial configuration;

0.2.0-beta.3

  • feat: dagreCompoud layout;

0.2.0-beta.0

  • feat: comboCombined layout;
  • feat: add source and target node to the parameters of gForce linkDistance;
  • feat: add hiddenNodes hiddenEdges hiddenCombos to the data of layout instance;

0.1.31

  • fix: dagre with sortByCombo error;

0.1.30

  • fix: flat problem;

0.1.29

  • fix: dagre error;

0.1.28

  • fix: dagre error;

0.1.27

  • fix: dagre error;

0.1.26

  • fix: dagre error;

0.1.25

  • fix: array flat and Infinite param problem;
  • fix: dagre with NaN node rank;
  • chore: lint;

0.1.23

  • fix: array flat compatibility;

0.1.22

  • fix: fruchterman without init clusterMap problem;

0.1.21

  • fix: comboForce with unnecessary positions for combos;
  • fix: dagre bug;

0.1.20

  • chore: migrate dagre from https://github.com/brickmaker/dagre to @antv/layout and re-write in es6 standard;
  • chore: fruchterman cluster re-computing problem;
  • feat: dagre supports begin position for the layout;

0.1.19

0.1.18

  • fix: add return value for grid layout;
  • fix: force atlas 2 default prune and barnesHut;