middle-east-pre.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. var fs = require('fs');
  2. // http://international.caixin.com/2013-09-06/100579154.html
  3. var dataSource = [
  4. ['美国','叙利亚反对派',100,'green'],
  5. ['美国','阿萨德',100,'red'],
  6. ['美国','伊朗',100,'red'],
  7. ['美国','塞西',100,'yellow'],
  8. ['美国','哈马斯',100,'red'],
  9. ['美国','以色列',100,'green'],
  10. ['美国','穆斯林兄弟会',100,'yellow'],
  11. ['美国','基地组织',100,'red'],
  12. ['俄罗斯','叙利亚反对派',100,'red'],
  13. ['俄罗斯','阿萨德',100,'green'],
  14. ['伊朗','叙利亚反对派',100,'red'],
  15. ['伊朗','阿萨德',100,'green'],
  16. ['伊朗','黎巴嫩什叶派',100,'green'],
  17. ['伊朗','哈马斯',100,'green'],
  18. ['以色列','叙利亚反对派',100,'green'],
  19. ['以色列','阿萨德',100,'red'],
  20. ['以色列','哈马斯',100,'red'],
  21. ['土耳其','塞西',100,'red'],
  22. ['土耳其','穆斯林兄弟会',100,'green'],
  23. ['土耳其','叙利亚反对派',100,'green'],
  24. ['土耳其','阿萨德',100,'red'],
  25. ['卡塔尔','叙利亚反对派',100,'green'],
  26. ['卡塔尔','阿萨德',100,'red'],
  27. ['卡塔尔','塞西',100,'red'],
  28. ['卡塔尔','穆斯林兄弟会',100,'green'],
  29. ['卡塔尔','哈马斯',100,'green'],
  30. ['沙特','叙利亚反对派',100,'green'],
  31. ['沙特','黎巴嫩逊尼派',100,'green'],
  32. ['沙特','塞西',100,'green'],
  33. ['沙特','穆斯林兄弟会',100,'red'],
  34. ['塞西','穆斯林兄弟会',100,'red'],
  35. ['黎巴嫩逊尼派','叙利亚反对派',100,'green'],
  36. ['黎巴嫩逊尼派','阿萨德',100,'red'],
  37. ['黎巴嫩什叶派','叙利亚反对派',100,'red'],
  38. ['黎巴嫩什叶派','阿萨德',100,'green'],
  39. ['哈马斯','叙利亚反对派',100,'green'],
  40. ['哈马斯','塞西',100,'red'],
  41. ['穆斯林兄弟会','阿萨德',100,'red'],
  42. ['基地组织','叙利亚反对派',100,'green'],
  43. ['基地组织','阿萨德',100,'red'],
  44. ['基地组织','沙特',100,'red']
  45. ];
  46. var groupIndices = {};
  47. var count = 0;
  48. for (var i = 0; i < dataSource.length; i++) {
  49. var country = dataSource[i][0];
  50. var country2 = dataSource[i][1];
  51. if (groupIndices[country] === undefined) {
  52. groupIndices[country] = count++;
  53. }
  54. if (groupIndices[country2] === undefined) {
  55. groupIndices[country2] = count++;
  56. }
  57. }
  58. for (var i = 0; i < dataSource.length; i++) {
  59. var target = dataSource[i][1];
  60. if (groupIndices[target] === undefined) {
  61. groupIndices[target] = count++;
  62. }
  63. }
  64. var attitudeMap = {
  65. 'green' : 0,
  66. 'red' : 1,
  67. 'yellow' : 2
  68. }
  69. var series = [{
  70. name : '支持',
  71. type : 'chord',
  72. showScaleText : false,
  73. data : [],
  74. matrix : []
  75. }, {
  76. name : '反对',
  77. type : 'chord',
  78. showScaleText : false,
  79. data : [],
  80. matrix : []
  81. }, {
  82. name : '未表态',
  83. type : 'chord',
  84. showScaleText : false,
  85. data : [],
  86. matrix : []
  87. }];
  88. for (var k = 0; k < 3; k++) {
  89. series[k].matrix = [];
  90. for(var countryName in groupIndices) {
  91. var idx = groupIndices[countryName];
  92. series[k].data[idx] = {
  93. name : countryName
  94. }
  95. }
  96. for (var i = 0; i < count; i++) {
  97. series[k].matrix[i] = [];
  98. for (var j = 0; j < count; j++) {
  99. series[k].matrix[i][j] = 0;
  100. }
  101. }
  102. }
  103. for (var i = 0; i < dataSource.length; i++) {
  104. var sourceIdx = groupIndices[dataSource[i][0]];
  105. var targetIdx = groupIndices[dataSource[i][1]];
  106. var val = dataSource[i][2];
  107. var serieIdx = attitudeMap[dataSource[i][3]];
  108. var matrix = series[serieIdx].matrix;
  109. matrix[sourceIdx][targetIdx] += 100;
  110. matrix[targetIdx][sourceIdx] += 10;
  111. }
  112. var res = {
  113. title : {
  114. text : "中东地区的敌友关系",
  115. subtext: '数据来自财新网',
  116. x:'right',
  117. y:'bottom'
  118. },
  119. legend : {
  120. data : Object.keys(groupIndices),
  121. orient : 'vertical',
  122. x : 'left'
  123. },
  124. series : series
  125. }
  126. fs.writeFileSync("middle-east.js", 'define(' + JSON.stringify(series) + ')');