d3.js - 'd3-circle-text' on zoomable circle-pack -
the 'd3-circle-text' plug-in works great on static circle-pack (many musically-ut contributing https://github.com/musically-ut/d3-circle-text). however, on zoomable circle-pack, labels fly place (in fiddle, stay static not repositioning on zoom).
is possible circle-text zoom circles? (if plug-in isn't zoomable, that's ok. i'll try labelling approach.)
here's code section i'm working on:
////////////circle text var circletext = d3.circletext() .radius(function(d) { return d.r - 5; }) .value(function(d) { return d.key; //get lables }) .method('align') .spacing('exact') .precision(0.1) .fontsize('100%'); var gtexts = svg.selectall('g.label') .data(pack.nodes) //returns names .enter() .append('g') .classed('label', true) .attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')'; }); /*.attr("x", function (d) { return d.x; }) .attr("y", function (d) { return d.y; }); */ attempt - not working /*.attr("cx", function (d) { return d.x; }) .attr("cy", function (d) { return d.y; }); */ attempt - not working //only put on 'parent' circles gtexts.filter(function(d) { return !!d.children; }) .call(circletext) //.style('fill', 'white');
here's full fiddle: http://jsfiddle.net/cajmcmahon/9a5xaovv/1/
thanks help.
i have updated plugin @ musically-ut/d3-circle-text
the layout generation has been simplified , handles transitions correctly.
the updated fiddle: http://jsfiddle.net/nxmkoo95/
notable changes
- hoisted definition of
circletext
top level , removed call.precision
. - used class
.leaf-label
identify text labels had manually moved. - added call update radius function of
circletext
, movedg.label
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(); }
Comments
Post a Comment