StackedCartesian.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. topSuite("Ext.chart.series.StackedCartesian",
  2. ['Ext.chart.*', 'Ext.data.ArrayStore', 'Ext.app.ViewController',
  3. 'Ext.Container', 'Ext.layout.Fit'],
  4. function() {
  5. describe('sprites', function () {
  6. var chart;
  7. afterEach(function() {
  8. Ext.destroy(chart);
  9. });
  10. it('should create the right number of sprites', function () {
  11. var layoutDone;
  12. runs(function () {
  13. chart = Ext.create({
  14. xtype: 'cartesian',
  15. renderTo: document.body,
  16. width: 500,
  17. height: 500,
  18. animation: false,
  19. legend: {
  20. docked: 'right'
  21. },
  22. axes: [{
  23. type: 'numeric',
  24. position: 'left',
  25. fields: 'data1',
  26. grid: true,
  27. minimum: 0
  28. }, {
  29. type: 'category',
  30. position: 'bottom',
  31. fields: 'month',
  32. grid: true
  33. }],
  34. series: [],
  35. listeners: {
  36. layout: function () {
  37. layoutDone = true;
  38. }
  39. }
  40. })
  41. });
  42. waitsFor(function () {
  43. return layoutDone;
  44. });
  45. runs(function () {
  46. layoutDone = false;
  47. chart.setStore(new Ext.data.Store({
  48. autoLoad: true,
  49. fields: ['month', 'data1', 'data2', 'data3', 'data4', 'other'],
  50. data: [{
  51. month: "Jan",
  52. data1: 20,
  53. data2: 37,
  54. data3: 35,
  55. data4: 4,
  56. other: 4
  57. }],
  58. listeners: {
  59. load: function () {
  60. var oldSeries = chart.getSeries();
  61. if (oldSeries) {
  62. chart.removeSeries(oldSeries);
  63. }
  64. chart.setSeries([{
  65. type: 'bar',
  66. title: ['IE', 'Firefox', 'Chrome', 'Safari'],
  67. xField: 'month',
  68. yField: ['data1', 'data2', 'data3', 'data4'],
  69. renderer: function () {
  70. return {};
  71. }
  72. }])
  73. }
  74. }
  75. }));
  76. });
  77. waitsFor(function () {
  78. return layoutDone;
  79. });
  80. runs(function () {
  81. layoutDone = false;
  82. var sprites = chart.getSeries()[0].getSprites();
  83. expect(sprites.length).toBe(4);
  84. expect(chart.getLegendStore().getCount()).toBe(4);
  85. expect(chart.getLegend().getSprites().length).toBe(4);
  86. });
  87. });
  88. });
  89. describe('highlight', function () {
  90. var chart;
  91. afterEach(function() {
  92. Ext.destroy(chart);
  93. });
  94. it('should propagate to "items" and "markers" templates of all MarkerHolder sprites', function () {
  95. var layoutDone;
  96. runs(function () {
  97. chart = Ext.create({
  98. xtype: 'cartesian',
  99. animation: false,
  100. renderTo: document.body,
  101. width: 400,
  102. height: 400,
  103. store: {
  104. fields: ['x', 'y1', 'y2', 'y3'],
  105. data: [
  106. {
  107. x: 'one',
  108. y1: 1,
  109. y2: 2,
  110. y3: 3
  111. },
  112. {
  113. x: 'two',
  114. y1: 2,
  115. y2: 3,
  116. y3: 4
  117. }
  118. ]
  119. },
  120. axes: [{
  121. type: 'numeric',
  122. position: 'left'
  123. }, {
  124. type: 'category',
  125. position: 'bottom'
  126. }],
  127. series: [{
  128. type: 'area',
  129. xField: 'x',
  130. yField: [ 'y1', 'y2', 'y3' ],
  131. marker: {
  132. opacity: 0,
  133. scaling: 0.01
  134. },
  135. highlightCfg: {
  136. opacity: 1,
  137. scaling: 1.5
  138. }
  139. }, {
  140. type: 'bar',
  141. stacked: false,
  142. xField: 'x',
  143. yField: [ 'y1', 'y2', 'y3' ],
  144. highlight: true
  145. }],
  146. listeners: {
  147. layout: function () {
  148. layoutDone = true;
  149. }
  150. }
  151. });
  152. });
  153. waitsFor(function () {
  154. return layoutDone;
  155. });
  156. runs(function () {
  157. var seriesList = chart.getSeries(),
  158. i, j, series, sprites, sprite, items, markers, style;
  159. for (j = 0; j < seriesList.length; j++) {
  160. series = seriesList[j];
  161. sprites = series.getSprites();
  162. for (i = 0; i < sprites.length; i++) {
  163. sprite = sprites[i];
  164. if (sprite.isMarkerHolder) {
  165. items = sprite.getMarker('items');
  166. if (items) {
  167. // Bar series will have the 'items' markers, but not 'markers' markers.
  168. style = items.getTemplate().modifiers.highlight.getStyle();
  169. // Default highlight style (when 'highlight: true' is used)
  170. // for series is yellow fill ('#ffff00') and red stroke ('#ff0000').
  171. expect(style.fillStyle).toBe('#ffff00');
  172. expect(style.strokeStyle).toBe('#ff0000');
  173. }
  174. markers = sprite.getMarker('markers');
  175. if (markers) {
  176. // Area series will have the 'markers' markers, but not the 'items' markers.
  177. style = markers.getTemplate().modifiers.highlight.getStyle();
  178. // 'opacity' and 'scaling' are sprite attribute aliases which
  179. // expand into 'globalAlpha' and 'scalingX/Y'.
  180. expect(style.globalAlpha).toBe(1);
  181. expect(style.scalingX).toBe(1.5);
  182. expect(style.scalingY).toBe(1.5);
  183. }
  184. }
  185. }
  186. }
  187. });
  188. });
  189. });
  190. });