From def4d1dcb9814d15b7118fc6567c3eaf939fa3ce Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 25 Apr 2025 10:58:48 +0200 Subject: [PATCH] decide best unit by range of axis instead of middle --- src/dim-converts/unitful-integration.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dim-converts/unitful-integration.jl b/src/dim-converts/unitful-integration.jl index c77671d153d..1d4c71bd039 100644 --- a/src/dim-converts/unitful-integration.jl +++ b/src/dim-converts/unitful-integration.jl @@ -91,10 +91,10 @@ function get_all_base10_units(x::Unitful.Unit{Sym, Unitful.𝐓}) where {Sym} end function best_unit(min, max) - middle = (min + max) / 2.0 - all_units = get_all_base10_units(middle) + axis_length = max - min + all_units = get_all_base10_units(axis_length) _, index = findmin(all_units) do unit - raw_value = abs(unit_convert(unit, middle)) + raw_value = abs(unit_convert(unit, axis_length)) # We want the unit that displays the value with the smallest number possible, but not something like 1.0e-19 # So, for fractions between 0..1, we use inv to penalize really small fractions positive = raw_value < 1.0 ? (inv(raw_value) + 100) : raw_value