@antv/g2 4.1.50 → 4.2.2
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/dist/g2.min.js +3 -3
- package/dist/g2.min.js.map +1 -1
- package/esm/animate/animation/sector-path-update.js +3 -3
- package/esm/animate/animation/sector-path-update.js.map +1 -1
- package/esm/animate/animation/util.js +2 -1
- package/esm/animate/animation/util.js.map +1 -1
- package/esm/chart/controller/annotation.js +20 -10
- package/esm/chart/controller/annotation.js.map +1 -1
- package/esm/chart/controller/coordinate.js +3 -3
- package/esm/chart/controller/coordinate.js.map +1 -1
- package/esm/chart/controller/legend.js +3 -3
- package/esm/chart/controller/legend.js.map +1 -1
- package/esm/chart/controller/scrollbar.js +8 -8
- package/esm/chart/controller/scrollbar.js.map +1 -1
- package/esm/chart/controller/slider.js +8 -8
- package/esm/chart/controller/slider.js.map +1 -1
- package/esm/chart/controller/tooltip.js +82 -34
- package/esm/chart/controller/tooltip.js.map +1 -1
- package/esm/chart/layout/auto.js +2 -2
- package/esm/chart/layout/auto.js.map +1 -1
- package/esm/chart/layout/constraint/constraint.js +2 -1
- package/esm/chart/layout/constraint/constraint.js.map +1 -1
- package/esm/chart/layout/constraint/solver.js +2 -1
- package/esm/chart/layout/constraint/solver.js.map +1 -1
- package/esm/chart/layout/padding-cal.js +4 -4
- package/esm/chart/layout/padding-cal.js.map +1 -1
- package/esm/chart/view.js +2 -2
- package/esm/chart/view.js.map +1 -1
- package/esm/component/labels.d.ts +1 -2
- package/esm/component/labels.js +134 -103
- package/esm/component/labels.js.map +1 -1
- package/esm/constant.d.ts +3 -1
- package/esm/constant.js +2 -0
- package/esm/constant.js.map +1 -1
- package/esm/core.d.ts +1 -1
- package/esm/core.js +1 -1
- package/esm/core.js.map +1 -1
- package/esm/facet/circle.js +2 -2
- package/esm/facet/circle.js.map +1 -1
- package/esm/facet/facet.js +3 -2
- package/esm/facet/facet.js.map +1 -1
- package/esm/facet/list.js +2 -2
- package/esm/facet/list.js.map +1 -1
- package/esm/facet/mirror.js +2 -2
- package/esm/facet/mirror.js.map +1 -1
- package/esm/facet/rect.js +2 -2
- package/esm/facet/rect.js.map +1 -1
- package/esm/facet/tree.js +20 -10
- package/esm/facet/tree.js.map +1 -1
- package/esm/geometry/base.d.ts +3 -0
- package/esm/geometry/base.js +151 -82
- package/esm/geometry/base.js.map +1 -1
- package/esm/geometry/element/index.js +3 -1
- package/esm/geometry/element/index.js.map +1 -1
- package/esm/geometry/heatmap.js +17 -7
- package/esm/geometry/heatmap.js.map +1 -1
- package/esm/geometry/label/base.d.ts +1 -1
- package/esm/geometry/label/base.js +20 -8
- package/esm/geometry/label/base.js.map +1 -1
- package/esm/geometry/label/layout/hide-overlap.d.ts +1 -1
- package/esm/geometry/label/layout/hide-overlap.js +65 -19
- package/esm/geometry/label/layout/hide-overlap.js.map +1 -1
- package/esm/geometry/label/layout/interval/hide-overlap.js +3 -2
- package/esm/geometry/label/layout/interval/hide-overlap.js.map +1 -1
- package/esm/geometry/label/layout/path/adjust-position.js +3 -2
- package/esm/geometry/label/layout/path/adjust-position.js.map +1 -1
- package/esm/geometry/label/layout/pie/distribute.js +14 -3
- package/esm/geometry/label/layout/pie/distribute.js.map +1 -1
- package/esm/geometry/label/layout/pie/outer.js +14 -3
- package/esm/geometry/label/layout/pie/outer.js.map +1 -1
- package/esm/geometry/label/layout/pie/spider.js +14 -3
- package/esm/geometry/label/layout/pie/spider.js.map +1 -1
- package/esm/geometry/label/layout/point/adjust-position.js +3 -2
- package/esm/geometry/label/layout/point/adjust-position.js.map +1 -1
- package/esm/geometry/label/layout/worker/hide-overlap.d.ts +2 -0
- package/esm/geometry/label/layout/worker/hide-overlap.js +155 -0
- package/esm/geometry/label/layout/worker/hide-overlap.js.map +1 -0
- package/esm/geometry/label/util/createWorker.d.ts +1 -0
- package/esm/geometry/label/util/createWorker.js +16 -0
- package/esm/geometry/label/util/createWorker.js.map +1 -0
- package/esm/geometry/label/util/index.d.ts +4 -2
- package/esm/geometry/label/util/index.js +3 -2
- package/esm/geometry/label/util/index.js.map +1 -1
- package/esm/geometry/path.js +65 -37
- package/esm/geometry/path.js.map +1 -1
- package/esm/geometry/shape/interval/tick.js +3 -2
- package/esm/geometry/shape/interval/tick.js.map +1 -1
- package/esm/geometry/shape/interval/util.js +14 -13
- package/esm/geometry/shape/interval/util.js.map +1 -1
- package/esm/geometry/shape/point/image.js +22 -11
- package/esm/geometry/shape/point/image.js.map +1 -1
- package/esm/geometry/shape/point/util.js +17 -7
- package/esm/geometry/shape/point/util.js.map +1 -1
- package/esm/geometry/shape/util/path.js +3 -1
- package/esm/geometry/shape/util/path.js.map +1 -1
- package/esm/geometry/util/group-data.js +17 -6
- package/esm/geometry/util/group-data.js.map +1 -1
- package/esm/interaction/action/active-region.js +42 -14
- package/esm/interaction/action/active-region.js.map +1 -1
- package/esm/interaction/action/component/axis/axis-description.d.ts +1 -1
- package/esm/interaction/action/component/axis/axis-description.js +13 -17
- package/esm/interaction/action/component/axis/axis-description.js.map +1 -1
- package/esm/interaction/action/component/list-focus.js +50 -13
- package/esm/interaction/action/component/list-focus.js.map +1 -1
- package/esm/interaction/action/data/filter.js +2 -2
- package/esm/interaction/action/data/filter.js.map +1 -1
- package/esm/interaction/action/data/range-filter.js +2 -2
- package/esm/interaction/action/data/range-filter.js.map +1 -1
- package/esm/interaction/action/element/filter.js +2 -2
- package/esm/interaction/action/element/filter.js.map +1 -1
- package/esm/util/attr.js +2 -2
- package/esm/util/attr.js.map +1 -1
- package/esm/util/bbox.js +3 -2
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/collision-detect.d.ts +8 -4
- package/esm/util/collision-detect.js +13 -11
- package/esm/util/collision-detect.js.map +1 -1
- package/esm/util/color.js +2 -1
- package/esm/util/color.js.map +1 -1
- package/esm/util/helper.js +16 -5
- package/esm/util/helper.js.map +1 -1
- package/esm/util/padding.js +3 -3
- package/esm/util/padding.js.map +1 -1
- package/esm/util/scale.js +2 -2
- package/esm/util/scale.js.map +1 -1
- package/esm/util/stat.js +2 -2
- package/esm/util/stat.js.map +1 -1
- package/esm/util/text.js +2 -2
- package/esm/util/text.js.map +1 -1
- package/esm/util/tooltip.js +109 -59
- package/esm/util/tooltip.js.map +1 -1
- package/lib/animate/animation/sector-path-update.js +2 -2
- package/lib/animate/animation/sector-path-update.js.map +1 -1
- package/lib/animate/animation/util.js +2 -1
- package/lib/animate/animation/util.js.map +1 -1
- package/lib/chart/controller/annotation.js +19 -9
- package/lib/chart/controller/annotation.js.map +1 -1
- package/lib/chart/controller/coordinate.js +2 -2
- package/lib/chart/controller/coordinate.js.map +1 -1
- package/lib/chart/controller/legend.js +2 -2
- package/lib/chart/controller/legend.js.map +1 -1
- package/lib/chart/controller/scrollbar.js +7 -7
- package/lib/chart/controller/scrollbar.js.map +1 -1
- package/lib/chart/controller/slider.js +7 -7
- package/lib/chart/controller/slider.js.map +1 -1
- package/lib/chart/controller/tooltip.js +81 -33
- package/lib/chart/controller/tooltip.js.map +1 -1
- package/lib/chart/layout/auto.js +1 -1
- package/lib/chart/layout/auto.js.map +1 -1
- package/lib/chart/layout/constraint/constraint.js +2 -1
- package/lib/chart/layout/constraint/constraint.js.map +1 -1
- package/lib/chart/layout/constraint/solver.js +2 -1
- package/lib/chart/layout/constraint/solver.js.map +1 -1
- package/lib/chart/layout/padding-cal.js +3 -3
- package/lib/chart/layout/padding-cal.js.map +1 -1
- package/lib/chart/view.js +1 -1
- package/lib/chart/view.js.map +1 -1
- package/lib/component/labels.d.ts +1 -2
- package/lib/component/labels.js +132 -101
- package/lib/component/labels.js.map +1 -1
- package/lib/constant.d.ts +3 -1
- package/lib/constant.js +2 -0
- package/lib/constant.js.map +1 -1
- package/lib/core.d.ts +1 -1
- package/lib/core.js +1 -1
- package/lib/core.js.map +1 -1
- package/lib/facet/circle.js +1 -1
- package/lib/facet/circle.js.map +1 -1
- package/lib/facet/facet.js +3 -2
- package/lib/facet/facet.js.map +1 -1
- package/lib/facet/list.js +1 -1
- package/lib/facet/list.js.map +1 -1
- package/lib/facet/mirror.js +1 -1
- package/lib/facet/mirror.js.map +1 -1
- package/lib/facet/rect.js +1 -1
- package/lib/facet/rect.js.map +1 -1
- package/lib/facet/tree.js +19 -9
- package/lib/facet/tree.js.map +1 -1
- package/lib/geometry/base.d.ts +3 -0
- package/lib/geometry/base.js +149 -80
- package/lib/geometry/base.js.map +1 -1
- package/lib/geometry/element/index.js +3 -1
- package/lib/geometry/element/index.js.map +1 -1
- package/lib/geometry/heatmap.js +16 -6
- package/lib/geometry/heatmap.js.map +1 -1
- package/lib/geometry/label/base.d.ts +1 -1
- package/lib/geometry/label/base.js +19 -7
- package/lib/geometry/label/base.js.map +1 -1
- package/lib/geometry/label/layout/hide-overlap.d.ts +1 -1
- package/lib/geometry/label/layout/hide-overlap.js +62 -16
- package/lib/geometry/label/layout/hide-overlap.js.map +1 -1
- package/lib/geometry/label/layout/interval/hide-overlap.js +3 -2
- package/lib/geometry/label/layout/interval/hide-overlap.js.map +1 -1
- package/lib/geometry/label/layout/path/adjust-position.js +3 -2
- package/lib/geometry/label/layout/path/adjust-position.js.map +1 -1
- package/lib/geometry/label/layout/pie/distribute.js +14 -3
- package/lib/geometry/label/layout/pie/distribute.js.map +1 -1
- package/lib/geometry/label/layout/pie/outer.js +14 -3
- package/lib/geometry/label/layout/pie/outer.js.map +1 -1
- package/lib/geometry/label/layout/pie/spider.js +14 -3
- package/lib/geometry/label/layout/pie/spider.js.map +1 -1
- package/lib/geometry/label/layout/point/adjust-position.js +3 -2
- package/lib/geometry/label/layout/point/adjust-position.js.map +1 -1
- package/lib/geometry/label/layout/worker/hide-overlap.d.ts +2 -0
- package/lib/geometry/label/layout/worker/hide-overlap.js +158 -0
- package/lib/geometry/label/layout/worker/hide-overlap.js.map +1 -0
- package/lib/geometry/label/util/createWorker.d.ts +1 -0
- package/lib/geometry/label/util/createWorker.js +20 -0
- package/lib/geometry/label/util/createWorker.js.map +1 -0
- package/lib/geometry/label/util/index.d.ts +4 -2
- package/lib/geometry/label/util/index.js +5 -4
- package/lib/geometry/label/util/index.js.map +1 -1
- package/lib/geometry/path.js +64 -36
- package/lib/geometry/path.js.map +1 -1
- package/lib/geometry/shape/interval/tick.js +2 -1
- package/lib/geometry/shape/interval/tick.js.map +1 -1
- package/lib/geometry/shape/interval/util.js +13 -12
- package/lib/geometry/shape/interval/util.js.map +1 -1
- package/lib/geometry/shape/point/image.js +22 -11
- package/lib/geometry/shape/point/image.js.map +1 -1
- package/lib/geometry/shape/point/util.js +16 -6
- package/lib/geometry/shape/point/util.js.map +1 -1
- package/lib/geometry/shape/util/path.js +3 -1
- package/lib/geometry/shape/util/path.js.map +1 -1
- package/lib/geometry/util/group-data.js +17 -6
- package/lib/geometry/util/group-data.js.map +1 -1
- package/lib/interaction/action/active-region.js +41 -13
- package/lib/interaction/action/active-region.js.map +1 -1
- package/lib/interaction/action/component/axis/axis-description.d.ts +1 -1
- package/lib/interaction/action/component/axis/axis-description.js +8 -12
- package/lib/interaction/action/component/axis/axis-description.js.map +1 -1
- package/lib/interaction/action/component/list-focus.js +49 -12
- package/lib/interaction/action/component/list-focus.js.map +1 -1
- package/lib/interaction/action/data/filter.js +1 -1
- package/lib/interaction/action/data/filter.js.map +1 -1
- package/lib/interaction/action/data/range-filter.js +1 -1
- package/lib/interaction/action/data/range-filter.js.map +1 -1
- package/lib/interaction/action/element/filter.js +1 -1
- package/lib/interaction/action/element/filter.js.map +1 -1
- package/lib/util/attr.js +1 -1
- package/lib/util/attr.js.map +1 -1
- package/lib/util/bbox.js +3 -2
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/collision-detect.d.ts +8 -4
- package/lib/util/collision-detect.js +14 -12
- package/lib/util/collision-detect.js.map +1 -1
- package/lib/util/color.js +1 -1
- package/lib/util/color.js.map +1 -1
- package/lib/util/helper.js +16 -5
- package/lib/util/helper.js.map +1 -1
- package/lib/util/padding.js +2 -2
- package/lib/util/padding.js.map +1 -1
- package/lib/util/scale.js +1 -1
- package/lib/util/scale.js.map +1 -1
- package/lib/util/stat.js +1 -1
- package/lib/util/stat.js.map +1 -1
- package/lib/util/text.js +1 -1
- package/lib/util/text.js.map +1 -1
- package/lib/util/tooltip.js +108 -58
- package/lib/util/tooltip.js.map +1 -1
- package/package.json +1 -1
- package/src/component/labels.ts +37 -40
- package/src/constant.ts +3 -0
- package/src/core.ts +1 -1
- package/src/geometry/base.ts +42 -30
- package/src/geometry/element/index.ts +2 -2
- package/src/geometry/label/base.ts +3 -3
- package/src/geometry/label/layout/hide-overlap.ts +73 -21
- package/src/geometry/label/layout/path/adjust-position.ts +1 -2
- package/src/geometry/label/layout/worker/hide-overlap.ts +192 -0
- package/src/geometry/label/util/createWorker.ts +15 -0
- package/src/geometry/label/util/index.ts +5 -4
- package/src/interaction/action/component/axis/axis-description.ts +36 -38
- package/src/util/collision-detect.ts +24 -14
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
const onmessage = function (e) {
|
|
2
|
+
type Item = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
rotation?: number;
|
|
8
|
+
visible?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Copy from src/util/collision-detect.ts
|
|
12
|
+
function generateUtils() {
|
|
13
|
+
type Vec2 = [number, number];
|
|
14
|
+
|
|
15
|
+
type Point = { x: number; y: number };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 定义投影对象
|
|
19
|
+
*/
|
|
20
|
+
type Projection = { min: number; max: number };
|
|
21
|
+
|
|
22
|
+
function dot(a, b) {
|
|
23
|
+
return (a[0] || 0) * (b[0] || 0) + (a[1] || 0) * (b[1] || 0) + (a[2] || 0) * (b[2] || 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 1. 获取投影轴
|
|
27
|
+
*/
|
|
28
|
+
function getAxes(points: Point[] /** 多边形的关键点 */): Vec2[] {
|
|
29
|
+
// 目前先处理 平行矩形 的场景, 其他多边形不处理
|
|
30
|
+
if (points.length > 4) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
// 获取向量
|
|
34
|
+
const vector = (start: Point, end: Point): Vec2 => {
|
|
35
|
+
return [end.x - start.x, end.y - start.y];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 由于 矩形的平行原理,所以只有 2 条投影轴: A -> B, B -> C
|
|
39
|
+
const AB = vector(points[0], points[1]);
|
|
40
|
+
const BC = vector(points[1], points[2]);
|
|
41
|
+
|
|
42
|
+
return [AB, BC];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 绕指定点顺时针旋转后的点坐标
|
|
47
|
+
* 默认绕原点旋转
|
|
48
|
+
*/
|
|
49
|
+
function rotateAtPoint(point: Point, deg = 0, origin = { x: 0, y: 0 }): Point {
|
|
50
|
+
const { x, y } = point;
|
|
51
|
+
return {
|
|
52
|
+
x: (x - origin.x) * Math.cos(-deg) + (y - origin.y) * Math.sin(-deg) + origin.x,
|
|
53
|
+
y: (origin.x - x) * Math.sin(-deg) + (y - origin.y) * Math.cos(-deg) + origin.y,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @private
|
|
59
|
+
* 转化为顶点坐标数组
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} box
|
|
62
|
+
*/
|
|
63
|
+
function getRectPoints(box: Item): Point[] {
|
|
64
|
+
const points = [
|
|
65
|
+
{ x: box.x, y: box.y },
|
|
66
|
+
{ x: box.x + box.width, y: box.y },
|
|
67
|
+
{ x: box.x + box.width, y: box.y + box.height },
|
|
68
|
+
{ x: box.x, y: box.y + box.height },
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const rotation = box.rotation;
|
|
72
|
+
if (rotation) {
|
|
73
|
+
return [
|
|
74
|
+
rotateAtPoint(points[0], rotation, points[0]),
|
|
75
|
+
rotateAtPoint(points[1], rotation, points[0]),
|
|
76
|
+
rotateAtPoint(points[2], rotation, points[0]),
|
|
77
|
+
rotateAtPoint(points[3], rotation, points[0]),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return points;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 2. 获取多边形在投影轴上的投影
|
|
86
|
+
*
|
|
87
|
+
* 向量的点积的其中一个几何含义是:一个向量在平行于另一个向量方向上的投影的数值乘积。
|
|
88
|
+
* 由于投影轴是单位向量(长度为1),投影的长度为 x1 * x2 + y1 * y2
|
|
89
|
+
*/
|
|
90
|
+
function getProjection(points: Point[] /** 多边形的关键点 */, axis: Vec2): Projection {
|
|
91
|
+
// 目前先处理矩形的场景
|
|
92
|
+
if (points.length > 4) {
|
|
93
|
+
return { min: 0, max: 0 };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const scalars = [];
|
|
97
|
+
points.forEach((point) => {
|
|
98
|
+
scalars.push(dot([point.x, point.y], axis));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return { min: Math.min.apply(null, scalars), max: Math.max.apply(null, scalars) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isProjectionOverlap(projection1: Projection, projection2: Projection): boolean {
|
|
105
|
+
return projection1.max > projection2.min && projection1.min < projection2.max;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isValidNumber(d: number) {
|
|
109
|
+
return typeof d === 'number' && !Number.isNaN(d) && d !== Infinity && d !== -Infinity;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isValidBox(box: Item) {
|
|
113
|
+
return ['x', 'y', 'width', 'height'].every(attr => isValidNumber(box[attr]))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isIntersectRect(box1: Item, box2: Item, margin: number = 0): boolean {
|
|
117
|
+
return !(
|
|
118
|
+
box2.x > box1.x + box1.width + margin ||
|
|
119
|
+
box2.x + box2.width < box1.x - margin ||
|
|
120
|
+
box2.y > box1.y + box1.height + margin ||
|
|
121
|
+
box2.y + box2.height < box1.y - margin
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
function intersect(box1: Item, box2: Item, margin: number = 0) {
|
|
125
|
+
if (!isValidBox(box1) || !isValidBox(box2)) return false;
|
|
126
|
+
|
|
127
|
+
// Quick detect, if rotation is null or zero.
|
|
128
|
+
if (!box1.rotation && !box2.rotation) {
|
|
129
|
+
return isIntersectRect(box1, box2, margin);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 分别获取 4 个关键点
|
|
133
|
+
const rect1Points = getRectPoints(box1);
|
|
134
|
+
const rect2Points = getRectPoints(box2);
|
|
135
|
+
|
|
136
|
+
// 获取所有投影轴
|
|
137
|
+
const axes = getAxes(rect1Points).concat(getAxes(rect2Points));
|
|
138
|
+
|
|
139
|
+
for (let i = 0; i < axes.length; i++) {
|
|
140
|
+
const axis = axes[i];
|
|
141
|
+
const projection1 = getProjection(rect1Points, axis);
|
|
142
|
+
const projection2 = getProjection(rect2Points, axis);
|
|
143
|
+
|
|
144
|
+
if (!isProjectionOverlap(projection1, projection2)) return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return { intersect }
|
|
150
|
+
}
|
|
151
|
+
const { intersect } = generateUtils();
|
|
152
|
+
|
|
153
|
+
// Label layouts.
|
|
154
|
+
function hideOverlap(items: Item[]) {
|
|
155
|
+
const boxes = items.slice();
|
|
156
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
157
|
+
const box1 = boxes[i];
|
|
158
|
+
if (box1.visible) {
|
|
159
|
+
for (let j = i + 1; j < boxes.length; j++) {
|
|
160
|
+
const box2 = boxes[j];
|
|
161
|
+
if (box1 !== box2 && box2.visible) {
|
|
162
|
+
if (intersect(box1, box2)) {
|
|
163
|
+
box2.visible = false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return boxes;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const methods = {
|
|
173
|
+
'hide-overlap': hideOverlap,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Main
|
|
177
|
+
try {
|
|
178
|
+
const eventData = JSON.parse(e.data);
|
|
179
|
+
if (!eventData || !eventData.type || !methods[eventData.type]) return;
|
|
180
|
+
|
|
181
|
+
const { type, items } = eventData;
|
|
182
|
+
const result = methods[type](items);
|
|
183
|
+
self.postMessage(result);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
throw e;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const code = `
|
|
190
|
+
self.onmessage = ${onmessage.toString()}
|
|
191
|
+
`
|
|
192
|
+
export { code };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function createWorker(f: any) {
|
|
2
|
+
if (typeof window === "undefined") return;
|
|
3
|
+
|
|
4
|
+
let blob;
|
|
5
|
+
try {
|
|
6
|
+
blob = new Blob([f.toString()], { type: 'application/javascript' });
|
|
7
|
+
} catch (e) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
blob = new window.BlobBuilder();
|
|
10
|
+
blob.append(f.toString());
|
|
11
|
+
blob = blob.getBlob();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return new Worker(URL.createObjectURL(blob));
|
|
15
|
+
}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { isNil, isNumber, some } from '@antv/util';
|
|
6
6
|
import { IElement, IGroup, BBox } from '../../../dependents';
|
|
7
7
|
import { rotate } from '../../../util/transform';
|
|
8
|
-
import { LabelItem } from '../interface';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* 查找 Label Group 中的文本 shape 对象
|
|
@@ -18,12 +17,12 @@ export function findLabelTextShape(label: IGroup): IElement {
|
|
|
18
17
|
/**
|
|
19
18
|
* 获取标签背景信息: box (无旋转) + rotation (旋转角度)
|
|
20
19
|
*/
|
|
21
|
-
export function
|
|
20
|
+
export function getLabelBackgroundInfo(
|
|
22
21
|
labelGroup: IGroup,
|
|
23
|
-
labelItem:
|
|
22
|
+
labelItem: { rotate?: number;[key: string]: any },
|
|
24
23
|
padding: number | number[] = [0, 0, 0, 0]
|
|
25
24
|
): { x: number; y: number; width: number; height: number; rotation: number } {
|
|
26
|
-
const content = labelGroup.getChildren()[0];
|
|
25
|
+
const content = labelGroup && labelGroup.getChildren()[0];
|
|
27
26
|
if (content) {
|
|
28
27
|
const labelShape = content.clone();
|
|
29
28
|
|
|
@@ -52,6 +51,8 @@ export function getlLabelBackgroundInfo(
|
|
|
52
51
|
rotation: labelItem?.rotate || 0,
|
|
53
52
|
};
|
|
54
53
|
}
|
|
54
|
+
|
|
55
|
+
return { x: 0, y: 0, width: 0, height: 0, rotation: 0 };
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { TOOLTIP_CSS_CONST } from
|
|
2
|
-
import { deepMix } from
|
|
3
|
-
import { HtmlTooltip } from
|
|
4
|
-
import Action from
|
|
5
|
-
import { getDelegationObject } from
|
|
1
|
+
import { TOOLTIP_CSS_CONST } from '@antv/component';
|
|
2
|
+
import { deepMix } from '@antv/util';
|
|
3
|
+
import { HtmlTooltip } from '../../../../dependents';
|
|
4
|
+
import Action from '../../base';
|
|
5
|
+
import { getDelegationObject } from '../../util';
|
|
6
|
+
import cx from 'classnames';
|
|
6
7
|
|
|
7
|
-
const AXIS_DESCRIPTION_TOOLTIP = 'aixs-description-tooltip'
|
|
8
|
+
const AXIS_DESCRIPTION_TOOLTIP = 'aixs-description-tooltip';
|
|
8
9
|
|
|
9
10
|
class AxisDescription extends Action {
|
|
10
11
|
private tooltip;
|
|
@@ -12,29 +13,26 @@ class AxisDescription extends Action {
|
|
|
12
13
|
public show() {
|
|
13
14
|
const context = this.context;
|
|
14
15
|
const { axis } = getDelegationObject(context);
|
|
15
|
-
const { description, text } = axis.cfg.title;
|
|
16
|
+
const { description, text, descriptionTooltipStyle } = axis.cfg.title;
|
|
16
17
|
const { x, y } = context.event;
|
|
17
|
-
if(!this.tooltip) {
|
|
18
|
-
this.renderTooltip()
|
|
19
|
-
}
|
|
18
|
+
if (!this.tooltip) {
|
|
19
|
+
this.renderTooltip();
|
|
20
|
+
}
|
|
20
21
|
this.tooltip.update({
|
|
21
22
|
title: text || '',
|
|
22
23
|
customContent: () => {
|
|
23
|
-
return
|
|
24
|
-
<div class="${TOOLTIP_CSS_CONST.CONTAINER_CLASS}">
|
|
24
|
+
return `
|
|
25
|
+
<div class="${TOOLTIP_CSS_CONST.CONTAINER_CLASS}" style={${descriptionTooltipStyle}}>
|
|
25
26
|
<div class="${TOOLTIP_CSS_CONST.TITLE_CLASS}">
|
|
26
|
-
|
|
27
|
-
</div>
|
|
28
|
-
<div class="${TOOLTIP_CSS_CONST.LIST_CLASS}">
|
|
29
|
-
${description}
|
|
27
|
+
字段说明:${description}
|
|
30
28
|
</div>
|
|
31
29
|
</div>
|
|
32
|
-
|
|
30
|
+
`;
|
|
33
31
|
},
|
|
34
32
|
x,
|
|
35
|
-
y
|
|
33
|
+
y,
|
|
36
34
|
});
|
|
37
|
-
this.tooltip.show()
|
|
35
|
+
this.tooltip.show();
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
public destroy() {
|
|
@@ -43,7 +41,7 @@ class AxisDescription extends Action {
|
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
public hide() {
|
|
46
|
-
this.tooltip && this.tooltip.hide()
|
|
44
|
+
this.tooltip && this.tooltip.hide();
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
public renderTooltip() {
|
|
@@ -59,28 +57,28 @@ class AxisDescription extends Action {
|
|
|
59
57
|
visible: false,
|
|
60
58
|
containerId: AXIS_DESCRIPTION_TOOLTIP,
|
|
61
59
|
domStyles: {
|
|
62
|
-
...deepMix(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
...deepMix(
|
|
61
|
+
{},
|
|
62
|
+
{
|
|
63
|
+
// 超长的时候,tooltip tip 最大宽度为 50%,然后可以换行
|
|
64
|
+
[TOOLTIP_CSS_CONST.CONTAINER_CLASS]: {
|
|
65
|
+
'max-width': '50%',
|
|
66
|
+
padding: '10px',
|
|
67
|
+
'line-height': '15px',
|
|
68
|
+
'font-size': '12px',
|
|
69
|
+
color: 'rgba(0, 0, 0, .65)',
|
|
70
|
+
},
|
|
71
|
+
[TOOLTIP_CSS_CONST.TITLE_CLASS]: {
|
|
72
|
+
'word-break': 'break-all',
|
|
73
|
+
'margin-bottom': '3px',
|
|
74
|
+
},
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
),
|
|
79
77
|
},
|
|
80
78
|
});
|
|
81
79
|
tooltip.init();
|
|
82
80
|
tooltip.setCapture(false);
|
|
83
|
-
this.tooltip = tooltip
|
|
81
|
+
this.tooltip = tooltip;
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
|
-
export default AxisDescription
|
|
84
|
+
export default AxisDescription;
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { isNumber } from '@antv/util';
|
|
2
|
-
import {
|
|
3
|
-
import { BBox, Point } from '../dependents';
|
|
2
|
+
import { Point } from '../dependents';
|
|
4
3
|
|
|
5
|
-
const { dot } = vec2;
|
|
6
4
|
type Vec2 = [number, number];
|
|
7
5
|
|
|
8
|
-
type
|
|
9
|
-
|
|
6
|
+
type Item = {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
rotation?: number;
|
|
12
|
+
visible?: boolean;
|
|
13
|
+
};
|
|
10
14
|
/**
|
|
11
15
|
* 定义投影对象
|
|
12
16
|
*/
|
|
13
17
|
type Projection = { min: number; max: number };
|
|
14
18
|
|
|
19
|
+
function dot(a, b) {
|
|
20
|
+
return (a[0] || 0) * (b[0] || 0) + (a[1] || 0) * (b[1] || 0) + (a[2] || 0) * (b[2] || 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* @private
|
|
17
25
|
* 1. 获取投影轴
|
|
@@ -52,7 +60,7 @@ function rotateAtPoint(point: Point, deg = 0, origin = { x: 0, y: 0 }): Point {
|
|
|
52
60
|
*
|
|
53
61
|
* @param {Object} box
|
|
54
62
|
*/
|
|
55
|
-
function getRectPoints(box:
|
|
63
|
+
function getRectPoints(box: Item): Point[] {
|
|
56
64
|
const points = [
|
|
57
65
|
{ x: box.x, y: box.y },
|
|
58
66
|
{ x: box.x + box.width, y: box.y },
|
|
@@ -99,17 +107,17 @@ function isProjectionOverlap(projection1: Projection, projection2: Projection):
|
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
function isValidNumber(d: number) {
|
|
102
|
-
return
|
|
110
|
+
return typeof d === 'number' && !Number.isNaN(d) && d !== Infinity && d !== -Infinity;
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
function isValidBox(box:
|
|
106
|
-
return
|
|
113
|
+
function isValidBox(box: Item) {
|
|
114
|
+
return ['x', 'y', 'width', 'height'].every(attr => isValidNumber(box[attr]))
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
/**
|
|
110
118
|
* 快速判断两个无旋转矩形是否遮挡
|
|
111
119
|
*/
|
|
112
|
-
export function isIntersectRect(box1:
|
|
120
|
+
export function isIntersectRect(box1: Item, box2: Item, margin: number = 0): boolean {
|
|
113
121
|
return !(
|
|
114
122
|
box2.x > box1.x + box1.width + margin ||
|
|
115
123
|
box2.x + box2.width < box1.x - margin ||
|
|
@@ -124,13 +132,13 @@ export function isIntersectRect(box1: Box, box2: Box, margin: number = 0): boole
|
|
|
124
132
|
*
|
|
125
133
|
* - 原理: 分离轴定律
|
|
126
134
|
*/
|
|
127
|
-
export function
|
|
135
|
+
export function intersect(box1: Item, box2: Item, margin: number = 0) {
|
|
128
136
|
// 如果两个 box 中有一个是不合法的 box,也就是不会被渲染出来的,那么它们就不相交。
|
|
129
137
|
if (!isValidBox(box1) || !isValidBox(box2)) return false;
|
|
130
138
|
|
|
131
139
|
// 如果两个矩形没有旋转,使用快速判断
|
|
132
140
|
if (!box1.rotation && !box2.rotation) {
|
|
133
|
-
return isIntersectRect(box1, box2);
|
|
141
|
+
return isIntersectRect(box1, box2, margin);
|
|
134
142
|
}
|
|
135
143
|
|
|
136
144
|
// 分别获取 4 个关键点
|
|
@@ -138,7 +146,7 @@ export function isIntersect(box1: Box, box2: Box) {
|
|
|
138
146
|
const rect2Points = getRectPoints(box2);
|
|
139
147
|
|
|
140
148
|
// 获取所有投影轴
|
|
141
|
-
const axes =
|
|
149
|
+
const axes = getAxes(rect1Points).concat(getAxes(rect2Points));
|
|
142
150
|
|
|
143
151
|
for (let i = 0; i < axes.length; i++) {
|
|
144
152
|
const axis = axes[i];
|
|
@@ -146,7 +154,9 @@ export function isIntersect(box1: Box, box2: Box) {
|
|
|
146
154
|
const projection2 = getProjection(rect2Points, axis);
|
|
147
155
|
|
|
148
156
|
// 判断投影轴上的投影是否存在重叠,若检测到存在间隙则立刻退出判断,消除不必要的运算。
|
|
149
|
-
if (!isProjectionOverlap(projection1, projection2))
|
|
157
|
+
if (!isProjectionOverlap(projection1, projection2)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
return true;
|