@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
@@ -1,5 +1,5 @@
1
1
  import { BBox } from '@antv/g-svg';
2
- import { each, isEmpty, isNumber, isNumberEqual } from '@antv/util';
2
+ import { each, isEmpty, isNumber, isNumberEqual, max, min } from '@antv/util';
3
3
  import { Coordinate, IShape, Point } from '../dependents';
4
4
  import { ShapeInfo } from '../interface';
5
5
 
@@ -30,6 +30,14 @@ function getPointsBox(points) {
30
30
  };
31
31
  }
32
32
 
33
+ function uniqueValues<T = number>(array: T[]) {
34
+ return Array.from(new Set(array)).length === 1;
35
+ }
36
+
37
+ function mid(array: number[]) {
38
+ return (min(array) + max(array)) / 2;
39
+ }
40
+
33
41
  /**
34
42
  * @ignore
35
43
  * 根据弧度计算极坐标系下的坐标点
@@ -183,14 +191,25 @@ export function getPolygonCentroid(xs: number | number[], ys: number | number[])
183
191
  // 普通色块图,xs 和 ys 是数值
184
192
  return [xs, ys];
185
193
  }
194
+
195
+ xs = xs as number[];
196
+ ys = ys as number[];
197
+ // 当这个 polygon 的点在一条线上的时候
198
+ // 也就是说 xs 里面的值都相同,比如:[1, 1, 1, 1]
199
+ // 或者说 ys 里面的值都相同,比如:[0, 0, 0, 0]
200
+ // 下面计算得到的 k = 0
201
+ // 导致返回的值是 [NaN, NaN]
202
+ // 所以这里做相应的处理
203
+ if (uniqueValues(xs) || uniqueValues(ys)) return [mid(xs), mid(ys)];
204
+
186
205
  let i = -1;
187
206
  let x = 0;
188
207
  let y = 0;
189
208
  let former;
190
- let current = (xs as number[]).length - 1;
209
+ let current = xs.length - 1;
191
210
  let diff;
192
211
  let k = 0;
193
- while (++i < (xs as number[]).length) {
212
+ while (++i < xs.length) {
194
213
  former = current;
195
214
  current = i;
196
215
  k += diff = xs[former] * ys[current] - xs[current] * ys[former];
@@ -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
+ }