在D3 Sankey图中的最后一个节点后添加文本

时间:2016-06-20 17:32:22

标签: javascript d3.js sankey-diagram

我正在尝试移动我的Sankey Diagram上最右边节点的标签,以跟随节点而不是在节点之前。我使用的是显示here的代码。

我可以通过键入过滤器功能行来获取文本以跟随节点,如下所示

// add in the title for the nodes
  node.append("text")
      .attr("x", -6)
      .attr("y", function(d) { return d.dy / 2; })
      .attr("dy", ".35em")
      .attr("text-anchor", "end")
      .attr("transform", null)
      .text(function(d) { return d.name + " ("+Math.round(d.value).toLocaleString('en') + ")"; })
    //.filter(function(d) { return d.x < width / 2; })
      .attr("x", 6 + sankey.nodeWidth())
      .attr("text-anchor", "start");

但是,现在这个文本被正确的边距切断了。即使调整屏幕宽度,它仍然会被切断。我怀疑代码中有一行,其中最右边的节点到达右边距。我是1)试图找到这一行和2)试图使这适用于文本而不是节点。

1 个答案:

答案 0 :(得分:1)

更改右边距
var margin = {top: 10, right: 10, bottom: 10, left: 10},

到此:

var margin = {top: 10, right: 90, bottom: 10, left: 10},

工作代码here