简体   繁体   English

d3包布局中的访问比例因子

[英]Access scale factor in d3's pack layout

I'm using d3's pack layout with the default radius function. 我正在使用带有默认半径功能的d3的背包布局。 This scales the size of the circles so that everything fits into the container. 这将缩放圆圈的大小,以便所有内容都适合容器。

How can I access this scale factor? 如何访问此比例因子?

This code will display scaling factor in node's tooltip: 该代码将在节点的工具提示中显示比例因子:

titles
    .attr("x", function(d) { return d.x; })
    .attr("y", function(d) { return d.y; })
    .text(function(d) {
        return (    "Scale factor  : " + (+d.value)/(d.r*d.r) + "\n" +
                    "Value: "  + d.value + "\n" +
                    "R: "  + d.r); 
    });

as in this test example jsfiddle . 如本测试示例jsfiddle所示

It looks the scaling factor is more or less the same for all leaf nodes in a circle pack, as illustrated in following two pictures: 看起来,圆包中所有叶节点的缩放因子或多或少都相同,如以下两幅图所示:

在此处输入图片说明

在此处输入图片说明

However, it may vary for all other nodes! 但是,对于所有其他节点,它可能会有所不同!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM