Permalink
Browse files

fix: timeCat type scale setting values caused an error in chart drawing.

  • Loading branch information...
simaQ committed May 18, 2018
1 parent 79c2e91 commit d1391bd33440e5d817e984a333da268bba8e6a27
Showing with 13 additions and 4 deletions.
  1. +1 −1 .gitignore
  2. +2 −2 src/scale/time-cat.js
  3. +10 −1 test/unit/scale/cat-spec.js
@@ -67,8 +67,8 @@ temp
.DS_Store
.vscode
.idea
#demos/assets/screenshots
demos/index.html
demos/assets/screenshots
demos/debug.html

*.sw*
@@ -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);
@@ -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() {
@@ -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.