为了账号安全,请及时绑定邮箱和手机立即绑定

如何将所有后代节点和链接设置为与级别 2 祖先相同的颜色?

如何将所有后代节点和链接设置为与级别 2 祖先相同的颜色?

呼唤远方 2021-06-07 17:43:21
我有一个 d3.js 树,其后代节点接收它们的 2 级祖先节点颜色。这是从第 2 级到第 3 级工作,但在第 4 级及以上停止工作。相关代码:var colourScale = d3.scale.ordinal()    .domain(["MD","Professional", "Leader", "Advocate", "Clinician", "Educator", "Scholar"])    .range(["#6695c8", "#cd3838","#d48440", "#a8ba5f", "#63b7c0", "#c97eb2", "#ccc136"]);和 nodeUpdate.select("circle")    .attr("r", 10)    .attr("fill-opacity","0.7")    .attr("stroke-opacity","1")    .style("fill", function(d) {      return d.depth === 2 ? colourScale(d.parent.name) : colourScale(d.name);    })    .style("stroke", function(d) {      return d.depth === 2 ? colourScale(d.parent.name) : colourScale(d.name);    });和// Enter any new links at the parent's previous position.  link.enter().insert("path", "g")    .attr("class", "link")    .attr("stroke-width", function(d) {      return 1;    })    .attr("d", function(d) {      var o = {        x: source.x0,        y: source.y0      };      return diagonal({        source: o,        target: o      });    })    .attr("opacity","0.3")    .style("stroke", function(d) {      return d.target.depth === 2 ? colourScale(d.target.parent.name) : colourScale(d.target.name);    });如何将父级的所有后代设置为相同的颜色(节点和链接)?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 114 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信