I was wondering if anyone had some guidance or thoughts on how to approach composing visualizations together. Right now I’m working with some SVG based d3 visualizations, and was hoping to find a sensible way to “export” individual visualizations from their own notebooks, and combine them together in a new cell in a new notebook.
For example, I’d love to take something like the angle
cell from here https://beta.observablehq.com/@digitaltopo/angle and combine it with another visualization, like a unit circle, or a Cartesian grid https://beta.observablehq.com/@digitaltopo/cartesian-grid.
Here’s the approach I’ve tried so far:
Using these two “visualization components”:
Composed: https://beta.observablehq.com/@digitaltopo/composed-viz
The approach is basically:
- In the individual components, check to see if there is a
canvas
passed in. If not, then we’ll create and draw to a new canvas, so that the component can be used in a stand-alone way. - In the
composedViz
create a canvas and pass it to the individual components.
Note: Yes the grid and angles aren’t scaled together properly in the examples, but hopefully you get the idea of what we’re trying to do.
I’d probably also leverage viewof
for the individual components so we can read values out of them as well.
In the composed visualization, I wasn’t expecting the standAloneAnge
and the angle in composedViz
to be linked… how is this happening anyway? Is the DOM.svg
shared across cells?
Wondering what others thoughts’ are on this. Thank you!