{
const svg= DOM.svg();
svg.setAttribute("viewBox","-80 -50 700 3300");
const ratingMinMax = d3.extent(data, d => +d.imdbRating);
const votesMinMax = d3.extent(data, d => +d.imdbVotes.replace(',', ''));
const runtimeMinMax = d3.extent(data, d=> +d.Runtime.match(/(\d+)/)[0]);
const sizeScale = d3.scaleLinear().domain(ratingMinMax).range([0.25, 1]);
const numPetalScale = d3.scaleQuantize().domain(votesMinMax).range([3,6,9,12,15,18,21]);
const ratedPetal =d3.scaleOrdinal().domain(["G","PG", "PG-13", "R" ]).range([petalPath, petalPath2, petalPath3, petalPath4])
const lineScale =d3.scaleLinear().domain(runtimeMinMax).range([0.25,3])
const colorScale =d3.scaleOrdinal().domain(["Drama", "Comedy", "Adventure", "Action", "Other"]).range(['red', 'green', 'blue', 'pink', 'yellow'])
const flowersData = _.map(data, d => {
const numPetals = numPetalScale(+d.imdbVotes.replace(',',''));
const petSize = sizeScale(+d.imdbRating);
const petalType = ratedPetal(d.Rated);
const lineThickness = lineScale(+d.Runtime.match(/(\d+)/)[0]);
const genreColor = colorScale(d.Genre.replace(" ","").replace(" ","").split(","))
const label = d.Title;
const genre = d.Genre;
console.log(genreColor);
return {
petSize,
petals: _.times(numPetals, i => {return {angle: 360 * i / numPetals, petalType}}),
numPetals,
label,
genre,
lineThickness,
genreColor,
}
});
console.log(flowersData)
const flowers = d3.select(svg)
.selectAll('g')
.data(flowersData)
.enter()
.append('g')
.attr('transform', (d, i) =>
`translate(${(i % 5) * petalSizeMulti}, ${Math.floor(i / 5) * petalSizeMulti})scale(${d.petSize})`)
.attr("stroke-width",function(d) { return (d.lineThickness); })
.style("isolation", "isolate");
flowers.selectAll('path')
.data(d => d.petals).enter().append('path')
.attr('d', d => d.petalType)
.attr('transform', d=> `rotate(${d.angle})` )
.style('stroke', 'black')
.attr('fill', 'none')
.attr('opacity', '0.85');
flowers.append("text")
.attr("x", 0)
.attr("y", d => Math.floor(60/d.petSize))
.attr('font-size', d => 8/ d.petSize)
.attr('text-anchor', 'middle')
.text(function(d) { return d.label; });
return svg;
}