jquery.flot.invertedaxis.Test.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* eslint-disable */
  2. /* global $, describe, it, xit, xdescribe, after, afterEach, expect*/
  3. describe('unit tests for the inverted scale functions', function () {
  4. var placeholder;
  5. beforeEach(function () {
  6. placeholder = setFixtures('<div id="test-container" style="width: 800px;height: 400px">')
  7. .find('#test-container');
  8. });
  9. it('should have reverse linear transform set properly', function () {
  10. var plot = $.plot(placeholder, [[0, 1, 2, 3]], {
  11. xaxes: [{
  12. mode: 'linear',
  13. inverted: true,
  14. }]
  15. });
  16. var axis = plot.getAxes().xaxis;
  17. expect(axis.options.transform.name).toBe('invertedTransform');
  18. expect(axis.options.inverseTransform.name).toBe('invertedTransform');
  19. });
  20. it('should have inverted log transform set properly', function () {
  21. var plot = $.plot(placeholder, [[0, 1, 2, 3]], {
  22. xaxes: [{
  23. mode: 'log',
  24. inverted: true,
  25. }]
  26. });
  27. var axis = plot.getAxes().xaxis;
  28. expect(axis.options.transform.name).toBe('invertedLogTransform');
  29. expect(axis.options.inverseTransform.name).toBe('invertedLogInverseTransform');
  30. });
  31. });
  32. describe("integration tests for the inverted scale functions", function () {
  33. var queryPlotForYTicks = function () {
  34. var actualTicks = [];
  35. var yAxisDivs = $('.yAxis');
  36. expect(yAxisDivs.length).toBe(1);
  37. var childDivs = yAxisDivs.find('.tickLabel');
  38. childDivs.each(function (i, e) {
  39. actualTicks.push({
  40. yPos: e.y.baseVal[0].value,
  41. tickName: e.textContent,
  42. });
  43. });
  44. return actualTicks
  45. .sort(function (a, b) { return b.yPos - a.yPos })
  46. .map(function (a) { return a.tickName });
  47. };
  48. var queryPlotForXTicks = function () {
  49. var actualTicks = [];
  50. var xAxisDivs = $('.xAxis');
  51. expect(xAxisDivs.length).toBe(1);
  52. var childDivs = xAxisDivs.find('.tickLabel');
  53. childDivs.each(function (i, e) {
  54. actualTicks.push({
  55. xPos: e.x.baseVal[0].value,
  56. tickName: e.textContent,
  57. });
  58. });
  59. return actualTicks
  60. .sort(function (a, b) { return a.xPos - b.xPos })
  61. .map(function (a) { return a.tickName });
  62. };
  63. var placeholder;
  64. beforeEach(function () {
  65. placeholder = setFixtures('<div id="test-container" style="width: 800px;height: 400px">')
  66. .find('#test-container');
  67. });
  68. it('first tick should be max, last tick should be min for linear axis (positive data)', function () {
  69. const data = [
  70. [0, 0],
  71. [1, 1],
  72. [2, 2],
  73. [3, 3]
  74. ];
  75. var plot = $.plot(placeholder, [data], {
  76. xaxis: {
  77. mode: 'linear',
  78. inverted: true,
  79. autoScale: 'exact'
  80. },
  81. yaxis: {
  82. mode: 'linear',
  83. inverted: true,
  84. autoScale: 'exact'
  85. }
  86. });
  87. const yTicks = queryPlotForYTicks();
  88. expect(yTicks[0]).toBe('3.0');
  89. expect(yTicks[yTicks.length - 1]).toBe('0.0');
  90. const xTicks = queryPlotForXTicks();
  91. expect(xTicks[0]).toBe('3.0');
  92. expect(xTicks[xTicks.length - 1]).toBe('0.0');
  93. });
  94. it('first tick should be max, last tick should be min for linear axis (negative data)', function () {
  95. const data = [
  96. [-0, -0],
  97. [-1, -1],
  98. [-2, -2],
  99. [-3, -3]
  100. ];
  101. var plot = $.plot(placeholder, [data], {
  102. xaxis: {
  103. mode: 'linear',
  104. inverted: true,
  105. autoScale: 'exact'
  106. },
  107. yaxis: {
  108. mode: 'linear',
  109. inverted: true,
  110. autoScale: 'exact'
  111. }
  112. });
  113. const yTicks = queryPlotForYTicks();
  114. expect(yTicks[0]).toBe('0.0');
  115. expect(yTicks[yTicks.length - 1]).toBe('-3.0');
  116. const xTicks = queryPlotForXTicks();
  117. expect(xTicks[0]).toBe('0.0');
  118. expect(xTicks[xTicks.length - 1]).toBe('-3.0');
  119. });
  120. it('first tick should be max, last tick should be min for log axis', function () {
  121. const data = [
  122. [0.1, 100],
  123. [1, 10],
  124. [10, 1],
  125. [100, 0.1]
  126. ];
  127. var plot = $.plot(placeholder, [data], {
  128. xaxis: {
  129. mode: 'log',
  130. inverted: true,
  131. autoScale: 'exact'
  132. },
  133. yaxis: {
  134. mode: 'log',
  135. inverted: true,
  136. autoScale: 'exact'
  137. }
  138. });
  139. const yTicks = queryPlotForYTicks();
  140. expect(yTicks[0]).toBe('100');
  141. expect(yTicks[yTicks.length - 1]).toBe('0.1');
  142. const xTicks = queryPlotForXTicks();
  143. expect(xTicks[0]).toBe('100');
  144. expect(xTicks[xTicks.length - 1]).toBe('0.1');
  145. });
  146. });