Skip to content

Commit

Permalink
fix(scale): fixed bug of first record with null
Browse files Browse the repository at this point in the history
  • Loading branch information
dxq613 committed Dec 5, 2017
1 parent 00f32bc commit f94cf37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/chart/assist/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ class ScaleAssist {
return scale;
}
const firstObj = data[0];
let firstValue = firstObj[field];
if (firstValue === null) {
firstValue = Util.Array.firstValue(data, field);
}

if (Util.isNumber(field) || (Util.isNil(firstObj[field])) && !def) {
if (Util.isNumber(field) || (Util.isNil(firstValue)) && !def) {
scale = Scale.identity({
value: field,
field: field.toString(),
Expand Down
10 changes: 10 additions & 0 deletions test/unit/geom/geom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ describe('test geom line', function() {
geom.paint();
});

it('first null line', function() {
clearCanvas(canvas);
const data = [{ a: 1, b: null, c: '1' }, { a: 4, b: null, c: '1' }, { a: 2, b: 2, c: '2' }, { a: 3, b: 4, c: '1' }, { a: 2.5, b: 3.5, c: '1' }];
geom.reset();
geom.set('data', data);
geom.position('a*b');
geom.init();
geom.paint();
});

it('destroy & reset', function() {
geom.destroy();
expect(geom.destroyed).equal(true);
Expand Down

0 comments on commit f94cf37

Please sign in to comment.