diff --git a/src/GovUk.Education.ExploreEducationStatistics.Common/Model/Chart/ChartAxisConfiguration.cs b/src/GovUk.Education.ExploreEducationStatistics.Common/Model/Chart/ChartAxisConfiguration.cs index 8bc8266b8c5..337dec84286 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Common/Model/Chart/ChartAxisConfiguration.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Common/Model/Chart/ChartAxisConfiguration.cs @@ -28,6 +28,7 @@ public class ChartAxisConfiguration public bool Visible = true; public string Title = null!; public string Unit = null!; + public int? DecimalPlaces; public bool ShowGrid = true; public AxisLabel Label = null!; diff --git a/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/ChartAxisConfiguration.tsx b/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/ChartAxisConfiguration.tsx index c671e0d1304..23240174f83 100644 --- a/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/ChartAxisConfiguration.tsx +++ b/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/ChartAxisConfiguration.tsx @@ -278,6 +278,7 @@ const ChartAxisConfiguration = ({ min: Yup.number(), visible: Yup.boolean(), unit: Yup.string(), + decimalPlaces: Yup.string(), labelText: Yup.string(), labelWidth: Yup.number().positive('Label width must be positive'), }); @@ -464,6 +465,7 @@ const ChartAxisConfiguration = ({ labelRotated: values?.label?.rotated ?? false, labelText: values?.label?.text ?? '', labelWidth: values?.label?.width ?? undefined, + decimalPlaces: values?.decimalPlaces ?? undefined, referenceLines: values?.referenceLines.map(line => { return { @@ -592,12 +594,20 @@ const ChartAxisConfiguration = ({ name="visible" label="Show axis" conditional={ - - label="Displayed unit" - name="unit" - hint="Leave blank to set default from metadata" - width={10} - /> + <> + + label="Displayed unit" + name="unit" + hint="Leave blank to set default from metadata" + width={10} + /> + + label="Displayed decimal places" + name="decimalPlaces" + hint="Leave blank to set default from metadata" + width={10} + /> + } /> )} diff --git a/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/__tests__/ChartAxisConfiguration.test.tsx b/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/__tests__/ChartAxisConfiguration.test.tsx index 9192b3b5083..4eccfd5afb1 100644 --- a/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/__tests__/ChartAxisConfiguration.test.tsx +++ b/src/explore-education-statistics-admin/src/pages/release/datablocks/components/chart/__tests__/ChartAxisConfiguration.test.tsx @@ -100,6 +100,7 @@ describe('ChartAxisConfiguration', () => { tickSpacing: 1, type: 'minor', unit: '', + decimalPlaces: undefined, visible: true, label: { text: '', width: 100, rotated: false }, max: undefined, diff --git a/src/explore-education-statistics-common/src/modules/charts/components/HorizontalBarBlock.tsx b/src/explore-education-statistics-common/src/modules/charts/components/HorizontalBarBlock.tsx index 779b51b3204..1508d8fef76 100644 --- a/src/explore-education-statistics-common/src/modules/charts/components/HorizontalBarBlock.tsx +++ b/src/explore-education-statistics-common/src/modules/charts/components/HorizontalBarBlock.tsx @@ -103,7 +103,10 @@ const HorizontalBarBlock = ({ meta, }); - const minorAxisDecimals = getMinorAxisDecimalPlaces(dataSetCategoryConfigs); + const minorAxisDecimals = getMinorAxisDecimalPlaces( + dataSetCategoryConfigs, + axes.minor.decimalPlaces, + ); const minorAxisUnit = axes.minor.unit || getUnit(dataSetCategoryConfigs); const chartHasNegativeValues = (parseNumber(minorDomainTicks.domain?.[0]) ?? 0) < 0; diff --git a/src/explore-education-statistics-common/src/modules/charts/components/LineChartBlock.tsx b/src/explore-education-statistics-common/src/modules/charts/components/LineChartBlock.tsx index 2988a26d92f..6cce1a6c2fa 100644 --- a/src/explore-education-statistics-common/src/modules/charts/components/LineChartBlock.tsx +++ b/src/explore-education-statistics-common/src/modules/charts/components/LineChartBlock.tsx @@ -90,7 +90,10 @@ const LineChartBlock = ({ legendItems: legend.items, meta, }); - const minorAxisDecimals = getMinorAxisDecimalPlaces(dataSetCategoryConfigs); + const minorAxisDecimals = getMinorAxisDecimalPlaces( + dataSetCategoryConfigs, + axes.minor.decimalPlaces, + ); const minorAxisUnit = axes.minor.unit || getUnit(dataSetCategoryConfigs); const yAxisWidth = getMinorAxisSize({ dataSetCategories, diff --git a/src/explore-education-statistics-common/src/modules/charts/components/VerticalBarBlock.tsx b/src/explore-education-statistics-common/src/modules/charts/components/VerticalBarBlock.tsx index cd8d9d59653..658345387c3 100644 --- a/src/explore-education-statistics-common/src/modules/charts/components/VerticalBarBlock.tsx +++ b/src/explore-education-statistics-common/src/modules/charts/components/VerticalBarBlock.tsx @@ -109,7 +109,10 @@ const VerticalBarBlock = ({ legendItems: legend.items, meta, }); - const minorAxisDecimals = getMinorAxisDecimalPlaces(dataSetCategoryConfigs); + const minorAxisDecimals = getMinorAxisDecimalPlaces( + dataSetCategoryConfigs, + axes.minor.decimalPlaces, + ); const minorAxisUnit = axes.minor.unit || getUnit(dataSetCategoryConfigs); const yAxisWidth = getMinorAxisSize({ dataSetCategories, diff --git a/src/explore-education-statistics-common/src/modules/charts/types/chart.ts b/src/explore-education-statistics-common/src/modules/charts/types/chart.ts index 3e23bf25703..66771b464a6 100644 --- a/src/explore-education-statistics-common/src/modules/charts/types/chart.ts +++ b/src/explore-education-statistics-common/src/modules/charts/types/chart.ts @@ -67,6 +67,7 @@ export interface AxisConfiguration { referenceLines: ReferenceLine[]; visible?: boolean; unit?: string; + decimalPlaces?: number; showGrid?: boolean; label?: Label; size?: number; diff --git a/src/explore-education-statistics-common/src/modules/charts/util/getMinorAxisDecimalPlaces.ts b/src/explore-education-statistics-common/src/modules/charts/util/getMinorAxisDecimalPlaces.ts index 56befa4b1ba..f9c421cd849 100644 --- a/src/explore-education-statistics-common/src/modules/charts/util/getMinorAxisDecimalPlaces.ts +++ b/src/explore-education-statistics-common/src/modules/charts/util/getMinorAxisDecimalPlaces.ts @@ -16,7 +16,11 @@ import { DataSetCategoryConfig } from '@common/modules/charts/util/getDataSetCat */ export default function getMinorAxisDecimalPlaces( categoryDataSets: DataSetCategoryConfig[], + decimalPlaces?: number, ): number | undefined { + if (decimalPlaces || decimalPlaces === 0) { + return decimalPlaces; + } return categoryDataSets.reduce((acc, { dataSet }) => { if (typeof dataSet.indicator.decimalPlaces === 'undefined') { return acc;