From 24caac7e52d9907288c57bc9c67e6d527505d5bb Mon Sep 17 00:00:00 2001 From: Frederic Freyer Date: Thu, 19 Dec 2024 14:12:12 +0100 Subject: [PATCH] Colorbar compat for compute (#4684) add Colorbar glue code --- src/compute-plots.jl | 31 ++++++++++++++++++++++++++++++ src/makielayout/blocks/colorbar.jl | 1 + 2 files changed, 32 insertions(+) diff --git a/src/compute-plots.jl b/src/compute-plots.jl index 55023a75f6a..357d86c8a80 100644 --- a/src/compute-plots.jl +++ b/src/compute-plots.jl @@ -476,3 +476,34 @@ end function ComputePipeline.update!(plot::ComputePlots; args...) return ComputePipeline.update!(plot.args[1]; args...) end + + +get_colormapping(plot::Plot) = get_colormapping(plot.args[1]) +function get_colormapping(attr::ComputePipeline.ComputeGraph) + # None of these are needed by the computation + register_computation!(attr, Symbol[], [:cb_colormapping]) do args, changed, cached + N = ndims(attr[:color][]) + Cin = typeof(attr[:color][]) + Cout = typeof(attr[:scaled_color][]) + if isnothing(cached) + cm = ColorMapping{N,Cin,Cout}( + map(_ -> attr[:color][], attr.onchange), # input color (typed) + map(_ -> attr[:alpha_colormap][], attr.onchange), # converted + alpha + map(_ -> attr[:raw_colormap][], attr.onchange), # _converted + alpha + map(_ -> attr[:colorscale][], attr.onchange), # typed as Function + map(_ -> attr[:color_mapping][], attr.onchange), # typed as Function + map(_ -> attr[:_colorrange][], attr.onchange), # unscaled but not automatic + map(_ -> attr[:lowclip][], attr.onchange), # automatic NOT replaced + map(_ -> attr[:highclip][], attr.onchange), # automatic NOT replaced + map(_ -> attr[:nan_color][], attr.onchange), # after color convert + map(_ -> colormapping_type(attr[:colormap][]), attr.onchange), + map(_ -> attr[:scaled_colorrange][], attr.onchange), # fully processed + map(_ -> attr[:scaled_color][], attr.onchange), # fully processed + ) + return (cm,) + else + return (cached[],) + end + end + return attr[:cb_colormapping][] +end \ No newline at end of file diff --git a/src/makielayout/blocks/colorbar.jl b/src/makielayout/blocks/colorbar.jl index b458e3c1d01..2132e23a48d 100644 --- a/src/makielayout/blocks/colorbar.jl +++ b/src/makielayout/blocks/colorbar.jl @@ -33,6 +33,7 @@ function extract_colormap(@nospecialize(plot::AbstractPlot)) return nothing end end +extract_colormap(@nospecialize(plot::ComputePlots)) = get_colormapping(plot)::ColorMapping function extract_colormap(plot::Union{Arrows, StreamPlot}) return extract_colormap(plot.plots[1])