Skip to content

Commit

Permalink
DataInspector: fix an attribute extraction bug for heatmaps & images (#…
Browse files Browse the repository at this point in the history
…3260)

If the colorrange attribute is left at default it returns
MakieCore.Automatic; the method for `get` that was called at
show_imagelike does not check for this type so the ensuing call to
interpolated_getindex would fail.

The colorrange is now generically extracted and
calculated_colors[].colorrange[] is preferred as it contains the actual
range.

Fixes #3101
  • Loading branch information
Sagnac authored Oct 24, 2023
1 parent 21b4d24 commit def433d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/interaction/inspector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ function show_imagelike(inspector, plot, name, edge_based)
a._color[] = if z isa AbstractFloat
interpolated_getindex(
to_colormap(plot.colormap[]), z,
to_value(get(plot.attributes, :colorrange, (0, 1)))
extract_colorrange(plot)
)
else
z
Expand Down
10 changes: 10 additions & 0 deletions src/makielayout/blocks/colorbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ function colorbar_check(keys, kwargs_keys)
end
end

function extract_colorrange(@nospecialize(plot::AbstractPlot))::Vec2{Float64}
if haskey(plot, :calculated_colors) && plot.calculated_colors[] isa Makie.ColorMapping
return plot.calculated_colors[].colorrange[]
elseif haskey(plot, :colorrange) && !(plot.colorrange[] isa Makie.Automatic)
return plot.colorrange[]
else
error("colorrange not found and calculated_colors for the plot is missing or is not a proper color map. Heatmaps and images should always contain calculated_colors[].colorrange")
end
end

function extract_colormap(@nospecialize(plot::AbstractPlot))
has_colorrange = haskey(plot, :colorrange) && !(plot.colorrange[] isa Makie.Automatic)
if haskey(plot, :calculated_colors) && plot.calculated_colors[] isa Makie.ColorMapping
Expand Down

0 comments on commit def433d

Please sign in to comment.