From bbd4364f64edc6e74d023b9b60972543085a1075 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 24 Apr 2016 09:14:21 -0400 Subject: [PATCH] Only use valid label moments --- src/scales/scale.time.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 2dbb4ba6d..45ce64b43 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -86,10 +86,13 @@ module.exports = function(Chart) { if (this.chart.data.labels && this.chart.data.labels.length > 0) { helpers.each(this.chart.data.labels, function(label, index) { var labelMoment = this.parseTime(label); - if (this.options.time.round) { - labelMoment.startOf(this.options.time.round); + + if (labelMoment.isValid()) { + if (this.options.time.round) { + labelMoment.startOf(this.options.time.round); + } + scaleLabelMoments.push(labelMoment); } - scaleLabelMoments.push(labelMoment); }, this); this.firstTick = moment.min.call(this, scaleLabelMoments); @@ -105,14 +108,17 @@ module.exports = function(Chart) { if (typeof dataset.data[0] === 'object') { helpers.each(dataset.data, function(value, index) { var labelMoment = this.parseTime(this.getRightValue(value)); - if (this.options.time.round) { - labelMoment.startOf(this.options.time.round); - } - momentsForDataset.push(labelMoment); - // May have gone outside the scale ranges, make sure we keep the first and last ticks updated - this.firstTick = this.firstTick !== null ? moment.min(this.firstTick, labelMoment) : labelMoment; - this.lastTick = this.lastTick !== null ? moment.max(this.lastTick, labelMoment) : labelMoment; + if (labelMoment.isValid()) { + if (this.options.time.round) { + labelMoment.startOf(this.options.time.round); + } + momentsForDataset.push(labelMoment); + + // May have gone outside the scale ranges, make sure we keep the first and last ticks updated + this.firstTick = this.firstTick !== null ? moment.min(this.firstTick, labelMoment) : labelMoment; + this.lastTick = this.lastTick !== null ? moment.max(this.lastTick, labelMoment) : labelMoment; + } }, this); } else { // We have no labels. Use the ones from the scale -- 2.47.2