Skip to content

Commit 847074d

Browse files
authored
Fix drilldown prevalence by month sorting and trellis chart sorting in data characterization (#3024)
* sort data for prevalence by month chart * numerically sort trellis charts * use sortedData in drilldown prevalence by month chart
1 parent 691f668 commit 847074d

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

plugins/ui/apps/portal/src/components/Charts/Common/Drilldown/DrilldownPrevalenceByMonthChart/DrilldownPrevalenceByMonthChart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ const DrilldownPrevalenceByMonthChart: FC<DrilldownPrevalenceByMonthChartProps>
2828
);
2929
}
3030

31+
// Sort data by XCALENDARMONTH
32+
const sortedData = [...data].sort((a: any, b: any) => {
33+
return Number(a["XCALENDARMONTH"]) - Number(b["XCALENDARMONTH"]);
34+
});
35+
3136
// Parse and format line chart data
3237
// Parse XCALENDARMONTH from e.g 200910 -> 10/2009
33-
const lineChartXAxisData = data.map(
38+
const lineChartXAxisData = sortedData.map(
3439
(obj: any) => obj["XCALENDARMONTH"].toString().slice(-2) + "/" + obj["XCALENDARMONTH"].toString().slice(0, 4)
3540
);
3641

3742
const series = [
3843
{
3944
type: "line",
40-
data: data.map((obj: any) => Number(obj["YPREVALENCE1000PP"]).toFixed()),
45+
data: sortedData.map((obj: any) => Number(obj["YPREVALENCE1000PP"]).toFixed()),
4146
},
4247
];
4348

plugins/ui/apps/portal/src/components/Charts/Common/Drilldown/DrilldownTrellisChart/DrilldownTrellisChart.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ const DrilldownTrellisChart: FC<DrilldownTrellisChartProps> = ({
5656
const TITLE_OFFSET = 6 / numRows; // Dynamic offset for grid titles
5757
const ROW_LABEL_OFFSET = 9 / numRows; // Dynamic offset for row labels
5858

59-
// Get keys from trellisData sorted
60-
const sortedTrellisNames = Object.keys(trellisData).sort();
59+
// Get keys from trellisData sorted naturally, so numeric ranges are ordered by value
60+
// instead of lexicographically
61+
const sortedTrellisNames = Object.keys(trellisData).sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
6162

6263
// Calculate global y-axis range for harmonization across all plots
6364
const allYValues = data.map((obj: any) => Number(obj[trellisXAxisKey])).filter((v: number) => !isNaN(v));

0 commit comments

Comments
 (0)