concept pie layout in category d3
appears as: pie layout, A pie layout, pie layout

This is an excerpt from Manning's book D3.js in Action, Second Edition: Data visualization with JavaScript.
In this section you’ll learn how to create a pie chart and transform it into a ring chart. You’ll also learn how to use tweening to properly transition it when you change its data source. After you create it, you can pass it an array of values (which I’ll call a dataset), and it will compute the necessary starting and ending angles for each of those values to draw a pie chart. When we pass an array of numbers as our dataset to a pie layout in the console, as in the following code, it doesn’t produce any kind of graphics like those seen in figure 5.6 but rather results in the response shown in figure 5.7.
Listing 5.4. Updated binding and transitioning for pie layout
pieChart .value(d => d.numTweets) .sort(null) #1 var tweetsPie = pieChart(nestedTweets) pieChart.value(d => d.numRetweets) var retweetsPie = pieChart(nestedTweets) nestedTweets.forEach((d,i) => { d.tweetsSlice = tweetsPie[i] d.retweetsSlice = retweetsPie[i] }) #2 ... .selectAll("path") .data(nestedTweets, d => d.key) #3 .enter() .append("path") .attr("d", d => newArc(d.tweetsSlice)) .style("fill", (d,i) => fillScale(i)) ... d3.selectAll("path") .transition() .duration(1000) .attrTween("d", arcTween) #4 function arcTween(d) { return t => { #5 var interpolateStartAngle = d3 .interpolate(d.tweetsSlice.startAngle, d.retweetsSlice.startAngle); var interpolateEndAngle = d3 .interpolate(d.tweetsSlice.endAngle, d.retweetsSlice.endAngle); d.startAngle = interpolateStartAngle(t); d.endAngle = interpolateEndAngle(t); return newArc(d); #6 } }