What is the recommend way of cloning within Notebook?

After creating a chart, I want to clone a copy of the chart, with different variable. So far, I have manage to succeed with:

{
const clone = chart.cloneNode(true)
yield clone

d3.select(clone)
.selectAll(“rect”)
.style(“fill”, “orange”)
}

example notebook: Cloning a Chart / muyueh | Observable

But I was wondering if there is a better way to this.

One thing you can do is make the creation of the chart a function in a different cell which returns your SVG node instead of making the cell return it directly. Then just call the function from two different cells.

3 Likes

Thank you! I just updated the notebook with your suggestion.