From d705fa69001c565ac346d5cbb01262e4d4222ac3 Mon Sep 17 00:00:00 2001 From: Tim Kuijpers <33220871+TJMKuijpers@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:56:34 +0100 Subject: [PATCH] Update function logScalePossible for generic assay negative data (#5084) * Update logScalePossible for generic assay negative data * make sure that return type is always boolean * Add test for negative and positive data of type number --- src/shared/components/plots/PlotsTabUtils.spec.ts | 15 +++++++++++++-- src/shared/components/plots/PlotsTabUtils.tsx | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/shared/components/plots/PlotsTabUtils.spec.ts b/src/shared/components/plots/PlotsTabUtils.spec.ts index 6d4255869b6..f319a46a5eb 100644 --- a/src/shared/components/plots/PlotsTabUtils.spec.ts +++ b/src/shared/components/plots/PlotsTabUtils.spec.ts @@ -767,10 +767,10 @@ describe('PlotsTabUtils', () => { }); describe('logScalePossible', () => { - it('should return true when data is type number', () => { + it('should return true when positive data is type number', () => { const axisData = ({ datatype: 'number', - data: [{ value: 1 }, { value: -2 }], + data: [{ value: 1 }, { value: 2 }], } as any) as IAxisData; const axisMenuSelection = ({ dataType: CLIN_ATTR_DATA_TYPE, @@ -778,6 +778,17 @@ describe('PlotsTabUtils', () => { } as any) as AxisMenuSelection; assert.isTrue(logScalePossible(axisMenuSelection, axisData)); }); + it('should return false when negative data is type number', () => { + const axisData = ({ + datatype: 'number', + data: [{ value: 1 }, { value: -2 }], + } as any) as IAxisData; + const axisMenuSelection = ({ + dataType: CLIN_ATTR_DATA_TYPE, + genericAssayDataType: DataTypeConstants.LIMITVALUE, + } as any) as AxisMenuSelection; + assert.isFalse(logScalePossible(axisMenuSelection, axisData)); + }); }); describe('axisHasNegativeNumbers', () => { diff --git a/src/shared/components/plots/PlotsTabUtils.tsx b/src/shared/components/plots/PlotsTabUtils.tsx index 23af98bf8ef..1a1db9e23e3 100644 --- a/src/shared/components/plots/PlotsTabUtils.tsx +++ b/src/shared/components/plots/PlotsTabUtils.tsx @@ -2583,11 +2583,12 @@ export function logScalePossible( ) { return true; } else if ( + axisData && isGenericAssaySelected(axisSelection) && axisSelection.genericAssayDataType === DataTypeConstants.LIMITVALUE ) { - // Generic Assay numeric profile is log scale possible - return true; + // Check negative values in log scale + return axisHasNegativeNumbers(axisData) ? false : true; } else { // molecular profile return !!(