@antv/g2 4.2.7 → 4.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/CHANGELOG.md +1433 -0
  2. package/dist/g2.min.js +2 -2
  3. package/dist/g2.min.js.map +1 -1
  4. package/esm/animate/animation/index.d.ts +1 -1
  5. package/esm/animate/index.js.map +1 -1
  6. package/esm/chart/controller/axis.d.ts +1 -1
  7. package/esm/chart/controller/axis.js +2 -1
  8. package/esm/chart/controller/axis.js.map +1 -1
  9. package/esm/chart/controller/base.d.ts +1 -1
  10. package/esm/chart/layout/constraint/types.d.ts +2 -2
  11. package/esm/chart/layout/index.d.ts +1 -1
  12. package/esm/chart/layout/padding-cal.d.ts +1 -1
  13. package/esm/chart/view.js +3 -2
  14. package/esm/chart/view.js.map +1 -1
  15. package/esm/component/update-label.d.ts +1 -1
  16. package/esm/core.d.ts +1 -1
  17. package/esm/core.js +1 -3
  18. package/esm/core.js.map +1 -1
  19. package/esm/dependents.d.ts +1 -1
  20. package/esm/geometry/label/base.d.ts +1 -1
  21. package/esm/geometry/label/index.d.ts +1 -1
  22. package/esm/geometry/label/interface.d.ts +2 -2
  23. package/esm/geometry/shape/area/index.js.map +1 -1
  24. package/esm/geometry/shape/area/line.js.map +1 -1
  25. package/esm/geometry/shape/area/smooth-line.js.map +1 -1
  26. package/esm/geometry/shape/area/smooth.js.map +1 -1
  27. package/esm/geometry/shape/base.js.map +1 -1
  28. package/esm/geometry/shape/edge/arc.js.map +1 -1
  29. package/esm/geometry/shape/edge/index.js.map +1 -1
  30. package/esm/geometry/shape/edge/smooth.js.map +1 -1
  31. package/esm/geometry/shape/edge/vhv.js.map +1 -1
  32. package/esm/geometry/shape/interval/funnel.js.map +1 -1
  33. package/esm/geometry/shape/interval/hollow-rect.js.map +1 -1
  34. package/esm/geometry/shape/interval/index.js.map +1 -1
  35. package/esm/geometry/shape/interval/line.js.map +1 -1
  36. package/esm/geometry/shape/interval/pyramid.js.map +1 -1
  37. package/esm/geometry/shape/interval/tick.js.map +1 -1
  38. package/esm/geometry/shape/line/index.js.map +1 -1
  39. package/esm/geometry/shape/line/step.js.map +1 -1
  40. package/esm/geometry/shape/point/hollow.js.map +1 -1
  41. package/esm/geometry/shape/point/image.js.map +1 -1
  42. package/esm/geometry/shape/point/index.js.map +1 -1
  43. package/esm/geometry/shape/point/solid.js.map +1 -1
  44. package/esm/geometry/shape/polygon/index.js.map +1 -1
  45. package/esm/geometry/shape/polygon/square.js.map +1 -1
  46. package/esm/geometry/shape/schema/box.js.map +1 -1
  47. package/esm/geometry/shape/schema/candle.js.map +1 -1
  48. package/esm/geometry/shape/violin/hollow.js.map +1 -1
  49. package/esm/geometry/shape/violin/index.js.map +1 -1
  50. package/esm/geometry/shape/violin/smooth.js.map +1 -1
  51. package/esm/index.js +67 -0
  52. package/esm/index.js.map +1 -1
  53. package/esm/interaction/action/element/highlight-util.d.ts +1 -1
  54. package/esm/interaction/action/element/highlight.d.ts +1 -1
  55. package/esm/interaction/action/element/link-by-color.d.ts +1 -1
  56. package/esm/interaction/action/mask/circle.d.ts +5 -0
  57. package/esm/interaction/action/mask/circle.js +18 -16
  58. package/esm/interaction/action/mask/circle.js.map +1 -1
  59. package/esm/interaction/action/mask/dim-rect.d.ts +1 -0
  60. package/esm/interaction/action/mask/dim-rect.js +38 -37
  61. package/esm/interaction/action/mask/dim-rect.js.map +1 -1
  62. package/esm/interaction/action/mask/multiple/base.d.ts +125 -0
  63. package/esm/interaction/action/mask/multiple/base.js +286 -0
  64. package/esm/interaction/action/mask/multiple/base.js.map +1 -0
  65. package/esm/interaction/action/mask/multiple/circle.d.ts +11 -0
  66. package/esm/interaction/action/mask/multiple/circle.js +19 -0
  67. package/esm/interaction/action/mask/multiple/circle.js.map +1 -0
  68. package/esm/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
  69. package/esm/interaction/action/mask/multiple/dim-rect.js +22 -0
  70. package/esm/interaction/action/mask/multiple/dim-rect.js.map +1 -0
  71. package/esm/interaction/action/mask/multiple/path.d.ts +12 -0
  72. package/esm/interaction/action/mask/multiple/path.js +22 -0
  73. package/esm/interaction/action/mask/multiple/path.js.map +1 -0
  74. package/esm/interaction/action/mask/multiple/rect.d.ts +16 -0
  75. package/esm/interaction/action/mask/multiple/rect.js +25 -0
  76. package/esm/interaction/action/mask/multiple/rect.js.map +1 -0
  77. package/esm/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
  78. package/esm/interaction/action/mask/multiple/smooth-path.js +19 -0
  79. package/esm/interaction/action/mask/multiple/smooth-path.js.map +1 -0
  80. package/esm/interaction/action/mask/path.d.ts +9 -0
  81. package/esm/interaction/action/mask/path.js +27 -18
  82. package/esm/interaction/action/mask/path.js.map +1 -1
  83. package/esm/interaction/action/mask/rect.d.ts +12 -0
  84. package/esm/interaction/action/mask/rect.js +25 -16
  85. package/esm/interaction/action/mask/rect.js.map +1 -1
  86. package/esm/interaction/action/mask/smooth-path.d.ts +12 -0
  87. package/esm/interaction/action/mask/smooth-path.js +17 -3
  88. package/esm/interaction/action/mask/smooth-path.js.map +1 -1
  89. package/esm/interaction/action/register.d.ts +1 -1
  90. package/esm/interaction/action/util.d.ts +6 -0
  91. package/esm/interaction/action/util.js +112 -12
  92. package/esm/interaction/action/util.js.map +1 -1
  93. package/esm/interaction/interaction.d.ts +1 -1
  94. package/esm/interface.d.ts +59 -59
  95. package/esm/util/collision-detect.d.ts +1 -1
  96. package/esm/util/legend.d.ts +1 -1
  97. package/esm/util/text.d.ts +2 -2
  98. package/esm/util/types.d.ts +1 -1
  99. package/lib/animate/animation/index.d.ts +1 -1
  100. package/lib/animate/index.js.map +1 -1
  101. package/lib/chart/controller/axis.d.ts +1 -1
  102. package/lib/chart/controller/axis.js +2 -1
  103. package/lib/chart/controller/axis.js.map +1 -1
  104. package/lib/chart/controller/base.d.ts +1 -1
  105. package/lib/chart/layout/constraint/types.d.ts +2 -2
  106. package/lib/chart/layout/index.d.ts +1 -1
  107. package/lib/chart/layout/padding-cal.d.ts +1 -1
  108. package/lib/chart/view.js +3 -2
  109. package/lib/chart/view.js.map +1 -1
  110. package/lib/component/update-label.d.ts +1 -1
  111. package/lib/core.d.ts +1 -1
  112. package/lib/core.js +9 -9
  113. package/lib/core.js.map +1 -1
  114. package/lib/dependents.d.ts +1 -1
  115. package/lib/geometry/label/base.d.ts +1 -1
  116. package/lib/geometry/label/index.d.ts +1 -1
  117. package/lib/geometry/label/interface.d.ts +2 -2
  118. package/lib/geometry/shape/area/index.js.map +1 -1
  119. package/lib/geometry/shape/area/line.js.map +1 -1
  120. package/lib/geometry/shape/area/smooth-line.js.map +1 -1
  121. package/lib/geometry/shape/area/smooth.js.map +1 -1
  122. package/lib/geometry/shape/base.js.map +1 -1
  123. package/lib/geometry/shape/edge/arc.js.map +1 -1
  124. package/lib/geometry/shape/edge/index.js.map +1 -1
  125. package/lib/geometry/shape/edge/smooth.js.map +1 -1
  126. package/lib/geometry/shape/edge/vhv.js.map +1 -1
  127. package/lib/geometry/shape/interval/funnel.js.map +1 -1
  128. package/lib/geometry/shape/interval/hollow-rect.js.map +1 -1
  129. package/lib/geometry/shape/interval/index.js.map +1 -1
  130. package/lib/geometry/shape/interval/line.js.map +1 -1
  131. package/lib/geometry/shape/interval/pyramid.js.map +1 -1
  132. package/lib/geometry/shape/interval/tick.js.map +1 -1
  133. package/lib/geometry/shape/line/index.js.map +1 -1
  134. package/lib/geometry/shape/line/step.js.map +1 -1
  135. package/lib/geometry/shape/point/hollow.js.map +1 -1
  136. package/lib/geometry/shape/point/image.js.map +1 -1
  137. package/lib/geometry/shape/point/index.js.map +1 -1
  138. package/lib/geometry/shape/point/solid.js.map +1 -1
  139. package/lib/geometry/shape/polygon/index.js.map +1 -1
  140. package/lib/geometry/shape/polygon/square.js.map +1 -1
  141. package/lib/geometry/shape/schema/box.js.map +1 -1
  142. package/lib/geometry/shape/schema/candle.js.map +1 -1
  143. package/lib/geometry/shape/violin/hollow.js.map +1 -1
  144. package/lib/geometry/shape/violin/index.js.map +1 -1
  145. package/lib/geometry/shape/violin/smooth.js.map +1 -1
  146. package/lib/index.js +67 -0
  147. package/lib/index.js.map +1 -1
  148. package/lib/interaction/action/element/highlight-util.d.ts +1 -1
  149. package/lib/interaction/action/element/highlight.d.ts +1 -1
  150. package/lib/interaction/action/element/link-by-color.d.ts +1 -1
  151. package/lib/interaction/action/mask/circle.d.ts +5 -0
  152. package/lib/interaction/action/mask/circle.js +20 -16
  153. package/lib/interaction/action/mask/circle.js.map +1 -1
  154. package/lib/interaction/action/mask/dim-rect.d.ts +1 -0
  155. package/lib/interaction/action/mask/dim-rect.js +40 -37
  156. package/lib/interaction/action/mask/dim-rect.js.map +1 -1
  157. package/lib/interaction/action/mask/multiple/base.d.ts +125 -0
  158. package/lib/interaction/action/mask/multiple/base.js +288 -0
  159. package/lib/interaction/action/mask/multiple/base.js.map +1 -0
  160. package/lib/interaction/action/mask/multiple/circle.d.ts +11 -0
  161. package/lib/interaction/action/mask/multiple/circle.js +21 -0
  162. package/lib/interaction/action/mask/multiple/circle.js.map +1 -0
  163. package/lib/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
  164. package/lib/interaction/action/mask/multiple/dim-rect.js +24 -0
  165. package/lib/interaction/action/mask/multiple/dim-rect.js.map +1 -0
  166. package/lib/interaction/action/mask/multiple/path.d.ts +12 -0
  167. package/lib/interaction/action/mask/multiple/path.js +24 -0
  168. package/lib/interaction/action/mask/multiple/path.js.map +1 -0
  169. package/lib/interaction/action/mask/multiple/rect.d.ts +16 -0
  170. package/lib/interaction/action/mask/multiple/rect.js +27 -0
  171. package/lib/interaction/action/mask/multiple/rect.js.map +1 -0
  172. package/lib/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
  173. package/lib/interaction/action/mask/multiple/smooth-path.js +21 -0
  174. package/lib/interaction/action/mask/multiple/smooth-path.js.map +1 -0
  175. package/lib/interaction/action/mask/path.d.ts +9 -0
  176. package/lib/interaction/action/mask/path.js +30 -18
  177. package/lib/interaction/action/mask/path.js.map +1 -1
  178. package/lib/interaction/action/mask/rect.d.ts +12 -0
  179. package/lib/interaction/action/mask/rect.js +28 -16
  180. package/lib/interaction/action/mask/rect.js.map +1 -1
  181. package/lib/interaction/action/mask/smooth-path.d.ts +12 -0
  182. package/lib/interaction/action/mask/smooth-path.js +20 -3
  183. package/lib/interaction/action/mask/smooth-path.js.map +1 -1
  184. package/lib/interaction/action/register.d.ts +1 -1
  185. package/lib/interaction/action/util.d.ts +6 -0
  186. package/lib/interaction/action/util.js +115 -14
  187. package/lib/interaction/action/util.js.map +1 -1
  188. package/lib/interaction/interaction.d.ts +1 -1
  189. package/lib/interface.d.ts +59 -59
  190. package/lib/util/collision-detect.d.ts +1 -1
  191. package/lib/util/legend.d.ts +1 -1
  192. package/lib/util/text.d.ts +2 -2
  193. package/lib/util/types.d.ts +1 -1
  194. package/package.json +2 -21
  195. package/src/chart/controller/axis.ts +1 -1
  196. package/src/chart/view.ts +3 -2
  197. package/src/core.ts +1 -1
  198. package/src/index.ts +70 -0
  199. package/src/interaction/action/mask/circle.ts +19 -16
  200. package/src/interaction/action/mask/dim-rect.ts +39 -37
  201. package/src/interaction/action/mask/multiple/base.ts +314 -0
  202. package/src/interaction/action/mask/multiple/circle.ts +13 -0
  203. package/src/interaction/action/mask/multiple/dim-rect.ts +16 -0
  204. package/src/interaction/action/mask/multiple/path.ts +16 -0
  205. package/src/interaction/action/mask/multiple/rect.ts +19 -0
  206. package/src/interaction/action/mask/multiple/smooth-path.ts +13 -0
  207. package/src/interaction/action/mask/path.ts +28 -18
  208. package/src/interaction/action/mask/rect.ts +28 -17
  209. package/src/interaction/action/mask/smooth-path.ts +19 -3
  210. package/src/interaction/action/util.ts +123 -12
@@ -2,6 +2,24 @@ import { last } from '@antv/util';
2
2
  import { distance } from '../util';
3
3
  import MaskBase from './base';
4
4
 
5
+ export function getMaskAttrs(points) {
6
+ const currentPoint = last(points);
7
+ let r = 0;
8
+ let x = 0;
9
+ let y = 0;
10
+ if (points.length) {
11
+ const first = points[0];
12
+ r = distance(first, currentPoint) / 2;
13
+ x = (currentPoint.x + first.x) / 2;
14
+ y = (currentPoint.y + first.y) / 2;
15
+ }
16
+ return {
17
+ x,
18
+ y,
19
+ r,
20
+ };
21
+ }
22
+
5
23
  /**
6
24
  * @ignore
7
25
  * 圆形辅助框 Action
@@ -9,22 +27,7 @@ import MaskBase from './base';
9
27
  class CircleMask extends MaskBase {
10
28
  protected shapeType = 'circle';
11
29
  protected getMaskAttrs() {
12
- const points = this.points;
13
- const currentPoint = last(this.points);
14
- let r = 0;
15
- let x = 0;
16
- let y = 0;
17
- if (points.length) {
18
- const first = points[0];
19
- r = distance(first, currentPoint) / 2;
20
- x = (currentPoint.x + first.x) / 2;
21
- y = (currentPoint.y + first.y) / 2;
22
- }
23
- return {
24
- x,
25
- y,
26
- r,
27
- };
30
+ return getMaskAttrs(this.points);
28
31
  }
29
32
  }
30
33
 
@@ -7,50 +7,52 @@ function clampPoint(point) {
7
7
  point.y = clamp(point.y, 0, 1);
8
8
  }
9
9
 
10
+ export function getRegion(points, dim, inPlot, coord): Region {
11
+ let start = null;
12
+ let end = null;
13
+ const normalStart = coord.invert(head(points));
14
+ const normalEnd = coord.invert(last(points));
15
+ if (inPlot) {
16
+ // 约束到 0 - 1 范围内
17
+ clampPoint(normalStart);
18
+ clampPoint(normalEnd);
19
+ }
20
+ if (dim === 'x') {
21
+ // x 轴方向扩展, y 轴方向占满全部
22
+ start = coord.convert({
23
+ x: normalStart.x,
24
+ y: 0,
25
+ });
26
+ end = coord.convert({
27
+ x: normalEnd.x,
28
+ y: 1,
29
+ });
30
+ } else {
31
+ // y 轴方向扩展, x 轴方向占满全部
32
+ start = coord.convert({
33
+ x: 0,
34
+ y: normalStart.y,
35
+ });
36
+ end = coord.convert({
37
+ x: 1,
38
+ y: normalEnd.y,
39
+ });
40
+ }
41
+ return {
42
+ start,
43
+ end,
44
+ };
45
+ }
46
+
10
47
  /**
11
48
  * @ignore
12
49
  */
13
50
  class DimRect extends RectMask {
14
51
  protected dim = 'x';
15
52
  protected inPlot = true;
16
- protected getRegion(): Region {
17
- let start = null;
18
- let end = null;
19
- const points = this.points;
20
- const dim = this.dim;
53
+ protected getRegion() {
21
54
  const coord = this.context.view.getCoordinate();
22
- const normalStart = coord.invert(head(points));
23
- const normalEnd = coord.invert(last(points));
24
- if (this.inPlot) {
25
- // 约束到 0 - 1 范围内
26
- clampPoint(normalStart);
27
- clampPoint(normalEnd);
28
- }
29
- if (dim === 'x') {
30
- // x 轴方向扩展, y 轴方向占满全部
31
- start = coord.convert({
32
- x: normalStart.x,
33
- y: 0,
34
- });
35
- end = coord.convert({
36
- x: normalEnd.x,
37
- y: 1,
38
- });
39
- } else {
40
- // y 轴方向扩展, x 轴方向占满全部
41
- start = coord.convert({
42
- x: 0,
43
- y: normalStart.y,
44
- });
45
- end = coord.convert({
46
- x: 1,
47
- y: normalEnd.y,
48
- });
49
- }
50
- return {
51
- start,
52
- end,
53
- };
55
+ return getRegion(this.points, this.dim, this.inPlot, coord);
54
56
  }
55
57
  }
56
58
 
@@ -0,0 +1,314 @@
1
+ import { deepMix } from '@antv/util';
2
+ import Action from '../../base';
3
+ import { LooseObject } from '../../../../interface';
4
+
5
+ /**
6
+ * @ignore
7
+ * 辅助框 Action 的基类
8
+ */
9
+ abstract class MultipleMaskBase extends Action {
10
+ // mask 图形
11
+ protected maskShapes = [];
12
+ // 开始 mask 的标记
13
+ protected starting = false;
14
+ // 开始移动的标记
15
+ protected moving = false;
16
+ // 记录 mask 节点
17
+ protected recordPoints = null;
18
+ protected preMovePoint = null;
19
+ protected shapeType = 'path';
20
+ protected maskType = 'multi-mask';
21
+
22
+ /**
23
+ * 获取当前的位置
24
+ */
25
+ protected getCurrentPoint() {
26
+ const event = this.context.event;
27
+ return {
28
+ x: event.x,
29
+ y: event.y,
30
+ };
31
+ }
32
+
33
+ /**
34
+ * 触发 mask 的事件
35
+ * @param type
36
+ */
37
+ protected emitEvent(type) {
38
+ const eventName = `${this.maskType}:${type}`;
39
+ const view = this.context.view;
40
+ const event = this.context.event;
41
+ const target = {
42
+ type: this.shapeType,
43
+ name: this.maskType,
44
+ get: (key: string) => (target.hasOwnProperty(key) ? target[key] : undefined),
45
+ };
46
+ view.emit(eventName, {
47
+ target,
48
+ maskShapes: this.maskShapes,
49
+ multiPoints: this.recordPoints,
50
+ x: event.x,
51
+ y: event.y,
52
+ });
53
+ }
54
+
55
+ /**
56
+ * 创建 mask
57
+ * @param index
58
+ */
59
+ private createMask(index: number) {
60
+ const view = this.context.view;
61
+ const points = this.recordPoints[index];
62
+ const maskAttrs = this.getMaskAttrs(points);
63
+ const maskShape = view.foregroundGroup.addShape({
64
+ type: this.shapeType,
65
+ name: 'mask',
66
+ draggable: true,
67
+ attrs: {
68
+ fill: '#C5D4EB',
69
+ opacity: 0.3,
70
+ ...maskAttrs,
71
+ },
72
+ });
73
+ this.maskShapes.push(maskShape);
74
+ }
75
+
76
+ /**
77
+ * 获取 mask shape attributes
78
+ * @param points
79
+ */
80
+ protected abstract getMaskAttrs(points: number[]): LooseObject;
81
+
82
+ /**
83
+ * 生成 mask 的路径
84
+ */
85
+ protected getMaskPath(points) {
86
+ return [];
87
+ }
88
+
89
+ /**
90
+ * 显示
91
+ */
92
+ public show() {
93
+ if (this.maskShapes.length > 0) {
94
+ this.maskShapes.forEach((maskShape) => maskShape.show());
95
+ this.emitEvent('show');
96
+ }
97
+ }
98
+
99
+ /**
100
+ * 开始
101
+ */
102
+ public start(arg?: { maskStyle: LooseObject }) {
103
+ this.recordPointStart();
104
+
105
+ this.starting = true;
106
+ // 开始时,保证移动结束
107
+ this.moving = false;
108
+ // 开始第 index 个 mask
109
+ const index = this.recordPoints.length - 1;
110
+ this.createMask(index);
111
+ // 开始时设置 capture: false,可以避免创建、resize 时触发事件
112
+ this.updateShapesCapture(false);
113
+ this.updateMask(arg?.maskStyle);
114
+ this.emitEvent('start');
115
+ }
116
+
117
+ /**
118
+ * 开始移动
119
+ */
120
+ public moveStart() {
121
+ this.moving = true;
122
+ this.preMovePoint = this.getCurrentPoint();
123
+ this.updateShapesCapture(false);
124
+ }
125
+
126
+ /**
127
+ * 移动 mask
128
+ */
129
+ public move() {
130
+ if (!this.moving || this.maskShapes.length === 0) {
131
+ return;
132
+ }
133
+ const currentPoint = this.getCurrentPoint();
134
+ const preMovePoint = this.preMovePoint;
135
+ const dx = currentPoint.x - preMovePoint.x;
136
+ const dy = currentPoint.y - preMovePoint.y;
137
+
138
+ // 只移动当前 event (x, y) 所在的某个 mask
139
+ const index = this.getCurMaskShapeIndex();
140
+ if (index > -1) {
141
+ this.recordPoints[index].forEach((point) => {
142
+ point.x += dx;
143
+ point.y += dy;
144
+ });
145
+ this.updateMask();
146
+ this.emitEvent('change');
147
+ this.preMovePoint = currentPoint;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * 更新
153
+ * @param maskStyle
154
+ */
155
+ protected updateMask(maskStyle?: LooseObject) {
156
+ this.recordPoints.forEach((points, index) => {
157
+ const attrs = deepMix({}, this.getMaskAttrs(points), maskStyle);
158
+ this.maskShapes[index].attr(attrs);
159
+ });
160
+ }
161
+
162
+ /**
163
+ * 大小变化
164
+ */
165
+ public resize() {
166
+ if (this.starting && this.maskShapes.length > 0) {
167
+ this.recordPointContinue();
168
+
169
+ this.updateMask();
170
+ this.emitEvent('change');
171
+ }
172
+ }
173
+
174
+ /**
175
+ * 结束移动
176
+ */
177
+ public moveEnd() {
178
+ this.moving = false;
179
+ this.preMovePoint = null;
180
+ this.updateShapesCapture(true);
181
+ }
182
+
183
+ /**
184
+ * 结束
185
+ */
186
+ public end() {
187
+ this.starting = false;
188
+ this.emitEvent('end');
189
+ this.updateShapesCapture(true);
190
+ }
191
+
192
+ /**
193
+ * 隐藏
194
+ */
195
+ public hide() {
196
+ if (this.maskShapes.length > 0) {
197
+ this.maskShapes.forEach((maskShape) => maskShape.hide());
198
+ this.emitEvent('hide');
199
+ }
200
+ }
201
+
202
+ /**
203
+ * 清除某个 mask
204
+ */
205
+ public remove() {
206
+ const index = this.getCurMaskShapeIndex();
207
+ if (index > -1) {
208
+ // event (x, y) 在的某个 mask 区域内时,清除该 mask
209
+ this.recordPoints.splice(index, 1);
210
+ this.maskShapes[index].remove();
211
+ this.maskShapes.splice(index, 1);
212
+ this.preMovePoint = null;
213
+ this.updateShapesCapture(true);
214
+ this.emitEvent('change');
215
+ }
216
+ }
217
+
218
+ /**
219
+ * 清除全部 mask
220
+ */
221
+ public clearAll() {
222
+ this.recordPointClear();
223
+ this.maskShapes.forEach((maskShape) => maskShape.remove());
224
+ this.maskShapes = [];
225
+ this.preMovePoint = null;
226
+ }
227
+
228
+ /**
229
+ * 清除
230
+ */
231
+ public clear() {
232
+ const index = this.getCurMaskShapeIndex();
233
+ if (index === -1) {
234
+ this.recordPointClear();
235
+ this.maskShapes.forEach((maskShape) => maskShape.remove());
236
+ this.maskShapes = [];
237
+ this.emitEvent('clearAll');
238
+ } else {
239
+ this.recordPoints.splice(index, 1);
240
+ this.maskShapes[index].remove();
241
+ this.maskShapes.splice(index, 1);
242
+ this.preMovePoint = null;
243
+ this.emitEvent('clearSingle');
244
+ }
245
+ this.preMovePoint = null;
246
+ }
247
+
248
+ /**
249
+ * 销毁
250
+ */
251
+ public destroy() {
252
+ this.clear();
253
+ super.destroy();
254
+ }
255
+
256
+ /**
257
+ * 获取 mask 节点记录
258
+ */
259
+ protected getRecordPoints() {
260
+ return [...(this.recordPoints ?? [])];
261
+ }
262
+
263
+ /**
264
+ * 创建 mask 节点记录
265
+ */
266
+ protected recordPointStart() {
267
+ const recordPoints = this.getRecordPoints();
268
+ const currentPoint = this.getCurrentPoint();
269
+ this.recordPoints = [...recordPoints, [currentPoint]];
270
+ }
271
+
272
+ /**
273
+ * 持续记录 mask 节点
274
+ */
275
+ protected recordPointContinue() {
276
+ const recordPoints = this.getRecordPoints();
277
+ const currentPoint = this.getCurrentPoint();
278
+ const lastPoints = recordPoints.splice(-1, 1)[0] || [];
279
+ lastPoints.push(currentPoint);
280
+ this.recordPoints = [...recordPoints, lastPoints];
281
+ }
282
+
283
+ /**
284
+ * 清除 mask 节点 记录
285
+ */
286
+ protected recordPointClear() {
287
+ this.recordPoints = [];
288
+ }
289
+
290
+ /**
291
+ * 设置 capture
292
+ * false: 避免创建、resize 时触发事件
293
+ * true: 正常触发其它事件
294
+ * @param isCapture
295
+ */
296
+ protected updateShapesCapture(isCapture: boolean) {
297
+ this.maskShapes.forEach((maskShape) => maskShape.set('capture', isCapture));
298
+ }
299
+
300
+ /**
301
+ *
302
+ * @returns 获取当前 event (x, y) 所在 maskShape 的 index
303
+ */
304
+ protected getCurMaskShapeIndex() {
305
+ const currentPoint = this.getCurrentPoint();
306
+ return this.maskShapes.findIndex((maskShape) => {
307
+ const { width, height, r } = maskShape.attrs;
308
+ const isEmpty = width === 0 || height === 0 || r === 0;
309
+ return !isEmpty && maskShape.isHit(currentPoint.x, currentPoint.y);
310
+ });
311
+ }
312
+ }
313
+
314
+ export default MultipleMaskBase;
@@ -0,0 +1,13 @@
1
+ import MultipleMaskBase from './base';
2
+ import { getMaskAttrs } from '../circle';
3
+
4
+ /**
5
+ * @ignore
6
+ * 圆形辅助框 Action
7
+ */
8
+ class CircleMultiMask extends MultipleMaskBase {
9
+ protected shapeType = 'circle';
10
+ protected getMaskAttrs = getMaskAttrs;
11
+ }
12
+
13
+ export default CircleMultiMask;
@@ -0,0 +1,16 @@
1
+ import MultipleRectMask from './rect';
2
+ import { getRegion } from '../dim-rect';
3
+
4
+ /**
5
+ * @ignore
6
+ */
7
+ class DimRectMultiMask extends MultipleRectMask {
8
+ protected dim = 'x';
9
+ protected inPlot = true;
10
+ protected getRegion(points) {
11
+ const coord = this.context.view.getCoordinate();
12
+ return getRegion(points, this.dim, this.inPlot, coord);
13
+ }
14
+ }
15
+
16
+ export default DimRectMultiMask;
@@ -0,0 +1,16 @@
1
+ import MultipleMaskBase from './base';
2
+ import { getMaskAttrs, getMaskPath } from '../path';
3
+
4
+ /**
5
+ * @ignore
6
+ * 多个点构成的 Path 辅助框 Action
7
+ */
8
+ class PathMultiMask extends MultipleMaskBase {
9
+ protected getMaskPath = getMaskPath;
10
+ protected getMaskAttrs = getMaskAttrs;
11
+ public addPoint() {
12
+ this.resize();
13
+ }
14
+ }
15
+
16
+ export default PathMultiMask;
@@ -0,0 +1,19 @@
1
+ import MultipleMaskBase from './base';
2
+ import { getRegion, getMaskAttrs } from '../rect';
3
+
4
+ /**
5
+ * @ignore
6
+ * 矩形的辅助框 Action
7
+ */
8
+ class RectMultiMask extends MultipleMaskBase {
9
+ protected shapeType = 'rect';
10
+ protected getRegion(points) {
11
+ return getRegion(points);
12
+ }
13
+ protected getMaskAttrs(points) {
14
+ const { start, end } = this.getRegion(points);
15
+ return getMaskAttrs(start, end);
16
+ }
17
+ }
18
+
19
+ export default RectMultiMask;
@@ -0,0 +1,13 @@
1
+ import MultiplePathMask from './path';
2
+ import { getMaskPath, getMaskAttrs } from '../smooth-path';
3
+
4
+ /**
5
+ * Smooth path mask
6
+ * @ignore
7
+ */
8
+ class SmoothPathMultiMask extends MultiplePathMask {
9
+ protected getMaskPath = getMaskPath;
10
+ protected getMaskAttrs = getMaskAttrs;
11
+ }
12
+
13
+ export default SmoothPathMultiMask;
@@ -1,32 +1,42 @@
1
1
  import { each } from '@antv/util';
2
2
  import MaskBase from './base';
3
3
 
4
+ /**
5
+ * 生成 mask 的路径
6
+ * @param points
7
+ * @returns
8
+ */
9
+ export function getMaskPath(points) {
10
+ const path = [];
11
+ if (points.length) {
12
+ each(points, (point, index) => {
13
+ if (index === 0) {
14
+ path.push(['M', point.x, point.y]);
15
+ } else {
16
+ path.push(['L', point.x, point.y]);
17
+ }
18
+ });
19
+ path.push(['L', points[0].x, points[0].y]);
20
+ }
21
+ return path;
22
+ }
23
+
24
+ export function getMaskAttrs(points) {
25
+ return {
26
+ path: getMaskPath(points),
27
+ };
28
+ }
29
+
4
30
  /**
5
31
  * @ignore
6
32
  * 多个点构成的 Path 辅助框 Action
7
33
  */
8
34
  class PathMask extends MaskBase {
9
- // 生成 mask 的路径
10
35
  protected getMaskPath() {
11
- const points = this.points;
12
- const path = [];
13
- if (points.length) {
14
- each(points, (point, index) => {
15
- if (index === 0) {
16
- path.push(['M', point.x, point.y]);
17
- } else {
18
- path.push(['L', point.x, point.y]);
19
- }
20
- });
21
- path.push(['L', points[0].x, points[0].y]);
22
- }
23
- return path;
36
+ return getMaskPath(this.points);
24
37
  }
25
-
26
38
  protected getMaskAttrs() {
27
- return {
28
- path: this.getMaskPath(),
29
- };
39
+ return getMaskAttrs(this.points);
30
40
  }
31
41
 
32
42
  /**
@@ -2,32 +2,43 @@ import { head, last } from '@antv/util';
2
2
  import { Region } from '../../../interface';
3
3
  import MaskBase from './base';
4
4
 
5
+ export function getRegion(points): Region {
6
+ return {
7
+ start: head(points),
8
+ end: last(points),
9
+ };
10
+ }
11
+
12
+ /**
13
+ * 添加图形
14
+ * @param points
15
+ * @returns
16
+ */
17
+ export function getMaskAttrs(start, end) {
18
+ const x = Math.min(start.x, end.x);
19
+ const y = Math.min(start.y, end.y);
20
+ const width = Math.abs(end.x - start.x);
21
+ const height = Math.abs(end.y - start.y);
22
+ return {
23
+ x,
24
+ y,
25
+ width,
26
+ height,
27
+ };
28
+ }
29
+
5
30
  /**
6
31
  * @ignore
7
32
  * 矩形的辅助框 Action
8
33
  */
9
34
  class RectMask extends MaskBase {
10
35
  protected shapeType = 'rect';
11
- protected getRegion(): Region {
12
- const points = this.points;
13
- return {
14
- start: head(points),
15
- end: last(points),
16
- };
36
+ protected getRegion() {
37
+ return getRegion(this.points);
17
38
  }
18
- // 添加图形
19
39
  protected getMaskAttrs() {
20
40
  const { start, end } = this.getRegion();
21
- const x = Math.min(start.x, end.x);
22
- const y = Math.min(start.y, end.y);
23
- const width = Math.abs(end.x - start.x);
24
- const height = Math.abs(end.y - start.y);
25
- return {
26
- x,
27
- y,
28
- width,
29
- height,
30
- };
41
+ return getMaskAttrs(start, end);
31
42
  }
32
43
  }
33
44
 
@@ -1,15 +1,31 @@
1
1
  import { getSpline } from '../util';
2
2
  import PathMask from './path';
3
3
 
4
+ /**
5
+ * 生成 mask 的路径
6
+ * @param points
7
+ * @returns
8
+ */
9
+ export function getMaskPath(points) {
10
+ return getSpline(points, true);
11
+ }
12
+
13
+ export function getMaskAttrs(points) {
14
+ return {
15
+ path: getMaskPath(points),
16
+ };
17
+ }
18
+
4
19
  /**
5
20
  * Smooth path mask
6
21
  * @ignore
7
22
  */
8
23
  class SmoothPathMask extends PathMask {
9
- // 生成 mask 的路径
10
24
  protected getMaskPath() {
11
- const points = this.points;
12
- return getSpline(points, true);
25
+ return getMaskPath(this.points);
26
+ }
27
+ protected getMaskAttrs() {
28
+ return getMaskAttrs(this.points);
13
29
  }
14
30
  }
15
31