The easiest solution to this problem is to set the missing values ββto zero , and not completely delete them, as in Part III Example Pie Chart chart . Then you get the persistence of the object for free: you have the same number of elements in the same order for updates.
Alternatively, if you want the data connection to be included in Part IV , you need to tell D3 where the arcs from and where the output arcs should go to are entered . A reasonable strategy is to find the nearest neighboring arc from opposite data: for a given incoming arc, find the nearest neighboring arc in the old data (preliminary transition); similarly for a given outgoing arc, find the nearest adjacent arc in the new data (post-transition).
To continue the example, say that you show apple sales in different regions and want to switch to showing oranges. You can use the following key function to keep the object constant:
function key(d) { return d.data.region; }
(This assumes you are using d3.layout.pie , which wraps your source data and provides it as d.data .)
Now tell me, when you go to oranges, you have the following old data and new data:
var data0 = path.data(),
For each input arc in index i (where d is data1[i] ), you can sequentially execute the previous data in data1 and see if a match can be found in data0 :
var m = data0.length; while (--i >= 0) { var k = key(data1[i]); for (var j = 0; j < m; ++j) { if (key(data0[j]) === k) return data0[j];
If you find a match, your inbound arcs can start at the corresponding angle at the end of the arc. If you do not find the previous match, you can search instead for the corresponding arc. If there are no matches, then they do not overlap between the two data sets, so you can enter arcs from an angle of 0 Β° or make a crossfade. You can also apply this technique to exit arcs.
Putting it all together, heres Part V :
