614f28a8188aee681e5e7b1528e9785c1d59ac58.svn-base 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var myChart = [];
  2. var domCode = $("[md='sidebar-code']");
  3. var domGraphic = $("[md='graphic']");
  4. var domMain = $("[md='main']");
  5. var domMessage = $("[md='wrong-message']");
  6. var iconResize = $("[md='icon-resize']");
  7. var needRefresh = false;
  8. function findIdxFromEvent(event) {
  9. event = event || window.event;
  10. return findIdx(event.target || event.srcElement);
  11. }
  12. function findIdx(d) {
  13. var p = d;
  14. while (p.className != 'container-fluid') {
  15. p = p.parentElement;
  16. }
  17. return $(p).attr('idx');
  18. }
  19. var idx;
  20. function autoResize(event) {
  21. idx = findIdxFromEvent(event);
  22. if (iconResize[idx].className == 'icon-resize-full') {
  23. focusCode();
  24. iconResize[idx].className = 'icon-resize-small';
  25. }
  26. else {
  27. focusGraphic();
  28. iconResize[idx].className = 'icon-resize-full';
  29. }
  30. }
  31. function focusCode() {
  32. domCode[idx].className = 'span8 ani';
  33. domGraphic[idx].className = 'span4 ani';
  34. }
  35. function focusGraphic() {
  36. domCode[idx].className = 'span4 ani';
  37. domGraphic[idx].className = 'span8 ani';
  38. if (needRefresh) {
  39. myChart[idx].showLoading();
  40. setTimeout(refresh, 1000);
  41. }
  42. }
  43. var domTextarea = $("[md='code']");
  44. var editor = [];
  45. for (var i = 0, l = domTextarea.length; i < l; i++) {
  46. editor[i] = CodeMirror.fromTextArea(
  47. domTextarea[i],
  48. { lineNumbers: true }
  49. );
  50. editor[i].setOption("theme", 'monokai');
  51. editor[i].on('change', function (){needRefresh = true;});
  52. }
  53. function refresh(isBtnRefresh, idd){
  54. if (isBtnRefresh) {
  55. idx = idd;
  56. needRefresh = true;
  57. focusGraphic();
  58. return;
  59. }
  60. needRefresh = false;
  61. if (myChart[idx] && myChart[idx].dispose) {
  62. myChart[idx].dispose();
  63. }
  64. myChart[idx] = echarts.init(domMain[idx]);
  65. (new Function (editor[idx].doc.getValue().replace(
  66. 'option', 'option[' + idx + ']'))
  67. )()
  68. myChart[idx].setOption(option[idx], true);
  69. domMessage[idx].innerHTML = '';
  70. }
  71. function refreshAll() {
  72. for (var i = 0, l = myChart.length; i < l; i++) {
  73. (new Function (editor[i].doc.getValue().replace(
  74. 'option', 'option[' + i + ']'))
  75. )();
  76. myChart[i].setOption(option[i], true);
  77. domMessage[i].innerHTML = '';
  78. }
  79. }
  80. var developMode = false;
  81. if (developMode) {
  82. window.esl = null;
  83. window.define = null;
  84. window.require = null;
  85. (function () {
  86. var script = document.createElement('script');
  87. script.async = true;
  88. script.src = '../../doc/asset/js/esl/esl.js';
  89. if (script.readyState) {
  90. script.onreadystatechange = fireLoad;
  91. }
  92. else {
  93. script.onload = fireLoad;
  94. }
  95. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  96. function fireLoad() {
  97. script.onload = script.onreadystatechange = null;
  98. setTimeout(loadedListener,100);
  99. }
  100. function loadedListener() {
  101. // for develop
  102. require.config({
  103. packages: [
  104. {
  105. name: 'echarts',
  106. location: '../../src',
  107. main: 'echarts'
  108. },
  109. {
  110. name: 'zrender',
  111. //location: 'http://ecomfe.github.io/zrender/src',
  112. location: '../../../zrender/src',
  113. main: 'zrender'
  114. }
  115. ]
  116. });
  117. launchExample();
  118. }
  119. })();
  120. }
  121. else {
  122. // for echarts online home page
  123. require.config({
  124. paths:{
  125. echarts: '../../build/dist'
  126. }
  127. });
  128. launchExample();
  129. }
  130. var isExampleLaunched;
  131. function launchExample() {
  132. if (isExampleLaunched) {
  133. return;
  134. }
  135. // 按需加载
  136. isExampleLaunched = 1;
  137. require(
  138. [
  139. 'echarts',
  140. 'echarts/chart/line',
  141. 'echarts/chart/bar',
  142. 'echarts/chart/scatter',
  143. 'echarts/chart/k',
  144. 'echarts/chart/pie',
  145. 'echarts/chart/radar',
  146. 'echarts/chart/force',
  147. 'echarts/chart/chord',
  148. 'echarts/chart/map',
  149. 'echarts/chart/gauge',
  150. 'echarts/chart/funnel',
  151. 'echarts/chart/venn',
  152. 'echarts/chart/treemap',
  153. 'echarts/chart/tree',
  154. 'echarts/chart/eventRiver'
  155. ],
  156. requireCallback
  157. );
  158. }
  159. var echarts;
  160. var option = {};
  161. function requireCallback (ec) {
  162. echarts = ec;
  163. if (myChart.length > 0) {
  164. for (var i = 0, l = myChart.length; i < l; i++) {
  165. myChart[i].dispose && myChart[i].dispose();
  166. }
  167. }
  168. myChart = [];
  169. for (var i = 0, l = domMain.length; i < l; i++) {
  170. myChart[i] = echarts.init(domMain[i]);
  171. }
  172. refreshAll();
  173. window.onresize = function (){
  174. for (var i = 0, l = myChart.length; i < l; i++) {
  175. myChart[i].resize && myChart[i].resize();
  176. }
  177. };
  178. }