'd3-circle-text' on zoomable circle-pack

旧时模样 提交于 2019-12-06 02:00:59

I have updated the plugin at musically-ut/d3-circle-text

The the layout generation has been simplified and it now handles transitions correctly.

The updated fiddle: http://jsfiddle.net/nxmkoo95/

Notable changes

  • Hoisted the definition of circleText to the top level and removed the call to .precision.
  • Used a class .leaf-label to identify the text labels which had to be manually moved.
  • Added a call to update the radius function of circleText and moved the g.label to the correct place.
function zoom(d, i) {
    var k = r / d.r / 2;
    x.domain([d.x - d.r, d.x + d.r]);
    y.domain([d.y - d.r, d.y + d.r]);

    var t = svg.transition()
        .duration(d3.event.altKey ? 7500 : 750);

    t.selectAll("circle")
        .attr("cx", function(d) {
            return x(d.x);
        })
        .attr("cy", function(d) {
            return y(d.y);
        })
        .attr("r", function(d) {
            return k * d.r;
        });

    circleText.radius(function (d) { return k * d.r - 5.0; });
    t.selectAll('g.label')
        .attr('transform', function (d) { 
            return "translate(" + x(d.x) + ',' + y(d.y) + ')';
        })
        .filter(function (d) { return !!d.children; })
        .call(circleText);

    t.selectAll(".leaf-label")
        .attr("x", function(d) {
            return x(d.x);
        })
        .attr("y", function(d) {
            return y(d.y);
        })
        .style("opacity", function(d) { return k * d.r > 20 ? 1 : 0; });

    node = d;
    d3.event.stopPropagation();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!