@@ -22,6 +22,7 @@ import { costAsPercentOfGdp } from "@/components/utils/formatters";
2222import { CostBasis } from " @/types/unitTypes" ;
2323import { debounce } from " perfect-debounce" ;
2424import { diffAgainstBaseline } from " ~/components/utils/comparisons" ;
25+ import useSortedScenarios from " ~/composables/useSortedScenarios" ;
2526
2627const props = defineProps <{
2728 diffing: boolean
@@ -32,11 +33,12 @@ let chart: Highcharts.Chart;
3233const seriesSummary = ref <Highcharts .SeriesColumnOptions []>([]); // This only exists for testing purposes
3334const chartContainer = ref <HTMLElement | null >(null );
3435const chartParentEl = computed (() => chartContainer .value ?.parentElement );
35- const scenarios = computed (() => {
36- return props .diffing
37- ? appStore .currentComparison .scenarios .filter (s => s .runId !== appStore .baselineScenario ?.runId )
38- : appStore .currentComparison .scenarios ;
39- });
36+
37+ const scenarios = computed (() => props .diffing
38+ ? appStore .currentComparison .scenarios .filter (s => s .runId !== appStore .baselineScenario ?.runId )
39+ : appStore .currentComparison .scenarios );
40+ const { sortedScenarios } = useSortedScenarios (scenarios );
41+
4042const costBasis = computed (() => appStore .preferences .costBasis );
4143const chartTitle = computed (() => {
4244 const firstScenarioTimeSeries = appStore .currentComparison .scenarios [0 ].result ?.data ?.time_series ;
@@ -54,15 +56,15 @@ const chartTitle = computed(() => {
5456// For example, one series should comprise each scenario's GDP.
5557const getSeries = (): Highcharts .SeriesColumnOptions [] => {
5658 // Take the first scenario's costs as an example to find out what the second-level breakdowns are.
57- const secondLevelCostIds = scenarios .value [0 ].result .data ?.costs [0 ].children ?.map (c => c .id ) || [];
59+ const secondLevelCostIds = sortedScenarios .value [0 ].result .data ?.costs [0 ].children ?.map (c => c .id ) || [];
5860 const allSeries = secondLevelCostIds ?.map ((costId , index ) => {
5961 return {
6062 type: " column" as Highcharts .SeriesColumnOptions [" type" ],
6163 name: appStore .getCostLabel (costId ),
6264 borderWidth: 1 ,
6365 borderColor: costsChartPalette [index ].rgb ,
6466 zIndex: secondLevelCostIds .length - index , // Ensure that stack segments are in front of each other from top to bottom.
65- data: scenarios .value .map ((scenario ) => {
67+ data: sortedScenarios .value .map ((scenario ) => {
6668 const subCost = appStore .getScenarioCostById (scenario , costId )! ;
6769 const yUSD = props .diffing ? diffAgainstBaseline (subCost , USD_METRIC ) : getValueFromCost (subCost , USD_METRIC );
6870 // yGdpPercent is calculated here since the national GDP may vary by scenario if the axis is 'country'.
@@ -136,7 +138,7 @@ const chartInitialOptions = () => {
136138 },
137139 },
138140 xAxis: {
139- categories: scenarios .value .map (s => appStore .getScenarioAxisValue (s )),
141+ categories: sortedScenarios .value .map (s => appStore .getScenarioAxisValue (s )),
140142 title: { text: appStore .axisMetadata ?.label },
141143 labels: {
142144 style: {
@@ -211,7 +213,7 @@ watch(() => props.diffing, () => {
211213 },
212214 title: { text: chartTitle .value },
213215 xAxis: {
214- categories: scenarios .value .map (s => appStore .getScenarioAxisValue (s ) || " " ),
216+ categories: sortedScenarios .value .map (s => appStore .getScenarioAxisValue (s ) || " " ),
215217 },
216218 yAxis: {
217219 min: props .diffing ? undefined : 0 ,
0 commit comments