Skip to content

Commit

Permalink
Polar area: startAngle in degrees, 0 at top.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jan 5, 2019
1 parent 87e44fa commit a18471b
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 @@ -68,7 +68,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 expects 0 to be at top

for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
starts[i] = start;
Expand Down Expand Up @@ -170,8 +171,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 @@ -424,10 +424,7 @@ module.exports = LinearScaleBase.extend({
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) {
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 a18471b

Please sign in to comment.