Open jariji opened 3 months ago
There are two parts to this not working, which more or less also apply to vspan/hspan and probably a number of other recipe plots. (I.e. this also applies to #4412)
The first point of failure is here:
https://github.com/MakieOrg/Makie.jl/blob/d7d407e59495eeced22aa71fe73377310e4a1d75/src/dim-converts/dim-converts.jl#L177-L181
Because vlines
only has one argument no dim conversion is attempted and thus the units do not get stripped, causing an error when converting to Point
types. If we remove this check we get further. On the vlines
level units now get handled correctly, convert_arguments() passes and plot!(::VLines)
passes.
But then we run into the second problem - dim_converts trigger again on the linesegments
plot created by vlines
. This plot has no units but is inserted into an Axis with units. We view this as incompatible, so it fails. Previously this would have skipped dim converts due to the check we removed.
If we did the same for hlines we'd run into another issue: try_dim_convert
assumes that plot.args[idx]
and converts[idx]
act in the same dimension. That's true for vlines where plot.args[1]
is an x value, but not hlines where it is a y value.
What I think we need is:
plot.args
map to spatial dimensions/dim_converts(1) seems failry straightforward to me. We could just add a function that given an args index returns a dim_converts index. Since some plots can change x/y direction via attributes, we'd need those there.
For (2) I'm not sure what to do. If we assume that only users add dim_converts (Units, Dates, Categorical values) we could just restrict dim converts to the top level plot. If not, we'd need to mark child plots as "probably already converted", where numeric values are seen as converted and units etc as needing conversions.
Note that I also have to do 1 in AlgebraOfGraphics, would be cool if I could completely avoid that because Makie has the required facilities included.
@ffreyer
If not, we'd need to mark child plots as "probably already converted", where numeric values are seen as converted and units etc as needing conversions.
Does this mean
fig, ax, plt = scatter(rand(5)s, rand(5))
vlines!(ax, rand(10))
would not error? I much prefer an error there since seconds and unitless numbers are not dimensionally compatible --- I use units to check my work.
Well that one actually doesn't error right now, but it would with those changes. Currently that bypasses unit conversions because of branch I pointed out and just continues as if rand(10)
was the correct unit. Without that branch and with (1) the args passed to vlines
would get processed by the unit conversion pipeline and error there. (2) would come after that to ensure that it doesn't get processed again.
I want the axis created with unitful values to keep those units
not revert to working with unitless values. Ideally it would error on
because the axis is unitful.