Skip to content
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

Cant plot empty vectors of LineString #2819

Closed
rafaqz opened this issue Mar 29, 2023 · 6 comments
Closed

Cant plot empty vectors of LineString #2819

rafaqz opened this issue Mar 29, 2023 · 6 comments

Comments

@rafaqz
Copy link
Contributor

rafaqz commented Mar 29, 2023

It would be good if this worked so we don't have to plot dummy linestrings

julia> Makie.plot(LineString[])
ERROR: BoundsError: attempt to access 0-element Vector{LineString} at index [1]
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] convert_arguments(PB::PointBased, linestring::Vector{LineString})
    @ Makie ~/.julia/dev/Makie/src/conversions.jl:214
  [3] convert_arguments(T::Type{Lines{Tuple{Vector{LineString}}}}, args::Vector{LineString}; kw::Base.Pairs{Sym
ol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/dev/Makie/src/conversions.jl:10
  [4] convert_arguments
    @ ~/.julia/dev/Makie/src/conversions.jl:7 [inlined]
  [5] plot!(scene::Scene, P::Type{Any}, attributes::Attributes, args::Vector{LineString}; kw_attributes::Base.P
irs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/dev/Makie/src/interfaces.jl:317
  [6] plot!(scene::Scene, P::Type{Any}, attributes::Attributes, args::Vector{LineString})
    @ Makie ~/.julia/dev/Makie/src/interfaces.jl:302
  [7] plot(P::Type{Any}, args::Vector{LineString}; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{
}, kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/dev/Makie/src/figureplotting.jl:48
  [8] plot
    @ ~/.julia/dev/Makie/src/figureplotting.jl:31 [inlined]
  [9] #plot#13
    @ ~/.julia/packages/MakieCore/msnkR/src/recipes.jl:34 [inlined]
 [10] plot(args::Vector{LineString})
    @ MakieCore ~/.julia/packages/MakieCore/msnkR/src/recipes.jl:33
 [11] top-level scope
    @ REPL[39]:1
@asinghvi17
Copy link
Member

asinghvi17 commented Mar 29, 2023

As I see it, there are two issues here (it's erroring on the first, but you'll run into the second):

  1. The convert_arguments for LineString is not well implemented for this case. This is something we can fix relatively easily.
  2. Primitives (and recipes) generally can't handle empty input. That might be a little more complicated :D

@rafaqz
Copy link
Contributor Author

rafaqz commented Mar 29, 2023

Oh no, so not so easy to fix...

The reason I want this is for MakieDraw.jl, where you really want to start with an empty plot and add things to it. Or sometimes want to delete everything and start from scratch. Currently I have to add a dummy geometry to everything so that they plot.

@asinghvi17
Copy link
Member

Yeah, it's definitely a feature which should exist, we had something similar with some specially implemented buffer plot types but they weren't totally generic.

@jkrumbiegel
Copy link
Member

Primitives (and recipes) generally can't handle empty input

That's not true, mostly these cases just hit type instabilities or reduce-over-empty-collection errors down the line. I fixed those for many cases where I needed them, for example you can easily set empty ticks on an Axis which gives you empty linesegments and text primitives.

@asinghvi17
Copy link
Member

Yeah, we'd have to implement code to handle this kind of thing, without leaving observables undefined, in each recipe. For example - what would streamplot do with empty input? It can of course set the pipeline up, but not actually run it.

Backends would be an easier task in comparison, CairoMakie could do this pretty easily.

@jkrumbiegel
Copy link
Member

In this specific case we just need to have a way to determine the type of the empty result vector correctly. Although Julia makes that tricky sometimes, for example Vector{LineString} has an abstract element type if I understand correctly, so you wouldn't be able to infer anything.

function convert_arguments(PB::PointBased, linestring::Union{Array{<:LineString}, MultiLineString})
    arr = copy(convert_arguments(PB, linestring[1])[1])
    for ls in 2:length(linestring)
        push!(arr, Point2f(NaN))
        append!(arr, convert_arguments(PB, linestring[ls])[1])
    end
    return (arr,)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants