Skip to content

Commit

Permalink
[fix] range slider doesn't work when step < 1 in dataset filter (#2240)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta committed Jun 9, 2023
1 parent fa3bb9c commit f562fbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/utils/src/data-utils.ts
Expand Up @@ -182,7 +182,17 @@ export function getRoundingDecimalFromStep(step: number): number {
assert(step);
}

const splitZero = step.toString().split('.');
const stepStr = step.toString();

// in case the step is a very small number e.g. 1e-7, return decimal e.g. 7 directly
const splitExponential = stepStr.split('e-');
if (splitExponential.length === 2) {
const coeffZero = splitExponential[0].split('.');
const coeffDecimal = coeffZero.length === 1 ? 0 : coeffZero[1].length;
return parseInt(splitExponential[1], 10) + coeffDecimal;
}

const splitZero = stepStr.split('.');
if (splitZero.length === 1) {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions test/node/utils/data-utils-test.js
Expand Up @@ -75,6 +75,8 @@ test('dataUtils -> getRoundingDecimalFromStep', t => {
t.equal(getRoundingDecimalFromStep(10), 0, 'decimal of step=10 should be 0');
t.equal(getRoundingDecimalFromStep(0.5), 1, 'decimal of step=0.5 should be 0');
t.equal(getRoundingDecimalFromStep(1.5), 1, 'decimal of step=1.5 should be 1');
t.equal(getRoundingDecimalFromStep(0.0000001), 7, 'decimal of step=1e-7 should be 7');
t.equal(getRoundingDecimalFromStep(0.0000000000123), 13, 'decimal of step=1.23e-11 should be 13');
t.end();
});

Expand Down

0 comments on commit f562fbe

Please sign in to comment.