Skip to content

Commit

Permalink
Merge pull request #1731 from silx-kit/fix-log-ticks
Browse files Browse the repository at this point in the history
Make log ticks formatter selection logic more robust
  • Loading branch information
axelboc authored Jan 15, 2025
2 parents 15ba529 + 5599c90 commit 3c8ea6d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/lib/src/vis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3c8ea6d

Please sign in to comment.