VegaLite.jl
VegaLite.jl copied to clipboard
@vlmod
I'm wondering whether we should add a more powerful modification API, something like the existing Setfield.jl story, but with more options.
The background for this is that I want to add something like QuickVega.jl or SimpleVega.jl or something like that, which has functions like scatter(x,y)
that return VLSpec
objects. Ideally we would not provide many options in these functions at all, but provide users a way to start with such a plot, and then use a powerful API that allows them to manipulate such a starting template like plot.
Here are some ideas how this might look in the end, with some random comments about complications:
df |> scatter(:x, :y) |> @vlmod(x.title="New title", y.title="Something else")
this shows how @vlmod
needs to make the same adjustments that we make in @vlplot
, for example move x
into the encoding
spec, i.e. make this equivalent to @vlmod(encoding.x.title="New title", encoding.y.title="Something else")
. It also shows how this could work with piping, and how multiple things could be modified in one go.
df |> scatter(:x, :y) |> @vlmod(color=:z)
this could show how we need to make this equivalent to @vlmod(encoding.color = {field=:z}
.
df |> scatter(:x, :y) |> @vlmod(x += {title="nothing", axis=nothing})
This could mean "add the fields title
and axis
to x
(or rather encoding.x
), and leave any existing fields in the x
structure there.
df |> scatter(:x, :y) |> @vlmod(-y)
could mean "remove element y
".
I think ideally we would use the Setfield.jl machinery under the hood for all of this. I haven't thought much about this, so there might be some really silly ideas in here :) @tkf, as always, any thoughts would be much appreciated!
@vlmod
sounds like useful outside VegaLite (it's implementable just by using Setfield). But I guess you'd want to implement @vlplot
-like shortcuts (e.g., scatter(:x, :y) |> @vlmod(y=:z)
).
Alternative API may be df |> scatter(:x, :y) ∪ @vlplot(x={title="New title"}, y={title="Something else"})
with ∪ = merge
for VLSpec
defined appropriately.
df |> scatter(:x, :y) |> @vlmod(-y)
could mean "remove element y".
How about supporting @set spec.y = undef
so that you automatically get @vlmod(y = undef)
?
I have been creating a package to plot power grid data (vegalite has been pretty powerful for hover, multiple legends, etc.), and this feature would make it very easy for a user to change a legend title or color range for these custom plots, just like the QuickVega
idea
I am curious how this will work with layered plots.