@antv/g2 4.2.8 → 4.2.10

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 (183) hide show
  1. package/dist/g2.min.js +2 -2
  2. package/dist/g2.min.js.map +1 -1
  3. package/esm/animate/animation/sector-path-update.js +2 -1
  4. package/esm/animate/animation/sector-path-update.js.map +1 -1
  5. package/esm/animate/animation/wave-in.js +2 -0
  6. package/esm/animate/animation/wave-in.js.map +1 -1
  7. package/esm/animate/animation/zoom.js +2 -1
  8. package/esm/animate/animation/zoom.js.map +1 -1
  9. package/esm/animate/index.js.map +1 -1
  10. package/esm/chart/controller/axis.js +2 -1
  11. package/esm/chart/controller/axis.js.map +1 -1
  12. package/esm/core.d.ts +1 -1
  13. package/esm/core.js +3 -1
  14. package/esm/core.js.map +1 -1
  15. package/esm/geometry/shape/area/index.js.map +1 -1
  16. package/esm/geometry/shape/area/line.js.map +1 -1
  17. package/esm/geometry/shape/area/smooth-line.js.map +1 -1
  18. package/esm/geometry/shape/area/smooth.js.map +1 -1
  19. package/esm/geometry/shape/base.js.map +1 -1
  20. package/esm/geometry/shape/edge/arc.js.map +1 -1
  21. package/esm/geometry/shape/edge/index.js.map +1 -1
  22. package/esm/geometry/shape/edge/smooth.js.map +1 -1
  23. package/esm/geometry/shape/edge/vhv.js.map +1 -1
  24. package/esm/geometry/shape/interval/funnel.js.map +1 -1
  25. package/esm/geometry/shape/interval/hollow-rect.js +1 -0
  26. package/esm/geometry/shape/interval/hollow-rect.js.map +1 -1
  27. package/esm/geometry/shape/interval/index.js +1 -0
  28. package/esm/geometry/shape/interval/index.js.map +1 -1
  29. package/esm/geometry/shape/interval/line.js.map +1 -1
  30. package/esm/geometry/shape/interval/pyramid.js.map +1 -1
  31. package/esm/geometry/shape/interval/tick.js.map +1 -1
  32. package/esm/geometry/shape/line/index.js.map +1 -1
  33. package/esm/geometry/shape/line/step.js.map +1 -1
  34. package/esm/geometry/shape/point/hollow.js.map +1 -1
  35. package/esm/geometry/shape/point/image.js.map +1 -1
  36. package/esm/geometry/shape/point/index.js.map +1 -1
  37. package/esm/geometry/shape/point/solid.js.map +1 -1
  38. package/esm/geometry/shape/polygon/index.js.map +1 -1
  39. package/esm/geometry/shape/polygon/square.js.map +1 -1
  40. package/esm/geometry/shape/schema/box.js.map +1 -1
  41. package/esm/geometry/shape/schema/candle.js.map +1 -1
  42. package/esm/geometry/shape/violin/hollow.js.map +1 -1
  43. package/esm/geometry/shape/violin/index.js.map +1 -1
  44. package/esm/geometry/shape/violin/smooth.js.map +1 -1
  45. package/esm/index.js +69 -2
  46. package/esm/index.js.map +1 -1
  47. package/esm/interaction/action/mask/circle.d.ts +5 -0
  48. package/esm/interaction/action/mask/circle.js +18 -16
  49. package/esm/interaction/action/mask/circle.js.map +1 -1
  50. package/esm/interaction/action/mask/dim-rect.d.ts +1 -0
  51. package/esm/interaction/action/mask/dim-rect.js +38 -37
  52. package/esm/interaction/action/mask/dim-rect.js.map +1 -1
  53. package/esm/interaction/action/mask/multiple/base.d.ts +125 -0
  54. package/esm/interaction/action/mask/multiple/base.js +286 -0
  55. package/esm/interaction/action/mask/multiple/base.js.map +1 -0
  56. package/esm/interaction/action/mask/multiple/circle.d.ts +11 -0
  57. package/esm/interaction/action/mask/multiple/circle.js +19 -0
  58. package/esm/interaction/action/mask/multiple/circle.js.map +1 -0
  59. package/esm/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
  60. package/esm/interaction/action/mask/multiple/dim-rect.js +22 -0
  61. package/esm/interaction/action/mask/multiple/dim-rect.js.map +1 -0
  62. package/esm/interaction/action/mask/multiple/path.d.ts +12 -0
  63. package/esm/interaction/action/mask/multiple/path.js +22 -0
  64. package/esm/interaction/action/mask/multiple/path.js.map +1 -0
  65. package/esm/interaction/action/mask/multiple/rect.d.ts +16 -0
  66. package/esm/interaction/action/mask/multiple/rect.js +25 -0
  67. package/esm/interaction/action/mask/multiple/rect.js.map +1 -0
  68. package/esm/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
  69. package/esm/interaction/action/mask/multiple/smooth-path.js +19 -0
  70. package/esm/interaction/action/mask/multiple/smooth-path.js.map +1 -0
  71. package/esm/interaction/action/mask/path.d.ts +9 -0
  72. package/esm/interaction/action/mask/path.js +27 -18
  73. package/esm/interaction/action/mask/path.js.map +1 -1
  74. package/esm/interaction/action/mask/rect.d.ts +12 -0
  75. package/esm/interaction/action/mask/rect.js +25 -16
  76. package/esm/interaction/action/mask/rect.js.map +1 -1
  77. package/esm/interaction/action/mask/smooth-path.d.ts +12 -0
  78. package/esm/interaction/action/mask/smooth-path.js +17 -3
  79. package/esm/interaction/action/mask/smooth-path.js.map +1 -1
  80. package/esm/interaction/action/util.d.ts +6 -0
  81. package/esm/interaction/action/util.js +112 -12
  82. package/esm/interaction/action/util.js.map +1 -1
  83. package/lib/animate/animation/sector-path-update.js +1 -0
  84. package/lib/animate/animation/sector-path-update.js.map +1 -1
  85. package/lib/animate/animation/wave-in.js +2 -0
  86. package/lib/animate/animation/wave-in.js.map +1 -1
  87. package/lib/animate/animation/zoom.js +1 -0
  88. package/lib/animate/animation/zoom.js.map +1 -1
  89. package/lib/animate/index.js.map +1 -1
  90. package/lib/chart/controller/axis.js +2 -1
  91. package/lib/chart/controller/axis.js.map +1 -1
  92. package/lib/core.d.ts +1 -1
  93. package/lib/core.js +9 -9
  94. package/lib/core.js.map +1 -1
  95. package/lib/geometry/shape/area/index.js.map +1 -1
  96. package/lib/geometry/shape/area/line.js.map +1 -1
  97. package/lib/geometry/shape/area/smooth-line.js.map +1 -1
  98. package/lib/geometry/shape/area/smooth.js.map +1 -1
  99. package/lib/geometry/shape/base.js.map +1 -1
  100. package/lib/geometry/shape/edge/arc.js.map +1 -1
  101. package/lib/geometry/shape/edge/index.js.map +1 -1
  102. package/lib/geometry/shape/edge/smooth.js.map +1 -1
  103. package/lib/geometry/shape/edge/vhv.js.map +1 -1
  104. package/lib/geometry/shape/interval/funnel.js.map +1 -1
  105. package/lib/geometry/shape/interval/hollow-rect.js +1 -0
  106. package/lib/geometry/shape/interval/hollow-rect.js.map +1 -1
  107. package/lib/geometry/shape/interval/index.js +1 -0
  108. package/lib/geometry/shape/interval/index.js.map +1 -1
  109. package/lib/geometry/shape/interval/line.js.map +1 -1
  110. package/lib/geometry/shape/interval/pyramid.js.map +1 -1
  111. package/lib/geometry/shape/interval/tick.js.map +1 -1
  112. package/lib/geometry/shape/line/index.js.map +1 -1
  113. package/lib/geometry/shape/line/step.js.map +1 -1
  114. package/lib/geometry/shape/point/hollow.js.map +1 -1
  115. package/lib/geometry/shape/point/image.js.map +1 -1
  116. package/lib/geometry/shape/point/index.js.map +1 -1
  117. package/lib/geometry/shape/point/solid.js.map +1 -1
  118. package/lib/geometry/shape/polygon/index.js.map +1 -1
  119. package/lib/geometry/shape/polygon/square.js.map +1 -1
  120. package/lib/geometry/shape/schema/box.js.map +1 -1
  121. package/lib/geometry/shape/schema/candle.js.map +1 -1
  122. package/lib/geometry/shape/violin/hollow.js.map +1 -1
  123. package/lib/geometry/shape/violin/index.js.map +1 -1
  124. package/lib/geometry/shape/violin/smooth.js.map +1 -1
  125. package/lib/index.js +69 -2
  126. package/lib/index.js.map +1 -1
  127. package/lib/interaction/action/mask/circle.d.ts +5 -0
  128. package/lib/interaction/action/mask/circle.js +20 -16
  129. package/lib/interaction/action/mask/circle.js.map +1 -1
  130. package/lib/interaction/action/mask/dim-rect.d.ts +1 -0
  131. package/lib/interaction/action/mask/dim-rect.js +40 -37
  132. package/lib/interaction/action/mask/dim-rect.js.map +1 -1
  133. package/lib/interaction/action/mask/multiple/base.d.ts +125 -0
  134. package/lib/interaction/action/mask/multiple/base.js +288 -0
  135. package/lib/interaction/action/mask/multiple/base.js.map +1 -0
  136. package/lib/interaction/action/mask/multiple/circle.d.ts +11 -0
  137. package/lib/interaction/action/mask/multiple/circle.js +21 -0
  138. package/lib/interaction/action/mask/multiple/circle.js.map +1 -0
  139. package/lib/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
  140. package/lib/interaction/action/mask/multiple/dim-rect.js +24 -0
  141. package/lib/interaction/action/mask/multiple/dim-rect.js.map +1 -0
  142. package/lib/interaction/action/mask/multiple/path.d.ts +12 -0
  143. package/lib/interaction/action/mask/multiple/path.js +24 -0
  144. package/lib/interaction/action/mask/multiple/path.js.map +1 -0
  145. package/lib/interaction/action/mask/multiple/rect.d.ts +16 -0
  146. package/lib/interaction/action/mask/multiple/rect.js +27 -0
  147. package/lib/interaction/action/mask/multiple/rect.js.map +1 -0
  148. package/lib/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
  149. package/lib/interaction/action/mask/multiple/smooth-path.js +21 -0
  150. package/lib/interaction/action/mask/multiple/smooth-path.js.map +1 -0
  151. package/lib/interaction/action/mask/path.d.ts +9 -0
  152. package/lib/interaction/action/mask/path.js +30 -18
  153. package/lib/interaction/action/mask/path.js.map +1 -1
  154. package/lib/interaction/action/mask/rect.d.ts +12 -0
  155. package/lib/interaction/action/mask/rect.js +28 -16
  156. package/lib/interaction/action/mask/rect.js.map +1 -1
  157. package/lib/interaction/action/mask/smooth-path.d.ts +12 -0
  158. package/lib/interaction/action/mask/smooth-path.js +20 -3
  159. package/lib/interaction/action/mask/smooth-path.js.map +1 -1
  160. package/lib/interaction/action/util.d.ts +6 -0
  161. package/lib/interaction/action/util.js +115 -14
  162. package/lib/interaction/action/util.js.map +1 -1
  163. package/package.json +2 -21
  164. package/src/animate/animation/sector-path-update.ts +2 -1
  165. package/src/animate/animation/wave-in.ts +2 -0
  166. package/src/animate/animation/zoom.ts +2 -1
  167. package/src/chart/controller/axis.ts +1 -1
  168. package/src/core.ts +1 -1
  169. package/src/geometry/shape/interval/hollow-rect.ts +1 -0
  170. package/src/geometry/shape/interval/index.ts +1 -0
  171. package/src/index.ts +72 -2
  172. package/src/interaction/action/mask/circle.ts +19 -16
  173. package/src/interaction/action/mask/dim-rect.ts +39 -37
  174. package/src/interaction/action/mask/multiple/base.ts +314 -0
  175. package/src/interaction/action/mask/multiple/circle.ts +13 -0
  176. package/src/interaction/action/mask/multiple/dim-rect.ts +16 -0
  177. package/src/interaction/action/mask/multiple/path.ts +16 -0
  178. package/src/interaction/action/mask/multiple/rect.ts +19 -0
  179. package/src/interaction/action/mask/multiple/smooth-path.ts +13 -0
  180. package/src/interaction/action/mask/path.ts +28 -18
  181. package/src/interaction/action/mask/rect.ts +28 -17
  182. package/src/interaction/action/mask/smooth-path.ts +19 -3
  183. package/src/interaction/action/util.ts +123 -12
package/src/index.ts CHANGED
@@ -207,6 +207,12 @@ import PathMask from './interaction/action/mask/path';
207
207
  import RectMask from './interaction/action/mask/rect';
208
208
  import SmoothPathMask from './interaction/action/mask/smooth-path';
209
209
 
210
+ import RectMultiMask from './interaction/action/mask/multiple/rect';
211
+ import DimRectMultiMask from './interaction/action/mask/multiple/dim-rect';
212
+ import CircleMultiMask from './interaction/action/mask/multiple/circle';
213
+ import PathMultiMask from './interaction/action/mask/multiple/path';
214
+ import SmoothPathMultiMask from './interaction/action/mask/multiple/smooth-path';
215
+
210
216
  import CursorAction from './interaction/action/cursor';
211
217
  import DataFilter from './interaction/action/data/filter';
212
218
  import DataRangeFilter, { BRUSH_FILTER_EVENTS } from './interaction/action/data/range-filter';
@@ -270,6 +276,13 @@ registerAction('circle-mask', CircleMask);
270
276
  registerAction('path-mask', PathMask);
271
277
  registerAction('smooth-path-mask', SmoothPathMask);
272
278
 
279
+ registerAction('rect-multi-mask', RectMultiMask);
280
+ registerAction('x-rect-multi-mask', DimRectMultiMask, { dim: 'x' });
281
+ registerAction('y-rect-multi-mask', DimRectMultiMask, { dim: 'y' });
282
+ registerAction('circle-multi-mask', CircleMultiMask);
283
+ registerAction('path-multi-mask', PathMultiMask);
284
+ registerAction('smooth-path-multi-mask', SmoothPathMultiMask);
285
+
273
286
  registerAction('cursor', CursorAction);
274
287
  registerAction('data-filter', DataFilter);
275
288
 
@@ -277,8 +290,8 @@ registerAction('brush', DataRangeFilter);
277
290
  registerAction('brush-x', DataRangeFilter, { dims: ['x'] });
278
291
  registerAction('brush-y', DataRangeFilter, { dims: ['y'] });
279
292
  registerAction('sibling-filter', SiblingFilter);
280
- registerAction('sibling-x-filter', SiblingFilter);
281
- registerAction('sibling-y-filter', SiblingFilter);
293
+ registerAction('sibling-x-filter', SiblingFilter, { dims: 'x' });
294
+ registerAction('sibling-y-filter', SiblingFilter, { dims: 'y' });
282
295
 
283
296
  registerAction('element-filter', ElementFilter);
284
297
  registerAction('element-sibling-filter', ElementSiblingFilter);
@@ -298,6 +311,7 @@ registerAction('mousewheel-scroll', MousewheelScroll);
298
311
 
299
312
  // 注册默认的 Interaction 交互行为
300
313
  import { registerInteraction } from './core';
314
+ import { isMultipleMask } from './interaction/action/util';
301
315
 
302
316
  function isPointInView(context: IInteractionContext) {
303
317
  return context.isInPlot();
@@ -559,6 +573,62 @@ registerInteraction('element-path-highlight', {
559
573
  rollback: [{ trigger: 'dblclick', action: 'path-mask:hide' }],
560
574
  });
561
575
 
576
+ registerInteraction('brush-x-multi', {
577
+ showEnable: [
578
+ { trigger: 'plot:mouseenter', action: 'cursor:crosshair' },
579
+ { trigger: 'mask:mouseenter', action: 'cursor:move' },
580
+ { trigger: 'plot:mouseleave', action: 'cursor:default' },
581
+ { trigger: 'mask:mouseleave', action: 'cursor:crosshair' },
582
+ ],
583
+ start: [
584
+ {
585
+ trigger: 'mousedown',
586
+ isEnable: isPointInView,
587
+ action: ['x-rect-multi-mask:start', 'x-rect-multi-mask:show'],
588
+ },
589
+ {
590
+ trigger: 'mask:dragstart',
591
+ action: ['x-rect-multi-mask:moveStart'],
592
+ },
593
+ ],
594
+ processing: [
595
+ {
596
+ trigger: 'mousemove',
597
+ isEnable: (context) => !isMultipleMask(context),
598
+ action: ['x-rect-multi-mask:resize'],
599
+ },
600
+ {
601
+ trigger: 'multi-mask:change',
602
+ action: 'element-range-highlight:highlight',
603
+ },
604
+ {
605
+ trigger: 'mask:drag',
606
+ action: ['x-rect-multi-mask:move'],
607
+ },
608
+ ],
609
+ end: [
610
+ {
611
+ trigger: 'mouseup',
612
+ action: ['x-rect-multi-mask:end'],
613
+ },
614
+ { trigger: 'mask:dragend', action: ['x-rect-multi-mask:moveEnd'] },
615
+ ],
616
+ rollback: [
617
+ {
618
+ trigger: 'dblclick',
619
+ action: ['x-rect-multi-mask:clear', 'cursor:crosshair'],
620
+ },
621
+ {
622
+ trigger: 'multi-mask:clearAll',
623
+ action: ['element-range-highlight:clear'],
624
+ },
625
+ {
626
+ trigger: 'multi-mask:clearSingle',
627
+ action: ['element-range-highlight:highlight'],
628
+ },
629
+ ],
630
+ });
631
+
562
632
  // 点击选中,允许取消
563
633
  registerInteraction('element-single-selected', {
564
634
  start: [{ trigger: 'element:click', action: 'element-single-selected:toggle' }],
@@ -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
  /**