@antv/g2plot 2.3.39 → 2.4.2

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 (116) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.en-US.md +0 -1
  3. package/README.md +0 -1
  4. package/dist/g2plot.min.js +18 -3
  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 +9 -1
  9. package/esm/index.js +9 -1
  10. package/esm/index.js.map +1 -1
  11. package/esm/plots/area/adaptor.js +15 -5
  12. package/esm/plots/area/adaptor.js.map +1 -1
  13. package/esm/plots/area/constants.d.ts +2 -0
  14. package/esm/plots/area/constants.js +2 -0
  15. package/esm/plots/area/constants.js.map +1 -1
  16. package/esm/plots/area/index.js +11 -4
  17. package/esm/plots/area/index.js.map +1 -1
  18. package/esm/plots/bar/adaptor.d.ts +7 -2
  19. package/esm/plots/bar/adaptor.js +67 -25
  20. package/esm/plots/bar/adaptor.js.map +1 -1
  21. package/esm/plots/bar/index.js +1 -2
  22. package/esm/plots/bar/index.js.map +1 -1
  23. package/esm/plots/line/adaptor.js +30 -15
  24. package/esm/plots/line/adaptor.js.map +1 -1
  25. package/esm/plots/line/constants.d.ts +2 -0
  26. package/esm/plots/line/constants.js +3 -0
  27. package/esm/plots/line/constants.js.map +1 -1
  28. package/esm/plots/line/index.js +8 -1
  29. package/esm/plots/line/index.js.map +1 -1
  30. package/esm/plots/line/interactions/marker-active.js +8 -11
  31. package/esm/plots/line/interactions/marker-active.js.map +1 -1
  32. package/esm/plots/sankey/helper.js +16 -2
  33. package/esm/plots/sankey/helper.js.map +1 -1
  34. package/esm/plots/sankey/types.d.ts +51 -8
  35. package/esm/plots/sankey/types.js.map +1 -1
  36. package/esm/plots/sunburst/adaptor.js +1 -11
  37. package/esm/plots/sunburst/adaptor.js.map +1 -1
  38. package/esm/plots/sunburst/constant.js +1 -0
  39. package/esm/plots/sunburst/constant.js.map +1 -1
  40. package/esm/plots/sunburst/types.d.ts +1 -1
  41. package/esm/plots/sunburst/types.js.map +1 -1
  42. package/esm/plots/venn/types.d.ts +1 -1
  43. package/esm/plots/venn/types.js.map +1 -1
  44. package/esm/utils/data.js +2 -0
  45. package/esm/utils/data.js.map +1 -1
  46. package/esm/utils/geometry.js +2 -1
  47. package/esm/utils/geometry.js.map +1 -1
  48. package/lib/adaptor/conversion-tag.js +3 -3
  49. package/lib/adaptor/conversion-tag.js.map +1 -1
  50. package/lib/index.d.ts +9 -1
  51. package/lib/index.js +13 -5
  52. package/lib/index.js.map +1 -1
  53. package/lib/plots/area/adaptor.js +13 -3
  54. package/lib/plots/area/adaptor.js.map +1 -1
  55. package/lib/plots/area/constants.d.ts +2 -0
  56. package/lib/plots/area/constants.js +3 -1
  57. package/lib/plots/area/constants.js.map +1 -1
  58. package/lib/plots/area/index.js +10 -3
  59. package/lib/plots/area/index.js.map +1 -1
  60. package/lib/plots/bar/adaptor.d.ts +7 -2
  61. package/lib/plots/bar/adaptor.js +69 -26
  62. package/lib/plots/bar/adaptor.js.map +1 -1
  63. package/lib/plots/bar/index.js +1 -2
  64. package/lib/plots/bar/index.js.map +1 -1
  65. package/lib/plots/line/adaptor.js +29 -14
  66. package/lib/plots/line/adaptor.js.map +1 -1
  67. package/lib/plots/line/constants.d.ts +2 -0
  68. package/lib/plots/line/constants.js +4 -1
  69. package/lib/plots/line/constants.js.map +1 -1
  70. package/lib/plots/line/index.js +7 -0
  71. package/lib/plots/line/index.js.map +1 -1
  72. package/lib/plots/line/interactions/marker-active.js +8 -11
  73. package/lib/plots/line/interactions/marker-active.js.map +1 -1
  74. package/lib/plots/sankey/helper.js +16 -2
  75. package/lib/plots/sankey/helper.js.map +1 -1
  76. package/lib/plots/sankey/types.d.ts +51 -8
  77. package/lib/plots/sankey/types.js.map +1 -1
  78. package/lib/plots/sunburst/adaptor.js +1 -11
  79. package/lib/plots/sunburst/adaptor.js.map +1 -1
  80. package/lib/plots/sunburst/constant.js +1 -0
  81. package/lib/plots/sunburst/constant.js.map +1 -1
  82. package/lib/plots/sunburst/types.d.ts +1 -1
  83. package/lib/plots/sunburst/types.js.map +1 -1
  84. package/lib/plots/venn/types.d.ts +1 -1
  85. package/lib/plots/venn/types.js.map +1 -1
  86. package/lib/utils/data.js +2 -0
  87. package/lib/utils/data.js.map +1 -1
  88. package/lib/utils/geometry.js +2 -1
  89. package/lib/utils/geometry.js.map +1 -1
  90. package/package.json +8 -7
  91. package/src/adaptor/conversion-tag.ts +3 -3
  92. package/src/index.ts +9 -1
  93. package/src/plots/area/adaptor.ts +16 -5
  94. package/src/plots/area/constants.ts +3 -0
  95. package/src/plots/area/index.ts +10 -3
  96. package/src/plots/bar/adaptor.ts +94 -47
  97. package/src/plots/bar/index.ts +1 -2
  98. package/src/plots/line/adaptor.ts +35 -14
  99. package/src/plots/line/constants.ts +4 -0
  100. package/src/plots/line/index.ts +8 -1
  101. package/src/plots/line/interactions/marker-active.ts +9 -12
  102. package/src/plots/sankey/helper.ts +26 -9
  103. package/src/plots/sankey/types.ts +52 -8
  104. package/src/plots/sunburst/adaptor.ts +9 -13
  105. package/src/plots/sunburst/constant.ts +1 -0
  106. package/src/plots/sunburst/types.ts +1 -1
  107. package/src/plots/venn/types.ts +1 -1
  108. package/src/utils/data.ts +1 -0
  109. package/src/utils/geometry.ts +2 -1
  110. package/esm/plots/bar/utils.d.ts +0 -6
  111. package/esm/plots/bar/utils.js +0 -8
  112. package/esm/plots/bar/utils.js.map +0 -1
  113. package/lib/plots/bar/utils.d.ts +0 -6
  114. package/lib/plots/bar/utils.js +0 -12
  115. package/lib/plots/bar/utils.js.map +0 -1
  116. package/src/plots/bar/utils.ts +0 -9
@@ -1,9 +1,19 @@
1
1
  import { isRealNumber, pick } from '../../utils';
2
2
  import { transformDataToNodeLinkData } from '../../utils/data';
3
- import { sankeyLayout } from './layout';
3
+ import { Data } from '../../types';
4
+ import { sankeyLayout, SankeyLayoutInputData } from './layout';
4
5
  import { cutoffCircle } from './circle';
5
6
  import { SankeyOptions } from './types';
6
7
 
8
+ /**
9
+ * 是否是 node-link 类型的数据结构
10
+ * @param dataTyp
11
+ * @returns
12
+ */
13
+ function isNodeLink(dataType: string) {
14
+ return dataType === 'node-link';
15
+ }
16
+
7
17
  export function getNodeWidthRatio(nodeWidth: number, nodeWidthRatio: number, width: number) {
8
18
  return isRealNumber(nodeWidth) ? nodeWidth / width : nodeWidthRatio;
9
19
  }
@@ -20,6 +30,7 @@ export function getNodePaddingRatio(nodePadding: number, nodePaddingRatio: numbe
20
30
  */
21
31
  export function transformToViewsData(options: SankeyOptions, width: number, height: number) {
22
32
  const {
33
+ dataType,
23
34
  data,
24
35
  sourceField,
25
36
  targetField,
@@ -34,13 +45,19 @@ export function transformToViewsData(options: SankeyOptions, width: number, heig
34
45
  rawFields = [],
35
46
  } = options;
36
47
 
37
- const sankeyLayoutInputData = transformDataToNodeLinkData(
38
- cutoffCircle(data, sourceField, targetField),
39
- sourceField,
40
- targetField,
41
- weightField,
42
- rawFields
43
- );
48
+ let sankeyLayoutInputData: unknown;
49
+
50
+ if (!isNodeLink(dataType)) {
51
+ sankeyLayoutInputData = transformDataToNodeLinkData(
52
+ cutoffCircle(data as Data, sourceField, targetField),
53
+ sourceField,
54
+ targetField,
55
+ weightField,
56
+ rawFields
57
+ );
58
+ } else {
59
+ sankeyLayoutInputData = data;
60
+ }
44
61
 
45
62
  // 3. layout 之后的数据
46
63
  const { nodes, links } = sankeyLayout(
@@ -51,7 +68,7 @@ export function transformToViewsData(options: SankeyOptions, width: number, heig
51
68
  nodeSort,
52
69
  nodeDepth,
53
70
  },
54
- sankeyLayoutInputData
71
+ sankeyLayoutInputData as SankeyLayoutInputData
55
72
  );
56
73
 
57
74
  // 4. 生成绘图数据
@@ -1,20 +1,64 @@
1
1
  import { Data, Options, State, StyleAttr } from '../../types';
2
2
  import { NodeDepth, NodeSort } from './layout';
3
3
 
4
+ /**
5
+ * node-link 数据类型的结构
6
+ */
7
+ export type NodeLinkData = {
8
+ /**
9
+ * 节点数据
10
+ */
11
+ readonly nodes: {
12
+ /**
13
+ * id 唯一即可,一般可以直接等于 name
14
+ */
15
+ readonly id: string;
16
+ /**
17
+ * 节点的名称,用于 UI 上的现实
18
+ */
19
+ readonly name: string;
20
+ /**
21
+ * 节点的值,不传则节点大小有来源求和决定
22
+ */
23
+ readonly fixedValue?: number;
24
+ }[];
25
+ /**
26
+ *
27
+ */
28
+ readonly links: {
29
+ /**
30
+ * 来源节点在 nodes 中的 index
31
+ */
32
+ readonly source: number;
33
+ /**
34
+ * 目标节点在 nodes 中的 index
35
+ */
36
+ readonly target: number;
37
+ /**
38
+ * 边的值
39
+ */
40
+ readonly value: number;
41
+ }[];
42
+ };
43
+
4
44
  /** 配置类型定义 */
5
- export interface SankeyOptions extends Omit<Options, 'xField' | 'yField' | 'xAxis' | 'yAxis'> {
45
+ export interface SankeyOptions extends Omit<Options, 'data' | 'xField' | 'yField' | 'xAxis' | 'yAxis'> {
46
+ /**
47
+ * 数据集的类型,默认为 detail
48
+ */
49
+ readonly dataType?: 'node-link' | 'detail';
6
50
  /**
7
- * 来源字段
51
+ * 来源字段,dataType = 'node-link' 的时候,不用传
8
52
  */
9
- readonly sourceField: string;
53
+ readonly sourceField?: string;
10
54
  /**
11
- * 去向字段
55
+ * 去向字段,dataType = 'node-link' 的时候,不用传
12
56
  */
13
- readonly targetField: string;
57
+ readonly targetField?: string;
14
58
  /**
15
- * 权重字段
59
+ * 权重字段,dataType = 'node-link' 的时候,不用传
16
60
  */
17
- readonly weightField: string;
61
+ readonly weightField?: string;
18
62
  /**
19
63
  * 附加的 元字段
20
64
  */
@@ -22,7 +66,7 @@ export interface SankeyOptions extends Omit<Options, 'xField' | 'yField' | 'xAxi
22
66
  /**
23
67
  * 数据
24
68
  */
25
- readonly data: Data;
69
+ readonly data: Data | NodeLinkData;
26
70
  /**
27
71
  * 节点宽度的比如,参考画布的宽度,默认值为 0.008
28
72
  */
@@ -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]);
@@ -7,7 +7,8 @@ import { reduce, get } from '@antv/util';
7
7
  * @param type
8
8
  */
9
9
  export function findGeometry(view: View, type: string): Geometry {
10
- return view.geometries.find((g: Geometry) => g.type === type);
10
+ const geometries = getAllGeometriesRecursively(view);
11
+ return geometries.find((g: Geometry) => g.type === type);
11
12
  }
12
13
 
13
14
  /**
@@ -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
- }