brushHelper.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var BoundingRect = require("zrender/lib/core/BoundingRect");
  20. var _cursorHelper = require("./cursorHelper");
  21. var onIrrelevantElement = _cursorHelper.onIrrelevantElement;
  22. var graphicUtil = require("../../util/graphic");
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. function makeRectPanelClipPath(rect) {
  42. rect = normalizeRect(rect);
  43. return function (localPoints, transform) {
  44. return graphicUtil.clipPointsByRect(localPoints, rect);
  45. };
  46. }
  47. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  48. rect = normalizeRect(rect);
  49. return function (xyIndex) {
  50. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  51. var brushWidth = idx ? rect.width : rect.height;
  52. var base = idx ? rect.x : rect.y;
  53. return [base, base + (brushWidth || 0)];
  54. };
  55. }
  56. function makeRectIsTargetByCursor(rect, api, targetModel) {
  57. rect = normalizeRect(rect);
  58. return function (e, localCursorPoint, transform) {
  59. return rect.contain(localCursorPoint[0], localCursorPoint[1]) && !onIrrelevantElement(e, api, targetModel);
  60. };
  61. } // Consider width/height is negative.
  62. function normalizeRect(rect) {
  63. return BoundingRect.create(rect);
  64. }
  65. exports.makeRectPanelClipPath = makeRectPanelClipPath;
  66. exports.makeLinearBrushOtherExtent = makeLinearBrushOtherExtent;
  67. exports.makeRectIsTargetByCursor = makeRectIsTargetByCursor;