Skip to content

Commit

Permalink
Fix point label counting in radialLinear scale (chartjs#6280)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix authored and simonbrunel committed May 16, 2019
1 parent cc1c98b commit 9585024
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/scales/scale.radialLinear.js
Expand Up @@ -59,11 +59,6 @@ var defaultConfig = {
}
};

function getValueCount(scale) {
var opts = scale.options;
return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
}

function getTickBackdropHeight(opts) {
var tickOpts = opts.ticks;

Expand Down Expand Up @@ -153,7 +148,7 @@ function fitWithPointLabels(scale) {
scale.ctx.font = plFont.string;
scale._pointLabelSizes = [];

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

for (var i = getValueCount(scale) - 1; i >= 0; i--) {
for (var i = scale.chart.data.labels.length - 1; i >= 0; i--) {
// Extra pixels out for some label spacing
var extra = (i === 0 ? tickBackdropHeight / 2 : 0);
var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
Expand All @@ -255,7 +250,7 @@ function drawPointLabels(scale) {
function drawRadiusLine(scale, gridLineOpts, radius, index) {
var ctx = scale.ctx;
var circular = gridLineOpts.circular;
var valueCount = getValueCount(scale);
var valueCount = scale.chart.data.labels.length;
var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1);
var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
var pointPosition;
Expand Down Expand Up @@ -403,8 +398,9 @@ module.exports = LinearScaleBase.extend({
},

getIndexAngle: function(index) {
var angleMultiplier = 360 / getValueCount(this);
var options = this.chart.options || {};
var chart = this.chart;
var angleMultiplier = 360 / chart.data.labels.length;
var options = chart.options || {};
var startAngle = options.startAngle || 0;

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

for (i = getValueCount(me) - 1; i >= 0; i--) {
for (i = me.chart.data.labels.length - 1; i >= 0; i--) {
offset = me.getDistanceFromCenterForValue(opts.ticks.reverse ? me.min : me.max);
position = me.getPointPosition(i, offset);
ctx.beginPath();
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/scale.radialLinear/anglelines-disable.json
@@ -0,0 +1,28 @@
{
"config": {
"type": "radar",
"data": {
"labels": ["A", "B", "C", "D", "E"]
},
"options": {
"responsive": false,
"legend": false,
"title": false,
"scale": {
"gridLines": {
"color": "rgb(0, 0, 0)",
"lineWidth": 1
},
"angleLines": {
"display": false
},
"pointLabels": {
"display": false
},
"ticks": {
"display": false
}
}
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions test/fixtures/scale.radialLinear/gridlines-disable.json
@@ -0,0 +1,28 @@
{
"config": {
"type": "radar",
"data": {
"labels": ["A", "B", "C", "D", "E"]
},
"options": {
"responsive": false,
"legend": false,
"title": false,
"scale": {
"gridLines": {
"display": false
},
"angleLines": {
"color": "rgb(0, 0, 0)",
"lineWidth": 1
},
"pointLabels": {
"display": false
},
"ticks": {
"display": false
}
}
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9585024

Please sign in to comment.