brushHelper.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var BoundingRect = require("zrender/lib/core/BoundingRect");
  2. var _cursorHelper = require("./cursorHelper");
  3. var onIrrelevantElement = _cursorHelper.onIrrelevantElement;
  4. var graphicUtil = require("../../util/graphic");
  5. function makeRectPanelClipPath(rect) {
  6. rect = normalizeRect(rect);
  7. return function (localPoints, transform) {
  8. return graphicUtil.clipPointsByRect(localPoints, rect);
  9. };
  10. }
  11. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  12. rect = normalizeRect(rect);
  13. return function (xyIndex) {
  14. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  15. var brushWidth = idx ? rect.width : rect.height;
  16. var base = idx ? rect.x : rect.y;
  17. return [base, base + (brushWidth || 0)];
  18. };
  19. }
  20. function makeRectIsTargetByCursor(rect, api, targetModel) {
  21. rect = normalizeRect(rect);
  22. return function (e, localCursorPoint, transform) {
  23. return rect.contain(localCursorPoint[0], localCursorPoint[1]) && !onIrrelevantElement(e, api, targetModel);
  24. };
  25. } // Consider width/height is negative.
  26. function normalizeRect(rect) {
  27. return BoundingRect.create(rect);
  28. }
  29. exports.makeRectPanelClipPath = makeRectPanelClipPath;
  30. exports.makeLinearBrushOtherExtent = makeLinearBrushOtherExtent;
  31. exports.makeRectIsTargetByCursor = makeRectIsTargetByCursor;