Skip to content

Commit

Permalink
Merge pull request #126 from sharmalab/chart-sort-order
Browse files Browse the repository at this point in the history
use intl collator sort for bar charts
  • Loading branch information
birm authored Oct 16, 2024
2 parents b4663af + cbd96e7 commit 68f363c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion source/components/VisualTools/Chart/BarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ const transform = (data, field, isList = false) => {
if (isList) {
return transformList(data, field);
}
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
function collSort(a, b) {
return collator.compare(a, b);
}
return d3.nest().key((d) => d[field])
.sortKeys(d3.ascending)
.sortKeys(collSort)
.rollup((v) => v.length)
.entries(data);
};
Expand Down
6 changes: 5 additions & 1 deletion source/components/VisualTools/Chart/HorizontalBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ const transform = (data, field, isList = false) => {
if (isList) {
return transformList(data, field);
}
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
function collSort(a, b) {
return collator.compare(a, b);
}
return d3
.nest()
.key((d) => d[field])
.sortKeys(d3.ascending)
.sortKeys(collSort)
.rollup((v) => v.length)
.entries(data);
};
Expand Down

0 comments on commit 68f363c

Please sign in to comment.