@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,282 @@
1
+ import { Text, Group } from '@antv/g';
2
+ import { get, deepMix, pick, keys, find, size, last } from '@antv/util';
3
+ import type { Node } from 'd3-hierarchy';
4
+ import type { DisplayObject } from '@antv/g';
5
+ import { subObject } from '../utils/helper';
6
+ import { PLOT_CLASS_NAME } from '../runtime';
7
+ import { select } from '../utils/selection';
8
+ import { treeDataTransform } from '../utils/treeDataTransform';
9
+ import { legendClearSetState } from './legendFilter';
10
+
11
+ // Get element.
12
+ const getElements = (plot) => {
13
+ return plot.querySelectorAll('.element');
14
+ };
15
+
16
+ function selectPlotArea(root: DisplayObject): DisplayObject {
17
+ return select(root).select(`.${PLOT_CLASS_NAME}`).node();
18
+ }
19
+
20
+ export type DrillDownOptions = {
21
+ originData?: Node[];
22
+ layout?: any;
23
+ [key: string]: any;
24
+ };
25
+
26
+ // Default breadCrumb config.
27
+ const DEFAULT_BREADCRUMB_STYLE = {
28
+ breadCrumbFill: 'rgba(0, 0, 0, 0.85)',
29
+ breadCrumbFontSize: 12,
30
+ breadCrumbY: 12,
31
+ activeFill: 'rgba(0, 0, 0, 0.5)',
32
+ };
33
+
34
+ /**
35
+ * TreemapDrillDown interaction.
36
+ */
37
+ export function TreemapDrillDown(drillDownOptions: DrillDownOptions = {}) {
38
+ const { originData = [], layout, ...style } = drillDownOptions;
39
+
40
+ const breadCrumb = deepMix({}, DEFAULT_BREADCRUMB_STYLE, style);
41
+
42
+ const breadCrumbStyle = subObject(breadCrumb, 'breadCrumb');
43
+ const breadCrumbActiveStyle = subObject(breadCrumb, 'active');
44
+
45
+ return (context) => {
46
+ const { update, setState, container, options } = context;
47
+ const plotArea = selectPlotArea(container);
48
+ const mark = options.marks[0];
49
+
50
+ const { state } = mark;
51
+
52
+ // Create breadCrumbTextsGroup,save textSeparator、drillTexts.
53
+ const textGroup = new Group();
54
+ plotArea.appendChild(textGroup);
55
+
56
+ // Modify the data and scale according to the path and the level of the current click, so as to achieve the effect of drilling down and drilling up and initialization.
57
+ const drillDownClick = async (path: string[], depth: number) => {
58
+ // Clear text.
59
+ textGroup.removeChildren();
60
+
61
+ // More path creation text.
62
+ if (depth) {
63
+ let name = '';
64
+ let y = breadCrumbStyle.y;
65
+ let x = 0;
66
+ const textPath = [];
67
+
68
+ const maxWidth = plotArea.getBBox().width;
69
+
70
+ // Create path: 'type1 / type2 / type3' -> '/ type1 / type2 / type3'.
71
+ const drillTexts = path.map((text, index) => {
72
+ name = `${name}${text}/`;
73
+ textPath.push(text);
74
+ const drillText = new Text({
75
+ name: name.replace(/\/$/, ''),
76
+ style: {
77
+ text,
78
+ x,
79
+ // @ts-ignore
80
+ path: [...textPath],
81
+ depth: index,
82
+ ...breadCrumbStyle,
83
+ y,
84
+ },
85
+ });
86
+
87
+ textGroup.appendChild(drillText);
88
+
89
+ x += drillText.getBBox().width;
90
+
91
+ const textSeparator = new Text({
92
+ style: {
93
+ x,
94
+ text: ' / ',
95
+ ...breadCrumbStyle,
96
+ y,
97
+ },
98
+ });
99
+
100
+ textGroup.appendChild(textSeparator);
101
+
102
+ x += textSeparator.getBBox().width;
103
+
104
+ /**
105
+ * Page width exceeds maximum, line feed.
106
+ * | ----maxWidth---- |
107
+ * | / tyep1 / tyep2 / type3 |
108
+ * ->
109
+ * | ----maxWidth---- |
110
+ * | / tyep1 / tyep2 |
111
+ * | / type3 |
112
+ */
113
+ if (x > maxWidth) {
114
+ y = textGroup.getBBox().height + breadCrumbStyle.y;
115
+ x = 0;
116
+ drillText.attr({
117
+ x,
118
+ y,
119
+ });
120
+ x += drillText.getBBox().width;
121
+ textSeparator.attr({
122
+ x,
123
+ y,
124
+ });
125
+ x += textSeparator.getBBox().width;
126
+ }
127
+
128
+ if (index === size(path) - 1) {
129
+ textSeparator.remove();
130
+ }
131
+
132
+ return drillText;
133
+ });
134
+
135
+ // Add Active, Add TreemapDrillDown
136
+ drillTexts.forEach((item, index) => {
137
+ // Last drillText
138
+ if (index === size(drillTexts) - 1) return;
139
+ const originalAttrs = { ...item.attributes };
140
+ item.attr('cursor', 'pointer');
141
+ item.addEventListener('mouseenter', () => {
142
+ item.attr(breadCrumbActiveStyle);
143
+ });
144
+ item.addEventListener('mouseleave', () => {
145
+ item.attr(originalAttrs);
146
+ });
147
+ item.addEventListener('click', () => {
148
+ drillDownClick(
149
+ get(item, ['style', 'path']),
150
+ get(item, ['style', 'depth']),
151
+ );
152
+ });
153
+ });
154
+ }
155
+
156
+ // LegendFilter interaction and treemapDrillDown clash.
157
+ legendClearSetState(container, setState);
158
+
159
+ // Update marks.
160
+ setState('treemapDrillDown', (viewOptions) => {
161
+ const { marks } = viewOptions;
162
+ // Add filter transform for every marks,
163
+ // which will skip for mark without color channel.
164
+
165
+ const strPath = path.join('/');
166
+
167
+ const newMarks = marks.map((mark) => {
168
+ if (mark.type !== 'rect') return mark;
169
+ let newData = originData;
170
+
171
+ if (depth) {
172
+ const filterData = originData
173
+ .filter((item) => {
174
+ const id = get(item, ['id']);
175
+ return id && (id.match(`${strPath}/`) || strPath.match(id));
176
+ })
177
+ .map((item) => ({
178
+ value: item.height === 0 ? get(item, ['value']) : undefined,
179
+ name: get(item, ['id']),
180
+ }));
181
+
182
+ const { paddingLeft, paddingBottom, paddingRight } = layout;
183
+
184
+ // New drill layout for calculation x y and filtration data.
185
+ const newLayout = {
186
+ ...layout,
187
+ paddingTop:
188
+ (layout.paddingTop || textGroup.getBBox().height + 10) /
189
+ (depth + 1),
190
+ paddingLeft: paddingLeft / (depth + 1),
191
+ paddingBottom: paddingBottom / (depth + 1),
192
+ paddingRight: paddingRight / (depth + 1),
193
+ path: (d) => d.name,
194
+ layer: (d) => d.depth === depth + 1,
195
+ };
196
+
197
+ // Transform the new matrix tree data.
198
+ newData = treeDataTransform(filterData, newLayout, {
199
+ value: 'value',
200
+ })[0];
201
+ } else {
202
+ newData = originData.filter((item) => {
203
+ return item.depth === 1;
204
+ });
205
+ }
206
+
207
+ const colorDomain = [];
208
+ newData.forEach(({ path }) => {
209
+ colorDomain.push(last(path));
210
+ });
211
+
212
+ // TreemapDrillDown by filtering the data and scale.
213
+ return deepMix({}, mark, {
214
+ data: newData,
215
+ scale: {
216
+ color: { domain: colorDomain },
217
+ },
218
+ });
219
+ });
220
+
221
+ return { ...viewOptions, marks: newMarks };
222
+ });
223
+
224
+ // The second argument is to allow the legendFilter event to be re-added; the update method itself causes legend to lose the interaction event.
225
+ await update(undefined, ['legendFilter']);
226
+ };
227
+
228
+ // Elements and BreadCrumb click.
229
+ const createDrillClick = (e) => {
230
+ const item = e.target;
231
+ if (get(item, ['markType']) !== 'rect') return;
232
+
233
+ const key = get(item, ['__data__', 'key']);
234
+ const node = find(originData, (d) => d.id === key);
235
+
236
+ // Node height = 0 no children
237
+ if (get(node, 'height')) {
238
+ drillDownClick(get(node, 'path'), get(node, 'depth'));
239
+ }
240
+ };
241
+
242
+ // Add click drill interaction.
243
+ plotArea.addEventListener('click', createDrillClick);
244
+
245
+ // Change attributes keys.
246
+ const changeStyleKey = keys({ ...state.active, ...state.inactive });
247
+
248
+ const createActive = () => {
249
+ const elements = getElements(plotArea);
250
+ elements.forEach((element) => {
251
+ const cursor = get(element, ['style', 'cursor']);
252
+ const node = find(
253
+ originData,
254
+ (d) => d.id === get(element, ['__data__', 'key']),
255
+ );
256
+
257
+ if (cursor !== 'pointer' && node?.height) {
258
+ element.style.cursor = 'pointer';
259
+ const originalAttrs = pick(element.attributes, changeStyleKey);
260
+
261
+ element.addEventListener('mouseenter', () => {
262
+ element.attr(state.active);
263
+ });
264
+
265
+ element.addEventListener('mouseleave', () => {
266
+ element.attr(deepMix(originalAttrs, state.inactive));
267
+ });
268
+ }
269
+ });
270
+ };
271
+
272
+ createActive();
273
+ // Animate elements update, Add active.
274
+ plotArea.addEventListener('mousemove', createActive);
275
+
276
+ return () => {
277
+ textGroup.remove();
278
+ plotArea.removeEventListener('click', createDrillClick);
279
+ plotArea.removeEventListener('mousemove', createActive);
280
+ };
281
+ };
282
+ }
@@ -43,9 +43,12 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
43
43
  }
44
44
 
45
45
  export function bboxOf(node) {
46
- if (node.nodeName !== 'rect') return node.getRenderBounds();
47
- const { x, y, width, height } = node.style;
48
- return { min: [x, y], max: [x + width, y + height] };
46
+ // if (node.nodeName === 'rect') {
47
+ return node.getBounds();
48
+ // }
49
+
50
+ // const { x = 0, y = 0, width, height } = node.style;
51
+ // return { min: [x, y], max: [x + width, y + height] };
49
52
  }
50
53
 
51
54
  export function mousePosition(target, event) {
@@ -419,7 +422,7 @@ export function renderBackground({
419
422
  fillOpacity = 0.3,
420
423
  zIndex = -2,
421
424
  padding = 0.001,
422
- strokeWidth = 0,
425
+ lineWidth = 0,
423
426
  ...style
424
427
  } = mapObject(rest, (d) => valueof(d, element));
425
428
  const finalStyle = {
@@ -428,7 +431,7 @@ export function renderBackground({
428
431
  fillOpacity,
429
432
  zIndex,
430
433
  padding,
431
- strokeWidth,
434
+ lineWidth,
432
435
  };
433
436
  const shapeOf = isOrdinalShape() ? bandShapeOf : cloneShapeOf;
434
437
  const shape = shapeOf(element, finalStyle);
package/src/lib/core.ts CHANGED
@@ -100,6 +100,7 @@ import {
100
100
  SliderFilter,
101
101
  Poptip,
102
102
  ScrollbarFilter,
103
+ TreemapDrillDown,
103
104
  } from '../interaction';
104
105
  import {
105
106
  SpaceLayer,
@@ -299,6 +300,7 @@ export function corelib() {
299
300
  'interaction.sliderFilter': SliderFilter,
300
301
  'interaction.scrollbarFilter': ScrollbarFilter,
301
302
  'interaction.poptip': Poptip,
303
+ 'interaction.treemapDrillDown': TreemapDrillDown,
302
304
  'composition.spaceLayer': SpaceLayer,
303
305
  'composition.spaceFlex': SpaceFlex,
304
306
  'composition.facetRect': FacetRect,
package/src/mark/chord.ts CHANGED
@@ -51,7 +51,6 @@ const DEFAULT_LINK_OPTIONS = {
51
51
  style: {
52
52
  opacity: 0.5,
53
53
  lineWidth: 1,
54
- strokeWidth: 1,
55
54
  },
56
55
  };
57
56
 
package/src/mark/gauge.ts CHANGED
@@ -9,6 +9,7 @@ import { getTransformOptions } from '../utils/coordinate';
9
9
  import { Radial } from '../coordinate';
10
10
  import { applyStyle, getOrigin } from '../shape/utils';
11
11
  import { select } from '../utils/selection';
12
+ import { GaugeRound } from '../shape';
12
13
 
13
14
  const indicatorShape: SC<ColorOptions> = (options, context) => {
14
15
  const { shape, radius, ...style } = options;
@@ -215,13 +216,16 @@ export const Gauge: CC<GaugeOptions> = (options) => {
215
216
  // pointer + pin
216
217
  const indicatorStyle = filterPrefixObject(style, ['pointer', 'pin']);
217
218
 
219
+ const arcStyle = subObject(style, 'arc');
220
+ const shape = arcStyle.shape;
221
+
218
222
  return [
219
223
  deepMix({}, DEFAULT_OPTIONS, {
220
224
  type: 'interval',
221
225
  transform: [{ type: 'stackY' }],
222
226
  data: totalData,
223
227
  scale: newScale,
224
- style: subObject(style, 'arc'),
228
+ style: shape === 'round' ? { ...arcStyle, shape: GaugeRound } : arcStyle,
225
229
  animate:
226
230
  typeof animate === 'object' ? subObject(animate, 'arc') : animate,
227
231
  ...resOptions,
@@ -136,7 +136,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
136
136
  labels: linkLabels,
137
137
  style: {
138
138
  fill: linkEncode.color ? undefined : '#aaa',
139
- strokeWidth: 0,
139
+ lineWidth: 0,
140
140
  ...subObject(style, 'link'),
141
141
  },
142
142
  tooltip: linkTooltip,
@@ -1,111 +1,12 @@
1
- import { deepMix } from '@antv/util';
2
- import {
3
- treemap as treemapLayout,
4
- treemapBinary,
5
- treemapDice,
6
- treemapSlice,
7
- treemapSliceDice,
8
- treemapSquarify,
9
- treemapResquarify,
10
- } from 'd3-hierarchy';
1
+ import { deepMix, get, last } from '@antv/util';
11
2
  import { subObject } from '../utils/helper';
12
3
  import { CompositionComponent as CC } from '../runtime';
13
4
  import { TreemapMark } from '../spec';
14
5
  import { maybeTooltip } from '../utils/mark';
15
- import { generateHierarchyRoot, field } from './utils';
6
+ import { treeDataTransform } from '../utils/treeDataTransform';
16
7
 
17
8
  export type TreemapOptions = Omit<TreemapMark, 'type'>;
18
9
 
19
- type Layout = {
20
- tile?:
21
- | 'treemapBinary'
22
- | 'treemapDice'
23
- | 'treemapSlice'
24
- | 'treemapSliceDice'
25
- | 'treemapSquarify'
26
- | 'treemapResquarify';
27
- size?: [number, number];
28
- round?: boolean;
29
- // Ignore the value of the parent node when calculating the total value.
30
- ignoreParentValue?: boolean;
31
- ratio?: number;
32
- padding?: number;
33
- paddingInner?: number;
34
- paddingOuter?: number;
35
- paddingTop?: number;
36
- paddingRight?: number;
37
- paddingBottom?: number;
38
- paddingLeft?: number;
39
- sort?(a: any, b: any): number;
40
- path?: (d: any) => any;
41
- /** The granularity of Display layer. */
42
- layer?: number | ((d: any) => any);
43
- };
44
-
45
- type TreemapData = {
46
- name: string;
47
- children: TreemapData[];
48
- [key: string]: any;
49
- }[];
50
-
51
- function getTileMethod(tile: string, ratio: number) {
52
- const tiles = {
53
- treemapBinary,
54
- treemapDice,
55
- treemapSlice,
56
- treemapSliceDice,
57
- treemapSquarify,
58
- treemapResquarify,
59
- };
60
- const tileMethod =
61
- tile === 'treemapSquarify' ? tiles[tile].ratio(ratio) : tiles[tile];
62
- if (!tileMethod) {
63
- throw new TypeError('Invalid tile method!');
64
- }
65
- return tileMethod;
66
- }
67
-
68
- function dataTransform(data, layout: Layout, encode): TreemapData {
69
- const { value } = encode;
70
- const tileMethod = getTileMethod(layout.tile, layout.ratio);
71
- const root = generateHierarchyRoot(data, layout.path);
72
-
73
- // Calculate the value and sort.
74
- value
75
- ? root
76
- .sum((d) =>
77
- layout.ignoreParentValue && d.children ? 0 : field(value)(d),
78
- )
79
- .sort(layout.sort)
80
- : root.count();
81
-
82
- treemapLayout()
83
- .tile(tileMethod)
84
- // @ts-ignore
85
- .size(layout.size)
86
- .round(layout.round)
87
- .paddingInner(layout.paddingInner)
88
- .paddingOuter(layout.paddingOuter)
89
- .paddingTop(layout.paddingTop)
90
- .paddingRight(layout.paddingRight)
91
- .paddingBottom(layout.paddingBottom)
92
- .paddingLeft(layout.paddingLeft)(root);
93
-
94
- return root
95
- .descendants()
96
- .map((d) =>
97
- Object.assign(d, {
98
- x: [d.x0, d.x1],
99
- y: [d.y0, d.y1],
100
- }),
101
- )
102
- .filter(
103
- typeof layout.layer === 'function'
104
- ? layout.layer
105
- : (d) => d.height === layout.layer,
106
- );
107
- }
108
-
109
10
  // Defaults
110
11
  const GET_DEFAULT_LAYOUT_OPTIONS = (width, height) => ({
111
12
  tile: 'treemapSquarify',
@@ -130,7 +31,8 @@ const GET_DEFAULT_OPTIONS = (width, height) => ({
130
31
  encode: {
131
32
  x: 'x',
132
33
  y: 'y',
133
- color: (d) => d.data.parent.name,
34
+ key: 'id',
35
+ color: (d) => d.path[1],
134
36
  },
135
37
  scale: {
136
38
  x: { domain: [0, width], range: [0, 1] },
@@ -139,11 +41,15 @@ const GET_DEFAULT_OPTIONS = (width, height) => ({
139
41
  style: {
140
42
  stroke: '#fff',
141
43
  },
44
+ state: {
45
+ active: { opacity: 0.6 },
46
+ inactive: { opacity: 1 },
47
+ },
142
48
  });
143
49
 
144
50
  const DEFAULT_LABEL_OPTIONS = {
145
51
  fontSize: 10,
146
- text: (d) => d.data.name,
52
+ text: (d) => last(d.path),
147
53
  position: 'inside',
148
54
  fill: '#000',
149
55
  textOverflow: 'clip',
@@ -153,12 +59,17 @@ const DEFAULT_LABEL_OPTIONS = {
153
59
  };
154
60
 
155
61
  const DEFAULT_TOOLTIP_OPTIONS = {
156
- title: (d) => d.data.name,
62
+ title: (d) => d.path?.join?.('.'),
63
+ items: [{ field: 'value' }],
64
+ };
65
+
66
+ const DEFAULT_TOOLTIP_OPTIONS_DRILL = {
67
+ title: (d) => last(d.path),
157
68
  items: [{ field: 'value' }],
158
69
  };
159
70
 
160
71
  export const Treemap: CC<TreemapOptions> = (options, context) => {
161
- const { width, height } = context;
72
+ const { width, height, options: markOptions } = context;
162
73
 
163
74
  const {
164
75
  data,
@@ -171,32 +82,74 @@ export const Treemap: CC<TreemapOptions> = (options, context) => {
171
82
  ...resOptions
172
83
  } = options;
173
84
 
85
+ const treemapDrillDown = get(markOptions, [
86
+ 'interaction',
87
+ 'treemapDrillDown',
88
+ ]);
89
+
90
+ // Layout
91
+ const layoutOptions = deepMix(
92
+ {},
93
+ GET_DEFAULT_LAYOUT_OPTIONS(width, height),
94
+ layout,
95
+ {
96
+ layer: treemapDrillDown
97
+ ? (d) => {
98
+ return d.depth === 1;
99
+ }
100
+ : layout.layer,
101
+ },
102
+ );
103
+
174
104
  // Data
175
- const transformedData = dataTransform(
105
+ const [transformedData, transformedDataAll] = treeDataTransform(
176
106
  data,
177
- deepMix({}, GET_DEFAULT_LAYOUT_OPTIONS(width, height), layout),
107
+ layoutOptions,
178
108
  encode,
179
109
  );
180
110
 
181
111
  // Label
182
112
  const labelStyle = subObject(style, 'label');
183
113
 
184
- return deepMix({}, GET_DEFAULT_OPTIONS(width, height), {
185
- data: transformedData,
186
- encode,
187
- scale,
188
- style,
189
- labels: [
190
- {
191
- ...DEFAULT_LABEL_OPTIONS,
192
- ...labelStyle,
193
- },
194
- ...labels,
195
- ],
196
- ...resOptions,
197
- tooltip: maybeTooltip(tooltip, DEFAULT_TOOLTIP_OPTIONS),
198
- axis: false,
199
- });
114
+ return deepMix(
115
+ {},
116
+ GET_DEFAULT_OPTIONS(width, height),
117
+ {
118
+ data: transformedData,
119
+ scale,
120
+ style,
121
+ labels: [
122
+ {
123
+ ...DEFAULT_LABEL_OPTIONS,
124
+ ...labelStyle,
125
+ },
126
+ ...labels,
127
+ ],
128
+ ...resOptions,
129
+ encode,
130
+ tooltip: maybeTooltip(tooltip, DEFAULT_TOOLTIP_OPTIONS),
131
+ axis: false,
132
+ },
133
+ treemapDrillDown
134
+ ? {
135
+ interaction: {
136
+ ...resOptions.interaction,
137
+ treemapDrillDown: treemapDrillDown
138
+ ? {
139
+ ...treemapDrillDown,
140
+ originData: transformedDataAll,
141
+ layout: layoutOptions,
142
+ }
143
+ : undefined,
144
+ },
145
+ encode: {
146
+ color: (d) => last(d.path),
147
+ ...encode,
148
+ },
149
+ tooltip: maybeTooltip(tooltip, DEFAULT_TOOLTIP_OPTIONS_DRILL),
150
+ }
151
+ : {},
152
+ );
200
153
  };
201
154
 
202
155
  Treemap.props = {};
package/src/mark/utils.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Band } from '@antv/scale';
2
- import { stratify, hierarchy } from 'd3-hierarchy';
3
2
  import { Primitive } from 'd3-array';
4
3
  import { Vector2 } from '@antv/coord';
5
4
  import { Scale } from '../runtime/types/component';
@@ -156,19 +155,3 @@ export function initializeData(
156
155
  nodes: nodes || Array.from(new Set([...LS, ...LT]), (key) => ({ key })),
157
156
  };
158
157
  }
159
-
160
- /**
161
- * @description Path need when the data is a flat json structure,
162
- * and the tree object structure do not need.
163
- */
164
- export function generateHierarchyRoot(
165
- data: any[] | Record<string, any>,
166
- path: (d: any) => any,
167
- ) {
168
- if (Array.isArray(data)) {
169
- return typeof path === 'function'
170
- ? stratify().path(path)(data)
171
- : stratify()(data);
172
- }
173
- return hierarchy(data);
174
- }