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.

104 lines
3.1 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Basic usage</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>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  15. <body>
  16. <div id="mynetwork"></div>
  17. <script type="text/javascript">
  18. // create an array with nodes
  19. var nodes = [
  20. {id: 1, label: 'Node 1'},
  21. {id: 2, label: 'Node 2'},
  22. {id: 3, label: 'Node 3'},
  23. {id: 4, label: 'Node 4'},
  24. {id: 5, label: 'Node 5'},
  25. {id: 6, label: 'Node 6', cid:1},
  26. {id: 7, label: 'Node 7', cid:1},
  27. {id: 8, label: 'Node 8', cid:1},
  28. {id: 9, label: 'Node 9', cid:1},
  29. {id: 10, label: 'Node 10', cid:1}
  30. ];
  31. // create an array with edges
  32. var edges = [
  33. {from: 1, to: 2},
  34. {from: 1, to: 3},
  35. {from: 10, to: 4},
  36. {from: 2, to: 5},
  37. {from: 6, to: 2},
  38. {from: 7, to: 5},
  39. {from: 8, to: 6},
  40. {from: 9, to: 7},
  41. {from: 10, to: 9}
  42. ];
  43. // create a network
  44. var container = document.getElementById('mynetwork');
  45. var data = {
  46. nodes: nodes,
  47. edges: edges
  48. };
  49. var options = {};
  50. var network = new vis.Network(container, data, options);
  51. var clusterOptions = {
  52. joinCondition:function(parentOptions,childOptions) {
  53. return true;
  54. },
  55. processClusterProperties: function (properties, childNodes, childEdges) {
  56. return properties;
  57. },
  58. clusterNodeProperties: {id:'bla', borderWidth:2},
  59. }
  60. var clusterOptionsByData = {
  61. joinCondition:function(childOptions) {
  62. return childOptions.cid == 1;
  63. },
  64. processClusterProperties: function (properties, childNodes, childEdges) {
  65. return properties;
  66. },
  67. clusterNodeProperties: {id:'bla', borderWidth:2}
  68. }
  69. // network.clusterByNodeData(clusterOptionsByData)
  70. network.clustering.clusterOutliers({clusterNodeProperties: {shape:'database',borderWidth:3}})
  71. // network.clusterByConnection(2, clusterOptions);
  72. // network.clusterByConnection(9, {
  73. // joinCondition:function(parentOptions,childOptions) {return true;},
  74. // processProperties:function (properties, childNodes, childEdges) {
  75. // return properties;
  76. // },
  77. // clusterNodeProperties: {id:'bla2', label:"bla2", borderWidth:8}
  78. // });
  79. network.body.emitter.on("select", function(params) {
  80. console.log("here1234")
  81. if (params.nodes.length == 1) {
  82. if (network.clustering.isCluster(params.nodes[0]) == true) {
  83. network.clustering.openCluster(params.nodes[0])
  84. }
  85. }
  86. })
  87. // network.openCluster('bla');
  88. // network.openCluster('bla2');
  89. </script>
  90. </body>
  91. </html>