Public
Edited
Feb 25, 2023
5 stars
Insert cell
Insert cell
Insert cell
svg1 = {
let svg = d3
.create('svg')
.attr('width', size)
.attr('height', size);
svg
.append('g')
.append('circle')
.attr('cx', `${size / 2}`)
.attr('cy', `${size / 2}`)
.attr('r', `${size / 4}`)
.attr('fill', '#aaa')
.attr('stroke', '#000');

return svg.node();
}
Insert cell
Insert cell
svg2 = {
let svg = d3.create("svg").attr("width", size).attr("height", size);

svg
.append("line")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", size)
.attr("y2", size)
.attr("stroke", "#000");

// Here, we select svg1, then select the circle.
// We also clone the circle since it can only be
// produced once in the DOM.
let other = d3.select(svg1);
let circle = other.select("g").clone(true);
svg.append(() => circle.node());

svg
.append("line")
.attr("x1", 0)
.attr("y1", size)
.attr("x2", size)
.attr("y2", 0)
.attr("stroke", "#000");

return svg.node();
}
Insert cell
Insert cell
svg3 = {
let svg = d3
.create('svg')
.attr('width', size)
.attr('height', size);

svg
.append('line')
.attr('x1', 0)
.attr('y1', 0)
.attr('x2', size)
.attr('y2', size)
.attr('stroke', '#000');

let other = d3.select(svg1).clone(true);
svg.append(() => other.node());

svg
.append('line')
.attr('x1', 0)
.attr('y1', size)
.attr('x2', size)
.attr('y2', 0)
.attr('stroke', '#000');

return svg.node();
}
Insert cell
size = 400
Insert cell
d3 = require('d3@6')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more