From b01d0e78af4738a507e6f010d3c74c0ebb4771b5 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 6 Nov 2017 10:52:27 +0100 Subject: [PATCH] Added some modifications to sunburst d3 function --- pandora_console/include/graphs/pandora.d3.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js index 121e41aaef..90d5f1124f 100644 --- a/pandora_console/include/graphs/pandora.d3.js +++ b/pandora_console/include/graphs/pandora.d3.js @@ -724,12 +724,13 @@ function sunburst (recipient, data, width, height) { .on("mousemove", move_tooltip); function computeTextRotation(d) { - var angle = x(d.x + d.dx / 2) - Math.PI / 2; - return angle / Math.PI * 180; + var ang = (x(d.x + d.dx / 2) - Math.PI / 2) / Math.PI * 180; + return (ang > 90) ? 180 + ang : ang; } var text = g.append("text") - .attr("x", function(d) { return y(d.y); }) + .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")rotate(" + computeTextRotation(d) + ")"; }) + .attr("x", function (d) { return computeTextRotation(d) > 180 ? -40 : -30; }) .attr("dx", "6") // margin .attr("dy", ".35em") // vertical-align .attr("opacity", function(d) { @@ -741,7 +742,6 @@ function sunburst (recipient, data, width, height) { .text(function(d) { return d.name; }) - .attr("transform", function(d) { return "rotate(" + computeTextRotation(d) + ")"; }) .style("font-size", "10px") // Makes svg elements invisible to events .style("pointer-events", "none"); @@ -768,8 +768,8 @@ function sunburst (recipient, data, width, height) { var arcText = d3.select(this.parentNode).select("text"); // fade in the text element and recalculate positions arcText - .attr("transform", function() { return "rotate(" + computeTextRotation(e) + ")" }) - .attr("x", function(d) { return y(d.y); }) + .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")rotate(" + computeTextRotation(d) + ")"; }) + .attr("x", function (d) { return computeTextRotation(d) > 180 ? -40 : -30; }) .transition().duration(250) .attr("opacity", 1); }