MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.39k stars 303 forks source link

Unhelpful error in recipe when forgetting the "self" argument #4039

Open mauro3 opened 2 months ago

mauro3 commented 2 months ago

Defining and using a recipe like so, with forgotten plot argument:

using GLMakie
@recipe(PltLine, x, y) do scene
    Attributes()
end
function Makie.plot!(plot::PltLine)
    lines!(plot.x, plot.y)
end
pltline(1:3, 1:3)

gives a super unhelpful error:

julia> include("/home/mauro/.julia/dev/WhereTheWaterFlows/examples/mk.jl")                                                                                                                      
Error showing value of type Makie.FigureAxisPlot:                                                                                                                                               
ERROR: StackOverflowError:                                                                                                                                                                      
Stacktrace:                                                                                                                                                                                     
     [1] data_limits(plot::Plot{pltline, Tuple{UnitRange{Int64}, UnitRange{Int64}}})                                                                                                            
       @ Makie ~/.julia/packages/Makie/rEu75/src/layouting/data_limits.jl:42                                                                                                                    
...

I got stuck now twice on this (ok, the second time it is my own fault ;-). Would be great if a more helpful error could be thrown.

jkrumbiegel commented 2 months ago

Hm so it must plot into an implicit axis there, which should not give an error per se, it's just random. But why does the data_limits call stack overflow from that, shouldn't plot be empty? Maybe that's the problem, that we have a bug for datalimits of recipes that are (accidentally) primitives because they have no children.

ffreyer commented 2 months ago

Because of

https://github.com/MakieOrg/Makie.jl/blob/699b7fc969ade3c9dd15474f59d27d3c35a67f18/src/layouting/data_limits.jl#L177-L178

but I think we can actually delete that. I think during reworking this code was at a state where some plots used data_limits directly and boundingbox still relied on iterate_transformed which relies on point_iterator. So for those I needed point_iterator defined. But now it just relies on data_limits directly except for MeshScatter and Scatter which have point_iterator defined.