error importing @d3/radial-tidy-tree

I ran into trouble trying to import the @d3/radial-tidy-tree notebook yesterday when trying to visualize my Advent ofCode input. Here’s a minimal repro:

I think something strange is happening here due to the yield at the end of the chart cell but I haven’t been able to figure it out.

Good find! This has to do with the order of execution in the runtime.

Currently, when a generator cell yields, it may resume before other variables that reference the cell have a chance to run. Hence in your notebook, the autoBox function is called before the chart is inserted into the DOM and the computed viewBox is [0, 0, 0, 0].

I’ve opened a pull request that defers the resumption of generators until after all active variables have a chance to start computing.

I’ll need to do more testing, but I believe this will fix the problem here and give more predictable behavior to yield.

In the meantime you can workaround this issue by calling autoBox again:

chart.setAttribute("viewBox", autoBox.call(chart)), chart
1 Like