I found the documentation of symbol size misleading, in particular for the circle. The documentation describes the size parameter as "The area in pixels of the symbols bounding box. Note that this value sets the area of the symbol; the side lengths will increase with the square root of this value.".
In the force-directed-layout example, the node size is set like this:
{
"size": {"signal": "2 * nodeRadius * nodeRadius"}
}
Yet, in the source code which renders the circle symbol, there is this
'circle': {
draw: function(context, size) {
var r = Math.sqrt(size) / 2;
context.moveTo(r, 0);
context.arc(0, 0, r, 0, Tau);
}
},
Substituting the calculation of the node size in the example using nodeRadius for size in the calculation of the variable r used to draw the circle gives:
r = Math.sqrt(2nodeRadiusnodeRadius)/2
r = Math.sqrt(2)/2*nodeRadius
I had a use case where I had to determine the outside edge of the circle. It took me a long time to realize that I needed to use 4*nodeRadius*nodeRadius to be able to use the nodeRadius in my calculations properly.
- I don't understand why
PI isn't used instead of 4 (inferred from the code) since that is the actual formula for the area of a circle.
- The force-directed-layout example's use of
size for the circle symbol is misleading.
I found the documentation of symbol size misleading, in particular for the
circle. The documentation describes the size parameter as "The area in pixels of the symbols bounding box. Note that this value sets the area of the symbol; the side lengths will increase with the square root of this value.".In the force-directed-layout example, the node size is set like this:
Yet, in the source code which renders the
circlesymbol, there is thisSubstituting the calculation of the node size in the example using
nodeRadiusfor size in the calculation of the variablerused to draw the circle gives:r = Math.sqrt(2nodeRadiusnodeRadius)/2
r = Math.sqrt(2)/2*nodeRadius
I had a use case where I had to determine the outside edge of the circle. It took me a long time to realize that I needed to use
4*nodeRadius*nodeRadiusto be able to use thenodeRadiusin my calculations properly.PIisn't used instead of 4 (inferred from the code) since that is the actual formula for the area of a circle.sizefor the circle symbol is misleading.