Skip to content

Commit

Permalink
Merge branch 'master' into ff/camera
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Feb 2, 2024
2 parents bba659d + b833443 commit 2eadc32
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 15 deletions.
2 changes: 1 addition & 1 deletion GLMakie/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can find instructions to set that up in:
https://nextjournal.com/sdanisch/GLMakie-nogpu
And for a headless github action:

https://github.com/MakieOrg/Makie.jl/blob/master/.github/workflows/glmakie.yaml
https://github.com/MakieOrg/Makie.jl/blob/master/.github/workflows/reference_tests.yml
If none of these work for you, there is also a Cairo and WebGL backend
for Makie which you can use:

Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master

- Fix issues with Camera3D not centering [#3582](https://github.com/MakieOrg/Makie.jl/pull/3582)
- Allowed creating legend entries from plot objects with scalar numbers as colors [#3587](https://github.com/MakieOrg/Makie.jl/pull/3587).

## 0.20.5

Expand Down
21 changes: 21 additions & 0 deletions ReferenceTests/src/tests/figures_and_makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ end
end
end

@reference_test "Legend with scalar colors" begin
f = Figure()
ax = Axis(f[1, 1])
for i in 1:3
lines!(ax, (1:3) .+ i, color = i, colorrange = (0, 4), colormap = :Blues, label = "Line $i", linewidth = 3)
end
for i in 1:3
scatter!(ax, (1:3) .+ i .+ 3, color = i, colorrange = (0, 4), colormap = :plasma, label = "Scatter $i", markersize = 15)
end
for i in 1:3
barplot!(ax, (1:3) .+ i .+ 8, fillto = (1:3) .+ i .+ 7.5, color = i, colorrange = (0, 4), colormap = :tab10, label = "Barplot $i")
end
for i in 1:3
poly!(ax, [Rect2f((j, i .+ 12 + j), (0.5, 0.5)) for j in 1:3], color = i, colorrange = (0, 4), colormap = :heat, label = "Poly $i")
end
Legend(f[1, 2], ax)
f
end

@reference_test "LaTeXStrings in Axis3 plots" begin
xs = LinRange(-10, 10, 100)
ys = LinRange(0, 15, 100)
Expand Down Expand Up @@ -204,6 +223,7 @@ end
rticklabelstrokewidth = 1, rticklabelstrokecolor = :white,
thetaticklabelsize = 18, thetaticklabelcolor = :blue,
thetaticklabelstrokewidth = 1, thetaticklabelstrokecolor = :white,
thetaticks = ([0, π/2, π, 3π/2], ["A", "B", "C", rich("D", color = :orange)]), # https://github.com/MakieOrg/Makie.jl/issues/3583
)
f
end
Expand Down Expand Up @@ -305,3 +325,4 @@ end
axislegend(ax)
fig
end

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
35 changes: 31 additions & 4 deletions src/makielayout/blocks/legend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ function legendelement_plots!(scene, element::MarkerElement, bbox::Observable{Re
scat = scatter!(scene, points, color = attrs.markercolor, marker = attrs.marker,
markersize = attrs.markersize,
strokewidth = attrs.markerstrokewidth,
strokecolor = attrs.markerstrokecolor, inspectable = false)
strokecolor = attrs.markerstrokecolor, inspectable = false,
colormap = attrs.markercolormap,
colorrange = attrs.markercolorrange,
)

return [scat]
end
Expand All @@ -284,6 +287,7 @@ function legendelement_plots!(scene, element::LineElement, bbox::Observable{Rect
fracpoints = attrs.linepoints
points = lift((bb, fp) -> fractionpoint.(Ref(bb), fp), scene, bbox, fracpoints)
lin = lines!(scene, points, linewidth = attrs.linewidth, color = attrs.linecolor,
colormap = attrs.linecolormap, colorrange = attrs.linecolorrange,
linestyle = attrs.linestyle, inspectable = false)

return [lin]
Expand All @@ -295,7 +299,8 @@ function legendelement_plots!(scene, element::PolyElement, bbox::Observable{Rect
fracpoints = attrs.polypoints
points = lift((bb, fp) -> fractionpoint.(Ref(bb), fp), scene, bbox, fracpoints)
pol = poly!(scene, points, strokewidth = attrs.polystrokewidth, color = attrs.polycolor,
strokecolor = attrs.polystrokecolor, inspectable = false)
strokecolor = attrs.polystrokecolor, inspectable = false,
colormap = attrs.polycolormap, colorrange = attrs.polycolorrange)

return [pol]
end
Expand Down Expand Up @@ -368,18 +373,24 @@ end
_renaming_mapping(::Type{LineElement}) = Dict(
:points => :linepoints,
:color => :linecolor,
:colormap => :linecolormap,
:colorrange => :linecolorrange,
)
_renaming_mapping(::Type{MarkerElement}) = Dict(
:points => :markerpoints,
:color => :markercolor,
:strokewidth => :markerstrokewidth,
:strokecolor => :markerstrokecolor,
:colormap => :markercolormap,
:colorrange => :markercolorrange,
)
_renaming_mapping(::Type{PolyElement}) = Dict(
:points => :polypoints,
:color => :polycolor,
:strokewidth => :polystrokewidth,
:strokecolor => :polystrokecolor,
:colormap => :polycolormap,
:colorrange => :polycolorrange,
)

function _rename_attributes!(T, a)
Expand Down Expand Up @@ -408,7 +419,10 @@ function legendelements(plot::Union{Lines, LineSegments}, legend)
LegendElement[LineElement(
color = extract_color(plot, legend.linecolor),
linestyle = choose_scalar(plot.linestyle, legend.linestyle),
linewidth = choose_scalar(plot.linewidth, legend.linewidth))]
linewidth = choose_scalar(plot.linewidth, legend.linewidth),
colormap = plot.colormap,
colorrange = plot.colorrange,
)]
end

function legendelements(plot::Scatter, legend)
Expand All @@ -418,6 +432,8 @@ function legendelements(plot::Scatter, legend)
markersize = choose_scalar(plot.markersize, legend.markersize),
strokewidth = choose_scalar(plot.strokewidth, legend.markerstrokewidth),
strokecolor = choose_scalar(plot.strokecolor, legend.markerstrokecolor),
colormap = plot.colormap,
colorrange = plot.colorrange,
)]
end

Expand All @@ -427,12 +443,23 @@ function legendelements(plot::Union{Poly, Violin, BoxPlot, CrossBar, Density}, l
color = color,
strokecolor = choose_scalar(plot.strokecolor, legend.polystrokecolor),
strokewidth = choose_scalar(plot.strokewidth, legend.polystrokewidth),
colormap = plot.colormap,
colorrange = plot.colorrange,
)]
end

function legendelements(plot::Band, legend)
# there seems to be no stroke for Band, so we set it invisible
LegendElement[PolyElement(polycolor = choose_scalar(plot.color, legend.polystrokecolor), polystrokecolor = :transparent, polystrokewidth = 0)]
return LegendElement[PolyElement(;
polycolor = choose_scalar(
plot.color,
legend.polystrokecolor
),
polystrokecolor = :transparent,
polystrokewidth = 0,
polycolormap = plot.colormap,
polycolorrange = plot.colorrange,
)]
end

# if there is no specific overload available, we go through the child plots and just stack
Expand Down
2 changes: 1 addition & 1 deletion src/makielayout/blocks/polaraxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function draw_axis!(po::PolarAxis)
end


thetatick_pos_lbl = Observable{Vector{<:Tuple{AbstractString, Point2f}}}()
thetatick_pos_lbl = Observable{Vector{<:Tuple{Any, Point2f}}}()
thetatick_align = Observable(Point2f[])
thetatick_offset = Observable(Point2f[])
thetagridpoints = Observable{Vector{Point2f}}()
Expand Down
6 changes: 3 additions & 3 deletions src/makielayout/defaultattributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ end
function attributenames(::Type{LegendEntry})
(:label, :labelsize, :labelfont, :labelcolor, :labelhalign, :labelvalign,
:patchsize, :patchstrokecolor, :patchstrokewidth, :patchcolor,
:linepoints, :linewidth, :linecolor, :linestyle,
:markerpoints, :markersize, :markerstrokewidth, :markercolor, :markerstrokecolor,
:polypoints, :polystrokewidth, :polycolor, :polystrokecolor)
:linepoints, :linewidth, :linecolor, :linestyle, :linecolorrange, :linecolormap,
:markerpoints, :markersize, :markerstrokewidth, :markercolor, :markerstrokecolor, :markercolorrange, :markercolormap,
:polypoints, :polystrokewidth, :polycolor, :polystrokecolor, :polycolorrange, :polycolormap)
end

function extractattributes(attributes::Attributes, typ::Type)
Expand Down
12 changes: 12 additions & 0 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1213,10 +1213,18 @@ const EntryGroup = Tuple{Any, Vector{LegendEntry}}
linewidth = theme(scene, :linewidth)
"The default line color used for LineElements"
linecolor = theme(scene, :linecolor)
"The default colormap for LineElements"
linecolormap = theme(scene, :colormap)
"The default colorrange for LineElements"
linecolorrange = automatic
"The default line style used for LineElements"
linestyle = :solid
"The default marker color for MarkerElements"
markercolor = theme(scene, :markercolor)
"The default marker colormap for MarkerElements"
markercolormap = theme(scene, :colormap)
"The default marker colorrange for MarkerElements"
markercolorrange = automatic
"The default marker for MarkerElements"
marker = theme(scene, :marker)
"The default marker points used for MarkerElements in normalized coordinates relative to each label patch."
Expand All @@ -1235,6 +1243,10 @@ const EntryGroup = Tuple{Any, Vector{LegendEntry}}
polycolor = theme(scene, :patchcolor)
"The default poly stroke color used for PolyElements."
polystrokecolor = theme(scene, :patchstrokecolor)
"The default colormap for PolyElements"
polycolormap = theme(scene, :colormap)
"The default colorrange for PolyElements"
polycolorrange = automatic
"The orientation of the legend (:horizontal or :vertical)."
orientation = :vertical
"The gap between each group title and its group."
Expand Down
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 2eadc32

Please sign in to comment.