#27 RFE: BasicRenderer ordering

open
nobody
None
5
2012-08-01
2012-08-01
Anonymous
No

Very similar to https://sourceforge.net/tracker/?func=detail&aid=3550871&group_id=73840&atid=539119

This is to request a way to set the order of vertices/edges.

I've come up against this one because I have lots of objects that often overlap - when a vertex is picked then I want to make sure it is drawn near the end so that it looks like it is "on top" of the other vertices.

Workaround is to subclass and @Override render() with ordering logic (draw un-picked then picked vertices) in it.

Discussion


  • Anonymous
    2012-08-01

    this one is ready for instant drop-in to the existing class ;-) (some use of Guava)

    Incidentally, since edges/vertices are By Design supposed to be unique in a Graph, I would strongly recommend changing all Graph APIs to return Set instead of Collection.

    public void render(RenderContext<V, E> renderContext, Layout<V, E> layout) {
    try {
    Set<E> edges = Sets.newHashSet(layout.getGraph().getEdges());
    Set<E> pickedEdges = renderContext.getPickedEdgeState().getPicked();
    paintEdges(renderContext, layout, Sets.difference(edges, pickedEdges));
    paintEdges(renderContext, layout, pickedEdges);

    Set<V> vertices = Sets.newHashSet(layout.getGraph().getVertices());
    Set<V> pickedVertices = renderContext.getPickedVertexState().getPicked();
    paintVertices(renderContext, layout, Sets.difference(vertices, pickedVertices));
    paintVertices(renderContext, layout, pickedVertices);
    } catch (ConcurrentModificationException cme) {
    renderContext.getScreenDevice().repaint();
    }
    }

    private void paintEdges(RenderContext<V, E> renderContext, Layout<V, E> layout, Collection<E> edges) {
    for (E e : edges) {
    renderEdge(renderContext, layout, e);
    renderEdgeLabel(renderContext, layout, e);
    }
    }

    private void paintVertices(RenderContext<V, E> renderContext, Layout<V, E> layout, Collection<V> vertices) {
    for (V v : vertices) {
    renderVertex(renderContext, layout, v);
    renderVertexLabel(renderContext, layout, v);
    }
    }