selector.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import * as polygonContain from 'zrender/lib/contain/polygon.js';
  41. import BoundingRect from 'zrender/lib/core/BoundingRect.js';
  42. import { linePolygonIntersect } from '../../util/graphic.js';
  43. export function makeBrushCommonSelectorForSeries(area) {
  44. var brushType = area.brushType;
  45. // Do not use function binding or curry for performance.
  46. var selectors = {
  47. point: function (itemLayout) {
  48. return selector[brushType].point(itemLayout, selectors, area);
  49. },
  50. rect: function (itemLayout) {
  51. return selector[brushType].rect(itemLayout, selectors, area);
  52. }
  53. };
  54. return selectors;
  55. }
  56. var selector = {
  57. lineX: getLineSelectors(0),
  58. lineY: getLineSelectors(1),
  59. rect: {
  60. point: function (itemLayout, selectors, area) {
  61. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
  62. },
  63. rect: function (itemLayout, selectors, area) {
  64. return itemLayout && area.boundingRect.intersect(itemLayout);
  65. }
  66. },
  67. polygon: {
  68. point: function (itemLayout, selectors, area) {
  69. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]) && polygonContain.contain(area.range, itemLayout[0], itemLayout[1]);
  70. },
  71. rect: function (itemLayout, selectors, area) {
  72. var points = area.range;
  73. if (!itemLayout || points.length <= 1) {
  74. return false;
  75. }
  76. var x = itemLayout.x;
  77. var y = itemLayout.y;
  78. var width = itemLayout.width;
  79. var height = itemLayout.height;
  80. var p = points[0];
  81. if (polygonContain.contain(points, x, y) || polygonContain.contain(points, x + width, y) || polygonContain.contain(points, x, y + height) || polygonContain.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)) {
  82. return true;
  83. }
  84. }
  85. }
  86. };
  87. function getLineSelectors(xyIndex) {
  88. var xy = ['x', 'y'];
  89. var wh = ['width', 'height'];
  90. return {
  91. point: function (itemLayout, selectors, area) {
  92. if (itemLayout) {
  93. var range = area.range;
  94. var p = itemLayout[xyIndex];
  95. return inLineRange(p, range);
  96. }
  97. },
  98. rect: function (itemLayout, selectors, area) {
  99. if (itemLayout) {
  100. var range = area.range;
  101. var layoutRange = [itemLayout[xy[xyIndex]], itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]];
  102. layoutRange[1] < layoutRange[0] && layoutRange.reverse();
  103. return inLineRange(layoutRange[0], range) || inLineRange(layoutRange[1], range) || inLineRange(range[0], layoutRange) || inLineRange(range[1], layoutRange);
  104. }
  105. }
  106. };
  107. }
  108. function inLineRange(p, range) {
  109. return range[0] <= p && p <= range[1];
  110. }
  111. export default selector;