Convert Figma logo to code with AI

antvis logoX6

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

6,274
1,833
6,274
154

Top Related Projects

A visual graph editor based on G6 and React

6,898

mxGraph is a fully client side JavaScript diagramming library

5,168

A proven SVG-based JavaScript diagramming library powering exceptional UIs

Graph theory (network) library for visualisation and analysis

5,365

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

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

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

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: Graph Editing and Visualization Engine

x6 flow

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

antvis%2FX6 | Trendshift

Official Documentation • Quick Start • Graph Examples • FAQ • Demo Template • Awesome X6

AntV X6 is a graph editing engine based on HTML and SVG, providing low-cost customization capabilities and out-of-the-box built-in extensions that make it easy to quickly build applications such as DAG diagrams, ER diagrams, flowcharts, lineage graphs, and more. We hope developers can use X6 to rapidly build various graph editing applications they need, making process relationship data controllable, interactive, and visualized.

✨ Features

As a professional graph editing and visualization engine, X6 has the following features:

  • 🌱 Highly Customizable: Supports customizing node styles and interactions using SVG / HTML / React / Vue / Angular, with a comprehensive event system that allows listening to any events occurring within the chart.
  • 🚀 Out-of-the-Box: Built-in 10+ graph editing extensions, such as lasso selection, alignment lines, minimap, etc.
  • 🧲 Data-Driven: Based on the MVC architecture, allowing users to focus more on data logic and business logic.
  • 💯 Server-Side Rendering: Supports server-side rendering with good browser compatibility.

🔨 Getting Started

You can install via package managers like NPM or Yarn.

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

# yarn
$ yarn add @antv/x6

After successful installation, you can import the Graph object using import.

<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,
});

If everything goes smoothly, you will get a simple flowchart canvas as shown below.

🧑🏻‍💻 Local Development

# Install project dependencies and initialize build
$ pnpm install

# Start examples to view results
pnpm run start:examples

📮 Contribution

Thank you to everyone who has contributed to this project and all supporters! 🙏

Contribution Leaderboard
  • Issue Feedback: If you encounter any issues with X6 during use, feel free to submit an Issue along with minimal reproducible code.
  • Contribution Guide: How to participate in the development and contribution of X6.
  • Discussion Ideas: Discuss on GitHub Discussion or DingTalk group.

📄 License

MIT.

NPM DownloadsLast 30 Days