MakieOrg / Makie.jl

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

Cannot set linestyle to :solid with observable #3693

Open oniehuis opened 7 months ago

oniehuis commented 7 months ago

When using an observable to change the linestyle of lines in an axis, it works for the :dot, :dash, :dotdash styles, but not for the :solid style (throws an error). Here is a short code that generates the error, with the error message, when running the code with Julia v1.10.2 and GLMakie v0.9.9.

using GLMakie

f = Figure()
ax = Axis(f[1, 1])
display(f)

ls = Observable{Symbol}(:dot)
lines!(ax, 1:100, rand(100), linestyle=ls)

ls[] = :dash  # ok
ls[] = :dashdot  # ok
ls[] = :dashdotdot  # ok
ls[] = :solid  # ERROR

ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Vector{Float32}

Closest candidates are:
  convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/EHHaF/src/SizedArray.jl:88
  convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, M, TData} where {M, TData<:AbstractArray{T, M}}) where {T, S, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/EHHaF/src/SizedArray.jl:82
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  ...

Stacktrace:
  [1] setproperty!(x::Observable{Vector{Float32}}, f::Symbol, v::Nothing)
    @ Base ./Base.jl:40
  [2] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:122
  [3] (::Observables.MapCallback)(value::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:436
  [4] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
  [5] invokelatest
    @ ./essentials.jl:889 [inlined]
  [6] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
  [7] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
  [8] (::Observables.SetindexCallback)(x::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:148
  [9] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [10] invokelatest
    @ ./essentials.jl:889 [inlined]
 [11] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [12] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
 [13] top-level scope
    @ ~/Desktop/test.jl:19
ffreyer commented 7 months ago

We could make this possible by treating :solid as a always-draw pattern (i.e. convert it to [0.0]) but that also means linestyle = :solid is going to be a bit slower than nothing