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.

105 lines
2.8 KiB

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