Run tests for vis-network
masterTo run the test suite, ensure you have installed the project dependencies first, then execute the test command.
$ npm install
$ npm run testrepository·master·Indexed 25 days ago
https://github.com/visjs/vis-networkA dynamic, browser-based visualization library for displaying networks consisting of nodes and edges. It utilizes HTML canvas for smooth rendering of up to a few thousand elements and supports clustering for larger datasets. The library includes features for hierarchical layouts, customizable edge styling (including various endpoint types like arrows, circles, and boxes), and flexible node leveling.
To run the test suite, ensure you have installed the project dependencies first, then execute the test command.
$ npm install
$ npm run testYou can install the vis-network package using npm to include it in your project dependencies.
$ npm install vis-networkWhen contributing to the vis-network repository, follow these rules for Pull Requests:
develop branch. Pull-requests against the master branch will be closed. (Note: Changes to gh-pages are also acceptable).lib folder. Do not commit changes to the builds located in the dist folder.To build the library from the source code:
npm install.npm run build.$ git clone git://github.com/visjs/vis-network.git
$ cd vis-network
$ npm install
$ npm run buildTo use a hierarchical layout, you must ensure consistency in how levels are defined across your nodes:
level in their options, the engine will automatically determine levels using the sortMethod (e.g., hubsize or directed).level property in a node's options, all nodes in the network must have a level defined.Note: If some nodes have a level defined and others do not, the engine will throw an error: "To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes."
To initialize a network, you need a container element in your HTML, a vis.DataSet containing nodes and edges, and an options object. You then instantiate the network using new vis.Network(container, data, options).
<!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>When using the editEdge manipulation mode, you can provide a custom function via the options.editEdge configuration key to intercept and modify an existing edge's properties.
options.editEdge can be configured in two ways:
editWithoutDrag function.In both cases, the function must accept two arguments:
defaultData: An object containing the current edge properties (e.g., id, from, to, label).callback: A function that receives the finalizedData. The network will update the edge if the finalizedData is not null or undefined.The hierarchical layout can be enabled and customized via the hierarchical configuration object. When enabled, the layout engine automatically adapts physics and edge settings to suit a hierarchical structure.
Key options include:
enabled: Boolean to turn hierarchical layout on or off.levelSeparation: Distance between levels.nodeSpacing: Distance between nodes on the same level.treeSpacing: Distance between separate trees (sub-networks).blockShifting: Boolean to enable/disable the block-shifting algorithm.edgeMinimization: Boolean to enable/disable edge minimization.parentCentralization: Boolean to enable/disable parent centralization.direction: The orientation of the layout. Options: UD (Up-Down), DU (Down-Up), LR (Left-Right), RL (Right-Left).sortMethod: Method to determine node levels. Options: hubsize, directed, or custom (requires predefined levels).The ViewFitOptions interface defines the configuration for fitting the network view to specific elements and zoom constraints.
Properties:
nodes: An array of IdType (string or number) representing the node IDs that the view should fit to.minZoomLevel: A number representing the minimum allowed zoom level. Must be greater than zero.maxZoomLevel: A number representing the maximum allowed zoom level. Must be greater than or equal to minZoomLevel.The improvedLayout option enables the Kamada Kawai algorithm for positioning nodes. This is a heavy algorithm that may use clustering to improve performance on large networks.
improvedLayout: Boolean to enable/disable the improved layout.clusterThreshold: A threshold used to decide when to cluster nodes before running the Kamada Kawai algorithm. If the number of nodes exceeds this threshold, the engine will attempt to cluster them to reduce computational load.When using the addEdge manipulation mode, you can provide a custom function via the options.addEdge configuration key to intercept and modify the edge data before it is added to the network.
Your function must accept two arguments:
defaultData: An object containing the initial edge properties (e.g., from, to).callback: A function that receives the finalizedData. The network will only add the edge if the finalizedData is not null or undefined.When using the addNode manipulation mode, you can provide a custom function via the options.addNode configuration key to intercept and modify the node data before it is added to the network.
Your function must accept two arguments:
defaultData: An object containing the initial node properties (e.g., id, x, y, label).callback: A function that receives the finalizedData. The network will only add the node if the finalizedData is not null or undefined.