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.

115 lines
3.4 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: 400px;
  10. height: 400px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. <script src="../googleAnalytics.js"></script>
  15. </head>
  16. <body>
  17. <h2>Static 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 nodes around each other 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. </div>
  29. <p>
  30. Smooth curve type:
  31. <select id="dropdownID">
  32. <option value="continuous" selected="selected">continuous</option>
  33. <option value="discrete">discrete</option>
  34. <option value="diagonalCross">diagonalCross</option>
  35. <option value="straightCross">straightCross</option>
  36. <option value="horizontal">horizontal</option>
  37. <option value="vertical">vertical</option>
  38. <option value="curvedCW">curvedCW</option>
  39. <option value="curvedCCW">curvedCCW</option>
  40. </select>
  41. </p>
  42. <p>
  43. Roundness (0..1): <input type="range" min="0" max="1" value="0.5" step="0.05" style="width:200px" id="roundnessSlider"> <input id="roundnessScreen" value="0.5"> (0.5 is max roundness for continuous, 1.0 for the others)
  44. </p>
  45. <div id="mynetwork"></div>
  46. <script type="text/javascript">
  47. var dropdown = document.getElementById("dropdownID");
  48. dropdown.onchange = update;
  49. var roundnessSlider = document.getElementById("roundnessSlider");
  50. roundnessSlider.onchange = update;
  51. var roundnessScreen = document.getElementById("roundnessScreen");
  52. // create an array with nodes
  53. var nodes = [
  54. {id: 1, label: 'Node 1'},
  55. {id: 2, label: 'Node 2', x:150, y:130, allowedToMoveX: true, allowedToMoveY: true}
  56. ];
  57. // create an array with edges
  58. var edges = [
  59. {from: 1, to: 2, style:"arrow"}
  60. ];
  61. // create a network
  62. var container = document.getElementById('mynetwork');
  63. var data = {
  64. nodes: nodes,
  65. edges: edges
  66. };
  67. var options = {
  68. physics:{
  69. barnesHut: {
  70. gravitationalConstant:0,
  71. springConstant:0,
  72. centralGravity: 0
  73. }
  74. },
  75. edges: {
  76. smooth: {
  77. dynamic: false,
  78. type: '1'
  79. }
  80. }
  81. };
  82. var network = new vis.Network(container, data, options);
  83. function update() {
  84. var type = dropdown.value;
  85. var roundness = parseFloat(roundnessSlider.value);
  86. roundnessScreen.value = roundness;
  87. var options = {
  88. edges: {
  89. smooth: {
  90. type: type,
  91. roundness: roundness
  92. }
  93. }
  94. };
  95. network.setOptions(options);
  96. }
  97. update();
  98. </script>
  99. </body>
  100. </html>