Fix point label counting in radialLinear scale (#6280)

This commit is contained in:
Akihiko Kusanagi 2019-05-16 19:34:43 +01:00 committed by Simon Brunel
parent e35b8891ce
commit 9482ee55eb
5 changed files with 63 additions and 11 deletions

View File

@ -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) { function getTickBackdropHeight(opts) {
var tickOpts = opts.ticks; var tickOpts = opts.ticks;
@ -153,7 +148,7 @@ function fitWithPointLabels(scale) {
scale.ctx.font = plFont.string; scale.ctx.font = plFont.string;
scale._pointLabelSizes = []; scale._pointLabelSizes = [];
var valueCount = getValueCount(scale); var valueCount = scale.chart.data.labels.length;
for (i = 0; i < valueCount; i++) { for (i = 0; i < valueCount; i++) {
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5); pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]); textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
@ -234,7 +229,7 @@ function drawPointLabels(scale) {
ctx.font = plFont.string; ctx.font = plFont.string;
ctx.textBaseline = 'middle'; 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 // Extra pixels out for some label spacing
var extra = (i === 0 ? tickBackdropHeight / 2 : 0); var extra = (i === 0 ? tickBackdropHeight / 2 : 0);
var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5); var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
@ -255,7 +250,7 @@ function drawPointLabels(scale) {
function drawRadiusLine(scale, gridLineOpts, radius, index) { function drawRadiusLine(scale, gridLineOpts, radius, index) {
var ctx = scale.ctx; var ctx = scale.ctx;
var circular = gridLineOpts.circular; var circular = gridLineOpts.circular;
var valueCount = getValueCount(scale); var valueCount = scale.chart.data.labels.length;
var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1); var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1);
var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1); var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
var pointPosition; var pointPosition;
@ -403,8 +398,9 @@ module.exports = LinearScaleBase.extend({
}, },
getIndexAngle: function(index) { getIndexAngle: function(index) {
var angleMultiplier = 360 / getValueCount(this); var chart = this.chart;
var options = this.chart.options || {}; var angleMultiplier = 360 / chart.data.labels.length;
var options = chart.options || {};
var startAngle = options.startAngle || 0; var startAngle = options.startAngle || 0;
// Start from the top instead of right, so remove a quarter of the circle // Start from the top instead of right, so remove a quarter of the circle
@ -488,7 +484,7 @@ module.exports = LinearScaleBase.extend({
ctx.lineDashOffset = resolve([angleLineOpts.borderDashOffset, gridLineOpts.borderDashOffset, 0.0]); 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); offset = me.getDistanceFromCenterForValue(opts.ticks.reverse ? me.min : me.max);
position = me.getPointPosition(i, offset); position = me.getPointPosition(i, offset);
ctx.beginPath(); ctx.beginPath();

View File

@ -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
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -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
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB