Commit 04df85ec authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix data label position on arc

parent c458905a
...@@ -974,11 +974,15 @@ ...@@ -974,11 +974,15 @@
return isArcType(d.data) ? svgArc(d, withoutUpdate) : "M 0 0"; return isArcType(d.data) ? svgArc(d, withoutUpdate) : "M 0 0";
} }
function transformForArcLabel(d) { function transformForArcLabel(d) {
var updated = updateAngle(d), c, x, y, h, translate = ""; var updated = updateAngle(d), c, x, y, h, ratio, translate = "";
if (updated) { if (updated) {
c = svgArc.centroid(updated); c = svgArc.centroid(updated);
x = c[0], y = c[1], h = Math.sqrt(x * x + y * y); x = c[0];
translate = "translate(" + ((x / h) * radius * 0.8) + ',' + ((y / h) * radius * 0.8) + ")"; y = c[1];
h = Math.sqrt(x * x + y * y);
// TODO: ratio should be an option?
ratio = (36 / radius > 0.375 ? 1.175 - 36 / radius : 0.8) * radius / h;
translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")";
} }
return translate; return translate;
} }
...@@ -3439,10 +3443,10 @@ ...@@ -3439,10 +3443,10 @@
.style('opacity', 0) .style('opacity', 0)
.remove(); .remove();
main.selectAll('.' + CLASS.chartArc).select('text') main.selectAll('.' + CLASS.chartArc).select('text')
.attr("transform", transformForArcLabel)
.style("opacity", 0) .style("opacity", 0)
.transition().duration(duration)
.text(textForArcLabel) .text(textForArcLabel)
.attr("transform", transformForArcLabel)
.transition().duration(duration)
.style("opacity", function (d) { return isTargetToShow(d.data.id) && isArcType(d.data) ? 1 : 0; }); .style("opacity", function (d) { return isTargetToShow(d.data.id) && isArcType(d.data) ? 1 : 0; });
main.select('.' + CLASS.chartArcsTitle) main.select('.' + CLASS.chartArcsTitle)
.style("opacity", hasDonutType(c3.data.targets) ? 1 : 0); .style("opacity", hasDonutType(c3.data.targets) ? 1 : 0);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment