Skip to content

Commit

Permalink
Fix #6892 (brush throws error if data has empty)
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Nov 1, 2017
1 parent 31243cd commit a546941
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/component/brush/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ var selector = {
lineY: getLineSelectors(1),
rect: {
point: function (itemLayout, selectors, area) {
return area.boundingRect.contain(itemLayout[0], itemLayout[1]);
return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
},
rect: function (itemLayout, selectors, area) {
return area.boundingRect.intersect(itemLayout);
return itemLayout && area.boundingRect.intersect(itemLayout);
}
},
polygon: {
point: function (itemLayout, selectors, area) {
return area.boundingRect.contain(itemLayout[0], itemLayout[1])
return itemLayout
&& area.boundingRect.contain(itemLayout[0], itemLayout[1])
&& polygonContain.contain(area.range, itemLayout[0], itemLayout[1]);
},
rect: function (itemLayout, selectors, area) {
var points = area.range;

if (points.length <= 1) {
if (!itemLayout || points.length <= 1) {
return false;
}

Expand Down Expand Up @@ -61,21 +62,25 @@ function getLineSelectors(xyIndex) {

return {
point: function (itemLayout, selectors, area) {
var range = area.range;
var p = itemLayout[xyIndex];
return inLineRange(p, range);
if (itemLayout) {
var range = area.range;
var p = itemLayout[xyIndex];
return inLineRange(p, range);
}
},
rect: function (itemLayout, selectors, area) {
var range = area.range;
var layoutRange = [
itemLayout[xy[xyIndex]],
itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]
];
layoutRange[1] < layoutRange[0] && layoutRange.reverse();
return inLineRange(layoutRange[0], range)
|| inLineRange(layoutRange[1], range)
|| inLineRange(range[0], layoutRange)
|| inLineRange(range[1], layoutRange);
if (itemLayout) {
var range = area.range;
var layoutRange = [
itemLayout[xy[xyIndex]],
itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]
];
layoutRange[1] < layoutRange[0] && layoutRange.reverse();
return inLineRange(layoutRange[0], range)
|| inLineRange(layoutRange[1], range)
|| inLineRange(range[0], layoutRange)
|| inLineRange(range[1], layoutRange);
}
}
};
}
Expand Down
9 changes: 8 additions & 1 deletion test/brush.html
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,14 @@

for (var i = 0; i < 10; i++) {
xAxisData.push('Class' + i);
data1.push((Math.random() * 2).toFixed(2));

if (i === 1) {
data1.push(null);
}
else {
data1.push((Math.random() * 2).toFixed(2));
}

data2.push(-Math.random().toFixed(2));
data3.push((Math.random() * 5).toFixed(2));
data4.push((Math.random() + 0.3).toFixed(2));
Expand Down

0 comments on commit a546941

Please sign in to comment.