force2.html 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/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'
  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, dataTool) {
  29. var gexf = dataTool.gexf;
  30. var chart = echarts.init(document.getElementById('main'), null, {
  31. });
  32. $.get('./data/les-miserables.gexf', function (xml) {
  33. var graph = gexf.parse(xml);
  34. var categories = [];
  35. for (var i = 0; i < 9; i++) {
  36. categories[i] = {
  37. name: '类目' + i
  38. };
  39. }
  40. graph.nodes.forEach(function (node) {
  41. node.itemStyle = null;
  42. node.symbolSize = 10;
  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. node.x = node.y = null;
  51. });
  52. chart.setOption({
  53. legend: [{
  54. // selectedMode: 'single',
  55. data: categories.map(function (a) {
  56. return a.name;
  57. })
  58. }],
  59. animationDurationUpdate: 1500,
  60. animationEasingUpdate: 'quinticInOut',
  61. series : [
  62. {
  63. name: 'Les Miserables',
  64. type: 'graph',
  65. layout: 'force',
  66. data: graph.nodes,
  67. links: graph.links,
  68. categories: categories,
  69. animation: false,
  70. roam: true,
  71. draggable: true,
  72. edgeSymbol: ['none', 'arrow'],
  73. edgeSymbolSize: 5,
  74. force: {
  75. repulsion: [0, 100]
  76. },
  77. label: {
  78. normal: {
  79. position: 'right'
  80. }
  81. }
  82. }
  83. ]
  84. });
  85. });
  86. });
  87. </script>
  88. </body>
  89. </html>