* @param {boolean} [useFinalPosition]
*/
getCenterPoint(useFinalPosition) {
- const {x, y, startAngle, endAngle, innerRadius, outerRadius} = this.getProps([
+ const {x, y, startAngle, endAngle, innerRadius, outerRadius, circumference} = this.getProps([
'x',
'y',
'startAngle',
'endAngle',
'innerRadius',
- 'outerRadius'
+ 'outerRadius',
+ 'circumference'
], useFinalPosition);
- const halfAngle = (startAngle + endAngle) / 2;
+ const halfAngle = isNaN(circumference) ? (startAngle + endAngle) / 2 : startAngle + circumference / 2;
const halfRadius = (innerRadius + outerRadius) / 2;
return {
x: x + Math.cos(halfAngle) * halfRadius,
expect(center.y).toBeCloseTo(0.5, 6);
});
+ it ('should get the center of full circle using endAngle', function() {
+ // Mock out the arc as if the controller put it there
+ var arc = new Chart.elements.ArcElement({
+ startAngle: 0,
+ endAngle: Math.PI * 2,
+ x: 2,
+ y: 2,
+ innerRadius: 0,
+ outerRadius: 2
+ });
+
+ var center = arc.getCenterPoint();
+ expect(center.x).toBeCloseTo(1, 6);
+ expect(center.y).toBeCloseTo(2, 6);
+ });
+
+ it ('should get the center of full circle using circumference', function() {
+ // Mock out the arc as if the controller put it there
+ var arc = new Chart.elements.ArcElement({
+ startAngle: 0,
+ endAngle: 0,
+ x: 2,
+ y: 2,
+ innerRadius: 0,
+ outerRadius: 2,
+ circumference: Math.PI * 2
+ });
+
+ var center = arc.getCenterPoint();
+ expect(center.x).toBeCloseTo(1, 6);
+ expect(center.y).toBeCloseTo(2, 6);
+ });
+
it('should not draw when radius < 0', function() {
var ctx = window.createMockContext();