p.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. var developMode = false;
  2. if (developMode) {
  3. window.esl = null;
  4. window.define = null;
  5. window.require = null;
  6. (function () {
  7. var script = document.createElement('script');
  8. script.async = true;
  9. script.src = '../../doc/asset/js/esl/esl.js';
  10. if (script.readyState) {
  11. script.onreadystatechange = fireLoad;
  12. }
  13. else {
  14. script.onload = fireLoad;
  15. }
  16. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  17. function fireLoad() {
  18. script.onload = script.onreadystatechange = null;
  19. setTimeout(loadedListener,100);
  20. }
  21. function loadedListener() {
  22. // for develop
  23. require.config({
  24. packages: [
  25. {
  26. name: 'echarts',
  27. location: '../../src',
  28. main: 'echarts'
  29. },
  30. {
  31. name: 'zrender',
  32. //location: 'http://ecomfe.github.io/zrender/src',
  33. location: '../../../zrender/src',
  34. main: 'zrender'
  35. }
  36. ]
  37. });
  38. launchExample();
  39. }
  40. })();
  41. }
  42. else {
  43. // for echarts online home page
  44. require.config({
  45. paths:{
  46. echarts: '../../build/dist'
  47. }
  48. });
  49. launchExample();
  50. }
  51. var isExampleLaunched;
  52. function launchExample() {
  53. if (isExampleLaunched) {
  54. return;
  55. }
  56. // 按需加载
  57. isExampleLaunched = 1;
  58. require(
  59. [
  60. 'echarts',
  61. 'echarts/chart/line',
  62. 'echarts/chart/bar',
  63. 'echarts/chart/scatter',
  64. 'echarts/chart/k',
  65. 'echarts/chart/pie',
  66. 'echarts/chart/radar',
  67. 'echarts/chart/force',
  68. 'echarts/chart/chord',
  69. 'echarts/chart/map',
  70. 'echarts/chart/gauge',
  71. 'echarts/chart/funnel',
  72. 'echarts/chart/eventRiver'
  73. ],
  74. requireCallback
  75. );
  76. }
  77. var echarts;
  78. var myChart;
  79. function requireCallback (ec) {
  80. echarts = ec;
  81. myChart = echarts.init(domMain);
  82. var opt = option('line', 100);
  83. myChart.setOption(opt, true);
  84. document.getElementById('res').innerHTML = 'ready!<br/>';
  85. document.getElementById('run').onclick = start;
  86. document.getElementById('auto-run').onclick = autoStart;
  87. }
  88. var domMain = document.getElementById('main');
  89. var isRunning = false;
  90. var isRunning;
  91. var round;
  92. var n;
  93. var result;
  94. var total;
  95. var chartType;
  96. function start() {
  97. if (isRunning) {
  98. return;
  99. }
  100. isRunning = true;
  101. document.getElementById('res').innerHTML += 'running ';
  102. round = document.getElementById('round').value;
  103. n = document.getElementById('count').value;
  104. result = [];
  105. total = 0;
  106. chartType = document.getElementById('chart').value;
  107. setTimeout(run,50);
  108. }
  109. var cList = [
  110. 'line','bar','scatter','k',
  111. 'pie','radar','chord','map'
  112. ];
  113. var autoIdx = 0;
  114. var autoRun = false;
  115. function autoStart() {
  116. if (isRunning) {
  117. return;
  118. }
  119. autoIdx = 0;
  120. autoRun = true;
  121. autoCheck();
  122. }
  123. function autoCheck() {
  124. if (autoRun && autoIdx < cList.length) {
  125. document.getElementById('chart').value = cList[autoIdx++];
  126. start();
  127. }
  128. else {
  129. autoRun = false;
  130. autoIdx = 0;
  131. }
  132. }
  133. function run(){
  134. if (round--) {
  135. var opt = option(chartType, n - 0);
  136. var ticket = new Date();
  137. myChart.setOption(opt, true);
  138. ticket = new Date() - ticket;
  139. total += ticket
  140. result.push(ticket);
  141. setTimeout(run,200);
  142. //myChart.showLoading();
  143. }
  144. else {
  145. //myChart.hideLoading();
  146. isRunning = false;
  147. document.getElementById('res').innerHTML +=
  148. '【' + chartType + '】 : ' +
  149. (
  150. (chartType == 'map' || chartType == 'radar' || chartType == 'pie' || chartType == 'chord')
  151. ? (n > 200 ? 200 : n)
  152. : (n >= 10000 ? (n / 10000 + '万') : n)
  153. )
  154. + '个数据平均render时间:'
  155. + Math.round(total/result.length)
  156. + 'ms : [' + result.join(',') + ']<br/>';
  157. autoCheck();
  158. }
  159. }