algorithm = new DijkstraShortestPathAlgorithm(graph, n);
algorithm.compute();
}
//Color
LinearGradient linearGradient = new LinearGradient(colors, positions);
//Algorithm
double maxDistance = algorithm.getMaxDistance();
if (!dontPaintUnreachable) {
maxDistance++; //+1 to have the maxdistance nodes a ratio<1
}
if (maxDistance > 0) {
for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
NodeData node = entry.getKey().getNodeData();
if (!Double.isInfinite(entry.getValue())) {
float ratio = (float) (entry.getValue() / maxDistance);
Color c = linearGradient.getValue(ratio);
node.setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f);
} else if (!dontPaintUnreachable) {
Color c = colors[colors.length - 1];
node.setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f);
}