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.

103 lines
2.6 KiB

9 years ago
9 years ago
  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. </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:8},
  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:8}
  68. }
  69. // network.clusterByNodeData(clusterOptionsByData)
  70. network.clustering.clusterOutliers({clusterNodeProperties: {borderWidth:8}})
  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.on("select", function(params) {
  80. if (params.nodes.length == 1) {
  81. if (network.clustering.isCluster(params.nodes[0]) == true) {
  82. network.clustering.openCluster(params.nodes[0])
  83. }
  84. }
  85. })
  86. // network.openCluster('bla');
  87. // network.openCluster('bla2');
  88. </script>
  89. </body>
  90. </html>