@antv/g2 4.2.8 → 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.
- package/CHANGELOG.md +1433 -0
- package/dist/g2.min.js +2 -2
- package/dist/g2.min.js.map +1 -1
- package/esm/animate/animation/index.d.ts +1 -1
- package/esm/chart/controller/axis.d.ts +1 -1
- package/esm/chart/controller/axis.js +2 -1
- package/esm/chart/controller/axis.js.map +1 -1
- package/esm/chart/controller/base.d.ts +1 -1
- package/esm/chart/layout/constraint/types.d.ts +2 -2
- package/esm/chart/layout/index.d.ts +1 -1
- package/esm/chart/layout/padding-cal.d.ts +1 -1
- package/esm/component/update-label.d.ts +1 -1
- package/esm/core.d.ts +1 -1
- package/esm/core.js +1 -1
- package/esm/core.js.map +1 -1
- package/esm/dependents.d.ts +1 -1
- package/esm/geometry/label/base.d.ts +1 -1
- package/esm/geometry/label/index.d.ts +1 -1
- package/esm/geometry/label/interface.d.ts +2 -2
- package/esm/index.js +67 -0
- package/esm/index.js.map +1 -1
- package/esm/interaction/action/element/highlight-util.d.ts +1 -1
- package/esm/interaction/action/element/highlight.d.ts +1 -1
- package/esm/interaction/action/element/link-by-color.d.ts +1 -1
- package/esm/interaction/action/mask/circle.d.ts +5 -0
- package/esm/interaction/action/mask/circle.js +18 -16
- package/esm/interaction/action/mask/circle.js.map +1 -1
- package/esm/interaction/action/mask/dim-rect.d.ts +1 -0
- package/esm/interaction/action/mask/dim-rect.js +38 -37
- package/esm/interaction/action/mask/dim-rect.js.map +1 -1
- package/esm/interaction/action/mask/multiple/base.d.ts +125 -0
- package/esm/interaction/action/mask/multiple/base.js +286 -0
- package/esm/interaction/action/mask/multiple/base.js.map +1 -0
- package/esm/interaction/action/mask/multiple/circle.d.ts +11 -0
- package/esm/interaction/action/mask/multiple/circle.js +19 -0
- package/esm/interaction/action/mask/multiple/circle.js.map +1 -0
- package/esm/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
- package/esm/interaction/action/mask/multiple/dim-rect.js +22 -0
- package/esm/interaction/action/mask/multiple/dim-rect.js.map +1 -0
- package/esm/interaction/action/mask/multiple/path.d.ts +12 -0
- package/esm/interaction/action/mask/multiple/path.js +22 -0
- package/esm/interaction/action/mask/multiple/path.js.map +1 -0
- package/esm/interaction/action/mask/multiple/rect.d.ts +16 -0
- package/esm/interaction/action/mask/multiple/rect.js +25 -0
- package/esm/interaction/action/mask/multiple/rect.js.map +1 -0
- package/esm/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
- package/esm/interaction/action/mask/multiple/smooth-path.js +19 -0
- package/esm/interaction/action/mask/multiple/smooth-path.js.map +1 -0
- package/esm/interaction/action/mask/path.d.ts +9 -0
- package/esm/interaction/action/mask/path.js +27 -18
- package/esm/interaction/action/mask/path.js.map +1 -1
- package/esm/interaction/action/mask/rect.d.ts +12 -0
- package/esm/interaction/action/mask/rect.js +25 -16
- package/esm/interaction/action/mask/rect.js.map +1 -1
- package/esm/interaction/action/mask/smooth-path.d.ts +12 -0
- package/esm/interaction/action/mask/smooth-path.js +17 -3
- package/esm/interaction/action/mask/smooth-path.js.map +1 -1
- package/esm/interaction/action/register.d.ts +1 -1
- package/esm/interaction/action/util.d.ts +6 -0
- package/esm/interaction/action/util.js +112 -12
- package/esm/interaction/action/util.js.map +1 -1
- package/esm/interaction/interaction.d.ts +1 -1
- package/esm/interface.d.ts +59 -59
- package/esm/util/collision-detect.d.ts +1 -1
- package/esm/util/legend.d.ts +1 -1
- package/esm/util/text.d.ts +2 -2
- package/esm/util/types.d.ts +1 -1
- package/lib/animate/animation/index.d.ts +1 -1
- package/lib/chart/controller/axis.d.ts +1 -1
- package/lib/chart/controller/axis.js +2 -1
- package/lib/chart/controller/axis.js.map +1 -1
- package/lib/chart/controller/base.d.ts +1 -1
- package/lib/chart/layout/constraint/types.d.ts +2 -2
- package/lib/chart/layout/index.d.ts +1 -1
- package/lib/chart/layout/padding-cal.d.ts +1 -1
- package/lib/component/update-label.d.ts +1 -1
- package/lib/core.d.ts +1 -1
- package/lib/core.js +1 -1
- package/lib/core.js.map +1 -1
- package/lib/dependents.d.ts +1 -1
- package/lib/geometry/label/base.d.ts +1 -1
- package/lib/geometry/label/index.d.ts +1 -1
- package/lib/geometry/label/interface.d.ts +2 -2
- package/lib/index.js +67 -0
- package/lib/index.js.map +1 -1
- package/lib/interaction/action/element/highlight-util.d.ts +1 -1
- package/lib/interaction/action/element/highlight.d.ts +1 -1
- package/lib/interaction/action/element/link-by-color.d.ts +1 -1
- package/lib/interaction/action/mask/circle.d.ts +5 -0
- package/lib/interaction/action/mask/circle.js +20 -16
- package/lib/interaction/action/mask/circle.js.map +1 -1
- package/lib/interaction/action/mask/dim-rect.d.ts +1 -0
- package/lib/interaction/action/mask/dim-rect.js +40 -37
- package/lib/interaction/action/mask/dim-rect.js.map +1 -1
- package/lib/interaction/action/mask/multiple/base.d.ts +125 -0
- package/lib/interaction/action/mask/multiple/base.js +288 -0
- package/lib/interaction/action/mask/multiple/base.js.map +1 -0
- package/lib/interaction/action/mask/multiple/circle.d.ts +11 -0
- package/lib/interaction/action/mask/multiple/circle.js +21 -0
- package/lib/interaction/action/mask/multiple/circle.js.map +1 -0
- package/lib/interaction/action/mask/multiple/dim-rect.d.ts +10 -0
- package/lib/interaction/action/mask/multiple/dim-rect.js +24 -0
- package/lib/interaction/action/mask/multiple/dim-rect.js.map +1 -0
- package/lib/interaction/action/mask/multiple/path.d.ts +12 -0
- package/lib/interaction/action/mask/multiple/path.js +24 -0
- package/lib/interaction/action/mask/multiple/path.js.map +1 -0
- package/lib/interaction/action/mask/multiple/rect.d.ts +16 -0
- package/lib/interaction/action/mask/multiple/rect.js +27 -0
- package/lib/interaction/action/mask/multiple/rect.js.map +1 -0
- package/lib/interaction/action/mask/multiple/smooth-path.d.ts +11 -0
- package/lib/interaction/action/mask/multiple/smooth-path.js +21 -0
- package/lib/interaction/action/mask/multiple/smooth-path.js.map +1 -0
- package/lib/interaction/action/mask/path.d.ts +9 -0
- package/lib/interaction/action/mask/path.js +30 -18
- package/lib/interaction/action/mask/path.js.map +1 -1
- package/lib/interaction/action/mask/rect.d.ts +12 -0
- package/lib/interaction/action/mask/rect.js +28 -16
- package/lib/interaction/action/mask/rect.js.map +1 -1
- package/lib/interaction/action/mask/smooth-path.d.ts +12 -0
- package/lib/interaction/action/mask/smooth-path.js +20 -3
- package/lib/interaction/action/mask/smooth-path.js.map +1 -1
- package/lib/interaction/action/register.d.ts +1 -1
- package/lib/interaction/action/util.d.ts +6 -0
- package/lib/interaction/action/util.js +115 -14
- package/lib/interaction/action/util.js.map +1 -1
- package/lib/interaction/interaction.d.ts +1 -1
- package/lib/interface.d.ts +59 -59
- package/lib/util/collision-detect.d.ts +1 -1
- package/lib/util/legend.d.ts +1 -1
- package/lib/util/text.d.ts +2 -2
- package/lib/util/types.d.ts +1 -1
- package/package.json +2 -21
- package/src/chart/controller/axis.ts +1 -1
- package/src/core.ts +1 -1
- package/src/index.ts +70 -0
- package/src/interaction/action/mask/circle.ts +19 -16
- package/src/interaction/action/mask/dim-rect.ts +39 -37
- package/src/interaction/action/mask/multiple/base.ts +314 -0
- package/src/interaction/action/mask/multiple/circle.ts +13 -0
- package/src/interaction/action/mask/multiple/dim-rect.ts +16 -0
- package/src/interaction/action/mask/multiple/path.ts +16 -0
- package/src/interaction/action/mask/multiple/rect.ts +19 -0
- package/src/interaction/action/mask/multiple/smooth-path.ts +13 -0
- package/src/interaction/action/mask/path.ts +28 -18
- package/src/interaction/action/mask/rect.ts +28 -17
- package/src/interaction/action/mask/smooth-path.ts +19 -3
- 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
|
-
|
|
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()
|
|
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
|
-
|
|
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
|
-
|
|
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()
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
25
|
+
return getMaskPath(this.points);
|
|
26
|
+
}
|
|
27
|
+
protected getMaskAttrs() {
|
|
28
|
+
return getMaskAttrs(this.points);
|
|
13
29
|
}
|
|
14
30
|
}
|
|
15
31
|
|