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.

145 lines
3.6 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Custom style</title>
  5. <style type="text/css">
  6. #mynetwork {
  7. width: 600px;
  8. height: 600px;
  9. border: 1px solid lightgray;
  10. }
  11. </style>
  12. <script type="text/javascript" src="../../dist/vis.js"></script>
  13. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  14. <script type="text/javascript">
  15. var nodes = null;
  16. var edges = null;
  17. var options = null;
  18. var network = null;
  19. // Called when the Visualization API is loaded.
  20. function draw() {
  21. // create nodes
  22. nodes = [
  23. {id: 1, label: 'black node', group: 'black'},
  24. {id: 2, label: 'black node', group: 'black'},
  25. {id: 3, label: 'black node', group: 'black'},
  26. {id: 4, label: 'red node', group: 'black', color: 'red'},
  27. {id: 5, label: 'gray node', group: 'gray'},
  28. {id: 6, label: 'gray node', group: 'gray'},
  29. {id: 7, label: 'gray node', group: 'gray'},
  30. {id: 8, label: 'gray node', group: 'gray'},
  31. {id: 9, label: 'image node', group: 'white'},
  32. {id: 10, label: 'image node', group: 'white'},
  33. {id: 11, label: 'default node'},
  34. {id: 12, label: 'default node'}
  35. ];
  36. // create edges
  37. edges = [
  38. {from: 1, to: 2},
  39. {from: 1, to: 3},
  40. {from: 1, to: 4},
  41. {from: 5, to: 6},
  42. {from: 5, to: 7},
  43. {from: 5, to: 8},
  44. {from: 9, to: 10},
  45. {from: 9, to: 11},
  46. {from: 9, to: 12},
  47. {from: 1, to: 5},
  48. {from: 5, to: 9},
  49. {from: 9, to: 1}
  50. ];
  51. // specify options
  52. options = {
  53. physics: {
  54. stabilization: false,
  55. barnesHut: {
  56. springLength:200
  57. }
  58. },
  59. edges: {
  60. width: 2,
  61. arrows: 'to',
  62. color: 'gray'
  63. },
  64. nodes: {
  65. // default for all nodes
  66. font: {
  67. face: 'times'
  68. },
  69. shape: 'circle',
  70. color: {
  71. border: 'orange',
  72. background: 'yellow',
  73. highlight: {
  74. border: 'darkorange',
  75. background: 'gold'
  76. }
  77. }
  78. },
  79. groups: {
  80. black: {
  81. // defaults for nodes in this group
  82. size: 15,
  83. color: 'black',
  84. font: {
  85. color: 'white',
  86. size: 18,
  87. face: 'courier'
  88. },
  89. shape: 'box'
  90. },
  91. gray: {
  92. color: {
  93. border: 'black',
  94. background: 'gray',
  95. highlight: {
  96. border: 'black',
  97. background: 'lightgray'
  98. }
  99. },
  100. font: {
  101. size: 18,
  102. face: 'arial'
  103. },
  104. shape: 'circle'
  105. },
  106. white: {
  107. color: {
  108. border: 'black',
  109. background: 'white'
  110. },
  111. font: {
  112. color: 'red'
  113. },
  114. shape: 'image',
  115. image: 'img/soft-scraps-icons/User-Coat-Blue-icon.png'
  116. }
  117. }
  118. };
  119. // create the network
  120. var container = document.getElementById('mynetwork');
  121. var data = {
  122. nodes: nodes,
  123. edges: edges
  124. };
  125. network = new vis.Network(container, data, options);
  126. }
  127. </script>
  128. <script src="../googleAnalytics.js"></script>
  129. </head>
  130. <p>
  131. Custom styles for nodes can be applied globally, per group, of to individual nodes. Same holds for edges.
  132. </p>
  133. <body onload="draw()">
  134. <div id="mynetwork"></div>
  135. </body>
  136. </html>