diff --git a/ReferenceTests/src/tests/figures_and_makielayout.jl b/ReferenceTests/src/tests/figures_and_makielayout.jl index 9d3d24d5cee..ea48e27f7d0 100644 --- a/ReferenceTests/src/tests/figures_and_makielayout.jl +++ b/ReferenceTests/src/tests/figures_and_makielayout.jl @@ -151,13 +151,13 @@ end f = Figure(resolution = (800, 400)) ax1 = PolarAxis(f[1, 1], title = "No spine", spinevisible = false) scatterlines!(ax1, range(0, 1, length=100), range(0, 10pi, length=100), color = 1:100) - + ax2 = PolarAxis(f[1, 2], title = "Modified spine") ax2.spinecolor[] = :red ax2.spinestyle[] = :dash ax2.spinewidth[] = 5 scatterlines!(ax2, range(0, 1, length=100), range(0, 10pi, length=100), color = 1:100) - + f end @@ -166,9 +166,9 @@ end @reference_test "PolarAxis decorations" begin f = Figure(resolution = (400, 400), backgroundcolor = :black) ax = PolarAxis( - f[1, 1], + f[1, 1], backgroundcolor = :black, - rminorgridvisible = true, rminorgridcolor = :red, + rminorgridvisible = true, rminorgridcolor = :red, rminorgridwidth = 1.0, rminorgridstyle = :dash, thetaminorgridvisible = true, thetaminorgridcolor = :blue, thetaminorgridwidth = 1.0, thetaminorgridstyle = :dash, @@ -179,7 +179,7 @@ end thetaticklabelsize = 18, thetaticklabelcolor = :blue, thetaticklabelstrokewidth = 1, thetaticklabelstrokecolor = :white, ) - + f end @@ -192,3 +192,34 @@ end end f end + +@reference_test "Colorbar for recipes" begin + fig, ax, pl = barplot(1:3; color=1:3, colormap=Makie.Categorical(:viridis)) + Colorbar(fig[1, 2], pl; size=100) + x = LinRange(-1, 1, 20) + y = LinRange(-1, 1, 20) + z = LinRange(-1, 1, 20) + values = [sin(x[i]) * cos(y[j]) * sin(z[k]) for i in 1:20, j in 1:20, k in 1:20] + + # TO not make this fail in CairoMakie, we dont actually plot the volume + _f, ax, cp = contour(x, y, z, values; levels=10, colormap=:viridis) + Colorbar(fig[2, :], cp; size=300) + + # horizontal colorbars + Colorbar(fig[1, 3][2, 1]; limits=(0, 10), colormap=:viridis, + vertical=false) + Colorbar(fig[1, 3][3, 1]; limits=(0, 5), size=25, + colormap=cgrad(:Spectral, 5; categorical=true), vertical=false) + Colorbar(fig[1, 3][4, 1]; limits=(-1, 1), colormap=:heat, vertical=false, flipaxis=false, + highclip=:cyan, lowclip=:red) + + ax, hm = contourf(fig[2, 3][1, 1], xs, ys, zs; + colormap=:Spectral, levels=[-1, -0.5, -0.25, 0, 0.25, 0.5, 1]) + Colorbar(fig[2, 3][1, 2], hm; ticks=-1:0.25:1) + + ax, hm = contourf(fig[3, :][1, 1], xs, ys, zs; + colormap=:Spectral, colorscale=sqrt, levels=[ 0, 0.25, 0.5, 1]) + Colorbar(fig[3, :][1, 2], hm; width=200) + + fig +end diff --git a/src/makielayout/blocks/colorbar.jl b/src/makielayout/blocks/colorbar.jl index d251f079778..7ef9bc73e85 100644 --- a/src/makielayout/blocks/colorbar.jl +++ b/src/makielayout/blocks/colorbar.jl @@ -123,6 +123,7 @@ function initialize_block!(cb::Colorbar) if cb.colormap[] isa ColorMapping cmap = cb.colormap[] else + # Old way without Colormapping. We keep it, to be able to create a colormap directly limits = lift(blockscene, cb.limits, cb.colorrange) do limits, colorrange if all(!isnothing, (limits, colorrange)) error("Both colorrange + limits are set, please only set one, they're aliases. colorrange: $(colorrange), limits: $(limits)") @@ -141,7 +142,7 @@ function initialize_block!(cb::Colorbar) colors = lift(blockscene, cmap.mapping, cmap.color_mapping_type, cmap.color, limits, cb.nsteps; ignore_equal_values=true) do mapping, mapping_type, values, limits, n if mapping === nothing if mapping_type === Makie.banded - return sort!(convert(Vector{Float64}, mapping)) + error("Banded without a mapping is invalid. Please use colormap=cgrad(...; categorical=true)") elseif mapping_type === Makie.categorical return convert(Vector{Float64},1:length(unique(values))) else @@ -197,7 +198,6 @@ function initialize_block!(cb::Colorbar) # for continous colormaps we sample a 1d image # to avoid white lines when rendering vector graphics - continous_pixels = lift(blockscene, cb.vertical, colors, cmap.color_mapping_type) do v, colors, mapping_type if mapping_type !== Makie.categorical @@ -206,9 +206,9 @@ function initialize_block!(cb::Colorbar) n = length(colors) return v ? reshape((colors), 1, n) : reshape((colors), n, 1) end + # TODO, implement interpolate = true for irregular grics in CairoMakie # Then, we can just use heatmap! and don't need the image plot! - show_cats = Observable(false; ignore_equal_values=true) show_continous = Observable(false; ignore_equal_values=true) on(blockscene, cmap.color_mapping_type; update=true) do type @@ -328,6 +328,7 @@ function initialize_block!(cb::Colorbar) ticks = Observable{Any}() map!(ticks, colors, cmap.color_mapping_type, cb.ticks) do cs, type, ticks + # For categorical we just enumerate type === Makie.categorical ? (1:length(cs), string.(cs)) : ticks end