timelineOptions.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. describe('timelineOptions', function() {
  2. var utHelper = window.utHelper;
  3. var testCase = utHelper.prepare([
  4. 'echarts/src/component/grid',
  5. 'echarts/src/chart/line',
  6. 'echarts/src/chart/pie',
  7. 'echarts/src/chart/bar',
  8. 'echarts/src/component/timeline'
  9. ]);
  10. function getData0(chart, seriesIndex) {
  11. return getSeries(chart, seriesIndex).getData().get('y', 0);
  12. }
  13. function getSeries(chart, seriesIndex) {
  14. return chart.getModel().getComponent('series', seriesIndex);
  15. }
  16. testCase.createChart()('timeline_setOptionOnceMore_baseOption', function () {
  17. var option = {
  18. baseOption: {
  19. timeline: {
  20. axisType: 'category',
  21. autoPlay: false,
  22. playInterval: 1000
  23. },
  24. xAxis: {data: ['a']},
  25. yAxis: {}
  26. },
  27. options: [
  28. {
  29. series: [
  30. {type: 'line', data: [11]},
  31. {type: 'line', data: [22]}
  32. ]
  33. },
  34. {
  35. series: [
  36. {type: 'line', data: [111]},
  37. {type: 'line', data: [222]}
  38. ]
  39. }
  40. ]
  41. };
  42. var chart = this.chart;
  43. chart.setOption(option);
  44. expect(getData0(chart, 0)).toEqual(11);
  45. expect(getData0(chart, 1)).toEqual(22);
  46. chart.setOption({
  47. xAxis: {data: ['b']}
  48. });
  49. expect(getData0(chart, 0)).toEqual(11);
  50. expect(getData0(chart, 1)).toEqual(22);
  51. chart.setOption({
  52. xAxis: {data: ['c']},
  53. timeline: {
  54. currentIndex: 1
  55. }
  56. });
  57. expect(getData0(chart, 0)).toEqual(111);
  58. expect(getData0(chart, 1)).toEqual(222);
  59. });
  60. testCase.createChart()('timeline_setOptionOnceMore_substitudeTimelineOptions', function () {
  61. var option = {
  62. baseOption: {
  63. timeline: {
  64. axisType: 'category',
  65. autoPlay: false,
  66. playInterval: 1000,
  67. currentIndex: 2
  68. },
  69. xAxis: {data: ['a']},
  70. yAxis: {}
  71. },
  72. options: [
  73. {
  74. series: [
  75. {type: 'line', data: [11]},
  76. {type: 'line', data: [22]}
  77. ]
  78. },
  79. {
  80. series: [
  81. {type: 'line', data: [111]},
  82. {type: 'line', data: [222]}
  83. ]
  84. },
  85. {
  86. series: [
  87. {type: 'line', data: [1111]},
  88. {type: 'line', data: [2222]}
  89. ]
  90. }
  91. ]
  92. };
  93. var chart = this.chart;
  94. chart.setOption(option);
  95. var ecModel = chart.getModel();
  96. expect(getData0(chart, 0)).toEqual(1111);
  97. expect(getData0(chart, 1)).toEqual(2222);
  98. chart.setOption({
  99. baseOption: {
  100. backgroundColor: '#987654',
  101. xAxis: {data: ['b']}
  102. },
  103. options: [
  104. {
  105. series: [
  106. {type: 'line', data: [55]},
  107. {type: 'line', data: [66]}
  108. ]
  109. },
  110. {
  111. series: [
  112. {type: 'line', data: [555]},
  113. {type: 'line', data: [666]}
  114. ]
  115. }
  116. ]
  117. });
  118. var ecModel = chart.getModel();
  119. var option = ecModel.getOption();
  120. expect(option.backgroundColor).toEqual('#987654');
  121. expect(getData0(chart, 0)).toEqual(1111);
  122. expect(getData0(chart, 1)).toEqual(2222);
  123. chart.setOption({
  124. timeline: {
  125. currentIndex: 0
  126. }
  127. });
  128. expect(getData0(chart, 0)).toEqual(55);
  129. expect(getData0(chart, 1)).toEqual(66);
  130. chart.setOption({
  131. timeline: {
  132. currentIndex: 2
  133. }
  134. });
  135. // no 1111 2222 any more, replaced totally by new timeline.
  136. expect(getData0(chart, 0)).toEqual(55);
  137. expect(getData0(chart, 1)).toEqual(66);
  138. });
  139. });