10-07-2007, 03:10 PM
This demo shows how to use images as nodes instead of text based rendering.
The LabelRenderer used in this demo (same as in the DataMountain demo)
You can also have a combined images/text rendering which is hopefully easy to implement based on this demo.
While this is quite straight forward the more tricky thing with this demo if you never did it before is that the default spring length of the edges is too short, the both images are overlapping.
Here we need to set this length explicitly, along with other parameters for the sake of demonstration (for which we use the default values)
be well and don't forget to also download the two attachted images a.jpg and b.jpg below in order to run the demo
The LabelRenderer used in this demo (same as in the DataMountain demo)
Code:
LabelRenderer nodeRenderer = new LabelRenderer(null, "image");
nodeRenderer.setTextField(null);
nodeRenderer.setVerticalAlignment(Constants.BOTTOM);
nodeRenderer.setHorizontalPadding(0);
nodeRenderer.setVerticalPadding(0);
nodeRenderer.setMaxImageDimensions(100,100);You can also have a combined images/text rendering which is hopefully easy to implement based on this demo.
While this is quite straight forward the more tricky thing with this demo if you never did it before is that the default spring length of the edges is too short, the both images are overlapping.
Here we need to set this length explicitly, along with other parameters for the sake of demonstration (for which we use the default values)
Code:
ForceSimulator fsim = new ForceSimulator(new RungeKuttaIntegrator());
float gravConstant = -1f;
float minDistance = -1f;
float theta = 0.9f;
float drag = 0.01f;
float springCoeff = 1E-4f;
float defaultLength = 150f; //default: 50f
fsim.addForce(new NBodyForce(gravConstant, minDistance, theta));
fsim.addForce(new DragForce(drag));
fsim.addForce(new SpringForce(springCoeff, defaultLength));
ForceDirectedLayout fdl = new ForceDirectedLayout(GRAPH, fsim,true);be well and don't forget to also download the two attachted images a.jpg and b.jpg below in order to run the demo

