Convert Figma logo to code with AI

visjs logovis-network

:dizzy: Display dynamic, automatically organised, customizable network views.

3,042
371
3,042
326

Top Related Projects

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

Graph theory (network) library for visualisation and analysis

Force-directed graph rendered on HTML5 canvas

4,650

Directed graph layout for JavaScript

11,025

♾ A Graph Visualization Framework in JavaScript.

11,241

A JavaScript library aimed at visualizing graphs of thousands of nodes and edges

Quick Overview

Vis-Network is a powerful JavaScript library for visualizing and manipulating dynamic, automatically organized network graphs. It is part of the larger Vis.js library and provides an easy-to-use, interactive way to display complex network data in web applications.

Pros

  • Highly customizable with numerous options for node and edge styling
  • Supports large datasets with smooth performance
  • Interactive features like zooming, dragging, and selecting nodes/edges
  • Extensive documentation and active community support

Cons

  • Learning curve can be steep for advanced customizations
  • Limited built-in layouts compared to some other graph visualization libraries
  • Can be resource-intensive for very large networks
  • Occasional breaking changes between major versions

Code Examples

  1. Creating a basic network:
const nodes = new vis.DataSet([
  { id: 1, label: 'Node 1' },
  { id: 2, label: 'Node 2' },
  { id: 3, label: 'Node 3' }
]);

const edges = new vis.DataSet([
  { from: 1, to: 2 },
  { from: 1, to: 3 }
]);

const container = document.getElementById('mynetwork');
const data = { nodes, edges };
const options = {};
const network = new vis.Network(container, data, options);
  1. Customizing node appearance:
const nodes = new vis.DataSet([
  { id: 1, label: 'Node 1', color: '#FF0000', shape: 'circle' },
  { id: 2, label: 'Node 2', color: '#00FF00', shape: 'box' },
  { id: 3, label: 'Node 3', color: '#0000FF', shape: 'diamond' }
]);
  1. Adding event listeners:
network.on('click', function(params) {
  if (params.nodes.length > 0) {
    const nodeId = params.nodes[0];
    console.log('Clicked node:', nodeId);
  }
});

Getting Started

  1. Include the Vis-Network library in your HTML:
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
  1. Create a container element in your HTML:
<div id="mynetwork"></div>
  1. Initialize the network in your JavaScript:
const container = document.getElementById('mynetwork');
const data = {
  nodes: new vis.DataSet([
    { id: 1, label: 'Node 1' },
    { id: 2, label: 'Node 2' }
  ]),
  edges: new vis.DataSet([
    { from: 1, to: 2 }
  ])
};
const options = {};
const network = new vis.Network(container, data, options);

This will create a simple network with two connected nodes. You can then customize the appearance and behavior of the network using the various options and methods provided by the Vis-Network library.

Competitor Comparisons

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

Pros of vis

  • More comprehensive library with additional components (Timeline, Graph2D, Graph3D)
  • Longer development history and potentially more stable codebase
  • Larger community and more extensive documentation

Cons of vis

  • No longer actively maintained (last commit in 2019)
  • Potentially outdated dependencies and compatibility issues
  • Larger bundle size due to inclusion of multiple components

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 network = new vis.Network(container, {nodes: nodes, edges: edges}, options);

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

The code for creating a basic network is identical in both libraries, as vis-network is a focused subset of the larger vis library. The main difference lies in the import statements and available features rather than the core network creation syntax.

Graph theory (network) library for visualisation and analysis

Pros of Cytoscape.js

  • More extensive graph theory algorithms and analysis capabilities
  • Better performance for large-scale networks (10,000+ nodes)
  • More flexible styling options and customization

Cons of Cytoscape.js

  • Steeper learning curve due to more complex API
  • Less intuitive for simple network visualizations
  • Requires more setup and configuration for basic use cases

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 network = new vis.Network(container, data, options);

Cytoscape.js:

var cy = cytoscape({
  container: document.getElementById('cy'),
  elements: [
    { data: { id: 'a' } },
    { data: { id: 'b' } },
    { data: { id: 'ab', source: 'a', target: 'b' } }
  ],
  style: [ /* ... */ ],
  layout: { name: 'grid' }
});

Both libraries offer powerful network visualization capabilities, but Cytoscape.js provides more advanced features for complex graph analysis and large-scale networks, while Vis-Network is generally easier to use for simpler visualizations. The choice between them depends on the specific requirements of your project.

Force-directed graph rendered on HTML5 canvas

Pros of force-graph

  • Lightweight and focused solely on force-directed graphs
  • Supports 3D rendering out of the box
  • Easier to customize and extend with modular architecture

Cons of force-graph

  • Less comprehensive documentation compared to vis-network
  • Fewer built-in layout algorithms and customization options
  • Smaller community and ecosystem

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 network = new vis.Network(container, { nodes, edges }, options);

force-graph:

const Graph = ForceGraph()
  .graphData({
    nodes: [{ id: 1 }, { id: 2 }],
    links: [{ source: 1, target: 2 }]
  })
  .nodeLabel('id')
  (document.getElementById('graph'));

Both libraries offer straightforward ways to create and render graphs, but force-graph's API is more concise and functional. vis-network provides more granular control over data management with its DataSet objects, while force-graph focuses on a simpler, more declarative approach to graph creation and manipulation.

4,650

Directed graph layout for JavaScript

Pros of dagre

  • Specialized in directed graph layouts, offering efficient algorithms for hierarchical structures
  • Lightweight and focused, making it easier to integrate into existing projects
  • Better performance for large, complex graphs with many nodes and edges

Cons of dagre

  • Limited built-in styling options compared to vis-network's extensive customization
  • Lacks interactive features like zooming, panning, and drag-and-drop functionality
  • Requires additional libraries for rendering, as it only handles layout calculations

Code Comparison

vis-network example:

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

dagre example:

var g = new dagre.graphlib.Graph();
g.setNode("1", { label: "Node 1" });
g.setNode("2", { label: "Node 2" });
g.setEdge("1", "2");
dagre.layout(g);
// Additional rendering code required
11,025

♾ A Graph Visualization Framework in JavaScript.

Pros of G6

  • More extensive and customizable graph visualization options
  • Better performance for large-scale graphs
  • Active development with frequent updates and new features

Cons of G6

  • Steeper learning curve due to more complex API
  • Less comprehensive documentation in English
  • Smaller community compared to vis-network

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 network = new vis.Network(container, {nodes: nodes, edges: edges}, options);

G6:

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});
graph.data({
  nodes: [{id: 'node1'}, {id: 'node2'}],
  edges: [{source: 'node1', target: 'node2'}]
});
graph.render();

Both libraries offer graph visualization capabilities, but G6 provides more advanced features and better performance for complex graphs. vis-network has a simpler API and may be easier for beginners. G6 excels in customization and large-scale graph rendering, while vis-network has more extensive English documentation and a larger community. The choice between them depends on project requirements and developer expertise.

11,241

A JavaScript library aimed at visualizing graphs of thousands of nodes and edges

Pros of sigma.js

  • Lightweight and focused on performance, especially for large-scale graphs
  • Highly customizable rendering engine with WebGL support
  • Extensive plugin system for adding features and functionality

Cons of sigma.js

  • Less built-in layout algorithms compared to vis-network
  • Steeper learning curve for beginners due to its low-level API
  • Fewer out-of-the-box interactive features

Code Comparison

sigma.js:

const s = new Sigma({
  graph: {
    nodes: [{ id: "n1" }, { id: "n2" }],
    edges: [{ id: "e1", source: "n1", target: "n2" }]
  },
  container: 'graph-container'
});

vis-network:

const nodes = new DataSet([{ id: 1 }, { id: 2 }]);
const edges = new DataSet([{ from: 1, to: 2 }]);
const network = new Network(container, { nodes, edges }, options);

Both libraries offer powerful graph visualization capabilities, but sigma.js focuses on performance and customization for large-scale graphs, while vis-network provides more built-in features and a gentler learning curve for simpler use cases.

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

vis-network

example chart

Network is a visualization to display networks and networks consisting of nodes and edges. The visualization is easy to use and supports custom shapes, styles, colors, sizes, images, and more. The network visualization works smooth on any modern browser for up to a few thousand nodes and edges. To handle a larger amount of nodes, Network has clustering support. Network uses HTML canvas for rendering.

Badges

semantic-release Renovate npm

dependencies Status devDependencies Status peerDependencies Status

GitHub contributors Backers on Open Collective Sponsors on Open Collective

Install

Install via npm:

$ npm install vis-network

Example

A basic example on loading a Network is shown below. More examples can be found in the examples directory of the project.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Network</title>
    <script
      type="text/javascript"
      src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"
    ></script>
    <style type="text/css">
      #mynetwork {
        width: 600px;
        height: 400px;
        border: 1px solid lightgray;
      }
    </style>
  </head>
  <body>
    <div id="mynetwork"></div>
    <script type="text/javascript">
      // create an array with nodes
      var nodes = new vis.DataSet([
        { id: 1, label: "Node 1" },
        { id: 2, label: "Node 2" },
        { id: 3, label: "Node 3" },
        { id: 4, label: "Node 4" },
        { id: 5, label: "Node 5" },
      ]);

      // create an array with edges
      var edges = new vis.DataSet([
        { from: 1, to: 3 },
        { from: 1, to: 2 },
        { from: 2, to: 4 },
        { from: 2, to: 5 },
        { from: 3, to: 3 },
      ]);

      // create a network
      var container = document.getElementById("mynetwork");
      var data = {
        nodes: nodes,
        edges: edges,
      };
      var options = {};
      var network = new vis.Network(container, data, options);
    </script>
  </body>
</html>

Build

To build the library from source, clone the project from github

$ git clone git://github.com/visjs/vis-network.git

The source code uses the module style of node (require and module.exports) to organize dependencies. To install all dependencies and build the library, run npm install in the root of the project.

$ cd vis-network
$ npm install

Then, the project can be build running:

$ npm run build

Test

To test the library, install the project dependencies once:

$ npm install

Then run the tests:

$ npm run test

Contribute

Contributions to the vis.js library are very welcome! We can't do this alone!

Backers

Thank you to all our backers! 🙏

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

License

Copyright (C) 2010-2018 Almende B.V. and Contributors Copyright (c) 2018-2021 Vis.js contributors

Vis.js is dual licensed under both

and

Vis.js may be distributed under either license.

NPM DownloadsLast 30 Days