简体   繁体   中英

Prefuse. When hovering over a node, how can I change the connected edges' visualization?

I use this typical snippet (from the prefuse examples) to change the color of one of my nodes when the mouse is over it:

ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
nFill.setDefaultColor(ColorLib.gray(255));
nFill.add("_hover", ColorLib.gray(200));

I'd like to set the color for the edges in & out of this node to a different color too, preferably a different color for the ins than for the outs, but I can't find the right predicate to use.

I'm using a directed graph, in case it matters.

Is there a way to iterate over the children/parents of the current node/edge in the predicate API ? Do you have a solution to my actual issue ?

I found a way to do it without predicates, but by creating my own ColorAction subclass:

class ConnectedEdgeColorAction extends ColorAction {

    final int outgoing = ColorLib.rgb(255, 100, 100);
    final int incoming = ColorLib.rgb(100, 255, 100);
    final int none = ColorLib.gray(100);

    public ConnectedEdgeColorAction(String group, String field) {
        super(group, field);
    }

    @Override
    public int getColor(VisualItem item) {
        if (item instanceof EdgeItem) {
            if (((EdgeItem) item).getSourceItem().isHover()) {
                return outgoing;
            } else if (((EdgeItem) item).getTargetItem().isHover()) {
                return incoming;
            }
        }

        return none;
    }

}

Then, I use that as the main color action for my edges:

ColorAction nEdges = new ConnectedEdgeColorAction(EDGES, VisualItem.STROKECOLOR);

I don't know if it's the "preferred" way to do it, but it works well enough for me.

Another solution could go along the line of

  • create a subclass of Action
  • invoke this Action on nodes with the predicate _hover
  • in the Action subclass go to incoming and outgoing edges and set their color

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM