@antv/g2plot 2.4.14 → 2.4.15
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 +6 -0
- package/dist/g2plot.min.js +4 -4
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/common.d.ts +10 -0
- package/esm/adaptor/common.js +25 -0
- package/esm/adaptor/common.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +4 -4
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/area/index.js +2 -2
- package/esm/plots/area/index.js.map +1 -1
- package/esm/plots/area/types.d.ts +6 -0
- package/esm/plots/area/types.js.map +1 -1
- package/esm/plots/bar/adaptor.js +3 -3
- package/esm/plots/bar/adaptor.js.map +1 -1
- package/esm/plots/bar/index.js +2 -2
- package/esm/plots/bar/index.js.map +1 -1
- package/esm/plots/column/adaptor.js +4 -4
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/column/index.js +2 -2
- package/esm/plots/column/index.js.map +1 -1
- package/esm/plots/column/types.d.ts +6 -0
- package/esm/plots/column/types.js.map +1 -1
- package/esm/plots/mix/utils.d.ts +18 -17
- package/esm/plots/mix/utils.js.map +1 -1
- package/esm/plots/pie/adaptor.js +1 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/types/coordinate.d.ts +13 -0
- package/esm/types/coordinate.js +1 -0
- package/esm/types/coordinate.js.map +1 -0
- package/esm/utils/transform/percent.d.ts +1 -1
- package/esm/utils/transform/percent.js +1 -1
- package/esm/utils/transform/percent.js.map +1 -1
- package/lib/adaptor/common.d.ts +10 -0
- package/lib/adaptor/common.js +27 -1
- package/lib/adaptor/common.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +2 -2
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/area/index.js +1 -1
- package/lib/plots/area/index.js.map +1 -1
- package/lib/plots/area/types.d.ts +6 -0
- package/lib/plots/area/types.js.map +1 -1
- package/lib/plots/bar/adaptor.js +3 -3
- package/lib/plots/bar/adaptor.js.map +1 -1
- package/lib/plots/bar/index.js +1 -1
- package/lib/plots/bar/index.js.map +1 -1
- package/lib/plots/column/adaptor.js +2 -2
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/column/index.js +1 -1
- package/lib/plots/column/index.js.map +1 -1
- package/lib/plots/column/types.d.ts +6 -0
- package/lib/plots/column/types.js.map +1 -1
- package/lib/plots/mix/utils.d.ts +18 -17
- package/lib/plots/mix/utils.js.map +1 -1
- package/lib/plots/pie/adaptor.js +1 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/types/coordinate.d.ts +13 -0
- package/lib/types/coordinate.js +3 -0
- package/lib/types/coordinate.js.map +1 -0
- package/lib/utils/transform/percent.d.ts +1 -1
- package/lib/utils/transform/percent.js +3 -3
- package/lib/utils/transform/percent.js.map +1 -1
- package/package.json +1 -1
- package/src/adaptor/common.ts +28 -1
- package/src/index.ts +1 -1
- package/src/plots/area/adaptor.ts +14 -3
- package/src/plots/area/index.ts +2 -2
- package/src/plots/area/types.ts +7 -0
- package/src/plots/bar/adaptor.ts +3 -3
- package/src/plots/bar/index.ts +2 -2
- package/src/plots/column/adaptor.ts +4 -2
- package/src/plots/column/index.ts +2 -2
- package/src/plots/column/types.ts +7 -0
- package/src/plots/mix/utils.ts +18 -17
- package/src/plots/pie/adaptor.ts +1 -1
- package/src/types/coordinate.ts +17 -0
- package/src/utils/transform/percent.ts +1 -1
package/package.json
CHANGED
package/src/adaptor/common.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Geometry } from '@antv/g2';
|
|
1
|
+
import { Geometry, Types } from '@antv/g2';
|
|
2
2
|
import { each, isNil, isObject } from '@antv/util';
|
|
3
3
|
import { Params } from '../core/adaptor';
|
|
4
4
|
import { Options } from '../types';
|
|
5
5
|
import { Interaction } from '../types/interaction';
|
|
6
|
+
import { Transformations } from '../types/coordinate';
|
|
6
7
|
import { Axis } from '../types/axis';
|
|
7
8
|
import { AXIS_META_CONFIG_KEYS } from '../constant';
|
|
8
9
|
import { pick, deepAssign } from '../utils';
|
|
@@ -207,4 +208,30 @@ export function limitInPlot(params: Params<Options>): Params<Options> {
|
|
|
207
208
|
return params;
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
/**
|
|
212
|
+
* 坐标系转换
|
|
213
|
+
*/
|
|
214
|
+
export function transformations(coordinateType: Types.CoordinateOption['type'] = 'rect') {
|
|
215
|
+
return (params: Params<Options & { coordinate: Transformations }>) => {
|
|
216
|
+
const { chart, options } = params;
|
|
217
|
+
const { coordinate } = options;
|
|
218
|
+
|
|
219
|
+
const actions: Types.CoordinateActions[] = Array.from(coordinate || [])
|
|
220
|
+
.map((cfg) => {
|
|
221
|
+
if (cfg.type === 'reflectX') return ['reflect', 'x'] as Types.CoordinateActions;
|
|
222
|
+
if (cfg.type === 'reflectY') return ['reflect', 'y'] as Types.CoordinateActions;
|
|
223
|
+
if (cfg.type === 'transpose') return ['transpose'] as Types.CoordinateActions;
|
|
224
|
+
|
|
225
|
+
return null;
|
|
226
|
+
})
|
|
227
|
+
.filter((d) => !!d);
|
|
228
|
+
|
|
229
|
+
if (actions.length !== 0) {
|
|
230
|
+
chart.coordinate({ type: coordinateType, actions });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return params;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
210
237
|
export { pattern } from './pattern';
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
2
|
import { each, omit } from '@antv/util';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
tooltip,
|
|
5
|
+
slider,
|
|
6
|
+
interaction,
|
|
7
|
+
animation,
|
|
8
|
+
theme,
|
|
9
|
+
annotation,
|
|
10
|
+
limitInPlot,
|
|
11
|
+
pattern,
|
|
12
|
+
transformations,
|
|
13
|
+
} from '../../adaptor/common';
|
|
4
14
|
import { findGeometry } from '../../utils';
|
|
5
15
|
import { Params } from '../../core/adaptor';
|
|
6
16
|
import { area, point, line } from '../../adaptor/geometries';
|
|
7
17
|
import { flow, transformLabel, deepAssign } from '../../utils';
|
|
8
|
-
import {
|
|
18
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
9
19
|
import { Datum } from '../../types';
|
|
10
20
|
import { meta, legend, axis } from '../line/adaptor';
|
|
11
21
|
import { AreaOptions } from './types';
|
|
@@ -33,7 +43,7 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
|
|
|
33
43
|
} = options;
|
|
34
44
|
const pointState = pointMapping?.state;
|
|
35
45
|
|
|
36
|
-
const chartData =
|
|
46
|
+
const chartData = getDataWhetherPercentage(data, yField, xField, yField, isPercent);
|
|
37
47
|
chart.data(chartData);
|
|
38
48
|
// 百分比堆积图,默认会给一个 % 格式化逻辑, 用户可自定义
|
|
39
49
|
const tooltipOptions = isPercent
|
|
@@ -149,6 +159,7 @@ export function adaptor(params: Params<AreaOptions>) {
|
|
|
149
159
|
return flow(
|
|
150
160
|
theme,
|
|
151
161
|
pattern('areaStyle'),
|
|
162
|
+
transformations('rect'),
|
|
152
163
|
geometry,
|
|
153
164
|
meta,
|
|
154
165
|
adjust,
|
package/src/plots/area/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plot } from '../../core/plot';
|
|
2
2
|
import { Adaptor } from '../../core/adaptor';
|
|
3
|
-
import {
|
|
3
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
4
4
|
import { AreaOptions } from './types';
|
|
5
5
|
import { adaptor, meta } from './adaptor';
|
|
6
6
|
import { DEFAULT_OPTIONS } from './constants';
|
|
@@ -35,7 +35,7 @@ export class Area extends Plot<AreaOptions> {
|
|
|
35
35
|
const { isPercent, xField, yField } = this.options;
|
|
36
36
|
const { chart, options } = this;
|
|
37
37
|
meta({ chart, options });
|
|
38
|
-
this.chart.changeData(
|
|
38
|
+
this.chart.changeData(getDataWhetherPercentage(data, yField, xField, yField, isPercent));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
package/src/plots/area/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GeometryOptions, LineGeometryOptions, PointGeometryOptions } from '../../adaptor/geometries';
|
|
2
2
|
import { Options, StyleAttr } from '../../types';
|
|
3
|
+
import { Transformations } from '../../types/coordinate';
|
|
3
4
|
|
|
4
5
|
/** 面积图的配置类型定义 */
|
|
5
6
|
export interface AreaOptions extends Options, Pick<GeometryOptions, 'customInfo'> {
|
|
@@ -48,4 +49,10 @@ export interface AreaOptions extends Options, Pick<GeometryOptions, 'customInfo'
|
|
|
48
49
|
* @default false
|
|
49
50
|
*/
|
|
50
51
|
readonly startOnZero?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @title 坐标转换
|
|
55
|
+
* @description 可以对坐标系进行转换,如: reflectX, reflectY, transpose 等
|
|
56
|
+
*/
|
|
57
|
+
readonly coordinate?: Transformations;
|
|
51
58
|
}
|
package/src/plots/bar/adaptor.ts
CHANGED
|
@@ -103,10 +103,10 @@ function legend(params: Params<BarOptions>): Params<BarOptions> {
|
|
|
103
103
|
* @param params
|
|
104
104
|
*/
|
|
105
105
|
function coordinate(params: Params<BarOptions>): Params<BarOptions> {
|
|
106
|
-
const { chart } = params;
|
|
107
106
|
// transpose column to bar 对角变换 & y 方向镜像变换
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const { options } = params;
|
|
108
|
+
const coordinateOptions = [{ type: 'transpose' }, { type: 'reflectY' }].concat(options.coordinate || []);
|
|
109
|
+
return deepAssign({}, params, { options: { coordinate: coordinateOptions } });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
package/src/plots/bar/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plot } from '../../core/plot';
|
|
2
2
|
import { Adaptor } from '../../core/adaptor';
|
|
3
|
-
import {
|
|
3
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
4
4
|
import { BarOptions } from './types';
|
|
5
5
|
import { adaptor, meta } from './adaptor';
|
|
6
6
|
import { DEFAULT_OPTIONS } from './constants';
|
|
@@ -31,7 +31,7 @@ export class Bar extends Plot<BarOptions> {
|
|
|
31
31
|
const { xField, yField, isPercent } = options;
|
|
32
32
|
const switchedFieldOptions = { ...options, xField: yField, yField: xField };
|
|
33
33
|
meta({ chart, options: switchedFieldOptions });
|
|
34
|
-
chart.changeData(
|
|
34
|
+
chart.changeData(getDataWhetherPercentage(data, xField, yField, xField, isPercent));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
scrollbar,
|
|
12
12
|
limitInPlot,
|
|
13
13
|
state,
|
|
14
|
+
transformations,
|
|
14
15
|
} from '../../adaptor/common';
|
|
15
16
|
import { conversionTag } from '../../adaptor/conversion-tag';
|
|
16
17
|
import { connectedArea } from '../../adaptor/connected-area';
|
|
@@ -18,7 +19,7 @@ import { interval } from '../../adaptor/geometries';
|
|
|
18
19
|
import { pattern } from '../../adaptor/pattern';
|
|
19
20
|
import { brushInteraction } from '../../adaptor/brush';
|
|
20
21
|
import { flow, transformLabel, deepAssign, findGeometry, adjustYMetaByZero, pick } from '../../utils';
|
|
21
|
-
import {
|
|
22
|
+
import { getDataWhetherPercentage, getDeepPercent } from '../../utils/transform/percent';
|
|
22
23
|
import { Datum } from '../../types';
|
|
23
24
|
import { ColumnOptions } from './types';
|
|
24
25
|
|
|
@@ -73,7 +74,7 @@ function geometry(params: Params<ColumnOptions>): Params<ColumnOptions> {
|
|
|
73
74
|
const percentData =
|
|
74
75
|
isPercent && isGroup && isStack
|
|
75
76
|
? getDeepPercent(data, yField, [xField, groupField], yField)
|
|
76
|
-
:
|
|
77
|
+
: getDataWhetherPercentage(data, yField, xField, yField, isPercent);
|
|
77
78
|
|
|
78
79
|
let chartData = [];
|
|
79
80
|
|
|
@@ -292,6 +293,7 @@ export function adaptor(params: Params<ColumnOptions>, isBar = false) {
|
|
|
292
293
|
theme, // theme 需要在 geometry 之前
|
|
293
294
|
pattern('columnStyle'),
|
|
294
295
|
state,
|
|
296
|
+
transformations('rect'),
|
|
295
297
|
geometry,
|
|
296
298
|
meta,
|
|
297
299
|
axis,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plot } from '../../core/plot';
|
|
2
2
|
import { Adaptor } from '../../core/adaptor';
|
|
3
|
-
import {
|
|
3
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
4
4
|
import { ColumnOptions } from './types';
|
|
5
5
|
import { adaptor, meta } from './adaptor';
|
|
6
6
|
import { DEFAULT_OPTIONS } from './constants';
|
|
@@ -30,7 +30,7 @@ export class Column extends Plot<ColumnOptions> {
|
|
|
30
30
|
const { yField, xField, isPercent } = this.options;
|
|
31
31
|
const { chart, options } = this;
|
|
32
32
|
meta({ chart, options });
|
|
33
|
-
this.chart.changeData(
|
|
33
|
+
this.chart.changeData(getDataWhetherPercentage(data, yField, xField, yField, isPercent));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -3,6 +3,7 @@ import { BrushCfg, Options, StyleAttr } from '../../types';
|
|
|
3
3
|
import { OptionWithConversionTag } from '../../adaptor/conversion-tag';
|
|
4
4
|
import { OptionWithConnectedArea } from '../../adaptor/connected-area';
|
|
5
5
|
import { IntervalGeometryOptions } from '../../adaptor/geometries/interval';
|
|
6
|
+
import { Transformations } from '../../types/coordinate';
|
|
6
7
|
|
|
7
8
|
type PartialIntervalGeometryOptions = Pick<IntervalGeometryOptions, 'dodgePadding' | 'intervalPadding'>;
|
|
8
9
|
|
|
@@ -84,4 +85,10 @@ export interface ColumnOptions
|
|
|
84
85
|
* @description 开启下钻交互,以及进行下钻交互的配置
|
|
85
86
|
*/
|
|
86
87
|
readonly brush?: BrushCfg;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @title 坐标转换
|
|
91
|
+
* @description 可以对坐标系进行转换,如: reflectX, reflectY, transpose 等
|
|
92
|
+
*/
|
|
93
|
+
readonly coordinate?: Transformations;
|
|
87
94
|
}
|
package/src/plots/mix/utils.ts
CHANGED
|
@@ -31,11 +31,12 @@ import { Scatter, ScatterOptions } from '../scatter';
|
|
|
31
31
|
import { Histogram, HistogramOptions } from '../histogram';
|
|
32
32
|
import { Funnel, FunnelOptions } from '../funnel';
|
|
33
33
|
import { Stock, StockOptions } from '../stock';
|
|
34
|
+
import { Options } from '../../types';
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
|
-
* 移除 options 中的 width、height
|
|
37
|
+
* 移除 options 中的 width、height 设置, 将 options 的 data 设置为可选
|
|
37
38
|
*/
|
|
38
|
-
type
|
|
39
|
+
type PlotOptions<T> = Omit<T, 'width' | 'height' | 'data'> & Partial<Pick<T extends Options ? T : never, 'data'>>;
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* multi-view 中的支持的 plots 类型(带 options 定义)
|
|
@@ -49,63 +50,63 @@ export type IPlotTypes =
|
|
|
49
50
|
/**
|
|
50
51
|
* plot 配置
|
|
51
52
|
*/
|
|
52
|
-
readonly options:
|
|
53
|
+
readonly options: PlotOptions<LineOptions>;
|
|
53
54
|
}
|
|
54
55
|
| {
|
|
55
56
|
readonly type: 'pie';
|
|
56
|
-
readonly options:
|
|
57
|
+
readonly options: PlotOptions<PieOptions>;
|
|
57
58
|
}
|
|
58
59
|
| {
|
|
59
60
|
readonly type: 'bar';
|
|
60
|
-
readonly options:
|
|
61
|
+
readonly options: PlotOptions<BarOptions>;
|
|
61
62
|
}
|
|
62
63
|
| {
|
|
63
64
|
readonly type: 'column';
|
|
64
|
-
readonly options:
|
|
65
|
+
readonly options: PlotOptions<ColumnOptions>;
|
|
65
66
|
}
|
|
66
67
|
| {
|
|
67
68
|
readonly type: 'area';
|
|
68
|
-
readonly options:
|
|
69
|
+
readonly options: PlotOptions<AreaOptions>;
|
|
69
70
|
}
|
|
70
71
|
| {
|
|
71
72
|
readonly type: 'gauge';
|
|
72
|
-
readonly options:
|
|
73
|
+
readonly options: PlotOptions<GaugeOptions>;
|
|
73
74
|
}
|
|
74
75
|
| {
|
|
75
76
|
readonly type: 'tiny-line';
|
|
76
|
-
readonly options:
|
|
77
|
+
readonly options: PlotOptions<TinyLineOptions>;
|
|
77
78
|
}
|
|
78
79
|
| {
|
|
79
80
|
readonly type: 'tiny-area';
|
|
80
|
-
readonly options:
|
|
81
|
+
readonly options: PlotOptions<TinyAreaOptions>;
|
|
81
82
|
}
|
|
82
83
|
| {
|
|
83
84
|
readonly type: 'tiny-column';
|
|
84
|
-
readonly options:
|
|
85
|
+
readonly options: PlotOptions<TinyColumnOptions>;
|
|
85
86
|
}
|
|
86
87
|
| {
|
|
87
88
|
readonly type: 'ring-progress';
|
|
88
|
-
readonly options:
|
|
89
|
+
readonly options: PlotOptions<RingProgressOptions>;
|
|
89
90
|
}
|
|
90
91
|
| {
|
|
91
92
|
readonly type: 'progress';
|
|
92
|
-
readonly options:
|
|
93
|
+
readonly options: PlotOptions<ProgressOptions>;
|
|
93
94
|
}
|
|
94
95
|
| {
|
|
95
96
|
readonly type: 'histogram';
|
|
96
|
-
readonly options:
|
|
97
|
+
readonly options: PlotOptions<HistogramOptions>;
|
|
97
98
|
}
|
|
98
99
|
| {
|
|
99
100
|
readonly type: 'scatter';
|
|
100
|
-
readonly options:
|
|
101
|
+
readonly options: PlotOptions<ScatterOptions>;
|
|
101
102
|
}
|
|
102
103
|
| {
|
|
103
104
|
readonly type: 'funnel';
|
|
104
|
-
readonly options:
|
|
105
|
+
readonly options: PlotOptions<FunnelOptions>;
|
|
105
106
|
}
|
|
106
107
|
| {
|
|
107
108
|
readonly type: 'stock';
|
|
108
|
-
readonly options:
|
|
109
|
+
readonly options: PlotOptions<StockOptions>;
|
|
109
110
|
};
|
|
110
111
|
|
|
111
112
|
/**
|
package/src/plots/pie/adaptor.ts
CHANGED
|
@@ -138,7 +138,7 @@ function label(params: Params<PieOptions>): Params<PieOptions> {
|
|
|
138
138
|
const angleScale = chart.getScaleByField(angleField);
|
|
139
139
|
const percent = angleScale?.scale(value);
|
|
140
140
|
return isFunction(content)
|
|
141
|
-
? // append
|
|
141
|
+
? // append percent (number) to data, users can get origin data from `dataum._origin`
|
|
142
142
|
content({ ...data, percent }, dataum, index)
|
|
143
143
|
: isString(content)
|
|
144
144
|
? template(content as string, {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transformations of coordinate
|
|
3
|
+
*/
|
|
4
|
+
export type Transformations = Array<
|
|
5
|
+
| {
|
|
6
|
+
/** send (x, y) to (-x, y) */
|
|
7
|
+
type: 'reflectX';
|
|
8
|
+
}
|
|
9
|
+
| {
|
|
10
|
+
/** send (x, y) to (x, -y) */
|
|
11
|
+
type: 'reflectY';
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
/** send (x, y) to (y, x) */
|
|
15
|
+
type: 'transpose';
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
@@ -85,7 +85,7 @@ export function getDeepPercent(data: Record<string, any>[], measure: string, fie
|
|
|
85
85
|
* 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)
|
|
86
86
|
* @param isPercent 是否百分比
|
|
87
87
|
*/
|
|
88
|
-
export function
|
|
88
|
+
export function getDataWhetherPercentage(
|
|
89
89
|
data: Record<string, any>[],
|
|
90
90
|
yField: string,
|
|
91
91
|
groupField: string,
|