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

Treat 0 as a valid point label #6279

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
9 changes: 6 additions & 3 deletions src/scales/scale.radialLinear.js
Expand Up @@ -156,7 +156,7 @@ function fitWithPointLabels(scale) {
var valueCount = getValueCount(scale);
for (i = 0; i < valueCount; i++) {
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]);
scale._pointLabelSizes[i] = textSize;

// Add quarter circle to make degree 0 mean top of circle
Expand Down Expand Up @@ -247,7 +247,7 @@ function drawPointLabels(scale) {
var angle = helpers.toDegrees(angleRadians);
ctx.textAlign = getTextAlignForAngle(angle);
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.lineHeight);
fillText(ctx, scale.pointLabels[i], pointLabelPosition, plFont.lineHeight);
}
ctx.restore();
}
Expand Down Expand Up @@ -348,7 +348,10 @@ module.exports = LinearScaleBase.extend({
LinearScaleBase.prototype.convertTicksToLabels.call(me);

// Point labels
me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
me.pointLabels = me.chart.data.labels.map(function() {
var label = helpers.callback(me.options.pointLabels.callback, arguments, me);
return label || label === 0 ? label : '';
benmccann marked this conversation as resolved.
Show resolved Hide resolved
});
},

getLabelForIndex: function(index, datasetIndex) {
Expand Down
14 changes: 14 additions & 0 deletions test/specs/scale.radialLinear.tests.js
Expand Up @@ -366,6 +366,20 @@ describe('Test the radial linear scale', function() {
expect(chart.scale.pointLabels).toEqual(['0', '1', '2', '3', '4']);
});

it('Should build point labels from falsy values', function() {
var chart = window.acquireChart({
type: 'radar',
data: {
datasets: [{
data: [10, 5, 0, 25, 78, 20]
}],
labels: [0, '', undefined, null, NaN, false]
}
});

expect(chart.scale.pointLabels).toEqual([0, '', '', '', '', '']);
});

it('should correctly set the center point', function() {
var chart = window.acquireChart({
type: 'radar',
Expand Down