簡體   English   中英

Radial Reingold Tilford Tree刪除根節點

[英]Radial Reingold Tilford Tree remove root node

我一直在尋找一種從徑向Tilford樹中刪除根節點的方法,但到目前為止還沒有運氣。 我在這里發現了一個類似的問題,但提供的答案並不具體,無法完全理解我需要使用d.depth > 0 我試圖在有意義但不成功的位置添加這行代碼(例如node.append和.data(nodes))。 附件的片段類似於用戶@JSBob在其他問題中所指的位置,任何方向都會有所幫助,因為我是D3的新手!

function createVisualization(root){
  //if (error) throw error;
  drawLegend();
  var nodes = tree.nodes(root), 
      links = tree.links(nodes);
      console.log(nodes);

  var link = svg.selectAll(".link")
      .data(links)
    .enter().append("path")
      .attr("class", "link")
      .attr("d", diagonal);

  var node = svg.selectAll(".node")
      .data(nodes)
    .enter().append("g")
      .attr("class", "node")
      .attr("transform", function(d) {
        return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
      .on("mouseover", mouseOverArc)
      .on("mousemove", mouseMoveArc)
      .on("mouseout", mouseOutArc);

  node.append("circle").attr("r", 5)
  .style("fill", function(d) {
    if(d.size == 0) {
       return "#8c6226"; //Brown
    } else if(d.size == 1){
      return "#DC143C"; //Crimson
    } else if(d.size == 2){
      return "#FFA500"; //Orange
    } else if(d.size == 3){
      return "#32CD32"; //LimeGree
    } else if(d.size == 4){
      return "#1E90FF"; //DodgerBlue
    }
    ;})

@JSBOB說的是,當您為根節點創建圓時,將其半徑設置為0,如下所示:

  node.append("circle")
    .attr("r", function(d) {
      if (d.depth == 0) {//for root node depth will be 0
        return 0;//make the circle's radius 0 for root node.
      } else {
        return 4.5;
      }
    }).style("fill", function(d) { ... });

這里工作樣本

采用 :

var link = svg.selectAll(".link")
      .data(links)
    .enter().append("path")
      .filter(function(d) { return d.source.depth != 0})
      .attr("class", "link")
      .attr("d", diagonal);

刪除指向根節點的鏈接

  var node = svg.selectAll(".node")
      .data(nodes)
    .enter().append("g")
      .filter(function(d) { return d.depth != 0})
      .attr("class", "node")
      .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })

刪除根節點

請參閱示例: http//plnkr.co/edit/GkXtUoAvUa6nijNCERxz?p = preview

暫無
暫無

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

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