1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | function draw(data, bounds) { statusText.style("display", "none"); scale = bounds ? Math.min( w / Math.abs(bounds[1].x - w / 2), w / Math.abs(bounds[0].x - w / 2), h / Math.abs(bounds[1].y - h / 2), h / Math.abs(bounds[0].y - h / 2)) / 2 : 1; words = data; var text = visualisation.selectAll("text") .data(words, function(d) { return d.text.toLowerCase(); }); text.transition() .duration(1000) .attr("transform", function(d) { return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"; }) .style("font-size", function(d) { return d.size + "px"; }); text.enter().append("text") .attr("text-anchor", "middle") .attr("transform", function(d) { return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"; }) .style("font-size", function(d) { return d.size + "px"; }) .on("click", function(d) { load(d.text); }) .style("opacity", 1e-6) .transition() .duration(1000) .style("opacity", 1); text.style("font-family", function(d) { return d.font; }) .style("fill", customFill) .text(function(d) { return d.text; }); var exitGroup = background.append("g") .attr("transform", visualisation.attr("transform")); var exitGroupNode = exitGroup.node(); text.exit().each(function() { exitGroupNode.appendChild(this); }); exitGroup.transition() .duration(1000) .style("opacity", 1e-6) .remove(); visualisation.transition() .delay(1000) .duration(750) .attr("transform", "translate(" + [w >> 1, h >> 1] + ")scale(" + scale + ")"); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |