Published
Edited
Oct 3, 2020
Insert cell
md`# Circle Spiro`
Insert cell
Insert cell
svg = {
let height = 600;
const svg = DOM.svg(width,height);
let centerX = width/2;
let centerY = height/2;
let circleCount = circleCountSlider;
let radius = 100;
let circleArray = [];
for (let i=0; i < circleCount; i++) {
circleArray[i] = (360/circleCount)*i;
}
d3.select(svg).selectAll("circle")
.data(circleArray)
.enter()
.append("circle")
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1)
.attr("r",radius)
.attr("cx", d => centerX + Math.sin(toRadians(d)) * radius)
.attr("cy",function (d,i) {
if (i < circleCount/2) {
return (centerY - radius) + Math.cos(toRadians(d)) * radius;
} else {
return (centerY + radius) - Math.cos(toRadians(d)) * radius;
}
})
// .attr("cy",(d,i) => radius + i*4);
return svg;
}
Insert cell
toRadians = function(angle) {
return angle * (Math.PI / 180);
}
Insert cell
d3 = require("d3@5")
Insert cell
import {slider} from "@jashkenas/inputs"
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