From 21a096600c03ab5e09cbad5b34ce93df677c9003 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Tue, 13 Dec 2022 09:58:43 +0100 Subject: [PATCH] fix `Colorbar` `scale` --- ReferenceTests/src/tests/examples2d.jl | 8 ++++++++ src/makielayout/blocks/axis.jl | 2 +- src/makielayout/blocks/colorbar.jl | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 757eadde6ae..cd673511381 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -523,6 +523,14 @@ end fig end +@reference_test "scaled colormap" begin + x = 10.0.^(1:0.1:4) + y = 1.0:0.1:5.0 + fig, ax, hm = heatmap(x, y, (x, y) -> log10(x); axis = (; xscale = log10)) + Colorbar(fig[1, 2], hm; scale = log10) + fig +end + @reference_test "multi rect with poly" begin # use thick strokewidth, so it will make tests fail if something is missing poly([Rect2f(0, 0, 1, 1)], color=:green, strokewidth=100, strokecolor=:black) diff --git a/src/makielayout/blocks/axis.jl b/src/makielayout/blocks/axis.jl index 926e6434263..22707276e72 100644 --- a/src/makielayout/blocks/axis.jl +++ b/src/makielayout/blocks/axis.jl @@ -817,7 +817,7 @@ function expandlimits(lims, margin_low, margin_high, scale) w_scaled = lims_scaled[2] - lims_scaled[1] d_low_scaled = w_scaled * margin_low d_high_scaled = w_scaled * margin_high - inverse = Makie.inverse_transform(scale) + inverse = inverse_transform(scale) lims = inverse.((lims_scaled[1] - d_low_scaled, lims_scaled[2] + d_high_scaled)) # guard against singular limits from something like a vline or hline diff --git a/src/makielayout/blocks/colorbar.jl b/src/makielayout/blocks/colorbar.jl index 88ab2ba34aa..84eeb6d840b 100644 --- a/src/makielayout/blocks/colorbar.jl +++ b/src/makielayout/blocks/colorbar.jl @@ -87,6 +87,8 @@ function initialize_block!(cb::Colorbar) return something(limits, colorrange, (0, 1)) end + unscaled_limits = @lift inverse_transform($(cb.scale)).($limits) + onany(cb.size, cb.vertical) do sz, vertical if vertical cb.layoutobservables.autosize[] = (sz, nothing) @@ -170,7 +172,6 @@ function initialize_block!(cb::Colorbar) # for categorical colormaps we make a number of rectangle polys rects_and_colors = lift(barbox, cb.vertical, steps, cgradient, cb.scale, limits) do bbox, v, steps, gradient, scale, lims - # we need to convert the 0 to 1 steps into rescaled 0 to 1 steps given the # colormap's `scale` attribute @@ -313,7 +314,7 @@ function initialize_block!(cb::Colorbar) end axis = LineAxis(blockscene, endpoints = axispoints, flipped = cb.flipaxis, - limits = limits, ticklabelalign = cb.ticklabelalign, label = cb.label, + limits = unscaled_limits, ticklabelalign = cb.ticklabelalign, label = cb.label, labelpadding = cb.labelpadding, labelvisible = cb.labelvisible, labelsize = cb.labelsize, labelcolor = cb.labelcolor, labelfont = cb.labelfont, ticklabelfont = cb.ticklabelfont, ticks = cb.ticks, tickformat = cb.tickformat,