Public
Edited
Mar 10, 2021
2 stars
Insert cell
md`# Colored moons`
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

for (
var smallMultiple = 0;
smallMultiple < multiples * multiples;
smallMultiple++
) {
var smGroup = svg.append("g").attr(
"transform",
`translate(
${((smallMultiple % multiples) * width) / multiples},
-${(Math.floor(smallMultiple / multiples) * height) / multiples}
)`
);

smGroup
.selectAll("circle")
.data([5])
.join("circle")
.attr("transform", d => `translate(${x(d)},${y(d * 2)})`)
.attr("fill", d3.schemePastel2[Math.floor(d3.randomUniform(0, 8)())])
.attr("fill-opacity", 0.66)
.attr("stroke-width", 0)
.attr('cx', d3.randomUniform(0.6, 2)() * 30)
.attr('cy', d3.randomUniform(1, 2)() * 20)
.attr('r', d3.randomUniform(0.6, 3)() * 20);

smGroup
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 2)
.selectAll("path")
.data([5])
.join("path")
.attr("transform", d => `translate(${x(d)},${y(d * 2)})`)
.attr("d", d => curve(width / multiples / 4, 50));
}

return svg.node();
}
Insert cell
curve = (width, height) => `M0 0
C${d3.randomUniform(0,3)()*width/5} ${d3.randomUniform(0,1.5)()*height},
${width - d3.randomUniform(0,3)()*width/5}
${d3.randomUniform(0,3)()*height}, ${d3.randomUniform(0,2.5)()*width} 0`
Insert cell
margin = ({top: 60, right: 30, bottom: 20, left: 20})
Insert cell
datard = d3.range(1,10,1)
Insert cell
Insert cell
multiples = 5
Insert cell
area = d3.area()
.curve(curve)
.x(d => x(d[0]) / multiples)
.y0(y(0))
.y1(d => y(d[1] / multiples))
Insert cell
y = d3.scaleLinear()
.domain([0,100])
.range([height - margin.bottom, margin.top])
Insert cell
x = d3.scaleLinear()
.domain([0, 100])
.range([margin.left, width - margin.right])
Insert cell
height = 720
Insert cell
d3 = require("d3@6")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more