vega icon indicating copy to clipboard operation
vega copied to clipboard

feat: Reference spec source in DataFlow nodes

Open danmarshall opened this issue 4 years ago • 1 comments

This PR adds a new property src to DataFlow nodes. This references the specification property which spawned each node. It is helpful to be able to map the scenegraph item to the specification.

Scenario: I have a custom Vega renderer which traverses the scenegraph and renders in WebGL. I am using Vega axes. I want one of these axes rendered in a 3D plane instead of 2D.

Example: In my spec for the axes, I add a new attribute plane:

"axes": [
        { "orient": "bottom", "scale": "x", "title": "X Axis"},
        { "orient": "left", "scale": "y", "title": "Y Axis" },
        { "orient": "left", "scale": "z", "title": "Z Axis", "plane": "z" },
    ],

During the scenegraph render pass, I can get to the mark node generated by the DataFlow, and via the src property I can get to this axis object from the spec and get the plane attribute.

This may also enable other scenarios, such as animation attributes etc.

danmarshall avatar Apr 10 '21 04:04 danmarshall

Thanks for the PR, and apologies for the delayed review. I'm a bit skeptical of annotating the runtime with specification source: this violates a "separation of concerns" across levels of abstraction and will also add bloat to the runtime.

That said, supporting extensibility (e.g., to new renderers) is a nice goal. Vega already supports this to some degree: any arbitrary encoding property can be defined and will be passed through as a property written to scenegraph items. This applies to axes and legends as well, but in those cases requires using a custom encoding block. For example, you could write custom properties to the axis group mark and have your custom renderer respond to those.

jheer avatar Sep 21 '21 16:09 jheer