@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
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) {
@@ -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
+ }