From: Evert Timberg Date: Sun, 24 Apr 2016 13:14:21 +0000 (-0400) Subject: Only use valid label moments X-Git-Tag: 2.1.0~47^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2345%2Fhead;p=thirdparty%2FChart.js.git Only use valid label moments --- 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