Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vis-network

Package Overview
Dependencies
Maintainers
4
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vis-network

A dynamic, browser-based visualization library.

  • 9.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
118K
increased by0.65%
Maintainers
4
Weekly downloads
 
Created

What is vis-network?

The vis-network npm package is a dynamic, browser-based visualization library that allows you to create, manipulate, and interact with network graphs. It is highly customizable and supports a wide range of features for visualizing complex networks.

What are vis-network's main functionalities?

Create a Basic Network

This code demonstrates how to create a basic network with nodes and edges using vis-network. The nodes and edges are defined using DataSet objects, and the network is rendered in a container element.

const vis = require('vis-network');

const 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' }
]);

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

const container = document.getElementById('mynetwork');
const data = { nodes: nodes, edges: edges };
const options = {};
const network = new vis.Network(container, data, options);

Customize Node and Edge Styles

This code sample shows how to customize the styles of nodes and edges in a vis-network graph. Nodes can have different colors, shapes, and font sizes, while edges can have different colors and styles (e.g., dashed lines).

const vis = require('vis-network');

const nodes = new vis.DataSet([
  { id: 1, label: 'Node 1', color: '#ff0000' },
  { id: 2, label: 'Node 2', shape: 'box' },
  { id: 3, label: 'Node 3', font: { size: 20 } }
]);

const edges = new vis.DataSet([
  { from: 1, to: 2, color: '#00ff00' },
  { from: 2, to: 3, dashes: true }
]);

const container = document.getElementById('mynetwork');
const data = { nodes: nodes, edges: edges };
const options = {};
const network = new vis.Network(container, data, options);

Add Interaction Events

This code demonstrates how to add interaction events to a vis-network graph. In this example, a click event is added to the network, which triggers an alert displaying the ID of the clicked node.

const vis = require('vis-network');

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

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

const container = document.getElementById('mynetwork');
const data = { nodes: nodes, edges: edges };
const options = {};
const network = new vis.Network(container, data, options);

network.on('click', function (params) {
  alert('Clicked node: ' + params.nodes);
});

Other packages similar to vis-network

Keywords

FAQs

Package last updated on 03 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc