MakieOrg / AlgebraOfGraphics.jl

Combine ingredients for a plot
https://aog.makie.org
MIT License
421 stars 44 forks source link

Neutral additive element #437

Open jonas-schulze opened 1 year ago

jonas-schulze commented 1 year ago

Problem description

I would like to have an optional layer in the background, to which I then add some other layers on top. The manual states that mapping() is the one-element, but what is the zero-element here?

if draw_background
    plt = ...
else
    plt = zero(Layer) # doesn't exist (yet)
end
plt += ...

Proposed solution

Define zero(Layer) or AoG.zero() or similar. While being at it, one may also define one(Layer) or oneunit(Layer) or AoG.one() or similar.

jkrumbiegel commented 3 weeks ago

I think what you want is Layers([]):

julia> Layers([]) + mapping(:x, :y)
Layers with 1 elements:
  Layer 1
    transformation: identity
    data: Nothing
    positional:
      1: x
      2: y
    named:

julia> Layers([]) * mapping(:x, :y)
Layers with 0 elements:
jonas-schulze commented 3 weeks ago

Yes, that's the behavior I was looking for! But Layers([]) doesn't feel intuitive to me (I don't remember interacting with it before), I will likely forget about it again. What do you think about giving the other names I suggested?