@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.
Files changed (62) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.en-US.md +0 -1
  3. package/README.md +0 -1
  4. package/dist/g2plot.min.js +4 -4
  5. package/dist/g2plot.min.js.map +1 -1
  6. package/esm/adaptor/conversion-tag.js +3 -3
  7. package/esm/adaptor/conversion-tag.js.map +1 -1
  8. package/esm/index.d.ts +1 -1
  9. package/esm/index.js +1 -1
  10. package/esm/index.js.map +1 -1
  11. package/esm/plots/bar/adaptor.d.ts +7 -2
  12. package/esm/plots/bar/adaptor.js +72 -25
  13. package/esm/plots/bar/adaptor.js.map +1 -1
  14. package/esm/plots/bar/index.js +1 -2
  15. package/esm/plots/bar/index.js.map +1 -1
  16. package/esm/plots/sunburst/adaptor.js +1 -11
  17. package/esm/plots/sunburst/adaptor.js.map +1 -1
  18. package/esm/plots/sunburst/constant.js +1 -0
  19. package/esm/plots/sunburst/constant.js.map +1 -1
  20. package/esm/plots/sunburst/types.d.ts +1 -1
  21. package/esm/plots/sunburst/types.js.map +1 -1
  22. package/esm/plots/venn/types.d.ts +1 -1
  23. package/esm/plots/venn/types.js.map +1 -1
  24. package/esm/utils/data.js +2 -0
  25. package/esm/utils/data.js.map +1 -1
  26. package/lib/adaptor/conversion-tag.js +3 -3
  27. package/lib/adaptor/conversion-tag.js.map +1 -1
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +1 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib/plots/bar/adaptor.d.ts +7 -2
  32. package/lib/plots/bar/adaptor.js +74 -26
  33. package/lib/plots/bar/adaptor.js.map +1 -1
  34. package/lib/plots/bar/index.js +1 -2
  35. package/lib/plots/bar/index.js.map +1 -1
  36. package/lib/plots/sunburst/adaptor.js +1 -11
  37. package/lib/plots/sunburst/adaptor.js.map +1 -1
  38. package/lib/plots/sunburst/constant.js +1 -0
  39. package/lib/plots/sunburst/constant.js.map +1 -1
  40. package/lib/plots/sunburst/types.d.ts +1 -1
  41. package/lib/plots/sunburst/types.js.map +1 -1
  42. package/lib/plots/venn/types.d.ts +1 -1
  43. package/lib/plots/venn/types.js.map +1 -1
  44. package/lib/utils/data.js +2 -0
  45. package/lib/utils/data.js.map +1 -1
  46. package/package.json +6 -5
  47. package/src/adaptor/conversion-tag.ts +3 -3
  48. package/src/index.ts +1 -1
  49. package/src/plots/bar/adaptor.ts +90 -47
  50. package/src/plots/bar/index.ts +1 -2
  51. package/src/plots/sunburst/adaptor.ts +9 -13
  52. package/src/plots/sunburst/constant.ts +1 -0
  53. package/src/plots/sunburst/types.ts +1 -1
  54. package/src/plots/venn/types.ts +1 -1
  55. package/src/utils/data.ts +1 -0
  56. package/esm/plots/bar/utils.d.ts +0 -6
  57. package/esm/plots/bar/utils.js +0 -8
  58. package/esm/plots/bar/utils.js.map +0 -1
  59. package/lib/plots/bar/utils.d.ts +0 -6
  60. package/lib/plots/bar/utils.js +0 -12
  61. package/lib/plots/bar/utils.js.map +0 -1
  62. 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.3.40",
4
- "description": "An nteractive and responsive charting library",
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=--max_old_space_size=8192 npm run site:clean && gatsby build --prefix-paths",
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.8",
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": "995 Kb"
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)[horizontal ? 3 : 0];
94
- const pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];
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 = horizontal ? interval.elements : interval.elements.slice().reverse();
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
@@ -1,4 +1,4 @@
1
- export const version = '2.3.40';
1
+ export const version = '2.4.0';
2
2
 
3
3
  // G2 自定义能力透出
4
4
  import * as G2 from '@antv/g2';
@@ -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
- export { meta } from '../column/adaptor';
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
- export function adaptor(params: Params<BarOptions>) {
13
- const { chart, options } = params;
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
- // 默认 tooltip 配置
60
- let { tooltip } = options;
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
- // transpose column to bar
73
- chart.coordinate().transpose();
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: options.barBackground,
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
  }
@@ -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(transformBarData(data), xField, yField, xField, isPercent));
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 { interaction as baseInteraction, animation, theme, annotation, scale, pattern } from '../../adaptor/common';
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
@@ -41,6 +41,7 @@ export const DEFAULT_OPTIONS: Partial<SunburstOptions> = deepAssign({}, Plot.get
41
41
  offset: 20,
42
42
  showTitle: false,
43
43
  },
44
+ legend: false,
44
45
 
45
46
  // 样式设置
46
47
  sunburstStyle: {
@@ -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' | 'legend' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
5
+ export interface SunburstOptions extends Omit<Options, 'data' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
6
6
  /** 旭日图数据 */
7
7
  readonly data: any;
8
8
  /** 径向类型 */
@@ -15,7 +15,7 @@ export interface VennOptions extends Options {
15
15
 
16
16
  // 韦恩图 样式
17
17
  /** color */
18
- readonly color?: string | string[] | ((datum: Datum, defaultColor: string) => string);
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
@@ -10,6 +10,7 @@ import { pick } from './pick';
10
10
  * @param field
11
11
  */
12
12
  export function adjustYMetaByZero(data: Data, field: string): Meta {
13
+ if (!data) return {};
13
14
  // 过滤出数字数据
14
15
  const numberData = data.filter((datum: Datum) => {
15
16
  const v = get(datum, [field]);
@@ -1,6 +0,0 @@
1
- import { BarOptions } from '.';
2
- /**
3
- * 条形图数据需要进行反转
4
- * @param data
5
- */
6
- export declare function transformBarData(data: BarOptions['data']): BarOptions['data'];
@@ -1,8 +0,0 @@
1
- /**
2
- * 条形图数据需要进行反转
3
- * @param data
4
- */
5
- export function transformBarData(data) {
6
- return data ? data.slice().reverse() : data;
7
- }
8
- //# 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,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"]}
@@ -1,6 +0,0 @@
1
- import { BarOptions } from '.';
2
- /**
3
- * 条形图数据需要进行反转
4
- * @param data
5
- */
6
- export declare function transformBarData(data: BarOptions['data']): BarOptions['data'];
@@ -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"]}
@@ -1,9 +0,0 @@
1
- import { BarOptions } from '.';
2
-
3
- /**
4
- * 条形图数据需要进行反转
5
- * @param data
6
- */
7
- export function transformBarData(data: BarOptions['data']): BarOptions['data'] {
8
- return data ? data.slice().reverse() : data;
9
- }