Skip to content

Commit

Permalink
Ignore invalid log scale min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Feb 9, 2019
1 parent 55128f7 commit f89aa06
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/scales/scale.logarithmic.js
Expand Up @@ -174,8 +174,8 @@ module.exports = Scale.extend({
var DEFAULT_MIN = 1;
var DEFAULT_MAX = 10;

me.min = valueOrDefault(tickOpts.min, me.min);
me.max = valueOrDefault(tickOpts.max, me.max);
me.min = tickOpts.min >= 0 ? tickOpts.min : me.min;
me.max = tickOpts.max >= 0 ? tickOpts.max : me.max;

if (me.min === me.max) {
if (me.min !== 0 && me.min !== null) {
Expand Down Expand Up @@ -211,8 +211,8 @@ module.exports = Scale.extend({
var reverse = !me.isHorizontal();

var generationOptions = {
min: tickOpts.min,
max: tickOpts.max
min: tickOpts.min >= 0 ? tickOpts.min : undefined,
max: tickOpts.max >= 0 ? tickOpts.max : undefined
};
var ticks = me.ticks = generateTicks(generationOptions, me);

Expand Down
32 changes: 32 additions & 0 deletions test/specs/scale.logarithmic.tests.js
Expand Up @@ -477,6 +477,38 @@ describe('Logarithmic Scale tests', function() {
expect(yScale.ticks[tickCount - 1]).toBe(10);
});

it('should ignore invalid min and max options', function() {
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
data: [1, 1, 1, 2, 1, 0]
}],
labels: []
},
options: {
scales: {
yAxes: [{
id: 'yScale',
type: 'logarithmic',
ticks: {
min: -10,
max: -1010,
callback: function(value) {
return value;
}
}
}]
}
}
});

var yScale = chart.scales.yScale;
var tickCount = yScale.ticks.length;
expect(yScale.min).toBe(0);
expect(yScale.max).toBe(2);
});

it('should generate tick marks', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down

0 comments on commit f89aa06

Please sign in to comment.