Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to use a circle pack layout in d3.js with fixed circle sizes?

This circle pack layout example (http://bl.ocks.org/4063269) is perfect for a project I'm working on, however it sizes all the circles relative to one another:

enter image description here

Is there a simple way to specify fixed radii for each circle?

I've scoured the source code, examples, google, and stackoverflow and can't seem to find anything helpful.

The exact sizing of circles is important to me.

like image 807
user2058412 Avatar asked Feb 10 '13 08:02

user2058412


1 Answers

It is possible, and simple thing to do. The first answer is accurate, but I believe mine is simpler, more explicit, so I am attaching it too.

Please take a look at this example: jsfiddle

When you press "Constant" button, you will see something like this:

enter image description here

The key code line is this:

    pack.value(function(d) { return 100; })

This will make circle radiuses constant regardles of data. 100 can be any constant of course. You can apply this line in circle pack initialization (most likely this will be your case), or reinitialization (like in my example).

Hope this helps.

like image 97
VividD Avatar answered Dec 29 '22 02:12

VividD