I have 4 copies of Graph A, but when A and the copies are rendered in 5 separate JFrames, the vertex placement is of course different in all of them. So, it is very hard to instantly navigate the graph and identify which vertex is which (despite the labels).
So I want to copy the location of all the Vertices in Graph A into the 4 copies of A. Or in other words, reproduce the layout of graph A, so they all look identical.
As the copies are in fact graph.copy()'ies, I can traverse each vertex in each copy and manually use getEquivalent to identify the original Vertex, and then get the position of that vertex and.. hopefully copy it into the equivalent vertex. Cause I am guessing as the position of a vertexA can be obtained through someLayoutX.getLocation(vertexA), the position of the vertexB in someLayoutY can be given the same coordinates? However, I have not managed to locate any setX og setPostion.. only get methods. Which is why I feel maybe there is a smart(er) way to do this..
If you understand what I want to do, and have any ideas - let me know. I wold greatly appreciate it!
/Pan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Once you've laid out the first graph to your satisfaction, you can use the vertex positions from that graph for the others, by passing the first Layout to the others as an optional argument to the initialize() method. (By default, initialize() uses random vertex locations as a starting point, but it can take a VertexLocationDecorator as a parameter--and Layout implements VLD.)
Even easier: lay the first one out, and use a StaticLayout for the others (again, initialized using the first one).
If you want to do this manually for some reason, check out Layout.forceMove() and Layout.lockVertex(). (I agree that forceMove() is not the most intuitive name for the method.)
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The good thing is I am already using the StaticLayout for the copies, and the ISOMLayout for the original. The sad thing is that I do not understand how to do this.. arg. This is how I currently display the graph copies:
--- 8< ------
sl_ = new StaticLayout(topology_);
cr_ = new ConfigurationRenderer(ps);
vv_ = new VisualizationViewer(sl_, cr_);
Not a chance.. I do not understand this at all. Please, advise.
What and how do I provide to the graph copies using StaticLayout so that the vertex layout is similar to the original graph? In Joshuas answer it simply seemed like all I had to do was pass the layout of the original graph.. However that and any other wild attempt of getting it to work fails.. miserably.
This is what I do:
sl_ = new StaticLayout(topology_);
// sl_.initialize(new Dimension(600, 622)); // this works
sl_.initialize(new Dimension(600, 622), (VertexLocationFunction) orgLayout); // this does not
This is what I get after doing the above:
--- 8< ---------
Exception in thread "main" java.lang.NullPointerException
at java.awt.geom.Point2D.setLocation(Point2D.java:241)
at edu.uci.ics.jung.visualization.AbstractLayout.initializeLocation(AbstractLayout.java:196)
at edu.uci.ics.jung.visualization.AbstractLayout.initializeLocations(AbstractLayout.java:174)
at edu.uci.ics.jung.visualization.AbstractLayout.initialize(AbstractLayout.java:114)
at no.gatada.sak.simulator.Configuration.displayJFrame(Configuration.java:421)
....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you actually visualized the first graph? If you haven't, it won't yet have vertex positions that it can give to the other layouts. You need to do this first. (Technically you don't have to actually visualize it--you can just advance the layout yourself--but visualizing it may be the easiest way to do it. Tom may be able to give you better advice.)
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What graph does orgLayout have? Is it the same graph as
_topology? If not, orgLayout will have no locations for
the _topology vertices in your static layout to use.
Tom Nelson
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, they are as mentioned all copies of the same graph:
// copying the graph
topology_ = (Graph) graph.copy();
I get a feeling I will have to manually do the equivalent trick on all vertices in all the copies? Starting to look into the forceMove() and lockVertex() to do this manually. Correct me if this is not the easiest way.
Thanks! :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have 4 copies of Graph A, but when A and the copies are rendered in 5 separate JFrames, the vertex placement is of course different in all of them. So, it is very hard to instantly navigate the graph and identify which vertex is which (despite the labels).
So I want to copy the location of all the Vertices in Graph A into the 4 copies of A. Or in other words, reproduce the layout of graph A, so they all look identical.
As the copies are in fact graph.copy()'ies, I can traverse each vertex in each copy and manually use getEquivalent to identify the original Vertex, and then get the position of that vertex and.. hopefully copy it into the equivalent vertex. Cause I am guessing as the position of a vertexA can be obtained through someLayoutX.getLocation(vertexA), the position of the vertexB in someLayoutY can be given the same coordinates? However, I have not managed to locate any setX og setPostion.. only get methods. Which is why I feel maybe there is a smart(er) way to do this..
If you understand what I want to do, and have any ideas - let me know. I wold greatly appreciate it!
/Pan
Pan:
Once you've laid out the first graph to your satisfaction, you can use the vertex positions from that graph for the others, by passing the first Layout to the others as an optional argument to the initialize() method. (By default, initialize() uses random vertex locations as a starting point, but it can take a VertexLocationDecorator as a parameter--and Layout implements VLD.)
Even easier: lay the first one out, and use a StaticLayout for the others (again, initialized using the first one).
If you want to do this manually for some reason, check out Layout.forceMove() and Layout.lockVertex(). (I agree that forceMove() is not the most intuitive name for the method.)
Joshua
Thanks Joshua,
The good thing is I am already using the StaticLayout for the copies, and the ISOMLayout for the original. The sad thing is that I do not understand how to do this.. arg. This is how I currently display the graph copies:
--- 8< ------
sl_ = new StaticLayout(topology_);
cr_ = new ConfigurationRenderer(ps);
vv_ = new VisualizationViewer(sl_, cr_);
vv_.setPickedState(ps);
jf_.getContentPane().add(vv_);
------------
And I tried to add this line after creating the StaticLayout (top line in the snipet):
sl_.initialize(orgLayout.getCurrentSize(), orgLayout);
However, that did not go very well. Eh... nullpointer. I will continue to try to understand this, but if you *know* the answer, let me know.
Thanks,
Pan
Not a chance.. I do not understand this at all. Please, advise.
What and how do I provide to the graph copies using StaticLayout so that the vertex layout is similar to the original graph? In Joshuas answer it simply seemed like all I had to do was pass the layout of the original graph.. However that and any other wild attempt of getting it to work fails.. miserably.
This is what I do:
sl_ = new StaticLayout(topology_);
// sl_.initialize(new Dimension(600, 622)); // this works
sl_.initialize(new Dimension(600, 622), (VertexLocationFunction) orgLayout); // this does not
This is what I get after doing the above:
--- 8< ---------
Exception in thread "main" java.lang.NullPointerException
at java.awt.geom.Point2D.setLocation(Point2D.java:241)
at edu.uci.ics.jung.visualization.AbstractLayout.initializeLocation(AbstractLayout.java:196)
at edu.uci.ics.jung.visualization.AbstractLayout.initializeLocations(AbstractLayout.java:174)
at edu.uci.ics.jung.visualization.AbstractLayout.initialize(AbstractLayout.java:114)
at no.gatada.sak.simulator.Configuration.displayJFrame(Configuration.java:421)
....
Pan:
Have you actually visualized the first graph? If you haven't, it won't yet have vertex positions that it can give to the other layouts. You need to do this first. (Technically you don't have to actually visualize it--you can just advance the layout yourself--but visualizing it may be the easiest way to do it. Tom may be able to give you better advice.)
Joshua
What graph does orgLayout have? Is it the same graph as
_topology? If not, orgLayout will have no locations for
the _topology vertices in your static layout to use.
Tom Nelson
Tom / Joshua:
Well, they are as mentioned all copies of the same graph:
// copying the graph
topology_ = (Graph) graph.copy();
I get a feeling I will have to manually do the equivalent trick on all vertices in all the copies? Starting to look into the forceMove() and lockVertex() to do this manually. Correct me if this is not the easiest way.
Thanks! :-)