Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e94d3c0

Browse files
authored
Merge pull request chartjs#2947 from chartjs/fix/524
Add polar area start angle setting
2 parents a2321d2 + a452094 commit e94d3c0

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

docs/06-Polar-Area-Chart.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ These are the customisation options specific to Polar Area charts. These options
7676

7777
Name | Type | Default | Description
7878
--- | --- | --- | ---
79+
startAngle | Number | -0.5 * Math.PI | Sets the starting angle for the first item in a dataset
7980
scale | Object | [See Scales](#scales) and [Defaults for Radial Linear Scale](#scales-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid.
8081
*scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
8182
*scale*.lineArc | Boolean | true | When true, lines are circular.

src/controllers/controller.polarArea.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = function(Chart) {
2020
animateScale: true
2121
},
2222

23+
startAngle: -0.5 * Math.PI,
2324
aspectRatio: 1,
2425
legendCallback: function(chart) {
2526
var text = [];
@@ -154,9 +155,10 @@ module.exports = function(Chart) {
154155
}
155156
}
156157

157-
var negHalfPI = -0.5 * Math.PI;
158+
//var negHalfPI = -0.5 * Math.PI;
159+
var datasetStartAngle = opts.startAngle;
158160
var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
159-
var startAngle = (negHalfPI) + (circumference * visibleCount);
161+
var startAngle = datasetStartAngle + (circumference * visibleCount);
160162
var endAngle = startAngle + (arc.hidden ? 0 : circumference);
161163

162164
var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
@@ -173,8 +175,8 @@ module.exports = function(Chart) {
173175
y: centerY,
174176
innerRadius: 0,
175177
outerRadius: reset ? resetRadius : distance,
176-
startAngle: reset && animationOpts.animateRotate ? negHalfPI : startAngle,
177-
endAngle: reset && animationOpts.animateRotate ? negHalfPI : endAngle,
178+
startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
179+
endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
178180
label: getValueAtIndexOrDefault(labels, index, labels[index])
179181
}
180182
});

test/controller.polarArea.tests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,52 @@ describe('Polar area controller tests', function() {
159159
}));
160160
});
161161

162+
it('should update elements with start angle from options', function() {
163+
var chart = window.acquireChart({
164+
type: 'polarArea',
165+
data: {
166+
datasets: [{
167+
data: [10, 15, 0, -4],
168+
label: 'dataset2'
169+
}],
170+
labels: ['label1', 'label2', 'label3', 'label4']
171+
},
172+
options: {
173+
showLines: true,
174+
startAngle: 0, // default is -0.5 * Math.PI
175+
elements: {
176+
arc: {
177+
backgroundColor: 'rgb(255, 0, 0)',
178+
borderColor: 'rgb(0, 255, 0)',
179+
borderWidth: 1.2
180+
}
181+
}
182+
}
183+
});
184+
185+
var meta = chart.getDatasetMeta(0);
186+
expect(meta.data.length).toBe(4);
187+
188+
[ { o: 156, s: 0, e: 0.5 * Math.PI },
189+
{ o: 211, s: 0.5 * Math.PI, e: Math.PI },
190+
{ o: 45, s: Math.PI, e: 1.5 * Math.PI },
191+
{ o: 0, s: 1.5 * Math.PI, e: 2.0 * Math.PI }
192+
].forEach(function(expected, i) {
193+
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
194+
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
195+
expect(meta.data[i]._model.innerRadius).toBeCloseToPixel(0);
196+
expect(meta.data[i]._model.outerRadius).toBeCloseToPixel(expected.o);
197+
expect(meta.data[i]._model.startAngle).toBe(expected.s);
198+
expect(meta.data[i]._model.endAngle).toBe(expected.e);
199+
expect(meta.data[i]._model).toEqual(jasmine.objectContaining({
200+
backgroundColor: 'rgb(255, 0, 0)',
201+
borderColor: 'rgb(0, 255, 0)',
202+
borderWidth: 1.2,
203+
label: chart.data.labels[i]
204+
}));
205+
});
206+
});
207+
162208
it('should handle number of data point changes in update', function() {
163209
var chart = window.acquireChart({
164210
type: 'polarArea',

0 commit comments

Comments
 (0)