@antv/g2plot 2.4.3 → 2.4.4
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 +0 -21
- package/dist/g2plot.min.js +4 -4
- package/dist/g2plot.min.js.map +1 -1
- package/esm/index.d.ts +1 -9
- package/esm/index.js +1 -9
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +5 -15
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/area/constants.d.ts +0 -2
- package/esm/plots/area/constants.js +0 -2
- package/esm/plots/area/constants.js.map +1 -1
- package/esm/plots/area/index.js +4 -11
- package/esm/plots/area/index.js.map +1 -1
- package/esm/plots/line/adaptor.js +15 -30
- package/esm/plots/line/adaptor.js.map +1 -1
- package/esm/plots/line/constants.d.ts +0 -2
- package/esm/plots/line/constants.js +0 -3
- package/esm/plots/line/constants.js.map +1 -1
- package/esm/plots/line/index.js +1 -8
- package/esm/plots/line/index.js.map +1 -1
- package/esm/plots/line/interactions/marker-active.js +6 -7
- package/esm/plots/line/interactions/marker-active.js.map +1 -1
- package/esm/utils/geometry.js +1 -2
- package/esm/utils/geometry.js.map +1 -1
- package/lib/index.d.ts +1 -9
- package/lib/index.js +5 -13
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +3 -13
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/area/constants.d.ts +0 -2
- package/lib/plots/area/constants.js +1 -3
- package/lib/plots/area/constants.js.map +1 -1
- package/lib/plots/area/index.js +3 -10
- package/lib/plots/area/index.js.map +1 -1
- package/lib/plots/line/adaptor.js +14 -29
- package/lib/plots/line/adaptor.js.map +1 -1
- package/lib/plots/line/constants.d.ts +0 -2
- package/lib/plots/line/constants.js +1 -4
- package/lib/plots/line/constants.js.map +1 -1
- package/lib/plots/line/index.js +0 -7
- package/lib/plots/line/index.js.map +1 -1
- package/lib/plots/line/interactions/marker-active.js +6 -7
- package/lib/plots/line/interactions/marker-active.js.map +1 -1
- package/lib/utils/geometry.js +1 -2
- package/lib/utils/geometry.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -9
- package/src/plots/area/adaptor.ts +5 -16
- package/src/plots/area/constants.ts +0 -3
- package/src/plots/area/index.ts +3 -10
- package/src/plots/line/adaptor.ts +14 -35
- package/src/plots/line/constants.ts +0 -4
- package/src/plots/line/index.ts +1 -8
- package/src/plots/line/interactions/marker-active.ts +7 -8
- package/src/utils/geometry.ts +1 -2
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
|
-
import { each
|
|
2
|
+
import { each } from '@antv/util';
|
|
3
3
|
import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot, pattern } from '../../adaptor/common';
|
|
4
|
-
import { findGeometry
|
|
4
|
+
import { findGeometry } from '../../utils';
|
|
5
5
|
import { Params } from '../../core/adaptor';
|
|
6
6
|
import { area, point, line } from '../../adaptor/geometries';
|
|
7
7
|
import { flow, transformLabel, deepAssign } from '../../utils';
|
|
8
8
|
import { getDataWhetherPecentage } from '../../utils/transform/percent';
|
|
9
9
|
import { Datum } from '../../types';
|
|
10
10
|
import { meta, legend, axis } from '../line/adaptor';
|
|
11
|
-
import { POINT_VIEW_ID } from './constants';
|
|
12
11
|
import { AreaOptions } from './types';
|
|
13
12
|
|
|
14
13
|
export { meta };
|
|
@@ -71,21 +70,12 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
|
|
|
71
70
|
const lineParams = deepAssign({ options: { line: { size: 2 } } }, primary, {
|
|
72
71
|
options: { sizeField: seriesField, tooltip: false },
|
|
73
72
|
});
|
|
73
|
+
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
|
|
74
74
|
|
|
75
75
|
// area geometry 处理
|
|
76
76
|
area(primary);
|
|
77
77
|
line(lineParams);
|
|
78
|
-
|
|
79
|
-
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
|
|
80
|
-
if (pointMapping) {
|
|
81
|
-
const pointView = chart.createView({ id: POINT_VIEW_ID });
|
|
82
|
-
pointView.axis(false);
|
|
83
|
-
pointView.tooltip(false);
|
|
84
|
-
pointView.legend(false);
|
|
85
|
-
// [PERFORMANCE] 🚀 数据为空的 point 标注点都不渲染(不包括:数据为 0)
|
|
86
|
-
pointView.data(data.filter((d) => !isNil(d[yField])));
|
|
87
|
-
point({ ...pointParams, chart: pointView });
|
|
88
|
-
}
|
|
78
|
+
point(pointParams);
|
|
89
79
|
|
|
90
80
|
return params;
|
|
91
81
|
}
|
|
@@ -131,8 +121,7 @@ function adjust(params: Params<AreaOptions>): Params<AreaOptions> {
|
|
|
131
121
|
const { chart, options } = params;
|
|
132
122
|
const { isStack, isPercent, seriesField } = options;
|
|
133
123
|
if ((isPercent || isStack) && seriesField) {
|
|
134
|
-
|
|
135
|
-
each(geometries, (g: Geometry) => {
|
|
124
|
+
each(chart.geometries, (g: Geometry) => {
|
|
136
125
|
g.adjust('stack');
|
|
137
126
|
});
|
|
138
127
|
}
|
package/src/plots/area/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { isNil } from '@antv/util';
|
|
2
1
|
import { Plot } from '../../core/plot';
|
|
3
2
|
import { Adaptor } from '../../core/adaptor';
|
|
4
3
|
import { getDataWhetherPecentage } from '../../utils/transform/percent';
|
|
5
|
-
import { findViewById } from '../../utils';
|
|
6
4
|
import { AreaOptions } from './types';
|
|
7
5
|
import { adaptor, meta } from './adaptor';
|
|
8
|
-
import { DEFAULT_OPTIONS
|
|
6
|
+
import { DEFAULT_OPTIONS } from './constants';
|
|
9
7
|
|
|
10
8
|
export type { AreaOptions };
|
|
11
9
|
|
|
@@ -34,15 +32,10 @@ export class Area extends Plot<AreaOptions> {
|
|
|
34
32
|
*/
|
|
35
33
|
public changeData(data: AreaOptions['data']) {
|
|
36
34
|
this.updateOption({ data });
|
|
35
|
+
const { isPercent, xField, yField } = this.options;
|
|
37
36
|
const { chart, options } = this;
|
|
38
|
-
const { isPercent, xField, yField } = options;
|
|
39
37
|
meta({ chart, options });
|
|
40
|
-
|
|
41
|
-
this.chart.changeData(chartdata);
|
|
42
|
-
const pointView = findViewById(this.chart, POINT_VIEW_ID);
|
|
43
|
-
if (pointView) {
|
|
44
|
-
pointView.changeData(data.filter((d) => !isNil(d[yField])));
|
|
45
|
-
}
|
|
38
|
+
this.chart.changeData(getDataWhetherPecentage(data, yField, xField, yField, isPercent));
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
|
-
import { each, isArray
|
|
2
|
+
import { each, isArray } from '@antv/util';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
4
|
import { tooltip, slider, interaction, animation, theme, scale, annotation, limitInPlot } from '../../adaptor/common';
|
|
5
|
-
import {
|
|
5
|
+
import { findGeometry, transformLabel, deepAssign } from '../../utils';
|
|
6
6
|
import { point, line, area } from '../../adaptor/geometries';
|
|
7
|
+
import { flow } from '../../utils';
|
|
7
8
|
import { adjustYMetaByZero } from '../../utils/data';
|
|
8
|
-
import { POINT_VIEW_ID } from './constants';
|
|
9
9
|
import { LineOptions } from './types';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -14,7 +14,7 @@ import { LineOptions } from './types';
|
|
|
14
14
|
*/
|
|
15
15
|
function geometry(params: Params<LineOptions>): Params<LineOptions> {
|
|
16
16
|
const { chart, options } = params;
|
|
17
|
-
const { data, color, lineStyle, lineShape, point: pointMapping, area: areaMapping,
|
|
17
|
+
const { data, color, lineStyle, lineShape, point: pointMapping, area: areaMapping, seriesField } = options;
|
|
18
18
|
const pointState = pointMapping?.state;
|
|
19
19
|
|
|
20
20
|
chart.data(data);
|
|
@@ -44,23 +44,13 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
|
|
|
44
44
|
label: undefined,
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
|
-
|
|
47
|
+
const second = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
|
|
48
48
|
const areaParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
|
|
49
49
|
|
|
50
50
|
line(primary);
|
|
51
|
+
point(second);
|
|
51
52
|
area(areaParams);
|
|
52
53
|
|
|
53
|
-
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
|
|
54
|
-
if (pointMapping) {
|
|
55
|
-
const pointView = chart.createView({ id: POINT_VIEW_ID });
|
|
56
|
-
pointView.axis(false);
|
|
57
|
-
pointView.tooltip(false);
|
|
58
|
-
pointView.legend(false);
|
|
59
|
-
// [PERFORMANCE] 🚀 数据为空的 point 标注点都不渲染(不包括:数据为 0)
|
|
60
|
-
pointView.data(data.filter((d) => !isNil(d[yField])));
|
|
61
|
-
point({ ...pointParams, chart: pointView });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
54
|
return params;
|
|
65
55
|
}
|
|
66
56
|
|
|
@@ -70,21 +60,7 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
|
|
|
70
60
|
*/
|
|
71
61
|
export function meta(params: Params<LineOptions>): Params<LineOptions> {
|
|
72
62
|
const { options } = params;
|
|
73
|
-
const { xAxis, yAxis, xField, yField, data
|
|
74
|
-
const defaultMeta = {
|
|
75
|
-
[xField]: {
|
|
76
|
-
type: 'cat',
|
|
77
|
-
sync: true,
|
|
78
|
-
values: uniq(data.map((d) => d[xField])),
|
|
79
|
-
},
|
|
80
|
-
[yField]: {
|
|
81
|
-
...adjustYMetaByZero(data, yField),
|
|
82
|
-
sync: true,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
if (seriesField) {
|
|
86
|
-
defaultMeta[seriesField] = { sync: true };
|
|
87
|
-
}
|
|
63
|
+
const { xAxis, yAxis, xField, yField, data } = options;
|
|
88
64
|
|
|
89
65
|
return flow(
|
|
90
66
|
scale(
|
|
@@ -92,7 +68,12 @@ export function meta(params: Params<LineOptions>): Params<LineOptions> {
|
|
|
92
68
|
[xField]: xAxis,
|
|
93
69
|
[yField]: yAxis,
|
|
94
70
|
},
|
|
95
|
-
|
|
71
|
+
{
|
|
72
|
+
[xField]: {
|
|
73
|
+
type: 'cat',
|
|
74
|
+
},
|
|
75
|
+
[yField]: adjustYMetaByZero(data, yField),
|
|
76
|
+
}
|
|
96
77
|
)
|
|
97
78
|
)(params);
|
|
98
79
|
}
|
|
@@ -199,10 +180,8 @@ export function adjust(params: Params<Pick<LineOptions, 'isStack'>>): Params<any
|
|
|
199
180
|
const { chart, options } = params;
|
|
200
181
|
const { isStack } = options;
|
|
201
182
|
|
|
202
|
-
const geometries = getAllGeometriesRecursively(chart);
|
|
203
|
-
|
|
204
183
|
if (isStack) {
|
|
205
|
-
each(geometries, (g: Geometry) => {
|
|
184
|
+
each(chart.geometries, (g: Geometry) => {
|
|
206
185
|
g.adjust('stack');
|
|
207
186
|
});
|
|
208
187
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { Plot } from '../../core/plot';
|
|
2
2
|
import { deepAssign } from '../../utils';
|
|
3
3
|
|
|
4
|
-
/** point 标注点视图 */
|
|
5
|
-
export const POINT_VIEW_ID = 'point-view';
|
|
6
|
-
|
|
7
4
|
/**
|
|
8
5
|
* 折线图默认配置项
|
|
9
6
|
*/
|
|
10
7
|
export const DEFAULT_OPTIONS = deepAssign({}, Plot.getDefaultOptions(), {
|
|
11
|
-
syncViewPadding: true,
|
|
12
8
|
tooltip: {
|
|
13
9
|
shared: true,
|
|
14
10
|
showMarkers: true,
|
package/src/plots/line/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { isNil } from '@antv/util';
|
|
2
1
|
import { Plot } from '../../core/plot';
|
|
3
2
|
import { Adaptor } from '../../core/adaptor';
|
|
4
|
-
import { findViewById } from '../../utils';
|
|
5
3
|
import { LineOptions } from './types';
|
|
6
4
|
import { adaptor, meta } from './adaptor';
|
|
7
|
-
import { DEFAULT_OPTIONS
|
|
5
|
+
import { DEFAULT_OPTIONS } from './constants';
|
|
8
6
|
import './interactions';
|
|
9
7
|
|
|
10
8
|
export type { LineOptions };
|
|
@@ -28,13 +26,8 @@ export class Line extends Plot<LineOptions> {
|
|
|
28
26
|
public changeData(data: LineOptions['data']) {
|
|
29
27
|
this.updateOption({ data });
|
|
30
28
|
const { chart, options } = this;
|
|
31
|
-
const { yField } = options;
|
|
32
29
|
meta({ chart, options });
|
|
33
30
|
this.chart.changeData(data);
|
|
34
|
-
const pointView = findViewById(this.chart, POINT_VIEW_ID);
|
|
35
|
-
if (pointView) {
|
|
36
|
-
pointView.changeData(data.filter((d) => !isNil(d[yField])));
|
|
37
|
-
}
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { each, findIndex } from '@antv/util';
|
|
2
|
-
import { InteractionAction, View } from '@antv/g2';
|
|
3
|
-
import { findGeometry } from '../../../utils';
|
|
2
|
+
import { InteractionAction, View, Geometry } from '@antv/g2';
|
|
4
3
|
|
|
5
4
|
export class MarkerActiveAction extends InteractionAction {
|
|
6
5
|
public active() {
|
|
@@ -9,24 +8,24 @@ export class MarkerActiveAction extends InteractionAction {
|
|
|
9
8
|
if (evt.data) {
|
|
10
9
|
// items: 数组对象,当前 tooltip 显示的每条内容
|
|
11
10
|
const { items } = evt.data;
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const points = view.geometries.filter((geom) => geom.type === 'point');
|
|
12
|
+
each(points, (point: Geometry) => {
|
|
14
13
|
each(point.elements, (element) => {
|
|
15
14
|
const active = findIndex(items, (item) => (item as any).data === element.data) !== -1;
|
|
16
15
|
element.setState('active', active);
|
|
17
16
|
});
|
|
18
|
-
}
|
|
17
|
+
});
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
public reset() {
|
|
23
22
|
const view = this.getView();
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
const points = view.geometries.filter((geom) => geom.type === 'point');
|
|
24
|
+
each(points, (point: Geometry) => {
|
|
26
25
|
each(point.elements, (element) => {
|
|
27
26
|
element.setState('active', false);
|
|
28
27
|
});
|
|
29
|
-
}
|
|
28
|
+
});
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
private getView(): View {
|
package/src/utils/geometry.ts
CHANGED
|
@@ -7,8 +7,7 @@ import { reduce, get } from '@antv/util';
|
|
|
7
7
|
* @param type
|
|
8
8
|
*/
|
|
9
9
|
export function findGeometry(view: View, type: string): Geometry {
|
|
10
|
-
|
|
11
|
-
return geometries.find((g: Geometry) => g.type === type);
|
|
10
|
+
return view.geometries.find((g: Geometry) => g.type === type);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
/**
|