Skip to content

Commit

Permalink
fix: when chart is clear, chart.getSnapRecords() should not be affected.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed May 17, 2018
1 parent e578106 commit 1dbdd79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ class Chart extends Base {
**/
getSnapRecords(point) {
const geom = this.get('geoms')[0];
const data = geom.getSnapRecords(point);
let data = [];
if (geom) { // need to judge
data = geom.getSnapRecords(point);
}
return data;
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/chart/chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ describe('chart test', () => {
const backPlot = chart.get('backPlot');
expect(frontPlot.get('children').length).to.equal(1);
expect(backPlot.get('children').length).to.equal(1);

// chart be cleared, check the robustness of getSnapRecords method
let data;
const throwFn = () => {
try {
data = chart.getSnapRecords({ x: 250, y: 150 });
} catch (err) {
throw new Error(err);
}
};
expect(throwFn).to.not.throw();
expect(data).to.be.an('array').that.is.empty;
});

it('change coord', function() {
Expand Down

0 comments on commit 1dbdd79

Please sign in to comment.