@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.
Files changed (274) hide show
  1. package/dist/g2.min.js +3 -3
  2. package/dist/g2.min.js.map +1 -1
  3. package/esm/animate/animation/sector-path-update.js +3 -3
  4. package/esm/animate/animation/sector-path-update.js.map +1 -1
  5. package/esm/animate/animation/util.js +2 -1
  6. package/esm/animate/animation/util.js.map +1 -1
  7. package/esm/chart/controller/annotation.js +20 -10
  8. package/esm/chart/controller/annotation.js.map +1 -1
  9. package/esm/chart/controller/coordinate.js +3 -3
  10. package/esm/chart/controller/coordinate.js.map +1 -1
  11. package/esm/chart/controller/legend.js +3 -3
  12. package/esm/chart/controller/legend.js.map +1 -1
  13. package/esm/chart/controller/scrollbar.js +8 -8
  14. package/esm/chart/controller/scrollbar.js.map +1 -1
  15. package/esm/chart/controller/slider.js +8 -8
  16. package/esm/chart/controller/slider.js.map +1 -1
  17. package/esm/chart/controller/tooltip.js +82 -34
  18. package/esm/chart/controller/tooltip.js.map +1 -1
  19. package/esm/chart/layout/auto.js +2 -2
  20. package/esm/chart/layout/auto.js.map +1 -1
  21. package/esm/chart/layout/constraint/constraint.js +2 -1
  22. package/esm/chart/layout/constraint/constraint.js.map +1 -1
  23. package/esm/chart/layout/constraint/solver.js +2 -1
  24. package/esm/chart/layout/constraint/solver.js.map +1 -1
  25. package/esm/chart/layout/padding-cal.js +4 -4
  26. package/esm/chart/layout/padding-cal.js.map +1 -1
  27. package/esm/chart/view.js +2 -2
  28. package/esm/chart/view.js.map +1 -1
  29. package/esm/component/labels.d.ts +1 -2
  30. package/esm/component/labels.js +134 -103
  31. package/esm/component/labels.js.map +1 -1
  32. package/esm/constant.d.ts +3 -1
  33. package/esm/constant.js +2 -0
  34. package/esm/constant.js.map +1 -1
  35. package/esm/core.d.ts +1 -1
  36. package/esm/core.js +1 -1
  37. package/esm/core.js.map +1 -1
  38. package/esm/facet/circle.js +2 -2
  39. package/esm/facet/circle.js.map +1 -1
  40. package/esm/facet/facet.js +3 -2
  41. package/esm/facet/facet.js.map +1 -1
  42. package/esm/facet/list.js +2 -2
  43. package/esm/facet/list.js.map +1 -1
  44. package/esm/facet/mirror.js +2 -2
  45. package/esm/facet/mirror.js.map +1 -1
  46. package/esm/facet/rect.js +2 -2
  47. package/esm/facet/rect.js.map +1 -1
  48. package/esm/facet/tree.js +20 -10
  49. package/esm/facet/tree.js.map +1 -1
  50. package/esm/geometry/base.d.ts +3 -0
  51. package/esm/geometry/base.js +151 -82
  52. package/esm/geometry/base.js.map +1 -1
  53. package/esm/geometry/element/index.js +3 -1
  54. package/esm/geometry/element/index.js.map +1 -1
  55. package/esm/geometry/heatmap.js +17 -7
  56. package/esm/geometry/heatmap.js.map +1 -1
  57. package/esm/geometry/label/base.d.ts +1 -1
  58. package/esm/geometry/label/base.js +20 -8
  59. package/esm/geometry/label/base.js.map +1 -1
  60. package/esm/geometry/label/layout/hide-overlap.d.ts +1 -1
  61. package/esm/geometry/label/layout/hide-overlap.js +65 -19
  62. package/esm/geometry/label/layout/hide-overlap.js.map +1 -1
  63. package/esm/geometry/label/layout/interval/hide-overlap.js +3 -2
  64. package/esm/geometry/label/layout/interval/hide-overlap.js.map +1 -1
  65. package/esm/geometry/label/layout/path/adjust-position.js +3 -2
  66. package/esm/geometry/label/layout/path/adjust-position.js.map +1 -1
  67. package/esm/geometry/label/layout/pie/distribute.js +14 -3
  68. package/esm/geometry/label/layout/pie/distribute.js.map +1 -1
  69. package/esm/geometry/label/layout/pie/outer.js +14 -3
  70. package/esm/geometry/label/layout/pie/outer.js.map +1 -1
  71. package/esm/geometry/label/layout/pie/spider.js +14 -3
  72. package/esm/geometry/label/layout/pie/spider.js.map +1 -1
  73. package/esm/geometry/label/layout/point/adjust-position.js +3 -2
  74. package/esm/geometry/label/layout/point/adjust-position.js.map +1 -1
  75. package/esm/geometry/label/layout/worker/hide-overlap.d.ts +2 -0
  76. package/esm/geometry/label/layout/worker/hide-overlap.js +155 -0
  77. package/esm/geometry/label/layout/worker/hide-overlap.js.map +1 -0
  78. package/esm/geometry/label/util/createWorker.d.ts +1 -0
  79. package/esm/geometry/label/util/createWorker.js +16 -0
  80. package/esm/geometry/label/util/createWorker.js.map +1 -0
  81. package/esm/geometry/label/util/index.d.ts +4 -2
  82. package/esm/geometry/label/util/index.js +3 -2
  83. package/esm/geometry/label/util/index.js.map +1 -1
  84. package/esm/geometry/path.js +65 -37
  85. package/esm/geometry/path.js.map +1 -1
  86. package/esm/geometry/shape/interval/tick.js +3 -2
  87. package/esm/geometry/shape/interval/tick.js.map +1 -1
  88. package/esm/geometry/shape/interval/util.js +14 -13
  89. package/esm/geometry/shape/interval/util.js.map +1 -1
  90. package/esm/geometry/shape/point/image.js +22 -11
  91. package/esm/geometry/shape/point/image.js.map +1 -1
  92. package/esm/geometry/shape/point/util.js +17 -7
  93. package/esm/geometry/shape/point/util.js.map +1 -1
  94. package/esm/geometry/shape/util/path.js +3 -1
  95. package/esm/geometry/shape/util/path.js.map +1 -1
  96. package/esm/geometry/util/group-data.js +17 -6
  97. package/esm/geometry/util/group-data.js.map +1 -1
  98. package/esm/interaction/action/active-region.js +42 -14
  99. package/esm/interaction/action/active-region.js.map +1 -1
  100. package/esm/interaction/action/component/axis/axis-description.d.ts +1 -1
  101. package/esm/interaction/action/component/axis/axis-description.js +13 -17
  102. package/esm/interaction/action/component/axis/axis-description.js.map +1 -1
  103. package/esm/interaction/action/component/list-focus.js +50 -13
  104. package/esm/interaction/action/component/list-focus.js.map +1 -1
  105. package/esm/interaction/action/data/filter.js +2 -2
  106. package/esm/interaction/action/data/filter.js.map +1 -1
  107. package/esm/interaction/action/data/range-filter.js +2 -2
  108. package/esm/interaction/action/data/range-filter.js.map +1 -1
  109. package/esm/interaction/action/element/filter.js +2 -2
  110. package/esm/interaction/action/element/filter.js.map +1 -1
  111. package/esm/util/attr.js +2 -2
  112. package/esm/util/attr.js.map +1 -1
  113. package/esm/util/bbox.js +3 -2
  114. package/esm/util/bbox.js.map +1 -1
  115. package/esm/util/collision-detect.d.ts +8 -4
  116. package/esm/util/collision-detect.js +13 -11
  117. package/esm/util/collision-detect.js.map +1 -1
  118. package/esm/util/color.js +2 -1
  119. package/esm/util/color.js.map +1 -1
  120. package/esm/util/helper.js +16 -5
  121. package/esm/util/helper.js.map +1 -1
  122. package/esm/util/padding.js +3 -3
  123. package/esm/util/padding.js.map +1 -1
  124. package/esm/util/scale.js +2 -2
  125. package/esm/util/scale.js.map +1 -1
  126. package/esm/util/stat.js +2 -2
  127. package/esm/util/stat.js.map +1 -1
  128. package/esm/util/text.js +2 -2
  129. package/esm/util/text.js.map +1 -1
  130. package/esm/util/tooltip.js +109 -59
  131. package/esm/util/tooltip.js.map +1 -1
  132. package/lib/animate/animation/sector-path-update.js +2 -2
  133. package/lib/animate/animation/sector-path-update.js.map +1 -1
  134. package/lib/animate/animation/util.js +2 -1
  135. package/lib/animate/animation/util.js.map +1 -1
  136. package/lib/chart/controller/annotation.js +19 -9
  137. package/lib/chart/controller/annotation.js.map +1 -1
  138. package/lib/chart/controller/coordinate.js +2 -2
  139. package/lib/chart/controller/coordinate.js.map +1 -1
  140. package/lib/chart/controller/legend.js +2 -2
  141. package/lib/chart/controller/legend.js.map +1 -1
  142. package/lib/chart/controller/scrollbar.js +7 -7
  143. package/lib/chart/controller/scrollbar.js.map +1 -1
  144. package/lib/chart/controller/slider.js +7 -7
  145. package/lib/chart/controller/slider.js.map +1 -1
  146. package/lib/chart/controller/tooltip.js +81 -33
  147. package/lib/chart/controller/tooltip.js.map +1 -1
  148. package/lib/chart/layout/auto.js +1 -1
  149. package/lib/chart/layout/auto.js.map +1 -1
  150. package/lib/chart/layout/constraint/constraint.js +2 -1
  151. package/lib/chart/layout/constraint/constraint.js.map +1 -1
  152. package/lib/chart/layout/constraint/solver.js +2 -1
  153. package/lib/chart/layout/constraint/solver.js.map +1 -1
  154. package/lib/chart/layout/padding-cal.js +3 -3
  155. package/lib/chart/layout/padding-cal.js.map +1 -1
  156. package/lib/chart/view.js +1 -1
  157. package/lib/chart/view.js.map +1 -1
  158. package/lib/component/labels.d.ts +1 -2
  159. package/lib/component/labels.js +132 -101
  160. package/lib/component/labels.js.map +1 -1
  161. package/lib/constant.d.ts +3 -1
  162. package/lib/constant.js +2 -0
  163. package/lib/constant.js.map +1 -1
  164. package/lib/core.d.ts +1 -1
  165. package/lib/core.js +1 -1
  166. package/lib/core.js.map +1 -1
  167. package/lib/facet/circle.js +1 -1
  168. package/lib/facet/circle.js.map +1 -1
  169. package/lib/facet/facet.js +3 -2
  170. package/lib/facet/facet.js.map +1 -1
  171. package/lib/facet/list.js +1 -1
  172. package/lib/facet/list.js.map +1 -1
  173. package/lib/facet/mirror.js +1 -1
  174. package/lib/facet/mirror.js.map +1 -1
  175. package/lib/facet/rect.js +1 -1
  176. package/lib/facet/rect.js.map +1 -1
  177. package/lib/facet/tree.js +19 -9
  178. package/lib/facet/tree.js.map +1 -1
  179. package/lib/geometry/base.d.ts +3 -0
  180. package/lib/geometry/base.js +149 -80
  181. package/lib/geometry/base.js.map +1 -1
  182. package/lib/geometry/element/index.js +3 -1
  183. package/lib/geometry/element/index.js.map +1 -1
  184. package/lib/geometry/heatmap.js +16 -6
  185. package/lib/geometry/heatmap.js.map +1 -1
  186. package/lib/geometry/label/base.d.ts +1 -1
  187. package/lib/geometry/label/base.js +19 -7
  188. package/lib/geometry/label/base.js.map +1 -1
  189. package/lib/geometry/label/layout/hide-overlap.d.ts +1 -1
  190. package/lib/geometry/label/layout/hide-overlap.js +62 -16
  191. package/lib/geometry/label/layout/hide-overlap.js.map +1 -1
  192. package/lib/geometry/label/layout/interval/hide-overlap.js +3 -2
  193. package/lib/geometry/label/layout/interval/hide-overlap.js.map +1 -1
  194. package/lib/geometry/label/layout/path/adjust-position.js +3 -2
  195. package/lib/geometry/label/layout/path/adjust-position.js.map +1 -1
  196. package/lib/geometry/label/layout/pie/distribute.js +14 -3
  197. package/lib/geometry/label/layout/pie/distribute.js.map +1 -1
  198. package/lib/geometry/label/layout/pie/outer.js +14 -3
  199. package/lib/geometry/label/layout/pie/outer.js.map +1 -1
  200. package/lib/geometry/label/layout/pie/spider.js +14 -3
  201. package/lib/geometry/label/layout/pie/spider.js.map +1 -1
  202. package/lib/geometry/label/layout/point/adjust-position.js +3 -2
  203. package/lib/geometry/label/layout/point/adjust-position.js.map +1 -1
  204. package/lib/geometry/label/layout/worker/hide-overlap.d.ts +2 -0
  205. package/lib/geometry/label/layout/worker/hide-overlap.js +158 -0
  206. package/lib/geometry/label/layout/worker/hide-overlap.js.map +1 -0
  207. package/lib/geometry/label/util/createWorker.d.ts +1 -0
  208. package/lib/geometry/label/util/createWorker.js +20 -0
  209. package/lib/geometry/label/util/createWorker.js.map +1 -0
  210. package/lib/geometry/label/util/index.d.ts +4 -2
  211. package/lib/geometry/label/util/index.js +5 -4
  212. package/lib/geometry/label/util/index.js.map +1 -1
  213. package/lib/geometry/path.js +64 -36
  214. package/lib/geometry/path.js.map +1 -1
  215. package/lib/geometry/shape/interval/tick.js +2 -1
  216. package/lib/geometry/shape/interval/tick.js.map +1 -1
  217. package/lib/geometry/shape/interval/util.js +13 -12
  218. package/lib/geometry/shape/interval/util.js.map +1 -1
  219. package/lib/geometry/shape/point/image.js +22 -11
  220. package/lib/geometry/shape/point/image.js.map +1 -1
  221. package/lib/geometry/shape/point/util.js +16 -6
  222. package/lib/geometry/shape/point/util.js.map +1 -1
  223. package/lib/geometry/shape/util/path.js +3 -1
  224. package/lib/geometry/shape/util/path.js.map +1 -1
  225. package/lib/geometry/util/group-data.js +17 -6
  226. package/lib/geometry/util/group-data.js.map +1 -1
  227. package/lib/interaction/action/active-region.js +41 -13
  228. package/lib/interaction/action/active-region.js.map +1 -1
  229. package/lib/interaction/action/component/axis/axis-description.d.ts +1 -1
  230. package/lib/interaction/action/component/axis/axis-description.js +8 -12
  231. package/lib/interaction/action/component/axis/axis-description.js.map +1 -1
  232. package/lib/interaction/action/component/list-focus.js +49 -12
  233. package/lib/interaction/action/component/list-focus.js.map +1 -1
  234. package/lib/interaction/action/data/filter.js +1 -1
  235. package/lib/interaction/action/data/filter.js.map +1 -1
  236. package/lib/interaction/action/data/range-filter.js +1 -1
  237. package/lib/interaction/action/data/range-filter.js.map +1 -1
  238. package/lib/interaction/action/element/filter.js +1 -1
  239. package/lib/interaction/action/element/filter.js.map +1 -1
  240. package/lib/util/attr.js +1 -1
  241. package/lib/util/attr.js.map +1 -1
  242. package/lib/util/bbox.js +3 -2
  243. package/lib/util/bbox.js.map +1 -1
  244. package/lib/util/collision-detect.d.ts +8 -4
  245. package/lib/util/collision-detect.js +14 -12
  246. package/lib/util/collision-detect.js.map +1 -1
  247. package/lib/util/color.js +1 -1
  248. package/lib/util/color.js.map +1 -1
  249. package/lib/util/helper.js +16 -5
  250. package/lib/util/helper.js.map +1 -1
  251. package/lib/util/padding.js +2 -2
  252. package/lib/util/padding.js.map +1 -1
  253. package/lib/util/scale.js +1 -1
  254. package/lib/util/scale.js.map +1 -1
  255. package/lib/util/stat.js +1 -1
  256. package/lib/util/stat.js.map +1 -1
  257. package/lib/util/text.js +1 -1
  258. package/lib/util/text.js.map +1 -1
  259. package/lib/util/tooltip.js +108 -58
  260. package/lib/util/tooltip.js.map +1 -1
  261. package/package.json +1 -1
  262. package/src/component/labels.ts +37 -40
  263. package/src/constant.ts +3 -0
  264. package/src/core.ts +1 -1
  265. package/src/geometry/base.ts +42 -30
  266. package/src/geometry/element/index.ts +2 -2
  267. package/src/geometry/label/base.ts +3 -3
  268. package/src/geometry/label/layout/hide-overlap.ts +73 -21
  269. package/src/geometry/label/layout/path/adjust-position.ts +1 -2
  270. package/src/geometry/label/layout/worker/hide-overlap.ts +192 -0
  271. package/src/geometry/label/util/createWorker.ts +15 -0
  272. package/src/geometry/label/util/index.ts +5 -4
  273. package/src/interaction/action/component/axis/axis-description.ts +36 -38
  274. 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 getlLabelBackgroundInfo(
20
+ export function getLabelBackgroundInfo(
22
21
  labelGroup: IGroup,
23
- labelItem: 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 "@antv/component";
2
- import { deepMix } from "@antv/util";
3
- import { HtmlTooltip } from "../../../../dependents";
4
- import Action from "../../base";
5
- import { getDelegationObject } from "../../util";
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
- ${text}
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
- // 超长的时候,tooltip tip 最大宽度为 50%,然后可以换行
64
- [TOOLTIP_CSS_CONST.CONTAINER_CLASS]: {
65
- 'max-width': '50%',
66
- 'padding': '5px',
67
- 'line-height': '15px'
68
- },
69
- [TOOLTIP_CSS_CONST.TITLE_CLASS]: {
70
- 'word-break': 'break-all',
71
- 'font-size': '14px',
72
- 'margin-bottom': '3px'
73
- },
74
- [TOOLTIP_CSS_CONST.LIST_CLASS]: {
75
- 'word-break': 'break-all',
76
- 'opacity': '.5'
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 { vec2 } from '@antv/matrix-util';
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 Box = Pick<BBox, 'x' | 'y' | 'width' | 'height'> & { rotation?: number };
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: Box): Point[] {
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 isNumber(d) && !Number.isNaN(d) && d !== Infinity && d !== -Infinity;
110
+ return typeof d === 'number' && !Number.isNaN(d) && d !== Infinity && d !== -Infinity;
103
111
  }
104
112
 
105
- function isValidBox(box: Box) {
106
- return Object.values(box).every(isValidNumber);
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: Box, box2: Box, margin: number = 0): boolean {
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 isIntersect(box1: Box, box2: Box) {
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 = [...getAxes(rect1Points), ...getAxes(rect2Points)];
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)) return false;
157
+ if (!isProjectionOverlap(projection1, projection2)) {
158
+ return false;
159
+ }
150
160
  }
151
161
 
152
162
  return true;