From 5599c90ea4a96def7dbef6df0f5414c317319d5f Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Wed, 15 Jan 2025 10:57:02 +0100 Subject: [PATCH] Make log ticks formatter selection logic more robust --- packages/lib/src/vis/utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/lib/src/vis/utils.ts b/packages/lib/src/vis/utils.ts index 4da8f893f..e6949c513 100644 --- a/packages/lib/src/vis/utils.ts +++ b/packages/lib/src/vis/utils.ts @@ -278,8 +278,15 @@ export function getTickFormatter( } // If available size allows for all log ticks to be rendered without overlap, use default formatter - const [min, max] = domain[0] > 0 ? domain : [-domain[1], -domain[0]]; const threshold = adaptedLogTicksThreshold(availableSize); + + /* In log scale, domain is either fully positive or fully negative + * (otherwise, it's `[NaN, NaN]` and it doesn't matter which formatter we use). + * If fully negative, convert to fully positive for threshold logic to work. */ + const absDomain = domain.map(Math.abs) as Domain; + absDomain.sort((a, b) => a - b); + + const [min, max] = absDomain; if (max / min < 10 ** threshold) { return formatTick; }