Convert Figma logo to code with AI

antvis logoG6

♾ A Graph Visualization Framework in JavaScript.

11,025
1,304
11,025
142

Top Related Projects

A visual graph editor based on G6 and React

Graph theory (network) library for visualisation and analysis

4,593

Directed graph layout for JavaScript

:dizzy: Display dynamic, automatically organised, customizable network views.

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

Force-directed graph layout using velocity Verlet integration.

Quick Overview

G6 is a graph visualization engine for JavaScript, providing developers with powerful tools to create interactive and customizable graph visualizations. It offers a wide range of graph types, layouts, and interactions, making it suitable for various applications such as data analysis, network visualization, and knowledge graphs.

Pros

  • Extensive graph visualization capabilities with support for various graph types and layouts
  • High performance and efficient rendering, even for large-scale graphs
  • Rich set of built-in interactions and customization options
  • Active development and community support

Cons

  • Steep learning curve for advanced features and customizations
  • Documentation can be inconsistent or outdated in some areas
  • Limited built-in support for certain specialized graph types

Code Examples

  1. Creating a basic graph:
import G6 from '@antv/g6';

const data = {
  nodes: [
    { id: 'node1', label: 'Node 1' },
    { id: 'node2', label: 'Node 2' },
  ],
  edges: [
    { source: 'node1', target: 'node2' },
  ],
};

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});

graph.data(data);
graph.render();
  1. Applying a custom layout:
import G6 from '@antv/g6';

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
  layout: {
    type: 'force',
    preventOverlap: true,
    nodeStrength: -30,
    edgeStrength: 0.1,
  },
});
  1. Adding custom node shapes:
import G6 from '@antv/g6';

G6.registerNode('custom-node', {
  draw(cfg, group) {
    const shape = group.addShape('rect', {
      attrs: {
        x: -30,
        y: -15,
        width: 60,
        height: 30,
        radius: 5,
        fill: '#1890FF',
        stroke: '#0050B3',
      },
    });
    return shape;
  },
});

const graph = new G6.Graph({
  // ... other configurations
  defaultNode: {
    type: 'custom-node',
  },
});

Getting Started

To get started with G6, follow these steps:

  1. Install G6 using npm:

    npm install @antv/g6
    
  2. Import G6 in your project:

    import G6 from '@antv/g6';
    
  3. Create a container element in your HTML:

    <div id="mountNode"></div>
    
  4. Initialize a graph instance and render your data:

    const graph = new G6.Graph({
      container: 'mountNode',
      width: 800,
      height: 600,
    });
    
    const data = {
      nodes: [
        { id: 'node1', label: 'Node 1' },
        { id: 'node2', label: 'Node 2' },
      ],
      edges: [
        { source: 'node1', target: 'node2' },
      ],
    };
    
    graph.data(data);
    graph.render();
    

This will create a basic graph visualization. From here, you can explore more advanced features and customizations provided by G6.

Competitor Comparisons

A visual graph editor based on G6 and React

Pros of GGEditor

  • Provides a higher-level abstraction for graph editing, with built-in support for flow charts and mind maps
  • Offers a more comprehensive set of editing tools and interactions out of the box
  • Integrates well with React, making it easier to use in React-based applications

Cons of GGEditor

  • Less flexible and customizable compared to G6's lower-level API
  • Smaller community and fewer updates, potentially leading to less support and fewer features
  • More opinionated design, which may not suit all use cases

Code Comparison

G6 (lower-level graph rendering):

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});
graph.data(data);
graph.render();

GGEditor (higher-level graph editing):

<GGEditor>
  <Flow data={data} />
  <EditableLabel />
  <ContextMenu />
  <Toolbar />
</GGEditor>

G6 provides a more flexible, lower-level API for graph rendering and manipulation, while GGEditor offers a higher-level, more opinionated approach with built-in editing components. G6 is better suited for custom graph visualizations, while GGEditor is more appropriate for quickly implementing editable diagrams with predefined functionality.

Graph theory (network) library for visualisation and analysis

Pros of Cytoscape.js

  • More extensive documentation and examples
  • Larger community and ecosystem of plugins
  • Better support for complex graph analysis algorithms

Cons of Cytoscape.js

  • Steeper learning curve for beginners
  • Less focus on performance optimization for large-scale graphs
  • More complex API for basic graph operations

Code Comparison

G6 example:

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});
graph.data(data);
graph.render();

Cytoscape.js example:

const cy = cytoscape({
  container: document.getElementById('cy'),
  elements: data,
  style: [ /* ... */ ],
  layout: { name: 'grid' }
});

Both libraries offer similar basic functionality for creating and rendering graphs. G6 provides a more straightforward API for simple use cases, while Cytoscape.js offers more flexibility and options out of the box. G6 focuses on performance and customization for large-scale graphs, whereas Cytoscape.js excels in providing a comprehensive set of graph analysis tools and algorithms.

4,593

Directed graph layout for JavaScript

Pros of dagre

  • Specialized in directed graph layout algorithms
  • Lightweight and focused on graph layout computation
  • Easier integration with other visualization libraries

Cons of dagre

  • Limited built-in rendering capabilities
  • Less comprehensive documentation and examples
  • Smaller community and fewer updates

Code Comparison

dagre:

var g = new dagre.graphlib.Graph();
g.setNode("a", { label: "A" });
g.setNode("b", { label: "B" });
g.setEdge("a", "b");
dagre.layout(g);

G6:

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});
graph.data({
  nodes: [{ id: 'a', label: 'A' }, { id: 'b', label: 'B' }],
  edges: [{ source: 'a', target: 'b' }],
});
graph.render();

Summary

dagre is a specialized library for directed graph layout algorithms, offering lightweight and focused functionality. It's easier to integrate with other visualization libraries but lacks built-in rendering capabilities. G6, on the other hand, provides a more comprehensive graph visualization solution with built-in rendering and a wider range of features. G6 has better documentation and a larger community, making it more suitable for complex graph visualization projects. dagre might be preferred for simpler layout computations or when used in conjunction with other rendering libraries.

:dizzy: Display dynamic, automatically organised, customizable network views.

Pros of vis-network

  • More mature and established project with a larger community
  • Extensive documentation and examples
  • Supports a wider range of graph visualization types

Cons of vis-network

  • Heavier library size compared to G6
  • Less focus on performance optimization for large datasets
  • Limited customization options for advanced visualizations

Code Comparison

vis-network:

var nodes = new vis.DataSet([
  { id: 1, label: 'Node 1' },
  { id: 2, label: 'Node 2' }
]);
var edges = new vis.DataSet([
  { from: 1, to: 2 }
]);
var network = new vis.Network(container, { nodes, edges }, options);

G6:

const data = {
  nodes: [
    { id: 'node1', label: 'Node 1' },
    { id: 'node2', label: 'Node 2' }
  ],
  edges: [{ source: 'node1', target: 'node2' }]
};
const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600
});
graph.data(data);
graph.render();

Both libraries offer similar functionality for creating basic network graphs, but G6 provides a more concise API and focuses on performance optimization. vis-network offers more built-in options and graph types out of the box, while G6 emphasizes customization and extensibility for complex visualizations.

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

Pros of vis

  • More comprehensive library with support for various visualization types (networks, timelines, graphs)
  • Longer development history and larger community, potentially leading to better stability and support
  • Extensive documentation and examples available

Cons of vis

  • Larger file size and potentially heavier performance impact
  • Less focused on graph visualization specifically compared to G6
  • May have a steeper learning curve due to its broader scope

Code Comparison

vis:

var nodes = new vis.DataSet([
  {id: 1, label: 'Node 1'},
  {id: 2, label: 'Node 2'}
]);
var edges = new vis.DataSet([
  {from: 1, to: 2}
]);
var network = new vis.Network(container, {nodes: nodes, edges: edges}, options);

G6:

const data = {
  nodes: [
    { id: 'node1', label: 'Node 1' },
    { id: 'node2', label: 'Node 2' }
  ],
  edges: [{ source: 'node1', target: 'node2' }]
};
const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600
});
graph.data(data);
graph.render();

Both libraries offer straightforward ways to create and render graphs, but G6's API appears more concise for basic graph creation.

Force-directed graph layout using velocity Verlet integration.

Pros of d3-force

  • More flexible and customizable for force-directed layouts
  • Part of the larger D3 ecosystem, integrating well with other D3 modules
  • Lightweight and focused specifically on force simulations

Cons of d3-force

  • Steeper learning curve, especially for those new to D3
  • Requires more manual setup and configuration for complex visualizations
  • Less out-of-the-box functionality for graph visualization compared to G6

Code Comparison

d3-force:

const simulation = d3.forceSimulation(nodes)
  .force("link", d3.forceLink(links).id(d => d.id))
  .force("charge", d3.forceManyBody())
  .force("center", d3.forceCenter(width / 2, height / 2));

G6:

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
  layout: { type: 'force' }
});
graph.data(data);
graph.render();

Summary

d3-force offers more flexibility and integration with the D3 ecosystem but requires more setup. G6 provides a more comprehensive graph visualization solution with easier initial setup but may be less customizable for specific force-directed layouts.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

English | 简体中文

G6:图可视分析引擎

npm Version Build Status Coverage Status npm Download typescript npm License

介绍 • 案例 • 教程 • API

G6 是一个图可视化引擎。它提供了图的绘制、布局、分析、交互、动画、主题、插件等图可视化和分析的基础能力。基于 G6,用户可以快速搭建自己的图可视化分析应用,让关系数据变得简单,透明,有意义。

✨ 特性

G6 作为一款专业的图可视化引擎,具有以下特性:

  • **丰富的元素**:内置丰富的节点、边、Combo UI 元素,样式配置丰富,支持数据回调,且具备有灵活扩展自定义元素的机制。
  • 可控的交互:内置 10+ 交互行为,且提供丰富的各类事件,便于扩展自定义的交互行为。
  • 高性能布局:内置 10+ 常用的图布局,部分基于 GPU、Rust 并行计算提升性能,支持自定义布局。
  • **便捷的组件**:优化内置组件功能及性能,且有灵活的扩展性,便于业务实现定制能力。
  • **多主题色板**:提供了亮色、暗色两套内置主题,在 AntV 新色板前提下,融入 20+ 常用社区色板。
  • 多环境渲染:发挥 G 能力, 支持 Canvas、SVG 以及 WebGL,和 Node.js 服务端渲染;基于 WebGL 提供强大 3D 渲染和空间交互的插件包。
  • **React 体系**:利用 React 前端生态,支持 React 节点,大大丰富 G6 的节点呈现样式。

🔨 开始使用

可以通过 NPM 或 Yarn 等包管理器来安装。

$ npm install @antv/g6

成功安装之后,可以通过 import 导入 Graph 对象。

<div id="container"></div>
import { Graph } from '@antv/g6';

// 准备数据
const data = {
  nodes: [
    /* your nodes data */
  ],
  edges: [
    /* your edges data */
  ],
};

// 初始化图表实例
const graph = new Graph({
  container: 'container',
  data,
  node: {
    palette: {
      type: 'group',
      field: 'cluster',
    },
  },
  layout: {
    type: 'force',
  },
  behaviors: ['drag-canvas', 'drag-node'],
});

// 渲染可视化
graph.render();

一切顺利,你可以得到下面的力导图!

🌍 生态

  • Ant Design Charts: React 图表库,基于 G2、G6、X6、L7。
  • Graphin:基于 G6 的 React 简单封装,以及图可视化应用研发的 SDK。

更多生态开源项目,欢迎 PR 收录进来。

📮 贡献

  • 问题反馈:使用过程遇到的 G6 的问题,欢迎提交 Issue,并附上可以复现问题的最小案例代码。
  • 贡献指南:如何参与到 G6 的开发和贡献。
  • 想法讨论:在 GitHub Discussion 上或者钉钉群里面讨论。

📄 License

MIT.

NPM DownloadsLast 30 Days