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.

63 lines
1.8 KiB

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