@antv/g2 4.1.31 → 4.1.36

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 (245) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.en-US.md +1 -2
  3. package/README.md +1 -2
  4. package/dist/g2.min.js +17 -3
  5. package/dist/g2.min.js.map +1 -1
  6. package/esm/chart/controller/axis.js +3 -3
  7. package/esm/chart/controller/axis.js.map +1 -1
  8. package/esm/chart/controller/gesture.js +2 -2
  9. package/esm/chart/controller/gesture.js.map +1 -1
  10. package/esm/chart/controller/legend.js +1 -1
  11. package/esm/chart/controller/legend.js.map +1 -1
  12. package/esm/chart/controller/scrollbar.js +1 -0
  13. package/esm/chart/controller/scrollbar.js.map +1 -1
  14. package/esm/chart/controller/tooltip.js +2 -2
  15. package/esm/chart/controller/tooltip.js.map +1 -1
  16. package/esm/chart/event.js +1 -1
  17. package/esm/chart/event.js.map +1 -1
  18. package/esm/chart/layout/constraint/bounds.js +4 -4
  19. package/esm/chart/layout/constraint/bounds.js.map +1 -1
  20. package/esm/chart/layout/constraint/constraint.js.map +1 -1
  21. package/esm/chart/layout/constraint/gauss.js +3 -3
  22. package/esm/chart/layout/constraint/gauss.js.map +1 -1
  23. package/esm/chart/layout/constraint/solver.js.map +1 -1
  24. package/esm/chart/layout/constraint/types.js.map +1 -1
  25. package/esm/chart/layout/constraint/variable.js +1 -1
  26. package/esm/chart/layout/constraint/variable.js.map +1 -1
  27. package/esm/chart/util/scale-pool.js +1 -1
  28. package/esm/chart/util/scale-pool.js.map +1 -1
  29. package/esm/chart/util/sync-view-padding.js.map +1 -1
  30. package/esm/chart/view.js +4 -4
  31. package/esm/chart/view.js.map +1 -1
  32. package/esm/core.d.ts +5 -1
  33. package/esm/core.js +6 -1
  34. package/esm/core.js.map +1 -1
  35. package/esm/dependents.d.ts +1 -1
  36. package/esm/dependents.js +1 -1
  37. package/esm/dependents.js.map +1 -1
  38. package/esm/engine/index.js +1 -1
  39. package/esm/engine/index.js.map +1 -1
  40. package/esm/geometry/base.d.ts +6 -2
  41. package/esm/geometry/base.js +22 -17
  42. package/esm/geometry/base.js.map +1 -1
  43. package/esm/geometry/element/index.d.ts +4 -0
  44. package/esm/geometry/element/index.js +5 -2
  45. package/esm/geometry/element/index.js.map +1 -1
  46. package/esm/geometry/label/base.js +2 -2
  47. package/esm/geometry/label/base.js.map +1 -1
  48. package/esm/geometry/label/interval.d.ts +2 -5
  49. package/esm/geometry/label/interval.js +11 -3
  50. package/esm/geometry/label/interval.js.map +1 -1
  51. package/esm/geometry/label/layout/limit-in-plot.js.map +1 -1
  52. package/esm/geometry/label/layout/overlap.js +2 -2
  53. package/esm/geometry/label/layout/overlap.js.map +1 -1
  54. package/esm/geometry/label/layout/pie/distribute.js +3 -3
  55. package/esm/geometry/label/layout/pie/distribute.js.map +1 -1
  56. package/esm/geometry/label/layout/pie/outer.js +6 -6
  57. package/esm/geometry/label/layout/pie/outer.js.map +1 -1
  58. package/esm/geometry/label/layout/pie/spider.js +5 -5
  59. package/esm/geometry/label/layout/pie/spider.js.map +1 -1
  60. package/esm/geometry/path.js +1 -0
  61. package/esm/geometry/path.js.map +1 -1
  62. package/esm/geometry/shape/edge/util.js +1 -6
  63. package/esm/geometry/shape/edge/util.js.map +1 -1
  64. package/esm/geometry/shape/interval/util.js +63 -47
  65. package/esm/geometry/shape/interval/util.js.map +1 -1
  66. package/esm/geometry/shape/line/index.d.ts +6 -0
  67. package/esm/geometry/shape/line/index.js +4 -1
  68. package/esm/geometry/shape/line/index.js.map +1 -1
  69. package/esm/geometry/shape/point/index.js +1 -1
  70. package/esm/geometry/shape/point/index.js.map +1 -1
  71. package/esm/geometry/shape/violin/hollow.js.map +1 -1
  72. package/esm/geometry/shape/violin/index.js.map +1 -1
  73. package/esm/geometry/util/group-data.js +1 -1
  74. package/esm/geometry/util/group-data.js.map +1 -1
  75. package/esm/geometry/util/shape-size.js +1 -1
  76. package/esm/geometry/util/shape-size.js.map +1 -1
  77. package/esm/index.js +20 -3
  78. package/esm/index.js.map +1 -1
  79. package/esm/interaction/action/component/list-checked.js +1 -1
  80. package/esm/interaction/action/component/list-checked.js.map +1 -1
  81. package/esm/interaction/action/component/list-focus.d.ts +5 -0
  82. package/esm/interaction/action/component/list-focus.js +30 -0
  83. package/esm/interaction/action/component/list-focus.js.map +1 -0
  84. package/esm/interaction/action/component/list-radio.d.ts +6 -0
  85. package/esm/interaction/action/component/list-radio.js +26 -0
  86. package/esm/interaction/action/component/list-radio.js.map +1 -0
  87. package/esm/interaction/action/mask/base.js +1 -1
  88. package/esm/interaction/action/mask/base.js.map +1 -1
  89. package/esm/interaction/action/view/mousewheel-scroll.js +1 -1
  90. package/esm/interaction/action/view/mousewheel-scroll.js.map +1 -1
  91. package/esm/interaction/grammar-interaction.js +2 -2
  92. package/esm/interaction/grammar-interaction.js.map +1 -1
  93. package/esm/interface.d.ts +5 -0
  94. package/esm/interface.js.map +1 -1
  95. package/esm/theme/util/create-by-style-sheet.js +9 -9
  96. package/esm/theme/util/create-by-style-sheet.js.map +1 -1
  97. package/esm/util/axis.js.map +1 -1
  98. package/esm/util/bbox.js +1 -2
  99. package/esm/util/bbox.js.map +1 -1
  100. package/esm/util/event.js +1 -1
  101. package/esm/util/event.js.map +1 -1
  102. package/esm/util/legend.js +3 -1
  103. package/esm/util/legend.js.map +1 -1
  104. package/esm/util/scale.js.map +1 -1
  105. package/esm/util/stat.js +1 -1
  106. package/esm/util/stat.js.map +1 -1
  107. package/esm/util/text.js +2 -2
  108. package/esm/util/text.js.map +1 -1
  109. package/lib/chart/controller/axis.js +3 -3
  110. package/lib/chart/controller/axis.js.map +1 -1
  111. package/lib/chart/controller/gesture.js +2 -2
  112. package/lib/chart/controller/gesture.js.map +1 -1
  113. package/lib/chart/controller/legend.js +1 -1
  114. package/lib/chart/controller/legend.js.map +1 -1
  115. package/lib/chart/controller/scrollbar.js +1 -0
  116. package/lib/chart/controller/scrollbar.js.map +1 -1
  117. package/lib/chart/controller/tooltip.js +2 -2
  118. package/lib/chart/controller/tooltip.js.map +1 -1
  119. package/lib/chart/event.js +1 -1
  120. package/lib/chart/event.js.map +1 -1
  121. package/lib/chart/layout/constraint/bounds.js +4 -4
  122. package/lib/chart/layout/constraint/bounds.js.map +1 -1
  123. package/lib/chart/layout/constraint/constraint.js.map +1 -1
  124. package/lib/chart/layout/constraint/gauss.js +3 -3
  125. package/lib/chart/layout/constraint/gauss.js.map +1 -1
  126. package/lib/chart/layout/constraint/solver.js.map +1 -1
  127. package/lib/chart/layout/constraint/types.js.map +1 -1
  128. package/lib/chart/layout/constraint/variable.js +1 -1
  129. package/lib/chart/layout/constraint/variable.js.map +1 -1
  130. package/lib/chart/util/scale-pool.js +1 -1
  131. package/lib/chart/util/scale-pool.js.map +1 -1
  132. package/lib/chart/util/sync-view-padding.js.map +1 -1
  133. package/lib/chart/view.js +4 -4
  134. package/lib/chart/view.js.map +1 -1
  135. package/lib/core.d.ts +5 -1
  136. package/lib/core.js +6 -1
  137. package/lib/core.js.map +1 -1
  138. package/lib/dependents.d.ts +1 -1
  139. package/lib/dependents.js.map +1 -1
  140. package/lib/engine/index.js +1 -1
  141. package/lib/engine/index.js.map +1 -1
  142. package/lib/geometry/base.d.ts +6 -2
  143. package/lib/geometry/base.js +22 -17
  144. package/lib/geometry/base.js.map +1 -1
  145. package/lib/geometry/element/index.d.ts +4 -0
  146. package/lib/geometry/element/index.js +5 -2
  147. package/lib/geometry/element/index.js.map +1 -1
  148. package/lib/geometry/label/base.js +2 -2
  149. package/lib/geometry/label/base.js.map +1 -1
  150. package/lib/geometry/label/interval.d.ts +2 -5
  151. package/lib/geometry/label/interval.js +11 -3
  152. package/lib/geometry/label/interval.js.map +1 -1
  153. package/lib/geometry/label/layout/limit-in-plot.js.map +1 -1
  154. package/lib/geometry/label/layout/overlap.js +2 -2
  155. package/lib/geometry/label/layout/overlap.js.map +1 -1
  156. package/lib/geometry/label/layout/pie/distribute.js +3 -3
  157. package/lib/geometry/label/layout/pie/distribute.js.map +1 -1
  158. package/lib/geometry/label/layout/pie/outer.js +6 -6
  159. package/lib/geometry/label/layout/pie/outer.js.map +1 -1
  160. package/lib/geometry/label/layout/pie/spider.js +5 -5
  161. package/lib/geometry/label/layout/pie/spider.js.map +1 -1
  162. package/lib/geometry/path.js +1 -0
  163. package/lib/geometry/path.js.map +1 -1
  164. package/lib/geometry/shape/edge/util.js +1 -6
  165. package/lib/geometry/shape/edge/util.js.map +1 -1
  166. package/lib/geometry/shape/interval/util.js +63 -47
  167. package/lib/geometry/shape/interval/util.js.map +1 -1
  168. package/lib/geometry/shape/line/index.d.ts +6 -0
  169. package/lib/geometry/shape/line/index.js +5 -0
  170. package/lib/geometry/shape/line/index.js.map +1 -1
  171. package/lib/geometry/shape/point/index.js +1 -1
  172. package/lib/geometry/shape/point/index.js.map +1 -1
  173. package/lib/geometry/shape/violin/hollow.js.map +1 -1
  174. package/lib/geometry/shape/violin/index.js.map +1 -1
  175. package/lib/geometry/util/group-data.js +1 -1
  176. package/lib/geometry/util/group-data.js.map +1 -1
  177. package/lib/geometry/util/shape-size.js +1 -1
  178. package/lib/geometry/util/shape-size.js.map +1 -1
  179. package/lib/index.js +20 -3
  180. package/lib/index.js.map +1 -1
  181. package/lib/interaction/action/component/list-checked.js +1 -1
  182. package/lib/interaction/action/component/list-checked.js.map +1 -1
  183. package/lib/interaction/action/component/list-focus.d.ts +5 -0
  184. package/lib/interaction/action/component/list-focus.js +32 -0
  185. package/lib/interaction/action/component/list-focus.js.map +1 -0
  186. package/lib/interaction/action/component/list-radio.d.ts +6 -0
  187. package/lib/interaction/action/component/list-radio.js +28 -0
  188. package/lib/interaction/action/component/list-radio.js.map +1 -0
  189. package/lib/interaction/action/mask/base.js +1 -1
  190. package/lib/interaction/action/mask/base.js.map +1 -1
  191. package/lib/interaction/action/view/mousewheel-scroll.js.map +1 -1
  192. package/lib/interaction/grammar-interaction.js +2 -2
  193. package/lib/interaction/grammar-interaction.js.map +1 -1
  194. package/lib/interface.d.ts +5 -0
  195. package/lib/interface.js.map +1 -1
  196. package/lib/theme/util/create-by-style-sheet.js +9 -9
  197. package/lib/theme/util/create-by-style-sheet.js.map +1 -1
  198. package/lib/util/axis.js.map +1 -1
  199. package/lib/util/bbox.js +1 -2
  200. package/lib/util/bbox.js.map +1 -1
  201. package/lib/util/event.js +1 -1
  202. package/lib/util/event.js.map +1 -1
  203. package/lib/util/legend.js +3 -1
  204. package/lib/util/legend.js.map +1 -1
  205. package/lib/util/scale.js.map +1 -1
  206. package/lib/util/stat.js +1 -1
  207. package/lib/util/stat.js.map +1 -1
  208. package/lib/util/text.js +2 -2
  209. package/lib/util/text.js.map +1 -1
  210. package/package.json +15 -15
  211. package/src/chart/controller/scrollbar.ts +13 -12
  212. package/src/chart/controller/tooltip.ts +2 -2
  213. package/src/chart/layout/constraint/bounds.ts +3 -4
  214. package/src/chart/layout/constraint/constraint.ts +4 -5
  215. package/src/chart/layout/constraint/gauss.ts +7 -7
  216. package/src/chart/layout/constraint/solver.ts +5 -6
  217. package/src/chart/layout/constraint/types.ts +2 -2
  218. package/src/chart/layout/constraint/variable.ts +2 -2
  219. package/src/chart/util/scale-pool.ts +8 -4
  220. package/src/chart/util/sync-view-padding.ts +1 -1
  221. package/src/chart/view.ts +10 -6
  222. package/src/core.ts +7 -1
  223. package/src/dependents.ts +11 -3
  224. package/src/geometry/base.ts +21 -11
  225. package/src/geometry/element/index.ts +9 -2
  226. package/src/geometry/label/interval.ts +20 -8
  227. package/src/geometry/label/layout/limit-in-plot.ts +6 -4
  228. package/src/geometry/path.ts +1 -0
  229. package/src/geometry/shape/edge/util.ts +1 -6
  230. package/src/geometry/shape/interval/util.ts +65 -46
  231. package/src/geometry/shape/line/index.ts +4 -1
  232. package/src/geometry/shape/violin/hollow.ts +1 -1
  233. package/src/geometry/shape/violin/index.ts +2 -2
  234. package/src/geometry/util/shape-size.ts +2 -5
  235. package/src/index.ts +20 -3
  236. package/src/interaction/action/component/list-checked.ts +1 -1
  237. package/src/interaction/action/component/list-focus.ts +24 -0
  238. package/src/interaction/action/component/list-radio.ts +23 -0
  239. package/src/interaction/action/view/mousewheel-scroll.ts +3 -4
  240. package/src/interface.ts +10 -3
  241. package/src/util/axis.ts +9 -4
  242. package/src/util/bbox.ts +1 -2
  243. package/src/util/legend.ts +6 -4
  244. package/src/util/scale.ts +9 -4
  245. package/src/util/stat.ts +9 -5
@@ -17,6 +17,8 @@ interface ElementCfg {
17
17
  shapeFactory: ShapeFactory;
18
18
  /** shape 容器 */
19
19
  container: IGroup;
20
+ /** element 的索引 */
21
+ elementIndex?: number;
20
22
  /** 虚拟 group,用户可以不传入 */
21
23
  offscreenGroup?: IGroup;
22
24
  /** 是否可见 */
@@ -32,6 +34,8 @@ export default class Element extends Base {
32
34
  public shapeFactory: ShapeFactory;
33
35
  /** shape 容器 */
34
36
  public container: IGroup;
37
+ /** element 索引 */
38
+ public elementIndex: number;
35
39
  /** 最后创建的图形对象 */
36
40
  public shape: IShape | IGroup;
37
41
  /** shape 的动画配置 */
@@ -59,11 +63,12 @@ export default class Element extends Base {
59
63
  constructor(cfg: ElementCfg) {
60
64
  super(cfg);
61
65
 
62
- const { shapeFactory, container, offscreenGroup, visible = true } = cfg;
66
+ const { shapeFactory, container, offscreenGroup, elementIndex, visible = true } = cfg;
63
67
  this.shapeFactory = shapeFactory;
64
68
  this.container = container;
65
69
  this.offscreenGroup = offscreenGroup;
66
70
  this.visible = visible;
71
+ this.elementIndex = elementIndex;
67
72
  }
68
73
 
69
74
  /**
@@ -224,7 +229,9 @@ export default class Element extends Base {
224
229
  }
225
230
  states.splice(index, 1);
226
231
  if (stateName === 'active' || stateName === 'selected') {
227
- shape?.toBack();
232
+ const { sortZIndex, zIndexReversed } = this.geometry;
233
+ const idx = zIndexReversed ? this.geometry.elements.length - this.elementIndex : this.elementIndex;
234
+ sortZIndex ? shape.setZIndex(idx) : shape.set('zIndex', idx);
228
235
  }
229
236
  }
230
237
 
@@ -2,7 +2,7 @@ import { get, deepMix, isArray } from '@antv/util';
2
2
  import { Writeable } from '../../util/types';
3
3
  import { MappingDatum, Point } from '../../interface';
4
4
  import GeometryLabel from './base';
5
- import { LabelCfg, LabelPointCfg } from './interface';
5
+ import { LabelCfg, LabelItem, LabelPointCfg, TextAlign } from './interface';
6
6
 
7
7
  /**
8
8
  * 柱状图 label
@@ -26,16 +26,28 @@ export default class IntervalLabel extends GeometryLabel {
26
26
  * @param index
27
27
  * @param total
28
28
  */
29
- protected getLabelOffsetPoint(labelCfg: LabelCfg, index: number, total: number) {
30
- const point = super.getLabelOffsetPoint(labelCfg, index, total);
31
- const transposed = this.getCoordinate().isTransposed;
29
+ protected getLabelOffsetPoint(labelCfg: LabelCfg, index: number, total: number, position?: string) {
30
+ let point = super.getLabelOffsetPoint(labelCfg, index, total);
31
+ const coordinate = this.getCoordinate();
32
+ const transposed = coordinate.isTransposed;
32
33
  const dim = transposed ? 'x' : 'y';
33
34
  const dir = this.getLabelValueDir(labelCfg.mappingData);
35
+ point = { ...point, [dim]: point[dim] * dir };
36
+
37
+ if (coordinate.isReflect('x')) {
38
+ point = {
39
+ ...point,
40
+ x: point.x * -1,
41
+ };
42
+ }
43
+ if (coordinate.isReflect('y')) {
44
+ point = {
45
+ ...point,
46
+ y: point.y * -1,
47
+ };
48
+ }
34
49
 
35
- return {
36
- ...point,
37
- [dim]: point[dim] * dir,
38
- };
50
+ return point;
39
51
  }
40
52
 
41
53
  /**
@@ -38,10 +38,12 @@ export function limitInPlot(
38
38
  if (!coordinate) {
39
39
  return;
40
40
  }
41
- const { minX: regionMinX, minY: regionMinY, maxX: regionMaxX, maxY: regionMaxY } = getCoordinateBBox(
42
- coordinate,
43
- margin
44
- );
41
+ const {
42
+ minX: regionMinX,
43
+ minY: regionMinY,
44
+ maxX: regionMaxX,
45
+ maxY: regionMaxY,
46
+ } = getCoordinateBBox(coordinate, margin);
45
47
 
46
48
  each(labels, (label: IGroup) => {
47
49
  const { minX, minY, maxX, maxY, x, y, width, height } = label.getCanvasBBox();
@@ -70,6 +70,7 @@ export default class Path extends Geometry {
70
70
  shapeFactory,
71
71
  container: this.container,
72
72
  offscreenGroup: this.getOffscreenGroup(),
73
+ elementIndex: i,
73
74
  });
74
75
  element.geometry = this;
75
76
  element.animate = this.animateOption;
@@ -9,12 +9,7 @@ import { Point } from '../../../interface';
9
9
  * @returns
10
10
  */
11
11
  export function getCPath(from: Point, to: Point) {
12
- return [
13
- 'C',
14
- (from.x * 1) / 2 + (to.x * 1) / 2, from.y,
15
- (from.x * 1) / 2 + (to.x * 1) / 2, to.y,
16
- to.x, to.y,
17
- ];
12
+ return ['C', (from.x * 1) / 2 + (to.x * 1) / 2, from.y, (from.x * 1) / 2 + (to.x * 1) / 2, to.y, to.x, to.y];
18
13
  }
19
14
 
20
15
  /**
@@ -251,71 +251,90 @@ export function getFunnelPath(points: Point[], nextPoints: Point[], isPyramid: b
251
251
  return path;
252
252
  }
253
253
 
254
+ /**
255
+ * 交换两个对象
256
+ */
257
+ function swap<T>(p0: T, p1: T) {
258
+ return [p1, p0];
259
+ }
260
+
254
261
  /**
255
262
  * 获取 倒角 矩形
256
263
  * - 目前只适用于笛卡尔坐标系下
257
264
  */
258
265
  export function getRectWithCornerRadius(points: Point[], coordinate: Coordinate, radius?: number | number[]) {
259
266
  // 获取 四个关键点
260
- let [p0, p1, p2, p3] = points;
261
- let [r1, r2, r3, r4] = [0, 0, 0, 0];
267
+ let [p0, p1, p2, p3] = [...points];
268
+ let [r1, r2, r3, r4] = typeof radius === 'number' ? Array(4).fill(radius) : radius;
269
+
270
+ if (coordinate.isTransposed) {
271
+ [p1, p3] = swap(p1, p3);
272
+ [r1, r2, r3, r4] = [r4, r1, r2, r3]
273
+ }
262
274
 
263
275
  /**
264
- * p1 → p2
265
- * ↑ ↓
266
- * p0 ← p3
267
- *
268
- * 负数的情况,关键点会变成下面的形式
269
- *
270
- * p0 ← p3
271
- * ↓ ↑
272
- * p1 → p2
276
+ * 存在镜像
273
277
  */
274
- if (p0.y < p1.y /** 负数情况 */) {
275
- [p1, p0, p3, p2] = points;
276
- [r4, r3, r2, r1] = parseRadius(radius, Math.min(p3.x - p0.x, p0.y - p1.y));
277
- } else {
278
- [r1, r2, r3, r4] = parseRadius(radius, Math.min(p3.x - p0.x, p0.y - p1.y));
278
+ if (coordinate.isReflect('y')) {
279
+ [p0, p1] = swap(p0, p1);
280
+ [p2, p3] = swap(p2, p3);
281
+ }
282
+ if (coordinate.isReflect('x')) {
283
+ [p0, p3] = swap(p0, p3);
284
+ [p1, p2] = swap(p1, p2);
279
285
  }
280
286
 
287
+ const path = [];
288
+
289
+
281
290
  /**
282
- * 转置前
283
291
  * p1 → p2
284
292
  * ↑ ↓
285
293
  * p0 ← p3
286
294
  *
287
- * 转置后(↓ 是 x 轴递增,→ 是 y 轴递增),从 p0 开始绘制,对应的 radius: [r3, r2, r1, r4]
288
- * p3 ← p2
289
- * ↓ ↑
290
- * P0 → p1(points[3])
291
- *
292
- * 负数的情况,y 轴翻转
295
+ * 负数的情况,关键点会变成下面的形式
293
296
  *
294
- * p0 → p1
295
- * ↑ ↓
296
- * p3 ← p2
297
+ * p0 ← p3 p2 ← p1
298
+ * ↓ ↑ ↓ ↑
299
+ * p1 → p2 --> (转置下) p3 → p0
297
300
  */
298
- if (coordinate.isTransposed) {
299
- [p0, p3, p2, p1] = points;
300
- if (points[0].x > points[1].x /** 负数情况 */) {
301
- [p3, p0, p1, p2] = points;
302
- [r1, r4, r3, r2] = parseRadius(radius, Math.min(p3.x - p0.x, p0.y - p1.y));
303
- } else {
304
- [r2, r3, r4, r1] = parseRadius(radius, Math.min(p3.x - p0.x, p0.y - p1.y));
305
- }
306
- }
301
+ const abs = v => Math.abs(v);
302
+ [r1, r2, r3, r4] = parseRadius([r1, r2, r3, r4], Math.min(abs(p3.x - p0.x), abs(p1.y - p0.y))).map(d => abs(d));
307
303
 
308
- const path = [];
309
- path.push(['M', p1.x, p1.y + r1]);
310
- r1 !== 0 && path.push(['A', r1, r1, 0, 0, 1, p1.x + r1, p1.y]);
311
- path.push(['L', p2.x - r2, p2.y]);
312
- r2 !== 0 && path.push(['A', r2, r2, 0, 0, 1, p2.x, p2.y + r2]);
313
- path.push(['L', p3.x, p3.y - r3]);
314
- r3 !== 0 && path.push(['A', r3, r3, 0, 0, 1, p3.x - r3, p3.y]);
315
- path.push(['L', p0.x + r4, p0.y]);
316
- r4 !== 0 && path.push(['A', r4, r4, 0, 0, 1, p0.x, p0.y - r4]);
317
- path.push(['L', p1.x, p1.y + r1]);
318
- path.push(['z']);
304
+ if (p0.y < p1.y /** 负数情况 */) {
305
+ path.push(['M', p3.x, p3.y + r3]);
306
+ r3 !== 0 && path.push(['A', r3, r3, 0, 0, 0, p3.x - r3, p3.y]);
307
+ path.push(['L', p0.x + r4, p0.y]);
308
+ r4 !== 0 && path.push(['A', r4, r4, 0, 0, 0, p0.x, p0.y + r4]);
309
+ path.push(['L', p1.x, p1.y - r1]);
310
+ r1 !== 0 && path.push(['A', r1, r1, 0, 0, 0/** 逆时针 */, p1.x + r1, p1.y]);
311
+ path.push(['L', p2.x - r2, p2.y]);
312
+ r2 !== 0 && path.push(['A', r2, r2, 0, 0, 0, p2.x, p2.y - r2]);
313
+ path.push(['L', p3.x, p3.y + r3]);
314
+ path.push(['z']);
315
+ } else if (p3.x < p0.x) {
316
+ path.push(['M', p2.x + r2, p2.y]);
317
+ r2 !== 0 && path.push(['A', r2, r2, 0, 0, 0, p2.x, p2.y + r2]);
318
+ path.push(['L', p3.x, p3.y - r3]);
319
+ r3 !== 0 && path.push(['A', r3, r3, 0, 0, 0, p3.x + r3, p3.y]);
320
+ path.push(['L', p0.x - r4, p0.y]);
321
+ r4 !== 0 && path.push(['A', r4, r4, 0, 0, 0, p0.x, p0.y - r4]);
322
+ path.push(['L', p1.x, p1.y + r1]);
323
+ r1 !== 0 && path.push(['A', r1, r1, 0, 0, 0, p1.x - r1, p1.y]);
324
+ path.push(['L', p2.x + r2, p2.y]);
325
+ path.push(['z']);
326
+ } else {
327
+ path.push(['M', p1.x, p1.y + r1]);
328
+ r1 !== 0 && path.push(['A', r1, r1, 0, 0, 1, p1.x + r1, p1.y]);
329
+ path.push(['L', p2.x - r2, p2.y]);
330
+ r2 !== 0 && path.push(['A', r2, r2, 0, 0, 1, p2.x, p2.y + r2]);
331
+ path.push(['L', p3.x, p3.y - r3]);
332
+ r3 !== 0 && path.push(['A', r3, r3, 0, 0, 1, p3.x - r3, p3.y]);
333
+ path.push(['L', p0.x + r4, p0.y]);
334
+ r4 !== 0 && path.push(['A', r4, r4, 0, 0, 1, p0.x, p0.y - r4]);
335
+ path.push(['L', p1.x, p1.y + r1]);
336
+ path.push(['z']);
337
+ }
319
338
 
320
339
  return path;
321
340
  }
@@ -82,7 +82,10 @@ function getRangePath(
82
82
  return topPath.concat(bottomPath);
83
83
  }
84
84
 
85
- function getPath(
85
+ /**
86
+ * 获取折线图 path
87
+ */
88
+ export function getPath(
86
89
  points: Point[] | RangePoint[],
87
90
  isInCircle: boolean,
88
91
  isStack?: boolean,
@@ -34,7 +34,7 @@ registerShape('violin', 'hollow', {
34
34
  /**
35
35
  * 平滑边界的空心小提琴图
36
36
  */
37
- registerShape('violin', 'hollow-smooth', {
37
+ registerShape('violin', 'hollow-smooth', {
38
38
  draw(cfg: ShapeInfo, container: IGroup) {
39
39
  const attrs = getStyle(cfg, true, false);
40
40
  const path = this.parsePath(getSmoothViolinPath(cfg.points));
@@ -5,7 +5,7 @@ import { registerShape, registerShapeFactory } from '../base';
5
5
  import { getViolinPath } from '../util/get-path-points';
6
6
  import { getStyle } from '../util/get-style';
7
7
 
8
- function normalizeSize(arr: number[]){
8
+ function normalizeSize(arr: number[]) {
9
9
  if (!isArray(arr)) {
10
10
  return [];
11
11
  }
@@ -19,7 +19,7 @@ const ViolinShapeFactory = registerShapeFactory('violin', {
19
19
  const radius = pointInfo.size / 2;
20
20
  const points = [];
21
21
  const sizeArr = normalizeSize(pointInfo._size);
22
-
22
+
23
23
  each(pointInfo.y as number[], (y, index) => {
24
24
  const offset = sizeArr[index] * radius;
25
25
  const isMin = index === 0;
@@ -41,10 +41,7 @@ export function getDefaultSize(geometry): number {
41
41
  let count: number = xValues.length;
42
42
  const xDimensionLength = getXDimensionLength(geometry.coordinate);
43
43
  // 获取柱宽相关配置项
44
- const {
45
- intervalPadding,
46
- dodgePadding,
47
- } = geometry;
44
+ const { intervalPadding, dodgePadding } = geometry;
48
45
  // 兼容theme配置
49
46
  const maxColumnWidth = geometry.maxColumnWidth || theme.maxColumnWidth;
50
47
  const minColumnWidth = geometry.minColumnWidth || theme.minColumnWidth;
@@ -108,7 +105,7 @@ export function getDefaultSize(geometry): number {
108
105
  // 组间距和组内间距均未配置
109
106
  normalizedSize = normalizedSize / dodgeCount;
110
107
  }
111
- normalizedSize = (normalizedSize >= 0) ? normalizedSize : 0;
108
+ normalizedSize = normalizedSize >= 0 ? normalizedSize : 0;
112
109
  }
113
110
 
114
111
  // 最大和最小限制
package/src/index.ts CHANGED
@@ -198,6 +198,8 @@ import ListHighlight from './interaction/action/component/list-highlight';
198
198
  import ListSelected from './interaction/action/component/list-selected';
199
199
  import ListUnchecked from './interaction/action/component/list-unchecked';
200
200
  import ListChecked from './interaction/action/component/list-checked';
201
+ import ListFocus from './interaction/action/component/list-focus';
202
+ import ListRadio from './interaction/action/component/list-radio';
201
203
 
202
204
  import CircleMask from './interaction/action/mask/circle';
203
205
  import DimMask from './interaction/action/mask/dim-rect';
@@ -248,6 +250,8 @@ registerAction('list-selected', ListSelected);
248
250
  registerAction('list-highlight', ListHighlight);
249
251
  registerAction('list-unchecked', ListUnchecked);
250
252
  registerAction('list-checked', ListChecked);
253
+ registerAction('list-focus', ListFocus);
254
+ registerAction('list-radio', ListRadio);
251
255
 
252
256
  registerAction('legend-item-highlight', ListHighlight, {
253
257
  componentNames: ['legend'],
@@ -560,10 +564,23 @@ registerInteraction('element-single-selected', {
560
564
  // 筛选数据
561
565
  registerInteraction('legend-filter', {
562
566
  showEnable: [
563
- { trigger: 'legend-item:mouseenter', action: 'cursor:pointer' },
564
- { trigger: 'legend-item:mouseleave', action: 'cursor:default' },
567
+ { trigger: 'legend-item:mouseenter', action: ['cursor:pointer', 'list-radio:show'] },
568
+ { trigger: 'legend-item:mouseleave', action: ['cursor:default', 'list-radio:hide'] },
569
+ ],
570
+ start: [
571
+ {
572
+ trigger: 'legend-item:click',
573
+ isEnable: (context) => {
574
+ return !context.isInShape('legend-item-radio');
575
+ },
576
+ action: ['list-unchecked:toggle', 'data-filter:filter', 'list-radio:show'],
577
+ },
578
+ // 正反选数据: 只有当 radio === truthy 的时候才会有 legend-item-radio 这个元素
579
+ {
580
+ trigger: 'legend-item-radio:click',
581
+ action: ['list-focus:toggle', 'data-filter:filter', 'list-radio:show'],
582
+ },
565
583
  ],
566
- start: [{ trigger: 'legend-item:click', action: ['list-unchecked:toggle', 'data-filter:filter'] }],
567
584
  });
568
585
 
569
586
  // 筛选数据
@@ -53,7 +53,7 @@ class ListChecked extends ListState {
53
53
  // 不知道 🤷‍♀️ 只认 unchecked status
54
54
  const allChecked = !some(list.getItems(), (t) => list.hasState(t, STATUS_UNCHECKED));
55
55
 
56
- //
56
+ //
57
57
  if (allChecked || list.hasState(item, STATUS_UNCHECKED)) {
58
58
  this.setItemState(list, item, true);
59
59
  } else {
@@ -0,0 +1,24 @@
1
+ import ListState from './list-state';
2
+
3
+ const STATUS_UNCHECKED = 'unchecked';
4
+
5
+ class ListFocus extends ListState {
6
+ public toggle() {
7
+ const triggerInfo = this.getTriggerListInfo();
8
+ if (triggerInfo?.item) {
9
+ const { list, item: clickedItem } = triggerInfo;
10
+ const items = list.getItems();
11
+ const checkedItems = items.filter((t) => !list.hasState(t, STATUS_UNCHECKED));
12
+ for (const item of items) {
13
+ if (item === clickedItem) {
14
+ list.setItemState(item, STATUS_UNCHECKED, false);
15
+ } else {
16
+ const status = checkedItems.length > 1;
17
+ list.setItemState(item, STATUS_UNCHECKED, status);
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ export default ListFocus;
@@ -0,0 +1,23 @@
1
+ import ListState from './list-state';
2
+
3
+ const STATUS_SHOW = 'showRadio';
4
+
5
+ class ListRadio extends ListState {
6
+ public show() {
7
+ const triggerInfo = this.getTriggerListInfo();
8
+ if (triggerInfo?.item) {
9
+ const { list, item } = triggerInfo;
10
+ list.setItemState(item, STATUS_SHOW, true);
11
+ }
12
+ }
13
+
14
+ public hide() {
15
+ const triggerInfo = this.getTriggerListInfo();
16
+ if (triggerInfo?.item) {
17
+ const { list, item } = triggerInfo;
18
+ list.setItemState(item, STATUS_SHOW, false);
19
+ }
20
+ }
21
+ }
22
+
23
+ export default ListRadio;
@@ -1,7 +1,7 @@
1
- import { clamp, size, valuesOfKey } from "@antv/util";
2
- import { COMPONENT_TYPE } from "../../../constant";
1
+ import { clamp, size, valuesOfKey } from '@antv/util';
2
+ import { COMPONENT_TYPE } from '../../../constant';
3
3
  import { Action } from '..';
4
- import { LooseObject } from "../../../interface";
4
+ import { LooseObject } from '../../../interface';
5
5
 
6
6
  function isWheelDown(event: LooseObject) {
7
7
  const wheelEvent = event.gEvent.originalEvent as WheelEvent;
@@ -10,7 +10,6 @@ function isWheelDown(event: LooseObject) {
10
10
 
11
11
  const DEFAULT_WHEELDELTA = 1;
12
12
  class MousewheelScroll extends Action {
13
-
14
13
  public scroll(arg?) {
15
14
  const { view, event } = this.context;
16
15
 
package/src/interface.ts CHANGED
@@ -39,6 +39,7 @@ import { View } from './chart';
39
39
  import { Facet } from './facet';
40
40
  import Element from './geometry/element';
41
41
  import { PaddingCalCtor } from './chart/layout/padding-cal';
42
+ import { LegendRadio } from '@antv/component';
42
43
 
43
44
  // ============================ 基础类型 ============================
44
45
  /** 通用对象 */
@@ -73,9 +74,11 @@ export interface RangePoint {
73
74
  /**
74
75
  * WAI-ARIA 无障碍标签配置
75
76
  */
76
- export type AriaOption = false | {
77
- readonly label: string;
78
- }
77
+ export type AriaOption =
78
+ | false
79
+ | {
80
+ readonly label: string;
81
+ };
79
82
 
80
83
  /** 用户数据经过图形映射处理后的数据结构 */
81
84
  export interface MappingDatum {
@@ -1061,6 +1064,10 @@ export interface LegendCfg extends Omit<CategoryLegendCfg, 'marker'> {
1061
1064
  * **分类图例适用**,用户自己配置图例项的内容。
1062
1065
  */
1063
1066
  items?: LegendItem[];
1067
+ /**
1068
+ * **分类图里适用**,用来配置正反选功能
1069
+ */
1070
+ radio?:LegendRadio
1064
1071
  /**
1065
1072
  * **分类图例适用**,是否将图例项逆序展示。
1066
1073
  */
package/src/util/axis.ts CHANGED
@@ -178,14 +178,19 @@ export function getAxisThemeCfg(theme: object, direction: string): object {
178
178
 
179
179
  /**
180
180
  * get the options of axis title,mix the cfg from theme, avoid common themeCfg not work
181
- * @param theme
182
- * @param direction
183
- * @param axisOptions
181
+ * @param theme
182
+ * @param direction
183
+ * @param axisOptions
184
184
  * @returns axis title options
185
185
  */
186
186
  export function getAxisTitleOptions(theme: object, direction: string, axisOptions?: object): object {
187
187
  const axisTheme = get(theme, ['components', 'axis'], {});
188
- return deepMix({}, get(axisTheme, ['common', 'title'], {}), deepMix({}, get(axisTheme, [direction, 'title'], {})), axisOptions);
188
+ return deepMix(
189
+ {},
190
+ get(axisTheme, ['common', 'title'], {}),
191
+ deepMix({}, get(axisTheme, [direction, 'title'], {})),
192
+ axisOptions
193
+ );
189
194
  }
190
195
 
191
196
  /**
package/src/util/bbox.ts CHANGED
@@ -221,8 +221,7 @@ export class BBox {
221
221
  * @param bbox
222
222
  */
223
223
  public collide(bbox: BBox): boolean {
224
- return this.minX < bbox.maxX && this.maxX > bbox.minX &&
225
- this.minY < bbox.maxY && this.maxY > bbox.minY;
224
+ return this.minX < bbox.maxX && this.maxX > bbox.minX && this.minY < bbox.maxY && this.maxY > bbox.minY;
226
225
  }
227
226
 
228
227
  /**
@@ -82,7 +82,7 @@ export function getLegendItems(
82
82
  geometry: Geometry,
83
83
  attr: Attribute,
84
84
  themeMarker: object,
85
- userMarker: LegendCfg['marker'],
85
+ userMarker: LegendCfg['marker']
86
86
  ): ComponentLegendItem[] {
87
87
  const scale = attr.getScale(attr.type);
88
88
  if (scale.isCategory) {
@@ -115,7 +115,7 @@ export function getLegendItems(
115
115
 
116
116
  let markerCfg = userMarker;
117
117
  if (isFunction(markerCfg)) {
118
- markerCfg = markerCfg(name, index, { name, value, ...deepMix({}, themeMarker, marker) })
118
+ markerCfg = markerCfg(name, index, { name, value, ...deepMix({}, themeMarker, marker) });
119
119
  }
120
120
 
121
121
  // the marker configure order should be ensure
@@ -146,10 +146,12 @@ export function getCustomLegendItems(themeMarker: object, userMarker: object, cu
146
146
  return customItems.map((item: LegendItem, index: number) => {
147
147
  let markerCfg = userMarker;
148
148
  if (isFunction(markerCfg)) {
149
- markerCfg = markerCfg(item.name, index, deepMix({}, themeMarker, item))
149
+ markerCfg = markerCfg(item.name, index, deepMix({}, themeMarker, item));
150
150
  }
151
151
 
152
- const itemMarker = isFunction(item.marker) ? item.marker(item.name, index, deepMix({}, themeMarker, item)) : item.marker;
152
+ const itemMarker = isFunction(item.marker)
153
+ ? item.marker(item.name, index, deepMix({}, themeMarker, item))
154
+ : item.marker;
153
155
 
154
156
  const marker = deepMix({}, themeMarker, markerCfg, itemMarker);
155
157
  setMarkerSymbol(marker);
package/src/util/scale.ts CHANGED
@@ -3,7 +3,8 @@ import { getScale, Scale, Coordinate } from '../dependents';
3
3
  import { LooseObject, ScaleOption, ViewCfg } from '../interface';
4
4
  import { isFullCircle } from './coordinate';
5
5
 
6
- const dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]+)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
6
+ const dateRegex =
7
+ /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]+)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
7
8
 
8
9
  /**
9
10
  * 获取字段对应数据的类型
@@ -86,9 +87,13 @@ export function getName(scale: Scale): string {
86
87
  * 根据 scale values 和 coordinate 获取分类默认 range
87
88
  * @param scale 需要获取的 scale 实例
88
89
  * @param coordinate coordinate 实例
89
- * @param theme theme
90
+ * @param theme theme
90
91
  */
91
- export function getDefaultCategoryScaleRange(scale: Scale, coordinate: Coordinate, theme: ViewCfg['theme']): Scale['range'] {
92
+ export function getDefaultCategoryScaleRange(
93
+ scale: Scale,
94
+ coordinate: Coordinate,
95
+ theme: ViewCfg['theme']
96
+ ): Scale['range'] {
92
97
  const { values } = scale;
93
98
  const count = values.length;
94
99
  let range;
@@ -121,7 +126,7 @@ export function getDefaultCategoryScaleRange(scale: Scale, coordinate: Coordinat
121
126
  */
122
127
  export function getMaxScale(scale: Scale) {
123
128
  // 过滤values[]中 NaN/undefined/null 等
124
- const values = scale.values.filter(item => !isNil(item) && !isNaN(item))
129
+ const values = scale.values.filter((item) => !isNil(item) && !isNaN(item));
125
130
 
126
131
  return Math.max(...values, isNil(scale.max) ? -Infinity : scale.max);
127
132
  }
package/src/util/stat.ts CHANGED
@@ -16,7 +16,7 @@ export function getMedian(array: number[]) {
16
16
  // median
17
17
  // 0
18
18
  if (len === 0) {
19
- return 0
19
+ return 0;
20
20
  }
21
21
 
22
22
  // 奇数
@@ -33,9 +33,13 @@ export function getMedian(array: number[]) {
33
33
  * @param array
34
34
  */
35
35
  export function getMean(array: number[]) {
36
- const sum = reduce(array, (r: number, num: number) => {
37
- return r += (isNaN(num) || !isNumber(num) ? 0 : num);
38
- }, 0);
36
+ const sum = reduce(
37
+ array,
38
+ (r: number, num: number) => {
39
+ return (r += isNaN(num) || !isNumber(num) ? 0 : num);
40
+ },
41
+ 0
42
+ );
39
43
 
40
44
  return array.length === 0 ? 0 : sum / array.length;
41
- }
45
+ }