Skip to content

Fix automatic unit decision for Unitful axes #4940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dim-converts/unitful-integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading