Skip to content

Commit

Permalink
Rename sortedBins to aggregatedBins
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Dec 3, 2019
1 parent e33674c commit 9aa43ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 10 additions & 8 deletions modules/aggregation-layers/src/utils/bin-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions test/modules/aggregation-layers/hexagon-layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand Down

0 comments on commit 9aa43ad

Please sign in to comment.