vis-network vs react-graph-vis
Graph Visualization Architecture in React
vis-networkreact-graph-vis

Graph Visualization Architecture in React

vis-network is the core visualization engine used for drawing dynamic networks and graphs in browsers. It is framework-agnostic and provides the underlying logic for rendering nodes, edges, and physics simulations. react-graph-vis is a React component wrapper built on top of vis-network. It aims to simplify integration by exposing the library as a declarative React component, handling the lifecycle mounting and unmounting internally. While react-graph-vis offers convenience, vis-network provides direct access to the full API without an abstraction layer.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
vis-network1,088,2633,63584.6 MB3465 days ago(Apache-2.0 OR MIT)
react-graph-vis29,546992-596 years agoMIT

Graph Visualization in React: Wrapper vs Core Library

Both react-graph-vis and vis-network enable developers to build interactive network graphs, but they differ significantly in architecture. vis-network is the underlying engine, while react-graph-vis is a React-specific wrapper around it. Let's compare how they handle initialization, events, and updates.

πŸ—οΈ Initialization: Declarative Component vs Imperative Instance

react-graph-vis treats the graph as a standard React component.

  • You pass data and options as props.
  • The library handles mounting the canvas internally.
// react-graph-vis: Declarative component
import Graph from 'react-graph-vis';

function MyGraph() {
  const data = { nodes: [...], edges: [...] };
  const options = { physics: { enabled: true } };

  return <Graph graph={data} options={options} />;
}

vis-network requires you to create an instance manually.

  • You must use a ref to access the DOM container.
  • Initialization happens inside a useEffect hook.
// vis-network: Imperative instance
import { Network } from 'vis-network/standalone';
import { useEffect, useRef } from 'react';

function MyGraph() {
  const containerRef = useRef(null);

  useEffect(() => {
    const data = { nodes: [...], edges: [...] };
    const options = { physics: { enabled: true } };
    new Network(containerRef.current, data, options);
  }, []);

  return <div ref={containerRef} />;
}

πŸ–±οΈ Event Handling: Props Callbacks vs Instance Listeners

react-graph-vis defines events in a props object.

  • Events are passed directly to the component.
  • Syntax matches standard React event handlers.
// react-graph-vis: Events via props
const events = {
  click: (params) => {
    console.log('Node clicked', params.nodes);
  }
};

<Graph graph={data} events={events} />;

vis-network attaches listeners to the network instance.

  • You must store the instance to add listeners.
  • Requires cleanup to prevent memory leaks.
// vis-network: Events via instance
useEffect(() => {
  const network = new Network(containerRef.current, data, options);
  network.on('click', (params) => {
    console.log('Node clicked', params.nodes);
  });

  return () => network.destroy(); // Cleanup
}, []);

πŸ”„ State Updates: Props Diffing vs Manual Redraw

react-graph-vis attempts to handle updates via prop changes.

  • Passing new graph props triggers internal updates.
  • Less control over exactly how the update occurs.
// react-graph-vis: Update via props
function MyGraph({ nodes }) {
  const data = { nodes, edges: [] };
  // Component re-renders when nodes change
  return <Graph graph={data} />;
}

vis-network gives you methods to update data explicitly.

  • You can call setData or manipulate datasets directly.
  • Better performance for frequent updates.
// vis-network: Update via methods
useEffect(() => {
  const network = new Network(containerRef.current, data, options);
  
  // Update nodes later without full re-init
  network.setData({ nodes: newNodes, edges: data.edges });
}, [newNodes]);

πŸ› οΈ Maintenance: Wrapper Lag vs Core Stability

react-graph-vis depends on the maintainer updating the wrapper.

  • If the core library changes, the wrapper might break.
  • Community support varies compared to the core repo.
// react-graph-vis: Potential version mismatch
// You rely on the wrapper author to update vis-network deps
import Graph from 'react-graph-vis'; 

vis-network is the source of truth for features.

  • Updates are available immediately via npm.
  • Direct access to bug fixes and new features.
// vis-network: Direct dependency
// You control the version of vis-network directly
import { Network } from 'vis-network/standalone';

🀝 Similarities: Shared Core Engine

Since react-graph-vis wraps vis-network, they share the underlying rendering logic. Here are key overlaps:

1. 🎨 Same Visualization Options

  • Both use the same options object structure for physics, styling, and layout.
  • Configuration docs apply to both packages.
// Shared options structure
const options = {
  nodes: { shape: 'dot' },
  physics: { enabled: true }
};

2. πŸ“¦ Same Data Format

  • Both expect nodes and edges arrays or datasets.
  • No transformation needed when switching between them.
// Shared data structure
const data = {
  nodes: [{ id: 1, label: 'Node 1' }],
  edges: [{ from: 1, to: 2 }]
};

3. 🌐 Browser Compatibility

  • Both rely on HTML5 Canvas for rendering.
  • Support modern browsers without polyfills.
// Both render to a DOM container
<div id=

How to Choose: vis-network vs react-graph-vis

  • vis-network:

    Choose vis-network if you require full control over the network instance, need to access imperative methods, or want to ensure you are using the latest features without waiting for a wrapper update. It is ideal for complex applications where you need to manipulate the graph programmatically or integrate deeply with React state management. This approach requires more setup but offers better long-term stability and flexibility.

  • react-graph-vis:

    Choose react-graph-vis if you need to get a simple graph up and running quickly with minimal boilerplate. It is suitable for projects where you want declarative props to manage data and options without writing useEffect hooks for initialization. However, be aware that wrapper libraries may lag behind the core library in features or React version compatibility.

README for vis-network

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.