Skip to content

Commit 9585024

Browse files
nagixsimonbrunel
authored andcommitted
Fix point label counting in radialLinear scale (chartjs#6280)
1 parent cc1c98b commit 9585024

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

src/scales/scale.radialLinear.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ var defaultConfig = {
5959
}
6060
};
6161

62-
function getValueCount(scale) {
63-
var opts = scale.options;
64-
return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
65-
}
66-
6762
function getTickBackdropHeight(opts) {
6863
var tickOpts = opts.ticks;
6964

@@ -153,7 +148,7 @@ function fitWithPointLabels(scale) {
153148
scale.ctx.font = plFont.string;
154149
scale._pointLabelSizes = [];
155150

156-
var valueCount = getValueCount(scale);
151+
var valueCount = scale.chart.data.labels.length;
157152
for (i = 0; i < valueCount; i++) {
158153
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
159154
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
@@ -234,7 +229,7 @@ function drawPointLabels(scale) {
234229
ctx.font = plFont.string;
235230
ctx.textBaseline = 'middle';
236231

237-
for (var i = getValueCount(scale) - 1; i >= 0; i--) {
232+
for (var i = scale.chart.data.labels.length - 1; i >= 0; i--) {
238233
// Extra pixels out for some label spacing
239234
var extra = (i === 0 ? tickBackdropHeight / 2 : 0);
240235
var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
@@ -255,7 +250,7 @@ function drawPointLabels(scale) {
255250
function drawRadiusLine(scale, gridLineOpts, radius, index) {
256251
var ctx = scale.ctx;
257252
var circular = gridLineOpts.circular;
258-
var valueCount = getValueCount(scale);
253+
var valueCount = scale.chart.data.labels.length;
259254
var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1);
260255
var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
261256
var pointPosition;
@@ -403,8 +398,9 @@ module.exports = LinearScaleBase.extend({
403398
},
404399

405400
getIndexAngle: function(index) {
406-
var angleMultiplier = 360 / getValueCount(this);
407-
var options = this.chart.options || {};
401+
var chart = this.chart;
402+
var angleMultiplier = 360 / chart.data.labels.length;
403+
var options = chart.options || {};
408404
var startAngle = options.startAngle || 0;
409405

410406
// Start from the top instead of right, so remove a quarter of the circle
@@ -488,7 +484,7 @@ module.exports = LinearScaleBase.extend({
488484
ctx.lineDashOffset = resolve([angleLineOpts.borderDashOffset, gridLineOpts.borderDashOffset, 0.0]);
489485
}
490486

491-
for (i = getValueCount(me) - 1; i >= 0; i--) {
487+
for (i = me.chart.data.labels.length - 1; i >= 0; i--) {
492488
offset = me.getDistanceFromCenterForValue(opts.ticks.reverse ? me.min : me.max);
493489
position = me.getPointPosition(i, offset);
494490
ctx.beginPath();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"config": {
3+
"type": "radar",
4+
"data": {
5+
"labels": ["A", "B", "C", "D", "E"]
6+
},
7+
"options": {
8+
"responsive": false,
9+
"legend": false,
10+
"title": false,
11+
"scale": {
12+
"gridLines": {
13+
"color": "rgb(0, 0, 0)",
14+
"lineWidth": 1
15+
},
16+
"angleLines": {
17+
"display": false
18+
},
19+
"pointLabels": {
20+
"display": false
21+
},
22+
"ticks": {
23+
"display": false
24+
}
25+
}
26+
}
27+
}
28+
}
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"config": {
3+
"type": "radar",
4+
"data": {
5+
"labels": ["A", "B", "C", "D", "E"]
6+
},
7+
"options": {
8+
"responsive": false,
9+
"legend": false,
10+
"title": false,
11+
"scale": {
12+
"gridLines": {
13+
"display": false
14+
},
15+
"angleLines": {
16+
"color": "rgb(0, 0, 0)",
17+
"lineWidth": 1
18+
},
19+
"pointLabels": {
20+
"display": false
21+
},
22+
"ticks": {
23+
"display": false
24+
}
25+
}
26+
}
27+
}
28+
}
Loading

0 commit comments

Comments
 (0)