2023-02-02 10:31:36 +08:00
# G6: A Graph Visualization Framework in TypeScript
2024-01-17 18:49:48 +08:00
> The 5.0 beta version is currently undergoing rapid iteration, with the stable release expected on June 6, 2024. There may be changes to the API during this period, so please exercise caution when using it in stable online product.
2023-06-01 09:31:19 +08:00
2023-02-02 10:31:36 +08:00
![](https://user-images.githubusercontent.com/6113694/45008751-ea465300-b036-11e8-8e2a-166cbb338ce2.png)
2024-01-30 10:46:29 +08:00
[![npm Version ](https://img.shields.io/npm/v/@antv/g6.svg )](https://www.npmjs.com/package/@antv/g6)
![typescript ](https://img.shields.io/badge/language-typescript-red.svg )
[![Build Status ](https://github.com/antvis/g6/workflows/build/badge.svg?branch=v5 )](https://github.com/antvis/g6/actions)
[![Coverage Status ](https://coveralls.io/repos/github/antvis/G6/badge.svg )](https://coveralls.io/github/antvis/G6)
[![npm Download ](https://img.shields.io/npm/dm/@antv/g6.svg )](https://www.npmjs.com/package/@antv/g6)
[![npm License ](https://img.shields.io/npm/l/@antv/g6.svg )](https://www.npmjs.com/package/@antv/g6)
[![Percentage of issues still open ](http://isitmaintained.com/badge/open/antvis/g6.svg )](http://isitmaintained.com/project/antvis/g6)
2023-02-02 10:31:36 +08:00
[中文 README ](README.md )
## What is G6
[G6 ](https://github.com/antvis/g6 ) is a graph visualization engine, which provides a set of basic mechanisms, including rendering, layout, analysis, interaction, animation, and other auxiliary tools. G6 aims to simplify the relationships, and help people to obtain the insight of relational data.
< img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*zTjwQaXokeQAAAAAAAAAAABkARQnAQ' width = 550 alt = '' / >
Developers are able to build graph visualization **analysis** applications or graph visualization **modeling** applications easily.
< img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*zau8QJcVpDQAAAAAAAAAAABkARQnAQ' height = 200 alt = '' / > < img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*RIlETY_S6IoAAAAAAAAAAABkARQnAQ' height = 200 alt = '' / >
< img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*cDzXR4jIWr8AAAAAAAAAAABkARQnAQ' height = 150 alt = '' / > < img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*DifbSahOblAAAAAAAAAAAABkARQnAQ' height = 150 alt = '' / > < img src = 'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*HTasSJGC4koAAAAAAAAAAABkARQnAQ' height = 150 alt = '' / >
> Powerful Animation and Interactions
< img src = "https://user-images.githubusercontent.com/6113694/44995293-02858600-afd5-11e8-840c-349e4730d63d.gif" height = 150 alt = '' / > < img src = "https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*I9OdTbXJIi0AAAAAAAAAAABkARQnAQ" height = 150 alt = '' / > < img src = "https://user-images.githubusercontent.com/6113694/44995332-2ba61680-afd5-11e8-8cab-db0e9d08ceb7.gif" height = 150 alt = '' / >
< img src = "https://gw.alipayobjects.com/zos/rmsportal/HQxYguinFOMIXrGQOABY.gif" height = 150 alt = '' / > < img src = "https://gw.alipayobjects.com/zos/rmsportal/nAugyFgrbrUWPmDIDiQm.gif" height = 150 alt = '' / > < img src = "https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*xoufSYcjK2AAAAAAAAAAAABkARQnAQ" height = 150 alt = '' / >
> Powerful Layouts
2023-06-01 09:31:19 +08:00
## Features (5.0 Alpha)
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
- Extensionable: All the modules (seven types) are integrated as plugins;
- Style and animation standards, supports level of details (see the graph below);
- Beautiful Built-in Theme and cound be customized (see the graph below);
- Layouts with Great Performance: More than 10 layout algorithms, supports GPU and Rust parallel computing, and custom layouts;
2023-02-02 10:31:36 +08:00
- Steerable Interactions: More than 10 basic interaction behaviors ;
- Friendly User Experience: Complete documents for different levels of user requirements. TypeScript supported.
2023-06-01 09:31:19 +08:00
- Multiple renderers: Canvas, SVG, WebGL;
- 3D Graph:
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
The gif is not fully loaded, [Click Here to See the Original Image ](https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*qPrmQrdV77gAAAAAAAAAAAAADmJ7AQ/original )
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*IUOnSbLisyoAAAAAAAAAAAAADmJ7AQ/original" width = 600 height = 334 alt = '' / >
> 3D Graph
The gif is not fully loaded, [Click Here to See the Original Image ](https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*1BFvQ4r3P7UAAAAAAAAAAAAADmJ7AQ/original )
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*tPPGSokdSYsAAAAAAAAAAAAADmJ7AQ/original" width = 600 height = 367 alt = '' / >
> Animations and Level of Details
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*QjJoSbD7GTwAAAAAAAAAAAAADmJ7AQ/original" width = 800 height = 226 alt = '' / >
> Built-in Themes and Custom Themes
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*x7NTT5_baKYAAAAAAAAAAAAADmJ7AQ/original" width = 400 height = 218 alt = '' / >
> Seven Types of Plugins
- (TODO: migrate from v4) Abundant Built-in Items: Nodes and edges with free configurations;
- (TODO: migrate from v4) Convenient Components: Outstanding ability and performance;
2023-12-04 20:46:28 +08:00
G6 concentrates on the principle of 'good by default'. In addition, the custom mechanism of the item, interaction behavior, and layout satisfies the customazation requirements.
2023-02-02 10:31:36 +08:00
> Abundant Built-in Items
2023-06-01 09:31:19 +08:00
## Installation (5.0 Alpha)
2023-02-02 10:31:36 +08:00
```bash
2023-12-12 14:52:07 +08:00
$ npm install @antv/g6@5 .0.0-beta.28
2023-02-02 10:31:36 +08:00
```
2023-06-01 09:31:19 +08:00
## Usage (5.0 Alpha)
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*M-MTRaLiZN0AAAAAAAAAAAAADmJ7AQ/original" width = 437 height = 148 alt = '' / >
The configuration specification of the graph can be refered to: https://github.com/antvis/G6/blob/v5/packages/g6/src/types/spec.ts
Graph API: https://github.com/antvis/G6/blob/2b44df189dd2e851447ba5a09541c372b49cd658/packages/g6/src/types/graph.ts#L23
A simple graph demo:
< img src = "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*M-MTRaLiZN0AAAAAAAAAAAAADmJ7AQ/original" width = 437 height = 138 alt = '' / >
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
[![Edit compassionate-lalande-5lxm7 ](https://codesandbox.io/static/img/play-codesandbox.svg )](https://codesandbox.io/embed/musing-matan-q255po?fontsize=14& hidenavigation=1& theme=dark)
2023-02-02 10:31:36 +08:00
```js
2024-01-17 18:59:21 +08:00
import { Graph } from "@antv/g6";
2023-02-02 10:31:36 +08:00
const data = {
nodes: [
{
2023-06-01 09:31:19 +08:00
id: "node1",
label: "Node 1",
data: {
x: 150,
y: 150,
},
2023-02-02 10:31:36 +08:00
},
{
2023-06-01 09:31:19 +08:00
id: "node2",
label: "Node 2",
data: {
x: 400,
y: 150,
},
2023-02-02 10:31:36 +08:00
},
],
edges: [
{
2023-06-01 09:31:19 +08:00
id: "edge1",
label: "Edge 1",
source: "node1",
target: "node2",
data: {},
2023-02-02 10:31:36 +08:00
},
],
};
2024-01-17 18:59:21 +08:00
const graph = new Graph({
2023-06-01 09:31:19 +08:00
container: "container",
2023-02-02 10:31:36 +08:00
width: 500,
height: 500,
2023-06-01 09:31:19 +08:00
data,
node: (innerModel) => ({
...innerModel,
type: "circle",
data: {
...innerModel.data,
labelShape: {
text: innerModel.label,
},
labelBackgroundShape: {},
iconShape: {
img: "https://gw.alipayobjects.com/zos/basement_prod/012bcf4f-423b-4922-8c24-32a89f8c41ce.svg",
2023-02-02 10:31:36 +08:00
},
},
2023-06-01 09:31:19 +08:00
}),
edge: (innerModel) => ({
...innerModel,
type: "line",
data: {
labelShape: {
text: innerModel.label,
},
labelBackgroundShape: {},
2023-02-02 10:31:36 +08:00
},
2023-06-01 09:31:19 +08:00
}),
2023-02-02 10:31:36 +08:00
});
```
2023-06-01 09:31:19 +08:00
## Development (5.0 Alpha)
2023-02-02 10:31:36 +08:00
```bash
2023-11-02 16:52:39 +08:00
# install dependencies by pnpm in the root directory
$ pnpm install
2023-02-02 10:31:36 +08:00
2023-11-02 16:52:39 +08:00
# enter packages/g6
$ cd ./packages/g6
2023-02-02 10:31:36 +08:00
2023-11-02 16:52:39 +08:00
# build g6
2023-06-01 09:31:19 +08:00
$ npm run build
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
# start the integration demos
$ npm run dev
2023-02-02 10:31:36 +08:00
# run test case
2023-06-01 09:31:19 +08:00
$ npm run test
2023-02-02 10:31:36 +08:00
# run test case in watch mode
2023-06-01 09:31:19 +08:00
npm test -- --watch ./tests/unit/node-spec
DEBUG_MODE=1 npm test -- --watch ./tests/unit/node-spec
2023-02-02 10:31:36 +08:00
```
2023-06-01 09:31:19 +08:00
## Documents (5.0 Alpha)
2023-02-02 10:31:36 +08:00
2023-06-01 09:31:19 +08:00
The documents will be ready after the 5.0 version being stable.
2023-02-02 10:31:36 +08:00
## How to Contribute
Please let us know what you are you going to help. Do check out [issues ](https://github.com/antvis/g6/issues ) for bug reports or suggestions first.
## License
[MIT license ](./LICENSE ).