Hi Jo,
I had seen the elm-vega package - it looks like you had as much fun deciphering the intent of the vega specification as me!
One of the reasons I started this project was to see what barriers I would run into when trying to build something like vega / ggplot / gadfly in a statically typed language and have it deeply embedded i.e. using the host languages type system rather than a DSL.
At some points, early on, I was convinced I would need more complex type machinery but I managed to express most of what I needed with Elm’s type system. Row polymorphism turned out to be a great help with the library both internally and when defining a plot.
I haven’t solved everything yet - It’s not immediately clear to me how I would extend to some of the other composition primitives vega has introduced (like ‘concatenation’) and whether it is even desirable to do so.
I have nascent versions of Facet in both F# and ReasonML and each type systems has advantages and disadvantages - polymorphic variants (which are described halfway through this page https://realworldocaml.org/v1/en/html/variants.html) in ReasonML have been the biggest eye opener and something I would love to have in other languages.
The take away was that it can be a little tricky to do what is needed in a static type system but the consequence is that adhering to some visualization best-practices (e.g. a single scale for a plot) became pretty much unavoidable.
As you may have noticed, the Scenegraph defined in the facet-scenegraph-alpha package is very similar to the vega scenegraph. If you can define your visualization in terms of a scenegraph then rendering is fairly straightforward since all the measurement is assumed to have been done by this point.
The main challenge for me was generating the scenegraph from the plot specification - this was the part the library that took the most time and still isn’t completely right. In particular, measuring axis labels has proved to be problematic when I have an axis with a continuous scale but the user hasn’t explicitly set the domain (i.e. I don’t know what the labels are yet!).
I would be interested if you have any insight as to how vega approaches this?
Cheers,
Michael