Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logarithmic: handle null/NaN values #8793

Merged
merged 1 commit into from Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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