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.

173 lines
6.2 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <script type="text/javascript" src="../dist/vis.js"></script>
  7. <link href="../dist/vis.css" rel="stylesheet" type="text/css"/>
  8. <style type="text/css">
  9. #mynetwork {
  10. width: 600px;
  11. height: 400px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="mynetwork"></div>
  18. <script>
  19. var network = null;
  20. // create an array with nodes
  21. var nodes = new vis.DataSet([
  22. {id: 1, label: 'Node 1', cid:1},
  23. {id: 2, label: 'Node 2', cid:1},
  24. {id: 3, label: 'Node 3'},
  25. {id: 4, label: 'Node 4'},
  26. {id: 5, label: 'Node 5'}
  27. ]);
  28. // create an array with edges
  29. var edges = new vis.DataSet([
  30. {id: 'e1', from: 1, to: 3, label: 'hi'},
  31. {from: 1, to: 2},
  32. {from: 2, to: 4},
  33. {from: 2, to: 5}
  34. ]);
  35. var data = {
  36. nodes: nodes,
  37. edges: edges
  38. };
  39. var container = document.getElementById('mynetwork');
  40. function drawQuick() {
  41. draw({physics:{stabilization:false}});
  42. }
  43. function draw(options) {
  44. // clean
  45. if (network !== null) {
  46. network.destroy();
  47. network = null;
  48. }
  49. network = new vis.Network(container, data, options);
  50. }
  51. function clusterByCid() {
  52. drawQuick();
  53. var clusterOptionsByData = {
  54. joinCondition:function(childOptions) {
  55. return childOptions.cid == 1;
  56. },
  57. clusterNodeProperties: {id:'cidCluster', borderWidth:3, shape:'database'}
  58. }
  59. network.cluster(clusterOptionsByData);
  60. }
  61. function clusterByConnection() {
  62. drawQuick();
  63. network.clusterByConnection(1)
  64. }
  65. function clusterByHubsize() {
  66. drawQuick();
  67. var clusterOptionsByData = {
  68. processProperties: function(clusterOptions, childNodes) {
  69. clusterOptions.label = "[" + childNodes.length + "]";
  70. return clusterOptions;
  71. },
  72. clusterNodeProperties: {borderWidth:3, shape:'box', font:{size:30}}
  73. }
  74. network.clusterByHubsize(undefined, clusterOptionsByData);
  75. }
  76. function checkMethods() {
  77. var methods = [
  78. {name:"setSize", arguments: [200,300]},
  79. {name:"canvasToDOM", arguments: [{x:10,y:20}]},
  80. {name:"DOMtoCanvas", arguments: [{x:10,y:20}]},
  81. {name:"findNode", arguments: [1]},
  82. {name:"isCluster", arguments: [1]},
  83. {name:"cluster", arguments: null, func: clusterByCid},
  84. {name:"findNode", arguments: [1]},
  85. {name:"isCluster", arguments: ['cidCluster']},
  86. {name:"getNodesInCluster", arguments: ['cidCluster']},
  87. {name:"openCluster", arguments: ['cidCluster']},
  88. {name:"clusterByConnection",arguments: null, func: clusterByConnection},
  89. {name:"clusterByHubsize", arguments: null, func: clusterByHubsize},
  90. {name:"clusterOutliers", arguments: null, funcFirst: drawQuick},
  91. {name:"getSeed", arguments: null, funcFirst: drawQuick},
  92. {name:"enableEditMode", arguments: null},
  93. {name:"disableEditMode", arguments: null},
  94. {name:"addNodeMode", arguments: null},
  95. {name:"disableEditMode", arguments: null},
  96. {name:"editNode", arguments: null, funcFirst: function() {network.setOptions({manipulation:{editNode:function(data,callback) {callback(data);}}})}},
  97. {name:"disableEditMode", arguments: null},
  98. {name:"addEdgeMode", arguments: null},
  99. {name:"disableEditMode", arguments: null},
  100. {name:"editEdgeMode", arguments: null},
  101. {name:"disableEditMode", arguments: null},
  102. {name:"selectNodes", arguments: [[5], true]},
  103. {name:"deleteSelected", arguments: null, funcFirst:drawQuick},
  104. {name:"disableEditMode", arguments: null},
  105. {name:"getPositions", arguments: [[1]]},
  106. {name:"storePositions", arguments: null},
  107. {name:"getBoundingBox", arguments: [1]},
  108. {name:"getConnectedNodes", arguments: [1]},
  109. {name:"getConnectedEdges", arguments: [1]},
  110. {name:"startSimulation", arguments: null},
  111. {name:"stopSimulation", arguments: null},
  112. {name:"stabilize", arguments: null},
  113. {name:"getSelection", arguments: null},
  114. {name:"getSelectedNodes", arguments: null},
  115. {name:"getSelectedEdges", arguments: null},
  116. {name:"getNodeAt", arguments: [{x:10,y:20}]},
  117. {name:"getEdgeAt", arguments: [{x:10,y:20}]},
  118. {name:"selectNodes", arguments: [[1],false]},
  119. {name:"selectEdges", arguments: [['e1']]},
  120. {name:"unselectAll", arguments: null},
  121. {name:"redraw", arguments: null},
  122. {name:"getScale", arguments: null},
  123. {name:"getViewPosition", arguments: null},
  124. {name:"fit", arguments: null},
  125. {name:"moveTo", arguments: [{position:{x:0,y:0}}]},
  126. {name:"focus", arguments: [1]},
  127. {name:"releaseNode", arguments: null},
  128. ]
  129. drawQuick();
  130. for (var i = 0; i < methods.length; i++) {
  131. setTimeout(testMethod.bind(this,methods,i), i*50);
  132. }
  133. }
  134. function testMethod(methods,i) {
  135. var methodName = methods[i].name;
  136. console.log("Currently testing:", methodName);
  137. if (methods[i].funcFirst !== undefined) {
  138. methods[i].funcFirst();
  139. }
  140. if (methods[i].func !== undefined) {
  141. methods[i].func();
  142. }
  143. else {
  144. if (methods[i].arguments === null) {
  145. network[methodName].apply(network);
  146. }
  147. else {
  148. network[methodName].apply(network, methods[i].arguments)
  149. }
  150. }
  151. }
  152. checkMethods();
  153. </script>
  154. </body>
  155. </html>