Skip to content

Commit

Permalink
Merge pull request #5434 from dfe-analytical-services/master
Browse files Browse the repository at this point in the history
Merge master into dev
  • Loading branch information
tomjonesdev authored Dec 6, 2024
2 parents 40fd56e + 7f4a0c3 commit cbf6304
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -592,12 +594,20 @@ const ChartAxisConfiguration = ({
name="visible"
label="Show axis"
conditional={
<FormFieldTextInput<ChartAxisConfigurationFormValues>
label="Displayed unit"
name="unit"
hint="Leave blank to set default from metadata"
width={10}
/>
<>
<FormFieldTextInput<ChartAxisConfigurationFormValues>
label="Displayed unit"
name="unit"
hint="Leave blank to set default from metadata"
width={10}
/>
<FormFieldNumberInput<ChartAxisConfigurationFormValues>
label="Displayed decimal places"
name="decimalPlaces"
hint="Leave blank to set default from metadata"
width={10}
/>
</>
}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('ChartAxisConfiguration', () => {
tickSpacing: 1,
type: 'minor',
unit: '',
decimalPlaces: undefined,
visible: true,
label: { text: '', width: 100, rotated: false },
max: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface AxisConfiguration {
referenceLines: ReferenceLine[];
visible?: boolean;
unit?: string;
decimalPlaces?: number;
showGrid?: boolean;
label?: Label;
size?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | undefined>((acc, { dataSet }) => {
if (typeof dataSet.indicator.decimalPlaces === 'undefined') {
return acc;
Expand Down

0 comments on commit cbf6304

Please sign in to comment.