簡體   English   中英

預熔。 將鼠標懸停在節點上時,如何更改連接邊的可視化效果?

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

當鼠標懸停在上面時,我使用這個典型的代碼段(來自預示例)來更改節點之一的顏色:

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

我也想將此節點的出入邊緣的顏色設置為不同的顏色,最好將ins的顏色設置為與outs的顏色不同,但是我找不到合適的謂詞。

我正在使用有向圖,以防萬一。

有沒有一種方法可以遍歷謂詞API中當前節點/邊的子級/父級? 您對我的實際問題有解決方案嗎?

我找到了一種無需謂詞的方法,但是通過創建自己的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;
    }

}

然后,將其用作邊緣的主要顏色操作:

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

我不知道這是否是“首選”方式,但對我來說效果很好。

另一個解決方案可以遵循

  • 創建動作的子類
  • 在帶有謂詞_hover的節點上調用此Action
  • 在“動作”子類中,轉到輸入和輸出邊緣並設置其顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM