Skip to content

Commit

Permalink
fix: linear NaN error
Browse files Browse the repository at this point in the history
  • Loading branch information
cycgit committed Aug 19, 2020
1 parent 34e170e commit 482c49d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/scale/linear-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const SNAP_COUNT_ARRAY = [ 1, 1.2, 1.5, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10
const DEFAULT_COUNT = 5; // 默认刻度值

export default cfg => {
const { min, max, tickCount, tickInterval } = cfg || {};
const { tickCount, tickInterval } = cfg || {};
let { min, max } = cfg || {};
min = isNaN(min) ? 0 : min;
max = isNaN(max) ? 0 : max;

let count = tickCount && tickCount >= 2 ? tickCount : DEFAULT_COUNT;

Expand Down
8 changes: 8 additions & 0 deletions test/unit/scale/linear-tick-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ describe('linear-tick', function() {
expect(tick).toEqual([ 0, 1, 2, 3, 4 ]);
});

it('max === min NaN', function() {
const tick = linearTick({
min: NaN,
max: NaN
});
expect(tick).toEqual([ 0, 1, 2, 3, 4 ]);
});

it('recursive to best ticks', function() {
const tick = linearTick({
min: -0.001,
Expand Down

0 comments on commit 482c49d

Please sign in to comment.