Changing positions of nodes
Hello, I am trying to plot the Nodes with custom x, y values but I notice that using the getters and setters from the Node objects, doesn't change their final position when displayed on the phone. Is it possible to change or modify the vector and/or position values of the Node object, so that I can display them where I want?
Thank you very much!
That's because the position values are overridden by the algorithm you are using. You could implement a new algorithm that does nothing, like this:
public class NoOpAlgorithm implements Algorithm {
private Size graphSize = new Size(0, 0);
private EdgeRenderer edgeRenderer = new StraightEdgeRenderer(); // or ArrowEdgeRender() or custom implementation
@NotNull
@Override
public Size getGraphSize() {
return graphSize;
}
@Override
public void run(@NotNull Graph graph) {
calculateGraphSize(graph);
}
@Override
public void drawEdges(@NotNull Canvas canvas, @NotNull Graph graph, @NotNull Paint linePaint) {
edgeRenderer.render(canvas, graph, linePaint);
}
@Override
public void setEdgeRenderer(@NotNull EdgeRenderer renderer) {
edgeRenderer = renderer;
}
private void calculateGraphSize(Graph graph) {
int left = Integer.MAX_VALUE;
int top = Integer.MAX_VALUE;
int right = Integer.MIN_VALUE;
int bottom = Integer.MIN_VALUE;
for (Node node : graph.getNodes()) {
left = (int) Math.min(left, node.getX());
top = (int) Math.min(top, node.getY());
right = (int) Math.max(right, node.getX() + node.getWidth());
bottom = (int) Math.max(bottom, node.getY() + node.getHeight());
}
graphSize = new Size(right - left, bottom - top);
}
}
Since I am using the algorithm for the Directed graph, I could not find the method which overrides the position values, could you point exactly which one takes care of that? Thank you!
Well, the point of the algorithms is calculating the positions for each node in the graph. If you try to "disable" the position setting the whole algorithm code is useless. Therefore I suggested a NoOpAlgorithm. But to answer your question this would be the https://github.com/Team-Blox/GraphView/blob/43dd72340ce08dba9f62cb0c5228a2d56206414c/graphview/src/main/java/de/blox/graphview/energy/FruchtermanReingoldAlgorithm.java#L153 method.
What are you trying to achieve? Do you want to position all of your nodes yourself or do you want to position them after the algorithm already run? The latter is currently not possible.
What I am trying to do is to put certain nodes on the same height as eachother, for example having node A and node B on the same Y axis level.
As mentioned earlier its not possible right now to change the position after the algorithm has run.
Right, ok. Thank you again!