Skip to content

Commit

Permalink
fix Colorbar scale
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 13, 2022
1 parent 5f78379 commit 080dfd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/makielayout/blocks/colorbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 080dfd7

Please sign in to comment.