Skip to content

Commit a18471b

Browse files
committed
Polar area: startAngle in degrees, 0 at top.
1 parent 87e44fa commit a18471b

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

docs/charts/polar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ These are the customisation options specific to Polar Area charts. These options
6868

6969
| Name | Type | Default | Description
7070
| ---- | ---- | ------- | -----------
71-
| `startAngle` | `Number` | `-0.5 * Math.PI` | Starting angle to draw arcs for the first item in a dataset.
71+
| `startAngle` | `Number` | `0` | Starting angle to draw arcs for the first item in a dataset. In degrees, 0 is top.
7272
| `animation.animateRotate` | `Boolean` | `true` | If true, the chart will animate in with a rotation animation. This property is in the `options.animation` object.
7373
| `animation.animateScale` | `Boolean` | `true` | If true, will animate scaling the chart from the center outwards.
7474

src/controllers/controller.polarArea.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defaults._set('polarArea', {
2828
animateScale: true
2929
},
3030

31-
startAngle: -0.5 * Math.PI,
31+
startAngle: 0,
3232
legendCallback: function(chart) {
3333
var text = [];
3434
text.push('<ul class="' + chart.id + '-legend">');
@@ -119,14 +119,15 @@ module.exports = DatasetController.extend({
119119
var me = this;
120120
var dataset = me.getDataset();
121121
var meta = me.getMeta();
122-
var start = me.chart.options.startAngle || 0;
122+
var start = helpers.toRadians(me.chart.options.startAngle || 0);
123123
var starts = me._starts = [];
124124
var angles = me._angles = [];
125125
var i, ilen, angle;
126126

127127
me._updateRadius();
128128

129129
meta.count = me.countVisibleElements();
130+
start -= Math.PI / 2.0; // radialLinear scale expects 0 to be at top
130131

131132
for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
132133
starts[i] = start;
@@ -170,8 +171,8 @@ module.exports = DatasetController.extend({
170171
var centerX = scale.xCenter;
171172
var centerY = scale.yCenter;
172173

173-
// var negHalfPI = -0.5 * Math.PI;
174-
var datasetStartAngle = opts.startAngle;
174+
var negHalfPI = -0.5 * Math.PI;
175+
var datasetStartAngle = helpers.toRadians(opts.startAngle) + negHalfPI;
175176
var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
176177
var startAngle = me._starts[index];
177178
var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);

src/scales/scale.radialLinear.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,7 @@ module.exports = LinearScaleBase.extend({
424424
this.chart.options.startAngle :
425425
0;
426426

427-
var startAngleRadians = startAngle * Math.PI * 2 / 360;
428-
429-
// Start from the top instead of right, so remove a quarter of the circle
430-
return index * angleMultiplier + startAngleRadians;
427+
return index * angleMultiplier + helpers.toRadians(startAngle);
431428
},
432429

433430
getDistanceFromCenterForValue: function(value) {

test/specs/controller.polarArea.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('Chart.controllers.polarArea', function() {
172172
showLines: true,
173173
legend: false,
174174
title: false,
175-
startAngle: 0, // default is -0.5 * Math.PI
175+
startAngle: 90, // default is 0
176176
elements: {
177177
arc: {
178178
backgroundColor: 'rgb(255, 0, 0)',

0 commit comments

Comments
 (0)