From def433d8abdb3c44845f89391d54de3dd4e3d6b8 Mon Sep 17 00:00:00 2001 From: Sagnac <83491030+Sagnac@users.noreply.github.com> Date: Tue, 24 Oct 2023 09:43:05 +0000 Subject: [PATCH] DataInspector: fix an attribute extraction bug for heatmaps & images (#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 --- src/interaction/inspector.jl | 2 +- src/makielayout/blocks/colorbar.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/interaction/inspector.jl b/src/interaction/inspector.jl index 393d91f6fc1..0fce5bbe703 100644 --- a/src/interaction/inspector.jl +++ b/src/interaction/inspector.jl @@ -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 diff --git a/src/makielayout/blocks/colorbar.jl b/src/makielayout/blocks/colorbar.jl index 1330308e364..ca2fb97da30 100644 --- a/src/makielayout/blocks/colorbar.jl +++ b/src/makielayout/blocks/colorbar.jl @@ -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