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 21a0966
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 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
2 changes: 1 addition & 1 deletion src/makielayout/blocks/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 21a0966

Please sign in to comment.