Skip to content

Commit

Permalink
fix: fix the error caused by empty data.Closed #238.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Aug 13, 2018
1 parent 0f04a79 commit 09de761
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/geom/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,15 @@ class Geom extends Base {
const shapeFactory = self.getShapeFactory();
shapeFactory.setCoord(self.get('coord'));
self._beforeMapping(dataArray);
// let shapes = [];
for (let i = 0, len = dataArray.length; i < len; i++) {
let data = dataArray[i];
data = self._mapping(data);
mappedArray.push(data);
self.draw(data, shapeFactory);
// shapes = shapes.concat(drawedShapes);
if (data.length) {
data = self._mapping(data);
mappedArray.push(data);
self.draw(data, shapeFactory);
}
}
self.set('dataArray', mappedArray);
// self.set('shapes', shapes);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/bug/issue-234-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ describe('issue 234', () => {

const tooltipMarker = markerGroup.get('children')[0];
expect(tooltipMarker.get('type')).to.equal('rect');

chart.destroy();
document.body.removeChild(canvas);
});
});
3 changes: 3 additions & 0 deletions test/bug/issue-235-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ describe('issue 235', () => {
const areaShape = geomContainer.get('children')[0];
expect(areaShape.attr('points')).to.be.an.instanceof(Array);
expect(areaShape.attr('points').length).to.equal(14);

chart.destroy();
document.body.removeChild(canvas);
});
});
28 changes: 28 additions & 0 deletions test/bug/issue-238-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const expect = require('chai').expect;
const F2 = require('../../src/core');
require('../../src/geom/area');

const canvas = document.createElement('canvas');
canvas.width = 375;
canvas.height = 260;
canvas.id = 'issue238';
document.body.appendChild(canvas);

describe('issue 238', () => {
it('Empty data cause error.', () => {
let chart;
const creatFunc = function() {
chart = new F2.Chart({
id: 'issue238',
pixelRatio: window.devicePixelRatio
});
chart.source([]);
chart.area().position('day*value').shape('smooth');
chart.render();
};
expect(creatFunc).not.to.throw();

chart.destroy();
document.body.removeChild(canvas);
});
});

0 comments on commit 09de761

Please sign in to comment.