Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing positions of nodes #32

Open
krechanski opened this issue Mar 7, 2019 · 6 comments
Open

Changing positions of nodes #32

krechanski opened this issue Mar 7, 2019 · 6 comments

Comments

@krechanski
Copy link

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!

@DennisBlock
Copy link
Contributor

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);
    }
}
@krechanski
Copy link
Author

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!

@DennisBlock
Copy link
Contributor

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.

@krechanski
Copy link
Author

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.

@GregorBlock
Copy link
Contributor

As mentioned earlier its not possible right now to change the position after the algorithm has run.

@krechanski
Copy link
Author

Right, ok. Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants