I’m playing a bit with D3.js and I got most things working. But I want to place my svg shapes in a circle. So I will show the difference in data with color and text. I know how to draw circles and pie charts, but I want to basically have a circle of same size circles. And not have them overlap, the order is irrelevant. I don’t know where to start, to find out the x & y for each circle.
Share
Here’s another approach to this, for shapes of arbitrary size, using D3’s
treelayout: http://jsfiddle.net/nrabinowitz/5CfGG/The
treelayout (docs, example) will figure out the x,y placement of each item for you, based on a given radius and a function returning the separation between the centers of any two items. In this example, I used circles of varying sizes, so the separation between them is a function of their radii:Using the D3
treelayout solves the first problem, laying out the items in a circle. The second problem, as @Markus notes, is how to calculate the right radius for the circle. I’ve taken a slightly rough approach here, for the sake of expediency: I estimate the circumference of the circle as the sum of the diameters of the various items, with a given padding in between, then calculate radius from the circumference:The circumference here isn’t exact, and this will be less and less accurate the fewer items you have in the circle, but it’s close enough for this purpose.