align_yaxes.test.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 = [
  8. { min: 5, max: 10 },
  9. { min: 2, max: 3 },
  10. ];
  11. expected = [
  12. { min: 5, max: 10 },
  13. { min: 1.5, max: 3 },
  14. ];
  15. alignYLevel(yaxes, alignY);
  16. expect(yaxes).toMatchObject(expected);
  17. });
  18. it('Should shrink Y axis', () => {
  19. yaxes = [
  20. { min: 2, max: 3 },
  21. { min: 5, max: 10 },
  22. ];
  23. expected = [
  24. { min: 1.5, max: 3 },
  25. { min: 5, max: 10 },
  26. ];
  27. alignYLevel(yaxes, alignY);
  28. expect(yaxes).toMatchObject(expected);
  29. });
  30. it('Should shrink Y axis', () => {
  31. yaxes = [
  32. { min: -10, max: -5 },
  33. { min: -3, max: -2 },
  34. ];
  35. expected = [
  36. { min: -10, max: -5 },
  37. { min: -3, max: -1.5 },
  38. ];
  39. alignYLevel(yaxes, alignY);
  40. expect(yaxes).toMatchObject(expected);
  41. });
  42. it('Should shrink Y axis', () => {
  43. yaxes = [
  44. { min: -3, max: -2 },
  45. { min: -10, max: -5 },
  46. ];
  47. expected = [
  48. { min: -3, max: -1.5 },
  49. { min: -10, max: -5 },
  50. ];
  51. alignYLevel(yaxes, alignY);
  52. expect(yaxes).toMatchObject(expected);
  53. });
  54. });
  55. describe('on the opposite sides with respect to zero', () => {
  56. it('Should shrink Y axes', () => {
  57. yaxes = [
  58. { min: -3, max: -1 },
  59. { min: 5, max: 10 },
  60. ];
  61. expected = [
  62. { min: -3, max: 3 },
  63. { min: -10, max: 10 },
  64. ];
  65. alignYLevel(yaxes, alignY);
  66. expect(yaxes).toMatchObject(expected);
  67. });
  68. it('Should shrink Y axes', () => {
  69. yaxes = [
  70. { min: 1, max: 3 },
  71. { min: -10, max: -5 },
  72. ];
  73. expected = [
  74. { min: -3, max: 3 },
  75. { min: -10, max: 10 },
  76. ];
  77. alignYLevel(yaxes, alignY);
  78. expect(yaxes).toMatchObject(expected);
  79. });
  80. });
  81. describe('both across zero', () => {
  82. it('Should shrink Y axes', () => {
  83. yaxes = [
  84. { min: -10, max: 5 },
  85. { min: -2, max: 3 },
  86. ];
  87. expected = [
  88. { min: -10, max: 15 },
  89. { min: -2, max: 3 },
  90. ];
  91. alignYLevel(yaxes, alignY);
  92. expect(yaxes).toMatchObject(expected);
  93. });
  94. it('Should shrink Y axes', () => {
  95. yaxes = [
  96. { min: -5, max: 10 },
  97. { min: -3, max: 2 },
  98. ];
  99. expected = [
  100. { min: -15, max: 10 },
  101. { min: -3, max: 2 },
  102. ];
  103. alignYLevel(yaxes, alignY);
  104. expect(yaxes).toMatchObject(expected);
  105. });
  106. });
  107. describe('one of graphs on zero', () => {
  108. it('Should shrink Y axes', () => {
  109. yaxes = [
  110. { min: 0, max: 3 },
  111. { min: 5, max: 10 },
  112. ];
  113. expected = [
  114. { min: 0, max: 3 },
  115. { min: 0, max: 10 },
  116. ];
  117. alignYLevel(yaxes, alignY);
  118. expect(yaxes).toMatchObject(expected);
  119. });
  120. it('Should shrink Y axes', () => {
  121. yaxes = [
  122. { min: 5, max: 10 },
  123. { min: 0, max: 3 },
  124. ];
  125. expected = [
  126. { min: 0, max: 10 },
  127. { min: 0, max: 3 },
  128. ];
  129. alignYLevel(yaxes, alignY);
  130. expect(yaxes).toMatchObject(expected);
  131. });
  132. it('Should shrink Y axes', () => {
  133. yaxes = [
  134. { min: -3, max: 0 },
  135. { min: -10, max: -5 },
  136. ];
  137. expected = [
  138. { min: -3, max: 0 },
  139. { min: -10, max: 0 },
  140. ];
  141. alignYLevel(yaxes, alignY);
  142. expect(yaxes).toMatchObject(expected);
  143. });
  144. it('Should shrink Y axes', () => {
  145. yaxes = [
  146. { min: -10, max: -5 },
  147. { min: -3, max: 0 },
  148. ];
  149. expected = [
  150. { min: -10, max: 0 },
  151. { min: -3, max: 0 },
  152. ];
  153. alignYLevel(yaxes, alignY);
  154. expect(yaxes).toMatchObject(expected);
  155. });
  156. });
  157. describe('both graphs on zero', () => {
  158. it('Should shrink Y axes', () => {
  159. yaxes = [
  160. { min: 0, max: 3 },
  161. { min: -10, max: 0 },
  162. ];
  163. expected = [
  164. { min: -3, max: 3 },
  165. { min: -10, max: 10 },
  166. ];
  167. alignYLevel(yaxes, alignY);
  168. expect(yaxes).toMatchObject(expected);
  169. });
  170. it('Should shrink Y axes', () => {
  171. yaxes = [
  172. { min: -3, max: 0 },
  173. { min: 0, max: 10 },
  174. ];
  175. expected = [
  176. { min: -3, max: 3 },
  177. { min: -10, max: 10 },
  178. ];
  179. alignYLevel(yaxes, alignY);
  180. expect(yaxes).toMatchObject(expected);
  181. });
  182. });
  183. describe('mixed placement of graphs relative to zero', () => {
  184. it('Should shrink Y axes', () => {
  185. yaxes = [
  186. { min: -10, max: 5 },
  187. { min: 1, max: 3 },
  188. ];
  189. expected = [
  190. { min: -10, max: 5 },
  191. { min: -6, max: 3 },
  192. ];
  193. alignYLevel(yaxes, alignY);
  194. expect(yaxes).toMatchObject(expected);
  195. });
  196. it('Should shrink Y axes', () => {
  197. yaxes = [
  198. { min: 1, max: 3 },
  199. { min: -10, max: 5 },
  200. ];
  201. expected = [
  202. { min: -6, max: 3 },
  203. { min: -10, max: 5 },
  204. ];
  205. alignYLevel(yaxes, alignY);
  206. expect(yaxes).toMatchObject(expected);
  207. });
  208. it('Should shrink Y axes', () => {
  209. yaxes = [
  210. { min: -10, max: 5 },
  211. { min: -3, max: -1 },
  212. ];
  213. expected = [
  214. { min: -10, max: 5 },
  215. { min: -3, max: 1.5 },
  216. ];
  217. alignYLevel(yaxes, alignY);
  218. expect(yaxes).toMatchObject(expected);
  219. });
  220. it('Should shrink Y axes', () => {
  221. yaxes = [
  222. { min: -3, max: -1 },
  223. { min: -10, max: 5 },
  224. ];
  225. expected = [
  226. { min: -3, max: 1.5 },
  227. { min: -10, max: 5 },
  228. ];
  229. alignYLevel(yaxes, alignY);
  230. expect(yaxes).toMatchObject(expected);
  231. });
  232. });
  233. describe('on level not zero', () => {
  234. it('Should shrink Y axis', () => {
  235. alignY = 1;
  236. yaxes = [
  237. { min: 5, max: 10 },
  238. { min: 2, max: 4 },
  239. ];
  240. expected = [
  241. { min: 4, max: 10 },
  242. { min: 2, max: 4 },
  243. ];
  244. alignYLevel(yaxes, alignY);
  245. expect(yaxes).toMatchObject(expected);
  246. });
  247. it('Should shrink Y axes', () => {
  248. alignY = 2;
  249. yaxes = [
  250. { min: -3, max: 1 },
  251. { min: 5, max: 10 },
  252. ];
  253. expected = [
  254. { min: -3, max: 7 },
  255. { min: -6, max: 10 },
  256. ];
  257. alignYLevel(yaxes, alignY);
  258. expect(yaxes).toMatchObject(expected);
  259. });
  260. it('Should shrink Y axes', () => {
  261. alignY = -1;
  262. yaxes = [
  263. { min: -5, max: 5 },
  264. { min: -2, max: 3 },
  265. ];
  266. expected = [
  267. { min: -5, max: 15 },
  268. { min: -2, max: 3 },
  269. ];
  270. alignYLevel(yaxes, alignY);
  271. expect(yaxes).toMatchObject(expected);
  272. });
  273. it('Should shrink Y axes', () => {
  274. alignY = -2;
  275. yaxes = [
  276. { min: -2, max: 3 },
  277. { min: 5, max: 10 },
  278. ];
  279. expected = [
  280. { min: -2, max: 3 },
  281. { min: -2, max: 10 },
  282. ];
  283. alignYLevel(yaxes, alignY);
  284. expect(yaxes).toMatchObject(expected);
  285. });
  286. });
  287. describe('on level not number value', () => {
  288. it('Should ignore without errors', () => {
  289. yaxes = [
  290. { min: 5, max: 10 },
  291. { min: 2, max: 4 },
  292. ];
  293. expected = [
  294. { min: 5, max: 10 },
  295. { min: 2, max: 4 },
  296. ];
  297. alignYLevel(yaxes, 'q');
  298. expect(yaxes).toMatchObject(expected);
  299. });
  300. });
  301. });