Published
Edited
Oct 17, 2021
2 forks
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
createPoppy = () => {
const petalPath = createPetalPath();
const petalColor = getPetalColor(petalColorValue);
const petalRotationSpeed = getRotationSpeed(rotationSpeed);
const petalEasing = getEasing(easing);
const petals = Array(petalCount)
.fill()
.map((_, i) => ({
angle: (360 * i) / petalCount,
petalSize: getPetalSize(petalSize),
petalPath,
petalColor,
petalRotationSpeed,
petalEasing
}));
return petals;
}
Insert cell
createPetalPath = () => {
const start = 0;
return [
'M',
`${start} ${start}`,
'C',
`-${curveX} -${curveY}`,
`-${curveX} -${cornerY}`,
`0 -${tipY}`,
'C',
`${curveX} -${cornerY}`,
`${curveX} -${curveY}`,
`${start} ${start}`
].join(' ');
}
Insert cell
getEasing = value => {
const crosswalk = {
linear: d3.easeLinear,
cubic: d3.easeCubic,
elastic: d3.easeElasticIn,
exponential: d3.easeExp
};
return crosswalk[value];
}
Insert cell
getRotationSpeed = value => {
const scale = d3.scaleLinear().range([1000, 3000]);
return scale(1 - value);
}
Insert cell
getPetalSize = value => {
const scale = d3.scaleLinear().range([2.5, 6.5]);
return scale(value);
}
Insert cell
getPetalColor = value => {
if (scheme == 'yellow-orange') {
const scale = d3.scaleLinear().range([0.4, 0.6]);
return d3.interpolateYlOrBr(scale(value));
} else if (scheme == 'red-yellow') {
const scale = d3.scaleLinear().range([0.2, 0.3]);
return d3.interpolateRdYlGn(scale(value));
} else if (scheme == 'purple') {
const scale = d3.scaleLinear().range([0.6, 0.7]);
return d3.interpolatePurples(scale(value));
}
}
Insert cell
petalRotation = angle => d3.transform().rotate(angle)
Insert cell
Insert cell
Insert cell
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