@antv/g2plot 2.4.14 → 2.4.17
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/dist/g2plot.min.js +3 -17
- 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/adaptor/geometries/area.js +2 -1
- package/esm/adaptor/geometries/area.js.map +1 -1
- package/esm/adaptor/geometries/edge.js +2 -1
- package/esm/adaptor/geometries/edge.js.map +1 -1
- package/esm/adaptor/geometries/interval.js +9 -2
- package/esm/adaptor/geometries/interval.js.map +1 -1
- package/esm/adaptor/geometries/line.js +2 -2
- package/esm/adaptor/geometries/line.js.map +1 -1
- package/esm/adaptor/geometries/point.js +2 -1
- package/esm/adaptor/geometries/point.js.map +1 -1
- package/esm/adaptor/geometries/polygon.js +2 -1
- package/esm/adaptor/geometries/polygon.js.map +1 -1
- package/esm/adaptor/geometries/schema.js +2 -1
- package/esm/adaptor/geometries/schema.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +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/plots/sankey/layout.js +14 -3
- package/esm/plots/sankey/layout.js.map +1 -1
- package/esm/types/common.d.ts +6 -0
- package/esm/types/common.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/adaptor/geometries/area.js +2 -1
- package/lib/adaptor/geometries/area.js.map +1 -1
- package/lib/adaptor/geometries/edge.js +2 -1
- package/lib/adaptor/geometries/edge.js.map +1 -1
- package/lib/adaptor/geometries/interval.js +9 -2
- package/lib/adaptor/geometries/interval.js.map +1 -1
- package/lib/adaptor/geometries/line.js +2 -2
- package/lib/adaptor/geometries/line.js.map +1 -1
- package/lib/adaptor/geometries/point.js +2 -1
- package/lib/adaptor/geometries/point.js.map +1 -1
- package/lib/adaptor/geometries/polygon.js +2 -1
- package/lib/adaptor/geometries/polygon.js.map +1 -1
- package/lib/adaptor/geometries/schema.js +2 -1
- package/lib/adaptor/geometries/schema.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +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/plots/sankey/layout.js +14 -3
- package/lib/plots/sankey/layout.js.map +1 -1
- package/lib/types/common.d.ts +6 -0
- package/lib/types/common.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 +2 -1
- package/src/adaptor/common.ts +28 -1
- package/src/adaptor/geometries/area.ts +2 -1
- package/src/adaptor/geometries/edge.ts +2 -1
- package/src/adaptor/geometries/interval.ts +9 -1
- package/src/adaptor/geometries/line.ts +2 -2
- package/src/adaptor/geometries/point.ts +2 -1
- package/src/adaptor/geometries/polygon.ts +2 -1
- package/src/adaptor/geometries/schema.ts +2 -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/plots/sankey/layout.ts +34 -21
- package/src/types/common.ts +6 -0
- package/src/types/coordinate.ts +17 -0
- package/src/utils/transform/percent.ts +1 -1
- package/CHANGELOG.md +0 -1515
|
@@ -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, {
|
|
@@ -150,25 +150,38 @@ export function sankeyLayout(
|
|
|
150
150
|
const layoutData: SankeyLayoutOutputData = sankeyProcessor(data);
|
|
151
151
|
|
|
152
152
|
// post process (x, y), etc.
|
|
153
|
-
layoutData.nodes
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
153
|
+
const nodes = layoutData.nodes
|
|
154
|
+
.map((node) => {
|
|
155
|
+
const { x0, x1, y0, y1 } = node;
|
|
156
|
+
/* points
|
|
157
|
+
* 3---2
|
|
158
|
+
* | |
|
|
159
|
+
* 0---1
|
|
160
|
+
*/
|
|
161
|
+
node.x = [x0, x1, x1, x0];
|
|
162
|
+
node.y = [y0, y0, y1, y1];
|
|
163
|
+
|
|
164
|
+
return node;
|
|
165
|
+
})
|
|
166
|
+
.filter((node) => {
|
|
167
|
+
return node.name !== null;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const links = layoutData.links
|
|
171
|
+
.map((edge) => {
|
|
172
|
+
const { source, target } = edge;
|
|
173
|
+
const sx = source.x1;
|
|
174
|
+
const tx = target.x0;
|
|
175
|
+
edge.x = [sx, sx, tx, tx];
|
|
176
|
+
const offset = edge.width / 2;
|
|
177
|
+
edge.y = [edge.y0 + offset, edge.y0 - offset, edge.y1 + offset, edge.y1 - offset];
|
|
178
|
+
|
|
179
|
+
return edge;
|
|
180
|
+
})
|
|
181
|
+
.filter((edge) => {
|
|
182
|
+
const { source, target } = edge;
|
|
183
|
+
return source.name !== null && target.name !== null;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return { nodes, links };
|
|
174
187
|
}
|
package/src/types/common.ts
CHANGED
|
@@ -147,6 +147,12 @@ export type Options = {
|
|
|
147
147
|
* @default false
|
|
148
148
|
*/
|
|
149
149
|
readonly supportCSSTransform?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* @title 是否开启 label 延迟渲染
|
|
152
|
+
* @description 开启后 label 渲染会在浏览器空闲时机执行。可制定具体 number 数值,来限定 timeout 时间 (建议开启时,指定 timeout 时间)
|
|
153
|
+
* @default false
|
|
154
|
+
*/
|
|
155
|
+
readonly useDeferredLabel?: boolean | number;
|
|
150
156
|
|
|
151
157
|
/**
|
|
152
158
|
* @title 数据
|
|
@@ -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,
|