@antv/g2plot 2.3.37 → 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 (166) hide show
  1. package/CHANGELOG.md +73 -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/adaptor/geometries/base.d.ts +2 -0
  9. package/esm/adaptor/geometries/base.js +7 -1
  10. package/esm/adaptor/geometries/base.js.map +1 -1
  11. package/esm/adaptor/geometries/index.d.ts +1 -0
  12. package/esm/adaptor/geometries/index.js.map +1 -1
  13. package/esm/index.d.ts +1 -1
  14. package/esm/index.js +1 -1
  15. package/esm/index.js.map +1 -1
  16. package/esm/plots/area/adaptor.js +5 -2
  17. package/esm/plots/area/adaptor.js.map +1 -1
  18. package/esm/plots/area/types.d.ts +2 -3
  19. package/esm/plots/area/types.js.map +1 -1
  20. package/esm/plots/bar/adaptor.d.ts +7 -2
  21. package/esm/plots/bar/adaptor.js +72 -25
  22. package/esm/plots/bar/adaptor.js.map +1 -1
  23. package/esm/plots/bar/index.js +1 -2
  24. package/esm/plots/bar/index.js.map +1 -1
  25. package/esm/plots/bidirectional-bar/adaptor.js +45 -9
  26. package/esm/plots/bidirectional-bar/adaptor.js.map +1 -1
  27. package/esm/plots/bidirectional-bar/index.d.ts +2 -0
  28. package/esm/plots/bidirectional-bar/index.js +2 -0
  29. package/esm/plots/bidirectional-bar/index.js.map +1 -1
  30. package/esm/plots/column/adaptor.js +2 -1
  31. package/esm/plots/column/adaptor.js.map +1 -1
  32. package/esm/plots/column/types.d.ts +3 -0
  33. package/esm/plots/column/types.js.map +1 -1
  34. package/esm/plots/heatmap/adaptor.js +23 -1
  35. package/esm/plots/heatmap/adaptor.js.map +1 -1
  36. package/esm/plots/heatmap/types.d.ts +4 -2
  37. package/esm/plots/heatmap/types.js.map +1 -1
  38. package/esm/plots/line/adaptor.js +25 -4
  39. package/esm/plots/line/adaptor.js.map +1 -1
  40. package/esm/plots/line/types.d.ts +6 -2
  41. package/esm/plots/line/types.js.map +1 -1
  42. package/esm/plots/pie/interactions/{pie-legend-action.d.ts → actions/legend-active.d.ts} +0 -0
  43. package/esm/plots/pie/interactions/{pie-legend-action.js → actions/legend-active.js} +2 -2
  44. package/esm/plots/pie/interactions/actions/legend-active.js.map +1 -0
  45. package/esm/plots/pie/interactions/{pie-statistic-action.d.ts → actions/statistic-active.d.ts} +1 -1
  46. package/esm/plots/pie/interactions/{pie-statistic-action.js → actions/statistic-active.js} +8 -2
  47. package/esm/plots/pie/interactions/actions/statistic-active.js.map +1 -0
  48. package/esm/plots/pie/interactions/index.js +2 -2
  49. package/esm/plots/pie/interactions/index.js.map +1 -1
  50. package/esm/plots/pie/interactions/util.d.ts +7 -0
  51. package/esm/plots/pie/interactions/util.js +15 -0
  52. package/esm/plots/pie/interactions/util.js.map +1 -0
  53. package/esm/plots/sankey/helper.js +16 -2
  54. package/esm/plots/sankey/helper.js.map +1 -1
  55. package/esm/plots/sankey/types.d.ts +51 -8
  56. package/esm/plots/sankey/types.js.map +1 -1
  57. package/esm/plots/sunburst/adaptor.js +1 -11
  58. package/esm/plots/sunburst/adaptor.js.map +1 -1
  59. package/esm/plots/sunburst/constant.js +1 -0
  60. package/esm/plots/sunburst/constant.js.map +1 -1
  61. package/esm/plots/sunburst/types.d.ts +1 -1
  62. package/esm/plots/sunburst/types.js.map +1 -1
  63. package/esm/plots/venn/types.d.ts +1 -1
  64. package/esm/plots/venn/types.js.map +1 -1
  65. package/esm/utils/data.js +2 -0
  66. package/esm/utils/data.js.map +1 -1
  67. package/lib/adaptor/conversion-tag.js +3 -3
  68. package/lib/adaptor/conversion-tag.js.map +1 -1
  69. package/lib/adaptor/geometries/base.d.ts +2 -0
  70. package/lib/adaptor/geometries/base.js +7 -1
  71. package/lib/adaptor/geometries/base.js.map +1 -1
  72. package/lib/adaptor/geometries/index.d.ts +1 -0
  73. package/lib/adaptor/geometries/index.js.map +1 -1
  74. package/lib/index.d.ts +1 -1
  75. package/lib/index.js +1 -1
  76. package/lib/index.js.map +1 -1
  77. package/lib/plots/area/adaptor.js +5 -2
  78. package/lib/plots/area/adaptor.js.map +1 -1
  79. package/lib/plots/area/types.d.ts +2 -3
  80. package/lib/plots/area/types.js.map +1 -1
  81. package/lib/plots/bar/adaptor.d.ts +7 -2
  82. package/lib/plots/bar/adaptor.js +74 -26
  83. package/lib/plots/bar/adaptor.js.map +1 -1
  84. package/lib/plots/bar/index.js +1 -2
  85. package/lib/plots/bar/index.js.map +1 -1
  86. package/lib/plots/bidirectional-bar/adaptor.js +45 -9
  87. package/lib/plots/bidirectional-bar/adaptor.js.map +1 -1
  88. package/lib/plots/bidirectional-bar/index.d.ts +2 -0
  89. package/lib/plots/bidirectional-bar/index.js +2 -0
  90. package/lib/plots/bidirectional-bar/index.js.map +1 -1
  91. package/lib/plots/column/adaptor.js +2 -1
  92. package/lib/plots/column/adaptor.js.map +1 -1
  93. package/lib/plots/column/types.d.ts +3 -0
  94. package/lib/plots/column/types.js.map +1 -1
  95. package/lib/plots/heatmap/adaptor.js +23 -1
  96. package/lib/plots/heatmap/adaptor.js.map +1 -1
  97. package/lib/plots/heatmap/types.d.ts +4 -2
  98. package/lib/plots/heatmap/types.js.map +1 -1
  99. package/lib/plots/line/adaptor.js +23 -2
  100. package/lib/plots/line/adaptor.js.map +1 -1
  101. package/lib/plots/line/types.d.ts +6 -2
  102. package/lib/plots/line/types.js.map +1 -1
  103. package/lib/plots/pie/interactions/{pie-legend-action.d.ts → actions/legend-active.d.ts} +0 -0
  104. package/lib/plots/pie/interactions/{pie-legend-action.js → actions/legend-active.js} +2 -2
  105. package/lib/plots/pie/interactions/actions/legend-active.js.map +1 -0
  106. package/lib/plots/pie/interactions/{pie-statistic-action.d.ts → actions/statistic-active.d.ts} +1 -1
  107. package/lib/plots/pie/interactions/{pie-statistic-action.js → actions/statistic-active.js} +8 -2
  108. package/lib/plots/pie/interactions/actions/statistic-active.js.map +1 -0
  109. package/lib/plots/pie/interactions/index.js +4 -4
  110. package/lib/plots/pie/interactions/index.js.map +1 -1
  111. package/lib/plots/pie/interactions/util.d.ts +7 -0
  112. package/lib/plots/pie/interactions/util.js +19 -0
  113. package/lib/plots/pie/interactions/util.js.map +1 -0
  114. package/lib/plots/sankey/helper.js +16 -2
  115. package/lib/plots/sankey/helper.js.map +1 -1
  116. package/lib/plots/sankey/types.d.ts +51 -8
  117. package/lib/plots/sankey/types.js.map +1 -1
  118. package/lib/plots/sunburst/adaptor.js +1 -11
  119. package/lib/plots/sunburst/adaptor.js.map +1 -1
  120. package/lib/plots/sunburst/constant.js +1 -0
  121. package/lib/plots/sunburst/constant.js.map +1 -1
  122. package/lib/plots/sunburst/types.d.ts +1 -1
  123. package/lib/plots/sunburst/types.js.map +1 -1
  124. package/lib/plots/venn/types.d.ts +1 -1
  125. package/lib/plots/venn/types.js.map +1 -1
  126. package/lib/utils/data.js +2 -0
  127. package/lib/utils/data.js.map +1 -1
  128. package/package.json +8 -7
  129. package/src/adaptor/conversion-tag.ts +3 -3
  130. package/src/adaptor/geometries/base.ts +23 -2
  131. package/src/adaptor/geometries/index.ts +1 -0
  132. package/src/index.ts +1 -1
  133. package/src/plots/area/adaptor.ts +5 -2
  134. package/src/plots/area/types.ts +2 -3
  135. package/src/plots/bar/adaptor.ts +90 -47
  136. package/src/plots/bar/index.ts +1 -2
  137. package/src/plots/bidirectional-bar/adaptor.ts +35 -7
  138. package/src/plots/bidirectional-bar/index.ts +3 -0
  139. package/src/plots/column/adaptor.ts +2 -0
  140. package/src/plots/column/types.ts +5 -0
  141. package/src/plots/heatmap/adaptor.ts +29 -11
  142. package/src/plots/heatmap/types.ts +6 -2
  143. package/src/plots/line/adaptor.ts +31 -3
  144. package/src/plots/line/types.ts +13 -2
  145. package/src/plots/pie/interactions/{pie-legend-action.ts → actions/legend-active.ts} +1 -1
  146. package/src/plots/pie/interactions/{pie-statistic-action.ts → actions/statistic-active.ts} +11 -3
  147. package/src/plots/pie/interactions/index.ts +2 -2
  148. package/src/plots/pie/interactions/util.ts +16 -0
  149. package/src/plots/sankey/helper.ts +26 -9
  150. package/src/plots/sankey/types.ts +52 -8
  151. package/src/plots/sunburst/adaptor.ts +9 -13
  152. package/src/plots/sunburst/constant.ts +1 -0
  153. package/src/plots/sunburst/types.ts +1 -1
  154. package/src/plots/venn/types.ts +1 -1
  155. package/src/utils/data.ts +1 -0
  156. package/esm/plots/bar/utils.d.ts +0 -6
  157. package/esm/plots/bar/utils.js +0 -8
  158. package/esm/plots/bar/utils.js.map +0 -1
  159. package/esm/plots/pie/interactions/pie-legend-action.js.map +0 -1
  160. package/esm/plots/pie/interactions/pie-statistic-action.js.map +0 -1
  161. package/lib/plots/bar/utils.d.ts +0 -6
  162. package/lib/plots/bar/utils.js +0 -12
  163. package/lib/plots/bar/utils.js.map +0 -1
  164. package/lib/plots/pie/interactions/pie-legend-action.js.map +0 -1
  165. package/lib/plots/pie/interactions/pie-statistic-action.js.map +0 -1
  166. package/src/plots/bar/utils.ts +0 -9
@@ -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
  /**
@@ -76,10 +76,7 @@ function geometry(params: Params<BidirectionalBarOptions>): Params<Bidirectional
76
76
  },
77
77
  id: SECOND_AXES_VIEW,
78
78
  });
79
- secondView
80
- .coordinate()
81
- .reflect('y')
82
- .rotate(Math.PI * 0); // 旋转
79
+ secondView.coordinate().reflect('y');
83
80
 
84
81
  firstView.data(firstViewData);
85
82
  secondView.data(secondViewData);
@@ -277,12 +274,12 @@ export function animation(params: Params<BidirectionalBarOptions>): Params<Bidir
277
274
  }
278
275
 
279
276
  /**
280
- * label 配置
277
+ * label 配置 (1. 设置 offset 偏移量默认值 2. leftView 偏移量需要 *= -1)
281
278
  * @param params
282
279
  */
283
280
  function label(params: Params<BidirectionalBarOptions>): Params<BidirectionalBarOptions> {
284
281
  const { chart, options } = params;
285
- const { label, yField } = options;
282
+ const { label, yField, layout } = options;
286
283
 
287
284
  const firstView = findViewById(chart, FIRST_AXES_VIEW);
288
285
  const secondView = findViewById(chart, SECOND_AXES_VIEW);
@@ -294,10 +291,41 @@ function label(params: Params<BidirectionalBarOptions>): Params<BidirectionalBar
294
291
  rightGeometry.label(false);
295
292
  } else {
296
293
  const { callback, ...cfg } = label;
294
+ /** ---- 设置默认配置 ---- */
295
+ // 默认居中
296
+ if (!cfg.position) {
297
+ cfg.position = 'middle';
298
+ }
299
+ if (cfg.offset === undefined) {
300
+ cfg.offset = 2;
301
+ }
302
+
303
+ /** ---- leftView label 设置 ---- */
304
+ const leftLabelCfg = { ...cfg };
305
+ if (isHorizontal(layout)) {
306
+ // 设置 textAlign 默认值
307
+ const textAlign = leftLabelCfg.style?.textAlign || (cfg.position === 'middle' ? 'center' : 'left');
308
+ cfg.style = deepAssign({}, cfg.style, { textAlign });
309
+ const textAlignMap = { left: 'right', right: 'left', center: 'center' };
310
+ leftLabelCfg.style = deepAssign({}, leftLabelCfg.style, { textAlign: textAlignMap[textAlign] });
311
+ } else {
312
+ const positionMap = { top: 'bottom', bottom: 'top', middle: 'middle' };
313
+ if (typeof cfg.position === 'string') {
314
+ cfg.position = positionMap[cfg.position];
315
+ } else if (typeof cfg.position === 'function') {
316
+ cfg.position = (...args) => positionMap[(cfg.position as Function).apply(this, args)];
317
+ }
318
+ // 设置 textBaseline 默认值
319
+ const textBaseline = leftLabelCfg.style?.textBaseline || 'bottom';
320
+ leftLabelCfg.style = deepAssign({}, leftLabelCfg.style, { textBaseline });
321
+ const textBaselineMap = { top: 'bottom', bottom: 'top', middle: 'middle' };
322
+ cfg.style = deepAssign({}, cfg.style, { textBaseline: textBaselineMap[textBaseline] });
323
+ }
324
+
297
325
  leftGeometry.label({
298
326
  fields: [yField[0]],
299
327
  callback,
300
- cfg: transformLabel(cfg),
328
+ cfg: transformLabel(leftLabelCfg),
301
329
  });
302
330
  rightGeometry.label({
303
331
  fields: [yField[1]],
@@ -20,6 +20,9 @@ export class BidirectionalBar extends Plot<BidirectionalBarOptions> {
20
20
  });
21
21
  }
22
22
 
23
+ /** 对称条形图分类字段 */
24
+ static SERIES_FIELD_KEY = SERIES_FIELD_KEY;
25
+
23
26
  /** 图表类型 */
24
27
  public type: string = 'bidirectional-bar';
25
28
 
@@ -67,6 +67,7 @@ function geometry(params: Params<ColumnOptions>): Params<ColumnOptions> {
67
67
  seriesField,
68
68
  groupField,
69
69
  tooltip,
70
+ shape,
70
71
  } = options;
71
72
 
72
73
  const percentData =
@@ -110,6 +111,7 @@ function geometry(params: Params<ColumnOptions>): Params<ColumnOptions> {
110
111
  widthRatio: columnWidthRatio,
111
112
  tooltip: tooltipOptions,
112
113
  interval: {
114
+ shape,
113
115
  style: columnStyle,
114
116
  color,
115
117
  },
@@ -40,6 +40,11 @@ export interface ColumnOptions
40
40
  /** 分组字段,优先级高于 seriesField , isGroup: true 时会根据 groupField 进行分组。*/
41
41
  readonly groupField?: string;
42
42
 
43
+ // 自定义相关
44
+ /** 自定义柱状图 interval 图形元素展示形状 */
45
+ readonly shape?: string;
46
+
43
47
  // 图表交互
48
+ /** 开启下钻交互,以及进行下钻交互的配置 */
44
49
  readonly brush?: BrushCfg;
45
50
  }
@@ -2,17 +2,7 @@ import { get } from '@antv/util';
2
2
  import { Params } from '../../core/adaptor';
3
3
  import { deepAssign, findGeometry } from '../../utils';
4
4
  import { flow, transformLabel } from '../../utils';
5
- import {
6
- tooltip,
7
- interaction,
8
- animation,
9
- theme,
10
- scale,
11
- annotation,
12
- state,
13
- legend,
14
- pattern,
15
- } from '../../adaptor/common';
5
+ import { tooltip, interaction, animation, theme, scale, annotation, state, pattern } from '../../adaptor/common';
16
6
  import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
17
7
  import { getTooltipMapping } from '../../utils/tooltip';
18
8
  import { HeatmapOptions } from './types';
@@ -116,6 +106,34 @@ function axis(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
116
106
  return params;
117
107
  }
118
108
 
109
+ /**
110
+ * legend 配置
111
+ * @param params
112
+ */
113
+ function legend(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
114
+ const { chart, options } = params;
115
+ const { legend, colorField, sizeField, sizeLegend } = options;
116
+
117
+ /** legend 不为 false, 则展示图例, 优先展示 color 分类图例 */
118
+ const showLegend = legend !== false;
119
+
120
+ if (colorField) {
121
+ chart.legend(colorField, showLegend ? legend : false);
122
+ }
123
+
124
+ // 旧版本: 有 sizeField 就有 sizeLegend. 这里默认继承下 legend 配置
125
+ if (sizeField) {
126
+ chart.legend(sizeField, sizeLegend === undefined ? legend : sizeLegend);
127
+ }
128
+
129
+ /** 默认没有 sizeField,则隐藏连续图例 */
130
+ if (!showLegend && !sizeLegend) {
131
+ chart.legend(false);
132
+ }
133
+
134
+ return params;
135
+ }
136
+
119
137
  /**
120
138
  * fixme 后续确认下,数据标签的逻辑为啥和通用的不一致
121
139
  * 数据标签
@@ -10,8 +10,6 @@ export interface HeatmapOptions extends Options {
10
10
  readonly yField: string;
11
11
  /** 颜色字段,可选 */
12
12
  readonly colorField?: string;
13
- /** 点大小映射对应的数据字段名,可选 */
14
- readonly sizeField?: string;
15
13
  /** 热力格子中的形状,可选 */
16
14
  readonly shape?: string;
17
15
  /** 热力格子中图形的尺寸比例,可选,只有当 shape 和 sizeField 至少指定一项后才生效 */
@@ -21,6 +19,12 @@ export interface HeatmapOptions extends Options {
21
19
  /** 极坐标属性 */
22
20
  readonly coordinate?: Types.CoordinateOption;
23
21
 
22
+ // 图例相关
23
+ /** 点大小映射对应的数据字段名,可选 */
24
+ readonly sizeField?: string;
25
+ /** size 对应的图例 */
26
+ readonly sizeLegend?: Options['legend'];
27
+
24
28
  // 样式相关
25
29
  /** 热力图形样式 */
26
30
  readonly heatmapStyle?: StyleAttr;
@@ -1,9 +1,9 @@
1
1
  import { Geometry } from '@antv/g2';
2
- import { each } from '@antv/util';
2
+ import { each, isArray } from '@antv/util';
3
3
  import { Params } from '../../core/adaptor';
4
4
  import { tooltip, slider, interaction, animation, theme, scale, annotation, limitInPlot } from '../../adaptor/common';
5
5
  import { findGeometry, transformLabel, deepAssign } from '../../utils';
6
- import { point, line } from '../../adaptor/geometries';
6
+ import { point, line, area } from '../../adaptor/geometries';
7
7
  import { flow } from '../../utils';
8
8
  import { adjustYMetaByZero } from '../../utils/data';
9
9
  import { LineOptions } from './types';
@@ -14,7 +14,7 @@ import { LineOptions } from './types';
14
14
  */
15
15
  function geometry(params: Params<LineOptions>): Params<LineOptions> {
16
16
  const { chart, options } = params;
17
- const { data, color, lineStyle, lineShape, point: pointMapping, seriesField } = options;
17
+ const { data, color, lineStyle, lineShape, point: pointMapping, area: areaMapping, seriesField } = options;
18
18
  const pointState = pointMapping?.state;
19
19
 
20
20
  chart.data(data);
@@ -35,14 +35,21 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
35
35
  shape: 'circle',
36
36
  ...pointMapping,
37
37
  },
38
+ // 面积配置
39
+ area: areaMapping && {
40
+ color,
41
+ ...areaMapping,
42
+ },
38
43
  // label 不传递给各个 geometry adaptor,由 label adaptor 处理
39
44
  label: undefined,
40
45
  },
41
46
  });
42
47
  const second = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
48
+ const areaParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
43
49
 
44
50
  line(primary);
45
51
  point(second);
52
+ area(areaParams);
46
53
 
47
54
  return params;
48
55
  }
@@ -71,6 +78,26 @@ export function meta(params: Params<LineOptions>): Params<LineOptions> {
71
78
  )(params);
72
79
  }
73
80
 
81
+ /**
82
+ * 坐标系配置. 支持 reflect 镜像处理
83
+ * @param params
84
+ */
85
+ function coordinate(params: Params<LineOptions>): Params<LineOptions> {
86
+ const { chart, options } = params;
87
+ const { reflect } = options;
88
+ if (reflect) {
89
+ let p = reflect as any;
90
+ if (!isArray(p)) {
91
+ p = [p];
92
+ }
93
+ const actions = p.map((d) => ['reflect', d]);
94
+
95
+ chart.coordinate({ type: 'rect', actions });
96
+ }
97
+
98
+ return params;
99
+ }
100
+
74
101
  /**
75
102
  * axis 配置
76
103
  * @param params
@@ -174,6 +201,7 @@ export function adaptor(params: Params<LineOptions>) {
174
201
  meta,
175
202
  adjust,
176
203
  theme,
204
+ coordinate,
177
205
  axis,
178
206
  legend,
179
207
  tooltip,
@@ -1,7 +1,12 @@
1
- import { LineGeometryOptions, PointGeometryOptions } from '../../adaptor/geometries';
1
+ import {
2
+ GeometryOptions,
3
+ AreaGeometryOptions,
4
+ LineGeometryOptions,
5
+ PointGeometryOptions,
6
+ } from '../../adaptor/geometries';
2
7
  import { Options, StyleAttr } from '../../types';
3
8
 
4
- export interface LineOptions extends Options {
9
+ export interface LineOptions extends Options, Pick<GeometryOptions, 'customInfo'> {
5
10
  /** 阶梯折线图类型 */
6
11
  readonly stepType?: string;
7
12
  /** x 轴字段 */
@@ -22,4 +27,10 @@ export interface LineOptions extends Options {
22
27
  readonly lineShape?: Required<LineGeometryOptions>['line']['shape'];
23
28
  /** 折线数据点:1、图形映射属性 2、状态样式 */
24
29
  readonly point?: PointGeometryOptions['point'] & Pick<PointGeometryOptions, 'state'>;
30
+ /** 折线趋势填充色:1、图形映射属性 */
31
+ readonly area?: AreaGeometryOptions['area'];
32
+
33
+ // 其他
34
+ /** 坐标轴反转配置 */
35
+ readonly reflect?: 'x' | 'y' | ['x', 'y'];
25
36
  }
@@ -1,7 +1,7 @@
1
1
  import { IElement, IGroup } from '@antv/g-base';
2
2
  import { Util, Element, Action } from '@antv/g2';
3
3
  import { isEqual } from '@antv/util';
4
- import { transform } from '../../../utils/matrix';
4
+ import { transform } from '../../../../utils/matrix';
5
5
 
6
6
  /**
7
7
  * 饼图 图例激活 action
@@ -1,8 +1,10 @@
1
1
  import { View, Action, Util, Types } from '@antv/g2';
2
2
  import { each, get } from '@antv/util';
3
- import { PieOptions } from '..';
4
- import { Annotation } from '../../../types/annotation';
5
- import { renderStatistic } from '../../../utils/statistic';
3
+ import { Annotation } from '../../../../types/annotation';
4
+ import { renderStatistic } from '../../../../utils/statistic';
5
+ import { PieOptions } from '../../types';
6
+ import { getCurrentElement } from '../util';
7
+
6
8
  /**
7
9
  * Pie 中心文本事件的 Action
8
10
  */
@@ -60,6 +62,12 @@ export class StatisticAction extends Action {
60
62
  renderStatistic(view, { statistic, plotType: 'pie' }, data);
61
63
  view.render(true);
62
64
  }
65
+
66
+ // 交互的时候,把 shape 提前
67
+ const ele = getCurrentElement(this.context);
68
+ if (ele) {
69
+ ele.shape.toFront();
70
+ }
63
71
  }
64
72
 
65
73
  public reset() {
@@ -1,6 +1,6 @@
1
1
  import { registerAction, registerInteraction } from '@antv/g2';
2
- import { PieLegendAction } from './pie-legend-action';
3
- import { StatisticAction } from './pie-statistic-action';
2
+ import { PieLegendAction } from './actions/legend-active';
3
+ import { StatisticAction } from './actions/statistic-active';
4
4
 
5
5
  export const PIE_STATISTIC = 'pie-statistic';
6
6
 
@@ -0,0 +1,16 @@
1
+ import { Element } from '@antv/g2';
2
+
3
+ /**
4
+ * 获取当前事件相关的图表元素
5
+ * @param context 交互的上下文
6
+ * @ignore
7
+ */
8
+ export function getCurrentElement(context): Element | undefined {
9
+ const event = context.event;
10
+ let element;
11
+ const target = event.target;
12
+ if (target) {
13
+ element = target.get('element');
14
+ }
15
+ return element;
16
+ }
@@ -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. 生成绘图数据