mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Merge pull request #3039 from ianks/getLabelMoment-fix
Fix out of bounds index access in getLabelMoment
This commit is contained in:
commit
8e2deede5b
@ -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;
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user