PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/performance/option.js

https://gitlab.com/xbsd/echarts
JavaScript | 337 lines | 330 code | 6 blank | 1 comment | 22 complexity | 137d871f45ddb9b67530fee8642944b0 MD5 | raw file
  1. var randomDataLength = 10000;
  2. var randomData = (function (){
  3. var l = [];
  4. var len = randomDataLength;
  5. while(len--) {
  6. l.push(Math.round(Math.random()* 1000));
  7. }
  8. return l;
  9. })();
  10. function option(chartType, n) {
  11. var opt = {
  12. animation:false,
  13. title : {
  14. text: chartType + '性能测试',
  15. subtext: '自动生成' + n + '数据'
  16. },
  17. tooltip : {
  18. trigger: 'axis'
  19. },
  20. legend: {
  21. data:['性能测试']
  22. },
  23. toolbox: {
  24. show : true,
  25. feature : {
  26. mark : {show: true},
  27. //dataZoom : {show: true},
  28. dataView : {show: true, readOnly: false},
  29. magicType : {show: true, type: ['line', 'bar']},
  30. restore : {show: true},
  31. saveAsImage : {show: true}
  32. }
  33. },
  34. dataRange: {
  35. min: 0,
  36. max: 1000,
  37. calculable : true,
  38. color: ['orangered','yellow','lightskyblue']
  39. },
  40. series : [
  41. {
  42. name:'性能测试',
  43. type: chartType,
  44. mapType: 'world',
  45. roam: true,
  46. large:true,
  47. data: function (){
  48. switch(chartType) {
  49. case 'scatter' :
  50. return scatterData(n);
  51. case 'k' :
  52. return kData(n);
  53. case 'radar' :
  54. return radarData(n);
  55. case 'pie' :
  56. return pieData(n);
  57. case 'map' :
  58. return mapData(n);
  59. default :
  60. var list = [];
  61. for (var i = 1; i <= n; i++) {
  62. list.push({
  63. value : randomData[i % randomDataLength],
  64. name : i
  65. });
  66. }
  67. return list;
  68. }
  69. }()
  70. }
  71. ]
  72. };
  73. if (chartType == 'line'
  74. || chartType == 'bar'
  75. || chartType == 'k'
  76. ) {
  77. opt.xAxis = [
  78. {
  79. type : 'category',
  80. data : function (){
  81. var list = [];
  82. for (var i = 1; i <= n; i++) {
  83. list.push(i);
  84. }
  85. return list;
  86. }()
  87. }
  88. ];
  89. opt.yAxis = [
  90. {
  91. type : 'value'
  92. }
  93. ];
  94. }
  95. else if (chartType == 'scatter') {
  96. opt.xAxis = [
  97. {
  98. type : 'value'
  99. }
  100. ];
  101. opt.yAxis = [
  102. {
  103. type : 'value'
  104. }
  105. ];
  106. }
  107. else if (chartType == 'radar') {
  108. opt.polar = [
  109. {
  110. indicator : [
  111. { text: '1', max: 1000},
  112. { text: '2', max: 1000},
  113. { text: '3', max: 1000},
  114. { text: '4', max: 1000},
  115. { text: '3', max: 1000}
  116. ]
  117. }
  118. ];
  119. }
  120. else if (chartType == 'chord') {
  121. opt.series = chordSeries();
  122. }
  123. return opt;
  124. }
  125. function scatterData(n){
  126. var list = [];
  127. for (var i = 1; i <= n; i++) {
  128. list.push([
  129. i , randomData[i % randomDataLength]
  130. ]);
  131. }
  132. return list;
  133. }
  134. function kData(n){
  135. var list = [];
  136. for (var i = 1; i <= n; i++) {
  137. list.push([
  138. randomData[i % randomDataLength],
  139. randomData[(i+1) % randomDataLength],
  140. randomData[(i+2) % randomDataLength],
  141. randomData[(i+3) % randomDataLength]
  142. ]);
  143. }
  144. return list;
  145. }
  146. function radarData(n){
  147. var list = [];
  148. n = n > 200 ? 200 : n;
  149. for (var i = 1; i <= n; i++) {
  150. list.push({
  151. value : [
  152. randomData[i % randomDataLength],
  153. randomData[(i+1) % randomDataLength],
  154. randomData[(i+2) % randomDataLength],
  155. randomData[(i+3) % randomDataLength],
  156. randomData[(i+4) % randomDataLength]
  157. ],
  158. name : i
  159. });
  160. }
  161. return list;
  162. }
  163. function pieData(n){
  164. var list = [];
  165. n = n > 200 ? 200 : n;
  166. for (var i = 1; i <= n; i++) {
  167. list.push({
  168. value : randomData[i % randomDataLength],
  169. name : i
  170. });
  171. }
  172. return list;
  173. }
  174. function chordSeries() {
  175. return [
  176. {
  177. "name": "性能测试",
  178. "type": "chord",
  179. "showScaleText": false,
  180. "data": [
  181. {"name": "美国"},
  182. {"name": "叙利亚反对派"},
  183. {"name": "阿萨德"},
  184. {"name": "伊朗"},
  185. {"name": "塞西"},
  186. {"name": "哈马斯"},
  187. {"name": "以色列"},
  188. {"name": "穆斯林兄弟会"},
  189. {"name": "基地组织"},
  190. {"name": "俄罗斯"},
  191. {"name": "黎巴嫩什叶派"},
  192. {"name": "土耳其"},
  193. {"name": "卡塔尔"},
  194. {"name": "沙特"},
  195. {"name": "黎巴嫩逊尼派"}
  196. ],
  197. "matrix": [
  198. [0,100,0,0,0,0,100,0,0,0,0,0,0,0,0],
  199. [10,0,0,0,0,10,10,0,10,0,0,10,10,10,10],
  200. [0,0,0,10,0,0,0,0,0,10,10,0,0,0,0],
  201. [0,0,100,0,0,100,0,0,0,0,100,0,0,0,0],
  202. [0,0,0,0,0,0,0,0,0,0,0,0,0,10,0],
  203. [0,100,0,10,0,0,0,0,0,0,0,0,10,0,0],
  204. [10,100,0,0,0,0,0,0,0,0,0,0,0,0,0],
  205. [0,0,0,0,0,0,0,0,0,0,0,10,10,0,0],
  206. [0,100,0,0,0,0,0,0,0,0,0,0,0,0,0],
  207. [0,0,100,0,0,0,0,0,0,0,0,0,0,0,0],
  208. [0,0,100,10,0,0,0,0,0,0,0,0,0,0,0],
  209. [0,100,0,0,0,0,0,100,0,0,0,0,0,0,0],
  210. [0,100,0,0,0,100,0,100,0,0,0,0,0,0,0],
  211. [0,100,0,0,100,0,0,0,0,0,0,0,0,0,100],
  212. [0,100,0,0,0,0,0,0,0,0,0,0,0,10,0]
  213. ]
  214. },
  215. {
  216. "name": "反对",
  217. "type": "chord",
  218. "showScaleText": false,
  219. "data": [
  220. {"name": "美国"},
  221. {"name": "叙利亚反对派"},
  222. {"name": "阿萨德"},
  223. {"name": "伊朗"},
  224. {"name": "塞西"},
  225. {"name": "哈马斯"},
  226. {"name": "以色列"},
  227. {"name": "穆斯林兄弟会"},
  228. {"name": "基地组织"},
  229. {"name": "俄罗斯"},
  230. {"name": "黎巴嫩什叶派"},
  231. {"name": "土耳其"},
  232. {"name": "卡塔尔"},
  233. {"name": "沙特"},
  234. {"name": "黎巴嫩逊尼派"}
  235. ],
  236. "matrix": [
  237. [0,0,100,100,0,100,0,0,100,0,0,0,0,0,0],
  238. [0,0,0,10,0,0,0,0,0,10,10,0,0,0,0],
  239. [10,0,0,0,0,0,10,10,10,0,0,10,10,0,10],
  240. [10,100,0,0,0,0,0,0,0,0,0,0,0,0,0],
  241. [0,0,0,0,0,10,0,100,0,0,0,10,10,0,0],
  242. [10,0,0,0,100,0,10,0,0,0,0,0,0,0,0],
  243. [0,0,100,0,0,100,0,0,0,0,0,0,0,0,0],
  244. [0,0,100,0,10,0,0,0,0,0,0,0,0,10,0],
  245. [10,0,100,0,0,0,0,0,0,0,0,0,0,100,0],
  246. [0,100,0,0,0,0,0,0,0,0,0,0,0,0,0],
  247. [0,100,0,0,0,0,0,0,0,0,0,0,0,0,0],
  248. [0,0,100,0,100,0,0,0,0,0,0,0,0,0,0],
  249. [0,0,100,0,100,0,0,0,0,0,0,0,0,0,0],
  250. [0,0,0,0,0,0,0,100,10,0,0,0,0,0,0],
  251. [0,0,100,0,0,0,0,0,0,0,0,0,0,0,0]
  252. ]
  253. },
  254. {
  255. "name": "未表态",
  256. "type": "chord",
  257. "showScaleText": false,
  258. "data": [
  259. {"name": "美国"},
  260. {"name": "叙利亚反对派"},
  261. {"name": "阿萨德"},
  262. {"name": "伊朗"},
  263. {"name": "塞西"},
  264. {"name": "哈马斯"},
  265. {"name": "以色列"},
  266. {"name": "穆斯林兄弟会"},
  267. {"name": "基地组织"},
  268. {"name": "俄罗斯"},
  269. {"name": "黎巴嫩什叶派"},
  270. {"name": "土耳其"},
  271. {"name": "卡塔尔"},
  272. {"name": "沙特"},
  273. {"name": "黎巴嫩逊尼派"}
  274. ],
  275. "matrix": [
  276. [0,0,0,0,100,0,0,100,0,0,0,0,0,0,0],
  277. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  278. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  279. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  280. [10,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  281. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  282. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  283. [10,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  284. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  285. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  286. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  287. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  288. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  289. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  290. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  291. ]
  292. }
  293. ];
  294. }
  295. function mapData(n) {
  296. var countryList = [
  297. 'Afghanistan','Angola','Albania','United Arab Emirates','Argentina','Armenia',
  298. 'French Southern and Antarctic Lands','Australia','Austria','Azerbaijan','Burundi',
  299. 'Belgium','Benin','Burkina Faso','Bangladesh','Bulgaria','The Bahamas',
  300. 'Bosnia and Herzegovina','Belarus','Belize','Bermuda','Bolivia','Brazil','Brunei',
  301. 'Bhutan','Botswana','Central African Republic','Canada','Switzerland','Chile','China',
  302. 'Ivory Coast','Cameroon','Democratic Republic of the Congo','Republic of the Congo',
  303. 'Colombia','Costa Rica','Cuba','Northern Cyprus','Cyprus','Czech Republic','Germany',
  304. 'Djibouti','Denmark','Dominican Republic','Algeria','Ecuador','Egypt','Eritrea','Spain',
  305. 'Estonia','Ethiopia','Finland','Fiji','Falkland Islands','France','Gabon','United Kingdom',
  306. 'Georgia','Ghana','Guinea','Gambia','Guinea Bissau','Equatorial Guinea','Greece',
  307. 'Greenland','Guatemala','French Guiana','Guyana','Honduras','Croatia','Haiti','Hungary',
  308. 'Indonesia','India','Ireland','Iran','Iraq','Iceland','Israel','Italy','Jamaica','Jordan',
  309. 'Japan','Kazakhstan','Kenya','Kyrgyzstan','Cambodia','South Korea','Kosovo','Kuwait',
  310. 'Laos','Lebanon','Liberia','Libya','Sri Lanka','Lesotho','Lithuania','Luxembourg','Latvia',
  311. 'Morocco','Moldova','Madagascar','Mexico','Macedonia','Mali','Myanmar','Montenegro',
  312. 'Mongolia','Mozambique','Mauritania','Malawi','Malaysia','Namibia','New Caledonia','Niger',
  313. 'Nigeria','Nicaragua','Netherlands','Norway','Nepal','New Zealand','Oman','Pakistan',
  314. 'Panama','Peru','Philippines','Papua New Guinea','Poland','Puerto Rico','North Korea',
  315. 'Portugal','Paraguay','Qatar','Romania','Russia','Rwanda','Western Sahara','Saudi Arabia',
  316. 'Sudan','South Sudan','Senegal','Solomon Islands','Sierra Leone','El Salvador','Somaliland',
  317. 'Somalia','Republic of Serbia','Suriname','Slovakia','Slovenia','Sweden','Swaziland',
  318. 'Syria','Chad','Togo','Thailand','Tajikistan','Turkmenistan','East Timor',
  319. 'Trinidad and Tobago','Tunisia','Turkey','United Republic of Tanzania','Uganda','Ukraine',
  320. 'Uruguay','United States of America','Uzbekistan','Venezuela','Vietnam','Vanuatu',
  321. 'West Bank','Yemen','South Africa','Zambia','Zimbabwe'
  322. ];
  323. var list = [];
  324. for (var i = 0, l = countryList.length; i < l; i ++) {
  325. list.push({
  326. name : countryList[i],
  327. value : randomData[(i + n) % randomDataLength]
  328. });
  329. }
  330. return list;
  331. }