align_yaxes.test.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { alignYLevel } from '../align_yaxes';
  2. describe('Graph Y axes aligner', () => {
  3. let yaxes, expected;
  4. let alignY = 0;
  5. describe('on the one hand with respect to zero', () => {
  6. it('Should shrink Y axis', () => {
  7. yaxes = [{ min: 5, max: 10 }, { min: 2, max: 3 }];
  8. expected = [{ min: 5, max: 10 }, { min: 1.5, max: 3 }];
  9. alignYLevel(yaxes, alignY);
  10. expect(yaxes).toMatchObject(expected);
  11. });
  12. it('Should shrink Y axis', () => {
  13. yaxes = [{ min: 2, max: 3 }, { min: 5, max: 10 }];
  14. expected = [{ min: 1.5, max: 3 }, { min: 5, max: 10 }];
  15. alignYLevel(yaxes, alignY);
  16. expect(yaxes).toMatchObject(expected);
  17. });
  18. it('Should shrink Y axis', () => {
  19. yaxes = [{ min: -10, max: -5 }, { min: -3, max: -2 }];
  20. expected = [{ min: -10, max: -5 }, { min: -3, max: -1.5 }];
  21. alignYLevel(yaxes, alignY);
  22. expect(yaxes).toMatchObject(expected);
  23. });
  24. it('Should shrink Y axis', () => {
  25. yaxes = [{ min: -3, max: -2 }, { min: -10, max: -5 }];
  26. expected = [{ min: -3, max: -1.5 }, { min: -10, max: -5 }];
  27. alignYLevel(yaxes, alignY);
  28. expect(yaxes).toMatchObject(expected);
  29. });
  30. });
  31. describe('on the opposite sides with respect to zero', () => {
  32. it('Should shrink Y axes', () => {
  33. yaxes = [{ min: -3, max: -1 }, { min: 5, max: 10 }];
  34. expected = [{ min: -3, max: 3 }, { min: -10, max: 10 }];
  35. alignYLevel(yaxes, alignY);
  36. expect(yaxes).toMatchObject(expected);
  37. });
  38. it('Should shrink Y axes', () => {
  39. yaxes = [{ min: 1, max: 3 }, { min: -10, max: -5 }];
  40. expected = [{ min: -3, max: 3 }, { min: -10, max: 10 }];
  41. alignYLevel(yaxes, alignY);
  42. expect(yaxes).toMatchObject(expected);
  43. });
  44. });
  45. describe('both across zero', () => {
  46. it('Should shrink Y axes', () => {
  47. yaxes = [{ min: -10, max: 5 }, { min: -2, max: 3 }];
  48. expected = [{ min: -10, max: 15 }, { min: -2, max: 3 }];
  49. alignYLevel(yaxes, alignY);
  50. expect(yaxes).toMatchObject(expected);
  51. });
  52. it('Should shrink Y axes', () => {
  53. yaxes = [{ min: -5, max: 10 }, { min: -3, max: 2 }];
  54. expected = [{ min: -15, max: 10 }, { min: -3, max: 2 }];
  55. alignYLevel(yaxes, alignY);
  56. expect(yaxes).toMatchObject(expected);
  57. });
  58. });
  59. describe('one of graphs on zero', () => {
  60. it('Should shrink Y axes', () => {
  61. yaxes = [{ min: 0, max: 3 }, { min: 5, max: 10 }];
  62. expected = [{ min: 0, max: 3 }, { min: 0, max: 10 }];
  63. alignYLevel(yaxes, alignY);
  64. expect(yaxes).toMatchObject(expected);
  65. });
  66. it('Should shrink Y axes', () => {
  67. yaxes = [{ min: 5, max: 10 }, { min: 0, max: 3 }];
  68. expected = [{ min: 0, max: 10 }, { min: 0, max: 3 }];
  69. alignYLevel(yaxes, alignY);
  70. expect(yaxes).toMatchObject(expected);
  71. });
  72. it('Should shrink Y axes', () => {
  73. yaxes = [{ min: -3, max: 0 }, { min: -10, max: -5 }];
  74. expected = [{ min: -3, max: 0 }, { min: -10, max: 0 }];
  75. alignYLevel(yaxes, alignY);
  76. expect(yaxes).toMatchObject(expected);
  77. });
  78. it('Should shrink Y axes', () => {
  79. yaxes = [{ min: -10, max: -5 }, { min: -3, max: 0 }];
  80. expected = [{ min: -10, max: 0 }, { min: -3, max: 0 }];
  81. alignYLevel(yaxes, alignY);
  82. expect(yaxes).toMatchObject(expected);
  83. });
  84. });
  85. describe('both graphs on zero', () => {
  86. it('Should shrink Y axes', () => {
  87. yaxes = [{ min: 0, max: 3 }, { min: -10, max: 0 }];
  88. expected = [{ min: -3, max: 3 }, { min: -10, max: 10 }];
  89. alignYLevel(yaxes, alignY);
  90. expect(yaxes).toMatchObject(expected);
  91. });
  92. it('Should shrink Y axes', () => {
  93. yaxes = [{ min: -3, max: 0 }, { min: 0, max: 10 }];
  94. expected = [{ min: -3, max: 3 }, { min: -10, max: 10 }];
  95. alignYLevel(yaxes, alignY);
  96. expect(yaxes).toMatchObject(expected);
  97. });
  98. });
  99. describe('mixed placement of graphs relative to zero', () => {
  100. it('Should shrink Y axes', () => {
  101. yaxes = [{ min: -10, max: 5 }, { min: 1, max: 3 }];
  102. expected = [{ min: -10, max: 5 }, { min: -6, max: 3 }];
  103. alignYLevel(yaxes, alignY);
  104. expect(yaxes).toMatchObject(expected);
  105. });
  106. it('Should shrink Y axes', () => {
  107. yaxes = [{ min: 1, max: 3 }, { min: -10, max: 5 }];
  108. expected = [{ min: -6, max: 3 }, { min: -10, max: 5 }];
  109. alignYLevel(yaxes, alignY);
  110. expect(yaxes).toMatchObject(expected);
  111. });
  112. it('Should shrink Y axes', () => {
  113. yaxes = [{ min: -10, max: 5 }, { min: -3, max: -1 }];
  114. expected = [{ min: -10, max: 5 }, { min: -3, max: 1.5 }];
  115. alignYLevel(yaxes, alignY);
  116. expect(yaxes).toMatchObject(expected);
  117. });
  118. it('Should shrink Y axes', () => {
  119. yaxes = [{ min: -3, max: -1 }, { min: -10, max: 5 }];
  120. expected = [{ min: -3, max: 1.5 }, { min: -10, max: 5 }];
  121. alignYLevel(yaxes, alignY);
  122. expect(yaxes).toMatchObject(expected);
  123. });
  124. });
  125. describe('on level not zero', () => {
  126. it('Should shrink Y axis', () => {
  127. alignY = 1;
  128. yaxes = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
  129. expected = [{ min: 4, max: 10 }, { min: 2, max: 4 }];
  130. alignYLevel(yaxes, alignY);
  131. expect(yaxes).toMatchObject(expected);
  132. });
  133. it('Should shrink Y axes', () => {
  134. alignY = 2;
  135. yaxes = [{ min: -3, max: 1 }, { min: 5, max: 10 }];
  136. expected = [{ min: -3, max: 7 }, { min: -6, max: 10 }];
  137. alignYLevel(yaxes, alignY);
  138. expect(yaxes).toMatchObject(expected);
  139. });
  140. it('Should shrink Y axes', () => {
  141. alignY = -1;
  142. yaxes = [{ min: -5, max: 5 }, { min: -2, max: 3 }];
  143. expected = [{ min: -5, max: 15 }, { min: -2, max: 3 }];
  144. alignYLevel(yaxes, alignY);
  145. expect(yaxes).toMatchObject(expected);
  146. });
  147. it('Should shrink Y axes', () => {
  148. alignY = -2;
  149. yaxes = [{ min: -2, max: 3 }, { min: 5, max: 10 }];
  150. expected = [{ min: -2, max: 3 }, { min: -2, max: 10 }];
  151. alignYLevel(yaxes, alignY);
  152. expect(yaxes).toMatchObject(expected);
  153. });
  154. });
  155. describe('on level not number value', () => {
  156. it('Should ignore without errors', () => {
  157. yaxes = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
  158. expected = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
  159. alignYLevel(yaxes, 'q');
  160. expect(yaxes).toMatchObject(expected);
  161. });
  162. });
  163. });