demo-compound.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <title>cytoscape-cose-bilkent.js demo (compound)</title>
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  6. <script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
  7. <!-- for testing with local version of cytoscape.js -->
  8. <!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
  9. <!--polyfills are needed for this extension for old browsers like IE -->
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.5.7/shim.min.js"></script>
  11. <script src="https://unpkg.com/layout-base/layout-base.js"></script>
  12. <script src="https://unpkg.com/cose-base/cose-base.js"></script>
  13. <script src="cytoscape-cose-bilkent.js"></script>
  14. <style>
  15. body {
  16. font-family: helvetica;
  17. font-size: 14px;
  18. }
  19. #cy {
  20. width: 100%;
  21. height: 90%;
  22. z-index: 999;
  23. }
  24. h1 {
  25. opacity: 0.5;
  26. font-size: 1em;
  27. }
  28. button {
  29. margin-right: 10px;
  30. }
  31. </style>
  32. <script>
  33. document.addEventListener('DOMContentLoaded', function(){
  34. var cy = window.cy = cytoscape({
  35. container: document.getElementById('cy'),
  36. ready: function(){
  37. this.nodes().forEach(function(node){
  38. let width = [30, 70, 110];
  39. let size = width[Math.floor(Math.random()*3)];
  40. node.css("width", size);
  41. node.css("height", size);
  42. });
  43. this.layout({name: 'cose-bilkent', animationDuration: 1000}).run();
  44. },
  45. style: [
  46. {
  47. selector: 'node',
  48. style: {
  49. 'background-color': '#ad1a66'
  50. }
  51. },
  52. {
  53. selector: ':parent',
  54. style: {
  55. 'background-opacity': 0.333
  56. }
  57. },
  58. {
  59. selector: 'edge',
  60. style: {
  61. 'width': 3,
  62. 'line-color': '#ad1a66'
  63. }
  64. }
  65. ],
  66. elements: [{ group:'nodes', data:{ id: 'n0'}},
  67. { group:'nodes', data:{ id: 'n1'}},
  68. { group:'nodes', data:{ id: 'n2'}},
  69. { group:'nodes', data:{ id: 'n3'}},
  70. { group:'nodes', data:{ id: 'n4', parent: 'n37'}},
  71. { group:'nodes', data:{ id: 'n5'}},
  72. { group:'nodes', data:{ id: 'n6'}},
  73. { group:'nodes', data:{ id: 'n7', parent: 'n37'}},
  74. { group:'nodes', data:{ id: 'n8', parent: 'n37'}},
  75. { group:'nodes', data:{ id: 'n9', parent: 'n37'}},
  76. { group:'nodes', data:{ id: 'n10', parent: 'n38'}},
  77. { group:'nodes', data:{ id: 'n12'}},
  78. { group:'nodes', data:{ id: 'n13'}},
  79. { group:'nodes', data:{ id: 'n14'}},
  80. { group:'nodes', data:{ id: 'n15'}},
  81. { group:'nodes', data:{ id: 'n16'}},
  82. { group:'nodes', data:{ id: 'n17'}},
  83. { group:'nodes', data:{ id: 'n18'}},
  84. { group:'nodes', data:{ id: 'n19'}},
  85. { group:'nodes', data:{ id: 'n20'}},
  86. { group:'nodes', data:{ id: 'n21'}},
  87. { group:'nodes', data:{ id: 'n22'}},
  88. { group:'nodes', data:{ id: 'n23'}},
  89. { group:'nodes', data:{ id: 'n24', parent: 'n39'}},
  90. { group:'nodes', data:{ id: 'n25', parent: 'n39'}},
  91. { group:'nodes', data:{ id: 'n26', parent: 'n42'}},
  92. { group:'nodes', data:{ id: 'n27', parent: 'n42'}},
  93. { group:'nodes', data:{ id: 'n28', parent: 'n42'}},
  94. { group:'nodes', data:{ id: 'n29', parent: 'n40'}},
  95. { group:'nodes', data:{ id: 'n31', parent: 'n41'}},
  96. { group:'nodes', data:{ id: 'n32', parent: 'n41'}},
  97. { group:'nodes', data:{ id: 'n33', parent: 'n41'}},
  98. { group:'nodes', data:{ id: 'n34', parent: 'n41'}},
  99. { group:'nodes', data:{ id: 'n35', parent: 'n41'}},
  100. { group:'nodes', data:{ id: 'n36', parent: 'n41'}},
  101. { group:'nodes', data:{ id: 'n37'}},
  102. { group:'nodes', data:{ id: 'n38'}},
  103. { group:'nodes', data:{ id: 'n39', parent: 'n43'}},
  104. { group:'nodes', data:{ id: 'n40', parent: 'n42'}},
  105. { group:'nodes', data:{ id: 'n41', parent: 'n42'}},
  106. { group:'nodes', data:{ id: 'n42', parent: 'n43'}},
  107. { group:'nodes', data:{ id: 'n43'}},
  108. { group:'edges', data:{ id: 'e0', source: 'n0', target: 'n1'} },
  109. { group:'edges', data:{ id: 'e1', source: 'n1', target: 'n2'} },
  110. { group:'edges', data:{ id: 'e2', source: 'n2', target: 'n3'} },
  111. { group:'edges', data:{ id: 'e3', source: 'n0', target: 'n3'} },
  112. { group:'edges', data:{ id: 'e4', source: 'n1', target: 'n4'} },
  113. { group:'edges', data:{ id: 'e5', source: 'n2', target: 'n4'} },
  114. { group:'edges', data:{ id: 'e6', source: 'n4', target: 'n5'} },
  115. { group:'edges', data:{ id: 'e7', source: 'n5', target: 'n6'} },
  116. { group:'edges', data:{ id: 'e8', source: 'n4', target: 'n6'} },
  117. { group:'edges', data:{ id: 'e9', source: 'n4', target: 'n7'} },
  118. { group:'edges', data:{ id: 'e10', source: 'n7', target: 'n8'} },
  119. { group:'edges', data:{ id: 'e11', source: 'n8', target: 'n9'} },
  120. { group:'edges', data:{ id: 'e12', source: 'n7', target: 'n9'} },
  121. { group:'edges', data:{ id: 'e13', source: 'n13', target: 'n14'} },
  122. { group:'edges', data:{ id: 'e14', source: 'n12', target: 'n14'} },
  123. { group:'edges', data:{ id: 'e15', source: 'n14', target: 'n15'} },
  124. { group:'edges', data:{ id: 'e16', source: 'n14', target: 'n16'} },
  125. { group:'edges', data:{ id: 'e17', source: 'n15', target: 'n17'} },
  126. { group:'edges', data:{ id: 'e18', source: 'n17', target: 'n18'} },
  127. { group:'edges', data:{ id: 'e19', source: 'n18', target: 'n19'} },
  128. { group:'edges', data:{ id: 'e20', source: 'n17', target: 'n20'} },
  129. { group:'edges', data:{ id: 'e21', source: 'n19', target: 'n20'} },
  130. { group:'edges', data:{ id: 'e22', source: 'n16', target: 'n20'} },
  131. { group:'edges', data:{ id: 'e23', source: 'n20', target: 'n21'} },
  132. { group:'edges', data:{ id: 'e25', source: 'n23', target: 'n24'} },
  133. { group:'edges', data:{ id: 'e26', source: 'n24', target: 'n25'} },
  134. { group:'edges', data:{ id: 'e27', source: 'n26', target: 'n38'} },
  135. { group:'edges', data:{ id: 'e29', source: 'n26', target: 'n39'} },
  136. { group:'edges', data:{ id: 'e30', source: 'n26', target: 'n27'} },
  137. { group:'edges', data:{ id: 'e31', source: 'n26', target: 'n28'} },
  138. { group:'edges', data:{ id: 'e33', source: 'n21', target: 'n31'} },
  139. { group:'edges', data:{ id: 'e35', source: 'n31', target: 'n33'} },
  140. { group:'edges', data:{ id: 'e36', source: 'n31', target: 'n34'} },
  141. { group:'edges', data:{ id: 'e37', source: 'n33', target: 'n34'} },
  142. { group:'edges', data:{ id: 'e38', source: 'n32', target: 'n35'} },
  143. { group:'edges', data:{ id: 'e39', source: 'n32', target: 'n36'} },
  144. { group:'edges', data:{ id: 'e40', source: 'n16', target: 'n40'} }
  145. ]
  146. });
  147. document.getElementById("layoutButton").addEventListener("click", function(){
  148. var layout = cy.layout({
  149. name: 'cose-bilkent',
  150. animate: 'end',
  151. animationEasing: 'ease-out',
  152. animationDuration: 1000,
  153. randomize: true
  154. });
  155. layout.run();
  156. });
  157. document.getElementById("randomize").addEventListener("click", function(){
  158. var layout = cy.layout({
  159. name: 'random',
  160. animate: true,
  161. animationDuration: 1000,
  162. animationEasing: 'ease-out'
  163. });
  164. layout.run();
  165. });
  166. });
  167. </script>
  168. </head>
  169. <body>
  170. <h1>cytoscape-cose-bilkent demo (compound)</h1>
  171. <button id="randomize" type="button">Randomize</button>
  172. <button id="layoutButton" type="button">CoSE-Bilkent</button>
  173. <div id="cy"></div>
  174. </body>
  175. </html>