I am trying to work out how to tween multiple arcs to new positions, while also changing the size of the arc in terms of its inner and outer radius.
Meaning it will move from its current position on the canvas to its new position while also morphing to its new shape based on changes in new data compared to the old data.
I have read many examples such as http://bl.ocks.org/mbostock/5100636 which are all great however I cannot adapt any example to my particular need. Most examples that Ive found do not involve moving the arc on the canvas.
here is how I am creating the arcs in the first place which is working fine, and also animating the arc from 0 to its end position according to the data.
// THIS IS CALLED ON LOAD OF THE GRAPH
function createLargeArcs(graph,data){
var arc = d3.svg.arc()
.innerRadius(function (data) { return (data.r * 5) + 5; })
.outerRadius(function (data) { return data.r * 5 })
.startAngle(0);
var endAngleFunction = function (data) {
return (data.percentage) * ((2 * Math.PI) / 180);
};
// a global variable
arcGroup = graph.append("g")
.attr("class", "arcsGroup");
var arcs = arcGroup.selectAll("path")
.data(data)
.enter()
.append("svg:path")
.attr("transform", function (d) { return "translate(" + xScale(d.u) + "," + yScale(d.t) + ")"; })
.style("fill", "red");
arcs.transition()
.duration(750)
.call(arcTween);
// http://bl.ocks.org/mbostock/5100636
function arcTween(transition, newAngle) {
transition.attrTween("d", function (d) {
var interpolate = d3.interpolate(0, endAngleFunction(d));
return function (t) {
d.endAngle = interpolate(t);
return arc(d);
};
});
}
}
- all of the above works just fine
But its the process of working out how to tween the arcs to their new positions and their new size based on new data values that I am struggling with.
so far I have a refresh function which accepts a new/updated data set and within the refresh function this is where I am targeting the tween of the arc elements. I have achieved the moving of all of the arcs to their new positions with the following :
// THIS IS CALLED LATER ON WHEN DATA CHANGES - ITS HERE I NEED TO IMPLEMENT
function refresh(data){
var arcs = arcGroup.selectAll("path")
.data(newData)
arcs.transition()
.duration(1000)
.attr("transform", function(d) { return "translate("+ xScale(d.users) + "," + yScale(d.traffic) + ")"; });
}
Any help would be much appreciated. Thanks