ticks.test.ts 983 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as ticks from '../utils/ticks';
  2. describe('ticks', () => {
  3. describe('getFlotTickDecimals()', () => {
  4. const ctx: any = {};
  5. beforeEach(() => {
  6. ctx.axis = {};
  7. });
  8. it('should calculate decimals precision based on graph height', () => {
  9. let dec = ticks.getFlotTickDecimals(0, 10, ctx.axis, 200);
  10. expect(dec.tickDecimals).toBe(1);
  11. expect(dec.scaledDecimals).toBe(1);
  12. dec = ticks.getFlotTickDecimals(0, 100, ctx.axis, 200);
  13. expect(dec.tickDecimals).toBe(0);
  14. expect(dec.scaledDecimals).toBe(-1);
  15. dec = ticks.getFlotTickDecimals(0, 1, ctx.axis, 200);
  16. expect(dec.tickDecimals).toBe(2);
  17. expect(dec.scaledDecimals).toBe(3);
  18. });
  19. });
  20. describe('getStringPrecision()', () => {
  21. it('"3.12" should return 2', () => {
  22. expect(ticks.getStringPrecision('3.12')).toBe(2);
  23. });
  24. it('"asd" should return 0', () => {
  25. expect(ticks.getStringPrecision('asd.asd')).toBe(0);
  26. });
  27. });
  28. });