Skip to content

Commit

Permalink
Colorbar compat for compute (#4684)
Browse files Browse the repository at this point in the history
add Colorbar glue code
  • Loading branch information
ffreyer authored Dec 19, 2024
1 parent 3cc755c commit 24caac7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/compute-plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/makielayout/blocks/colorbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 24caac7

Please sign in to comment.