[英]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. 我也想将此节点的出入边缘的颜色设置为不同的颜色,最好将ins的颜色设置为与outs的颜色不同,但是我找不到合适的谓词。
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 ? 有没有一种方法可以遍历谓词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: 我找到了一种无需谓词的方法,但是通过创建自己的ColorAction子类:
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 另一个解决方案可以遵循
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.