Handling color in Plots user recipe that produces an image, or indexed color

I have a Grid type, and I have a way to plot it in terms of an image (Array{RBGA{...}, 2}), so I define the following user recipe:

using Plots
using Plots: RGBA
using RecipesBase
using OffsetArrays

struct Grid
    x::OffsetArray{Bool, 2, Array{Bool, 2}}
end

@recipe function f(s::Grid)
    # TODO use :seriescolor and :seriesalpha in plotattributes
    full = RGBA(0.0, 0.0, 1.0, 0.5)
    empty = RGBA(0.0, 0.0, 0.0, 0.0)
    axs = axes(s.x)
    f = first.(axs) .- 0.5
    l = last.(axs) .+ 0.5
    _range(start, step, stop) = start:step:stop
    extents = map(_range, f, [1.0, 1.0], l)
    (d1, d2) = extents
    d1, d2, ifelse.(transpose(s.x.parent), full, empty)
end

a = fill(false, (-5:5, 0:10))
a[:] .= rand(Bool, 11, 11)[:]
plot(Grid(a))

which produces

image

What’s a good way to handle e.g. plot(Grid(a), color=:red, alpha=0.2) (which would correspond to full = RGBA(1.0, 0.0, 1.0, 0.2)) ? I imagine roughly two strategies:

  1. handle the conversion to RGBA in my recipe
  2. find some plot type that would handle that conversion for me

The conversion I spoke of is done by:

and e.g.

It’s probably against the spirit of a user recipe to do this conversion in the recipe.

I’ve opened a feature request: [FR] indexed image with `:auto` color · Issue #3448 · JuliaPlots/Plots.jl · GitHub