Convert Figma logo to code with AI

antvis logoX6

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

5,694
1,694
5,694
413

Top Related Projects

A visual graph editor based on G6 and React

6,804

mxGraph is a fully client side JavaScript diagramming library

4,611

A proven SVG-based JavaScript diagramming library powering exceptional UIs

Graph theory (network) library for visualisation and analysis

4,650

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,804

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.

4,611

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.

4,650

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

flow

X6 是 AntV 旗下的图编辑引擎

提供简单易用的节点定制能力和开箱即用的交互组件,方便我们快速搭建流程图、DAG 图、ER 图等图应用

build NPM Package NPM Downloads

MIT License Language PRs Welcome website

特性

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

兼容环境

  • 现代浏览器
  • 支持服务端渲染。
Firefox
Firefox
Chrome
Chrome
Safari
Safari
last 2 versionslast 2 versionslast 2 versions

安装

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

# yarn
$ yarn add @antv/x6

示例

<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

# 进入到指定项目开发和调试
cd packages/x6
pnpm run build:watch

# 启动 example 查看效果
cd examples/x6-example-features
pnpm run start

参与共建

如果希望参与到 X6 的开发中,请遵从我们的贡献指南。如果你贡献度足够活跃,你可以申请成为社区协作者。

Contributors

开源协议

该项目的代码和文档基于 MIT License 开源协议。

NPM DownloadsLast 30 Days