Skip to content

Commit

Permalink
Logarithmic: handle null/NaN values (chartjs#8793)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Apr 4, 2021
1 parent 98e890c commit e4142d8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/scales/scale.logarithmic.js
Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions test/fixtures/scale.logarithmic/null-values.js
@@ -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 added test/fixtures/scale.logarithmic/null-values.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/specs/scale.logarithmic.tests.js
Expand Up @@ -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);
Expand Down

0 comments on commit e4142d8

Please sign in to comment.