简体   繁体   中英

Access scale factor in d3's pack layout

I'm using d3's pack layout with the default radius function. 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 .

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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