I’m drawing a pie chart in D3, but having trouble with the text clipping itself:

Here’s my draw function:
pie: function(config)
{
var width = config.width || 840,
height = config.height || 520,
radius = Math.min(width, height) / 2;
var color = this._color = d3.scale.ordinal().range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
var arc = d3.svg.arc().outerRadius(radius - 10).innerRadius(0);
var pie = d3.layout.pie().sort(null).value(function(d) { return d.value; });
var svg = d3.select("body").append("svg").attr('id', config.id || 'chart').attr("width", width).attr("height", height)
.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var g = svg.selectAll(".arc").data(pie(config.data)).enter().append("g").attr("class", "arc");
g.append("path").attr("d", arc).style("fill", function(d) { return color(d.data.name); });
g.append("text")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return d.data.name; });
return $('#'+(config.id || 'chart'));
},
Is there an easy way to prevent such text clipping?
Update: See the answer to D3 put arc labels in a Pie Chart if there is enough space for a more comprehensive answer.
If by avoiding clipping you mean that the
<text>elements should not be occluded by the ensuing arc, then this can be achieved by making the<text>elements occur after the.arcelements in the DOM. One way of doing it is shown here: http://jsfiddle.net/tu3Pk/2/Here, I have created a fresh
g.arc-labelselement which contains the labels and appears in the DOM afterg.arcs.However, this does not help in legibility much. To make the labels more legible, you might want to take a look at the question: Preventing overlap of text in D3 pie chart in which case, the solution would be on these lines: http://jsfiddle.net/tu3Pk/3/