]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Treat 0 as a valid point label for radial scale (#6279)
authorAkihiko Kusanagi <nagi@nagi-p.com>
Thu, 16 May 2019 18:17:46 +0000 (19:17 +0100)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Thu, 16 May 2019 18:17:46 +0000 (20:17 +0200)
src/scales/scale.radialLinear.js
test/specs/scale.radialLinear.tests.js

index 47b1089d93de8dbf6b941bea9667fe86e3210d37..75dcb09192f26cb349bd864a0f3e867e55e018ef 100644 (file)
@@ -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
@@ -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();
 }
@@ -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 : '';
+               });
        },
 
        getLabelForIndex: function(index, datasetIndex) {
index 1a7761808dd7e3e1fa036b35eff7324a1770c444..4413cdd55dce1ac4e0eec9bc585ea0cad4f4f6c8 100644 (file)
@@ -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',