Skip to content

Commit

Permalink
Fix scatterlines scalar number color (#3586)
Browse files Browse the repository at this point in the history
* Fix scalar number as color in scatterlines

* add unit test
  • Loading branch information
jkrumbiegel authored Feb 1, 2024
1 parent 7a08265 commit 41a9550
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/basic_recipes/scatterlines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ $(ATTRIBUTES)
linestyle = l_theme.linestyle,
linewidth = l_theme.linewidth,
markercolor = automatic,
markercolormap = s_theme.colormap,
markercolorrange = get(s_theme.attributes, :colorrange, automatic),
markercolormap = automatic,
markercolorrange = automatic,
markersize = s_theme.markersize,
strokecolor = s_theme.strokecolor,
strokewidth = s_theme.strokewidth,
Expand All @@ -32,8 +32,7 @@ end
function plot!(p::Plot{scatterlines, <:NTuple{N, Any}}) where N

# markercolor is the same as linecolor if left automatic
# RGBColors -> union of all colortypes that `to_color` accepts + returns
real_markercolor = Observable{RGBColors}()
real_markercolor = Observable{Any}()
map!(real_markercolor, p.color, p.markercolor) do col, mcol
if mcol === automatic
return to_color(col)
Expand All @@ -42,6 +41,16 @@ function plot!(p::Plot{scatterlines, <:NTuple{N, Any}}) where N
end
end

real_markercolormap = Observable{Any}()
map!(real_markercolormap, p.colormap, p.markercolormap) do col, mcol
mcol === automatic ? col : mcol
end

real_markercolorrange = Observable{Any}()
map!(real_markercolorrange, p.colorrange, p.markercolorrange) do col, mcol
mcol === automatic ? col : mcol
end

lines!(p, p[1:N]...;
color = p.color,
linestyle = p.linestyle,
Expand All @@ -57,9 +66,9 @@ function plot!(p::Plot{scatterlines, <:NTuple{N, Any}}) where N
strokewidth = p.strokewidth,
marker = p.marker,
markersize = p.markersize,
colormap = p.markercolormap,
colormap = real_markercolormap,
colorscale = p.colorscale,
colorrange = p.markercolorrange,
colorrange = real_markercolorrange,
inspectable = p.inspectable
)
end
25 changes: 25 additions & 0 deletions test/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,28 @@ end
# linesegments!(Makie.data_limits(ax.scene), color=:red)
# display(fig)
# end


# https://github.com/MakieOrg/Makie.jl/issues/3551
@testset "scalar color for scatterlines" begin
colorrange = (1, 5)
colormap = :Blues
f, ax, sl = scatterlines(1:10,1:10,color=3,colormap=colormap,colorrange=colorrange)
l = sl.plots[1]::Lines
sc = sl.plots[2]::Scatter
@test l.color[] == 3
@test l.colorrange[] == colorrange
@test l.colormap[] == colormap
@test sc.color[] == 3
@test sc.colorrange[] == colorrange
@test sc.colormap[] == colormap
sl.markercolor = 4
sl.markercolormap = :jet
sl.markercolorrange = (2, 7)
@test l.color[] == 3
@test l.colorrange[] == colorrange
@test l.colormap[] == colormap
@test sc.color[] == 4
@test sc.colorrange[] == (2, 7)
@test sc.colormap[] == :jet
end

0 comments on commit 41a9550

Please sign in to comment.