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.

107 lines
3.3 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-network.min.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. #mynetwork {
  9. width: 600px;
  10. height: 600px;
  11. border: 1px solid lightgray;
  12. }
  13. p {
  14. max-width:600px;
  15. }
  16. h4 {
  17. margin-bottom:3px;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <p>
  23. Demonstrating getBaseEdges, getClusteredEdges updateEdge and updateClusteredNode. <br/><ul><li>Clicking on the cluster will change it to a star (updateClusteredNode).</li>
  24. <li>Clicking on an edge will make it red regardless of whether it is a clusteredEdge or not (updateEdge)</li>
  25. <li>Clicking on an edge will also show the results of getBaseEdges and getClusteredEdge</li>
  26. </ul>
  27. </p>
  28. <div id="mynetwork"></div>
  29. <pre id="eventSpan"></pre>
  30. <script type="text/javascript">
  31. // create an array with nodes
  32. var nodes = [
  33. {id: 1, label: 'Node 1', color:'orange'},
  34. {id: 2, label: 'Node 2', color:'DarkViolet', font:{color:'white'}},
  35. {id: 3, label: 'Node 3', color:'orange'},
  36. {id: 4, label: 'Node 4', color:'DarkViolet', font:{color:'white'}},
  37. {id: 5, label: 'Node 5', color:'orange'},
  38. {id: 6, label: 'cid = 1', cid:1, color:'orange'},
  39. {id: 7, label: 'cid = 1', cid:1, color:'DarkViolet', font:{color:'white'}},
  40. {id: 8, label: 'cid = 1', cid:1, color:'lime'},
  41. {id: 9, label: 'cid = 1', cid:1, color:'orange'},
  42. {id: 10, label: 'cid = 1', cid:1, color:'lime'}
  43. ];
  44. // create an array with edges
  45. var edges = [
  46. {from: 1, to: 2},
  47. {from: 1, to: 3},
  48. {from: 10, to: 4},
  49. {from: 2, to: 5},
  50. {from: 6, to: 2},
  51. {from: 7, to: 5},
  52. {from: 8, to: 6},
  53. {from: 9, to: 7},
  54. {from: 10, to: 9}
  55. ];
  56. // create a network
  57. var container = document.getElementById('mynetwork');
  58. var data = {
  59. nodes: nodes,
  60. edges: edges
  61. };
  62. var options = {layout:{randomSeed:8}};
  63. var network = new vis.Network(container, data, options);
  64. var clusterOptionsByData = {
  65. joinCondition:function(childOptions) {
  66. return childOptions.cid == 1;
  67. },
  68. clusterNodeProperties: {id:'cidCluster', borderWidth:3, shape:'database'}
  69. };
  70. network.cluster(clusterOptionsByData);
  71. network.on("selectNode", function(params) {
  72. if (params.nodes.length == 1) {
  73. if (network.isCluster(params.nodes[0]) == true) {
  74. network.clustering.updateClusteredNode(params.nodes[0], {shape : 'star'});
  75. }
  76. }
  77. });
  78. network.on("selectEdge", function(params) {
  79. if (params.edges.length == 1) {
  80. // Single edge selected
  81. var obj = {};
  82. obj.clicked_id = params.edges[0];
  83. network.clustering.updateEdge(params.edges[0], {color : '#aa0000'});
  84. obj.base_edges = network.clustering.getBaseEdges(params.edges[0]);
  85. obj.all_clustered_edges = network.clustering.getClusteredEdges(params.edges[0]);
  86. document.getElementById('eventSpan').innerHTML = '<h2>selectEdge event:</h2>' + JSON.stringify(obj, null, 4);
  87. }
  88. });
  89. </script>
  90. </body>
  91. </html>