force.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <script src="lib/jquery.min.js"></script>
  7. <script src="lib/dat.gui.min.js"></script>
  8. </head>
  9. <body>
  10. <style>
  11. html, body, #main {
  12. width: 100%;
  13. height: 100%;
  14. margin: 0;
  15. }
  16. </style>
  17. <div id="main"></div>
  18. <script>
  19. require([
  20. 'echarts',
  21. 'extension/dataTool/gexf',
  22. 'echarts/chart/graph',
  23. 'echarts/component/title',
  24. 'echarts/component/legend',
  25. 'echarts/component/geo',
  26. 'echarts/component/tooltip',
  27. 'echarts/component/visualMap'
  28. ], function (echarts) {
  29. var chart = echarts.init(document.getElementById('main'), null, {
  30. renderer: 'canvas'
  31. });
  32. function createNodes(count) {
  33. var nodes = [];
  34. for (var i = 0; i < count; i++) {
  35. nodes.push({
  36. id: i
  37. });
  38. }
  39. return nodes;
  40. }
  41. function createEdges(count) {
  42. var edges = [];
  43. if (count === 2) {
  44. return [[0, 1]];
  45. }
  46. for (var i = 0; i < count; i++) {
  47. edges.push([i, (i + 1) % count]);
  48. }
  49. return edges;
  50. }
  51. var datas = [];
  52. for (var i = 0; i < 16; i++) {
  53. datas.push({
  54. nodes: createNodes(i + 2),
  55. edges: createEdges(i + 2)
  56. });
  57. }
  58. chart.setOption({
  59. series: datas.map(function (item, idx) {
  60. return {
  61. type: 'graph',
  62. layout: 'force',
  63. animation: false,
  64. data: item.nodes,
  65. left: (idx % 4) * 25 + '%',
  66. top: Math.floor(idx / 4) * 25 + '%',
  67. width: '25%',
  68. height: '25%',
  69. force: {
  70. // initLayout: 'circular'
  71. // gravity: 0
  72. repulsion: 100,
  73. edgeLength: 5
  74. },
  75. edges: item.edges.map(function (e) {
  76. return {
  77. source: e[0],
  78. target: e[1]
  79. };
  80. })
  81. };
  82. })
  83. });
  84. });
  85. </script>
  86. </body>
  87. </html>