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. //
  52. // var clusterOptions = {
  53. // joinCondition:function(parentOptions,childOptions) {
  54. // return true;
  55. // },
  56. // processClusterProperties: function (properties, childNodes, childEdges) {
  57. // return properties;
  58. // },
  59. // clusterNodeProperties: {id:'bla', borderWidth:2},
  60. // }
  61. var clusterOptionsByData = {
  62. joinCondition:function(childOptions) {
  63. console.log(childOptions.id)
  64. return childOptions.cid == 1;
  65. },
  66. processProperties: function (properties, childNodes, childEdges) {
  67. return properties;
  68. },
  69. clusterNodeProperties: {id:'bla', borderWidth:2}
  70. }
  71. network.clustering.cluster(clusterOptionsByData)
  72. // network.clustering.clusterOutliers({clusterNodeProperties: {shape:'database',borderWidth:3}})
  73. // network.clusterByConnection(2, clusterOptions);
  74. // network.clusterByConnection(9, {
  75. // joinCondition:function(parentOptions,childOptions) {return true;},
  76. // processProperties:function (properties, childNodes, childEdges) {
  77. // return properties;
  78. // },
  79. // clusterNodeProperties: {id:'bla2', label:"bla2", borderWidth:8}
  80. // });
  81. network.body.emitter.on("select", function(params) {
  82. if (params.nodes.length == 1) {
  83. if (network.clustering.isCluster(params.nodes[0]) == true) {
  84. network.clustering.openCluster(params.nodes[0])
  85. }
  86. }
  87. })
  88. // network.openCluster('bla');
  89. // network.openCluster('bla2');
  90. </script>
  91. </body>
  92. </html>