getVisual.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* jshint maxlen:200 */
  2. describe('api/getVisual', function() {
  3. // TODO
  4. // test each chart type, which may set visual on view which can not get from List.
  5. // each of which should test visual map.
  6. // symbol and symbolSize should be tested.
  7. var utHelper = window.utHelper;
  8. var testCase = utHelper.prepare([
  9. 'echarts/src/chart/pie',
  10. 'echarts/src/chart/scatter',
  11. 'echarts/src/chart/graph',
  12. 'echarts/src/component/geo',
  13. 'echarts/src/component/grid',
  14. 'echarts/src/component/polar',
  15. 'echarts/src/component/visualMap',
  16. 'echarts/src/component/dataZoom'
  17. ]);
  18. testCase.createChart()('scatter', function () {
  19. var chart = this.chart;
  20. chart.setOption({
  21. xAxis: {},
  22. yAxis: {},
  23. color: ['#000', '#111', '#222'],
  24. visualMap: {
  25. seriesIndex: 3,
  26. demension: 1,
  27. min: 0,
  28. max: 10000,
  29. inRange: {
  30. color: 'red'
  31. }
  32. },
  33. series: [
  34. {
  35. id: 'k0',
  36. type: 'scatter',
  37. data: [[1000, 700], [333, 222]]
  38. },
  39. {
  40. id: 'k1',
  41. type: 'scatter',
  42. data: [[10, 7]],
  43. itemStyle: {
  44. normal: {
  45. color: '#fff'
  46. }
  47. }
  48. },
  49. {
  50. id: 'k2',
  51. type: 'scatter',
  52. data: [
  53. [10, 7],
  54. {
  55. value: [333, 222],
  56. itemStyle: {
  57. normal: {
  58. color: '#ff0'
  59. }
  60. }
  61. }
  62. ],
  63. itemStyle: {
  64. normal: {
  65. color: '#eee'
  66. }
  67. }
  68. },
  69. {
  70. id: 'k3',
  71. type: 'scatter',
  72. data: [
  73. [10, 7],
  74. {
  75. value: [333, 9999],
  76. itemStyle: {
  77. normal: {
  78. color: '#ff0'
  79. }
  80. }
  81. }
  82. ],
  83. itemStyle: {
  84. normal: {
  85. color: '#eee'
  86. }
  87. }
  88. }
  89. ]
  90. });
  91. var width = chart.getWidth();
  92. expect(chart.getVisual({dataIndex: 1}, 'color')).toEqual('#000');
  93. expect(chart.getVisual({dataIndex: 0, seriesIndex: 1}, 'color')).toEqual('#fff');
  94. expect(chart.getVisual({seriesIndex: 1}, 'color')).toEqual('#fff');
  95. expect(chart.getVisual({dataIndex: 1, seriesId: 'k2'}, 'color')).toEqual('#ff0');
  96. expect(chart.getVisual({seriesId: 'k2'}, 'color')).toEqual('#eee');
  97. expect(chart.getVisual({dataIndex: 1, seriesId: 'k3'}, 'color')).toEqual('rgba(255,0,0,1)');
  98. expect(chart.getVisual({seriesId: 'k3'}, 'color')).toEqual('#eee');
  99. });
  100. testCase.createChart()('dataZoom', function () {
  101. var chart = this.chart;
  102. chart.setOption({
  103. xAxis: {},
  104. yAxis: {},
  105. color: ['#000', '#111', '#222'],
  106. dataZoom: {
  107. xAxisIndex: 0,
  108. startValue: 45
  109. },
  110. series: [
  111. {
  112. id: 'k2',
  113. type: 'scatter',
  114. data: [
  115. [10, 7],
  116. [20, 7],
  117. [30, 7],
  118. [40, 7],
  119. {
  120. value: [50, 222],
  121. itemStyle: {
  122. normal: {
  123. color: '#ff0'
  124. }
  125. }
  126. }
  127. ],
  128. itemStyle: {
  129. normal: {
  130. color: '#eee'
  131. }
  132. }
  133. }
  134. ]
  135. });
  136. var width = chart.getWidth();
  137. expect(chart.getVisual({dataIndex: 4, seriesId: 'k2'}, 'color')).toEqual('#ff0');
  138. expect(chart.getVisual({dataIndexInside: 0, seriesId: 'k2'}, 'color')).toEqual('#ff0');
  139. expect(chart.getVisual({dataIndex: 1, seriesId: 'k2'}, 'color')).toEqual('#eee');
  140. });
  141. // testCase.createChart()('pie', function () {
  142. // var chart = this.chart;
  143. // chart.setOption({
  144. // series: [
  145. // {
  146. // id: 'k1',
  147. // type: 'pie',
  148. // center: [40, '50%'],
  149. // radius: [10, '50%'],
  150. // data: [
  151. // {x: 1000, y: 2000},
  152. // {x: 1000, y: 5000},
  153. // {x: 3000, y: 5000},
  154. // {x: 3000, y: 2000}
  155. // ],
  156. // links: []
  157. // }
  158. // ]
  159. // });
  160. // var height = chart.getHeight();
  161. // expect(chart.containPixel('series', [40, height / 2])).toEqual(false);
  162. // expect(chart.containPixel('series', [40, height / 2 + 10])).toEqual(true);
  163. // expect(chart.containPixel('series', [9.5, 1])).toEqual(false);
  164. // });
  165. // testCase.createChart()('graph', function () {
  166. // var chart = this.chart;
  167. // chart.setOption({
  168. // series: [
  169. // {
  170. // id: 'k1',
  171. // type: 'graph',
  172. // left: 10,
  173. // right: '50%',
  174. // top: 30,
  175. // bottom: 40,
  176. // data: [
  177. // {x: 1000, y: 2000},
  178. // {x: 1000, y: 5000},
  179. // {x: 3000, y: 5000},
  180. // {x: 3000, y: 2000}
  181. // ],
  182. // links: []
  183. // }
  184. // ]
  185. // });
  186. // expect(chart.containPixel('series', [15, 35])).toEqual(true);
  187. // expect(chart.containPixel('series', [3, 4])).toEqual(false);
  188. // });
  189. });