{
const svg = DOM.svg(petalSize * 20, petalSize * 44);
const ratingMinMax = d3.extent(data, (d) => +d.imdbRating);
const votesMinMax = d3.extent(data, (d) => +d.imdbVotes.replace(",", ""));
const sizeScale = d3.scaleLinear().domain(ratingMinMax).range([0.25, 1]);
const petalScale = d3
.scaleQuantize()
.domain(votesMinMax)
.range([3, 6, 9, 12, 15, 18]);
const d = data[34];
const flowerData = _.map(data, (d) => {
const numPetals = petalScale(+d.imdbVotes.replace(",", ""));
const petSize = sizeScale(+d.imdbRating);
return {
petSize,
petals: _.times(numPetals, (i) => {
return { angle: (360 * i) / numPetals, petalPath };
}),
numPetals,
name: d.Title
};
});
const flowers = d3
.select(svg)
.selectAll("g")
.data(flowerData)
.enter()
.append("g")
.attr(
"transform",
(d, i) =>
`translate(${(i % 5) * (petalSize + 30) + 50},${
Math.floor(i / 5) * (petalSize + 30) + 50
})scale(${d.petSize})`
);
flowers
.append("svg:title")
.data(flowerData)
.text((d) => d.name);
flowers
.selectAll("path")
.data((d) => d.petals)
.enter()
.append("path")
.attr("d", (d) => d.petalPath)
.attr("transform", (d) => `rotate(${d.angle})`)
.attr("fill", (d, i) => d3.interpolateRainbow(d.angle / 360));
return svg;
}