Skip to content

Commit

Permalink
fix: timeCat type scale setting values caused an error in chart drawing.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 11, 2018
1 parent 79c2e91 commit d1391bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -67,8 +67,8 @@ temp
.DS_Store
.vscode
.idea
#demos/assets/screenshots
demos/index.html
demos/assets/screenshots
demos/debug.html

*.sw*
Expand Down
4 changes: 2 additions & 2 deletions src/scale/time-cat.js
Expand Up @@ -111,9 +111,9 @@ class TimeCategory extends Category {
const rangeMin = this.rangeMin();
const rangeMax = this.rangeMax();
const index = this.translate(value);
let percent;

if (this.values.length === 1) {
let percent;
if (this.values.length === 1 || isNaN(index)) { // is index is NAN should not be set as 0
percent = index;
} else if (index > -1) {
percent = (index) / (this.values.length - 1);
Expand Down
11 changes: 10 additions & 1 deletion test/unit/scale/cat-spec.js
Expand Up @@ -168,7 +168,7 @@ describe('scale time cat', function() {
it('scale', function() {
expect(scale.scale(1441296000000)).to.be.equal(0);
expect(scale.scale(2)).to.be.equal(1);
expect(scale.scale('2015/10/06')).to.be.equal(0);
expect(scale.scale('2015/10/06')).to.be.NaN;
});

it('invert', function() {
Expand Down Expand Up @@ -230,4 +230,13 @@ describe('scale time cat', function() {
const text = scale.getText('1519084800000');
expect(text).to.be.equal('time is 1519084800000'); // 原始值
});

it('scale scale a value not in scale values', () => {
const scale = new Scale.TimeCat({
values: [ 1519084800000, 1519171200000, 1519257600000 ]
});

const scaledValue = scale.scale(1441296000000);
expect(scaledValue).to.be.NaN;
});
});

0 comments on commit d1391bd

Please sign in to comment.