graph.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. 'theme/vintage'
  29. ], function (echarts, gexf) {
  30. var chart = echarts.init(document.getElementById('main'), 'vintage', {
  31. renderer: 'canvas'
  32. });
  33. $.get('./data/les-miserables.gexf', function (xml) {
  34. var graph = gexf.parse(xml);
  35. var categories = [];
  36. for (var i = 0; i < 9; i++) {
  37. categories[i] = {
  38. name: '类目' + i
  39. };
  40. }
  41. graph.nodes.forEach(function (node) {
  42. delete node.itemStyle;
  43. node.value = node.symbolSize;
  44. node.label = {
  45. normal: {
  46. show: node.symbolSize > 30
  47. }
  48. };
  49. node.category = node.attributes['modularity_class'];
  50. });
  51. graph.links.forEach(function (link) {
  52. delete link.lineStyle;
  53. });
  54. var option = {
  55. tooltip: {},
  56. legend: [{
  57. // selectedMode: 'single',
  58. data: categories.map(function (a) {
  59. return a.name;
  60. })
  61. }],
  62. // visualMap: {
  63. // max: 100,
  64. // inRange: {
  65. // colorSaturation: [1, 0.3]
  66. // }
  67. // },
  68. animationDurationUpdate: 1500,
  69. animationEasingUpdate: 'quinticInOut',
  70. series : [
  71. {
  72. name: 'Les Miserables',
  73. type: 'graph',
  74. layout: 'none',
  75. data: graph.nodes,
  76. links: graph.links,
  77. categories: categories,
  78. roam: true,
  79. draggable: true,
  80. // edgeSymbol: ['none', 'arrow'],
  81. // scaleLimit: {
  82. // min: 1.5,
  83. // max: 2
  84. // },
  85. label: {
  86. normal: {
  87. position: 'right',
  88. formatter: '{b}'
  89. }
  90. },
  91. lineStyle: {
  92. normal: {
  93. curveness: 0.3
  94. }
  95. }
  96. }
  97. ]
  98. };
  99. chart.setOption(option);
  100. var config = {
  101. layout: 'none'
  102. };
  103. chart.on('click', function (params) {
  104. console.log(params, params.data);
  105. });
  106. var gui = new dat.GUI();
  107. gui.add(config, 'layout', ['none', 'circular'])
  108. .onChange(function (value) {
  109. chart.setOption({
  110. series: [{
  111. name: 'Les Miserables',
  112. layout: value
  113. }]
  114. });
  115. });
  116. });
  117. });
  118. </script>
  119. </body>
  120. </html>