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.

121 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. </head>
  31. <body>
  32. <p>Nodes may be set to have fixed, minimum and maximum widths and minimum heights.
  33. Nodes with minimum heights may also have a vertical alignment set.</p>
  34. <p>Edges may be set to have maximum widths.</p>
  35. <div id="mynetwork"></div>
  36. <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>
  37. <p>The <code>widthConstraint: { minimum: value }</code> option sets the minimum width of the element to the value.</p>
  38. <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>
  39. <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>
  40. <div class="sep"></div>
  41. <p>The <code>heightConstraint: value</code> option sets the minimum height of the element to the value (respecting top and bottom margins).</p>
  42. <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>
  43. <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>
  44. <div class="sep"></div>
  45. <p>Node width and height constraints may both be applied together, of course.</p>
  46. <p>The constraint options may be applied to elements individually, or at the whole-set level.
  47. Whole-set node and edge constraints are exclusive.</p>
  48. <script type="text/javascript">
  49. var nodes = [
  50. { id: 100, label: 'This node has no fixed, minimum or maximum width or height', x: -50, y: -300 },
  51. { id: 210, widthConstraint: { minimum: 120 }, label: 'This node has a mimimum width', x: -400, y: -200 },
  52. { id: 211, widthConstraint: { minimum: 120 }, label: '...so does this', x: -500, y: -50 },
  53. { 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 },
  54. { id: 221, widthConstraint: { maximum: 170 }, label: '...this too', x: -100, y: 0 },
  55. { 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 },
  56. { id: 201, widthConstraint: 150, label: '...this as well', x: -300, y: 200 },
  57. { id: 300, heightConstraint: { minimum: 70 }, label: 'This node\nhas a\nminimum\nheight', x: 100, y: -150 },
  58. { id: 301, heightConstraint: { minimum: 70 }, label: '...this one here too', x: 100, y: 0 },
  59. { id: 400, heightConstraint: { minimum: 100, valign: 'top' }, label: 'Minimum height\nvertical alignment\nmay be top', x: 300, y: -200 },
  60. { id: 401, heightConstraint: { minimum: 100, valign: 'middle' }, label: 'Minimum height\nvertical alignment\nmay be middle\n(default)', x: 300, y: 0 },
  61. { id: 402, heightConstraint: { minimum: 100, valign: 'bottom' }, label: 'Minimum height\nvertical alignment\nmay be bottom', x: 300, y: 200 }
  62. ];
  63. var edges = [
  64. { from: 100, to: 210, label: "unconstrained to minimum width"},
  65. { from: 210, to: 211, label: "more minimum width"},
  66. { from: 100, to: 220, label: "unconstrained to maximum width"},
  67. { from: 220, to: 221, label: "more maximum width"},
  68. { from: 210, to: 200, label: "minimum width to fixed width"},
  69. { from: 220, to: 200, label: "maximum width to fixed width"},
  70. { from: 200, to: 201, label: "more fixed width"},
  71. { from: 100, to: 300, label: "unconstrained to minimum height"},
  72. { from: 300, to: 301, label: "more minimum height"},
  73. { from: 100, to: 400, label: "unconstrained to top valign"},
  74. { from: 400, to: 401, label: "top valign to middle valign"},
  75. { from: 401, to: 402, widthConstraint: { maximum: 150 }, label: "middle valign to bottom valign"},
  76. ];
  77. var container = document.getElementById('mynetwork');
  78. var data = {
  79. nodes: nodes,
  80. edges: edges
  81. };
  82. var options = {
  83. edges: {
  84. font: {
  85. size: 12
  86. },
  87. widthConstraint: {
  88. maximum: 90
  89. }
  90. },
  91. nodes: {
  92. shape: 'box',
  93. margin: 10,
  94. widthConstraint: {
  95. maximum: 200
  96. }
  97. },
  98. physics: {
  99. enabled: false
  100. }
  101. };
  102. var network = new vis.Network(container, data, options);
  103. </script>
  104. </body>
  105. </html>