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.

74 lines
1.9 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: 600px;
  10. height: 400px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p>
  17. Create a simple network with some nodes and edges.
  18. </p>
  19. <div id="mynetwork"></div>
  20. <script type="text/javascript">
  21. var nodes = new vis.DataSet()
  22. nodes.add({id:'A', label:"A", x:0, y:0})
  23. nodes.add({id:'B', label:"B", x:100, y:0})
  24. nodes.add({id:'C', label:"C", x:200, y:0})
  25. nodes.add({id:'D', label:"D", x:0, y:100})
  26. nodes.add({id:'E', label:"E", x:100, y:100})
  27. nodes.add({id:'F', label:"F", x:200, y:100})
  28. nodes.add({id:'G', label:"G", x:-100, y:200})
  29. var edges = new vis.DataSet()
  30. edges.add({id:'1', from:"A", to:"B"})
  31. edges.add({id:'2', from:"B", to:"C"})
  32. edges.add({id:'3', from:"D", to:"E"})
  33. edges.add({id:'4', from:"E", to:"F"})
  34. edges.add({id:'5', from:"D", to:"G"})
  35. var options = {physics:false, edges:{smooth:false}};
  36. var network = new vis.Network(document.getElementById("mynetwork"), {
  37. nodes: nodes,
  38. edges: edges
  39. }, options)
  40. console.log("MAKE C1")
  41. network.cluster({
  42. joinCondition:function(nodeOptions) {
  43. return nodeOptions.id == "B" || nodeOptions.id == "E";
  44. },
  45. clusterNodeProperties: {id:'C1', label:"C1"}
  46. })
  47. console.log("MAKE C2")
  48. network.cluster({
  49. joinCondition:function(nodeOptions) {
  50. return nodeOptions.id == "D" || nodeOptions.id == "G";
  51. },
  52. clusterNodeProperties: {id:'C2', label:"C2"}
  53. })
  54. network.openCluster('C1', {
  55. releaseFunction: function (cpos, npos) {
  56. console.log(npos)
  57. return npos;
  58. }
  59. })
  60. </script>
  61. </body>
  62. </html>