@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.
- package/CHANGELOG.md +74 -0
- package/README.en-US.md +1 -1
- package/README.md +1 -1
- package/dist/g2.min.js +4 -18
- package/dist/g2.min.js.map +1 -1
- package/esm/chart/chart.d.ts +10 -0
- package/esm/chart/chart.js +20 -0
- package/esm/chart/chart.js.map +1 -1
- package/esm/chart/controller/scrollbar.d.ts +8 -0
- package/esm/chart/controller/scrollbar.js +24 -3
- package/esm/chart/controller/scrollbar.js.map +1 -1
- package/esm/chart/controller/tooltip.js +2 -2
- package/esm/chart/controller/tooltip.js.map +1 -1
- package/esm/chart/layout/constraint/bounds.js.map +1 -1
- package/esm/chart/layout/constraint/constraint.js.map +1 -1
- package/esm/chart/layout/constraint/gauss.js +3 -3
- package/esm/chart/layout/constraint/gauss.js.map +1 -1
- package/esm/chart/layout/constraint/solver.js.map +1 -1
- package/esm/chart/layout/constraint/types.js.map +1 -1
- package/esm/chart/layout/constraint/variable.js.map +1 -1
- package/esm/chart/util/scale-pool.js +1 -1
- package/esm/chart/util/scale-pool.js.map +1 -1
- package/esm/chart/util/sync-view-padding.js.map +1 -1
- package/esm/chart/view.js.map +1 -1
- package/esm/core.d.ts +5 -1
- package/esm/core.js +6 -1
- package/esm/core.js.map +1 -1
- package/esm/dependents.d.ts +1 -1
- package/esm/dependents.js +1 -1
- package/esm/dependents.js.map +1 -1
- package/esm/geometry/base.d.ts +2 -2
- package/esm/geometry/base.js +10 -10
- package/esm/geometry/base.js.map +1 -1
- package/esm/geometry/element/index.d.ts +4 -0
- package/esm/geometry/element/index.js +9 -3
- package/esm/geometry/element/index.js.map +1 -1
- package/esm/geometry/label/interval.d.ts +2 -5
- package/esm/geometry/label/interval.js +11 -3
- package/esm/geometry/label/interval.js.map +1 -1
- package/esm/geometry/label/layout/limit-in-plot.js.map +1 -1
- package/esm/geometry/path.js +1 -0
- package/esm/geometry/path.js.map +1 -1
- package/esm/geometry/shape/edge/util.js +1 -6
- package/esm/geometry/shape/edge/util.js.map +1 -1
- package/esm/geometry/shape/line/index.d.ts +6 -0
- package/esm/geometry/shape/line/index.js +4 -1
- package/esm/geometry/shape/line/index.js.map +1 -1
- package/esm/geometry/shape/violin/hollow.js.map +1 -1
- package/esm/geometry/shape/violin/index.js.map +1 -1
- package/esm/geometry/util/shape-size.js +1 -1
- package/esm/geometry/util/shape-size.js.map +1 -1
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -1
- package/esm/interaction/action/component/list-checked.js +1 -1
- package/esm/interaction/action/component/list-checked.js.map +1 -1
- package/esm/interaction/action/view/mousewheel-scroll.d.ts +5 -0
- package/esm/interaction/action/view/mousewheel-scroll.js +35 -0
- package/esm/interaction/action/view/mousewheel-scroll.js.map +1 -0
- package/esm/interaction/context.js +2 -2
- package/esm/interaction/context.js.map +1 -1
- package/esm/interface.d.ts +9 -3
- package/esm/interface.js.map +1 -1
- package/esm/util/axis.js.map +1 -1
- package/esm/util/bbox.js +1 -2
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/collision-detect.js +10 -0
- package/esm/util/collision-detect.js.map +1 -1
- package/esm/util/graphics.js +17 -1
- package/esm/util/graphics.js.map +1 -1
- package/esm/util/legend.js +3 -1
- package/esm/util/legend.js.map +1 -1
- package/esm/util/scale.js.map +1 -1
- package/esm/util/stat.js +1 -1
- package/esm/util/stat.js.map +1 -1
- package/lib/chart/chart.d.ts +10 -0
- package/lib/chart/chart.js +20 -0
- package/lib/chart/chart.js.map +1 -1
- package/lib/chart/controller/scrollbar.d.ts +8 -0
- package/lib/chart/controller/scrollbar.js +23 -2
- package/lib/chart/controller/scrollbar.js.map +1 -1
- package/lib/chart/controller/tooltip.js +2 -2
- package/lib/chart/controller/tooltip.js.map +1 -1
- package/lib/chart/layout/constraint/bounds.js.map +1 -1
- package/lib/chart/layout/constraint/constraint.js.map +1 -1
- package/lib/chart/layout/constraint/gauss.js +3 -3
- package/lib/chart/layout/constraint/gauss.js.map +1 -1
- package/lib/chart/layout/constraint/solver.js.map +1 -1
- package/lib/chart/layout/constraint/types.js.map +1 -1
- package/lib/chart/layout/constraint/variable.js.map +1 -1
- package/lib/chart/util/scale-pool.js +1 -1
- package/lib/chart/util/scale-pool.js.map +1 -1
- package/lib/chart/util/sync-view-padding.js.map +1 -1
- package/lib/chart/view.js.map +1 -1
- package/lib/core.d.ts +5 -1
- package/lib/core.js +6 -1
- package/lib/core.js.map +1 -1
- package/lib/dependents.d.ts +1 -1
- package/lib/dependents.js.map +1 -1
- package/lib/geometry/base.d.ts +2 -2
- package/lib/geometry/base.js +10 -10
- package/lib/geometry/base.js.map +1 -1
- package/lib/geometry/element/index.d.ts +4 -0
- package/lib/geometry/element/index.js +9 -3
- package/lib/geometry/element/index.js.map +1 -1
- package/lib/geometry/label/interval.d.ts +2 -5
- package/lib/geometry/label/interval.js +11 -3
- package/lib/geometry/label/interval.js.map +1 -1
- package/lib/geometry/label/layout/limit-in-plot.js.map +1 -1
- package/lib/geometry/path.js +1 -0
- package/lib/geometry/path.js.map +1 -1
- package/lib/geometry/shape/edge/util.js +1 -6
- package/lib/geometry/shape/edge/util.js.map +1 -1
- package/lib/geometry/shape/line/index.d.ts +6 -0
- package/lib/geometry/shape/line/index.js +5 -0
- package/lib/geometry/shape/line/index.js.map +1 -1
- package/lib/geometry/shape/violin/hollow.js.map +1 -1
- package/lib/geometry/shape/violin/index.js.map +1 -1
- package/lib/geometry/util/shape-size.js +1 -1
- package/lib/geometry/util/shape-size.js.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/interaction/action/component/list-checked.js +1 -1
- package/lib/interaction/action/component/list-checked.js.map +1 -1
- package/lib/interaction/action/view/mousewheel-scroll.d.ts +5 -0
- package/lib/interaction/action/view/mousewheel-scroll.js +37 -0
- package/lib/interaction/action/view/mousewheel-scroll.js.map +1 -0
- package/lib/interaction/context.js +2 -2
- package/lib/interaction/context.js.map +1 -1
- package/lib/interface.d.ts +9 -3
- package/lib/interface.js.map +1 -1
- package/lib/util/axis.js.map +1 -1
- package/lib/util/bbox.js +1 -2
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/collision-detect.js +10 -0
- package/lib/util/collision-detect.js.map +1 -1
- package/lib/util/graphics.js +16 -0
- package/lib/util/graphics.js.map +1 -1
- package/lib/util/legend.js +3 -1
- package/lib/util/legend.js.map +1 -1
- package/lib/util/scale.js.map +1 -1
- package/lib/util/stat.js +1 -1
- package/lib/util/stat.js.map +1 -1
- package/package.json +17 -15
- package/src/chart/chart.ts +24 -1
- package/src/chart/controller/scrollbar.ts +27 -2
- package/src/chart/controller/tooltip.ts +2 -2
- package/src/chart/layout/constraint/bounds.ts +3 -4
- package/src/chart/layout/constraint/constraint.ts +4 -5
- package/src/chart/layout/constraint/gauss.ts +7 -7
- package/src/chart/layout/constraint/solver.ts +5 -6
- package/src/chart/layout/constraint/types.ts +2 -2
- package/src/chart/layout/constraint/variable.ts +2 -2
- package/src/chart/util/scale-pool.ts +8 -4
- package/src/chart/util/sync-view-padding.ts +1 -1
- package/src/chart/view.ts +10 -6
- package/src/core.ts +7 -1
- package/src/dependents.ts +11 -3
- package/src/geometry/base.ts +10 -11
- package/src/geometry/element/index.ts +12 -3
- package/src/geometry/label/interval.ts +20 -8
- package/src/geometry/label/layout/limit-in-plot.ts +6 -4
- package/src/geometry/path.ts +1 -0
- package/src/geometry/shape/edge/util.ts +1 -6
- package/src/geometry/shape/line/index.ts +4 -1
- package/src/geometry/shape/violin/hollow.ts +1 -1
- package/src/geometry/shape/violin/index.ts +2 -2
- package/src/geometry/util/shape-size.ts +2 -5
- package/src/index.ts +7 -0
- package/src/interaction/action/component/list-checked.ts +1 -1
- package/src/interaction/action/view/mousewheel-scroll.ts +38 -0
- package/src/interaction/context.ts +2 -2
- package/src/interface.ts +12 -2
- package/src/util/axis.ts +9 -4
- package/src/util/bbox.ts +1 -2
- package/src/util/collision-detect.ts +12 -2
- package/src/util/graphics.ts +22 -3
- package/src/util/legend.ts +6 -4
- package/src/util/scale.ts +9 -4
- package/src/util/stat.ts +9 -5
package/src/util/graphics.ts
CHANGED
|
@@ -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 =
|
|
209
|
+
let current = xs.length - 1;
|
|
191
210
|
let diff;
|
|
192
211
|
let k = 0;
|
|
193
|
-
while (++i <
|
|
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];
|
package/src/util/legend.ts
CHANGED
|
@@ -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)
|
|
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 =
|
|
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(
|
|
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(
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
}
|