UNPKG

2.15 kBHTMLView Raw
1<!doctype html>
2<html>
3<head>
4 <title>Network | Label alignment</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: 400px;
13 border: 1px solid lightgray;
14 }
15 p {
16 max-width:600px;
17 }
18 </style>
19
20</head>
21
22<body>
23
24<p>Labels of edges can be aligned to edges in various ways.</p>
25<p>Text-alignment within node labels can be 'left' or 'center', other font alignments not implemented.</p>
26<p>Label alignment (placement of label &quot;box&quot;) for nodes (top, bottom, left, right, inside) is
27planned but not in vis yet.</p>
28<p>The click event is captured and displayed to illustrate how the clicking on labels works.
29You can drag the nodes over each other to see how this influences the click event values.
30</p>
31
32<div id="mynetwork"></div>
33<pre id="eventSpan"></pre>
34
35<script type="text/javascript">
36 // create an array with nodes
37 var nodes = [
38 {id: 1, label: 'Node 1'},
39 {id: 2, label: 'Node 2'},
40 {id: 3, label: 'Node 3:\nLeft-Aligned', font: {'face': 'Monospace', align: 'left'}},
41 {id: 4, label: 'Node 4'},
42 {id: 5, label: 'Node 5\nLeft-Aligned box', shape: 'box',
43 font: {'face': 'Monospace', align: 'left'}}
44 ];
45
46 // create an array with edges
47 var edges = [
48 {from: 1, to: 2, label: 'middle', font: {align: 'middle'}},
49 {from: 1, to: 3, label: 'top', font: {align: 'top'}},
50 {from: 2, to: 4, label: 'horizontal', font: {align: 'horizontal'}},
51 {from: 2, to: 5, label: 'bottom', font: {align: 'bottom'}}
52 ];
53
54 // create a network
55 var container = document.getElementById('mynetwork');
56 var data = {
57 nodes: nodes,
58 edges: edges
59 };
60 var options = {physics:false};
61 var network = new vis.Network(container, data, options);
62
63 network.on("click", function (params) {
64 params.event = "[original event]";
65 document.getElementById('eventSpan').innerHTML = '<h2>Click event:</h2>' + JSON.stringify(params, null, 4);
66 });
67</script>
68
69</body>
70</html>