@antv/g2 5.1.13 → 5.1.15-beta.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 (239) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/growInX.js +1 -1
  4. package/esm/animation/growInX.js.map +1 -1
  5. package/esm/animation/growInY.js +1 -1
  6. package/esm/animation/growInY.js.map +1 -1
  7. package/esm/animation/morphing.js +8 -4
  8. package/esm/animation/morphing.js.map +1 -1
  9. package/esm/animation/scaleInY.js +2 -5
  10. package/esm/animation/scaleInY.js.map +1 -1
  11. package/esm/animation/waveIn.js +2 -1
  12. package/esm/animation/waveIn.js.map +1 -1
  13. package/esm/api/utils.js +27 -15
  14. package/esm/api/utils.js.map +1 -1
  15. package/esm/component/axis.js +13 -7
  16. package/esm/component/axis.js.map +1 -1
  17. package/esm/component/title.js +2 -1
  18. package/esm/component/title.js.map +1 -1
  19. package/esm/coordinate/polar.d.ts +1 -1
  20. package/esm/coordinate/polar.js +3 -1
  21. package/esm/coordinate/polar.js.map +1 -1
  22. package/esm/index.d.ts +2 -0
  23. package/esm/interaction/event.js +15 -3
  24. package/esm/interaction/event.js.map +1 -1
  25. package/esm/interaction/index.d.ts +1 -0
  26. package/esm/interaction/index.js +1 -0
  27. package/esm/interaction/index.js.map +1 -1
  28. package/esm/interaction/legendFilter.d.ts +1 -0
  29. package/esm/interaction/legendFilter.js +6 -0
  30. package/esm/interaction/legendFilter.js.map +1 -1
  31. package/esm/interaction/scrollbarFilter.js +5 -1
  32. package/esm/interaction/scrollbarFilter.js.map +1 -1
  33. package/esm/interaction/sliderFilter.d.ts +1 -1
  34. package/esm/interaction/sliderFilter.js +19 -2
  35. package/esm/interaction/sliderFilter.js.map +1 -1
  36. package/esm/interaction/tooltip.js +2 -2
  37. package/esm/interaction/tooltip.js.map +1 -1
  38. package/esm/interaction/treemapDrillDown.d.ts +10 -0
  39. package/esm/interaction/treemapDrillDown.js +229 -0
  40. package/esm/interaction/treemapDrillDown.js.map +1 -0
  41. package/esm/interaction/utils.js +7 -6
  42. package/esm/interaction/utils.js.map +1 -1
  43. package/esm/lib/core.d.ts +2 -1
  44. package/esm/lib/core.js +2 -1
  45. package/esm/lib/core.js.map +1 -1
  46. package/esm/lib/std.d.ts +1 -0
  47. package/esm/mark/chord.js +0 -1
  48. package/esm/mark/chord.js.map +1 -1
  49. package/esm/mark/gauge.js +4 -1
  50. package/esm/mark/gauge.js.map +1 -1
  51. package/esm/mark/sankey.js +1 -1
  52. package/esm/mark/sankey.js.map +1 -1
  53. package/esm/mark/treemap.js +37 -57
  54. package/esm/mark/treemap.js.map +1 -1
  55. package/esm/mark/utils.d.ts +0 -5
  56. package/esm/mark/utils.js +0 -13
  57. package/esm/mark/utils.js.map +1 -1
  58. package/esm/runtime/plot.js +52 -35
  59. package/esm/runtime/plot.js.map +1 -1
  60. package/esm/runtime/types/common.d.ts +1 -1
  61. package/esm/shape/connector/connector.js +1 -1
  62. package/esm/shape/connector/connector.js.map +1 -1
  63. package/esm/shape/gauge/round.d.ts +3 -0
  64. package/esm/shape/gauge/round.js +40 -0
  65. package/esm/shape/gauge/round.js.map +1 -0
  66. package/esm/shape/image/image.js +1 -1
  67. package/esm/shape/index.d.ts +1 -0
  68. package/esm/shape/index.js +1 -0
  69. package/esm/shape/index.js.map +1 -1
  70. package/esm/shape/interval/color.js +1 -1
  71. package/esm/shape/interval/color.js.map +1 -1
  72. package/esm/shape/interval/funnel.js +1 -1
  73. package/esm/shape/interval/funnel.js.map +1 -1
  74. package/esm/shape/label/position/default.js +9 -9
  75. package/esm/shape/label/position/default.js.map +1 -1
  76. package/esm/shape/lineXY/line.js +1 -1
  77. package/esm/shape/lineXY/line.js.map +1 -1
  78. package/esm/shape/liquid/liquid.js +4 -4
  79. package/esm/shape/liquid/liquid.js.map +1 -1
  80. package/esm/shape/liquid/wave.js +1 -1
  81. package/esm/shape/liquid/wave.js.map +1 -1
  82. package/esm/shape/point/color.js +1 -0
  83. package/esm/shape/point/color.js.map +1 -1
  84. package/esm/shape/text/advance.js +2 -1
  85. package/esm/shape/text/advance.js.map +1 -1
  86. package/esm/shape/utils.js +2 -2
  87. package/esm/shape/utils.js.map +1 -1
  88. package/esm/theme/create.d.ts +2 -2
  89. package/esm/theme/create.js +2 -2
  90. package/esm/theme/create.js.map +1 -1
  91. package/esm/utils/angle.d.ts +4 -0
  92. package/esm/utils/angle.js +18 -0
  93. package/esm/utils/angle.js.map +1 -1
  94. package/esm/utils/marker.d.ts +1 -1
  95. package/esm/utils/marker.js +2 -2
  96. package/esm/utils/marker.js.map +1 -1
  97. package/esm/utils/treeDataTransform.d.ts +21 -0
  98. package/esm/utils/treeDataTransform.js +90 -0
  99. package/esm/utils/treeDataTransform.js.map +1 -0
  100. package/lib/animation/growInX.js +1 -1
  101. package/lib/animation/growInX.js.map +1 -1
  102. package/lib/animation/growInY.js +1 -1
  103. package/lib/animation/growInY.js.map +1 -1
  104. package/lib/animation/morphing.js +8 -4
  105. package/lib/animation/morphing.js.map +1 -1
  106. package/lib/animation/scaleInY.js +2 -5
  107. package/lib/animation/scaleInY.js.map +1 -1
  108. package/lib/animation/waveIn.js +2 -1
  109. package/lib/animation/waveIn.js.map +1 -1
  110. package/lib/api/utils.js +27 -15
  111. package/lib/api/utils.js.map +1 -1
  112. package/lib/component/axis.js +13 -7
  113. package/lib/component/axis.js.map +1 -1
  114. package/lib/component/title.js +2 -1
  115. package/lib/component/title.js.map +1 -1
  116. package/lib/coordinate/polar.d.ts +1 -1
  117. package/lib/coordinate/polar.js +3 -1
  118. package/lib/coordinate/polar.js.map +1 -1
  119. package/lib/index.d.ts +2 -0
  120. package/lib/interaction/event.js +15 -3
  121. package/lib/interaction/event.js.map +1 -1
  122. package/lib/interaction/index.d.ts +1 -0
  123. package/lib/interaction/index.js +3 -1
  124. package/lib/interaction/index.js.map +1 -1
  125. package/lib/interaction/legendFilter.d.ts +1 -0
  126. package/lib/interaction/legendFilter.js +8 -1
  127. package/lib/interaction/legendFilter.js.map +1 -1
  128. package/lib/interaction/scrollbarFilter.js +5 -1
  129. package/lib/interaction/scrollbarFilter.js.map +1 -1
  130. package/lib/interaction/sliderFilter.d.ts +1 -1
  131. package/lib/interaction/sliderFilter.js +19 -2
  132. package/lib/interaction/sliderFilter.js.map +1 -1
  133. package/lib/interaction/tooltip.js +2 -2
  134. package/lib/interaction/tooltip.js.map +1 -1
  135. package/lib/interaction/treemapDrillDown.d.ts +10 -0
  136. package/lib/interaction/treemapDrillDown.js +233 -0
  137. package/lib/interaction/treemapDrillDown.js.map +1 -0
  138. package/lib/interaction/utils.js +7 -6
  139. package/lib/interaction/utils.js.map +1 -1
  140. package/lib/lib/core.d.ts +2 -1
  141. package/lib/lib/core.js +1 -0
  142. package/lib/lib/core.js.map +1 -1
  143. package/lib/lib/std.d.ts +1 -0
  144. package/lib/mark/chord.js +0 -1
  145. package/lib/mark/chord.js.map +1 -1
  146. package/lib/mark/gauge.js +4 -1
  147. package/lib/mark/gauge.js.map +1 -1
  148. package/lib/mark/sankey.js +1 -1
  149. package/lib/mark/sankey.js.map +1 -1
  150. package/lib/mark/treemap.js +36 -56
  151. package/lib/mark/treemap.js.map +1 -1
  152. package/lib/mark/utils.d.ts +0 -5
  153. package/lib/mark/utils.js +1 -15
  154. package/lib/mark/utils.js.map +1 -1
  155. package/lib/runtime/plot.js +51 -34
  156. package/lib/runtime/plot.js.map +1 -1
  157. package/lib/runtime/types/common.d.ts +1 -1
  158. package/lib/shape/connector/connector.js +1 -1
  159. package/lib/shape/connector/connector.js.map +1 -1
  160. package/lib/shape/gauge/round.d.ts +3 -0
  161. package/lib/shape/gauge/round.js +44 -0
  162. package/lib/shape/gauge/round.js.map +1 -0
  163. package/lib/shape/image/image.js +1 -1
  164. package/lib/shape/index.d.ts +1 -0
  165. package/lib/shape/index.js +3 -1
  166. package/lib/shape/index.js.map +1 -1
  167. package/lib/shape/interval/color.js +1 -1
  168. package/lib/shape/interval/color.js.map +1 -1
  169. package/lib/shape/interval/funnel.js +1 -1
  170. package/lib/shape/interval/funnel.js.map +1 -1
  171. package/lib/shape/label/position/default.js +9 -9
  172. package/lib/shape/label/position/default.js.map +1 -1
  173. package/lib/shape/lineXY/line.js +1 -1
  174. package/lib/shape/lineXY/line.js.map +1 -1
  175. package/lib/shape/liquid/liquid.js +4 -4
  176. package/lib/shape/liquid/liquid.js.map +1 -1
  177. package/lib/shape/liquid/wave.js +1 -1
  178. package/lib/shape/liquid/wave.js.map +1 -1
  179. package/lib/shape/point/color.js +1 -0
  180. package/lib/shape/point/color.js.map +1 -1
  181. package/lib/shape/text/advance.js +2 -1
  182. package/lib/shape/text/advance.js.map +1 -1
  183. package/lib/shape/utils.js +1 -1
  184. package/lib/shape/utils.js.map +1 -1
  185. package/lib/theme/create.d.ts +2 -2
  186. package/lib/theme/create.js +2 -2
  187. package/lib/theme/create.js.map +1 -1
  188. package/lib/utils/angle.d.ts +4 -0
  189. package/lib/utils/angle.js +20 -1
  190. package/lib/utils/angle.js.map +1 -1
  191. package/lib/utils/marker.d.ts +1 -1
  192. package/lib/utils/marker.js +2 -2
  193. package/lib/utils/marker.js.map +1 -1
  194. package/lib/utils/treeDataTransform.d.ts +21 -0
  195. package/lib/utils/treeDataTransform.js +94 -0
  196. package/lib/utils/treeDataTransform.js.map +1 -0
  197. package/package.json +15 -15
  198. package/src/animation/growInX.ts +1 -1
  199. package/src/animation/growInY.ts +1 -1
  200. package/src/animation/morphing.ts +7 -5
  201. package/src/animation/scaleInY.ts +2 -5
  202. package/src/animation/waveIn.ts +2 -1
  203. package/src/api/utils.ts +41 -13
  204. package/src/component/axis.ts +17 -10
  205. package/src/component/title.ts +4 -0
  206. package/src/coordinate/polar.ts +6 -1
  207. package/src/interaction/event.ts +20 -7
  208. package/src/interaction/index.ts +1 -0
  209. package/src/interaction/legendFilter.ts +8 -0
  210. package/src/interaction/scrollbarFilter.ts +4 -0
  211. package/src/interaction/sliderFilter.ts +21 -1
  212. package/src/interaction/tooltip.ts +3 -3
  213. package/src/interaction/treemapDrillDown.ts +282 -0
  214. package/src/interaction/utils.ts +8 -5
  215. package/src/lib/core.ts +2 -0
  216. package/src/mark/chord.ts +0 -1
  217. package/src/mark/gauge.ts +5 -1
  218. package/src/mark/sankey.ts +1 -1
  219. package/src/mark/treemap.ts +76 -123
  220. package/src/mark/utils.ts +0 -17
  221. package/src/runtime/plot.ts +93 -45
  222. package/src/runtime/types/common.ts +5 -1
  223. package/src/shape/connector/connector.ts +1 -1
  224. package/src/shape/gauge/round.ts +57 -0
  225. package/src/shape/image/image.ts +1 -1
  226. package/src/shape/index.ts +1 -0
  227. package/src/shape/interval/color.ts +1 -1
  228. package/src/shape/interval/funnel.ts +1 -1
  229. package/src/shape/label/position/default.ts +9 -9
  230. package/src/shape/lineXY/line.ts +1 -2
  231. package/src/shape/liquid/liquid.ts +4 -4
  232. package/src/shape/liquid/wave.ts +1 -1
  233. package/src/shape/point/color.ts +1 -0
  234. package/src/shape/text/advance.ts +3 -1
  235. package/src/shape/utils.ts +3 -2
  236. package/src/theme/create.ts +2 -2
  237. package/src/utils/angle.ts +22 -0
  238. package/src/utils/marker.ts +2 -11
  239. package/src/utils/treeDataTransform.ts +153 -0
@@ -0,0 +1,153 @@
1
+ import { isArray, get } from '@antv/util';
2
+ import {
3
+ stratify,
4
+ hierarchy,
5
+ treemap as treemapLayout,
6
+ treemapBinary,
7
+ treemapDice,
8
+ treemapSlice,
9
+ treemapSliceDice,
10
+ treemapSquarify,
11
+ treemapResquarify,
12
+ } from 'd3-hierarchy';
13
+ import type { Node } from 'd3-hierarchy';
14
+ import { field } from '../mark/utils';
15
+
16
+ type Layout = {
17
+ tile?:
18
+ | 'treemapBinary'
19
+ | 'treemapDice'
20
+ | 'treemapSlice'
21
+ | 'treemapSliceDice'
22
+ | 'treemapSquarify'
23
+ | 'treemapResquarify';
24
+ size?: [number, number];
25
+ round?: boolean;
26
+ // Ignore the value of the parent node when calculating the total value.
27
+ ignoreParentValue?: boolean;
28
+ ratio?: number;
29
+ padding?: number;
30
+ paddingInner?: number;
31
+ paddingOuter?: number;
32
+ paddingTop?: number;
33
+ paddingRight?: number;
34
+ paddingBottom?: number;
35
+ paddingLeft?: number;
36
+ sort?(a: any, b: any): number;
37
+ path?: (d: any) => any;
38
+ /** The granularity of Display layer. */
39
+ layer?: number | ((d: any) => any);
40
+ };
41
+
42
+ /**
43
+ * @description Path need when the data is a flat json structure,
44
+ * and the tree object structure do not need.
45
+ */
46
+ function generateHierarchyRoot(
47
+ data: any[] | Record<string, any>,
48
+ path: (d: any) => any,
49
+ ): Node {
50
+ if (Array.isArray(data)) {
51
+ return typeof path === 'function'
52
+ ? stratify().path(path)(data)
53
+ : stratify()(data);
54
+ }
55
+ return hierarchy(data);
56
+ }
57
+
58
+ function addObjectDataPath(root: Node, path = [root.data.name]) {
59
+ root.id = root.id || root.data.name;
60
+ root.path = path;
61
+
62
+ if (root.children) {
63
+ root.children.forEach((item) => {
64
+ item.id = `${root.id}/${item.data.name}`;
65
+ item.path = [...path, item.data.name];
66
+ addObjectDataPath(item, item.path);
67
+ });
68
+ }
69
+ }
70
+
71
+ function addArrayDataPath(root: Node) {
72
+ const name = get(root, ['data', 'name']);
73
+ if (name.replaceAll) {
74
+ root.path = name.replaceAll('.', '/').split('/');
75
+ }
76
+
77
+ if (root.children) {
78
+ root.children.forEach((item) => {
79
+ addArrayDataPath(item);
80
+ });
81
+ }
82
+ }
83
+
84
+ function getTileMethod(tile: string, ratio: number) {
85
+ const tiles = {
86
+ treemapBinary,
87
+ treemapDice,
88
+ treemapSlice,
89
+ treemapSliceDice,
90
+ treemapSquarify,
91
+ treemapResquarify,
92
+ };
93
+ const tileMethod =
94
+ tile === 'treemapSquarify' ? tiles[tile].ratio(ratio) : tiles[tile];
95
+ if (!tileMethod) {
96
+ throw new TypeError('Invalid tile method!');
97
+ }
98
+ return tileMethod;
99
+ }
100
+
101
+ export function treeDataTransform(
102
+ data,
103
+ layout: Layout,
104
+ encode,
105
+ ): [Node[], Node[]] {
106
+ const { value } = encode;
107
+ const tileMethod = getTileMethod(layout.tile, layout.ratio);
108
+
109
+ const root = generateHierarchyRoot(data, layout.path);
110
+
111
+ if (isArray(data)) {
112
+ addArrayDataPath(root);
113
+ } else {
114
+ addObjectDataPath(root);
115
+ }
116
+
117
+ // Calculate the value and sort.
118
+ value
119
+ ? root
120
+ .sum((d) =>
121
+ layout.ignoreParentValue && d.children ? 0 : field(value)(d),
122
+ )
123
+ .sort(layout.sort)
124
+ : root.count();
125
+
126
+ treemapLayout()
127
+ .tile(tileMethod)
128
+ // @ts-ignore
129
+ .size(layout.size)
130
+ .round(layout.round)
131
+ .paddingInner(layout.paddingInner)
132
+ .paddingOuter(layout.paddingOuter)
133
+ .paddingTop(layout.paddingTop)
134
+ .paddingRight(layout.paddingRight)
135
+ .paddingBottom(layout.paddingBottom)
136
+ .paddingLeft(layout.paddingLeft)(root);
137
+
138
+ const nodes = root.descendants().map((d) =>
139
+ Object.assign(d, {
140
+ id: d.id.replace(/^\//, ''),
141
+ x: [d.x0, d.x1],
142
+ y: [d.y0, d.y1],
143
+ }),
144
+ );
145
+
146
+ const filterData = nodes.filter(
147
+ typeof layout.layer === 'function'
148
+ ? layout.layer
149
+ : (d) => d.height === layout.layer,
150
+ );
151
+
152
+ return [filterData, nodes];
153
+ }