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.

78 lines
2.2 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JS Bin</title>
  6. <script type="text/javascript" src="../dist/vis.js"></script> <!-- network handling framework -->
  7. <link href="../dist/vis.css" rel="stylesheet" type="text/css"/>
  8. <style type="text/css">
  9. #network{
  10. width: 1200px;
  11. height: 800px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>Network Test</h1>
  18. <div id="network"></div>
  19. <script>
  20. var nodes = new vis.DataSet([
  21. {id: 1, label: '1'},
  22. {id: 2, label: '2'},
  23. {id: 3, label: '3'},
  24. {id: 4, label: '4'},
  25. {id: 5, label: '5'},
  26. {id: 6, label: '6'},
  27. {id: 7, label: '7'},
  28. ]);
  29. var edges = new vis.DataSet([
  30. {id: "e1", from: 2, to: 1, label: "e1"},
  31. {id: "e2", from: 3, to: 1, label: "e2"},
  32. {id: "e3", from: 4, to: 1, label: "e3"},
  33. {id: "e4", from: 5, to: 1, label: "e4"},
  34. {id: "e5", from: 6, to: 1, label: "e5"},
  35. {id: "e6", from: 2, to: 7, label: "e6"},
  36. {id: "e7", from: 3, to: 7, label: "e7"},
  37. {id: "e8", from: 4, to: 7, label: "e8"},
  38. {id: "e9", from: 5, to: 7, label: "e9"},
  39. {id: "e10", from: 6, to: 7, label: "e10"},
  40. ]);
  41. // create a network
  42. var container = document.getElementById('network');
  43. var data = {
  44. nodes: nodes,
  45. edges: edges
  46. };
  47. var options = {
  48. layout: {randomSeed: 8},
  49. edges: {
  50. arrows: {
  51. to: {
  52. scaleFactor: 0.5
  53. }
  54. },
  55. font: {
  56. align: "middle"
  57. }
  58. }
  59. };
  60. var network = new vis.Network(container, data, options);
  61. var clusterOptionsByData = {
  62. joinCondition: function(node) {
  63. if (node.id > 1 && node.id < 7)
  64. return true;
  65. return false;
  66. },
  67. clusterNodeProperties: {id:"c1", label:'c1'}
  68. };
  69. network.cluster(clusterOptionsByData);
  70. setTimeout(function() {
  71. network.setOptions({layout: { hierarchical: { direction: "LR" }}});
  72. },2000)
  73. </script>
  74. </body>
  75. </html>