UNPKG

1.81 kBHTMLView Raw
1<!doctype html>
2<html>
3<head>
4 <title>Network | Label margins</title>
5
6 <script type="text/javascript" src="../../../dist/vis-network.min.js"></script>
7 <link href="../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
8
9 <style type="text/css">
10 #mynetwork {
11 width: 600px;
12 height: 600px;
13 border: 1px solid lightgray;
14 }
15 p {
16 max-width:600px;
17 }
18 </style>
19
20</head>
21
22<body>
23
24<p>The labels of box, circle, database, icon and text nodes may have different margin values.
25 Top, right, bottom and left margins may be different for each node.</p>
26<p>Setting the margin value in the network's nodes property sets it as the default.</p>
27<p>Setting a the value to a number uses that number for the margins. If the value is an object, a different value for each margin will be set.</p>
28<p>Note that negative values appropriately push labels outside the node.
29
30<div id="mynetwork"></div>
31
32<script type="text/javascript">
33 // create an array with nodes
34 var nodes = [
35 { id: 1, label: 'Default Value\n(5)', x: -150, y: -150 },
36 { id: 2, label: 'Single Value\n(25)', margin: 20, x: 0, y: 0 },
37 { id: 3, label: 'Different Values\n(10, 20, 40, 30)', margin: { top: 10, right: 20, bottom: 40, left: 30 }, x: 120, y: 120},
38 { id: 4, label: 'A Negative Value\n(10, 20, 40, -50)', margin: { top: 10, right: 20, bottom: 30, left: -20 }, x: 300, y: -300}
39 ];
40
41 // create an array with edges
42 var edges = [
43 {from: 1, to: 2},
44 {from: 2, to: 3},
45 {from: 3, to: 4}
46 ];
47
48 // create a network
49 var container = document.getElementById('mynetwork');
50 var data = {
51 nodes: nodes,
52 edges: edges
53 };
54 var options = {
55 nodes: {
56 shape: 'box'
57 }
58 };
59 var network = new vis.Network(container, data, options);
60</script>
61
62</body>
63</html>