Skip to content

Commit

Permalink
d3.transition differs from d3.selection
Browse files Browse the repository at this point in the history
for #1167
apparently this is the only place where our use of dc.selection
is risky, because we don't use the *tween functions very much

places where this problem is currently avoided:
- lineChart has .ease commented-out
- numberDisplay does not use dc.transition
  • Loading branch information
gordonwoodhull committed Jul 28, 2016
1 parent 5ad6a2b commit eea7758
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/pie-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,30 @@ dc.pieChart = function (parent, chartGroup) {
});

polyline.exit().remove();
dc.transition(polyline, _chart.transitionDuration())
.attrTween('points', function (d) {
this._current = this._current || d;
var interpolate = d3.interpolate(this._current, d);
this._current = interpolate(0);
return function (t) {
var arc2 = d3.svg.arc()
.outerRadius(_radius - _externalRadiusPadding + _externalLabelRadius)
.innerRadius(_radius - _externalRadiusPadding);
var d2 = interpolate(t);
return [arc.centroid(d2), arc2.centroid(d2)];
};
})
.style('visibility', function (d) {
return d.endAngle - d.startAngle < 0.0001 ? 'hidden' : 'visible';
var arc2 = d3.svg.arc()
.outerRadius(_radius - _externalRadiusPadding + _externalLabelRadius)
.innerRadius(_radius - _externalRadiusPadding);
var transition = dc.transition(polyline, _chart.transitionDuration());
// this is one rare case where d3.selection differs from d3.transition
if (transition.attrTween) {
transition
.attrTween('points', function (d) {
this._current = this._current || d;
var interpolate = d3.interpolate(this._current, d);
this._current = interpolate(0);
return function (t) {
var d2 = interpolate(t);
return [arc.centroid(d2), arc2.centroid(d2)];
};
});
} else {
transition.attr('points', function (d) {
return [arc.centroid(d), arc2.centroid(d)];
});
}
transition.style('visibility', function (d) {
return d.endAngle - d.startAngle < 0.0001 ? 'hidden' : 'visible';
});

}

Expand Down

0 comments on commit eea7758

Please sign in to comment.