cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
72 lines (71 loc) • 2.82 kB
JavaScript
import { contain } from "../../../../zrender/lib/contain/polygon.mjs";
import BoundingRect from "../../../../zrender/lib/core/BoundingRect.mjs";
import { linePolygonIntersect } from "../../util/graphic.mjs";
function makeBrushCommonSelectorForSeries(area) {
var brushType = area.brushType;
var selectors = {
point: function(itemLayout) {
return selector[brushType].point(itemLayout, selectors, area);
},
rect: function(itemLayout) {
return selector[brushType].rect(itemLayout, selectors, area);
}
};
return selectors;
}
var selector = {
lineX: getLineSelectors(0),
lineY: getLineSelectors(1),
rect: {
point: function(itemLayout, selectors, area) {
return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
},
rect: function(itemLayout, selectors, area) {
return itemLayout && area.boundingRect.intersect(itemLayout);
}
},
polygon: {
point: function(itemLayout, selectors, area) {
return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]) && contain(area.range, itemLayout[0], itemLayout[1]);
},
rect: function(itemLayout, selectors, area) {
var points = area.range;
if (!itemLayout || points.length <= 1) {
return false;
}
var x = itemLayout.x;
var y = itemLayout.y;
var width = itemLayout.width;
var height = itemLayout.height;
var p = points[0];
if (contain(points, x, y) || contain(points, x + width, y) || contain(points, x, y + height) || contain(points, x + width, y + height) || BoundingRect.create(itemLayout).contain(p[0], p[1]) || linePolygonIntersect(x, y, x + width, y, points) || linePolygonIntersect(x, y, x, y + height, points) || linePolygonIntersect(x + width, y, x + width, y + height, points) || linePolygonIntersect(x, y + height, x + width, y + height, points)) {
return true;
}
}
}
};
function getLineSelectors(xyIndex) {
var xy = ["x", "y"];
var wh = ["width", "height"];
return {
point: function(itemLayout, selectors, area) {
if (itemLayout) {
var range = area.range;
var p = itemLayout[xyIndex];
return inLineRange(p, range);
}
},
rect: function(itemLayout, selectors, area) {
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);
}
}
};
}
function inLineRange(p, range) {
return range[0] <= p && p <= range[1];
}
export { selector as default, makeBrushCommonSelectorForSeries };