From: Jukka Kurkela Date: Tue, 23 Feb 2021 20:31:43 +0000 (+0200) Subject: Time scale: skip invalid data (#8508) X-Git-Tag: v3.0.0-beta.12~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4207645a9a6a424b1cec6c53cd0d98d5402f9d1c;p=thirdparty%2FChart.js.git Time scale: skip invalid data (#8508) --- diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index b4f702d25..52ead3523 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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 index 000000000..fa5faadca --- /dev/null +++ b/test/fixtures/scale.time/invalid-data.js @@ -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 index 000000000..1cdd9b95d Binary files /dev/null and b/test/fixtures/scale.time/invalid-data.png differ