]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Only use valid label moments 2345/head
authorEvert Timberg <evert.timberg+github@gmail.com>
Sun, 24 Apr 2016 13:14:21 +0000 (09:14 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 24 Apr 2016 13:14:21 +0000 (09:14 -0400)
src/scales/scale.time.js

index 2dbb4ba6d4d067e2a24b5772d6517072b0737a53..45ce64b43d707d06b1db135b421feb578aaa4d96 100644 (file)
@@ -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