Top Related Projects
Directed graph layout for JavaScript
♾ A Graph Visualization Framework in JavaScript.
Graph theory (network) library for visualisation and analysis
:dizzy: Display dynamic, automatically organised, customizable network views.
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
a super simple, no-nonsense diagramming library written in react that just works
Quick Overview
mxGraph is a powerful JavaScript diagramming library that allows developers to create interactive graphs and flowcharts in web applications. It provides a comprehensive set of features for creating, editing, and manipulating diagrams, making it suitable for a wide range of diagramming needs.
Pros
- Extensive functionality for creating complex diagrams and flowcharts
- Highly customizable with a wide range of styling options
- Supports both SVG and HTML5 Canvas rendering
- Active community and extensive documentation
Cons
- Steep learning curve due to its comprehensive feature set
- Large file size, which may impact load times for web applications
- Some users report performance issues with very large graphs
- Limited built-in responsive design features
Code Examples
- Creating a basic graph:
// Create a graph inside the given container
var graph = new mxGraph(container);
// Gets the default parent for inserting new cells
var parent = graph.getDefaultParent();
// Adds cells to the model in a single step
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 {
// Updates the display
graph.getModel().endUpdate();
}
- Adding a custom shape:
function CustomShape() {
mxShape.call(this);
}
mxUtils.extend(CustomShape, mxShape);
CustomShape.prototype.paintVertexShape = function(c, x, y, w, h) {
c.begin();
c.moveTo(x, y);
c.lineTo(x + w, y);
c.lineTo(x + w / 2, y + h);
c.close();
c.fillAndStroke();
};
mxCellRenderer.registerShape('custom', CustomShape);
- Implementing drag and drop:
// Enables dragging of vertices
graph.setConnectable(true);
graph.setDropEnabled(true);
// Adds drop handler
graph.addDropHandler(function(graph, evt, cell, x, y) {
var vertex = graph.getModel().cloneCell(source);
vertex.geometry.x = x;
vertex.geometry.y = y;
graph.addCell(vertex);
graph.setSelectionCell(vertex);
});
Getting Started
To get started with mxGraph:
- Include the mxGraph library in your HTML file:
<script type="text/javascript" src="https://jgraph.github.io/mxgraph/javascript/src/js/mxClient.js"></script>
- Create a container for the graph:
<div id="graphContainer" style="width:600px;height:400px;"></div>
- Initialize the graph in your JavaScript code:
// Checks if the browser is supported
if (!mxClient.isBrowserSupported()) {
mxUtils.error('Browser is not supported!', 200, false);
}
else {
// Creates the graph inside the given container
var container = document.getElementById('graphContainer');
var graph = new mxGraph(container);
// Enables rubberband selection
new mxRubberband(graph);
// Gets the default parent for inserting new cells
var parent = graph.getDefaultParent();
// Adds cells to the model in a single step
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);
Competitor Comparisons
Directed graph layout for JavaScript
Pros of dagre
- Lightweight and focused on graph layout algorithms
- Easier to integrate with other JavaScript libraries
- Better performance for large graphs with many nodes
Cons of dagre
- Limited built-in UI components and interactivity features
- Less comprehensive documentation and examples
- Smaller community and fewer updates compared to mxGraph
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();
}
dagre:
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);
♾ A Graph Visualization Framework in JavaScript.
Pros of G6
- More modern and actively maintained, with frequent updates and new features
- Better performance for large-scale graph rendering and interactions
- Rich set of built-in layouts and customizable algorithms
Cons of G6
- Steeper learning curve due to more complex API and configuration options
- Less comprehensive documentation and examples compared to mxGraph
- Smaller community and ecosystem, potentially leading to fewer third-party resources
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();
}
G6:
const graph = new G6.Graph({
container: 'mountNode',
width: 800,
height: 600,
});
const data = {
nodes: [
{ id: 'node1', x: 100, y: 200, label: 'Hello' },
{ id: 'node2', x: 300, y: 200, label: 'World!' },
],
edges: [{ source: 'node1', target: 'node2' }],
};
graph.data(data);
graph.render();
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- More lightweight and faster rendering for large graphs
- Extensive plugin ecosystem for additional functionality
- Better support for mobile and touch devices
Cons of Cytoscape.js
- Less comprehensive built-in features compared to mxGraph
- Steeper learning curve for complex graph manipulations
- Limited out-of-the-box support for certain diagram types (e.g., flowcharts)
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();
}
Cytoscape.js:
var cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'a', label: 'Hello,' } },
{ data: { id: 'b', label: 'World!' } },
{ data: { id: 'ab', source: 'a', target: 'b' } }
],
style: [
{ selector: 'node', style: { 'label': 'data(label)' } }
]
});
:dizzy: Display dynamic, automatically organised, customizable network views.
Pros of vis-network
- Lightweight and fast, especially for large datasets
- Extensive documentation and examples
- Supports both 2D and 3D network visualization
Cons of vis-network
- Less feature-rich compared to mxgraph
- Limited built-in shape options for nodes
- Steeper learning curve for complex customizations
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 container = document.getElementById('mynetwork');
var data = {nodes: nodes, edges: edges};
var options = {};
var network = new vis.Network(container, data, options);
mxgraph:
var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
var v1 = graph.insertVertex(parent, null, 'Node 1', 20, 20, 80, 30);
var v2 = graph.insertVertex(parent, null, 'Node 2', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
graph.getModel().endUpdate();
}
Both libraries offer ways to create and manipulate graph structures, but mxgraph provides more low-level control over the graph elements and their behavior.
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
Pros of vis
- More lightweight and focused on data visualization
- Easier to learn and implement for simple graph and network visualizations
- Better performance for large datasets and dynamic updates
Cons of vis
- Less comprehensive feature set for advanced graph editing and manipulation
- Limited built-in layout algorithms compared to mxGraph
- Smaller community and fewer extensions/plugins available
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);
mxGraph:
var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
var v1 = graph.insertVertex(parent, null, 'Node 1', 20, 20, 80, 30);
var v2 = graph.insertVertex(parent, null, 'Node 2', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
graph.getModel().endUpdate();
}
Both libraries offer ways to create and manipulate graphs, but vis focuses on simplicity and ease of use, while mxGraph provides more control and advanced features for complex graph applications.
a super simple, no-nonsense diagramming library written in react that just works
Pros of react-diagrams
- Built specifically for React, offering seamless integration with React applications
- More modern and actively maintained, with regular updates and improvements
- Lightweight and focused on diagram creation, making it easier to learn and implement
Cons of react-diagrams
- Less feature-rich compared to mxgraph, which offers a wider range of diagram types and functionalities
- Smaller community and ecosystem, potentially leading to fewer resources and third-party extensions
- May require more custom development for complex diagram requirements
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();
}
react-diagrams:
const engine = new DiagramEngine();
const node1 = new DefaultNodeModel('Hello,', 'rgb(0,192,255)');
node1.setPosition(100, 100);
const node2 = new DefaultNodeModel('World!', 'rgb(192,255,0)');
node2.setPosition(400, 100);
const link = node1.getPort('out').link(node2.getPort('in'));
engine.getModel().addAll(node1, node2, link);
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
NOTE 09.11.2020 : Development on mxGraph has now stopped, this repo is effectively end of life.
Known forks:
https://github.com/jsGraph/mxgraph
https://github.com/process-analytics/mxgraph
mxGraph
mxGraph is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.
The PHP model was deprecated after release 4.0.3 and the archive can be found here.
The unmaintained npm build is here
We don't support Typescript, but there is a project to implement this, with this repo currently used as the lead repo.
The mxGraph library uses no third-party software, it requires no plugins and can be integrated in virtually any framework (it's vanilla JS).
Getting Started
In the root folder there is an index.html file that contains links to all resources. You can view the documentation online on the Github pages branch. The key resources are the JavaScript user manual, the JavaScript examples and the JavaScript API specificiation.
Support
There is a mxgraph tag on Stack Overflow. Please ensure your questions adhere to the SO guidelines, otherwise it is likely to be closed.
If you are looking for active support, your better route is one of the commercial diagramming tools, like yFiles or GoJS.
History
We created mxGraph in 2005 as a commercial project and it ran through to 2016 that way. Our USP was the support for non-SVG browsers, when that advantage expired we moved onto commercial activity around draw.io. mxGraph is pretty much feature complete, production tested in many large enterprises and stable for many years.
Over time you can expect this codebase will break features against new browser releases, it's not advised to start new projects against this codebase for that reason.
Top Related Projects
Directed graph layout for JavaScript
♾ A Graph Visualization Framework in JavaScript.
Graph theory (network) library for visualisation and analysis
:dizzy: Display dynamic, automatically organised, customizable network views.
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
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