The thing initially really slowed down even at some low recursion level like four or five. If each level has, say 100 children, then the first level has 100 nodes, second 100 * 100, third 100 * 100 * 100, and so on. That is very steep exponential curve, which I solved by measuring a radius of each node. If the radius is less than 2.5 pixels, I don't enter the recursion, and things get fast enough to get a static image.
Calculating positions and radiuses was a tricky thing. I tried to make it mathematically correct, but when I entered a system of equations to Wolfram Alpha, I got two pages long solutions. I also tried an option of making inner and outer circles concentric, drawing child circles each with the same smaller fit radius, then 3D rotating the whole thing, so the near circles get big, and far ones small. This was also unacceptable, as there was a big focus distorsion of coordinates on very near circles.
I finally settled down with binary search of x, y and r. First I set bounds on minimum and maximum coordinates and radius, then I check if circles intersect, and that is a case when:
- the distance between centers is less than the sum of radiuses - for one circle next to another
- absolute value of radius difference is less than the distance between centers - for one circle inside another
If there is an intersect, I half the position and radius in one direction. If there is no intersect, I half the position and radius in the other direction. After some 16 steps for each circle (I actually measure a pixel precision to stop the binary search), I get coordinates and radius precise enough to draw it without noticing an error in approximation. Surprisingly, this is a very fast method, probably faster than getting mathematically correct model because each calculation step is very simple.
More or less I'm done with the static part (the posted image is actual browser screenshot), but I still have to make it responsible to mouse drags and clicks. Also, each node will probably have a user defined HTML to draw it at certain magnification level (I still have to check the speed of this perversion).
Then It probably goes to Github, but I'll give it another thought after it's finished.
[Edit] I attached another screenshot...