如何在d3 Sankey图中将节点标题放在节点的左侧或右侧? [英] How to place node title to the left or right of the node in d3 Sankey graph?
本文介绍了如何在d3 Sankey图中将节点标题放在节点的左侧或右侧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我指的示例: http://bl.ocks.org/d3noob/c9b90689c1438f57d649
第二层节点的标题位于其右侧.如何将它们放置在节点的左侧?请帮忙.
The second level nodes have their title to their right. How can I place those to the left of the nodes? Please help.
推荐答案
这是向节点制作文本的方式.
This is how you make text to 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; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
为了使右边的文本始终有效,请执行以下操作:
For making the text on the right always do :
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; })
//.filter(function(d) { return d.x < width / 2; }) //COMMENT THIS LINE
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
注释上面显示的行,以便它不过滤宽度超过SVG一半的节点.
Comment the line shown above so that it does not filter the nodes > half of width SVG.
工作代码此处
这篇关于如何在d3 Sankey图中将节点标题放在节点的左侧或右侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文