@antv/g2 5.1.13 → 5.1.15
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.
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/api/utils.js +27 -15
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +13 -7
- package/esm/component/axis.js.map +1 -1
- package/esm/coordinate/polar.d.ts +1 -1
- package/esm/coordinate/polar.js +3 -1
- package/esm/coordinate/polar.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/event.js +15 -3
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/legendFilter.d.ts +1 -0
- package/esm/interaction/legendFilter.js +6 -0
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/scrollbarFilter.js +5 -1
- package/esm/interaction/scrollbarFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.d.ts +1 -1
- package/esm/interaction/sliderFilter.js +19 -2
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +1 -1
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/treemapDrillDown.d.ts +10 -0
- package/esm/interaction/treemapDrillDown.js +229 -0
- package/esm/interaction/treemapDrillDown.js.map +1 -0
- package/esm/lib/core.d.ts +2 -1
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/treemap.js +37 -57
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/utils.d.ts +0 -5
- package/esm/mark/utils.js +0 -13
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/plot.js +46 -28
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -1
- package/esm/shape/utils.js +2 -2
- package/esm/shape/utils.js.map +1 -1
- package/esm/utils/angle.d.ts +4 -0
- package/esm/utils/angle.js +18 -0
- package/esm/utils/angle.js.map +1 -1
- package/esm/utils/treeDataTransform.d.ts +21 -0
- package/esm/utils/treeDataTransform.js +90 -0
- package/esm/utils/treeDataTransform.js.map +1 -0
- package/lib/api/utils.js +27 -15
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +13 -7
- package/lib/component/axis.js.map +1 -1
- package/lib/coordinate/polar.d.ts +1 -1
- package/lib/coordinate/polar.js +3 -1
- package/lib/coordinate/polar.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/event.js +15 -3
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/legendFilter.d.ts +1 -0
- package/lib/interaction/legendFilter.js +8 -1
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/scrollbarFilter.js +5 -1
- package/lib/interaction/scrollbarFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.d.ts +1 -1
- package/lib/interaction/sliderFilter.js +19 -2
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +1 -1
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/treemapDrillDown.d.ts +10 -0
- package/lib/interaction/treemapDrillDown.js +233 -0
- package/lib/interaction/treemapDrillDown.js.map +1 -0
- package/lib/lib/core.d.ts +2 -1
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/treemap.js +36 -56
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/utils.d.ts +0 -5
- package/lib/mark/utils.js +1 -15
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/plot.js +45 -27
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/utils/angle.d.ts +4 -0
- package/lib/utils/angle.js +20 -1
- package/lib/utils/angle.js.map +1 -1
- package/lib/utils/treeDataTransform.d.ts +21 -0
- package/lib/utils/treeDataTransform.js +94 -0
- package/lib/utils/treeDataTransform.js.map +1 -0
- package/package.json +3 -2
- package/src/api/utils.ts +41 -13
- package/src/component/axis.ts +17 -10
- package/src/coordinate/polar.ts +6 -1
- package/src/interaction/event.ts +20 -7
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +8 -0
- package/src/interaction/scrollbarFilter.ts +4 -0
- package/src/interaction/sliderFilter.ts +21 -1
- package/src/interaction/tooltip.ts +2 -2
- package/src/interaction/treemapDrillDown.ts +282 -0
- package/src/lib/core.ts +2 -0
- package/src/mark/treemap.ts +76 -123
- package/src/mark/utils.ts +0 -17
- package/src/runtime/plot.ts +79 -38
- package/src/runtime/types/common.ts +5 -1
- package/src/shape/utils.ts +3 -2
- package/src/utils/angle.ts +22 -0
- package/src/utils/treeDataTransform.ts +153 -0
package/src/runtime/plot.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector2 } from '@antv/coord';
|
|
2
2
|
import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
|
|
3
|
-
import { deepMix, upperFirst } from '@antv/util';
|
|
4
|
-
import { group, groups
|
|
3
|
+
import { deepMix, upperFirst, isArray } from '@antv/util';
|
|
4
|
+
import { group, groups } from 'd3-array';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
7
|
import { ChartEvent } from '../utils/event';
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
InteractionComponent,
|
|
67
67
|
LabelTransform,
|
|
68
68
|
LabelTransformComponent,
|
|
69
|
+
Scale,
|
|
69
70
|
Shape,
|
|
70
71
|
ShapeComponent,
|
|
71
72
|
Theme,
|
|
@@ -89,6 +90,8 @@ import {
|
|
|
89
90
|
G2ViewTree,
|
|
90
91
|
} from './types/options';
|
|
91
92
|
|
|
93
|
+
type Store = Map<any, (options: G2ViewTree) => G2ViewTree>;
|
|
94
|
+
|
|
92
95
|
export async function plot<T extends G2ViewTree>(
|
|
93
96
|
options: T,
|
|
94
97
|
selection: Selection,
|
|
@@ -241,12 +244,19 @@ export async function plot<T extends G2ViewTree>(
|
|
|
241
244
|
// Apply interactions.
|
|
242
245
|
const viewInstanceof = (
|
|
243
246
|
viewContainer: Map<G2ViewDescriptor, DisplayObject>,
|
|
247
|
+
updateInteractions?: (
|
|
248
|
+
container: Map<G2ViewDescriptor, DisplayObject>,
|
|
249
|
+
updateTypes?: string[],
|
|
250
|
+
store?: Store,
|
|
251
|
+
) => void,
|
|
252
|
+
oldStore?: Store,
|
|
244
253
|
) => {
|
|
245
254
|
return Array.from(viewContainer.entries()).map(([view, container]) => {
|
|
246
255
|
// Index state by component or interaction name,
|
|
247
256
|
// such as legend, scrollbar, brushFilter.
|
|
248
257
|
// Each state transform options to another options.
|
|
249
|
-
const store =
|
|
258
|
+
const store =
|
|
259
|
+
oldStore || new Map<any, (options: G2ViewTree) => G2ViewTree>();
|
|
250
260
|
const setState = (key, reducer = (x) => x) => store.set(key, reducer);
|
|
251
261
|
const options = viewNode.get(view);
|
|
252
262
|
const update = createUpdateView(
|
|
@@ -260,18 +270,68 @@ export async function plot<T extends G2ViewTree>(
|
|
|
260
270
|
container,
|
|
261
271
|
options,
|
|
262
272
|
setState,
|
|
263
|
-
update: async (from) => {
|
|
273
|
+
update: async (from, updateTypes) => {
|
|
264
274
|
// Apply all state functions to get new options.
|
|
265
275
|
const reducer = compose(Array.from(store.values()));
|
|
266
276
|
const newOptions = reducer(options);
|
|
267
|
-
return await update(newOptions, from)
|
|
277
|
+
return await update(newOptions, from, () => {
|
|
278
|
+
if (isArray(updateTypes)) {
|
|
279
|
+
updateInteractions(viewContainer, updateTypes, store);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
268
282
|
},
|
|
269
283
|
};
|
|
270
284
|
});
|
|
271
285
|
};
|
|
272
286
|
|
|
287
|
+
const updateInteractions = (
|
|
288
|
+
container = updateContainer,
|
|
289
|
+
updateType?: string[],
|
|
290
|
+
oldStore?: Map<any, (options: G2ViewTree) => G2ViewTree>,
|
|
291
|
+
) => {
|
|
292
|
+
// Interactions for update views.
|
|
293
|
+
const updateViewInstances = viewInstanceof(
|
|
294
|
+
container,
|
|
295
|
+
updateInteractions,
|
|
296
|
+
oldStore,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
for (const target of updateViewInstances) {
|
|
300
|
+
const { options, container } = target;
|
|
301
|
+
const nameInteraction = container['nameInteraction'];
|
|
302
|
+
let typeOptions = inferInteraction(options);
|
|
303
|
+
|
|
304
|
+
if (updateType) {
|
|
305
|
+
typeOptions = typeOptions.filter((v) => updateType.includes(v[0]));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
for (const typeOption of typeOptions) {
|
|
309
|
+
const [type, option] = typeOption;
|
|
310
|
+
// Remove interaction for existed views.
|
|
311
|
+
const prevInteraction = nameInteraction.get(type);
|
|
312
|
+
if (prevInteraction) prevInteraction.destroy?.();
|
|
313
|
+
|
|
314
|
+
// Apply new interaction.
|
|
315
|
+
if (option) {
|
|
316
|
+
const interaction = useThemeInteraction(
|
|
317
|
+
target.view,
|
|
318
|
+
type,
|
|
319
|
+
option as Record<string, any>,
|
|
320
|
+
useInteraction,
|
|
321
|
+
);
|
|
322
|
+
const destroy = interaction(
|
|
323
|
+
target,
|
|
324
|
+
updateViewInstances,
|
|
325
|
+
context.emitter,
|
|
326
|
+
);
|
|
327
|
+
nameInteraction.set(type, { destroy });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
273
333
|
// Interactions for enter views.
|
|
274
|
-
const enterViewInstances = viewInstanceof(enterContainer);
|
|
334
|
+
const enterViewInstances = viewInstanceof(enterContainer, updateInteractions);
|
|
275
335
|
for (const target of enterViewInstances) {
|
|
276
336
|
const { options } = target;
|
|
277
337
|
|
|
@@ -299,35 +359,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
299
359
|
}
|
|
300
360
|
}
|
|
301
361
|
|
|
302
|
-
|
|
303
|
-
const updateViewInstances = viewInstanceof(updateContainer);
|
|
304
|
-
for (const target of updateViewInstances) {
|
|
305
|
-
const { options, container } = target;
|
|
306
|
-
const nameInteraction = container['nameInteraction'];
|
|
307
|
-
for (const typeOption of inferInteraction(options)) {
|
|
308
|
-
const [type, option] = typeOption;
|
|
309
|
-
|
|
310
|
-
// Remove interaction for existed views.
|
|
311
|
-
const prevInteraction = nameInteraction.get(type);
|
|
312
|
-
if (prevInteraction) prevInteraction.destroy?.();
|
|
313
|
-
|
|
314
|
-
// Apply new interaction.
|
|
315
|
-
if (option) {
|
|
316
|
-
const interaction = useThemeInteraction(
|
|
317
|
-
target.view,
|
|
318
|
-
type,
|
|
319
|
-
option as Record<string, any>,
|
|
320
|
-
useInteraction,
|
|
321
|
-
);
|
|
322
|
-
const destroy = interaction(
|
|
323
|
-
target,
|
|
324
|
-
updateViewInstances,
|
|
325
|
-
context.emitter,
|
|
326
|
-
);
|
|
327
|
-
nameInteraction.set(type, { destroy });
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
362
|
+
updateInteractions();
|
|
331
363
|
|
|
332
364
|
// Author animations.
|
|
333
365
|
const { width, height } = options;
|
|
@@ -402,7 +434,7 @@ function createUpdateView(
|
|
|
402
434
|
.filter(filter)
|
|
403
435
|
.map((d) => d[0]);
|
|
404
436
|
|
|
405
|
-
return async (newOptions, source) => {
|
|
437
|
+
return async (newOptions, source, callback) => {
|
|
406
438
|
const transitions = [];
|
|
407
439
|
const [newView, newChildren] = await initializeView(newOptions, library);
|
|
408
440
|
plotView(newView, selection, transitions, library, context);
|
|
@@ -415,7 +447,7 @@ function createUpdateView(
|
|
|
415
447
|
for (const child of newChildren) {
|
|
416
448
|
plot(child, selection, library, context);
|
|
417
449
|
}
|
|
418
|
-
|
|
450
|
+
callback();
|
|
419
451
|
return { options: newOptions, view: newView };
|
|
420
452
|
};
|
|
421
453
|
}
|
|
@@ -710,7 +742,7 @@ function initializeState(
|
|
|
710
742
|
processAxisZ(components);
|
|
711
743
|
|
|
712
744
|
// Scale from marks and components.
|
|
713
|
-
const scaleInstance = {};
|
|
745
|
+
const scaleInstance: Record<string, Scale> = {};
|
|
714
746
|
|
|
715
747
|
// Initialize scale from components.
|
|
716
748
|
for (const component of components) {
|
|
@@ -720,8 +752,17 @@ function initializeState(
|
|
|
720
752
|
const { name } = descriptor;
|
|
721
753
|
const scale = useRelationScale(descriptor, library);
|
|
722
754
|
scales.push(scale);
|
|
755
|
+
// Delivery the scale of axisX to the AxisY,
|
|
756
|
+
// in order to calculate the angle of axisY component when rendering radar chart.
|
|
757
|
+
if (name === 'y') {
|
|
758
|
+
scale.update({
|
|
759
|
+
...scale.getOptions(),
|
|
760
|
+
xScale: scaleInstance.x,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
723
763
|
assignScale(scaleInstance, { [name]: scale });
|
|
724
764
|
}
|
|
765
|
+
|
|
725
766
|
component.scaleInstances = scales;
|
|
726
767
|
}
|
|
727
768
|
|
|
@@ -53,7 +53,11 @@ export type G2ViewInstance = {
|
|
|
53
53
|
view: G2ViewDescriptor;
|
|
54
54
|
container: DisplayObject;
|
|
55
55
|
options: G2ViewTree;
|
|
56
|
-
update: (
|
|
56
|
+
update: (
|
|
57
|
+
options: G2ViewTree,
|
|
58
|
+
source?: string | string[],
|
|
59
|
+
callback?: any,
|
|
60
|
+
) => Promise<any>;
|
|
57
61
|
};
|
|
58
62
|
|
|
59
63
|
export type ChannelGroups = {
|
package/src/shape/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Coordinate } from '@antv/coord';
|
|
2
2
|
import { Linear } from '@antv/scale';
|
|
3
|
-
import { lowerFirst } from '@antv/util';
|
|
3
|
+
import { isNumber, lowerFirst } from '@antv/util';
|
|
4
4
|
import { extent } from 'd3-array';
|
|
5
5
|
import { Path as D3Path } from 'd3-path';
|
|
6
6
|
import { Primitive, Vector2, Vector3 } from '../runtime';
|
|
@@ -148,7 +148,8 @@ export function computeGradient(
|
|
|
148
148
|
range: [0, 100],
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
const percentage = (i) =>
|
|
151
|
+
const percentage = (i) =>
|
|
152
|
+
isNumber(P[i]) && !Number.isNaN(P[i]) ? p.map(P[i]) : 0;
|
|
152
153
|
|
|
153
154
|
const gradientMode = {
|
|
154
155
|
// Interpolate the colors for this segment.
|
package/src/utils/angle.ts
CHANGED
|
@@ -5,3 +5,25 @@ export function toRadian(degree: number): number {
|
|
|
5
5
|
export function toDegree(radian: number): number {
|
|
6
6
|
return (radian * 180) / Math.PI;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
// convert the angle to the range of 0 to 4*Math.PI
|
|
10
|
+
export function convertAngles(startAngle: number, endAngle: number) {
|
|
11
|
+
startAngle = startAngle % (2 * Math.PI);
|
|
12
|
+
endAngle = endAngle % (2 * Math.PI);
|
|
13
|
+
|
|
14
|
+
if (startAngle < 0) {
|
|
15
|
+
startAngle = 2 * Math.PI + startAngle;
|
|
16
|
+
}
|
|
17
|
+
if (endAngle < 0) {
|
|
18
|
+
endAngle = 2 * Math.PI + endAngle;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (startAngle >= endAngle) {
|
|
22
|
+
endAngle = endAngle + 2 * Math.PI;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
startAngle,
|
|
27
|
+
endAngle,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -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
|
+
}
|