Wouter Lievens Wouter Lievens - 17 days ago 12
Java Question

GraphStream nodes with input and output ports

I'd like to model a graph in GraphStream and render it with its Viewer, but my nodes need to have distinct input and output ports (preferably on the left-hand and right-hand side of the node box, respectively), and edges should connect with those ports rather than the node center.

Is that even possible in GraphStream? If not, is there another Java library that can be used? I know GraphViz Dot allows this, but I'd rather not call that by command line since that introduces an external dependency that's not part of my project.

EDIT: an example of the kind of thing I want to render (but for a very different domain): enter image description here

I'm perfectly willing to do the rendering myself, but of course I still need routing and coordinates for the nodes and edges.

Answer

There is no way in GraphStream yet to declare anchors, handles, or ports on the nodes.

However, since you want your edges tighten on the left and right sides of the nodes, then you might want to the give the "freeplan" CSS property a try. See the example below and especially the "stylesheet" attribute on the graph:

Graph graph = new SingleGraph("FreePlane");
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
graph.display();
graph.setAttribute("stylesheet", "node { "
        + "     shape: rounded-box; "
        + "     padding: 5px; "
        + "     fill-color: white; "
        + "     stroke-mode: plain; "
        + "     size-mode: fit; "
        + "} "
        + "edge { "
        + "     shape: freeplane; "
        + "}");
graph.addAttribute("ui.quality");
graph.addAttribute("ui.antialias");

Node a = graph.addNode("A");
Node b = graph.addNode("B");
graph.addEdge("AB", "A", "B");
Node c = graph.addNode("C");
graph.addEdge("BC", "B", "C"); 

a.addAttribute("ui.label", "node A");
b.addAttribute("ui.label", "node B");
c.addAttribute("ui.label", "node C");

That would give you something like that : screeshot of the window generetaed by this code

Comments