@antv/g2 4.1.34 → 4.1.38

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 (149) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.en-US.md +0 -1
  3. package/README.md +0 -1
  4. package/dist/g2.min.js +3 -3
  5. package/dist/g2.min.js.map +1 -1
  6. package/esm/chart/controller/annotation.js +35 -21
  7. package/esm/chart/controller/annotation.js.map +1 -1
  8. package/esm/chart/controller/axis.js +3 -3
  9. package/esm/chart/controller/axis.js.map +1 -1
  10. package/esm/chart/controller/gesture.js +2 -2
  11. package/esm/chart/controller/gesture.js.map +1 -1
  12. package/esm/chart/controller/legend.js +1 -1
  13. package/esm/chart/controller/legend.js.map +1 -1
  14. package/esm/chart/controller/scrollbar.js +4 -1
  15. package/esm/chart/controller/scrollbar.js.map +1 -1
  16. package/esm/chart/controller/slider.js +7 -1
  17. package/esm/chart/controller/slider.js.map +1 -1
  18. package/esm/chart/event.js +1 -1
  19. package/esm/chart/event.js.map +1 -1
  20. package/esm/chart/layout/constraint/bounds.js +4 -4
  21. package/esm/chart/layout/constraint/bounds.js.map +1 -1
  22. package/esm/chart/layout/constraint/variable.js +1 -1
  23. package/esm/chart/layout/constraint/variable.js.map +1 -1
  24. package/esm/chart/view.js +4 -4
  25. package/esm/chart/view.js.map +1 -1
  26. package/esm/core.d.ts +1 -1
  27. package/esm/core.js +1 -1
  28. package/esm/core.js.map +1 -1
  29. package/esm/engine/index.js +1 -1
  30. package/esm/engine/index.js.map +1 -1
  31. package/esm/geometry/base.d.ts +4 -0
  32. package/esm/geometry/base.js +14 -9
  33. package/esm/geometry/base.js.map +1 -1
  34. package/esm/geometry/element/index.js +3 -6
  35. package/esm/geometry/element/index.js.map +1 -1
  36. package/esm/geometry/label/base.js +2 -2
  37. package/esm/geometry/label/base.js.map +1 -1
  38. package/esm/geometry/label/layout/overlap.js +2 -2
  39. package/esm/geometry/label/layout/overlap.js.map +1 -1
  40. package/esm/geometry/label/layout/pie/distribute.js +3 -3
  41. package/esm/geometry/label/layout/pie/distribute.js.map +1 -1
  42. package/esm/geometry/label/layout/pie/outer.js +6 -6
  43. package/esm/geometry/label/layout/pie/outer.js.map +1 -1
  44. package/esm/geometry/label/layout/pie/spider.js +5 -5
  45. package/esm/geometry/label/layout/pie/spider.js.map +1 -1
  46. package/esm/geometry/shape/interval/util.js +63 -47
  47. package/esm/geometry/shape/interval/util.js.map +1 -1
  48. package/esm/geometry/shape/point/index.js +1 -1
  49. package/esm/geometry/shape/point/index.js.map +1 -1
  50. package/esm/geometry/util/group-data.js +1 -1
  51. package/esm/geometry/util/group-data.js.map +1 -1
  52. package/esm/index.js +20 -3
  53. package/esm/index.js.map +1 -1
  54. package/esm/interaction/action/component/list-focus.d.ts +5 -0
  55. package/esm/interaction/action/component/list-focus.js +30 -0
  56. package/esm/interaction/action/component/list-focus.js.map +1 -0
  57. package/esm/interaction/action/component/list-radio.d.ts +6 -0
  58. package/esm/interaction/action/component/list-radio.js +26 -0
  59. package/esm/interaction/action/component/list-radio.js.map +1 -0
  60. package/esm/interaction/action/mask/base.js +1 -1
  61. package/esm/interaction/action/mask/base.js.map +1 -1
  62. package/esm/interaction/grammar-interaction.js +2 -2
  63. package/esm/interaction/grammar-interaction.js.map +1 -1
  64. package/esm/interface.d.ts +5 -0
  65. package/esm/interface.js.map +1 -1
  66. package/esm/theme/util/create-by-style-sheet.js +9 -9
  67. package/esm/theme/util/create-by-style-sheet.js.map +1 -1
  68. package/esm/util/event.js +1 -1
  69. package/esm/util/event.js.map +1 -1
  70. package/esm/util/text.js +2 -2
  71. package/esm/util/text.js.map +1 -1
  72. package/lib/chart/controller/annotation.js +35 -21
  73. package/lib/chart/controller/annotation.js.map +1 -1
  74. package/lib/chart/controller/axis.js +3 -3
  75. package/lib/chart/controller/axis.js.map +1 -1
  76. package/lib/chart/controller/gesture.js +2 -2
  77. package/lib/chart/controller/gesture.js.map +1 -1
  78. package/lib/chart/controller/legend.js +1 -1
  79. package/lib/chart/controller/legend.js.map +1 -1
  80. package/lib/chart/controller/scrollbar.js +4 -1
  81. package/lib/chart/controller/scrollbar.js.map +1 -1
  82. package/lib/chart/controller/slider.js +7 -1
  83. package/lib/chart/controller/slider.js.map +1 -1
  84. package/lib/chart/event.js +1 -1
  85. package/lib/chart/event.js.map +1 -1
  86. package/lib/chart/layout/constraint/bounds.js +4 -4
  87. package/lib/chart/layout/constraint/bounds.js.map +1 -1
  88. package/lib/chart/layout/constraint/variable.js +1 -1
  89. package/lib/chart/layout/constraint/variable.js.map +1 -1
  90. package/lib/chart/view.js +4 -4
  91. package/lib/chart/view.js.map +1 -1
  92. package/lib/core.d.ts +1 -1
  93. package/lib/core.js +1 -1
  94. package/lib/core.js.map +1 -1
  95. package/lib/engine/index.js +1 -1
  96. package/lib/engine/index.js.map +1 -1
  97. package/lib/geometry/base.d.ts +4 -0
  98. package/lib/geometry/base.js +14 -9
  99. package/lib/geometry/base.js.map +1 -1
  100. package/lib/geometry/element/index.js +3 -6
  101. package/lib/geometry/element/index.js.map +1 -1
  102. package/lib/geometry/label/base.js +2 -2
  103. package/lib/geometry/label/base.js.map +1 -1
  104. package/lib/geometry/label/layout/overlap.js +2 -2
  105. package/lib/geometry/label/layout/overlap.js.map +1 -1
  106. package/lib/geometry/label/layout/pie/distribute.js +3 -3
  107. package/lib/geometry/label/layout/pie/distribute.js.map +1 -1
  108. package/lib/geometry/label/layout/pie/outer.js +6 -6
  109. package/lib/geometry/label/layout/pie/outer.js.map +1 -1
  110. package/lib/geometry/label/layout/pie/spider.js +5 -5
  111. package/lib/geometry/label/layout/pie/spider.js.map +1 -1
  112. package/lib/geometry/shape/interval/util.js +63 -47
  113. package/lib/geometry/shape/interval/util.js.map +1 -1
  114. package/lib/geometry/shape/point/index.js +1 -1
  115. package/lib/geometry/shape/point/index.js.map +1 -1
  116. package/lib/geometry/util/group-data.js +1 -1
  117. package/lib/geometry/util/group-data.js.map +1 -1
  118. package/lib/index.js +20 -3
  119. package/lib/index.js.map +1 -1
  120. package/lib/interaction/action/component/list-focus.d.ts +5 -0
  121. package/lib/interaction/action/component/list-focus.js +32 -0
  122. package/lib/interaction/action/component/list-focus.js.map +1 -0
  123. package/lib/interaction/action/component/list-radio.d.ts +6 -0
  124. package/lib/interaction/action/component/list-radio.js +28 -0
  125. package/lib/interaction/action/component/list-radio.js.map +1 -0
  126. package/lib/interaction/action/mask/base.js +1 -1
  127. package/lib/interaction/action/mask/base.js.map +1 -1
  128. package/lib/interaction/grammar-interaction.js +2 -2
  129. package/lib/interaction/grammar-interaction.js.map +1 -1
  130. package/lib/interface.d.ts +5 -0
  131. package/lib/interface.js.map +1 -1
  132. package/lib/theme/util/create-by-style-sheet.js +9 -9
  133. package/lib/theme/util/create-by-style-sheet.js.map +1 -1
  134. package/lib/util/event.js +1 -1
  135. package/lib/util/event.js.map +1 -1
  136. package/lib/util/text.js +2 -2
  137. package/lib/util/text.js.map +1 -1
  138. package/package.json +2 -4
  139. package/src/chart/controller/annotation.ts +31 -18
  140. package/src/chart/controller/scrollbar.ts +18 -13
  141. package/src/chart/controller/slider.ts +12 -2
  142. package/src/core.ts +1 -1
  143. package/src/geometry/base.ts +13 -2
  144. package/src/geometry/element/index.ts +3 -5
  145. package/src/geometry/shape/interval/util.ts +65 -46
  146. package/src/index.ts +20 -3
  147. package/src/interaction/action/component/list-focus.ts +24 -0
  148. package/src/interaction/action/component/list-radio.ts +23 -0
  149. package/src/interface.ts +5 -0
@@ -55,7 +55,7 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
55
55
  this.view.off(VIEW_LIFE_CIRCLE.BEFORE_CHANGE_SIZE, this.resetMeasure);
56
56
  }
57
57
 
58
- public init() {}
58
+ public init() { }
59
59
 
60
60
  /**
61
61
  * 渲染
@@ -240,13 +240,18 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
240
240
  const { type } = this.getValidScrollbarCfg();
241
241
  const isHorizontal = type !== 'vertical';
242
242
  const values = valuesOfKey(this.data, this.xScaleCfg.field);
243
- const xValues = isHorizontal ? values : values.reverse();
243
+
244
+ // 如果是 xScale 数值类型,则进行排序
245
+ const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
246
+
247
+ const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
244
248
  this.yScalesCfg.forEach((cfg) => {
245
249
  this.view.scale(cfg.field, {
246
250
  formatter: cfg.formatter,
247
251
  type: cfg.type as ScaleOption['type'],
248
252
  min: cfg.min,
249
253
  max: cfg.max,
254
+ tickMethod: cfg.tickMethod
250
255
  });
251
256
  });
252
257
  this.view.filter(this.xScaleCfg.field, (val) => {
@@ -280,11 +285,11 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
280
285
  const config = this.getScrollbarComponentCfg();
281
286
  const realConfig = this.trackLen
282
287
  ? {
283
- ...config,
284
- trackLen: this.trackLen,
285
- thumbLen: this.thumbLen,
286
- thumbOffset: (this.trackLen - this.thumbLen) * this.ratio,
287
- }
288
+ ...config,
289
+ trackLen: this.trackLen,
290
+ thumbLen: this.thumbLen,
291
+ thumbOffset: (this.trackLen - this.thumbLen) * this.ratio,
292
+ }
288
293
  : { ...config };
289
294
  this.scrollbar.component.update(realConfig);
290
295
 
@@ -319,13 +324,13 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
319
324
  const [paddingTop, paddingRight, paddingBottom, paddingLeft] = padding;
320
325
  const position = isHorizontal
321
326
  ? {
322
- x: coordinateBBox.minX + paddingLeft,
323
- y: viewBBox.maxY - height - paddingBottom,
324
- }
327
+ x: coordinateBBox.minX + paddingLeft,
328
+ y: viewBBox.maxY - height - paddingBottom,
329
+ }
325
330
  : {
326
- x: viewBBox.maxX - width - paddingRight,
327
- y: coordinateBBox.minY + paddingTop,
328
- };
331
+ x: viewBBox.maxX - width - paddingRight,
332
+ y: coordinateBBox.minY + paddingTop,
333
+ };
329
334
  const step = this.getStep();
330
335
  const cnt = this.getCnt();
331
336
  const trackLen = isHorizontal
@@ -272,7 +272,13 @@ export default class Slider extends Controller<SliderOption> {
272
272
  const data = this.view.getOptions().data;
273
273
  const xScale = this.view.getXScale();
274
274
  const isHorizontal = true;
275
- const values = valuesOfKey(data, xScale.field);
275
+ let values = valuesOfKey(data, xScale.field);
276
+
277
+ // 如果是 xScale 数值类型,则进行排序
278
+ if (xScale.isLinear) {
279
+ values = values.sort();
280
+ }
281
+
276
282
  const xValues = isHorizontal ? values : values.reverse();
277
283
  const dataSize = size(data);
278
284
 
@@ -314,7 +320,11 @@ export default class Slider extends Controller<SliderOption> {
314
320
  }
315
321
  const isHorizontal = true;
316
322
  const values = valuesOfKey(data, xScale.field);
317
- const xValues = isHorizontal ? values : values.reverse();
323
+
324
+ // 如果是 xScale 数值类型,则进行排序
325
+ const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
326
+
327
+ const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
318
328
  const xTickCount = size(xValues);
319
329
 
320
330
  const minIndex = Math.floor(min * (xTickCount - 1));
package/src/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* G2 的一个壳子,不包含 Geometry,由开发者自己定义和引入 */
2
2
 
3
- export const VERSION = '4.1.34';
3
+ export const VERSION = '4.1.38';
4
4
 
5
5
  // 核心基类导出
6
6
  export { Chart, View, Event } from './chart'; // Chart, View 类
@@ -132,6 +132,8 @@ export interface GeometryCfg {
132
132
  sortable?: boolean;
133
133
  /** elements 的 zIndex 默认按顺序提升,通过 zIndexReversed 可以反序,从而数据越前,层级越高 */
134
134
  zIndexReversed?: boolean;
135
+ /** 是否需要对 zIndex 进行 sort。因为耗时长,由具体场景自行决定 */
136
+ sortZIndex?: boolean;
135
137
  /** 是否可见 */
136
138
  visible?: boolean;
137
139
  /** 主题配置 */
@@ -260,6 +262,8 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
260
262
  protected multiplePieWidthRatio: number;
261
263
  /** elements 的 zIndex 默认按顺序提升,通过 zIndexReversed 可以反序,从而数据越前,层级越高 */
262
264
  public zIndexReversed?: boolean;
265
+ /** 是否需要对 zIndex 进行 sort。因为耗时长,由具体场景自行决定 */
266
+ public sortZIndex?: boolean;
263
267
 
264
268
  /** 虚拟 Group,用于图形更新 */
265
269
  private offscreenGroup: IGroup;
@@ -293,6 +297,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
293
297
  roseWidthRatio,
294
298
  multiplePieWidthRatio,
295
299
  zIndexReversed,
300
+ sortZIndex,
296
301
  } = cfg;
297
302
 
298
303
  this.container = container;
@@ -313,6 +318,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
313
318
  this.roseWidthRatio = roseWidthRatio;
314
319
  this.multiplePieWidthRatio = multiplePieWidthRatio;
315
320
  this.zIndexReversed = zIndexReversed;
321
+ this.sortZIndex = sortZIndex;
316
322
  }
317
323
 
318
324
  /**
@@ -1546,7 +1552,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1546
1552
  this.elements[i] = element;
1547
1553
  this.elementsMap[key] = element;
1548
1554
  if (element.shape) {
1549
- element.shape.setZIndex(this.zIndexReversed ? this.elements.length - i : i);
1555
+ element.shape.set('zIndex', this.zIndexReversed ? this.elements.length - i : i);
1550
1556
  }
1551
1557
  }
1552
1558
 
@@ -1565,10 +1571,15 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1565
1571
  this.elements[i] = element;
1566
1572
  this.elementsMap[key] = element;
1567
1573
  if (element.shape) {
1568
- element.shape.setZIndex(this.zIndexReversed ? this.elements.length - i : i);
1574
+ element.shape.set('zIndex', this.zIndexReversed ? this.elements.length - i : i);
1569
1575
  }
1570
1576
  }
1571
1577
 
1578
+ // 全部 setZIndex 之后,再执行 sort
1579
+ if (this.container) {
1580
+ this.container.sort();
1581
+ }
1582
+
1572
1583
  // 销毁被删除的 elements
1573
1584
  for (const key of removed) {
1574
1585
  const element = this.lastElementsMap[key];
@@ -229,11 +229,9 @@ export default class Element extends Base {
229
229
  }
230
230
  states.splice(index, 1);
231
231
  if (stateName === 'active' || stateName === 'selected') {
232
- if (this.geometry.zIndexReversed) {
233
- shape.setZIndex(this.geometry.elements.length - this.elementIndex);
234
- } else {
235
- shape.setZIndex(this.elementIndex);
236
- }
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);
237
235
  }
238
236
  }
239
237
 
@@ -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
  }
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
  // 筛选数据
@@ -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;
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
  /** 通用对象 */
@@ -1063,6 +1064,10 @@ export interface LegendCfg extends Omit<CategoryLegendCfg, 'marker'> {
1063
1064
  * **分类图例适用**,用户自己配置图例项的内容。
1064
1065
  */
1065
1066
  items?: LegendItem[];
1067
+ /**
1068
+ * **分类图里适用**,用来配置正反选功能
1069
+ */
1070
+ radio?:LegendRadio
1066
1071
  /**
1067
1072
  * **分类图例适用**,是否将图例项逆序展示。
1068
1073
  */