Merge pull request #3039 from ianks/getLabelMoment-fix

Fix out of bounds index access in getLabelMoment
This commit is contained in:
Evert Timberg 2016-07-26 20:57:34 -04:00 committed by GitHub
commit 8e2deede5b
2 changed files with 34 additions and 1 deletions

View File

@ -76,7 +76,11 @@ module.exports = function(Chart) {
Chart.Scale.prototype.initialize.call(this);
},
getLabelMoment: function(datasetIndex, index) {
return this.labelMoments[datasetIndex][index];
if (typeof this.labelMoments[datasetIndex] != 'undefined') {
return this.labelMoments[datasetIndex][index];
}
return null;
},
getMomentStartOf: function(tick) {
var me = this;

View File

@ -479,4 +479,33 @@ describe('Time scale tests', function() {
threshold: 0.75
});
});
it("should not throw an error if the datasetIndex is out of bounds", function() {
var chart = window.acquireChart({
type: 'line',
data: {
labels: ["2016-06-26"],
datasets: [{
type: "line",
data: [5]
}]
},
options: {
scales: {
xAxes: [{
display: true,
type: "time",
}]
}
}
});
var xScale = chartInstance.scales.xScale0;
var getOutOfBoundPixelForValue = function() {
xScale.getLabelMoment(12, 0);
};
expect(getOutOfBoundPixelForValue).not.toThrow();
});
});