Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix point label counting in radialLinear scale #6280

Merged
merged 1 commit into from May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -400,8 +395,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 @@ -485,7 +481,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.