Public
Edited
Nov 25, 2023
Fork of Simple D3
Insert cell
Insert cell
{
const id = 0
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
svg
.selectAll("circle")
.data(d3.range(total))
.join("circle")
.attr("cx", d => width/2 + Math.cos(d/total*Math.PI*2 * factors(d).length) * width/2 / factors(d).length )
.attr("cy", d => height/2 + Math.sin(d/total*Math.PI*2 * factors(d).length) * height/2 / factors(d).length )
.attr("r", d => 1*4)// Math.sin(d / Math.PI)*Math.sin(d / Math.PI )*2)
.attr("fill", 'hsl( 23deg 100% 13%)')
return svg.node()
}
Insert cell
height = width
Insert cell
total = 100
Insert cell
function primes(n) {
return d3.range(n).filter(isPrime);
}
Insert cell
function isPrime(n) {
if (2 > n) return false;
if (0 === n % 2) return 2 === n;
for (var index = 3; n / index >= index; index += 2) {
if (0 === n % index) return false;
}
return true;
}

Insert cell

function factors(n) {
var result = [];
for (var i = 1; i <= n / 2; i++) {
if (n % i === 0) result.push(i);
}
//if (n) result.push(n);
return result;
}
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