Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});