Hey there!
I am trying to reproduce this: vis.js Network (Graph) - JSFiddle - Code Playground
For that, I am adding this to the my app’s custom code:
<script src="
https://cdn.jsdelivr.net/npm/vis-network@9.1.5/peer/umd/vis-network.min.js
"></script>
<link href="
https://cdn.jsdelivr.net/npm/vis-network@9.1.5/styles/vis-network.min.css
" rel="stylesheet">
<style>
#mynetwork {
width: 500px;
height: 350px;
border: 1px solid lightgray;
}
</style>
<script>
// 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
}]);
// create a network
var container = wwLib.getFrontDocument().querySelector('#mynetwork')
// provide the data in the vis format
var data = {
nodes: nodes,
edges: edges
};
var options = {
layout: {
randomSeed: undefined,
improvedLayout: true,
hierarchical: {
enabled: true,
levelSeparation: 180,
direction: 'UD', // UD, DU, LR, RL
sortMethod: 'directed' // hubsize, directed
}
}
}
// initialize your network!
var network = new vis.Network(container, data, options);
var nodeNo = 6;
wwLib.getFrontDocument().querySelector('#addnode').click(function () {
nodes.add({
id: nodeNo,
label: "Node " + nodeNo
});
edges.add({
id: nodeNo,
from: 1,
to: nodeNo
});
nodeNo++;
});
</script>
In the JS Fiddle they are using JQuery so I tried to account for that.
Using wwLib.getFrontDocument().querySelector('#mynetwork')
doesn’t work, and in this case using document.getElementById('mynetwork')
as well does not work.
Anyone know how I can make this work? Many thanks in advance!