-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Incorrect linestyle representation in legend for custom linestyles #2851
Comments
Notice also that the values I give to this four-element vector do not affect the display of the legend in any way |
the dash is probably just as long as the marker, increase patchsize to make the pattern visible |
if not, it's a bug |
...
al = axislegend(ax)
display(f)
al.blockscene.children[1].plots[end].linestyle[] # nothing |
great, thanks, so this is clearly a bug then. |
Ah I think I understand what's happening, it's because the legend code assumes |
+1 for the struct, and also documenting what these values mean (coz I really have no clue!) |
They're positions where the line flips from being drawn to not or vice versa, in units of linewidth. So with |
Hi there @jkrumbiegel ; I'm currently preparing some figures for a publication that I'm about to submit, and I would really like to solve this issue as I need custom linestyles in the legend. No worries, I'm not expecting you to do it :P I'd like to solve this PR, but I would like some guidance first... My plan:
|
|
Okay, I now really need to fix this because our paper is about to be published so I'll get to work here!!! @jkrumbiegel could I please ge tsome support here? I do not know what to do about part 5 nor where in the source code to add this new type |
"""
Linestyle(spec::Vector{<:Real})
A type that can be used as value for the `linestyle` keyword argument
of plotting functions to arbitrarily customize the linestyle.
The `spec` is a vector of positions where the line flips from being drawn or not
and vice versa. The values of `spec` are in units of linewidth.
For example, with `spec = [0.0, 4.0, 6.0, 9.5]`
you start drawing at 0, stop at 4 linewidths, start again at 6, stop at 9.5,
then repeat with 0 and 9.5 being treated as the same position.
"""
struct Linestyle
spec::Vector{Float32}
end type is here for reference. |
It appears that I should add this type here: https://github.com/MakieOrg/Makie.jl/blob/master/MakieCore/src/types.jl |
Yeah that location could work, or somewhere in Makie where other attribute types are defined. Then you'd define a method here https://github.com/MakieOrg/Makie.jl/blob/master/src/conversions.jl#L870 for this new type, create a plot and see where in the backend it errors because GLMakie etc. don't know about it. Alternatively, this type could get an attribute convert to the array form, then it might just work immediately. Although I was kind of hoping we could remove that one since we're not using arrays for scalar attributes anywhere else so I consider it to be a design wart. @SimonDanisch ? |
Are there any instructions anywhere on how to "develop" makie? Due to the mono repo structure, I do not know how I can do it, as I only know how to do |
@jkrumbiegel I already replied to you, but the message is gone somehow -.- Ah well:
What do you want to remove? And I think linestyle is the only attribute left, where we use an array for scalar attributes, right? |
@SimonDanisch the ability to give a linestyle as an array of numbers at all. If it's an array it should be an array of |
OH MY DEAR LORD. GUYS. IT JUST WORKED. I cAN"T BELIEVE HOW EASY IT WAS: # here CairoMakie, Makie, MakieCore are in development mode:
"""
Linestyle(value::Vector{<:Real})
A type that can be used as value for the `linestyle` keyword argument
of plotting functions to arbitrarily customize the linestyle.
The `value` is a vector of positions where the line flips from being drawn or not
and vice versa. The values of `value` are in units of linewidth.
For example, with `value = [0.0, 4.0, 6.0, 9.5]`
you start drawing at 0, stop at 4 linewidths, start again at 6, stop at 9.5,
then repeat with 0 and 9.5 being treated as the same position.
"""
struct Linestyle
value::Vector{Float32}
end
# Overload conversions
Makie.convert_attribute(A::Linestyle, ::key"linestyle") = [float(x - A.value[1]) for x in A.value]
# add deprecation for old conversion
function Makie.convert_attribute(A::AbstractVector, ::key"linestyle")
@warn "Using a vector as a linestyle attribute is deprecated. Wrap it in a `Linestyle`."
return [float(x - A[1]) for x in A]
end
# MWE:
f = Figure()
ax = Axis(f[1, 1])
xs = 0:0.01:10
ys = 0.5 .* sin.(xs)
lw = 3
i = 1
lines!(xs, ys .- i/6, linestyle = nothing, linewidth = lw, label = "$(lw)")
lines!(xs, ys .- i/6 .- 2, linestyle = :dot, linewidth = lw, label = "$(lw)")
lines!(xs, ys .- i/6 .- 4, linestyle = Linestyle([0.0, 4.0, 6.0, 9.5]), linewidth = lw, label = "$(lw)")
axislegend(ax)
display(f) |
I am doing a PR right now!!! |
Now it's |
MWE:
as you can see, the legend incorrectly displays the linestyle: it doesn't have any dashes, but it is a continuous line.
The text was updated successfully, but these errors were encountered: