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.

75 lines
2.2 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Cluster Test</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. #network_graph {
  10. width: 1000px;
  11. height: 800px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. </head>
  16. <body onload="draw()">
  17. <p>
  18. Clusters can contain other clusters, but clusters of a single node is only possible by adding
  19. <pre>allowSingleNodeCluster: true</pre>
  20. to clusterNodeProperties<br/>
  21. In this example repeatedly clicking on the node with open the Clusters.
  22. </p>
  23. <div id="network_graph"></div>
  24. <div id="info"></div>
  25. <script type="text/javascript">
  26. var network;
  27. var node_color = ['orange', 'green', 'red', 'yellow', 'cyan'];
  28. var node_shape = ['star', 'database', 'diamond', 'square', 'triangle'];
  29. var nodes = new vis.DataSet([
  30. {id: 'x', label: 'Node X'},
  31. {id: 'y', label: 'Node Y'},
  32. ]);
  33. var network_options = {};
  34. var edges = new vis.DataSet([
  35. {from: 'x', to: 'y'}
  36. ]);
  37. var cluster_id = 1;
  38. function draw() {
  39. network = new vis.Network(
  40. document.getElementById('network_graph'),
  41. {
  42. nodes: nodes,
  43. edges: edges
  44. },
  45. network_options
  46. );
  47. network.on('click', function (params) {
  48. if (params.nodes.length == 1) {
  49. if (network.isCluster(params.nodes[0]) == true) {
  50. network.openCluster(params.nodes[0]);
  51. }
  52. }
  53. });
  54. cluster();
  55. cluster();
  56. cluster();
  57. }
  58. function cluster() {
  59. var clusterOptions = {
  60. joinCondition: function (childOptions) {
  61. console.log(childOptions);
  62. return true;
  63. },
  64. clusterNodeProperties: {id: cluster_id, label: "Cluster " + cluster_id, color: node_color[cluster_id - 1], shape: node_shape[cluster_id - 1], allowSingleNodeCluster: true}
  65. };
  66. cluster_id++;
  67. network.cluster(clusterOptions);
  68. }
  69. </script>
  70. </body>
  71. </html>