]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fixed Issue with tooltip label display when given null data value (#3528)
authorJerry Chang <therealjerrycan@gmail.com>
Mon, 31 Oct 2016 00:34:06 +0000 (17:34 -0700)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 19 Nov 2016 14:29:15 +0000 (09:29 -0500)
When datasets.data contains a null value, the label displays incorrect
value.

code additions:
- unit tests for truthy label values (when data is null)
- checks to ensure handling of null value in getLabelByIndex method

added mock data sets from issue #3528 example

expect the return value from getLabelForIndex method to be valid (truthy)

added check for null of first data value in getLabelForIndex

fixed indentation and null comparison operator in code

fixed mistake in definition of firstData variable

changed testing for data on index 0 to using index variable

changed firstData to use value instead

condense the statments to use value variable

.gitignore
src/scales/scale.time.js
test/scale.time.tests.js

index 8ef0139ea96b216d8e52c67fbd276c8adb55c4be..172413437e6c875b482719d6e49c91b2dbb6e260 100644 (file)
@@ -8,3 +8,5 @@
 .idea
 .vscode
 bower.json
+
+*.swp
index 0057dd92aea654b534b933850426c1037e2084d6..61796c6ebcc634c0d058bea63b610ed661945ee5 100755 (executable)
@@ -360,9 +360,10 @@ module.exports = function(Chart) {
                getLabelForIndex: function(index, datasetIndex) {
                        var me = this;
                        var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
+                       var value = me.chart.data.datasets[datasetIndex].data[index];
 
-                       if (typeof me.chart.data.datasets[datasetIndex].data[0] === 'object') {
-                               label = me.getRightValue(me.chart.data.datasets[datasetIndex].data[index]);
+                       if (value !== null && typeof value === 'object') {
+                               label = me.getRightValue(value);
                        }
 
                        // Format nicely
index 896ff00d4f78e54439833a48102875c65501dde5..d3d5d7b7f8be3afaae40fb4ecabc9eff7ee4f518 100755 (executable)
@@ -428,7 +428,7 @@ describe('Time scale tests', function() {
                                datasets: [{
                                        xAxisID: 'xScale0',
                                        yAxisID: 'yScale0',
-                                       data: []
+                                       data: [null, 10, 3]
                                }],
                                labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days
                        },
@@ -449,6 +449,7 @@ describe('Time scale tests', function() {
                });
 
                var xScale = chart.scales.xScale0;
+               expect(xScale.getLabelForIndex(0, 0)).toBeTruthy();
                expect(xScale.getLabelForIndex(0, 0)).toBe('2015-01-01T20:00:00');
                expect(xScale.getLabelForIndex(6, 0)).toBe('2015-01-10T12:00');
        });