@antv/g2 4.1.30 → 4.1.35

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 (258) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.en-US.md +1 -2
  3. package/README.md +1 -2
  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/axis.js +3 -3
  10. package/esm/chart/controller/axis.js.map +1 -1
  11. package/esm/chart/controller/gesture.js +2 -2
  12. package/esm/chart/controller/gesture.js.map +1 -1
  13. package/esm/chart/controller/legend.js +1 -1
  14. package/esm/chart/controller/legend.js.map +1 -1
  15. package/esm/chart/controller/scrollbar.d.ts +8 -0
  16. package/esm/chart/controller/scrollbar.js +24 -3
  17. package/esm/chart/controller/scrollbar.js.map +1 -1
  18. package/esm/chart/controller/tooltip.js +2 -2
  19. package/esm/chart/controller/tooltip.js.map +1 -1
  20. package/esm/chart/event.js +1 -1
  21. package/esm/chart/event.js.map +1 -1
  22. package/esm/chart/layout/constraint/bounds.js +4 -4
  23. package/esm/chart/layout/constraint/bounds.js.map +1 -1
  24. package/esm/chart/layout/constraint/constraint.js.map +1 -1
  25. package/esm/chart/layout/constraint/gauss.js +3 -3
  26. package/esm/chart/layout/constraint/gauss.js.map +1 -1
  27. package/esm/chart/layout/constraint/solver.js.map +1 -1
  28. package/esm/chart/layout/constraint/types.js.map +1 -1
  29. package/esm/chart/layout/constraint/variable.js +1 -1
  30. package/esm/chart/layout/constraint/variable.js.map +1 -1
  31. package/esm/chart/util/scale-pool.js +1 -1
  32. package/esm/chart/util/scale-pool.js.map +1 -1
  33. package/esm/chart/util/sync-view-padding.js.map +1 -1
  34. package/esm/chart/view.js +4 -4
  35. package/esm/chart/view.js.map +1 -1
  36. package/esm/core.d.ts +5 -1
  37. package/esm/core.js +6 -1
  38. package/esm/core.js.map +1 -1
  39. package/esm/dependents.d.ts +1 -1
  40. package/esm/dependents.js +1 -1
  41. package/esm/dependents.js.map +1 -1
  42. package/esm/engine/index.js +1 -1
  43. package/esm/engine/index.js.map +1 -1
  44. package/esm/geometry/base.d.ts +2 -2
  45. package/esm/geometry/base.js +16 -16
  46. package/esm/geometry/base.js.map +1 -1
  47. package/esm/geometry/element/index.d.ts +4 -0
  48. package/esm/geometry/element/index.js +8 -2
  49. package/esm/geometry/element/index.js.map +1 -1
  50. package/esm/geometry/label/base.js +2 -2
  51. package/esm/geometry/label/base.js.map +1 -1
  52. package/esm/geometry/label/interval.d.ts +2 -5
  53. package/esm/geometry/label/interval.js +11 -3
  54. package/esm/geometry/label/interval.js.map +1 -1
  55. package/esm/geometry/label/layout/limit-in-plot.js.map +1 -1
  56. package/esm/geometry/label/layout/overlap.js +2 -2
  57. package/esm/geometry/label/layout/overlap.js.map +1 -1
  58. package/esm/geometry/label/layout/pie/distribute.js +3 -3
  59. package/esm/geometry/label/layout/pie/distribute.js.map +1 -1
  60. package/esm/geometry/label/layout/pie/outer.js +6 -6
  61. package/esm/geometry/label/layout/pie/outer.js.map +1 -1
  62. package/esm/geometry/label/layout/pie/spider.js +5 -5
  63. package/esm/geometry/label/layout/pie/spider.js.map +1 -1
  64. package/esm/geometry/path.js +1 -0
  65. package/esm/geometry/path.js.map +1 -1
  66. package/esm/geometry/shape/edge/util.js +1 -6
  67. package/esm/geometry/shape/edge/util.js.map +1 -1
  68. package/esm/geometry/shape/interval/util.js +63 -47
  69. package/esm/geometry/shape/interval/util.js.map +1 -1
  70. package/esm/geometry/shape/line/index.d.ts +6 -0
  71. package/esm/geometry/shape/line/index.js +4 -1
  72. package/esm/geometry/shape/line/index.js.map +1 -1
  73. package/esm/geometry/shape/point/index.js +1 -1
  74. package/esm/geometry/shape/point/index.js.map +1 -1
  75. package/esm/geometry/shape/violin/hollow.js.map +1 -1
  76. package/esm/geometry/shape/violin/index.js.map +1 -1
  77. package/esm/geometry/util/group-data.js +1 -1
  78. package/esm/geometry/util/group-data.js.map +1 -1
  79. package/esm/geometry/util/shape-size.js +1 -1
  80. package/esm/geometry/util/shape-size.js.map +1 -1
  81. package/esm/index.js +5 -0
  82. package/esm/index.js.map +1 -1
  83. package/esm/interaction/action/component/list-checked.js +1 -1
  84. package/esm/interaction/action/component/list-checked.js.map +1 -1
  85. package/esm/interaction/action/mask/base.js +1 -1
  86. package/esm/interaction/action/mask/base.js.map +1 -1
  87. package/esm/interaction/action/view/mousewheel-scroll.d.ts +5 -0
  88. package/esm/interaction/action/view/mousewheel-scroll.js +35 -0
  89. package/esm/interaction/action/view/mousewheel-scroll.js.map +1 -0
  90. package/esm/interaction/context.js +2 -2
  91. package/esm/interaction/context.js.map +1 -1
  92. package/esm/interaction/grammar-interaction.js +2 -2
  93. package/esm/interaction/grammar-interaction.js.map +1 -1
  94. package/esm/interface.d.ts +9 -3
  95. package/esm/interface.js.map +1 -1
  96. package/esm/theme/util/create-by-style-sheet.js +9 -9
  97. package/esm/theme/util/create-by-style-sheet.js.map +1 -1
  98. package/esm/util/axis.js.map +1 -1
  99. package/esm/util/bbox.js +1 -2
  100. package/esm/util/bbox.js.map +1 -1
  101. package/esm/util/collision-detect.js +10 -0
  102. package/esm/util/collision-detect.js.map +1 -1
  103. package/esm/util/event.js +1 -1
  104. package/esm/util/event.js.map +1 -1
  105. package/esm/util/graphics.js +17 -1
  106. package/esm/util/graphics.js.map +1 -1
  107. package/esm/util/legend.js +3 -1
  108. package/esm/util/legend.js.map +1 -1
  109. package/esm/util/scale.js.map +1 -1
  110. package/esm/util/stat.js +1 -1
  111. package/esm/util/stat.js.map +1 -1
  112. package/esm/util/text.js +2 -2
  113. package/esm/util/text.js.map +1 -1
  114. package/lib/chart/chart.d.ts +10 -0
  115. package/lib/chart/chart.js +20 -0
  116. package/lib/chart/chart.js.map +1 -1
  117. package/lib/chart/controller/axis.js +3 -3
  118. package/lib/chart/controller/axis.js.map +1 -1
  119. package/lib/chart/controller/gesture.js +2 -2
  120. package/lib/chart/controller/gesture.js.map +1 -1
  121. package/lib/chart/controller/legend.js +1 -1
  122. package/lib/chart/controller/legend.js.map +1 -1
  123. package/lib/chart/controller/scrollbar.d.ts +8 -0
  124. package/lib/chart/controller/scrollbar.js +23 -2
  125. package/lib/chart/controller/scrollbar.js.map +1 -1
  126. package/lib/chart/controller/tooltip.js +2 -2
  127. package/lib/chart/controller/tooltip.js.map +1 -1
  128. package/lib/chart/event.js +1 -1
  129. package/lib/chart/event.js.map +1 -1
  130. package/lib/chart/layout/constraint/bounds.js +4 -4
  131. package/lib/chart/layout/constraint/bounds.js.map +1 -1
  132. package/lib/chart/layout/constraint/constraint.js.map +1 -1
  133. package/lib/chart/layout/constraint/gauss.js +3 -3
  134. package/lib/chart/layout/constraint/gauss.js.map +1 -1
  135. package/lib/chart/layout/constraint/solver.js.map +1 -1
  136. package/lib/chart/layout/constraint/types.js.map +1 -1
  137. package/lib/chart/layout/constraint/variable.js +1 -1
  138. package/lib/chart/layout/constraint/variable.js.map +1 -1
  139. package/lib/chart/util/scale-pool.js +1 -1
  140. package/lib/chart/util/scale-pool.js.map +1 -1
  141. package/lib/chart/util/sync-view-padding.js.map +1 -1
  142. package/lib/chart/view.js +4 -4
  143. package/lib/chart/view.js.map +1 -1
  144. package/lib/core.d.ts +5 -1
  145. package/lib/core.js +6 -1
  146. package/lib/core.js.map +1 -1
  147. package/lib/dependents.d.ts +1 -1
  148. package/lib/dependents.js.map +1 -1
  149. package/lib/engine/index.js +1 -1
  150. package/lib/engine/index.js.map +1 -1
  151. package/lib/geometry/base.d.ts +2 -2
  152. package/lib/geometry/base.js +16 -16
  153. package/lib/geometry/base.js.map +1 -1
  154. package/lib/geometry/element/index.d.ts +4 -0
  155. package/lib/geometry/element/index.js +8 -2
  156. package/lib/geometry/element/index.js.map +1 -1
  157. package/lib/geometry/label/base.js +2 -2
  158. package/lib/geometry/label/base.js.map +1 -1
  159. package/lib/geometry/label/interval.d.ts +2 -5
  160. package/lib/geometry/label/interval.js +11 -3
  161. package/lib/geometry/label/interval.js.map +1 -1
  162. package/lib/geometry/label/layout/limit-in-plot.js.map +1 -1
  163. package/lib/geometry/label/layout/overlap.js +2 -2
  164. package/lib/geometry/label/layout/overlap.js.map +1 -1
  165. package/lib/geometry/label/layout/pie/distribute.js +3 -3
  166. package/lib/geometry/label/layout/pie/distribute.js.map +1 -1
  167. package/lib/geometry/label/layout/pie/outer.js +6 -6
  168. package/lib/geometry/label/layout/pie/outer.js.map +1 -1
  169. package/lib/geometry/label/layout/pie/spider.js +5 -5
  170. package/lib/geometry/label/layout/pie/spider.js.map +1 -1
  171. package/lib/geometry/path.js +1 -0
  172. package/lib/geometry/path.js.map +1 -1
  173. package/lib/geometry/shape/edge/util.js +1 -6
  174. package/lib/geometry/shape/edge/util.js.map +1 -1
  175. package/lib/geometry/shape/interval/util.js +63 -47
  176. package/lib/geometry/shape/interval/util.js.map +1 -1
  177. package/lib/geometry/shape/line/index.d.ts +6 -0
  178. package/lib/geometry/shape/line/index.js +5 -0
  179. package/lib/geometry/shape/line/index.js.map +1 -1
  180. package/lib/geometry/shape/point/index.js +1 -1
  181. package/lib/geometry/shape/point/index.js.map +1 -1
  182. package/lib/geometry/shape/violin/hollow.js.map +1 -1
  183. package/lib/geometry/shape/violin/index.js.map +1 -1
  184. package/lib/geometry/util/group-data.js +1 -1
  185. package/lib/geometry/util/group-data.js.map +1 -1
  186. package/lib/geometry/util/shape-size.js +1 -1
  187. package/lib/geometry/util/shape-size.js.map +1 -1
  188. package/lib/index.js +5 -0
  189. package/lib/index.js.map +1 -1
  190. package/lib/interaction/action/component/list-checked.js +1 -1
  191. package/lib/interaction/action/component/list-checked.js.map +1 -1
  192. package/lib/interaction/action/mask/base.js +1 -1
  193. package/lib/interaction/action/mask/base.js.map +1 -1
  194. package/lib/interaction/action/view/mousewheel-scroll.d.ts +5 -0
  195. package/lib/interaction/action/view/mousewheel-scroll.js +37 -0
  196. package/lib/interaction/action/view/mousewheel-scroll.js.map +1 -0
  197. package/lib/interaction/context.js +2 -2
  198. package/lib/interaction/context.js.map +1 -1
  199. package/lib/interaction/grammar-interaction.js +2 -2
  200. package/lib/interaction/grammar-interaction.js.map +1 -1
  201. package/lib/interface.d.ts +9 -3
  202. package/lib/interface.js.map +1 -1
  203. package/lib/theme/util/create-by-style-sheet.js +9 -9
  204. package/lib/theme/util/create-by-style-sheet.js.map +1 -1
  205. package/lib/util/axis.js.map +1 -1
  206. package/lib/util/bbox.js +1 -2
  207. package/lib/util/bbox.js.map +1 -1
  208. package/lib/util/collision-detect.js +10 -0
  209. package/lib/util/collision-detect.js.map +1 -1
  210. package/lib/util/event.js +1 -1
  211. package/lib/util/event.js.map +1 -1
  212. package/lib/util/graphics.js +16 -0
  213. package/lib/util/graphics.js.map +1 -1
  214. package/lib/util/legend.js +3 -1
  215. package/lib/util/legend.js.map +1 -1
  216. package/lib/util/scale.js.map +1 -1
  217. package/lib/util/stat.js +1 -1
  218. package/lib/util/stat.js.map +1 -1
  219. package/lib/util/text.js +2 -2
  220. package/lib/util/text.js.map +1 -1
  221. package/package.json +15 -15
  222. package/src/chart/chart.ts +24 -1
  223. package/src/chart/controller/scrollbar.ts +27 -2
  224. package/src/chart/controller/tooltip.ts +2 -2
  225. package/src/chart/layout/constraint/bounds.ts +3 -4
  226. package/src/chart/layout/constraint/constraint.ts +4 -5
  227. package/src/chart/layout/constraint/gauss.ts +7 -7
  228. package/src/chart/layout/constraint/solver.ts +5 -6
  229. package/src/chart/layout/constraint/types.ts +2 -2
  230. package/src/chart/layout/constraint/variable.ts +2 -2
  231. package/src/chart/util/scale-pool.ts +8 -4
  232. package/src/chart/util/sync-view-padding.ts +1 -1
  233. package/src/chart/view.ts +10 -6
  234. package/src/core.ts +7 -1
  235. package/src/dependents.ts +11 -3
  236. package/src/geometry/base.ts +10 -11
  237. package/src/geometry/element/index.ts +11 -2
  238. package/src/geometry/label/interval.ts +20 -8
  239. package/src/geometry/label/layout/limit-in-plot.ts +6 -4
  240. package/src/geometry/path.ts +1 -0
  241. package/src/geometry/shape/edge/util.ts +1 -6
  242. package/src/geometry/shape/interval/util.ts +65 -46
  243. package/src/geometry/shape/line/index.ts +4 -1
  244. package/src/geometry/shape/violin/hollow.ts +1 -1
  245. package/src/geometry/shape/violin/index.ts +2 -2
  246. package/src/geometry/util/shape-size.ts +2 -5
  247. package/src/index.ts +7 -0
  248. package/src/interaction/action/component/list-checked.ts +1 -1
  249. package/src/interaction/action/view/mousewheel-scroll.ts +38 -0
  250. package/src/interaction/context.ts +2 -2
  251. package/src/interface.ts +12 -2
  252. package/src/util/axis.ts +9 -4
  253. package/src/util/bbox.ts +1 -2
  254. package/src/util/collision-detect.ts +12 -2
  255. package/src/util/graphics.ts +22 -3
  256. package/src/util/legend.ts +6 -4
  257. package/src/util/scale.ts +9 -4
  258. package/src/util/stat.ts +9 -5
@@ -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.30';
3
+ export const VERSION = '4.1.35';
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
 
@@ -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
@@ -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
  /* 筛选器函数类型定义 */