Convert Figma logo to code with AI

antvis logoX6

🚀 JavaScript diagramming library that uses SVG and HTML for rendering.

6,134
1,817
6,134
512

Top Related Projects

A visual graph editor based on G6 and React

6,883

mxGraph is a fully client side JavaScript diagramming library

5,090

A proven SVG-based JavaScript diagramming library powering exceptional UIs

Graph theory (network) library for visualisation and analysis

5,178

Directed graph layout for JavaScript

a super simple, no-nonsense diagramming library written in react that just works

Quick Overview

X6 is a powerful and flexible JavaScript diagramming library that can be used to create various types of interactive graphs and charts. It provides a rich set of features for building complex diagrams, flowcharts, and network topologies, making it suitable for a wide range of applications in data visualization and graph-based user interfaces.

Pros

  • Highly customizable with a wide range of built-in shapes, connectors, and tools
  • Supports both SVG and Canvas rendering for optimal performance
  • Extensive API and event system for advanced interactions and integrations
  • Active development and community support

Cons

  • Steeper learning curve compared to simpler diagramming libraries
  • Large file size may impact initial load times for web applications
  • Limited documentation and examples for some advanced features
  • May require additional setup for certain framework integrations (e.g., React, Vue)

Code Examples

Creating a basic graph:

import { Graph } from '@antv/x6';

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

const rect = graph.addNode({
  x: 100,
  y: 100,
  width: 80,
  height: 40,
  label: 'Hello',
});

const circle = graph.addNode({
  x: 300,
  y: 100,
  width: 60,
  height: 60,
  shape: 'circle',
  label: 'World',
});

graph.addEdge({
  source: rect,
  target: circle,
});

Adding interactivity to nodes:

graph.on('node:click', ({ node }) => {
  node.attr('body/fill', 'lightblue');
});

graph.on('node:mouseenter', ({ node }) => {
  node.addTools([
    'boundary',
    {
      name: 'button-remove',
      args: {
        x: 0,
        y: 0,
        offset: { x: 10, y: 10 },
      },
    },
  ]);
});

graph.on('node:mouseleave', ({ node }) => {
  node.removeTools();
});

Using a custom shape:

Graph.registerNode(
  'custom-rect',
  {
    inherit: 'rect',
    markup: [
      {
        tagName: 'rect',
        selector: 'body',
      },
      {
        tagName: 'text',
        selector: 'label',
      },
    ],
    attrs: {
      body: {
        strokeWidth: 2,
        stroke: '#5F95FF',
        fill: '#EFF4FF',
      },
      label: {
        textAnchor: 'middle',
        textVerticalAnchor: 'middle',
        fontSize: 12,
      },
    },
  },
  true
);

graph.addNode({
  shape: 'custom-rect',
  x: 200,
  y: 200,
  width: 100,
  height: 50,
  label: 'Custom Shape',
});

Getting Started

  1. Install X6 using npm:

    npm install @antv/x6
    
  2. Create a container element in your HTML:

    <div id="container"></div>
    
  3. Import and initialize X6 in your JavaScript file:

    import { Graph } from '@antv/x6';
    
    const graph = new Graph({
      container: document.getElementById('container'),
      width: 800,
      height: 600,
    });
    
    // Start adding nodes and edges to your graph
    
  4. Customize and extend the graph as needed using X6's extensive API and event system.

Competitor Comparisons

A visual graph editor based on G6 and React

Pros of GGEditor

  • More user-friendly and easier to get started with for beginners
  • Provides a complete graph editing solution out-of-the-box
  • Better integration with React components

Cons of GGEditor

  • Less flexible and customizable compared to X6
  • Fewer advanced features and graph types supported
  • Less active development and community support

Code Comparison

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

const FlowChart = () => (
  <GGEditor>
    <Flow />
  </GGEditor>
);

X6:

import { Graph } from '@antv/x6';

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

Summary

GGEditor is a more straightforward solution for creating graph editors, especially for React-based projects. It offers a quicker setup and easier integration but sacrifices some flexibility and advanced features.

X6, on the other hand, provides a more powerful and customizable graph editing framework. It offers greater control over graph rendering and behavior but requires more setup and configuration.

Choose GGEditor for simpler projects or when rapid development is a priority. Opt for X6 when you need more advanced features, customization options, or better performance for large-scale graphs.

6,883

mxGraph is a fully client side JavaScript diagramming library

Pros of mxgraph

  • More mature and established project with a longer history
  • Extensive documentation and examples available
  • Supports a wider range of browsers, including older versions

Cons of mxgraph

  • Larger file size and potentially slower performance
  • Less modern API design and syntax
  • Limited built-in support for touch devices and mobile interactions

Code Comparison

mxgraph:

var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
  var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
  var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
  var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
  graph.getModel().endUpdate();
}

X6:

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

const source = graph.addNode({
  x: 20,
  y: 20,
  width: 80,
  height: 30,
  label: 'Hello,',
});

const target = graph.addNode({
  x: 200,
  y: 150,
  width: 80,
  height: 30,
  label: 'World!',
});

graph.addEdge({ source, target });

Both libraries offer powerful graph visualization capabilities, but X6 provides a more modern and streamlined API, while mxgraph offers broader compatibility and extensive documentation.

5,090

A proven SVG-based JavaScript diagramming library powering exceptional UIs

Pros of Joint

  • More mature project with longer development history
  • Extensive documentation and examples
  • Larger community and ecosystem of plugins

Cons of Joint

  • Steeper learning curve for beginners
  • Less frequent updates and releases
  • Heavier library size

Code Comparison

Joint:

var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
    el: $('#paper'),
    width: 600,
    height: 400,
    model: graph
});

X6:

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

Summary

Joint is a more established library with a rich ecosystem, but it may be more challenging for newcomers. X6 offers a more modern approach with easier setup and frequent updates. Joint provides more out-of-the-box features, while X6 focuses on performance and flexibility. The choice between the two depends on project requirements, team expertise, and desired customization level.

Graph theory (network) library for visualisation and analysis

Pros of Cytoscape.js

  • More mature and established library with a larger community and ecosystem
  • Extensive documentation and examples for various graph visualization scenarios
  • Built-in support for complex graph algorithms and analysis

Cons of Cytoscape.js

  • Steeper learning curve for beginners due to its comprehensive feature set
  • Less focus on customizable and interactive diagram editing capabilities
  • Performance may degrade with very large graphs (10,000+ elements)

Code Comparison

X6 example:

import { Graph } from '@antv/x6';

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

graph.addNode({ x: 100, y: 100, width: 80, height: 40, label: 'Hello' });

Cytoscape.js example:

var cy = cytoscape({
  container: document.getElementById('cy'),
  elements: [
    { data: { id: 'a' }, position: { x: 100, y: 100 } },
    { data: { id: 'b', label: 'Hello' } }
  ],
  style: [ { selector: 'node', style: { 'label': 'data(label)' } } ]
});

Both libraries offer graph visualization capabilities, but X6 focuses more on interactive diagramming, while Cytoscape.js provides a broader set of graph analysis features. X6 may be easier for beginners to start with, while Cytoscape.js offers more advanced functionality for complex graph-based applications.

5,178

Directed graph layout for JavaScript

Pros of dagre

  • Lightweight and focused on graph layout algorithms
  • Easier to integrate into existing projects due to its simplicity
  • Better performance for large graphs with many nodes and edges

Cons of dagre

  • Limited built-in rendering capabilities
  • Less active development and fewer recent updates
  • Fewer out-of-the-box features for graph manipulation and interaction

Code Comparison

X6 example:

import { Graph } from '@antv/x6';

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

graph.addNode({ x: 100, y: 100, width: 80, height: 40, label: 'Hello' });

dagre example:

var g = new dagre.graphlib.Graph();

g.setNode("kspacey", { label: "Kevin Spacey", width: 144, height: 100 });
g.setNode("swilliams", { label: "Saul Williams", width: 160, height: 100 });
g.setEdge("kspacey", "swilliams");

dagre.layout(g);

X6 provides a more comprehensive graph manipulation and rendering solution, while dagre focuses on layout algorithms and requires additional libraries for rendering. X6 offers a wider range of features out-of-the-box, but dagre may be more suitable for projects that only need layout capabilities or have specific performance requirements.

a super simple, no-nonsense diagramming library written in react that just works

Pros of react-diagrams

  • Specifically designed for React applications, offering seamless integration
  • Simpler API and easier learning curve for React developers
  • More lightweight and focused on diagram functionality

Cons of react-diagrams

  • Less comprehensive feature set compared to X6
  • Limited customization options for advanced use cases
  • Smaller community and fewer extensions/plugins available

Code Comparison

react-diagrams:

import { DiagramEngine, DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';

const engine = new DiagramEngine();
const model = new DiagramModel();
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
model.addNode(node1);
engine.setModel(model);

X6:

import { Graph } from '@antv/x6';

const graph = new Graph({
  container: document.getElementById('container'),
  width: 800,
  height: 600,
});
const node = graph.addNode({
  x: 100,
  y: 100,
  label: 'Node 1',
});

Both libraries offer ways to create and manage diagrams, but X6 provides a more flexible and feature-rich API, while react-diagrams focuses on simplicity and React integration. X6 is better suited for complex, customizable diagrams, while react-diagrams is ideal for straightforward React-based diagramming needs.

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

X6:图编辑可视化引擎

x6 flow

NPM Package build coverage Package size NPM Downloads MIT License Language PRs Welcome website

官网文档 • 快速开始 • 图表示例 • 常见问题 • Demo 模板 • Awesome X6

AntV X6 是基于 HTML 和 SVG 的图编辑引擎,提供低成本的定制能力和开箱即用的内置扩展,方便我们快速搭建 DAG 图、ER 图、流程图、血缘图等应用。我们期望开发者基于 X6 可以快速构建自己需要的各种图编辑应用,让流程关系数据变得可控、可交互,以及可视化。

✨ 特性

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

  • 🌱 _极易定制_:支持使用 SVG / HTML / React / Vue / Angular 定制节点样式和交互,完备的事件系统,可以监听图表内发生的任何事件
  • 🚀 _开箱即用_:内置 10+ 图编辑配套扩展,如框选、对齐线、小地图等
  • 🧲 _数据驱动_:基于 MVC 架构,用户更加专注于数据逻辑和业务逻辑
  • 💯 _服务端渲染_:支持服务端渲染,且有不错的浏览器兼容性。

🔨 开始使用

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

# npm
$ npm install @antv/x6 --save

# yarn
$ yarn add @antv/x6

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

<div id="container" style="width: 600px; height: 400px"></div>
import { Graph } from '@antv/x6'

const graph = new Graph({
  container: document.getElementById('container'),
  grid: true,
})

const source = graph.addNode({
  x: 300,
  y: 40,
  width: 80,
  height: 40,
  label: 'Hello',
});

const target = graph.addNode({
  x: 420,
  y: 180,
  width: 80,
  height: 40,
  label: 'World',
});

graph.addEdge({
  source,
  target,
});

一切顺利,你可以得到下面的简单的流程图画布。

🧑🏻‍💻 本地开发

# 安装项目依赖和初始化构建
$ pnpm install

# 启动 examples 查看效果
pnpm run start:examples

📮 贡献

感谢所有为这个项目做出贡献的人,感谢所有支持者!🙏

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

📄 License

MIT.

NPM DownloadsLast 30 Days