3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
 
/*
* A third-party license is embeded for some of the code in this file:
* The treemap layout implementation was originally copied from
* "d3.js" with some modifications made for this project.
* (See more details in the comment of the method "squarify" below.)
* The use of the source code of this file is also subject to the terms
* and consitions of the license of "d3.js" (BSD-3Clause, see
* </licenses/LICENSE-d3>).
*/
 
import * as zrUtil from 'zrender/src/core/util';
import BoundingRect, { RectLike } from 'zrender/src/core/BoundingRect';
import {parsePercent, MAX_SAFE_INTEGER} from '../../util/number';
import * as layout from '../../util/layout';
import * as helper from '../helper/treeHelper';
import TreemapSeriesModel, { TreemapSeriesNodeItemOption } from './TreemapSeries';
import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import { TreeNode } from '../../data/Tree';
import Model from '../../model/Model';
import { TreemapRenderPayload, TreemapMovePayload, TreemapZoomToNodePayload } from './treemapAction';
 
const mathMax = Math.max;
const mathMin = Math.min;
const retrieveValue = zrUtil.retrieve;
const each = zrUtil.each;
 
const PATH_BORDER_WIDTH = ['itemStyle', 'borderWidth'] as const;
const PATH_GAP_WIDTH = ['itemStyle', 'gapWidth'] as const;
const PATH_UPPER_LABEL_SHOW = ['upperLabel', 'show'] as const;
const PATH_UPPER_LABEL_HEIGHT = ['upperLabel', 'height'] as const;
 
export interface TreemapLayoutNode extends TreeNode {
    parentNode: TreemapLayoutNode
    children: TreemapLayoutNode[]
    viewChildren: TreemapLayoutNode[]
}
 
export interface TreemapItemLayout extends RectLike {
    area: number
    isLeafRoot: boolean
    dataExtent: [number, number]
 
    borderWidth: number
    upperHeight: number
    upperLabelHeight: number
 
    isInView: boolean
    invisible: boolean
 
    isAboveViewRoot: boolean
};
 
type NodeModel = Model<TreemapSeriesNodeItemOption>;
 
type OrderBy = 'asc' | 'desc' | boolean;
 
type LayoutRow = TreemapLayoutNode[] & {
    area: number
};
/**
 * @public
 */
export default {
    seriesType: 'treemap',
    reset: function (
        seriesModel: TreemapSeriesModel,
        ecModel: GlobalModel,
        api: ExtensionAPI,
        payload?: TreemapZoomToNodePayload | TreemapRenderPayload | TreemapMovePayload
    ) {
        // Layout result in each node:
        // {x, y, width, height, area, borderWidth}
        const ecWidth = api.getWidth();
        const ecHeight = api.getHeight();
        const seriesOption = seriesModel.option;
 
        const layoutInfo = layout.getLayoutRect(
            seriesModel.getBoxLayoutParams(),
            {
                width: api.getWidth(),
                height: api.getHeight()
            }
        );
 
        const size = seriesOption.size || []; // Compatible with ec2.
        const containerWidth = parsePercent(
            retrieveValue(layoutInfo.width, size[0]),
            ecWidth
        );
        const containerHeight = parsePercent(
            retrieveValue(layoutInfo.height, size[1]),
            ecHeight
        );
 
        // Fetch payload info.
        const payloadType = payload && payload.type;
        const types = ['treemapZoomToNode', 'treemapRootToNode'];
        const targetInfo = helper
            .retrieveTargetInfo(payload, types, seriesModel);
        const rootRect = (payloadType === 'treemapRender' || payloadType === 'treemapMove')
            ? payload.rootRect : null;
        const viewRoot = seriesModel.getViewRoot();
        const viewAbovePath = helper.getPathToRoot(viewRoot) as TreemapLayoutNode[];
 
        if (payloadType !== 'treemapMove') {
            const rootSize = payloadType === 'treemapZoomToNode'
                ? estimateRootSize(
                    seriesModel, targetInfo, viewRoot, containerWidth, containerHeight
                )
                : rootRect
                ? [rootRect.width, rootRect.height]
                : [containerWidth, containerHeight];
 
            let sort = seriesOption.sort;
            if (sort && sort !== 'asc' && sort !== 'desc') {
                // Default to be desc order.
                sort = 'desc';
            }
            const options = {
                squareRatio: seriesOption.squareRatio,
                sort: sort,
                leafDepth: seriesOption.leafDepth
            };
 
            // layout should be cleared because using updateView but not update.
            viewRoot.hostTree.clearLayouts();
 
            // TODO
            // optimize: if out of view clip, do not layout.
            // But take care that if do not render node out of view clip,
            // how to calculate start po
 
            let viewRootLayout = {
                x: 0,
                y: 0,
                width: rootSize[0],
                height: rootSize[1],
                area: rootSize[0] * rootSize[1]
            };
            viewRoot.setLayout(viewRootLayout);
 
            squarify(viewRoot, options, false, 0);
            // Supplement layout.
            viewRootLayout = viewRoot.getLayout();
            each(viewAbovePath, function (node, index) {
                const childValue = (viewAbovePath[index + 1] || viewRoot).getValue();
                node.setLayout(zrUtil.extend(
                    {
                        dataExtent: [childValue, childValue],
                        borderWidth: 0,
                        upperHeight: 0
                    },
                    viewRootLayout
                ));
            });
        }
 
        const treeRoot = seriesModel.getData().tree.root;
 
        treeRoot.setLayout(
            calculateRootPosition(layoutInfo, rootRect, targetInfo),
            true
        );
 
        seriesModel.setLayoutInfo(layoutInfo);
 
        // FIXME
        // 现在没有clip功能,暂时取ec高宽。
        prunning(
            treeRoot,
            // Transform to base element coordinate system.
            new BoundingRect(-layoutInfo.x, -layoutInfo.y, ecWidth, ecHeight),
            viewAbovePath,
            viewRoot,
            0
        );
    }
};
 
/**
 * Layout treemap with squarify algorithm.
 * The original presentation of this algorithm
 * was made by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
 * <https://graphics.ethz.ch/teaching/scivis_common/Literature/squarifiedTreeMaps.pdf>.
 * The implementation of this algorithm was originally copied from "d3.js"
 * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/layout/treemap.js>
 * with some modifications made for this program.
 * See the license statement at the head of this file.
 *
 * @protected
 * @param {module:echarts/data/Tree~TreeNode} node
 * @param {Object} options
 * @param {string} options.sort 'asc' or 'desc'
 * @param {number} options.squareRatio
 * @param {boolean} hideChildren
 * @param {number} depth
 */
function squarify(
    node: TreemapLayoutNode,
    options: {
        sort?: OrderBy
        squareRatio?: number
        leafDepth?: number
    },
    hideChildren: boolean,
    depth: number
) {
    let width;
    let height;
 
    if (node.isRemoved()) {
        return;
    }
 
    const thisLayout = node.getLayout();
    width = thisLayout.width;
    height = thisLayout.height;
 
    // Considering border and gap
    const nodeModel = node.getModel<TreemapSeriesNodeItemOption>();
    const borderWidth = nodeModel.get(PATH_BORDER_WIDTH);
    const halfGapWidth = nodeModel.get(PATH_GAP_WIDTH) / 2;
    const upperLabelHeight = getUpperLabelHeight(nodeModel);
    const upperHeight = Math.max(borderWidth, upperLabelHeight);
    const layoutOffset = borderWidth - halfGapWidth;
    const layoutOffsetUpper = upperHeight - halfGapWidth;
 
    node.setLayout({
        borderWidth: borderWidth,
        upperHeight: upperHeight,
        upperLabelHeight: upperLabelHeight
    }, true);
 
    width = mathMax(width - 2 * layoutOffset, 0);
    height = mathMax(height - layoutOffset - layoutOffsetUpper, 0);
 
    const totalArea = width * height;
    const viewChildren = initChildren(
        node, nodeModel, totalArea, options, hideChildren, depth
    );
 
    if (!viewChildren.length) {
        return;
    }
 
    const rect = {x: layoutOffset, y: layoutOffsetUpper, width: width, height: height};
    let rowFixedLength = mathMin(width, height);
    let best = Infinity; // the best row score so far
    const row = [] as LayoutRow;
    row.area = 0;
 
    for (let i = 0, len = viewChildren.length; i < len;) {
        const child = viewChildren[i];
 
        row.push(child);
        row.area += child.getLayout().area;
        const score = worst(row, rowFixedLength, options.squareRatio);
 
        // continue with this orientation
        if (score <= best) {
            i++;
            best = score;
        }
        // abort, and try a different orientation
        else {
            row.area -= row.pop().getLayout().area;
            position(row, rowFixedLength, rect, halfGapWidth, false);
            rowFixedLength = mathMin(rect.width, rect.height);
            row.length = row.area = 0;
            best = Infinity;
        }
    }
 
    if (row.length) {
        position(row, rowFixedLength, rect, halfGapWidth, true);
    }
 
    if (!hideChildren) {
        const childrenVisibleMin = nodeModel.get('childrenVisibleMin');
        if (childrenVisibleMin != null && totalArea < childrenVisibleMin) {
            hideChildren = true;
        }
    }
 
    for (let i = 0, len = viewChildren.length; i < len; i++) {
        squarify(viewChildren[i], options, hideChildren, depth + 1);
    }
}
 
/**
 * Set area to each child, and calculate data extent for visual coding.
 */
function initChildren(
    node: TreemapLayoutNode,
    nodeModel: NodeModel,
    totalArea: number,
    options: {
        sort?: OrderBy
        leafDepth?: number
    },
    hideChildren: boolean,
    depth: number
) {
    let viewChildren = node.children || [];
    let orderBy = options.sort;
    orderBy !== 'asc' && orderBy !== 'desc' && (orderBy = null);
 
    const overLeafDepth = options.leafDepth != null && options.leafDepth <= depth;
 
    // leafDepth has higher priority.
    if (hideChildren && !overLeafDepth) {
        return (node.viewChildren = []);
    }
 
    // Sort children, order by desc.
    viewChildren = zrUtil.filter(viewChildren, function (child) {
        return !child.isRemoved();
    });
 
    sort(viewChildren, orderBy);
 
    const info = statistic(nodeModel, viewChildren, orderBy);
 
    if (info.sum === 0) {
        return (node.viewChildren = []);
    }
 
    info.sum = filterByThreshold(nodeModel, totalArea, info.sum, orderBy, viewChildren);
 
    if (info.sum === 0) {
        return (node.viewChildren = []);
    }
 
    // Set area to each child.
    for (let i = 0, len = viewChildren.length; i < len; i++) {
        const area = viewChildren[i].getValue() as number / info.sum * totalArea;
        // Do not use setLayout({...}, true), because it is needed to clear last layout.
        viewChildren[i].setLayout({
            area: area
        });
    }
 
    if (overLeafDepth) {
        viewChildren.length && node.setLayout({
            isLeafRoot: true
        }, true);
        viewChildren.length = 0;
    }
 
    node.viewChildren = viewChildren;
    node.setLayout({
        dataExtent: info.dataExtent
    }, true);
 
    return viewChildren;
}
 
/**
 * Consider 'visibleMin'. Modify viewChildren and get new sum.
 */
function filterByThreshold(
    nodeModel: NodeModel,
    totalArea: number,
    sum: number,
    orderBy: OrderBy,
    orderedChildren: TreemapLayoutNode[]
) {
 
    // visibleMin is not supported yet when no option.sort.
    if (!orderBy) {
        return sum;
    }
 
    const visibleMin = nodeModel.get('visibleMin');
    const len = orderedChildren.length;
    let deletePoint = len;
 
    // Always travel from little value to big value.
    for (let i = len - 1; i >= 0; i--) {
        const value = orderedChildren[
            orderBy === 'asc' ? len - i - 1 : i
        ].getValue() as number;
 
        if (value / sum * totalArea < visibleMin) {
            deletePoint = i;
            sum -= value;
        }
    }
 
    orderBy === 'asc'
        ? orderedChildren.splice(0, len - deletePoint)
        : orderedChildren.splice(deletePoint, len - deletePoint);
 
    return sum;
}
 
/**
 * Sort
 */
function sort(
    viewChildren: TreemapLayoutNode[],
    orderBy: OrderBy
) {
    if (orderBy) {
        viewChildren.sort(function (a, b) {
            const diff = orderBy === 'asc'
                ? a.getValue() as number - (b.getValue() as number)
                : b.getValue() as number - (a.getValue() as number);
            return diff === 0
                ? (orderBy === 'asc'
                    ? a.dataIndex - b.dataIndex : b.dataIndex - a.dataIndex
                )
                : diff;
        });
    }
    return viewChildren;
}
 
/**
 * Statistic
 */
function statistic(
    nodeModel: NodeModel,
    children: TreemapLayoutNode[],
    orderBy: OrderBy
) {
    // Calculate sum.
    let sum = 0;
    for (let i = 0, len = children.length; i < len; i++) {
        sum += children[i].getValue() as number;
    }
 
    // Statistic data extent for latter visual coding.
    // Notice: data extent should be calculate based on raw children
    // but not filtered view children, otherwise visual mapping will not
    // be stable when zoom (where children is filtered by visibleMin).
 
    const dimension = nodeModel.get('visualDimension');
    let dataExtent: number[];
 
    // The same as area dimension.
    if (!children || !children.length) {
        dataExtent = [NaN, NaN];
    }
    else if (dimension === 'value' && orderBy) {
        dataExtent = [
            children[children.length - 1].getValue() as number,
            children[0].getValue() as number
        ];
        orderBy === 'asc' && dataExtent.reverse();
    }
    // Other dimension.
    else {
        dataExtent = [Infinity, -Infinity];
        each(children, function (child) {
            const value = child.getValue(dimension) as number;
            value < dataExtent[0] && (dataExtent[0] = value);
            value > dataExtent[1] && (dataExtent[1] = value);
        });
    }
 
    return {sum: sum, dataExtent: dataExtent};
}
 
/**
 * Computes the score for the specified row,
 * as the worst aspect ratio.
 */
function worst(row: LayoutRow, rowFixedLength: number, ratio: number) {
    let areaMax = 0;
    let areaMin = Infinity;
 
    for (let i = 0, area, len = row.length; i < len; i++) {
        area = row[i].getLayout().area;
        if (area) {
            area < areaMin && (areaMin = area);
            area > areaMax && (areaMax = area);
        }
    }
 
    const squareArea = row.area * row.area;
    const f = rowFixedLength * rowFixedLength * ratio;
 
    return squareArea
        ? mathMax(
            (f * areaMax) / squareArea,
            squareArea / (f * areaMin)
        )
        : Infinity;
}
 
/**
 * Positions the specified row of nodes. Modifies `rect`.
 */
function position(
    row: LayoutRow,
    rowFixedLength: number,
    rect: RectLike,
    halfGapWidth: number,
    flush?: boolean
) {
    // When rowFixedLength === rect.width,
    // it is horizontal subdivision,
    // rowFixedLength is the width of the subdivision,
    // rowOtherLength is the height of the subdivision,
    // and nodes will be positioned from left to right.
 
    // wh[idx0WhenH] means: when horizontal,
    //      wh[idx0WhenH] => wh[0] => 'width'.
    //      xy[idx1WhenH] => xy[1] => 'y'.
    const idx0WhenH = rowFixedLength === rect.width ? 0 : 1;
    const idx1WhenH = 1 - idx0WhenH;
    const xy = ['x', 'y'] as const;
    const wh = ['width', 'height'] as const;
 
    let last = rect[xy[idx0WhenH]];
    let rowOtherLength = rowFixedLength
        ? row.area / rowFixedLength : 0;
 
    if (flush || rowOtherLength > rect[wh[idx1WhenH]]) {
        rowOtherLength = rect[wh[idx1WhenH]]; // over+underflow
    }
    for (let i = 0, rowLen = row.length; i < rowLen; i++) {
        const node = row[i];
        const nodeLayout = {} as TreemapItemLayout;
        const step = rowOtherLength
            ? node.getLayout().area / rowOtherLength : 0;
 
        const wh1 = nodeLayout[wh[idx1WhenH]] = mathMax(rowOtherLength - 2 * halfGapWidth, 0);
 
        // We use Math.max/min to avoid negative width/height when considering gap width.
        const remain = rect[xy[idx0WhenH]] + rect[wh[idx0WhenH]] - last;
        const modWH = (i === rowLen - 1 || remain < step) ? remain : step;
        const wh0 = nodeLayout[wh[idx0WhenH]] = mathMax(modWH - 2 * halfGapWidth, 0);
 
        nodeLayout[xy[idx1WhenH]] = rect[xy[idx1WhenH]] + mathMin(halfGapWidth, wh1 / 2);
        nodeLayout[xy[idx0WhenH]] = last + mathMin(halfGapWidth, wh0 / 2);
 
        last += modWH;
        node.setLayout(nodeLayout, true);
    }
 
    rect[xy[idx1WhenH]] += rowOtherLength;
    rect[wh[idx1WhenH]] -= rowOtherLength;
}
 
// Return [containerWidth, containerHeight] as default.
function estimateRootSize(
    seriesModel: TreemapSeriesModel,
    targetInfo: { node: TreemapLayoutNode },
    viewRoot: TreemapLayoutNode,
    containerWidth: number,
    containerHeight: number
) {
    // If targetInfo.node exists, we zoom to the node,
    // so estimate whold width and heigth by target node.
    let currNode = (targetInfo || {}).node;
    const defaultSize = [containerWidth, containerHeight];
 
    if (!currNode || currNode === viewRoot) {
        return defaultSize;
    }
 
    let parent;
    const viewArea = containerWidth * containerHeight;
    let area = viewArea * seriesModel.option.zoomToNodeRatio;
 
    while (parent = currNode.parentNode) { // jshint ignore:line
        let sum = 0;
        const siblings = parent.children;
 
        for (let i = 0, len = siblings.length; i < len; i++) {
            sum += siblings[i].getValue() as number;
        }
        const currNodeValue = currNode.getValue() as number;
        if (currNodeValue === 0) {
            return defaultSize;
        }
        area *= sum / currNodeValue;
 
        // Considering border, suppose aspect ratio is 1.
        const parentModel = parent.getModel<TreemapSeriesNodeItemOption>();
        const borderWidth = parentModel.get(PATH_BORDER_WIDTH);
        const upperHeight = Math.max(borderWidth, getUpperLabelHeight(parentModel));
        area += 4 * borderWidth * borderWidth
            + (3 * borderWidth + upperHeight) * Math.pow(area, 0.5);
 
        area > MAX_SAFE_INTEGER && (area = MAX_SAFE_INTEGER);
 
        currNode = parent;
    }
 
    area < viewArea && (area = viewArea);
    const scale = Math.pow(area / viewArea, 0.5);
 
    return [containerWidth * scale, containerHeight * scale];
}
 
// Root postion base on coord of containerGroup
function calculateRootPosition(
    layoutInfo: layout.LayoutRect,
    rootRect: RectLike,
    targetInfo: { node: TreemapLayoutNode }
) {
    if (rootRect) {
        return {x: rootRect.x, y: rootRect.y};
    }
 
    const defaultPosition = {x: 0, y: 0};
    if (!targetInfo) {
        return defaultPosition;
    }
 
    // If targetInfo is fetched by 'retrieveTargetInfo',
    // old tree and new tree are the same tree,
    // so the node still exists and we can visit it.
 
    const targetNode = targetInfo.node;
    const layout = targetNode.getLayout();
 
    if (!layout) {
        return defaultPosition;
    }
 
    // Transform coord from local to container.
    const targetCenter = [layout.width / 2, layout.height / 2];
    let node = targetNode;
    while (node) {
        const nodeLayout = node.getLayout();
        targetCenter[0] += nodeLayout.x;
        targetCenter[1] += nodeLayout.y;
        node = node.parentNode;
    }
 
    return {
        x: layoutInfo.width / 2 - targetCenter[0],
        y: layoutInfo.height / 2 - targetCenter[1]
    };
}
 
// Mark nodes visible for prunning when visual coding and rendering.
// Prunning depends on layout and root position, so we have to do it after layout.
function prunning(
    node: TreemapLayoutNode,
    clipRect: BoundingRect,
    viewAbovePath: TreemapLayoutNode[],
    viewRoot: TreemapLayoutNode,
    depth: number
) {
    const nodeLayout = node.getLayout();
    const nodeInViewAbovePath = viewAbovePath[depth];
    const isAboveViewRoot = nodeInViewAbovePath && nodeInViewAbovePath === node;
 
    if (
        (nodeInViewAbovePath && !isAboveViewRoot)
        || (depth === viewAbovePath.length && node !== viewRoot)
    ) {
        return;
    }
 
    node.setLayout({
        // isInView means: viewRoot sub tree + viewAbovePath
        isInView: true,
        // invisible only means: outside view clip so that the node can not
        // see but still layout for animation preparation but not render.
        invisible: !isAboveViewRoot && !clipRect.intersect(nodeLayout),
        isAboveViewRoot
    }, true);
 
    // Transform to child coordinate.
    const childClipRect = new BoundingRect(
        clipRect.x - nodeLayout.x,
        clipRect.y - nodeLayout.y,
        clipRect.width,
        clipRect.height
    );
 
    each(node.viewChildren || [], function (child) {
        prunning(child, childClipRect, viewAbovePath, viewRoot, depth + 1);
    });
}
 
function getUpperLabelHeight(model: NodeModel): number {
    return model.get(PATH_UPPER_LABEL_SHOW) ? model.get(PATH_UPPER_LABEL_HEIGHT) : 0;
}