Question

In my prefuse visualization I want to add label to edges. I followed some examples proposed here on SO, but I can't bring it to work:

I use this Renderer for my edges:

private class CustomEdgeRenderer extends LabelRenderer {

    private EdgeRenderer edgeRenderer = new EdgeRenderer();

    @Override
    public String getText(VisualItem item) {
        System.out.println("edgerenderer");
        return "test";
    }

    @Override
    public void render(Graphics2D g, VisualItem item) {
        edgeRenderer.render(g, item);
        item.setTextColor(BLACK);
    }

}

The problem now is, that the text isn't displayed, but the edges are drawn in a weird form. That is they aren't correctly drawn. If I don't overwrite render, then the text is drawn, but no edges. How can i make this work?

Was it helpful?

Solution

Following the architecture of prefuse you would create a separate group of visual items for the labels, so called DecoratorItem.

An example can be found in the TreeMap demo: https://github.com/prefuse/Prefuse/blob/master/demos/prefuse/demos/TreeMap.java

OTHER TIPS

Another more ad-hoc solution:

  • Extend EdgeRenderer.
  • Take care of drawing the label in the render method.
  • Call super.render to let prefuse draw the edge.

You could check this question:

Displaying edges labels in prefuse (java) graphs

Google send me here and the previous questions, and looking for some code, I recently found the following version and runs ok.

http://netgrok.googlecode.com/svn-history/r2/trunk/src/test/AggregateDecoratorDemo.java

Regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top