Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Decrease filter step size for small domains (#958)
Isaac Brodskyf35c4038a110
diff --git a/src/utils/filter-utils.js b/src/utils/filter-utils.jsindex 75a3461a5..0cfde72bd 100644--- a/src/utils/filter-utils.js+++ b/src/utils/filter-utils.js@@ -684,13 +684,23 @@ export function getNumericFieldDomain(data, valueAccessor) {return {domain, step, histogram, enlargedHistogram};}-function getNumericStepSize(diff) {+export function getNumericStepSize(diff) {+ diff = Math.abs(diff);+if (diff > 100) {return 1;- } else if (diff < 20 && diff > 3) {+ } else if (diff > 3) {return 0.01;- } else if (diff <= 3) {+ } else if (diff > 1) {return 0.001;+ } else if (diff <= 1) {+ // Try to get at least 1000 steps - and keep the step size below that of+ // the (diff > 1) case.+ const x = diff / 1000;+ // Find the exponent and truncate to 10 to the power of that exponent.+ const exponentialForm = x.toExponential();+ const exponent = parseFloat(exponentialForm.split('e')[1]);+ return Math.pow(10, exponent);}}diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.jsindex 19bf74928..0683d62e6 100644--- a/test/fixtures/state-saved-v0.js+++ b/test/fixtures/state-saved-v0.js@@ -994,7 +994,7 @@ export const mergedFilters = [enlargedHistogram: ['not tested'],domain: [94107, 94132],value: [94115.3, 94132],- step: 0.1,+ step: 0.01,speed: 1,fieldType: 'integer',typeOptions: ['range'],diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.jsindex 9d333e7a5..e0f46c95c 100644--- a/test/fixtures/state-saved-v1-1.js+++ b/test/fixtures/state-saved-v1-1.js@@ -842,9 +842,9 @@ export const mergedFilters = [name: ['zip_area'],type: 'range',fieldIdx: [3],- domain: [0, 48.1],- value: [0, 21.8],- step: 0.1,+ domain: [0.03, 48.09],+ value: [0.03, 21.8],+ step: 0.01,plotType: 'histogram',yAxis: null,interval: null,diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.jsindex 1eeee3dfe..66c8f8d93 100644--- a/test/fixtures/test-csv-data.js+++ b/test/fixtures/test-csv-data.js@@ -1390,3 +1390,10 @@ export const updatedLayerV2 = {}};/* eslint-enable max-lens */++export const numericRangesCsv = `smallest,small,negative,medium,large+0.00000,0,-10,10,0+0.00001,1,-20,20,200+0.00005,1.5,-30,30,400+0.00099,2,-40,40,800+`;diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.jsindex 63231c266..230336f32 100644--- a/test/fixtures/test-hex-id-data.js+++ b/test/fixtures/test-hex-id-data.js@@ -162,7 +162,7 @@ export const mergedFilters = [isAnimating: false,fieldIdx: [1],domain: [1, 76],- step: 0.1,+ step: 0.01,interval: null,histogram: ['Not tested'],enlargedHistogram: ['Not tested'],@@ -193,7 +193,7 @@ const mergedFields = [analyzerType: 'INT',filterProps: {domain: [1, 76],- step: 0.1,+ step: 0.01,histogram: [{count: 4, x0: 1, x1: 2},{count: 2, x0: 2, x1: 4},diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.jsindex 29bb19ba1..ba6183107 100644--- a/test/node/reducers/vis-state-test.js+++ b/test/node/reducers/vis-state-test.js@@ -1383,15 +1383,15 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {];const expectedFilterProps = {- domain: [12.25, 12.29],- step: 0.001,+ domain: [12.249990000000002,12.290000000000001],+ step: 0.00001,histogram: [1], // test not emptyenlargedHistogram: [2], // test not emptyfieldType: 'real',type: mockFilter.type,gpu: true,typeOptions: ['range'],- value: [12.25, 12.29]+ value: [12.249990000000002,12.290000000000001]};const expectedFilter = {diff --git a/test/node/utils/filter-utils-test.js b/test/node/utils/filter-utils-test.jsindex d2372950c..04a2dc0e1 100644--- a/test/node/utils/filter-utils-test.js+++ b/test/node/utils/filter-utils-test.js@@ -20,7 +20,10 @@import test from 'tape';import moment from 'moment';-import testData, {testFields} from 'test/fixtures/test-csv-data';+import testData, {+ numericRangesCsv,+ testFields+} from 'test/fixtures/test-csv-data';import {adjustValueToFilterDomain,@@ -36,8 +39,10 @@ import {diffFilters} from 'utils/filter-utils';+import {preciseRound} from 'utils/data-utils';import {getDatasetFieldIndexForFilter} from 'utils/gpu-filter-utils';+import {FILTER_TYPES} from 'constants/default-settings';import {processCsvData} from 'processors/data-processor';import {mockPolygonFeature, mockPolygonData} from '../../fixtures/polygon';@@ -93,6 +98,44 @@ function testGetTimeFieldDomain(rows, allFields, t) {);}+function testGetNumericFieldStep(rows, allFields, t) {+ const test_cases = [+ {+ name: 'smallest',+ input: getFieldDomain(rows, allFields[0]).step,+ output: 0.0000001+ },+ {+ name: 'small',+ input: getFieldDomain(rows, allFields[1]).step,+ output: 0.001+ },+ {+ name: 'negative',+ input: getFieldDomain(rows, allFields[2]).step,+ output: 0.01+ },+ {+ name: 'medium',+ input: getFieldDomain(rows, allFields[3]).step,+ output: 0.01+ },+ {+ name: 'large',+ input: getFieldDomain(rows, allFields[4]).step,+ output: 1+ },+ ];++ test_cases.forEach(tc =>+ t.equal(+ preciseRound(tc.input, 5),+ preciseRound(tc.output, 5),+ `should process correct step for field ${tc.name}`+ )+ );+}+function testGetFilterFunction(rows, fields, t) {const dataId = 'dataset-1';const timeStringFilter = {@@ -288,6 +331,16 @@ test('filterUtils -> getFieldDomain.time', async t => {t.end();});+test('filterUtils -> getFieldDomain.numeric', async t => {+ const data = numericRangesCsv;++ const {fields, rows} = await processCsvData(data);++ testGetNumericFieldStep(rows, fields, t);++ t.end();+});+test('filterUtils -> getTimestampFieldDomain', t => {/* eslint-disable func-style */const valueAccessor = d => moment.utc(d).valueOf();