Skip to content

Commit

Permalink
correctly sort all values
Browse files Browse the repository at this point in the history
  • Loading branch information
heshan0131 committed Apr 25, 2020
1 parent 0bacf5c commit ad6b0cb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/aggregation-layers/src/utils/bin-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const defaultGetPoints = bin => bin.points;
// access index of each bin
const defaultGetIndex = bin => bin.index;

// d3-scending
const ascending = (a, b) => (a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN);

const defaultProps = {
getValue: defaultGetValue,
getPoints: defaultGetPoints,
Expand Down Expand Up @@ -150,7 +153,7 @@ export default class BinSorter {
*/
getValueRange(percentileRange) {
if (!this.sortedBins) {
this.sortedBins = this.aggregatedBins.sort((a, b) => a.value - b.value);
this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
}
if (!this.sortedBins.length) {
return [];
Expand All @@ -169,7 +172,7 @@ export default class BinSorter {

getValueDomainByScale(scale, [lower = 0, upper = 100] = []) {
if (!this.sortedBins) {
this.sortedBins = this.aggregatedBins.sort((a, b) => a.value - b.value);
this.sortedBins = this.aggregatedBins.sort((a, b) => ascending(a.value, b.value));
}
if (!this.sortedBins.length) {
return [];
Expand Down

0 comments on commit ad6b0cb

Please sign in to comment.