New Vega config abstraction

Nate Agrin · Friday Demos · December 20, 2024 · 7:09

Some behind-the-scenes work to allow better composability as we create Vega specs for our visualizations. Outcome would be better feature development velocity for vis.

Transcript

This transcript is auto-generated. Names and product terms may be wrong.

  1. so veal lights based on this idea of like a static scheme or static config that you pass into it looks something like this uh generating this is obviously complicated um and it's very particular and so like writing code to generate these things can become pretty unwieldy pretty quickly um there's this Library that's kind of been sitting a little bit in the background uh that Vega like the folks behind Vega and Vega light uh they published this a couple years ago um but basically it allows you to have a programmatic API to generating these complicated configs so this pretty nice um it just basically means that you can generate these configs in a less error prone way um and so my demo which is almost a

  2. non-d demo is like if I start clicking around here you see we get charts kind of charts that we would expect to get today uh the big difference here is this is all running through it's a branch on my local that's running through this Library instead of the code that we've had and uh the goal here is to continue building on this in order to support things like uh you know Common requests where we have like data labels on multiple measures um or the ability to add trellising relatively quickly things like that or the ability to like tweak the density of our labels because they can often uh sort of olude each other so yeah this all runs through this this new code path using

  3. this Library um one really cool thing is the way I've built it is as soon it does feature detection so as soon as it detects a config that it's not compatible with it drops back to uh using the code we have in place so it gives us a nice Progressive way to roll it out so for example this two measures it knows it doesn't support and so seamlessly just drops back to the old code path so we can roll this stuff out you know over time and to give you quick question is is the idea that uh like users would still be able to touch the Vega config that spits out or is this is this new sort of intermediate the thing that people would

  4. touch like what's your thought there yeah so um at the end of the day it is just generating a Vega config uh so we should be able to open it here and uh not totally sure why it just fell back to the old one um but we'll definitely like you'll definitely still be able to interact with the Vega config and the advanced editor if that's what you want to do I think there is a compelling you know potential use case for supporting this syntax um yeah just because it is a lot clearer and easier to work with um yeah there are some technical reasons why it was difficult to get this working in our infrastructure uh so part of the work I've been doing is

  5. basically making our infrastructure compatible with this Library uh specifically like the library doesn't support typescript right now so I do some work to make that happen um yeah I guess this is a good reminder that like this branch is very Alpha it's not going into production in probably the next week or two um hoping in you know within three to four weeks like it'll be out there and silently running in the background um and the last thing I just want to demonstrate is uh the like what this code looks like so basically the way it works is we're using this Library called Zod under the hood Zod lets you define um schemas for for like different data structures in your application and we use this

  6. all over the place to deal with like data that we're sending back and forth between uh like the browser and the server things like that in this case what I'm actually trying to do is I'm trying to parse the config we store for a visualization in our database and then uh have a declarative way of saying like we accept the the config that you're sending us and it can use the new code pathway or you know that config has some feature like data labels that we don't currently support so like for example here you can see this set of unsupported features and um Zod will parse the config and tell us like okay it's compatible or not and then we can run you know we

  7. can run forward and and choose which code about to to go down um and then the other really cool thing about Zod is not only is it a parsing library but it also has a fances for doing Transformations so we can take our relatively complicated uh config that we store internally and reduce it down to a very small tractable config that this new code pathway can uh can operate on so for example like we know that we want to support like a color Channel and like an X Channel and these things Vega needs a field in the data to map them to so we know we need to have a field property um another good example is like for calculating titles we kind of we

  8. pull data from different parts of our config um and so this just brings that fairly complicated calculation like higher up into the code so it only has to happen in one place uh so this thing spits out basically a new object and then the code that actually generates these charts um if I go back uh it's literally right now it's 50 lines of code um so huge reduction in surface area internally um this is currently handling the basic XY cases along with uh XY color stacking cases um so obviously I expect this like numbers of lines of code here to grow but I I won't be surprised if it's like an order of magnitude fewer lines than we currently have just basically means it's going

  9. to be a lot easier to support long term also going to be a lot easier to add new features long term so um I know there's been a huge amount of appetite for viz features I I see them every week um and just throwing this out there as like a heads up that it's coming so