Just a short one, How can I set the Edge thickness between
2 vertices, I tried using the setEdgeThickness function, but
this gives me weird results, as it doesnt only set the thickness
between 2 certain Vertices, but also others around it.
In the JUNG API Documentation it also says:
setEdgeThickness(int i)
- Forces all edges to draw with this thickness.
So this would be it, I dont want all edges to be drawn the same thickness,
but only between 2 pre-selected vertices.
Also also tried looking at:
setEdgeThicknessFunction(EdgeThicknessFunction etf)
- This version takes a function that dynamically chooses an edge thickness.
but didnt realy understand how to use it.
Anyone with experiance regarding thickness of edges?
Thanks in advance
Ido
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Take a look at ClusteringDemo for an example. Basically, an EdgeThicknessFunction has to provide a method getEdgeThickness(Edge) returns a thickness for the specified edge; this method is called for each edge. To treat some edges differently than others, you can give your EdgeThicknessFunction a method that allows you to specify an edge (or set of edges) to give special treatment to.
Warning: drawing thick edges tends to take more time to render than drawing thin edges. So if you have a large graph and want to emphasize a lot of edges in it, using color might be a better choice.
Hope this helps--
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-03-26
The ClusteringDemo indeed has a nice sample how to use the
EdgeThicknessFunction, so thanks for that.
Unfortunatly, one thing I forgot to mention, is that I use
my own Renderer to draw my Vertices and Edges and the edge
thickness doesnt seem to work then.
I tried an other solution, found a nice line drawing routine on
the internet where you can vary thickness aswell. But now
something goes teribly wrong with the order of drawing my edges.
In my paintEdge function I draw 2 things, a line and an arrow head.
If I use g.drawLine(x1, y1, x2, y2); everything gets drawn ok, but if
I use my own line function: drawThickLine(g, x1, y1, x2, y2, edgeWeight);
the order is screwed up, it draws lines between wrong vertices, while my
arrow heads are still drawn ok.
So howcome my arrows are drawn ok, but my lines are drawn between wrong
Vertices? Both my line and arrow functions look pretty the same.
very strange...
Regards
Ido
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-03-26
May be, it comes from a problem of synchronization between the thread painting the layout and the thread computing the layout. Try to delay the painting, or stop the layout computation.
Ciao, ciao,
Vincent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-03-26
Thanks for the quick answer, but what exactly do you mean with "stop the
layout computation", when, where, how do I stop this? :)
And wont this interfear with my network drawing, the way that it displays?
Btw, I have the following code for drawing my network:
I can't say I know what's going on with your drawThickEdge function.
But it's actually simpler than you think to get a thick edge in Java. In fact, you shouldn't have to change any of your code for it--just pop in a few lines
1) A Graphics2D is just a cast of a Graphics
2) A Graphics2D has a method called setStroke
So we do something like this:
renderEdge( Graphics g .... ) {
...
// here's the new code
// it sets the pen to be a little thicker
Graphics2D g2d = (Graphics2D) g;
Stroke s = new BasicStroke( 2.0f ); // line of thickness 2
g2d.setStroke( s );
// now draw your line IN THE SAME
// WAY YOU DID BEFORE .
g.drawLine( g, x1 , ... );
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-03-26
The synchronization problem may occur only if your graph is large (>> 500), if you are using a heavy layout like Kamada-Kawai, and/or if for some reasons your painting methods slow down the process. In other cases search the bug somewhere else !
For my application, I don't use the visualization kit of JUNG to display graphs (mainly because of the synchronization problem). Then I've got the bad habit to modify the JUNG source code. So I don't have any proper way to advice you how to interrupt the layout calculation. I would tell you to extend the prerelax time of the layout, and stop Graphdraw before painting but may be it's wrong.
Vincent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just a short one, How can I set the Edge thickness between
2 vertices, I tried using the setEdgeThickness function, but
this gives me weird results, as it doesnt only set the thickness
between 2 certain Vertices, but also others around it.
In the JUNG API Documentation it also says:
setEdgeThickness(int i)
- Forces all edges to draw with this thickness.
So this would be it, I dont want all edges to be drawn the same thickness,
but only between 2 pre-selected vertices.
Also also tried looking at:
setEdgeThicknessFunction(EdgeThicknessFunction etf)
- This version takes a function that dynamically chooses an edge thickness.
but didnt realy understand how to use it.
Anyone with experiance regarding thickness of edges?
Thanks in advance
Ido
Take a look at ClusteringDemo for an example. Basically, an EdgeThicknessFunction has to provide a method getEdgeThickness(Edge) returns a thickness for the specified edge; this method is called for each edge. To treat some edges differently than others, you can give your EdgeThicknessFunction a method that allows you to specify an edge (or set of edges) to give special treatment to.
Warning: drawing thick edges tends to take more time to render than drawing thin edges. So if you have a large graph and want to emphasize a lot of edges in it, using color might be a better choice.
Hope this helps--
Joshua
The ClusteringDemo indeed has a nice sample how to use the
EdgeThicknessFunction, so thanks for that.
Unfortunatly, one thing I forgot to mention, is that I use
my own Renderer to draw my Vertices and Edges and the edge
thickness doesnt seem to work then.
I tried an other solution, found a nice line drawing routine on
the internet where you can vary thickness aswell. But now
something goes teribly wrong with the order of drawing my edges.
In my paintEdge function I draw 2 things, a line and an arrow head.
If I use g.drawLine(x1, y1, x2, y2); everything gets drawn ok, but if
I use my own line function: drawThickLine(g, x1, y1, x2, y2, edgeWeight);
the order is screwed up, it draws lines between wrong vertices, while my
arrow heads are still drawn ok.
So howcome my arrows are drawn ok, but my lines are drawn between wrong
Vertices? Both my line and arrow functions look pretty the same.
very strange...
Regards
Ido
May be, it comes from a problem of synchronization between the thread painting the layout and the thread computing the layout. Try to delay the painting, or stop the layout computation.
Ciao, ciao,
Vincent
Thanks for the quick answer, but what exactly do you mean with "stop the
layout computation", when, where, how do I stop this? :)
And wont this interfear with my network drawing, the way that it displays?
Btw, I have the following code for drawing my network:
..............
networkPanel.removeAll();
gd.removeAllEdges();
gd.removeAllVertices();
//drawing my Vertices (only 1 shown here)
Vertex vertex = (Vertex) graph.addVertex(new SparseVertex());
//Drawing my edges (only 1 shown here)
DirectedEdge edge = (DirectedEdge) graph.addEdge(new DirectedSparseEdge(srcVertex, desVertex)
//Show graph
gd = new GraphDraw(graph);
gd.setBackground(Color.WHITE);
gd.hideStatus();
gd.setGraphLayout(new FRLayout(graph));
gd.restartLayout();
gd.setRenderer(new MyRenderer(StringLabeller.getLabeller(graph));
gd.addGraphMouseListener(new GraphMouseListener() { ... }
gd.getComponent(1).setVisible(false); // hide left gray column ??
networkPanel.add(gd, new XYConstraints(5,5,770,354));
gd.getRootPane().updateUI(); // repaint gd!!!
..............
Ido,
I can't say I know what's going on with your drawThickEdge function.
But it's actually simpler than you think to get a thick edge in Java. In fact, you shouldn't have to change any of your code for it--just pop in a few lines
In the graphics 2D API
http://java.sun.com/docs/books/tutorial/2d/display/strokeandfill.html
we learn that
1) A Graphics2D is just a cast of a Graphics
2) A Graphics2D has a method called setStroke
So we do something like this:
renderEdge( Graphics g .... ) {
...
// here's the new code
// it sets the pen to be a little thicker
Graphics2D g2d = (Graphics2D) g;
Stroke s = new BasicStroke( 2.0f ); // line of thickness 2
g2d.setStroke( s );
// now draw your line IN THE SAME
// WAY YOU DID BEFORE .
g.drawLine( g, x1 , ... );
}
The synchronization problem may occur only if your graph is large (>> 500), if you are using a heavy layout like Kamada-Kawai, and/or if for some reasons your painting methods slow down the process. In other cases search the bug somewhere else !
For my application, I don't use the visualization kit of JUNG to display graphs (mainly because of the synchronization problem). Then I've got the bad habit to modify the JUNG source code. So I don't have any proper way to advice you how to interrupt the layout calculation. I would tell you to extend the prerelax time of the layout, and stop Graphdraw before painting but may be it's wrong.
Vincent