Skip to content

Commit e35b889

Browse files
nagixsimonbrunel
authored andcommitted
Treat 0 as a valid point label for radial scale (#6279)
1 parent e5c68e2 commit e35b889

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/scales/scale.radialLinear.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function fitWithPointLabels(scale) {
156156
var valueCount = getValueCount(scale);
157157
for (i = 0; i < valueCount; i++) {
158158
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
159-
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i] || '');
159+
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
160160
scale._pointLabelSizes[i] = textSize;
161161

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

350350
// Point labels
351-
me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
351+
me.pointLabels = me.chart.data.labels.map(function() {
352+
var label = helpers.callback(me.options.pointLabels.callback, arguments, me);
353+
return label || label === 0 ? label : '';
354+
});
352355
},
353356

354357
getLabelForIndex: function(index, datasetIndex) {

test/specs/scale.radialLinear.tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,20 @@ describe('Test the radial linear scale', function() {
366366
expect(chart.scale.pointLabels).toEqual(['0', '1', '2', '3', '4']);
367367
});
368368

369+
it('Should build point labels from falsy values', function() {
370+
var chart = window.acquireChart({
371+
type: 'radar',
372+
data: {
373+
datasets: [{
374+
data: [10, 5, 0, 25, 78, 20]
375+
}],
376+
labels: [0, '', undefined, null, NaN, false]
377+
}
378+
});
379+
380+
expect(chart.scale.pointLabels).toEqual([0, '', '', '', '', '']);
381+
});
382+
369383
it('should correctly set the center point', function() {
370384
var chart = window.acquireChart({
371385
type: 'radar',

0 commit comments

Comments
 (0)