@antv/g2plot 2.3.36 → 2.3.40

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 (237) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/g2plot.min.js +18 -3
  3. package/dist/g2plot.min.js.map +1 -1
  4. package/esm/adaptor/geometries/base.d.ts +2 -0
  5. package/esm/adaptor/geometries/base.js +7 -1
  6. package/esm/adaptor/geometries/base.js.map +1 -1
  7. package/esm/adaptor/geometries/index.d.ts +1 -0
  8. package/esm/adaptor/geometries/index.js.map +1 -1
  9. package/esm/adaptor/pattern.d.ts +1 -1
  10. package/esm/core/plot.d.ts +1 -1
  11. package/esm/core/plot.js +2 -2
  12. package/esm/core/plot.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/interactions/actions/drill-down.d.ts +5 -1
  17. package/esm/interactions/actions/drill-down.js +12 -4
  18. package/esm/interactions/actions/drill-down.js.map +1 -1
  19. package/esm/interactions/drill-down.js +23 -0
  20. package/esm/interactions/drill-down.js.map +1 -1
  21. package/esm/plots/area/adaptor.js +5 -2
  22. package/esm/plots/area/adaptor.js.map +1 -1
  23. package/esm/plots/area/types.d.ts +2 -3
  24. package/esm/plots/area/types.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/box/adaptor.js +17 -2
  31. package/esm/plots/box/adaptor.js.map +1 -1
  32. package/esm/plots/column/adaptor.js +2 -1
  33. package/esm/plots/column/adaptor.js.map +1 -1
  34. package/esm/plots/column/types.d.ts +3 -0
  35. package/esm/plots/column/types.js.map +1 -1
  36. package/esm/plots/funnel/adaptor.js +3 -3
  37. package/esm/plots/funnel/adaptor.js.map +1 -1
  38. package/esm/plots/heatmap/adaptor.js +23 -1
  39. package/esm/plots/heatmap/adaptor.js.map +1 -1
  40. package/esm/plots/heatmap/types.d.ts +4 -2
  41. package/esm/plots/heatmap/types.js.map +1 -1
  42. package/esm/plots/line/adaptor.js +25 -4
  43. package/esm/plots/line/adaptor.js.map +1 -1
  44. package/esm/plots/line/types.d.ts +6 -2
  45. package/esm/plots/line/types.js.map +1 -1
  46. package/esm/plots/pie/interactions/{pie-legend-action.d.ts → actions/legend-active.d.ts} +0 -0
  47. package/esm/plots/pie/interactions/{pie-legend-action.js → actions/legend-active.js} +2 -2
  48. package/esm/plots/pie/interactions/actions/legend-active.js.map +1 -0
  49. package/{lib/plots/pie/interactions/pie-statistic-action.d.ts → esm/plots/pie/interactions/actions/statistic-active.d.ts} +1 -1
  50. package/esm/plots/pie/interactions/{pie-statistic-action.js → actions/statistic-active.js} +8 -2
  51. package/esm/plots/pie/interactions/actions/statistic-active.js.map +1 -0
  52. package/esm/plots/pie/interactions/index.js +2 -2
  53. package/esm/plots/pie/interactions/index.js.map +1 -1
  54. package/esm/plots/pie/interactions/util.d.ts +7 -0
  55. package/esm/plots/pie/interactions/util.js +15 -0
  56. package/esm/plots/pie/interactions/util.js.map +1 -0
  57. package/esm/plots/sankey/helper.js +16 -2
  58. package/esm/plots/sankey/helper.js.map +1 -1
  59. package/esm/plots/sankey/types.d.ts +51 -8
  60. package/esm/plots/sankey/types.js.map +1 -1
  61. package/esm/plots/sunburst/types.d.ts +3 -1
  62. package/esm/plots/sunburst/types.js.map +1 -1
  63. package/esm/plots/sunburst/utils.js +6 -1
  64. package/esm/plots/sunburst/utils.js.map +1 -1
  65. package/esm/plots/venn/adaptor.d.ts +1 -1
  66. package/esm/plots/venn/adaptor.js +53 -14
  67. package/esm/plots/venn/adaptor.js.map +1 -1
  68. package/esm/plots/venn/constant.js +22 -6
  69. package/esm/plots/venn/constant.js.map +1 -1
  70. package/esm/plots/venn/interactions/actions/active.d.ts +14 -0
  71. package/esm/plots/venn/interactions/actions/active.js +34 -0
  72. package/esm/plots/venn/interactions/actions/active.js.map +1 -0
  73. package/esm/plots/venn/interactions/actions/highlight.d.ts +16 -0
  74. package/esm/plots/venn/interactions/actions/highlight.js +39 -0
  75. package/esm/plots/venn/interactions/actions/highlight.js.map +1 -0
  76. package/esm/plots/venn/interactions/actions/selected.d.ts +33 -0
  77. package/esm/plots/venn/interactions/actions/selected.js +70 -0
  78. package/esm/plots/venn/interactions/actions/selected.js.map +1 -0
  79. package/esm/plots/venn/{interaction → interactions}/index.d.ts +0 -0
  80. package/esm/plots/venn/interactions/index.js +48 -0
  81. package/esm/plots/venn/interactions/index.js.map +1 -0
  82. package/esm/plots/venn/interactions/util.d.ts +3 -0
  83. package/esm/plots/venn/interactions/util.js +11 -0
  84. package/esm/plots/venn/interactions/util.js.map +1 -0
  85. package/esm/plots/venn/types.d.ts +2 -2
  86. package/esm/plots/venn/types.js.map +1 -1
  87. package/esm/plots/venn/utils.d.ts +3 -4
  88. package/esm/plots/venn/utils.js +2 -3
  89. package/esm/plots/venn/utils.js.map +1 -1
  90. package/esm/types/attr.d.ts +1 -1
  91. package/esm/types/attr.js.map +1 -1
  92. package/esm/types/common.d.ts +2 -0
  93. package/esm/types/common.js.map +1 -1
  94. package/lib/adaptor/geometries/base.d.ts +2 -0
  95. package/lib/adaptor/geometries/base.js +7 -1
  96. package/lib/adaptor/geometries/base.js.map +1 -1
  97. package/lib/adaptor/geometries/index.d.ts +1 -0
  98. package/lib/adaptor/geometries/index.js.map +1 -1
  99. package/lib/adaptor/pattern.d.ts +1 -1
  100. package/lib/core/plot.d.ts +1 -1
  101. package/lib/core/plot.js +2 -2
  102. package/lib/core/plot.js.map +1 -1
  103. package/lib/index.d.ts +1 -1
  104. package/lib/index.js +1 -1
  105. package/lib/index.js.map +1 -1
  106. package/lib/interactions/actions/drill-down.d.ts +5 -1
  107. package/lib/interactions/actions/drill-down.js +11 -3
  108. package/lib/interactions/actions/drill-down.js.map +1 -1
  109. package/lib/interactions/drill-down.js +23 -0
  110. package/lib/interactions/drill-down.js.map +1 -1
  111. package/lib/plots/area/adaptor.js +5 -2
  112. package/lib/plots/area/adaptor.js.map +1 -1
  113. package/lib/plots/area/types.d.ts +2 -3
  114. package/lib/plots/area/types.js.map +1 -1
  115. package/lib/plots/bidirectional-bar/adaptor.js +45 -9
  116. package/lib/plots/bidirectional-bar/adaptor.js.map +1 -1
  117. package/lib/plots/bidirectional-bar/index.d.ts +2 -0
  118. package/lib/plots/bidirectional-bar/index.js +2 -0
  119. package/lib/plots/bidirectional-bar/index.js.map +1 -1
  120. package/lib/plots/box/adaptor.js +17 -2
  121. package/lib/plots/box/adaptor.js.map +1 -1
  122. package/lib/plots/column/adaptor.js +2 -1
  123. package/lib/plots/column/adaptor.js.map +1 -1
  124. package/lib/plots/column/types.d.ts +3 -0
  125. package/lib/plots/column/types.js.map +1 -1
  126. package/lib/plots/funnel/adaptor.js +2 -2
  127. package/lib/plots/funnel/adaptor.js.map +1 -1
  128. package/lib/plots/heatmap/adaptor.js +23 -1
  129. package/lib/plots/heatmap/adaptor.js.map +1 -1
  130. package/lib/plots/heatmap/types.d.ts +4 -2
  131. package/lib/plots/heatmap/types.js.map +1 -1
  132. package/lib/plots/line/adaptor.js +23 -2
  133. package/lib/plots/line/adaptor.js.map +1 -1
  134. package/lib/plots/line/types.d.ts +6 -2
  135. package/lib/plots/line/types.js.map +1 -1
  136. package/lib/plots/pie/interactions/{pie-legend-action.d.ts → actions/legend-active.d.ts} +0 -0
  137. package/lib/plots/pie/interactions/{pie-legend-action.js → actions/legend-active.js} +2 -2
  138. package/lib/plots/pie/interactions/actions/legend-active.js.map +1 -0
  139. package/{esm/plots/pie/interactions/pie-statistic-action.d.ts → lib/plots/pie/interactions/actions/statistic-active.d.ts} +1 -1
  140. package/lib/plots/pie/interactions/{pie-statistic-action.js → actions/statistic-active.js} +8 -2
  141. package/lib/plots/pie/interactions/actions/statistic-active.js.map +1 -0
  142. package/lib/plots/pie/interactions/index.js +4 -4
  143. package/lib/plots/pie/interactions/index.js.map +1 -1
  144. package/lib/plots/pie/interactions/util.d.ts +7 -0
  145. package/lib/plots/pie/interactions/util.js +19 -0
  146. package/lib/plots/pie/interactions/util.js.map +1 -0
  147. package/lib/plots/sankey/helper.js +16 -2
  148. package/lib/plots/sankey/helper.js.map +1 -1
  149. package/lib/plots/sankey/types.d.ts +51 -8
  150. package/lib/plots/sankey/types.js.map +1 -1
  151. package/lib/plots/sunburst/types.d.ts +3 -1
  152. package/lib/plots/sunburst/types.js.map +1 -1
  153. package/lib/plots/sunburst/utils.js +6 -1
  154. package/lib/plots/sunburst/utils.js.map +1 -1
  155. package/lib/plots/venn/adaptor.d.ts +1 -1
  156. package/lib/plots/venn/adaptor.js +52 -13
  157. package/lib/plots/venn/adaptor.js.map +1 -1
  158. package/lib/plots/venn/constant.js +22 -6
  159. package/lib/plots/venn/constant.js.map +1 -1
  160. package/lib/plots/venn/interactions/actions/active.d.ts +14 -0
  161. package/lib/plots/venn/interactions/actions/active.js +37 -0
  162. package/lib/plots/venn/interactions/actions/active.js.map +1 -0
  163. package/lib/plots/venn/interactions/actions/highlight.d.ts +16 -0
  164. package/lib/plots/venn/interactions/actions/highlight.js +42 -0
  165. package/lib/plots/venn/interactions/actions/highlight.js.map +1 -0
  166. package/lib/plots/venn/interactions/actions/selected.d.ts +33 -0
  167. package/lib/plots/venn/interactions/actions/selected.js +73 -0
  168. package/lib/plots/venn/interactions/actions/selected.js.map +1 -0
  169. package/lib/plots/venn/{interaction → interactions}/index.d.ts +0 -0
  170. package/lib/plots/venn/interactions/index.js +50 -0
  171. package/lib/plots/venn/interactions/index.js.map +1 -0
  172. package/lib/plots/venn/interactions/util.d.ts +3 -0
  173. package/lib/plots/venn/interactions/util.js +15 -0
  174. package/lib/plots/venn/interactions/util.js.map +1 -0
  175. package/lib/plots/venn/types.d.ts +2 -2
  176. package/lib/plots/venn/types.js.map +1 -1
  177. package/lib/plots/venn/utils.d.ts +3 -4
  178. package/lib/plots/venn/utils.js +2 -3
  179. package/lib/plots/venn/utils.js.map +1 -1
  180. package/lib/types/attr.d.ts +1 -1
  181. package/lib/types/attr.js.map +1 -1
  182. package/lib/types/common.d.ts +2 -0
  183. package/lib/types/common.js.map +1 -1
  184. package/package.json +5 -5
  185. package/src/adaptor/geometries/base.ts +23 -2
  186. package/src/adaptor/geometries/index.ts +1 -0
  187. package/src/core/plot.ts +3 -1
  188. package/src/index.ts +1 -1
  189. package/src/interactions/actions/drill-down.ts +13 -4
  190. package/src/interactions/drill-down.ts +24 -1
  191. package/src/plots/area/adaptor.ts +5 -2
  192. package/src/plots/area/types.ts +2 -3
  193. package/src/plots/bidirectional-bar/adaptor.ts +35 -7
  194. package/src/plots/bidirectional-bar/index.ts +3 -0
  195. package/src/plots/box/adaptor.ts +14 -2
  196. package/src/plots/column/adaptor.ts +2 -0
  197. package/src/plots/column/types.ts +5 -0
  198. package/src/plots/funnel/adaptor.ts +3 -3
  199. package/src/plots/heatmap/adaptor.ts +29 -11
  200. package/src/plots/heatmap/types.ts +6 -2
  201. package/src/plots/line/adaptor.ts +31 -3
  202. package/src/plots/line/types.ts +13 -2
  203. package/src/plots/pie/interactions/{pie-legend-action.ts → actions/legend-active.ts} +1 -1
  204. package/src/plots/pie/interactions/{pie-statistic-action.ts → actions/statistic-active.ts} +11 -3
  205. package/src/plots/pie/interactions/index.ts +2 -2
  206. package/src/plots/pie/interactions/util.ts +16 -0
  207. package/src/plots/sankey/helper.ts +26 -9
  208. package/src/plots/sankey/types.ts +52 -8
  209. package/src/plots/sunburst/types.ts +3 -1
  210. package/src/plots/sunburst/utils.ts +6 -1
  211. package/src/plots/venn/adaptor.ts +63 -13
  212. package/src/plots/venn/constant.ts +22 -6
  213. package/src/plots/venn/interactions/actions/active.ts +31 -0
  214. package/src/plots/venn/interactions/actions/highlight.ts +37 -0
  215. package/src/plots/venn/interactions/actions/selected.ts +65 -0
  216. package/src/plots/venn/interactions/index.ts +55 -0
  217. package/src/plots/venn/interactions/util.ts +12 -0
  218. package/src/plots/venn/types.ts +2 -2
  219. package/src/plots/venn/utils.ts +10 -4
  220. package/src/types/attr.ts +1 -1
  221. package/src/types/common.ts +2 -0
  222. package/esm/plots/pie/interactions/pie-legend-action.js.map +0 -1
  223. package/esm/plots/pie/interactions/pie-statistic-action.js.map +0 -1
  224. package/esm/plots/venn/interaction/action.d.ts +0 -18
  225. package/esm/plots/venn/interaction/action.js +0 -77
  226. package/esm/plots/venn/interaction/action.js.map +0 -1
  227. package/esm/plots/venn/interaction/index.js +0 -15
  228. package/esm/plots/venn/interaction/index.js.map +0 -1
  229. package/lib/plots/pie/interactions/pie-legend-action.js.map +0 -1
  230. package/lib/plots/pie/interactions/pie-statistic-action.js.map +0 -1
  231. package/lib/plots/venn/interaction/action.d.ts +0 -18
  232. package/lib/plots/venn/interaction/action.js +0 -80
  233. package/lib/plots/venn/interaction/action.js.map +0 -1
  234. package/lib/plots/venn/interaction/index.js +0 -17
  235. package/lib/plots/venn/interaction/index.js.map +0 -1
  236. package/src/plots/venn/interaction/action.ts +0 -67
  237. package/src/plots/venn/interaction/index.ts +0 -17
@@ -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. 生成绘图数据
@@ -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
  */
@@ -24,8 +24,10 @@ export interface SunburstOptions extends Omit<Options, 'data' | 'legend' | 'slid
24
24
  readonly hierarchyConfig?: Omit<HierarchyOption, 'as' | 'type'> & {
25
25
  /** default: 'value', required data to be like: { name: 'xx', [field]: 12, children: [] } */
26
26
  readonly field?: string;
27
- /** 是否忽略 */
27
+ /** 是否忽略父节点的权重, 默认: false, 其父节点的权重不由子节点权重总和决定 */
28
28
  readonly ignoreParentValue?: boolean;
29
+ /** 默认展示的层级深度. 默认空, 代表全部展示. 取值 > 0 */
30
+ readonly activeDepth?: number;
29
31
  };
30
32
 
31
33
  // 其他
@@ -1,3 +1,4 @@
1
+ import { omit } from '@antv/util';
1
2
  import { HIERARCHY_DATA_TRANSFORM_PARAMS } from '../../interactions/actions/drill-down';
2
3
  import { pick } from '../../utils';
3
4
  import { partition } from '../../utils/hierarchy/partition';
@@ -11,6 +12,7 @@ import { SunburstOptions } from './types';
11
12
  */
12
13
  export function transformData(options: Pick<SunburstOptions, 'data' | 'colorField' | 'rawFields' | 'hierarchyConfig'>) {
13
14
  const { data, colorField, rawFields, hierarchyConfig = {} } = options;
15
+ const { activeDepth } = hierarchyConfig;
14
16
  const transform = {
15
17
  partition: partition,
16
18
  treemap: treemap,
@@ -22,7 +24,7 @@ export function transformData(options: Pick<SunburstOptions, 'data' | 'colorFiel
22
24
 
23
25
  const nodes = transform[type](data, {
24
26
  field: seriesField || 'value',
25
- ...hierarchyConfig,
27
+ ...omit(hierarchyConfig, ['activeDepth']),
26
28
  // @ts-ignore
27
29
  type: `hierarchy.${type}`,
28
30
  as: ['x', 'y'],
@@ -34,6 +36,9 @@ export function transformData(options: Pick<SunburstOptions, 'data' | 'colorFiel
34
36
  if (node.depth === 0) {
35
37
  return null;
36
38
  }
39
+ if (activeDepth > 0 && node.depth > activeDepth) {
40
+ return null;
41
+ }
37
42
 
38
43
  let path = node.data.name;
39
44
  let ancestorNode = { ...node };
@@ -19,26 +19,38 @@ import { CustomInfo, VennData, VennOptions } from './types';
19
19
  import { ID_FIELD } from './constant';
20
20
  import './shape';
21
21
  import './label';
22
- import './interaction';
22
+ import './interactions';
23
23
 
24
24
  /** 图例默认预留空间 */
25
25
  export const LEGEND_SPACE = 40;
26
26
 
27
+ /**
28
+ * 获取 color 映射
29
+ */
30
+ function colorMap(params: Params<VennOptions>, data: VennData, colorPalette?: string[]) {
31
+ const { chart, options } = params;
32
+ const { blendMode, setsField } = options;
33
+ const { colors10, colors20 } = chart.getTheme();
34
+ let palette = colorPalette;
35
+ if (!isArray(palette)) {
36
+ palette = data.filter((d) => d[setsField].length === 1).length <= 10 ? colors10 : colors20;
37
+ }
38
+ const map = getColorMap(palette, data, blendMode, setsField);
39
+
40
+ return (id: string) => map.get(id) || palette[0];
41
+ }
42
+
27
43
  /**
28
44
  * color options 转换
29
45
  */
30
46
  function transformColor(params: Params<VennOptions>, data: VennData): VennOptions['color'] {
31
- const { chart, options } = params;
32
- const { color, setsField } = options;
47
+ const { options } = params;
48
+ const { color } = options;
33
49
 
34
50
  if (typeof color !== 'function') {
35
- let colorPalette = typeof color === 'string' ? [color] : color;
36
- if (!isArray(colorPalette)) {
37
- const { colors10, colors20 } = chart.getTheme();
38
- colorPalette = data.filter((d) => d[setsField].length === 1).length <= 10 ? colors10 : colors20;
39
- }
40
- const colorMap = getColorMap(colorPalette, data, options);
41
- return (datum: Datum) => colorMap.get(datum[ID_FIELD]) || colorPalette[0];
51
+ const colorPalette = typeof color === 'string' ? [color] : color;
52
+ const map = colorMap(params, data, colorPalette);
53
+ return (datum: Datum) => map(datum[ID_FIELD]);
42
54
  }
43
55
  return color;
44
56
  }
@@ -132,7 +144,6 @@ function geometry(params: Params<VennOptions>): Params<VennOptions> {
132
144
  schema: {
133
145
  shape: 'venn',
134
146
  style: pointStyle,
135
- color: transformColor(params, vennData),
136
147
  },
137
148
  },
138
149
  })
@@ -141,6 +152,16 @@ function geometry(params: Params<VennOptions>): Params<VennOptions> {
141
152
  const geometry = ext.geometry as Geometry;
142
153
  geometry.customInfo(customInfo);
143
154
 
155
+ const colorOptions = transformColor(params, vennData);
156
+ // 韦恩图试点, color 通道只能映射一个字段. 通过外部查找获取 datum
157
+ if (typeof colorOptions === 'function') {
158
+ geometry.color(ID_FIELD, (id) => {
159
+ const datum = vennData.find((d) => d[ID_FIELD] === id);
160
+ const defaultColor = colorMap(params, vennData)(id);
161
+ return colorOptions(datum, defaultColor);
162
+ });
163
+ }
164
+
144
165
  return params;
145
166
  }
146
167
 
@@ -153,7 +174,7 @@ function label(params: Params<VennOptions>): Params<VennOptions> {
153
174
  const { label } = options;
154
175
 
155
176
  // 获取容器大小
156
- const [t, r, b, l] = normalPadding(chart.appendPadding);
177
+ const [t, , , l] = normalPadding(chart.appendPadding);
157
178
  // 传入 label 布局函数所需的 自定义参数
158
179
  const customLabelInfo = { offsetX: l, offsetY: t };
159
180
 
@@ -203,6 +224,35 @@ export function axis(params: Params<VennOptions>): Params<VennOptions> {
203
224
  return params;
204
225
  }
205
226
 
227
+ /**
228
+ * 韦恩图 interaction 交互适配器
229
+ */
230
+ function vennInteraction(params: Params<VennOptions>): Params<VennOptions> {
231
+ const { options, chart } = params;
232
+ const { interactions } = options;
233
+
234
+ if (interactions) {
235
+ const MAP = {
236
+ 'legend-active': 'venn-legend-active',
237
+ 'legend-highlight': 'venn-legend-highlight',
238
+ };
239
+ interaction(
240
+ deepAssign({}, params, {
241
+ options: {
242
+ interactions: interactions.map((i) => ({
243
+ ...i,
244
+ type: MAP[i.type] || i.type,
245
+ })),
246
+ },
247
+ })
248
+ );
249
+ }
250
+
251
+ chart.removeInteraction('legend-active');
252
+ chart.removeInteraction('legend-highlight');
253
+ return params;
254
+ }
255
+
206
256
  /**
207
257
  * 图适配器
208
258
  * @param chart
@@ -220,7 +270,7 @@ export function adaptor(params: Params<VennOptions>) {
220
270
  legend,
221
271
  axis,
222
272
  tooltip,
223
- interaction,
273
+ vennInteraction,
224
274
  animation
225
275
  // ... 其他的 adaptor flow
226
276
  )(params);
@@ -26,10 +26,26 @@ export const DEFAULT_OPTIONS: Partial<VennOptions> = {
26
26
  },
27
27
  },
28
28
  // 默认不开启 图例筛选交互
29
- interactions: [
30
- { type: 'legend-filter', enable: false },
31
- // hover 激活的时候,元素的层级展示不太好 先移除该交互
32
- { type: 'legend-highlight', enable: false },
33
- { type: 'legend-active', enable: false },
34
- ],
29
+ interactions: [{ type: 'legend-filter', enable: false }],
30
+ state: {
31
+ active: {
32
+ style: {
33
+ stroke: '#000',
34
+ },
35
+ },
36
+ selected: {
37
+ style: {
38
+ stroke: '#000',
39
+ lineWidth: 2,
40
+ },
41
+ },
42
+ inactive: {
43
+ style: {
44
+ fillOpacity: 0.3,
45
+ strokeOpacity: 0.3,
46
+ },
47
+ },
48
+ },
49
+ // 韦恩图的默认内置注册的交互
50
+ defaultInteractions: ['tooltip', 'venn-legend-active'],
35
51
  };
@@ -0,0 +1,31 @@
1
+ import { getActionClass } from '@antv/g2';
2
+ import { placeElementsOrdered } from '../util';
3
+
4
+ const ElementActiveAction: any = getActionClass('element-active');
5
+
6
+ export class VennElementActive extends ElementActiveAction {
7
+ /**
8
+ * 同步所有元素的位置
9
+ */
10
+ protected syncElementsPos() {
11
+ placeElementsOrdered(this.context.view);
12
+ }
13
+
14
+ /** 激活图形元素 */
15
+ public active() {
16
+ super.active();
17
+ this.syncElementsPos();
18
+ }
19
+
20
+ /** toggle 图形元素激活状态 */
21
+ public toggle() {
22
+ super.toggle();
23
+ this.syncElementsPos();
24
+ }
25
+
26
+ /** 重置 */
27
+ public reset() {
28
+ super.reset();
29
+ this.syncElementsPos();
30
+ }
31
+ }
@@ -0,0 +1,37 @@
1
+ import { getActionClass } from '@antv/g2';
2
+ import { placeElementsOrdered } from '../util';
3
+
4
+ const ElementHighlightAction: any = getActionClass('element-highlight');
5
+
6
+ export class VennElementHighlight extends ElementHighlightAction {
7
+ /**
8
+ * 同步所有元素的位置
9
+ */
10
+ protected syncElementsPos() {
11
+ placeElementsOrdered(this.context.view);
12
+ }
13
+
14
+ /** 高亮图形元素 */
15
+ public highlight() {
16
+ super.highlight();
17
+ this.syncElementsPos();
18
+ }
19
+
20
+ /** toggle 图形元素高亮状态 */
21
+ public toggle() {
22
+ super.toggle();
23
+ this.syncElementsPos();
24
+ }
25
+
26
+ /** 清楚 */
27
+ public clear() {
28
+ super.clear();
29
+ this.syncElementsPos();
30
+ }
31
+
32
+ /** 重置 */
33
+ public reset() {
34
+ super.reset();
35
+ this.syncElementsPos();
36
+ }
37
+ }
@@ -0,0 +1,65 @@
1
+ import { getActionClass } from '@antv/g2';
2
+ import { placeElementsOrdered } from '../util';
3
+
4
+ const ElementSelectedAction: any = getActionClass('element-selected');
5
+ const ElementSingleSelectedAction: any = getActionClass('element-single-selected');
6
+
7
+ /**
8
+ * 韦恩图元素 多选交互
9
+ */
10
+ export class VennElementSelected extends ElementSelectedAction {
11
+ /**
12
+ * 同步所有元素的位置
13
+ */
14
+ protected syncElementsPos() {
15
+ placeElementsOrdered(this.context.view);
16
+ }
17
+
18
+ /** 激活图形元素 */
19
+ public selected() {
20
+ super.selected();
21
+ this.syncElementsPos();
22
+ }
23
+
24
+ /** toggle 图形元素激活状态 */
25
+ public toggle() {
26
+ super.toggle();
27
+ this.syncElementsPos();
28
+ }
29
+
30
+ /** 重置 */
31
+ public reset() {
32
+ super.reset();
33
+ this.syncElementsPos();
34
+ }
35
+ }
36
+
37
+ /**
38
+ * 韦恩图元素 单选交互
39
+ */
40
+ export class VennElementSingleSelected extends ElementSingleSelectedAction {
41
+ /**
42
+ * 同步所有元素的位置
43
+ */
44
+ protected syncElementsPos() {
45
+ placeElementsOrdered(this.context.view);
46
+ }
47
+
48
+ /** 激活图形元素 */
49
+ public selected() {
50
+ super.selected();
51
+ this.syncElementsPos();
52
+ }
53
+
54
+ /** toggle 图形元素激活状态 */
55
+ public toggle() {
56
+ super.toggle();
57
+ this.syncElementsPos();
58
+ }
59
+
60
+ /** 重置 */
61
+ public reset() {
62
+ super.reset();
63
+ this.syncElementsPos();
64
+ }
65
+ }