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.

120 lines
3.7 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Static smooth curves</title>
  5. <script type="text/javascript" src="../../../../dist/vis.js"></script>
  6. <link href="../../../../dist/vis.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. #mynetwork {
  9. width: 500px;
  10. height: 500px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. <script src="../../../googleAnalytics.js"></script>
  15. </head>
  16. <body>
  17. <h2>Smooth curves</h2>
  18. <div style="width:700px; font-size:14px; text-align: justify;">
  19. All the smooth curves in the examples so far have been using dynamic smooth curves. This means that each curve has a
  20. support node which takes part in the physics simulation. For large networks or dense clusters, this may not be the ideal
  21. solution. To solve this, static smooth curves have been added. The static smooth curves are based only on the positions of the connected
  22. nodes. There are multiple ways to determine the way this curve is drawn. This example shows the effect of the different
  23. types. <br /> <br />
  24. Drag the node around to see how the smooth curves are drawn for each setting. For animated system, we
  25. recommend only the continuous mode. In the next example you can see the effect of these methods on a large network. Keep in mind
  26. that the direction (the from and to) of the curve matters.
  27. <br /> <br />
  28. When you select the dynamic type, you can see the interaction with the fixed node and the edge, any other type will not interact with other nodes.
  29. <br /> <br />
  30. </div>
  31. <p>
  32. Smooth curve type:
  33. <select id="dropdownID" onchange="update();">
  34. <option value="continuous" selected="selected">continuous</option>
  35. <option value="discrete">discrete</option>
  36. <option value="diagonalCross">diagonalCross</option>
  37. <option value="straightCross">straightCross</option>
  38. <option value="horizontal">horizontal</option>
  39. <option value="vertical">vertical</option>
  40. <option value="curvedCW">curvedCW</option>
  41. <option value="curvedCCW">curvedCCW</option>
  42. <option value="dynamic">dynamic</option>
  43. <option value="none">none</option>
  44. </select>
  45. </p>
  46. <p>
  47. Roundness (0..1): <input type="range" min="0" max="1" value="0.5" step="0.05" style="width:200px" id="roundnessSlider" onchange="update();"> <input id="roundnessScreen" style="width:30px;" value="0.5"> <br>(0.5 is max roundness for continuous, 1.0 for the others)
  48. </p>
  49. <div id="mynetwork"></div>
  50. <script type="text/javascript">
  51. var dropdown = document.getElementById("dropdownID");
  52. var roundnessSlider = document.getElementById("roundnessSlider");
  53. var roundnessScreen = document.getElementById("roundnessScreen");
  54. // create an array with nodes
  55. var nodes = [
  56. {id: 1, label: 'Fixed node', x:0, y:0, fixed:true},
  57. {id: 2, label: 'Drag me', x:150, y:130, physics:false},
  58. {id: 3, label: 'Obstacle', x:80, y:-80, fixed:true, mass:5}
  59. ];
  60. // create an array with edges
  61. var edges = [
  62. {from: 1, to: 2, arrows:'to'}
  63. ];
  64. // create a network
  65. var container = document.getElementById('mynetwork');
  66. var data = {
  67. nodes: nodes,
  68. edges: edges
  69. };
  70. var options = {
  71. physics:true,
  72. edges: {
  73. smooth: {
  74. type: 'continuous'
  75. }
  76. }
  77. };
  78. var network = new vis.Network(container, data, options);
  79. function update() {
  80. var type = dropdown.value;
  81. var options;
  82. var roundness = parseFloat(roundnessSlider.value);
  83. roundnessScreen.value = roundness;
  84. if (type === 'none') {
  85. options = {
  86. edges: {
  87. smooth: false
  88. }
  89. };
  90. }
  91. else {
  92. options = {
  93. edges: {
  94. smooth: {
  95. type: type,
  96. roundness: roundness
  97. }
  98. }
  99. };
  100. }
  101. network.setOptions(options);
  102. }
  103. update();
  104. </script>
  105. </body>
  106. </html>