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.

118 lines
5.3 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Label Width and Height Settings</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: 400px;
  11. border: 1px solid lightgray;
  12. }
  13. code {
  14. font-size: 14px;
  15. background: #dddddd;
  16. }
  17. p {
  18. max-width: 600px;
  19. }
  20. .indented {
  21. margin-left: 30px;
  22. }
  23. .sep {
  24. height: 1px;
  25. width: 35%;
  26. margin-left: 40px;
  27. background-color: #dddddd;
  28. }
  29. </style>
  30. <script src="../../googleAnalytics.js"></script>
  31. </head>
  32. <body>
  33. <p>Nodes may be set to have fixed, minimum and maximum widths and minimum heights.
  34. Nodes with minimum heights may also have a vertical alignment set.</p>
  35. <p>Edges may be set to have maximum widths.</p>
  36. <div id="mynetwork"></div>
  37. <p>The <code>widthConstraint: value</code> option means a fixed width, the minimum and maximum width of the element are set to the value (respecting left and right margins). Lines exceeding the maximum width will be broken at space boundaries to fit.</p>
  38. <p>The <code>widthConstraint: { minimum: value }</code> option sets the minimum width of the element to the value.</p>
  39. <p>The <code>widthConstraint: { maximum: value }</code> option sets the maximum width of the element to the value (respecting left and right margins). Lines exceeding the maximum width will be broken at space boundaries to fit.</p>
  40. <p>Minimum width line sizing is applied after maximum width line breaking, so counterintuitively, the minimum being greater than the maximum has a meaningful interpretation.</p>
  41. <div class="sep"></div>
  42. <p>The <code>heightConstraint: value</code> option sets the minimum height of the element to the value (respecting top and bottom margins).</p>
  43. <p>The <code>heightConstraint: { minimum: value }</code> option also sets the minimum height of the element to the value (respecting top and bottom margins).</p>
  44. <p>The <code>heightConstraint: { valign: value }</code> option (with value <code>'top'</code>, <code>'middle'</code>, or <code>'bottom'</code>, sets the alignment of the text in the element's label to the elements top, middle or bottom (respecting top and bottom margins) when it's height is less than the minimum. The middle value is the default.</p>
  45. <div class="sep"></div>
  46. <p>Node width and height constraints may both be applied together, of course.</p>
  47. <p>The constraint options may be applied to elements individually, or at the whole-set level.
  48. Whole-set node and edge constraints are exclusive.</p>
  49. <script type="text/javascript">
  50. var nodes = [
  51. { id: 100, label: 'This node has no fixed, minimum or maximum width or height', x: -50, y: -300 },
  52. { id: 210, widthConstraint: { minimum: 120 }, label: 'This node has a mimimum width', x: -400, y: -200 },
  53. { id: 211, widthConstraint: { minimum: 120 }, label: '...so does this', x: -500, y: -50 },
  54. { id: 220, widthConstraint: { maximum: 170 }, label: 'This node has a maximum width and breaks have been automatically inserted into the label', x: -150, y: -150 },
  55. { id: 221, widthConstraint: { maximum: 170 }, label: '...this too', x: -100, y: 0 },
  56. { id: 200, font: { multi: true }, widthConstraint: 150, label: '<b>This</b> node has a fixed width and breaks have been automatically inserted into the label', x: -300, y: 50 },
  57. { id: 201, widthConstraint: 150, label: '...this as well', x: -300, y: 200 },
  58. { id: 300, heightConstraint: { minimum: 70 }, label: 'This node\nhas a\nminimum\nheight', x: 100, y: -150 },
  59. { id: 301, heightConstraint: { minimum: 70 }, label: '...this one here too', x: 100, y: 0 },
  60. { id: 400, heightConstraint: { minimum: 100, valign: 'top' }, label: 'Minimum height\nvertical alignment\nmay be top', x: 300, y: -200 },
  61. { id: 401, heightConstraint: { minimum: 100, valign: 'middle' }, label: 'Minimum height\nvertical alignment\nmay be middle\n(default)', x: 300, y: 0 },
  62. { id: 402, heightConstraint: { minimum: 100, valign: 'bottom' }, label: 'Minimum height\nvertical alignment\nmay be bottom', x: 300, y: 200 }
  63. ];
  64. var edges = [
  65. { from: 100, to: 210, label: "unconstrained to minimum width"},
  66. { from: 210, to: 211, label: "more minimum width"},
  67. { from: 100, to: 220, label: "unconstrained to maximum width"},
  68. { from: 220, to: 221, label: "more maximum width"},
  69. { from: 210, to: 200, label: "minimum width to fixed width"},
  70. { from: 220, to: 200, label: "maximum width to fixed width"},
  71. { from: 200, to: 201, label: "more fixed width"},
  72. { from: 100, to: 300, label: "unconstrained to minimum height"},
  73. { from: 300, to: 301, label: "more minimum height"},
  74. { from: 100, to: 400, label: "unconstrained to top valign"},
  75. { from: 400, to: 401, label: "top valign to middle valign"},
  76. { from: 401, to: 402, label: "middle valign to bottom valign"},
  77. ];
  78. var container = document.getElementById('mynetwork');
  79. var data = {
  80. nodes: nodes,
  81. edges: edges
  82. };
  83. var options = {
  84. edges: {
  85. font: {
  86. size: 12
  87. },
  88. widthConstraint: {
  89. maximum: 90
  90. }
  91. },
  92. nodes: {
  93. shape: 'box',
  94. margin: 10
  95. },
  96. physics: {
  97. enabled: false
  98. }
  99. };
  100. var network = new vis.Network(container, data, options);
  101. </script>
  102. </body>
  103. </html>