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
.idea
.vscode
bower.json
+
+*.swp
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
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
},
});
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');
});