{
const margin = ({top: 20, right: 30, bottom: 30, left: 40});
const innerWidth = width - (margin.left + margin.right);
const height = innerWidth + (margin.top + margin.bottom);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.append("rect")
.attr("width", innerWidth)
.attr("height", innerWidth)
.attr("fill", "none")
.attr("stroke", "red");
svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.append("circle")
.attr("cx", (innerWidth)/2)
.attr("cy", (innerWidth)/2)
.attr("r", innerWidth/2)
.attr("fill", "none")
.attr("stroke", "red");
svg.append("g")
.attr("transform", `translate(${margin.left+innerWidth}, ${margin.top+innerWidth})`)
.append("text")
.attr('x', 0)
.attr('y', 0)
.attr('stroke', 'green')
.style("font-size", 19)
.attr("text-anchor", "end")
.attr("dy", "16")
.text("I'm another piece of text");
const x = d3.scaleLinear()
.domain(d3.extent(data, d => d.x)).nice()
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain(d3.extent(data, d => d.y)).nice()
.range([height - margin.bottom, margin.top]);
svg.append("g")
.attr("transform", `translate(${0}, ${margin.top+(height-margin.top-margin.bottom)/2})`)
.call(d3.axisBottom(x))
.call(g => g.append("text")
.attr("x", width - margin.right)
.attr("y", -4)
.attr("fill", "#000")
.attr("font-weight", "bold")
.attr("text-anchor", "end")
.text(data.x));
svg.append("g")
.attr("transform", `translate(${margin.left+(width-margin.left-margin.right)/2}, 0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 4)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y));
return svg.node();
}