Thanks. I looked at the code, hacked out the irrelevant stuff and produced this:
Code: Select all
package nodesizegephi;
import java.util.ArrayList;
import java.util.List;
public class NodeSizeGephi
{
private static float sizeMinimum, sizeMaximum;
private static void setDefaults() {
sizeMaximum = 100f;
sizeMinimum = 4f;
}
public static void main(String[] args)
{
setDefaults();
//... Inject my two nodes
List<Node> nodes = new ArrayList<>();
nodes.add(new Node(20.0f));
nodes.add(new Node(21.0f));
float sizeMin = Float.POSITIVE_INFINITY;
float sizeMax = Float.NEGATIVE_INFINITY;
float sizeRatio = 0f;
//Measure
for( Node node : nodes )
{
sizeMin = Math.min(node.getSize(), sizeMin);
sizeMax = Math.max(node.getSize(), sizeMax);
}
if (sizeMin != 0 && sizeMax != 0)
{
if (sizeMin == sizeMax) {
sizeRatio = sizeMinimum / sizeMin;
} else {
sizeRatio = (sizeMaximum - sizeMinimum) / (sizeMax - sizeMin);
}
//Scale node size
for( Node node : nodes )
{
float size = (node.getSize() - sizeMin) * sizeRatio + sizeMinimum;
node.setSize(size);
}
}
nodes.forEach((node)->System.out.println("Node size: " +node.getSize()));
}
}
class Node
{
private float size;
public Node(float size)
{
this.size = size;
}
public float getSize() {
return size;
}
public void setSize(float size) {
this.size = size;
}
}
Running this I get returned:
Node size: 4.0
Node size: 100.0
Which are the max and min sizes. The centroid stuff in the original code will not change things I believe as nodeSize will only be 1 (with two nodes). So my node sizes, originally marginally different become wildly altered.
Seeing this, I tried with a GEXF with just one node (size 21.0) to see what would happen (nodeSize would be zero).
:
<node id="3" label="NodeSize:21.0">
<viz:color r="255" g="0" b="0"/>
<viz:size value="21.0"/>
</node>
:
It produced this (without me having adjusted anything):