GoJS
JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
Top Related Projects
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
♾ A Graph Visualization Framework in JavaScript.
Graph theory (network) library for visualisation and analysis
Directed graph layout for JavaScript
:dizzy: Display dynamic, automatically organised, customizable network views.
draw.io is a JavaScript, client-side editor for general diagramming.
Quick Overview
GoJS is a feature-rich JavaScript library for implementing interactive diagrams, graphs, and complex visualizations in web browsers. It provides a flexible and customizable framework for creating various types of diagrams, including flowcharts, org charts, BPMN, and more, without requiring any server-side dependencies.
Pros
- Extensive set of built-in diagram types and layouts
- Highly customizable with a wide range of properties and methods
- Supports data binding and model-view separation
- Cross-browser compatibility and touch device support
Cons
- Steep learning curve due to its extensive API and features
- Commercial license required for production use
- Large file size, which may impact initial page load times
- Limited built-in theming options compared to some alternatives
Code Examples
- Creating a simple diagram:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "lightblue" }),
$(go.TextBlock, { margin: 8 },
new go.Binding("text", "key"))
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: "Alpha" },
{ key: "Beta" },
{ key: "Gamma" }
],
[
{ from: "Alpha", to: "Beta" },
{ from: "Alpha", to: "Gamma" }
]);
- Adding interactivity with a context menu:
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "lightblue" }),
$(go.TextBlock, { margin: 8 },
new go.Binding("text", "key")),
{
contextMenu:
$("ContextMenu",
$("ContextMenuButton",
$(go.TextBlock, "Delete"),
{ click: function(e, obj) { e.diagram.commandHandler.deleteSelection(); } }
)
)
}
);
- Implementing a custom layout:
function CustomLayout() {
go.Layout.call(this);
}
go.Diagram.inherit(CustomLayout, go.Layout);
CustomLayout.prototype.doLayout = function(coll) {
coll.each(function(node) {
if (node instanceof go.Node) {
node.location = new go.Point(Math.random() * 500, Math.random() * 500);
}
});
};
myDiagram.layout = new CustomLayout();
Getting Started
- Include GoJS in your HTML file:
<script src="https://unpkg.com/gojs/release/go.js"></script>
- Create a div element for your diagram:
<div id="myDiagramDiv" style="width: 400px; height: 300px; border: 1px solid black;"></div>
- Initialize a basic diagram:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "lightblue" }),
$(go.TextBlock, { margin: 8 },
new go.Binding("text", "key"))
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: "Hello" },
{ key: "World" }
],
[
{ from: "Hello", to: "World" }
]);
Competitor Comparisons
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Pros of mermaid
- Lightweight and easy to integrate into existing projects
- Text-based diagram creation, making it version-control friendly
- Free and open-source
Cons of mermaid
- Limited customization options for diagram appearance
- Less interactive features for end-users
- Steeper learning curve for complex diagrams
Code Comparison
mermaid:
graph TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[End]
GoJS:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "lightblue" }),
$(go.TextBlock, { margin: 8 }, new go.Binding("text", "key"))
);
mermaid uses a simple text-based syntax to define diagrams, while GoJS employs a more programmatic approach with JavaScript. mermaid's syntax is more concise and easier to read for simple diagrams, but GoJS offers greater flexibility and control over diagram elements and interactions.
♾ A Graph Visualization Framework in JavaScript.
Pros of G6
- Open-source and free to use, with a large community and frequent updates
- Extensive documentation and examples in both Chinese and English
- Supports custom rendering and interactions through plugins and extensions
Cons of G6
- Less mature and feature-rich compared to GoJS
- Limited built-in layout options and diagram types
- May require more manual configuration for complex diagrams
Code Comparison
G6:
import G6 from '@antv/g6';
const graph = new G6.Graph({
container: 'mountNode',
width: 800,
height: 600,
});
graph.data(data);
graph.render();
GoJS:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.model = new go.GraphLinksModel(
[{ key: "Alpha" }, { key: "Beta" }],
[{ from: "Alpha", to: "Beta" }]
);
Both libraries offer straightforward ways to create and render graphs, but GoJS provides a more declarative approach with its "$ function" for creating diagram objects. G6 focuses on a more configuration-based setup, which can be more flexible for certain use cases but may require more code for complex diagrams.
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- Open-source and free to use
- Extensive documentation and active community support
- Highly customizable with a wide range of layout algorithms
Cons of Cytoscape.js
- Steeper learning curve for complex visualizations
- Limited built-in UI components compared to GoJS
- Performance may degrade with very large graphs
Code Comparison
Cytoscape.js:
var cy = cytoscape({
container: document.getElementById('cy'),
elements: [ // list of graph elements to start with
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{ data: { id: 'ab', source: 'a', target: 'b' } }
],
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
}
]
});
GoJS:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { strokeWidth: 0 },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text", "key"))
);
Directed graph layout for JavaScript
Pros of dagre
- Open-source and free to use, unlike GoJS which is commercial
- Lightweight and focused specifically on graph layout algorithms
- Easier integration with other JavaScript libraries and frameworks
Cons of dagre
- Limited built-in features compared to GoJS's extensive diagramming toolkit
- Less comprehensive documentation and examples
- Smaller community and fewer updates
Code Comparison
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");
GoJS:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate = $(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "white" }),
$(go.TextBlock, { margin: 8, font: "bold 14px sans-serif" },
new go.Binding("text", "key"))
);
The code comparison shows that dagre focuses on graph structure and layout, while GoJS provides a more comprehensive diagramming solution with built-in visual elements and data binding.
:dizzy: Display dynamic, automatically organised, customizable network views.
Pros of vis-network
- Open-source and free to use
- Lightweight and easy to integrate
- Supports both directed and undirected graphs
Cons of vis-network
- Limited customization options compared to GoJS
- Less comprehensive documentation
- Fewer built-in layout algorithms
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);
GoJS:
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.model = new go.GraphLinksModel(
[{key: 1, text: "Node 1"}, {key: 2, text: "Node 2"}],
[{from: 1, to: 2}]
);
Both libraries allow for easy creation of nodes and edges, but GoJS offers more built-in functionality and customization options. vis-network has a simpler API, making it easier to get started quickly, while GoJS provides more advanced features for complex diagrams and interactions.
draw.io is a JavaScript, client-side editor for general diagramming.
Pros of draw.io
- Open-source and free to use, with a self-hosted option available
- Supports a wide range of diagram types and integrations
- User-friendly interface with drag-and-drop functionality
Cons of draw.io
- Limited customization options for advanced users
- Performance can be slower with large, complex diagrams
- Less extensive documentation compared to GoJS
Code Comparison
draw.io (XML-based diagram definition):
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="Hello, World!" style="rounded=1;" vertex="1" parent="1">
<mxGeometry x="120" y="120" width="100" height="40" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
GoJS (JavaScript-based diagram definition):
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.model = new go.GraphLinksModel(
[{ key: 1, text: "Hello, World!" }],
[]
);
Both libraries offer powerful diagramming capabilities, but GoJS provides more flexibility and performance for complex diagrams, while draw.io offers a more accessible, open-source solution with a user-friendly interface.
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
GoJS, a JavaScript Library for HTML Diagrams
GoJS is a JavaScript and TypeScript library for creating and manipulating diagrams, charts, and graphs.
GoJS is a flexible library that can be used to create a number of different kinds of interactive diagrams, including data visualizations, drawing tools, and graph editors. There are samples for flowchart, org chart, business process BPMN, swimlanes, timelines, state charts, kanban, network, mindmap, sankey, family trees and genogram charts, fishbone diagrams, floor plans, UML, decision trees, PERT charts, Gantt, and hundreds more. GoJS includes a number of built in layouts including tree layout, force directed, circular, and layered digraph layout, and many custom layout extensions and examples.
GoJS is renders either to an HTML Canvas element (with export to SVG or image formats) or directly as SVG DOM. GoJS can run in a web browser, or server side in Node or Puppeteer. GoJS Diagrams are backed by Models, with saving and loading typically via JSON-formatted text.
Read more about GoJS at gojs.net
This repository contains only the library. The sources for all samples, extensions, and documentation can be installed by running:
$ npm create gojs-kit@latest
You can use the GitHub repository to quickly search through all of the sources.
Minimal Sample
Graphs are constructed by creating one or more templates, with desired properties data-bound, and adding model data.
<div id="myDiagramDiv" style="width:400px; height:150px;"></div>
<script src="https://unpkg.com/gojs"></script>
<script>
const myDiagram = new go.Diagram(
'myDiagramDiv', // create a Diagram for the HTML Div element
{ 'undoManager.isEnabled': true }
); // enable undo & redo
// define a simple Node template
myDiagram.nodeTemplate = new go.Node('Auto') // the Shape will automatically surround the TextBlock
// add a Shape and a TextBlock to this "Auto" Panel
.add(
new go.Shape('RoundedRectangle', { strokeWidth: 0, fill: 'white' }) // no border; default fill is white
.bind('fill', 'color')
) // Shape.fill is bound to Node.data.color
.add(
new go.TextBlock({ margin: 8, stroke: '#333' }) // some room around the text
.bind('text', 'key')
); // TextBlock.text is bound to Node.data.key
// but use the default Link template, by not setting Diagram.linkTemplate
// create the model data that will be represented by Nodes and Links
myDiagram.model = new go.GraphLinksModel(
[
{ key: 'Alpha', color: 'lightblue' },
{ key: 'Beta', color: 'orange' },
{ key: 'Gamma', color: 'lightgreen' },
{ key: 'Delta', color: 'pink' },
],
[
{ from: 'Alpha', to: 'Beta' },
{ from: 'Alpha', to: 'Gamma' },
{ from: 'Beta', to: 'Beta' },
{ from: 'Gamma', to: 'Delta' },
{ from: 'Delta', to: 'Alpha' },
]
);
</script>
The above diagram and model code creates the following graph. The user can now click on nodes or links to select them, copy-and-paste them, drag them, delete them, scroll, pan, and zoom, with a mouse or with fingers.
Click the image to see the interactive GoJS Diagram
Support
Northwoods Software offers a month of free developer-to-developer support for GoJS to prospective customers so you can finish your project faster.
Read and search the official GoJS forum for any topics related to your questions.
Posting in the forum is the fastest and most effective way of obtaining support for any GoJS related inquiries. Please register for support at Northwoods Software's registration form before posting in the forum.
For any nontechnical questions about GoJS, such as about sales or licensing, please visit Northwoods Software's contact form.
License
The GoJS software license.
Copyright (c) Northwoods Software Corporation
Top Related Projects
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
♾ A Graph Visualization Framework in JavaScript.
Graph theory (network) library for visualisation and analysis
Directed graph layout for JavaScript
:dizzy: Display dynamic, automatically organised, customizable network views.
draw.io is a JavaScript, client-side editor for general diagramming.
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