Skip to content

Commit

Permalink
startAngle in degrees, 0 at top.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Dec 17, 2018
1 parent 2388eea commit d464ba2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/charts/polar.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ These are the customisation options specific to Polar Area charts. These options

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

Expand Down
9 changes: 5 additions & 4 deletions src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defaults._set('polarArea', {
animateScale: true
},

startAngle: -0.5 * Math.PI,
startAngle: 0,
legendCallback: function(chart) {
var text = [];
text.push('<ul class="' + chart.id + '-legend">');
Expand Down Expand Up @@ -119,14 +119,15 @@ module.exports = DatasetController.extend({
var me = this;
var dataset = me.getDataset();
var meta = me.getMeta();
var start = me.chart.options.startAngle || 0;
var start = helpers.toRadians(me.chart.options.startAngle || 0);
var starts = me._starts = [];
var angles = me._angles = [];
var i, ilen, angle;

me._updateRadius();

meta.count = me.countVisibleElements();
start -= Math.PI / 2.0; // radialLinear scale excepts 0 to be at top

for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
starts[i] = start;
Expand Down Expand Up @@ -171,8 +172,8 @@ module.exports = DatasetController.extend({
var centerX = scale.xCenter;
var centerY = scale.yCenter;

// var negHalfPI = -0.5 * Math.PI;
var datasetStartAngle = opts.startAngle;
var negHalfPI = -0.5 * Math.PI;
var datasetStartAngle = helpers.toRadians(opts.startAngle) + negHalfPI;
var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
var startAngle = me._starts[index];
var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);
Expand Down
5 changes: 1 addition & 4 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,7 @@ module.exports = function(Chart) {
this.chart.options.startAngle :
0;

var startAngleRadians = startAngle * Math.PI * 2 / 360;

// Start from the top instead of right, so remove a quarter of the circle
return index * angleMultiplier + startAngleRadians;
return index * angleMultiplier + helpers.toRadians(startAngle);
},
getDistanceFromCenterForValue: function(value) {
var me = this;
Expand Down
2 changes: 1 addition & 1 deletion test/specs/controller.polarArea.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('Chart.controllers.polarArea', function() {
showLines: true,
legend: false,
title: false,
startAngle: 0, // default is -0.5 * Math.PI
startAngle: 90, // default is 0
elements: {
arc: {
backgroundColor: 'rgb(255, 0, 0)',
Expand Down

0 comments on commit d464ba2

Please sign in to comment.