簡體   English   中英

如何隱藏節點祖先的名稱

[英]how can i hide the names of ancestors of a node

我是 d3 的新手,我試圖用 d3 圓形包裝來表示代碼模型。 問題是類和接口太多,圓圈的標簽難以閱讀。 我發現我可能需要隱藏父節點的名稱以使事情更清楚,如下所示:

var node = svg.append("g").selectAll("circle")
    .data(root.descendants())
    .join("circle")
    .on("mouseover", d =>{
      //hide the label of the parent of the node
         var parentNodeLabel = label.filter((e) =>{

            return e == d.parent;
        })
        .style("fill-opacity", "0")
        })
     }

它按預期工作,但后來我意識到只隱藏父母的名字並沒有多大作用,所以現在我試圖隱藏所有祖先的名字。 我試過這樣:

.on("mouseover", function(d) {
        var ancestorNodeLabels = label.filter((e) =>{
            return e == d.ancestors().slice(1);
        })
        .style("fill-opacity", "0")
        })
}

但它似乎根本不起作用。 我需要有關如何完成我正在嘗試做的事情的提示。

沒關系,我只是愚蠢。 我需要檢查 e 是否包含在祖先中,不要將其分配給它們。

var ancestorNodeLabels = label.filter((e) =>{
            return (d.ancestors().slice(1)).includes(e);
        })
        .style("fill-opacity", "0")

暫無
暫無

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

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