@antv/g2 4.1.29 → 4.1.34

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 (179) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.en-US.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/g2.min.js +4 -18
  5. package/dist/g2.min.js.map +1 -1
  6. package/esm/chart/chart.d.ts +10 -0
  7. package/esm/chart/chart.js +20 -0
  8. package/esm/chart/chart.js.map +1 -1
  9. package/esm/chart/controller/scrollbar.d.ts +8 -0
  10. package/esm/chart/controller/scrollbar.js +24 -3
  11. package/esm/chart/controller/scrollbar.js.map +1 -1
  12. package/esm/chart/controller/tooltip.js +2 -2
  13. package/esm/chart/controller/tooltip.js.map +1 -1
  14. package/esm/chart/layout/constraint/bounds.js.map +1 -1
  15. package/esm/chart/layout/constraint/constraint.js.map +1 -1
  16. package/esm/chart/layout/constraint/gauss.js +3 -3
  17. package/esm/chart/layout/constraint/gauss.js.map +1 -1
  18. package/esm/chart/layout/constraint/solver.js.map +1 -1
  19. package/esm/chart/layout/constraint/types.js.map +1 -1
  20. package/esm/chart/layout/constraint/variable.js.map +1 -1
  21. package/esm/chart/util/scale-pool.js +1 -1
  22. package/esm/chart/util/scale-pool.js.map +1 -1
  23. package/esm/chart/util/sync-view-padding.js.map +1 -1
  24. package/esm/chart/view.js.map +1 -1
  25. package/esm/core.d.ts +5 -1
  26. package/esm/core.js +6 -1
  27. package/esm/core.js.map +1 -1
  28. package/esm/dependents.d.ts +1 -1
  29. package/esm/dependents.js +1 -1
  30. package/esm/dependents.js.map +1 -1
  31. package/esm/geometry/base.d.ts +2 -2
  32. package/esm/geometry/base.js +10 -10
  33. package/esm/geometry/base.js.map +1 -1
  34. package/esm/geometry/element/index.d.ts +4 -0
  35. package/esm/geometry/element/index.js +9 -3
  36. package/esm/geometry/element/index.js.map +1 -1
  37. package/esm/geometry/label/interval.d.ts +2 -5
  38. package/esm/geometry/label/interval.js +11 -3
  39. package/esm/geometry/label/interval.js.map +1 -1
  40. package/esm/geometry/label/layout/limit-in-plot.js.map +1 -1
  41. package/esm/geometry/path.js +1 -0
  42. package/esm/geometry/path.js.map +1 -1
  43. package/esm/geometry/shape/edge/util.js +1 -6
  44. package/esm/geometry/shape/edge/util.js.map +1 -1
  45. package/esm/geometry/shape/line/index.d.ts +6 -0
  46. package/esm/geometry/shape/line/index.js +4 -1
  47. package/esm/geometry/shape/line/index.js.map +1 -1
  48. package/esm/geometry/shape/violin/hollow.js.map +1 -1
  49. package/esm/geometry/shape/violin/index.js.map +1 -1
  50. package/esm/geometry/util/shape-size.js +1 -1
  51. package/esm/geometry/util/shape-size.js.map +1 -1
  52. package/esm/index.js +5 -0
  53. package/esm/index.js.map +1 -1
  54. package/esm/interaction/action/component/list-checked.js +1 -1
  55. package/esm/interaction/action/component/list-checked.js.map +1 -1
  56. package/esm/interaction/action/view/mousewheel-scroll.d.ts +5 -0
  57. package/esm/interaction/action/view/mousewheel-scroll.js +35 -0
  58. package/esm/interaction/action/view/mousewheel-scroll.js.map +1 -0
  59. package/esm/interaction/context.js +2 -2
  60. package/esm/interaction/context.js.map +1 -1
  61. package/esm/interface.d.ts +9 -3
  62. package/esm/interface.js.map +1 -1
  63. package/esm/util/axis.js.map +1 -1
  64. package/esm/util/bbox.js +1 -2
  65. package/esm/util/bbox.js.map +1 -1
  66. package/esm/util/collision-detect.js +10 -0
  67. package/esm/util/collision-detect.js.map +1 -1
  68. package/esm/util/graphics.js +17 -1
  69. package/esm/util/graphics.js.map +1 -1
  70. package/esm/util/legend.js +3 -1
  71. package/esm/util/legend.js.map +1 -1
  72. package/esm/util/scale.js.map +1 -1
  73. package/esm/util/stat.js +1 -1
  74. package/esm/util/stat.js.map +1 -1
  75. package/lib/chart/chart.d.ts +10 -0
  76. package/lib/chart/chart.js +20 -0
  77. package/lib/chart/chart.js.map +1 -1
  78. package/lib/chart/controller/scrollbar.d.ts +8 -0
  79. package/lib/chart/controller/scrollbar.js +23 -2
  80. package/lib/chart/controller/scrollbar.js.map +1 -1
  81. package/lib/chart/controller/tooltip.js +2 -2
  82. package/lib/chart/controller/tooltip.js.map +1 -1
  83. package/lib/chart/layout/constraint/bounds.js.map +1 -1
  84. package/lib/chart/layout/constraint/constraint.js.map +1 -1
  85. package/lib/chart/layout/constraint/gauss.js +3 -3
  86. package/lib/chart/layout/constraint/gauss.js.map +1 -1
  87. package/lib/chart/layout/constraint/solver.js.map +1 -1
  88. package/lib/chart/layout/constraint/types.js.map +1 -1
  89. package/lib/chart/layout/constraint/variable.js.map +1 -1
  90. package/lib/chart/util/scale-pool.js +1 -1
  91. package/lib/chart/util/scale-pool.js.map +1 -1
  92. package/lib/chart/util/sync-view-padding.js.map +1 -1
  93. package/lib/chart/view.js.map +1 -1
  94. package/lib/core.d.ts +5 -1
  95. package/lib/core.js +6 -1
  96. package/lib/core.js.map +1 -1
  97. package/lib/dependents.d.ts +1 -1
  98. package/lib/dependents.js.map +1 -1
  99. package/lib/geometry/base.d.ts +2 -2
  100. package/lib/geometry/base.js +10 -10
  101. package/lib/geometry/base.js.map +1 -1
  102. package/lib/geometry/element/index.d.ts +4 -0
  103. package/lib/geometry/element/index.js +9 -3
  104. package/lib/geometry/element/index.js.map +1 -1
  105. package/lib/geometry/label/interval.d.ts +2 -5
  106. package/lib/geometry/label/interval.js +11 -3
  107. package/lib/geometry/label/interval.js.map +1 -1
  108. package/lib/geometry/label/layout/limit-in-plot.js.map +1 -1
  109. package/lib/geometry/path.js +1 -0
  110. package/lib/geometry/path.js.map +1 -1
  111. package/lib/geometry/shape/edge/util.js +1 -6
  112. package/lib/geometry/shape/edge/util.js.map +1 -1
  113. package/lib/geometry/shape/line/index.d.ts +6 -0
  114. package/lib/geometry/shape/line/index.js +5 -0
  115. package/lib/geometry/shape/line/index.js.map +1 -1
  116. package/lib/geometry/shape/violin/hollow.js.map +1 -1
  117. package/lib/geometry/shape/violin/index.js.map +1 -1
  118. package/lib/geometry/util/shape-size.js +1 -1
  119. package/lib/geometry/util/shape-size.js.map +1 -1
  120. package/lib/index.js +5 -0
  121. package/lib/index.js.map +1 -1
  122. package/lib/interaction/action/component/list-checked.js +1 -1
  123. package/lib/interaction/action/component/list-checked.js.map +1 -1
  124. package/lib/interaction/action/view/mousewheel-scroll.d.ts +5 -0
  125. package/lib/interaction/action/view/mousewheel-scroll.js +37 -0
  126. package/lib/interaction/action/view/mousewheel-scroll.js.map +1 -0
  127. package/lib/interaction/context.js +2 -2
  128. package/lib/interaction/context.js.map +1 -1
  129. package/lib/interface.d.ts +9 -3
  130. package/lib/interface.js.map +1 -1
  131. package/lib/util/axis.js.map +1 -1
  132. package/lib/util/bbox.js +1 -2
  133. package/lib/util/bbox.js.map +1 -1
  134. package/lib/util/collision-detect.js +10 -0
  135. package/lib/util/collision-detect.js.map +1 -1
  136. package/lib/util/graphics.js +16 -0
  137. package/lib/util/graphics.js.map +1 -1
  138. package/lib/util/legend.js +3 -1
  139. package/lib/util/legend.js.map +1 -1
  140. package/lib/util/scale.js.map +1 -1
  141. package/lib/util/stat.js +1 -1
  142. package/lib/util/stat.js.map +1 -1
  143. package/package.json +17 -15
  144. package/src/chart/chart.ts +24 -1
  145. package/src/chart/controller/scrollbar.ts +27 -2
  146. package/src/chart/controller/tooltip.ts +2 -2
  147. package/src/chart/layout/constraint/bounds.ts +3 -4
  148. package/src/chart/layout/constraint/constraint.ts +4 -5
  149. package/src/chart/layout/constraint/gauss.ts +7 -7
  150. package/src/chart/layout/constraint/solver.ts +5 -6
  151. package/src/chart/layout/constraint/types.ts +2 -2
  152. package/src/chart/layout/constraint/variable.ts +2 -2
  153. package/src/chart/util/scale-pool.ts +8 -4
  154. package/src/chart/util/sync-view-padding.ts +1 -1
  155. package/src/chart/view.ts +10 -6
  156. package/src/core.ts +7 -1
  157. package/src/dependents.ts +11 -3
  158. package/src/geometry/base.ts +10 -11
  159. package/src/geometry/element/index.ts +12 -3
  160. package/src/geometry/label/interval.ts +20 -8
  161. package/src/geometry/label/layout/limit-in-plot.ts +6 -4
  162. package/src/geometry/path.ts +1 -0
  163. package/src/geometry/shape/edge/util.ts +1 -6
  164. package/src/geometry/shape/line/index.ts +4 -1
  165. package/src/geometry/shape/violin/hollow.ts +1 -1
  166. package/src/geometry/shape/violin/index.ts +2 -2
  167. package/src/geometry/util/shape-size.ts +2 -5
  168. package/src/index.ts +7 -0
  169. package/src/interaction/action/component/list-checked.ts +1 -1
  170. package/src/interaction/action/view/mousewheel-scroll.ts +38 -0
  171. package/src/interaction/context.ts +2 -2
  172. package/src/interface.ts +12 -2
  173. package/src/util/axis.ts +9 -4
  174. package/src/util/bbox.ts +1 -2
  175. package/src/util/collision-detect.ts +12 -2
  176. package/src/util/graphics.ts +22 -3
  177. package/src/util/legend.ts +6 -4
  178. package/src/util/scale.ts +9 -4
  179. package/src/util/stat.ts +9 -5
@@ -10,7 +10,6 @@ import type { Variable } from './variable';
10
10
  * 所以将算法退化成多元一次方程组的解法,直接使用高斯消元法(o(n^2))
11
11
  */
12
12
  export class Solver {
13
-
14
13
  /**
15
14
  * 存在的约束
16
15
  */
@@ -45,7 +44,7 @@ export class Solver {
45
44
 
46
45
  this.m = this.constraints.length;
47
46
  this.n = this.variables.length;
48
-
47
+
49
48
  // 2. 获取消元矩阵
50
49
  const matrix = this.getGaussMatrix();
51
50
 
@@ -78,7 +77,7 @@ export class Solver {
78
77
  */
79
78
  private getGaussMatrix() {
80
79
  const variableMap = new Map<Variable, number>();
81
-
80
+
82
81
  for (let i = 0; i < this.n; i++) {
83
82
  const variable = this.variables[i];
84
83
  variableMap.set(variable, i);
@@ -87,12 +86,12 @@ export class Solver {
87
86
  const matrix = [];
88
87
  for (let i = 0; i < this.m; i++) {
89
88
  const constraint = this.constraints[i];
90
-
89
+
91
90
  const arr = constraint.getGaussArr(variableMap);
92
91
 
93
92
  matrix.push(arr);
94
93
  }
95
-
94
+
96
95
  return matrix;
97
96
  }
98
- }
97
+ }
@@ -1,4 +1,4 @@
1
- import type { Variable } from './variable'
1
+ import type { Variable } from './variable';
2
2
 
3
3
  /**
4
4
  * 操作符的枚举值
@@ -17,7 +17,7 @@ export type BoxObject = {
17
17
  y: number;
18
18
  width: number;
19
19
  height: number;
20
- }
20
+ };
21
21
 
22
22
  /**
23
23
  * 几种情况
@@ -16,8 +16,8 @@ export class Variable {
16
16
 
17
17
  /**
18
18
  * 判断是否为一个变量
19
- * @param v
20
- * @returns
19
+ * @param v
20
+ * @returns
21
21
  */
22
22
  public static isVariable(v: any): v is Variable {
23
23
  return v instanceof Variable;
@@ -96,10 +96,14 @@ export class ScalePool {
96
96
  // 存在 value 值,且用户没有配置 range 配置 to fix https://github.com/antvis/G2/issues/2996
97
97
  if (values && !get(cacheScaleMeta, ['scaleDef', 'range'])) {
98
98
  // 更新 range
99
- range = getDefaultCategoryScaleRange(deepMix({}, scale, {
100
- values
101
- }), coordinate, theme);
102
- }
99
+ range = getDefaultCategoryScaleRange(
100
+ deepMix({}, scale, {
101
+ values,
102
+ }),
103
+ coordinate,
104
+ theme
105
+ );
106
+ }
103
107
  scale.change({
104
108
  values,
105
109
  range,
@@ -1,5 +1,5 @@
1
1
  import { PaddingCalCtor } from '../layout/padding-cal';
2
- import{ View } from '../view';
2
+ import { View } from '../view';
3
3
 
4
4
  /**
5
5
  * 默认的 syncViewPadding 逻辑
package/src/chart/view.ts CHANGED
@@ -1035,9 +1035,13 @@ export class View extends Base {
1035
1035
  * 获取 view 中的所有 geome
1036
1036
  */
1037
1037
  public getElements(): Element[] {
1038
- return reduce(this.geometries, (elements: Element[], geometry: Geometry) => {
1039
- return elements.concat(geometry.getElements());
1040
- }, []);
1038
+ return reduce(
1039
+ this.geometries,
1040
+ (elements: Element[], geometry: Geometry) => {
1041
+ return elements.concat(geometry.getElements());
1042
+ },
1043
+ []
1044
+ );
1041
1045
  }
1042
1046
 
1043
1047
  /**
@@ -1055,7 +1059,7 @@ export class View extends Base {
1055
1059
  * @returns
1056
1060
  */
1057
1061
  public getElementsBy(condition: (element: Element) => boolean): Element[] {
1058
- return this.getElements().filter(el => condition(el));
1062
+ return this.getElements().filter((el) => condition(el));
1059
1063
  }
1060
1064
 
1061
1065
  /**
@@ -1086,7 +1090,7 @@ export class View extends Base {
1086
1090
  * @returns 维度字段的 Attribute 数组
1087
1091
  */
1088
1092
  public getLegendAttributes(): Attribute[] {
1089
- return (flatten(this.geometries.map((g: Geometry) => g.getGroupAttributes())) as unknown) as Attribute[];
1093
+ return flatten(this.geometries.map((g: Geometry) => g.getGroupAttributes())) as unknown as Attribute[];
1090
1094
  }
1091
1095
 
1092
1096
  /**
@@ -1104,7 +1108,7 @@ export class View extends Base {
1104
1108
  * @returns G.Canvas 画布实例。
1105
1109
  */
1106
1110
  public getCanvas(): ICanvas {
1107
- return ((this.getRootView() as unknown) as Chart).canvas;
1111
+ return (this.getRootView() as unknown as Chart).canvas;
1108
1112
  }
1109
1113
 
1110
1114
  /**
package/src/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* G2 的一个壳子,不包含 Geometry,由开发者自己定义和引入 */
2
2
 
3
- export const VERSION = '4.1.29';
3
+ export const VERSION = '4.1.34';
4
4
 
5
5
  // 核心基类导出
6
6
  export { Chart, View, Event } from './chart'; // Chart, View 类
@@ -60,6 +60,9 @@ import { getAngle, getSectorPath, polarToCartesian } from './util/graphics';
60
60
  import { rotate, transform, translate, zoom } from './util/transform';
61
61
  import { getTooltipItems } from './util/tooltip';
62
62
  import { getDelegationObject } from './interaction/action/util';
63
+ import { getPathPoints } from './geometry/shape/util/get-path-points';
64
+ import { getPath } from './geometry/shape/line';
65
+
63
66
  export const Util = {
64
67
  getLegendItems,
65
68
  translate,
@@ -72,4 +75,7 @@ export const Util = {
72
75
  getDelegationObject,
73
76
  getTooltipItems,
74
77
  getMappingValue,
78
+ // shape 的一些操作方法
79
+ getPath,
80
+ getPathPoints,
75
81
  };
package/src/dependents.ts CHANGED
@@ -2,9 +2,17 @@
2
2
 
3
3
  // G
4
4
  export {
5
- ICanvas, IElement, IGroup, IShape,
6
- PathCommand, BBox, Point, ShapeAttrs,
7
- Event, AbstractGroup, AbstractShape
5
+ ICanvas,
6
+ IElement,
7
+ IGroup,
8
+ IShape,
9
+ PathCommand,
10
+ BBox,
11
+ Point,
12
+ ShapeAttrs,
13
+ Event,
14
+ AbstractGroup,
15
+ AbstractShape,
8
16
  } from '@antv/g-base';
9
17
  // 需要有 G-base 提供 g engine 类型定义
10
18
  export type IG = any;
@@ -259,7 +259,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
259
259
  /** 多层饼图/环图占比 */
260
260
  protected multiplePieWidthRatio: number;
261
261
  /** elements 的 zIndex 默认按顺序提升,通过 zIndexReversed 可以反序,从而数据越前,层级越高 */
262
- protected zIndexReversed?: boolean;
262
+ public zIndexReversed?: boolean;
263
263
 
264
264
  /** 虚拟 Group,用于图形更新 */
265
265
  private offscreenGroup: IGroup;
@@ -1450,7 +1450,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1450
1450
  * @param [isUpdate] 是否处于更新阶段
1451
1451
  * @returns element 返回创建的 Element 实例
1452
1452
  */
1453
- protected createElement(mappingDatum: MappingDatum, isUpdate: boolean = false): Element {
1453
+ protected createElement(mappingDatum: MappingDatum, index: number, isUpdate: boolean = false): Element {
1454
1454
  const { container } = this;
1455
1455
 
1456
1456
  const shapeCfg = this.getDrawCfg(mappingDatum); // 获取绘制图形的配置信息
@@ -1460,6 +1460,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1460
1460
  shapeFactory,
1461
1461
  container,
1462
1462
  offscreenGroup: this.getOffscreenGroup(),
1463
+ elementIndex: index,
1463
1464
  });
1464
1465
  element.animate = this.animateOption;
1465
1466
  element.geometry = this;
@@ -1540,10 +1541,13 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1540
1541
  // 新建 element
1541
1542
  for (const key of added) {
1542
1543
  const mappingDatum = keyDatum.get(key);
1543
- const element = this.createElement(mappingDatum, isUpdate);
1544
1544
  const i = keyIndex.get(key);
1545
+ const element = this.createElement(mappingDatum, i, isUpdate);
1545
1546
  this.elements[i] = element;
1546
1547
  this.elementsMap[key] = element;
1548
+ if (element.shape) {
1549
+ element.shape.setZIndex(this.zIndexReversed ? this.elements.length - i : i);
1550
+ }
1547
1551
  }
1548
1552
 
1549
1553
  // 更新 element
@@ -1560,6 +1564,9 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1560
1564
  }
1561
1565
  this.elements[i] = element;
1562
1566
  this.elementsMap[key] = element;
1567
+ if (element.shape) {
1568
+ element.shape.setZIndex(this.zIndexReversed ? this.elements.length - i : i);
1569
+ }
1563
1570
  }
1564
1571
 
1565
1572
  // 销毁被删除的 elements
@@ -1569,14 +1576,6 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
1569
1576
  element.animate = this.animateOption;
1570
1577
  element.destroy();
1571
1578
  }
1572
-
1573
- // 对 elements 的 zIndex 进行反序
1574
- if (this.zIndexReversed) {
1575
- const length = this.elements.length;
1576
- for (let i = 0; i < length; i++) {
1577
- this.elements[i].shape.setZIndex(length - i);
1578
- }
1579
- }
1580
1579
  }
1581
1580
 
1582
1581
  /**
@@ -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,11 @@ 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
+ if (this.geometry.zIndexReversed) {
233
+ shape.setZIndex(this.geometry.elements.length - this.elementIndex);
234
+ } else {
235
+ shape.setZIndex(this.elementIndex);
236
+ }
228
237
  }
229
238
  }
230
239
 
@@ -491,7 +500,7 @@ export default class Element extends Base {
491
500
  toAttrs: newAttrs,
492
501
  shapeModel: this.model,
493
502
  });
494
- } else if (isEmpty(states)) {
503
+ } else if (!isEmpty(states)) {
495
504
  sourceShape.stopAnimate();
496
505
  sourceShape.animate(newAttrs, {
497
506
  duration: 300,
@@ -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
  /**
@@ -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
@@ -217,6 +217,7 @@ import ViewDrag from './interaction/action/view/drag';
217
217
  import ViewMove from './interaction/action/view/move';
218
218
  import ScaleTranslate from './interaction/action/view/scale-translate';
219
219
  import ScaleZoom from './interaction/action/view/scale-zoom';
220
+ import MousewheelScroll from './interaction/action/view/mousewheel-scroll';
220
221
 
221
222
  registerAction('tooltip', TooltipAction);
222
223
  registerAction('sibling-tooltip', SiblingTooltip);
@@ -287,6 +288,8 @@ registerAction('reset-button', ButtonAction, {
287
288
  text: 'reset',
288
289
  });
289
290
 
291
+ registerAction('mousewheel-scroll', MousewheelScroll);
292
+
290
293
  // 注册默认的 Interaction 交互行为
291
294
  import { registerInteraction } from './core';
292
295
 
@@ -617,6 +620,10 @@ registerInteraction('sibling-tooltip', {
617
620
  end: [{ trigger: 'plot:mouseleave', action: 'sibling-tooltip:hide' }],
618
621
  });
619
622
 
623
+ registerInteraction('plot-mousewheel-scroll', {
624
+ start: [{ trigger: 'plot:mousewheel', action: 'mousewheel-scroll:scroll' }],
625
+ });
626
+
620
627
  // 让 TS 支持 View 原型上添加的创建 Geometry 方法的智能提示
621
628
  /**
622
629
  * 往 View 原型上添加的创建 Geometry 的方法
@@ -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,38 @@
1
+ import { clamp, size, valuesOfKey } from '@antv/util';
2
+ import { COMPONENT_TYPE } from '../../../constant';
3
+ import { Action } from '..';
4
+ import { LooseObject } from '../../../interface';
5
+
6
+ function isWheelDown(event: LooseObject) {
7
+ const wheelEvent = event.gEvent.originalEvent as WheelEvent;
8
+ return wheelEvent.deltaY > 0;
9
+ }
10
+
11
+ const DEFAULT_WHEELDELTA = 1;
12
+ class MousewheelScroll extends Action {
13
+ public scroll(arg?) {
14
+ const { view, event } = this.context;
15
+
16
+ if (!view.getOptions().scrollbar) {
17
+ return;
18
+ }
19
+
20
+ const wheelDelta = arg?.wheelDelta || DEFAULT_WHEELDELTA;
21
+ const scrollbarController = view.getController('scrollbar');
22
+
23
+ const xScale = view.getXScale();
24
+ const data = view.getOptions().data;
25
+ const dataSize = size(valuesOfKey(data, xScale.field));
26
+ const step = size(xScale.values);
27
+
28
+ const currentRatio = scrollbarController.getValue();
29
+ const currentStart = Math.floor((dataSize - step) * currentRatio);
30
+
31
+ const nextStart = currentStart + (isWheelDown(event) ? wheelDelta : -wheelDelta);
32
+ const correction = wheelDelta / (dataSize - step) / 10000;
33
+ const nextRatio = clamp(nextStart / (dataSize - step) + correction, 0, 1);
34
+ scrollbarController.setValue(nextRatio);
35
+ }
36
+ }
37
+
38
+ export default MousewheelScroll;
@@ -138,12 +138,12 @@ export default class Context implements IInteractionContext {
138
138
  * 销毁
139
139
  */
140
140
  public destroy() {
141
- this.view = null;
142
- this.event = null;
143
141
  // 先销毁 action 再清空,一边遍历,一边删除,所以数组需要更新引用
144
142
  each(this.actions.slice(), (action) => {
145
143
  action.destroy();
146
144
  });
145
+ this.view = null;
146
+ this.event = null;
147
147
  this.actions = null;
148
148
  this.cacheMap = null;
149
149
  }
package/src/interface.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  ICanvas,
21
21
  IGroup,
22
22
  IShape,
23
+ CategoryLegendCfg,
23
24
  LegendBackgroundCfg,
24
25
  LegendItemNameCfg,
25
26
  LegendItemValueCfg,
@@ -69,6 +70,15 @@ export interface RangePoint {
69
70
  readonly y?: number | number[];
70
71
  }
71
72
 
73
+ /**
74
+ * WAI-ARIA 无障碍标签配置
75
+ */
76
+ export type AriaOption =
77
+ | false
78
+ | {
79
+ readonly label: string;
80
+ };
81
+
72
82
  /** 用户数据经过图形映射处理后的数据结构 */
73
83
  export interface MappingDatum {
74
84
  /** 原始数据 */
@@ -912,7 +922,7 @@ export interface G2LegendTitleCfg extends LegendTitleCfg {
912
922
  /**
913
923
  * 图例项配置
914
924
  */
915
- export interface LegendCfg {
925
+ export interface LegendCfg extends Omit<CategoryLegendCfg, 'marker'> {
916
926
  /**
917
927
  * 是否为自定义图例,当该属性为 true 时,需要声明 items 属性。
918
928
  */
@@ -1614,7 +1624,7 @@ export type Marker =
1614
1624
  | 'hyphen'
1615
1625
  | 'line';
1616
1626
  /** 自定义 Marker 的回调函数定义 */
1617
- export type MarkerCallback = (x: number, y: number, r: number) => PathCommand;
1627
+ export type MarkerCallback = (x: number, y: number, r: number) => PathCommand[];
1618
1628
  /** chart.tooltip() 参数类型 */
1619
1629
  export type TooltipOption = TooltipCfg | boolean;
1620
1630
  /* 筛选器函数类型定义 */
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
  /**
@@ -1,10 +1,10 @@
1
- import { vec2 } from '@antv/matrix-util';
1
+ import { isNumber } from '@antv/util';
2
+ import { vec2 } from '@antv/matrix-util';
2
3
  import { BBox, Point } from '../dependents';
3
4
 
4
5
  const { dot } = vec2;
5
6
  type Vec2 = [number, number];
6
7
 
7
-
8
8
  type Box = Pick<BBox, 'x' | 'y' | 'width' | 'height'> & { rotation?: number };
9
9
 
10
10
  /**
@@ -98,6 +98,14 @@ function isProjectionOverlap(projection1: Projection, projection2: Projection):
98
98
  return projection1.max > projection2.min && projection1.min < projection2.max;
99
99
  }
100
100
 
101
+ function isValidNumber(d: number) {
102
+ return isNumber(d) && !Number.isNaN(d) && d !== Infinity && d !== -Infinity;
103
+ }
104
+
105
+ function isValidBox(box: Box) {
106
+ return Object.values(box).every(isValidNumber);
107
+ }
108
+
101
109
  /**
102
110
  * 快速判断两个无旋转矩形是否遮挡
103
111
  */
@@ -117,6 +125,8 @@ export function isIntersectRect(box1: Box, box2: Box, margin: number = 0): boole
117
125
  * - 原理: 分离轴定律
118
126
  */
119
127
  export function isIntersect(box1: Box, box2: Box) {
128
+ // 如果两个 box 中有一个是不合法的 box,也就是不会被渲染出来的,那么它们就不相交。
129
+ if (!isValidBox(box1) || !isValidBox(box2)) return false;
120
130
 
121
131
  // 如果两个矩形没有旋转,使用快速判断
122
132
  if (!box1.rotation && !box2.rotation) {