From 78bd3d8c10ac90f8af62ff5a04605f0e4732097a Mon Sep 17 00:00:00 2001 From: 1chandu Date: Tue, 3 Dec 2019 09:39:15 -0800 Subject: [PATCH] Rename sortedBins to aggregatedBins --- .../aggregation-layers/src/utils/bin-sorter.js | 18 ++++++++++-------- .../cpu-grid-layer/cpu-grid-layer.spec.js | 10 +++++----- .../aggregation-layers/hexagon-layer.spec.js | 10 +++++----- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/modules/aggregation-layers/src/utils/bin-sorter.js b/modules/aggregation-layers/src/utils/bin-sorter.js index 05d2a1aa5f9..75b0adce2a4 100644 --- a/modules/aggregation-layers/src/utils/bin-sorter.js +++ b/modules/aggregation-layers/src/utils/bin-sorter.js @@ -27,18 +27,20 @@ const MAX_32_BIT_FLOAT = 3.402823466e38; export default class BinSorter { constructor(bins = [], getValue = defaultGetValue, sort = true) { - this.sortedBins = this.getSortedBins(bins, getValue, sort); + this.aggregatedBins = this.getAggregatedBins(bins, getValue, sort); this._updateMinMaxValues(); this.binMap = this.getBinMap(); } /** - * Get an array of object with sorted values and index of bins + * Get an array of object with aggregated values and index of bins + * Array object will be sorted by value optionally. * @param {Array} bins * @param {Function} getValue + * @param {Bool} sort * @return {Array} array of values and index lookup */ - getSortedBins(bins, getValue, sort) { + getAggregatedBins(bins, getValue, sort) { const aggregatedBins = bins.reduce((accu, h, i) => { const value = getValue(h.points); @@ -67,23 +69,23 @@ export default class BinSorter { * @return {Array} array of new value range */ getValueRange([lower, upper]) { - const len = this.sortedBins.length; + const len = this.aggregatedBins.length; if (!len) { return [0, 0]; } const lowerIdx = Math.ceil((lower / 100) * (len - 1)); const upperIdx = Math.floor((upper / 100) * (len - 1)); - return [this.sortedBins[lowerIdx].value, this.sortedBins[upperIdx].value]; + return [this.aggregatedBins[lowerIdx].value, this.aggregatedBins[upperIdx].value]; } /** * Get a mapping from cell/hexagon index to sorted bin * This is used to retrieve bin value for color calculation - * @return {Object} bin index to sortedBins + * @return {Object} bin index to aggregatedBins */ getBinMap() { - return this.sortedBins.reduce( + return this.aggregatedBins.reduce( (mapper, curr) => Object.assign(mapper, { [curr.i]: curr @@ -103,7 +105,7 @@ export default class BinSorter { let maxValue = 0; let minValue = MAX_32_BIT_FLOAT; let totalCount = 0; - for (const x of this.sortedBins) { + for (const x of this.aggregatedBins) { maxCount = maxCount > x.counts ? maxCount : x.counts; maxValue = maxValue > x.value ? maxValue : x.value; minValue = minValue < x.value ? minValue : x.value; diff --git a/test/modules/aggregation-layers/cpu-grid-layer/cpu-grid-layer.spec.js b/test/modules/aggregation-layers/cpu-grid-layer/cpu-grid-layer.spec.js index 6da9192ab5b..add426288ca 100644 --- a/test/modules/aggregation-layers/cpu-grid-layer/cpu-grid-layer.spec.js +++ b/test/modules/aggregation-layers/cpu-grid-layer/cpu-grid-layer.spec.js @@ -340,12 +340,12 @@ test('CPUGridLayer#updates', t => { ); t.ok( - Array.isArray(fillColor.sortedBins.sortedBins), - 'aggregatorState.dimension.fillColor.sortedBins.sortedBins calculated' + Array.isArray(fillColor.sortedBins.aggregatedBins), + 'aggregatorState.dimension.fillColor.sortedBins.aggregatedBins calculated' ); t.ok( - Array.isArray(elevation.sortedBins.sortedBins), - 'aggregatorState.dimension.elevation.sortedBins.sortedBins calculated' + Array.isArray(elevation.sortedBins.aggregatedBins), + 'aggregatorState.dimension.elevation.sortedBins.aggregatedBins calculated' ); t.ok( Number.isFinite(fillColor.sortedBins.maxCount), @@ -356,7 +356,7 @@ test('CPUGridLayer#updates', t => { 'aggregatorState.dimension.elevation.sortedBins.maxCount calculated' ); - const firstSortedBin = fillColor.sortedBins.sortedBins[0]; + const firstSortedBin = fillColor.sortedBins.aggregatedBins[0]; const binTocell = layerData.data.find(d => d.index === firstSortedBin.i); t.ok( diff --git a/test/modules/aggregation-layers/hexagon-layer.spec.js b/test/modules/aggregation-layers/hexagon-layer.spec.js index 1c0479d11a8..e417ed99e2b 100644 --- a/test/modules/aggregation-layers/hexagon-layer.spec.js +++ b/test/modules/aggregation-layers/hexagon-layer.spec.js @@ -263,12 +263,12 @@ test('HexagonLayer#updateLayer', t => { ); t.ok( - Array.isArray(fillColor.sortedBins.sortedBins), - 'aggregatorState.dimension.fillColor.sortedBins.sortedBins calculated' + Array.isArray(fillColor.sortedBins.aggregatedBins), + 'aggregatorState.dimension.fillColor.sortedBins.aggregatedBins calculated' ); t.ok( - Array.isArray(elevation.sortedBins.sortedBins), - 'aggregatorState.dimension.elevation.sortedBins.sortedBins calculated' + Array.isArray(elevation.sortedBins.aggregatedBins), + 'aggregatorState.dimension.elevation.sortedBins.aggregatedBins calculated' ); t.ok( Number.isFinite(fillColor.sortedBins.maxCount), @@ -279,7 +279,7 @@ test('HexagonLayer#updateLayer', t => { 'aggregatorState.dimension.elevation.sortedBins.maxCount calculated' ); - const firstSortedBin = fillColor.sortedBins.sortedBins[0]; + const firstSortedBin = fillColor.sortedBins.aggregatedBins[0]; const binTocell = layerData.data.find(d => d.index === firstSortedBin.i); t.ok(