@antv/g2plot 2.3.40 → 2.4.0
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 +27 -0
- package/README.en-US.md +0 -1
- package/README.md +0 -1
- package/dist/g2plot.min.js +4 -4
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/conversion-tag.js +3 -3
- package/esm/adaptor/conversion-tag.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/bar/adaptor.d.ts +7 -2
- package/esm/plots/bar/adaptor.js +72 -25
- package/esm/plots/bar/adaptor.js.map +1 -1
- package/esm/plots/bar/index.js +1 -2
- package/esm/plots/bar/index.js.map +1 -1
- package/esm/plots/sunburst/adaptor.js +1 -11
- package/esm/plots/sunburst/adaptor.js.map +1 -1
- package/esm/plots/sunburst/constant.js +1 -0
- package/esm/plots/sunburst/constant.js.map +1 -1
- package/esm/plots/sunburst/types.d.ts +1 -1
- package/esm/plots/sunburst/types.js.map +1 -1
- package/esm/plots/venn/types.d.ts +1 -1
- package/esm/plots/venn/types.js.map +1 -1
- package/esm/utils/data.js +2 -0
- package/esm/utils/data.js.map +1 -1
- package/lib/adaptor/conversion-tag.js +3 -3
- package/lib/adaptor/conversion-tag.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/bar/adaptor.d.ts +7 -2
- package/lib/plots/bar/adaptor.js +74 -26
- package/lib/plots/bar/adaptor.js.map +1 -1
- package/lib/plots/bar/index.js +1 -2
- package/lib/plots/bar/index.js.map +1 -1
- package/lib/plots/sunburst/adaptor.js +1 -11
- package/lib/plots/sunburst/adaptor.js.map +1 -1
- package/lib/plots/sunburst/constant.js +1 -0
- package/lib/plots/sunburst/constant.js.map +1 -1
- package/lib/plots/sunburst/types.d.ts +1 -1
- package/lib/plots/sunburst/types.js.map +1 -1
- package/lib/plots/venn/types.d.ts +1 -1
- package/lib/plots/venn/types.js.map +1 -1
- package/lib/utils/data.js +2 -0
- package/lib/utils/data.js.map +1 -1
- package/package.json +6 -5
- package/src/adaptor/conversion-tag.ts +3 -3
- package/src/index.ts +1 -1
- package/src/plots/bar/adaptor.ts +90 -47
- package/src/plots/bar/index.ts +1 -2
- package/src/plots/sunburst/adaptor.ts +9 -13
- package/src/plots/sunburst/constant.ts +1 -0
- package/src/plots/sunburst/types.ts +1 -1
- package/src/plots/venn/types.ts +1 -1
- package/src/utils/data.ts +1 -0
- package/esm/plots/bar/utils.d.ts +0 -6
- package/esm/plots/bar/utils.js +0 -8
- package/esm/plots/bar/utils.js.map +0 -1
- package/lib/plots/bar/utils.d.ts +0 -6
- package/lib/plots/bar/utils.js +0 -12
- package/lib/plots/bar/utils.js.map +0 -1
- package/src/plots/bar/utils.ts +0 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2plot",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "An
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "An interactive and responsive charting library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
7
7
|
"plot",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"start": "npm run site:clean && npm run site:develop",
|
|
28
28
|
"site:develop": "cross-env PORT=8080 gatsby develop --open -H 0.0.0.0",
|
|
29
|
-
"site:build": "NODE_OPTIONS
|
|
29
|
+
"site:build": "NODE_OPTIONS='--max_old_space_size=8192' npm run site:clean && gatsby build --prefix-paths",
|
|
30
30
|
"site:clean": "gatsby clean",
|
|
31
31
|
"site:deploy": "npm run build && npm run site:build && gh-pages -d public",
|
|
32
32
|
"fix": "eslint --ext .ts ./src ./__tests__ --fix && prettier --write ./src ./__tests__ && lint-md --fix ./examples ./docs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@antv/data-set": "^0.11.5",
|
|
69
|
-
"@antv/gatsby-theme-antv": "^1.1.
|
|
69
|
+
"@antv/gatsby-theme-antv": "^1.1.15",
|
|
70
70
|
"@babel/core": "^7.10.4",
|
|
71
71
|
"@babel/plugin-transform-runtime": "^7.11.5",
|
|
72
72
|
"@babel/preset-env": "^7.10.4",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"miz": "^1.0.1",
|
|
101
101
|
"npm-run-all": "^4.1.5",
|
|
102
102
|
"prettier": "^2.0.1",
|
|
103
|
+
"rc-for-plots": "^0.0.1",
|
|
103
104
|
"react": "^16.11.0",
|
|
104
105
|
"react-dom": "^16.11.0",
|
|
105
106
|
"react-i18next": "^11.7.0",
|
|
@@ -144,7 +145,7 @@
|
|
|
144
145
|
"limit-size": [
|
|
145
146
|
{
|
|
146
147
|
"path": "dist/g2plot.min.js",
|
|
147
|
-
"limit": "
|
|
148
|
+
"limit": "998 Kb"
|
|
148
149
|
},
|
|
149
150
|
{
|
|
150
151
|
"path": "dist/g2plot.min.js",
|
|
@@ -90,8 +90,8 @@ function renderArrowTag(config: TagRenderConfig, elemPrev: Element, elemNext: El
|
|
|
90
90
|
const { view, geometry, group, options, horizontal } = config;
|
|
91
91
|
const { offset, size, arrow } = options;
|
|
92
92
|
const coordinate = view.getCoordinate();
|
|
93
|
-
const pointPrev = parsePoints(coordinate, elemPrev)[
|
|
94
|
-
const pointNext = parsePoints(coordinate, elemNext)[
|
|
93
|
+
const pointPrev = parsePoints(coordinate, elemPrev)[3];
|
|
94
|
+
const pointNext = parsePoints(coordinate, elemNext)[0];
|
|
95
95
|
const totalHeight = pointNext.y - pointPrev.y;
|
|
96
96
|
const totalWidth = pointNext.x - pointPrev.x;
|
|
97
97
|
|
|
@@ -238,7 +238,7 @@ export function conversionTag<O extends OptionWithConversionTag & Options>(
|
|
|
238
238
|
horizontal,
|
|
239
239
|
options: getConversionTagOptionsWithDefaults(conversionTag, horizontal),
|
|
240
240
|
};
|
|
241
|
-
const elements =
|
|
241
|
+
const elements = interval.elements;
|
|
242
242
|
each(elements, (elem: Element, idx: number) => {
|
|
243
243
|
if (idx > 0) {
|
|
244
244
|
renderTag(config, elements[idx - 1], elem);
|
package/src/index.ts
CHANGED
package/src/plots/bar/adaptor.ts
CHANGED
|
@@ -1,31 +1,58 @@
|
|
|
1
1
|
import { Params } from '../../core/adaptor';
|
|
2
|
+
import { tooltip } from '../../adaptor/common';
|
|
3
|
+
import { deepAssign, flow } from '../../utils';
|
|
2
4
|
import { adaptor as columnAdaptor } from '../column/adaptor';
|
|
5
|
+
export { meta } from '../column/adaptor';
|
|
3
6
|
import { BarOptions } from './types';
|
|
4
|
-
import { transformBarData } from './utils';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 处理默认配置项
|
|
10
|
+
* 1. switch xField、 yField
|
|
11
|
+
* 2. switch xAxis、 yAxis and adjust axis.position configuration
|
|
12
|
+
*/
|
|
13
|
+
function defaultOptions(params: Params<BarOptions>): Params<BarOptions> {
|
|
14
|
+
const { options } = params;
|
|
15
|
+
const { xField, yField, xAxis, yAxis } = options;
|
|
16
|
+
|
|
17
|
+
const position = {
|
|
18
|
+
left: 'bottom',
|
|
19
|
+
right: 'top',
|
|
20
|
+
top: 'left',
|
|
21
|
+
bottom: 'right',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const verticalAxis =
|
|
25
|
+
yAxis !== false
|
|
26
|
+
? {
|
|
27
|
+
position: position[yAxis?.position || 'left'],
|
|
28
|
+
...yAxis,
|
|
29
|
+
}
|
|
30
|
+
: false;
|
|
31
|
+
const horizontalAxis =
|
|
32
|
+
xAxis !== false
|
|
33
|
+
? {
|
|
34
|
+
position: position[xAxis?.position || 'bottom'],
|
|
35
|
+
...xAxis,
|
|
36
|
+
}
|
|
37
|
+
: false;
|
|
38
|
+
|
|
39
|
+
return deepAssign({}, params, {
|
|
40
|
+
options: {
|
|
41
|
+
xField: yField,
|
|
42
|
+
yField: xField,
|
|
43
|
+
xAxis: verticalAxis,
|
|
44
|
+
yAxis: horizontalAxis,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
7
48
|
|
|
8
49
|
/**
|
|
9
|
-
*
|
|
50
|
+
* label 适配器
|
|
10
51
|
* @param params
|
|
11
52
|
*/
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
const {
|
|
15
|
-
xField,
|
|
16
|
-
yField,
|
|
17
|
-
xAxis,
|
|
18
|
-
yAxis,
|
|
19
|
-
barStyle,
|
|
20
|
-
barWidthRatio,
|
|
21
|
-
label,
|
|
22
|
-
data,
|
|
23
|
-
seriesField,
|
|
24
|
-
isStack,
|
|
25
|
-
minBarWidth,
|
|
26
|
-
maxBarWidth,
|
|
27
|
-
} = options;
|
|
28
|
-
|
|
53
|
+
function label(params: Params<BarOptions>): Params<BarOptions> {
|
|
54
|
+
const { options } = params;
|
|
55
|
+
const { label } = options;
|
|
29
56
|
// label of bar charts default position is left, if plot has label
|
|
30
57
|
if (label && !label.position) {
|
|
31
58
|
label.position = 'left';
|
|
@@ -40,59 +67,75 @@ export function adaptor(params: Params<BarOptions>) {
|
|
|
40
67
|
}
|
|
41
68
|
}
|
|
42
69
|
|
|
70
|
+
return deepAssign({}, params, { options: { label } });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* legend 适配器
|
|
75
|
+
* @param params
|
|
76
|
+
*/
|
|
77
|
+
function legend(params: Params<BarOptions>): Params<BarOptions> {
|
|
78
|
+
const { options } = params;
|
|
79
|
+
|
|
43
80
|
// 默认 legend 位置
|
|
81
|
+
const { seriesField, isStack } = options;
|
|
44
82
|
let { legend } = options;
|
|
45
83
|
if (seriesField) {
|
|
46
84
|
if (legend !== false) {
|
|
47
85
|
legend = {
|
|
48
86
|
position: isStack ? 'top-left' : 'right-top',
|
|
49
|
-
reversed: isStack ? false : true,
|
|
50
87
|
...(legend || {}),
|
|
51
88
|
};
|
|
52
89
|
}
|
|
53
90
|
} else {
|
|
54
91
|
legend = false;
|
|
55
92
|
}
|
|
56
|
-
// @ts-ignore 直接改值
|
|
57
|
-
params.options.legend = legend;
|
|
58
93
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (seriesField) {
|
|
62
|
-
if (tooltip !== false) {
|
|
63
|
-
tooltip = {
|
|
64
|
-
reversed: isStack ? false : true,
|
|
65
|
-
...(tooltip || {}),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// @ts-ignore 直接改值
|
|
70
|
-
params.options.tooltip = tooltip;
|
|
94
|
+
return deepAssign({}, params, { options: { legend } });
|
|
95
|
+
}
|
|
71
96
|
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
/**
|
|
98
|
+
* coordinate 适配器
|
|
99
|
+
* @param params
|
|
100
|
+
*/
|
|
101
|
+
function coordinate(params: Params<BarOptions>): Params<BarOptions> {
|
|
102
|
+
const { chart } = params;
|
|
103
|
+
// transpose column to bar 对角变换 & y 方向镜像变换
|
|
104
|
+
chart.coordinate({ actions: [['transpose'], ['reflect', 'y']] });
|
|
105
|
+
return params;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 柱形图适配器
|
|
110
|
+
* @param params
|
|
111
|
+
*/
|
|
112
|
+
export function geometry(params: Params<BarOptions>) {
|
|
113
|
+
const { chart, options } = params;
|
|
114
|
+
|
|
115
|
+
const { barStyle, barWidthRatio, minBarWidth, maxBarWidth, barBackground } = options;
|
|
74
116
|
|
|
75
117
|
return columnAdaptor(
|
|
76
118
|
{
|
|
77
119
|
chart,
|
|
78
120
|
options: {
|
|
79
121
|
...options,
|
|
80
|
-
label,
|
|
81
|
-
// switch xField and yField
|
|
82
|
-
xField: yField,
|
|
83
|
-
yField: xField,
|
|
84
|
-
xAxis: yAxis,
|
|
85
|
-
yAxis: xAxis,
|
|
86
122
|
// rename attrs as column
|
|
87
123
|
columnStyle: barStyle,
|
|
88
124
|
columnWidthRatio: barWidthRatio,
|
|
89
125
|
minColumnWidth: minBarWidth,
|
|
90
126
|
maxColumnWidth: maxBarWidth,
|
|
91
|
-
columnBackground:
|
|
92
|
-
// bar 调整数据顺序
|
|
93
|
-
data: transformBarData(data),
|
|
127
|
+
columnBackground: barBackground,
|
|
94
128
|
},
|
|
95
129
|
},
|
|
96
130
|
true
|
|
97
|
-
)
|
|
131
|
+
) as Params<BarOptions>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param chart
|
|
136
|
+
* @param options
|
|
137
|
+
*/
|
|
138
|
+
export function adaptor(params: Params<BarOptions>): Params<BarOptions> {
|
|
139
|
+
// flow 的方式处理所有的配置到 G2 API
|
|
140
|
+
return flow<Params<BarOptions>>(defaultOptions, label, legend, tooltip, coordinate, geometry)(params);
|
|
98
141
|
}
|
package/src/plots/bar/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { getDataWhetherPecentage } from '../../utils/transform/percent';
|
|
|
4
4
|
import { BarOptions } from './types';
|
|
5
5
|
import { adaptor, meta } from './adaptor';
|
|
6
6
|
import { DEFAULT_OPTIONS } from './constants';
|
|
7
|
-
import { transformBarData } from './utils';
|
|
8
7
|
|
|
9
8
|
export type { BarOptions };
|
|
10
9
|
|
|
@@ -32,7 +31,7 @@ export class Bar extends Plot<BarOptions> {
|
|
|
32
31
|
const { xField, yField, isPercent } = options;
|
|
33
32
|
const switchedFieldOptions = { ...options, xField: yField, yField: xField };
|
|
34
33
|
meta({ chart, options: switchedFieldOptions });
|
|
35
|
-
chart.changeData(getDataWhetherPecentage(
|
|
34
|
+
chart.changeData(getDataWhetherPecentage(data, xField, yField, xField, isPercent));
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
/**
|
|
@@ -2,7 +2,15 @@ import { isFunction, get, uniq } from '@antv/util';
|
|
|
2
2
|
import { Types } from '@antv/g2';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
4
|
import { polygon as polygonAdaptor } from '../../adaptor/geometries';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
interaction as baseInteraction,
|
|
7
|
+
animation,
|
|
8
|
+
theme,
|
|
9
|
+
annotation,
|
|
10
|
+
scale,
|
|
11
|
+
pattern,
|
|
12
|
+
legend,
|
|
13
|
+
} from '../../adaptor/common';
|
|
6
14
|
import { flow, findGeometry, transformLabel, deepAssign } from '../../utils';
|
|
7
15
|
import { getAdjustAppendPadding } from '../../utils/padding';
|
|
8
16
|
import { Datum } from '../../types';
|
|
@@ -63,18 +71,6 @@ export function axis(params: Params<SunburstOptions>): Params<SunburstOptions> {
|
|
|
63
71
|
return params;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
/**
|
|
67
|
-
* legend 配置(旭日图暂时不支持图例,后续需要支持的话,得自定义数据筛选)
|
|
68
|
-
* @param params
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
function legend(params: Params<SunburstOptions>): Params<SunburstOptions> {
|
|
72
|
-
const { chart } = params;
|
|
73
|
-
|
|
74
|
-
chart.legend(false);
|
|
75
|
-
return params;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
74
|
/**
|
|
79
75
|
* 数据标签
|
|
80
76
|
* @param params
|
|
@@ -2,7 +2,7 @@ import { ColorAttr, Options, StyleAttr } from '../../types';
|
|
|
2
2
|
import { DrillDownCfg } from '../../types/drill-down';
|
|
3
3
|
import { HierarchyOption } from '../../utils/hierarchy/types';
|
|
4
4
|
|
|
5
|
-
export interface SunburstOptions extends Omit<Options, 'data' | '
|
|
5
|
+
export interface SunburstOptions extends Omit<Options, 'data' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
|
|
6
6
|
/** 旭日图数据 */
|
|
7
7
|
readonly data: any;
|
|
8
8
|
/** 径向类型 */
|
package/src/plots/venn/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface VennOptions extends Options {
|
|
|
15
15
|
|
|
16
16
|
// 韦恩图 样式
|
|
17
17
|
/** color */
|
|
18
|
-
readonly color?: string | string[] | ((datum: Datum, defaultColor
|
|
18
|
+
readonly color?: string | string[] | ((datum: Datum, defaultColor?: string) => string);
|
|
19
19
|
/** 并集合的颜色混合方式, 可选项: 参考 https://gka.github.io/chroma.js/#chroma-blend, 默认: multiply */
|
|
20
20
|
readonly blendMode?: string;
|
|
21
21
|
/** point 样式 */
|
package/src/utils/data.ts
CHANGED
package/esm/plots/bar/utils.d.ts
DELETED
package/esm/plots/bar/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/bar/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAwB;IACvD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC","sourcesContent":["import { BarOptions } from '.';\n\n/**\n * 条形图数据需要进行反转\n * @param data\n */\nexport function transformBarData(data: BarOptions['data']): BarOptions['data'] {\n return data ? data.slice().reverse() : data;\n}\n"]}
|
package/lib/plots/bar/utils.d.ts
DELETED
package/lib/plots/bar/utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformBarData = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* 条形图数据需要进行反转
|
|
6
|
-
* @param data
|
|
7
|
-
*/
|
|
8
|
-
function transformBarData(data) {
|
|
9
|
-
return data ? data.slice().reverse() : data;
|
|
10
|
-
}
|
|
11
|
-
exports.transformBarData = transformBarData;
|
|
12
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/bar/utils.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,IAAwB;IACvD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AAFD,4CAEC","sourcesContent":["import { BarOptions } from '.';\n\n/**\n * 条形图数据需要进行反转\n * @param data\n */\nexport function transformBarData(data: BarOptions['data']): BarOptions['data'] {\n return data ? data.slice().reverse() : data;\n}\n"]}
|