Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[fix] range slider doesn't work when step < 1 in dataset filter (#2240)
Igor Df562fbe00a38
diff --git a/src/utils/src/data-utils.ts b/src/utils/src/data-utils.tsindex 4a29c30b9..7d3e7db51 100644--- a/src/utils/src/data-utils.ts+++ b/src/utils/src/data-utils.ts@@ -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;}diff --git a/test/node/utils/data-utils-test.js b/test/node/utils/data-utils-test.jsindex 10dddbe67..776630808 100644--- a/test/node/utils/data-utils-test.js+++ b/test/node/utils/data-utils-test.js@@ -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();});