]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Time scale: skip invalid data (#8508)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Tue, 23 Feb 2021 20:31:43 +0000 (22:31 +0200)
committerGitHub <noreply@github.com>
Tue, 23 Feb 2021 20:31:43 +0000 (15:31 -0500)
src/scales/scale.time.js
test/fixtures/scale.time/invalid-data.js [new file with mode: 0644]
test/fixtures/scale.time/invalid-data.png [new file with mode: 0644]

index b4f702d254e7154a0ef97da10c5c1eadc6fba81b..52ead35238e55bec28e3b7a7157e766fe688c981 100644 (file)
@@ -47,7 +47,7 @@ function sorter(a, b) {
  */
 function parse(scale, input) {
   if (isNullOrUndef(input)) {
-    return null;
+    return NaN;
   }
 
   const adapter = scale._adapter;
@@ -67,7 +67,7 @@ function parse(scale, input) {
   }
 
   if (value === null) {
-    return value;
+    return NaN;
   }
 
   if (round) {
diff --git a/test/fixtures/scale.time/invalid-data.js b/test/fixtures/scale.time/invalid-data.js
new file mode 100644 (file)
index 0000000..fa5faad
--- /dev/null
@@ -0,0 +1,50 @@
+module.exports = {
+  description: 'Invalid data, https://github.com/chartjs/Chart.js/issues/5563',
+  config: {
+    type: 'line',
+    data: {
+      datasets: [{
+        data: [{
+          x: '14:45:00',
+          y: 20,
+        }, {
+          x: '20:30:00',
+          y: 10,
+        }, {
+          x: '25:15:00',
+          y: 15,
+        }, {
+          x: null,
+          y: 15,
+        }, {
+          x: undefined,
+          y: 15,
+        }, {
+          x: NaN,
+          y: 15,
+        }, {
+          x: 'monday',
+          y: 15,
+        }],
+      }]
+    },
+    options: {
+      scales: {
+        x: {
+          type: 'time',
+          time: {
+            parser: 'HH:mm:ss',
+            unit: 'hour'
+          },
+        },
+      },
+      layout: {
+        padding: 16
+      }
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {width: 1000, height: 200}
+  }
+};
diff --git a/test/fixtures/scale.time/invalid-data.png b/test/fixtures/scale.time/invalid-data.png
new file mode 100644 (file)
index 0000000..1cdd9b9
Binary files /dev/null and b/test/fixtures/scale.time/invalid-data.png differ