Open ptiede opened 3 weeks ago
Adding the method does seem to correct this
Makie.to_endpoints(x::Tuple{Unitful.AbstractQuantity,Unitful.AbstractQuantity}) = (ustrip(x[1]), ustrip(x[2]))
Hmm, this might need more dimension expanding. Unitful quantities should never be hitting convert_arguments
in the first place
Is it a expand_dimension
method that is missing? I noticed that expand_dimensions
only seems to be defined for abstract vectors and an interval isn't a subtype of that
I'm really new to the Makie codebase (but long time user) so I don't understand the expand_dimension and conversion pipeline yet.
The expand dimensions pipeline is also super new 😄 but the idea is that all unit information is stripped by expand_dimensions
, and then the only values passed into convert_arguments
are unitless. This also allows us to ensure that all unitful quantities of the same dimension share the same unit / magnitude (so you don't have combinations of m
and km
, which don't make sense).
There are two main methods to target AFAIK - should_dim_convert
and expand_dimensions
. I have to step out now but will dive into the codebase tomorrow and send a better explanation.
The solution here is probably to support unitful intervals for x and y on ImageLike
and GridBased
conversion traits.
Looking through the code one thing I noticed is that AbstractIntervals
aren't being treated the same as AbstractVectors
, especially w.r.t. get_element_type
. Currently get_element_type
will just return the interval and I would guess it should be
get_element_type(int::AbstractInterval{T}) where {T} = T
so that whatever conversion pipeline can see that the element type is not real and run a convert on it.
EDIT or maybe if eltype is Any you can do
function get_element_type(int::AbstractInterval{T}) where {T}
if T === Any
return mapreduce(typeof, promote_type, endpoints(int))
else
return T
end
end
So if you add the get_element_type
method you run into more errors, although they all live int unitful_integration.jl
.
My guess is that's a good thing! The main problem in this file is that a lot of the dim_convert machinery assumes that the dimensions are iterable, which isn't true for Intervals
. To fix this you can add the following definitions
function eltype_extrema(values::ClosedInterval)
return eltype_extrema(endpoints(values))
end
function unit_convert(unit::T, x::ClosedInterval) where T <: Union{Type{<:Unitful.AbstractQuantity}, Unitful.FreeUnits, Unitful.Unit}
int = endpoints(x)
return ClosedInterval(unit_convert.(Ref(unit), int)...)
end
_check_convert(unit, values) = unit_convert(unit, values)
_check_convert(unit, value::ClosedInterval) = unit_convert(unit, minimum(value))
function convert_dim_observable(conversion::UnitfulConversion, value_obs::Observable, deregister)
result = map(conversion.unit, value_obs; ignore_equal_values=true) do unit, values
if !isempty(values)
# try if conversion works, to through error if not!
# Is there a function for this to check in Unitful?
_check_convert(unit, values)
end
update_extrema!(conversion, value_obs)
return unit_convert(conversion.unit[], values)
end
append!(deregister, result.inputs)
return result
end
These changes fix the MWE, but I am not sure if this is correct Makie code.
Makie version: 0.21.7
It looks like
to_endpoints
is missing a dispatch for uniful intervals. MWE