vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

145 lines
3.6 KiB

<!doctype html>
<html>
<head>
<title>Network | Custom style</title>
<style type="text/css">
#mynetwork {
width: 600px;
height: 600px;
border: 1px solid lightgray;
}
</style>
<script type="text/javascript" src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var nodes = null;
var edges = null;
var options = null;
var network = null;
// Called when the Visualization API is loaded.
function draw() {
// create nodes
nodes = [
{id: 1, label: 'black node', group: 'black'},
{id: 2, label: 'black node', group: 'black'},
{id: 3, label: 'black node', group: 'black'},
{id: 4, label: 'red node', group: 'black', color: 'red'},
{id: 5, label: 'gray node', group: 'gray'},
{id: 6, label: 'gray node', group: 'gray'},
{id: 7, label: 'gray node', group: 'gray'},
{id: 8, label: 'gray node', group: 'gray'},
{id: 9, label: 'image node', group: 'white'},
{id: 10, label: 'image node', group: 'white'},
{id: 11, label: 'default node'},
{id: 12, label: 'default node'}
];
// create edges
edges = [
{from: 1, to: 2},
{from: 1, to: 3},
{from: 1, to: 4},
{from: 5, to: 6},
{from: 5, to: 7},
{from: 5, to: 8},
{from: 9, to: 10},
{from: 9, to: 11},
{from: 9, to: 12},
{from: 1, to: 5},
{from: 5, to: 9},
{from: 9, to: 1}
];
// specify options
options = {
physics: {
stabilization: false,
barnesHut: {
springLength:200
}
},
edges: {
width: 2,
arrows: 'to',
color: 'gray'
},
nodes: {
// default for all nodes
font: {
face: 'times'
},
shape: 'circle',
color: {
border: 'orange',
background: 'yellow',
highlight: {
border: 'darkorange',
background: 'gold'
}
}
},
groups: {
black: {
// defaults for nodes in this group
size: 15,
color: 'black',
font: {
color: 'white',
size: 18,
face: 'courier'
},
shape: 'box'
},
gray: {
color: {
border: 'black',
background: 'gray',
highlight: {
border: 'black',
background: 'lightgray'
}
},
font: {
size: 18,
face: 'arial'
},
shape: 'circle'
},
white: {
color: {
border: 'black',
background: 'white'
},
font: {
color: 'red'
},
shape: 'image',
image: 'img/soft-scraps-icons/User-Coat-Blue-icon.png'
}
}
};
// create the network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
network = new vis.Network(container, data, options);
}
</script>
<script src="../googleAnalytics.js"></script>
</head>
<p>
Custom styles for nodes can be applied globally, per group, of to individual nodes. Same holds for edges.
</p>
<body onload="draw()">
<div id="mynetwork"></div>
</body>
</html>