Logarithmic: handle null/NaN values (#8793)

This commit is contained in:
Jukka Kurkela 2021-04-03 15:01:48 +03:00 committed by GitHub
parent 6f6b1b2d17
commit bd1df1bc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

View File

@ -170,6 +170,9 @@ export default class LogarithmicScale extends Scale {
if (value === undefined || value === 0) {
value = me.min;
}
if (value === null || isNaN(value)) {
return NaN;
}
return me.getPixelForDecimal(value === me.min
? 0
: (log10(value) - me._startValue) / me._valueRange);

View File

@ -0,0 +1,49 @@
module.exports = {
config: {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
backgroundColor: 'red',
borderColor: 'red',
fill: false,
data: [
150,
null,
1500,
200,
9000,
3000,
8888
],
spanGaps: true
}, {
backgroundColor: 'blue',
borderColor: 'blue',
fill: false,
data: [
1000,
5500,
800,
7777,
null,
6666,
5555
],
spanGaps: false
}]
},
options: {
responsive: true,
scales: {
x: {
display: false,
},
y: {
display: false,
type: 'logarithmic',
}
}
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -3,6 +3,8 @@ function getLabels(scale) {
}
describe('Logarithmic Scale tests', function() {
describe('auto', jasmine.fixture.specs('scale.logarithmic'));
it('should register', function() {
var Constructor = Chart.registry.getScale('logarithmic');
expect(Constructor).not.toBe(undefined);