Top Related Projects
A JavaScript library aimed at visualizing graphs of thousands of nodes and edges
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
:dizzy: Display dynamic, automatically organised, customizable network views.
Graph theory (network) library for visualisation and analysis
3D force-directed graph component using ThreeJS/WebGL
A D3-based renderer for Dagre
Quick Overview
VivaGraphJS is a graph drawing library for JavaScript. It aims to provide a fast and customizable solution for rendering large graphs in the browser, supporting various layouts and rendering methods. The library is designed to be flexible and can be used with both Canvas and WebGL for optimal performance.
Pros
- High performance, capable of rendering large graphs with thousands of nodes
- Supports multiple rendering methods (SVG, Canvas, WebGL) for flexibility and performance
- Customizable layouts and appearance of nodes and edges
- Active development and community support
Cons
- Learning curve can be steep for complex graph visualizations
- Documentation could be more comprehensive, especially for advanced features
- Limited built-in graph analysis algorithms compared to some other libraries
- Performance may degrade with very large graphs (tens of thousands of nodes) in some browsers
Code Examples
- Creating a simple graph:
var graph = Viva.Graph.graph();
graph.addNode('1', { name: 'Node 1' });
graph.addNode('2', { name: 'Node 2' });
graph.addLink('1', '2');
- Rendering the graph using SVG:
var graphics = Viva.Graph.View.svgGraphics();
var renderer = Viva.Graph.View.renderer(graph, {
graphics: graphics
});
renderer.run();
- Customizing node appearance:
var graphics = Viva.Graph.View.svgGraphics();
graphics.node(function(node) {
return Viva.Graph.svg('circle')
.attr('r', 7)
.attr('fill', node.data.color || '#00a2e8');
});
var renderer = Viva.Graph.View.renderer(graph, { graphics: graphics });
renderer.run();
Getting Started
To get started with VivaGraphJS, follow these steps:
-
Include the library in your HTML file:
<script src="https://unpkg.com/vivagraphjs/dist/vivagraph.min.js"></script>
-
Create a container for the graph:
<div id="graph-container" style="width: 600px; height: 400px;"></div>
-
Initialize and render the graph:
var graph = Viva.Graph.graph(); graph.addNode('1'); graph.addNode('2'); graph.addLink('1', '2'); var renderer = Viva.Graph.View.renderer(graph, { container: document.getElementById('graph-container') }); renderer.run();
This will create a simple graph with two connected nodes. You can then customize the appearance and layout as needed.
Competitor Comparisons
A JavaScript library aimed at visualizing graphs of thousands of nodes and edges
Pros of sigma.js
- More extensive documentation and examples
- Built-in support for WebGL rendering, offering better performance for large graphs
- Active community and regular updates
Cons of sigma.js
- Steeper learning curve due to more complex API
- Heavier file size compared to VivaGraphJS
Code Comparison
sigma.js:
const s = new sigma({
graph: g,
container: 'sigma-container',
settings: {
defaultNodeColor: '#ec5148'
}
});
VivaGraphJS:
var graph = Viva.Graph.graph();
var renderer = Viva.Graph.View.renderer(graph, {
container: document.getElementById('graphDiv')
});
renderer.run();
Key Differences
- sigma.js offers more customization options out of the box
- VivaGraphJS has a simpler API, making it easier to get started
- sigma.js provides better performance for larger graphs due to WebGL support
- VivaGraphJS has a smaller file size, which can be beneficial for smaller projects
Both libraries are capable of rendering interactive graphs, but sigma.js is generally better suited for complex, large-scale visualizations, while VivaGraphJS excels in simplicity and ease of use for smaller projects.
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
Pros of vis
- More comprehensive library with multiple visualization types (networks, timelines, graphs)
- Extensive documentation and examples
- Active community and regular updates
Cons of vis
- Larger file size and potentially heavier performance impact
- Steeper learning curve due to more features and options
- Less focused on graph-specific optimizations
Code comparison
VivaGraphJS:
var graph = Viva.Graph.graph();
graph.addNode('id', {custom: 'property'});
graph.addLink('id1', 'id2');
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
vis:
var nodes = new vis.DataSet([{id: 1, label: 'Node 1'}]);
var edges = new vis.DataSet([{from: 1, to: 2}]);
var container = document.getElementById('mynetwork');
var data = {nodes: nodes, edges: edges};
var network = new vis.Network(container, data, options);
Summary
VivaGraphJS is a focused graph visualization library optimized for performance and large-scale graphs. It offers a simpler API but with fewer built-in features. vis is a more comprehensive visualization library with support for various chart types, including networks. It provides more options and features out-of-the-box but may have a steeper learning curve and potentially higher performance overhead for simpler use cases. The choice between the two depends on specific project requirements, desired customization level, and performance needs.
:dizzy: Display dynamic, automatically organised, customizable network views.
Pros of vis-network
- More comprehensive documentation and examples
- Wider range of built-in layouts and customization options
- Active development and community support
Cons of vis-network
- Larger file size and potentially slower performance for very large graphs
- Steeper learning curve due to more complex API
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);
VivaGraphJS:
var graph = Viva.Graph.graph();
graph.addNode('1', {label: 'Node 1'});
graph.addNode('2', {label: 'Node 2'});
graph.addLink('1', '2');
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
Both libraries offer graph visualization capabilities, but vis-network provides more out-of-the-box features and customization options. VivaGraphJS, on the other hand, focuses on performance and simplicity, making it potentially better suited for large-scale graph rendering. The code comparison shows that vis-network has a more structured approach to data management and network creation, while VivaGraphJS offers a more straightforward API for basic graph operations.
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- More comprehensive and feature-rich library for graph visualization and analysis
- Extensive documentation and active community support
- Built-in support for various graph algorithms and layouts
Cons of Cytoscape.js
- Steeper learning curve due to its extensive API and features
- Potentially slower performance for very large graphs compared to VivaGraphJS
Code Comparison
VivaGraphJS:
var graph = Viva.Graph.graph();
graph.addNode('hello');
graph.addNode('world');
graph.addLink('hello', 'world');
Cytoscape.js:
var cy = cytoscape({
elements: [
{ data: { id: 'hello' } },
{ data: { id: 'world' } },
{ data: { source: 'hello', target: 'world' } }
]
});
Both libraries offer straightforward ways to create and manipulate graphs, but Cytoscape.js provides a more declarative approach with its initialization options. VivaGraphJS focuses on simplicity and performance, while Cytoscape.js offers a wider range of built-in features and customization options.
Cytoscape.js is better suited for projects requiring advanced graph analysis and visualization techniques, whereas VivaGraphJS excels in scenarios where performance is critical, especially for large-scale graphs.
3D force-directed graph component using ThreeJS/WebGL
Pros of 3d-force-graph
- Specialized for 3D force-directed graphs
- Built-in support for WebGL rendering
- Extensive customization options for node and link appearance
Cons of 3d-force-graph
- Steeper learning curve due to 3D complexity
- Potentially higher performance overhead for large graphs
- Limited to 3D visualizations, less suitable for 2D-only use cases
Code Comparison
VivaGraphJS:
var graph = Viva.Graph.graph();
graph.addNode('1');
graph.addNode('2');
graph.addLink('1', '2');
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
3d-force-graph:
const Graph = ForceGraph3D()
.graphData({
nodes: [{ id: '1' }, { id: '2' }],
links: [{ source: '1', target: '2' }]
})
.nodeColor(() => 'red')
.linkWidth(2);
Both libraries offer graph visualization capabilities, but 3d-force-graph focuses on 3D representations with WebGL support, while VivaGraphJS provides more flexibility for both 2D and 3D graphs. 3d-force-graph offers more built-in customization options, whereas VivaGraphJS may require more manual configuration for advanced visualizations. The choice between them depends on the specific requirements of the project, such as dimensionality, performance needs, and desired level of customization.
A D3-based renderer for Dagre
Pros of dagre-d3
- Specialized for directed graphs and hierarchical layouts
- Integrates seamlessly with D3.js for enhanced visualization capabilities
- Provides automatic graph layout algorithms
Cons of dagre-d3
- Limited to directed graphs, less versatile for other graph types
- May have performance issues with very large graphs
- Less active development and community support
Code Comparison
VivaGraphJS:
var graph = Viva.Graph.graph();
graph.addNode('1');
graph.addNode('2');
graph.addLink('1', '2');
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
dagre-d3:
var g = new dagreD3.graphlib.Graph().setGraph({});
g.setNode("1", { label: "Node 1" });
g.setNode("2", { label: "Node 2" });
g.setEdge("1", "2");
var render = new dagreD3.render();
render(d3.select("svg g"), g);
Summary
VivaGraphJS is a more general-purpose graph visualization library with better performance for large graphs and support for various graph types. It has a simpler API but requires more manual configuration for advanced layouts.
dagre-d3 excels in directed graph visualization and hierarchical layouts, leveraging D3.js for enhanced rendering. It offers automatic layout algorithms but may struggle with very large graphs and is less versatile for non-directed graph types.
Choose VivaGraphJS for general graph visualization needs and large-scale graphs, while dagre-d3 is better suited for directed graphs and when integration with D3.js is desired.
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
VivaGraph 
VivaGraphJS is designed to be extensible and to support different rendering engines and layout algorithms. Underlying algorithms have been broken out into ngraph.
The larger family of modules can be found by querying npm for "ngraph".
Enough talking. Show me the demo!
Some examples of library usage in the real projects:
- Amazon Visualization Shows related products on Amazon.com, uses SVG as graph output
- Graph Viewer visualization of sparse matrices collection of the University of Florida. WebGL based.
- Vkontakte Visualization friendship visualization of the largest social network in Russia vk.com. WebGL based.
To start using the library include vivagraph.js
script from the dist
folder. The following code is the minimum required to render a graph with two nodes and one edge:
var graph = Viva.Graph.graph();
graph.addLink(1, 2);
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
This will instantiate a graph inside document.body
:
If you want to render graph in your own DOM element:
var graph = Viva.Graph.graph();
graph.addLink(1, 2);
// specify where it should be rendered:
var renderer = Viva.Graph.View.renderer(graph, {
container: document.getElementById('graphDiv')
});
renderer.run();
The code above adds a link to the graph between nodes 1
and 2
. Since nodes
are not yet in the graph they will be created. It's equivalent to
var graph = Viva.Graph.graph();
graph.addNode(1);
graph.addNode(2);
graph.addLink(1, 2);
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
Customization
VivaGraphJS is all about customization. You can easily change the appearance of nodes and links. You can also change the layouting algorithm and medium that displays elements of the graph. For example: The following code allows you to use WebGL-based rendering, instead of the default SVG.
var graph = Viva.Graph.graph();
graph.addLink(1, 2);
var graphics = Viva.Graph.View.webglGraphics();
var renderer = Viva.Graph.View.renderer(graph,
{
graphics : graphics
});
renderer.run();
graphics
class is responsible for rendering nodes and links on the page. And renderer
orchestrates the process. To change nodes appearance tell graphics
how to represent them. Here is an example of graph with six people who I follow at github:
var graph = Viva.Graph.graph();
// Construct the graph
graph.addNode('anvaka', {url : 'https://secure.gravatar.com/avatar/91bad8ceeec43ae303790f8fe238164b'});
graph.addNode('manunt', {url : 'https://secure.gravatar.com/avatar/c81bfc2cf23958504617dd4fada3afa8'});
graph.addNode('thlorenz', {url : 'https://secure.gravatar.com/avatar/1c9054d6242bffd5fd25ec652a2b79cc'});
graph.addNode('bling', {url : 'https://secure.gravatar.com/avatar/24a5b6e62e9a486743a71e0a0a4f71af'});
graph.addNode('diyan', {url : 'https://secure.gravatar.com/avatar/01bce7702975191fdc402565bd1045a8?'});
graph.addNode('pocheptsov', {url : 'https://secure.gravatar.com/avatar/13da974fc9716b42f5d62e3c8056c718'});
graph.addNode('dimapasko', {url : 'https://secure.gravatar.com/avatar/8e587a4232502a9f1ca14e2810e3c3dd'});
graph.addLink('anvaka', 'manunt');
graph.addLink('anvaka', 'thlorenz');
graph.addLink('anvaka', 'bling');
graph.addLink('anvaka', 'diyan');
graph.addLink('anvaka', 'pocheptsov');
graph.addLink('anvaka', 'dimapasko');
// Set custom nodes appearance
var graphics = Viva.Graph.View.svgGraphics();
graphics.node(function(node) {
// The function is called every time renderer needs a ui to display node
return Viva.Graph.svg('image')
.attr('width', 24)
.attr('height', 24)
.link(node.data.url); // node.data holds custom object passed to graph.addNode();
})
.placeNode(function(nodeUI, pos){
// Shift image to let links go to the center:
nodeUI.attr('x', pos.x - 12).attr('y', pos.y - 12);
});
var renderer = Viva.Graph.View.renderer(graph, {
graphics : graphics
});
renderer.run();
The result is:
Tuning layout algorithm
Graphs vary by their nature. Some graphs have hundreds of nodes and few edges (or links), some might connect every node with every other. Tuning the physics often helps get the best layout. Consider the following example:
var graphGenerator = Viva.Graph.generator();
var graph = graphGenerator.grid(3, 3);
var renderer = Viva.Graph.View.renderer(graph);
renderer.run();
Graph generators are part of the library, which can produce classic graphs.
grid
generator creates a grid with given number of columns and rows. But with
default parameters the rendering is pretty ugly:
Let's tweak the original code:
var graphGenerator = Viva.Graph.generator();
var graph = graphGenerator.grid(3, 3);
var layout = Viva.Graph.Layout.forceDirected(graph, {
springLength : 10,
springCoeff : 0.0005,
dragCoeff : 0.02,
gravity : -1.2
});
var renderer = Viva.Graph.View.renderer(graph, {
layout : layout
});
renderer.run();
Now the result is much better:
You can tune values during simulation with layout.simulator.springLength(newValue)
, layout.simulator.springCoeff(newValue)
, etc. See all the values that you can tune in this source file.
Tuning layout algorithm is definitely one of the hardest part of using this library. It has to be improved in future to simplify usage. Each of the force directed algorithm parameters are described in the source code.
Design philosophy/roadmap
Until version 0.7.x VivaGraph was a single monolithic code base. Starting from
0.7.x the library is bundled from small npm modules into Viva
namespace.
All these modules are part of a larger ngraph
family. ngraph
modules support rendering graphs into images, 3D rendering,
integration with gephi, pagerank calculation and many more.
Version 0.7 is a compromise between maximum backward compatibility and ngraph flexibility. Eventually I hope to further simplify API and provide interface for custom builds.
Upgrade guide
Please refer the upgrade guide to see how to update older versions of the library to the latest one.
Local Build
Run the following script:
git clone https://github.com/anvaka/VivaGraphJS.git
cd ./VivaGraphJS
npm install
gulp release
The combined/minified code should be stored in dist
folder.
Looking for alternatives?
I'm trying to put up a list of all known graph drawing libraries. Please find it here
I need your feedback
Disclaimer: I wrote this library to learn JavaScript. By no means I pretend to be an expert in the language and chosen approach to design may not be the optimal. I would love to hear your feedback and suggestions.
Though I implemented this library from scratch, I went through many existing libraries to pick the best (at my view) out of them. If you are evaluating libraries for your project make sure to check them out as well.
My goal is to create highly performant javascript library, which serves in the field of graph drawing. To certain extent I achieved it. But I have no doubt there is much more to improve here.
Top Related Projects
A JavaScript library aimed at visualizing graphs of thousands of nodes and edges
⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
:dizzy: Display dynamic, automatically organised, customizable network views.
Graph theory (network) library for visualisation and analysis
3D force-directed graph component using ThreeJS/WebGL
A D3-based renderer for Dagre
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