Bar.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. topSuite("Ext.chart.series.Bar", ['Ext.chart.*', 'Ext.data.ArrayStore'], function() {
  2. describe("x axis range", function () {
  3. var chart, layoutDone;
  4. afterEach(function () {
  5. chart = Ext.destroy(chart);
  6. layoutDone = false;
  7. });
  8. it("should be expanded on both sides by half bar width in case of two bars", function () {
  9. runs(function () {
  10. chart = Ext.create({
  11. xtype: 'cartesian',
  12. renderTo: document.body,
  13. width: 300,
  14. height: 200,
  15. store: {
  16. data: [{
  17. name: 'one',
  18. value: 1
  19. }, {
  20. name: 'two',
  21. value: 2
  22. }]
  23. },
  24. axes: [{
  25. type: 'numeric',
  26. position: 'left'
  27. }, {
  28. type: 'category',
  29. position: 'bottom'
  30. }],
  31. series: {
  32. type: 'bar',
  33. xField: 'name',
  34. yField: 'value'
  35. },
  36. listeners: {
  37. layout: function () {
  38. layoutDone = true;
  39. }
  40. }
  41. });
  42. });
  43. waitsFor(function () {
  44. return layoutDone;
  45. });
  46. runs(function () {
  47. var range = chart.getAxes()[1].getRange();
  48. // Original range of [0, 1] is expanded to fit the left side
  49. // of the left bar and the right side of the right bar.
  50. expect(range[0]).toBe(-0.5);
  51. expect(range[1]).toBe(1.5);
  52. });
  53. });
  54. it("should be expanded on both sides by half bar width in case of multiple bars", function () {
  55. runs(function () {
  56. chart = Ext.create({
  57. xtype: 'cartesian',
  58. renderTo: document.body,
  59. width: 300,
  60. height: 200,
  61. store: {
  62. data: [{
  63. name: 'one',
  64. value: 1
  65. }, {
  66. name: 'two',
  67. value: 2
  68. }, {
  69. name: 'three',
  70. value: 3
  71. }]
  72. },
  73. axes: [{
  74. type: 'numeric',
  75. position: 'left'
  76. }, {
  77. type: 'category',
  78. position: 'bottom'
  79. }],
  80. series: {
  81. type: 'bar',
  82. xField: 'name',
  83. yField: 'value'
  84. },
  85. listeners: {
  86. layout: function () {
  87. layoutDone = true;
  88. }
  89. }
  90. });
  91. });
  92. waitsFor(function () {
  93. return layoutDone;
  94. });
  95. runs(function () {
  96. var range = chart.getAxes()[1].getRange();
  97. // Original range of [0, 1] is expanded to fit the left side
  98. // of the left bar and the right side of the right bar.
  99. expect(range[0]).toBe(-0.5);
  100. expect(range[1]).toBe(2.5);
  101. });
  102. });
  103. it("should not be expanded in case of a single bar", function () {
  104. runs(function () {
  105. chart = Ext.create({
  106. xtype: 'cartesian',
  107. renderTo: document.body,
  108. width: 300,
  109. height: 200,
  110. store: {
  111. data: [{
  112. name: 'one',
  113. value: 1
  114. }]
  115. },
  116. axes: [{
  117. type: 'numeric',
  118. position: 'left'
  119. }, {
  120. type: 'category',
  121. position: 'bottom'
  122. }],
  123. series: {
  124. type: 'bar',
  125. xField: 'name',
  126. yField: 'value'
  127. },
  128. listeners: {
  129. layout: function () {
  130. layoutDone = true;
  131. }
  132. }
  133. });
  134. });
  135. waitsFor(function () {
  136. return layoutDone;
  137. });
  138. runs(function () {
  139. var range = chart.getAxes()[1].getRange();
  140. // Original range of [0, 1] is expanded to fit the left side
  141. // of the left bar and the right side of the right bar.
  142. expect(range[0]).toBe(-0.5);
  143. expect(range[1]).toBe(0.5);
  144. });
  145. });
  146. });
  147. });