Skip to content

Commit

Permalink
Move startAngle to scale options (#8593)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle authored Mar 8, 2021
1 parent 275fdaf commit 7ec99c3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/docs/axes/radial/linear.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Namespace: `options.scales[scaleId]`
| `angleLines` | `object` | | Angle line configuration. [more...](#angle-line-options)
| `beginAtZero` | `boolean` | `false` | if true, scale will include 0 if it is not already included.
| `pointLabels` | `object` | | Point label configuration. [more...](#point-label-options)
| `startAngle` | `number` | `0` | Starting angle of the scale. In degrees, 0 is at top.

<CommonAll />

Expand Down
1 change: 0 additions & 1 deletion docs/docs/charts/polar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ These are the customisation options specific to Polar Area charts. These options

| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `startAngle` | `number` | `0` | Starting angle to draw arcs for the first item in a dataset. In degrees, 0 is at 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
1 change: 1 addition & 0 deletions docs/docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ A number of changes were made to the configuration options passed to the `Chart`
* `scales.[x/y]Axes.zeroLine*` options of axes were removed. Use scriptable scale options instead.
* The dataset option `steppedLine` was removed. Use `stepped`
* The chart option `showLines` was renamed to `showLine` to match the dataset option.
* The chart option `startAngle` was moved to `radial` scale options.
* To override the platform class used in a chart instance, pass `platform: PlatformClass` in the config object. Note that the class should be passed, not an instance of the class.
* `aspectRatio` defaults to 1 for doughnut, pie, polarArea, and radar charts
* `TimeScale` does not read `t` from object data by default anymore. The default property is `x` or `y`, depending on the orientation. See [data structures](../general/data-structures.md) for details on how to change the default.
Expand Down
11 changes: 3 additions & 8 deletions src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import DatasetController from '../core/core.datasetController';
import {toRadians, PI} from '../helpers/index';

function getStartAngleRadians(deg) {
// radialLinear scale draws angleLines using startAngle. 0 is expected to be at top.
// Here we adjust to standard unit circle used in drawing, where 0 is at right.
return toRadians(deg) - 0.5 * PI;
}

export default class PolarAreaController extends DatasetController {

constructor(chart, datasetIndex) {
Expand Down Expand Up @@ -51,7 +45,7 @@ export default class PolarAreaController extends DatasetController {
const scale = me._cachedMeta.rScale;
const centerX = scale.xCenter;
const centerY = scale.yCenter;
const datasetStartAngle = getStartAngleRadians(opts.startAngle);
const datasetStartAngle = scale.getIndexAngle(0) - 0.5 * PI;
let angle = datasetStartAngle;
let i;

Expand Down Expand Up @@ -198,7 +192,8 @@ PolarAreaController.overrides = {
},
pointLabels: {
display: false
}
},
startAngle: 0
}
}
};
9 changes: 4 additions & 5 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,8 @@ export default class RadialLinearScale extends LinearScaleBase {
}

getIndexAngle(index) {
const chart = this.chart;
const angleMultiplier = TAU / chart.data.labels.length;
const options = chart.options || {};
const startAngle = options.startAngle || 0;

const angleMultiplier = TAU / this.getLabels().length;
const startAngle = this.options.startAngle || 0;
return _normalizeAngle(index * angleMultiplier + toRadians(startAngle));
}

Expand Down Expand Up @@ -564,6 +561,8 @@ RadialLinearScale.defaults = {
circular: false
},

startAngle: 0,

// label settings
ticks: {
// Boolean - Show a backdrop to the scale label
Expand Down
6 changes: 5 additions & 1 deletion test/specs/controller.polarArea.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ describe('Chart.controllers.polarArea', function() {
legend: false,
title: false,
},
startAngle: 90, // default is 0
scales: {
r: {
startAngle: 90, // default is 0
}
},
elements: {
arc: {
backgroundColor: 'rgb(255, 0, 0)',
Expand Down
8 changes: 5 additions & 3 deletions test/specs/scale.radialLinear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('Test the radial linear scale', function() {
circular: false
},

startAngle: 0,

ticks: {
color: Chart.defaults.color,
showLabelBackdrop: true,
Expand Down Expand Up @@ -500,14 +502,14 @@ describe('Test the radial linear scale', function() {
options: {
scales: {
r: {
startAngle: 15,
pointLabels: {
callback: function(value, index) {
return index.toString();
}
}
}
},
startAngle: 15
}
});

Expand All @@ -521,7 +523,7 @@ describe('Test the radial linear scale', function() {
expect(radToNearestDegree(chart.scales.r.getIndexAngle(i))).toBe(15 + (slice * i));
}

chart.options.startAngle = 0;
chart.scales.r.options.startAngle = 0;
chart.update();

for (var x = 0; x < 5; x++) {
Expand Down Expand Up @@ -569,7 +571,7 @@ describe('Test the radial linear scale', function() {
textAlign: ['right', 'right', 'left', 'left', 'left'],
y: [82, 366, 506, 319, 53]
}].forEach(function(expected) {
chart.options.startAngle = expected.startAngle;
scale.options.startAngle = expected.startAngle;
chart.update();

scale.ctx = window.createMockContext();
Expand Down

0 comments on commit 7ec99c3

Please sign in to comment.