Top Related Projects
A visual graph editor based on G6 and React
mxGraph is a fully client side JavaScript diagramming library
A proven SVG-based JavaScript diagramming library powering exceptional UIs
Graph theory (network) library for visualisation and analysis
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
-
Install X6 using npm:
npm install @antv/x6
-
Create a container element in your HTML:
<div id="container"></div>
-
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
-
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.
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.
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.
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ç®ä½ä¸æ | English
X6 æ¯ AntV æä¸çå¾ç¼è¾å¼æ
æä¾ç®åæç¨çèç¹å®å¶è½ååå¼ç®±å³ç¨ç交äºç»ä»¶ï¼æ¹ä¾¿æ们快éæ建æµç¨å¾ãDAG å¾ãER å¾çå¾åºç¨
ç¹æ§
- ð± ãææå®å¶ï¼æ¯æä½¿ç¨ SVG/HTML/React/Vue/Angular å®å¶èç¹æ ·å¼å交äº
- ð ãå¼ç®±å³ç¨ï¼å ç½® 10+ å¾ç¼è¾é å¥æ©å±ï¼å¦æ¡éã对é½çº¿ãå°å°å¾ç
- 𧲠ãæ°æ®é©±å¨ï¼åºäº MVC æ¶æï¼ç¨æ·æ´å ä¸æ³¨äºæ°æ®é»è¾åä¸å¡é»è¾
- ð¯ ãäºä»¶é©±å¨ï¼å®å¤çäºä»¶ç³»ç»ï¼å¯ä»¥çå¬å¾è¡¨å åççä»»ä½äºä»¶
å ¼å®¹ç¯å¢
- ç°ä»£æµè§å¨
- æ¯ææå¡ç«¯æ¸²æã
Firefox | Chrome | Safari |
---|---|---|
last 2 versions | last 2 versions | last 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 çå¼åä¸ï¼è¯·éµä»æ们çè´¡ç®æåãå¦æä½ è´¡ç®åº¦è¶³å¤æ´»è·ï¼ä½ å¯ä»¥ç³è¯·æ为社åºåä½è ã
å¼æºåè®®
该项ç®ç代ç åææ¡£åºäº MIT License å¼æºåè®®ã
Top Related Projects
A visual graph editor based on G6 and React
mxGraph is a fully client side JavaScript diagramming library
A proven SVG-based JavaScript diagramming library powering exceptional UIs
Graph theory (network) library for visualisation and analysis
Directed graph layout for JavaScript
a super simple, no-nonsense diagramming library written in react that just works
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot