all files / diagram/layout/ mind-map.js

98.68% Statements 75/76
86.05% Branches 37/43
100% Functions 11/11
98.68% Lines 75/76
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   10×     46813×   27× 27× 13×     14× 14× 14× 14× 14× 14×         27× 27× 27× 27× 27× 27× 27× 101× 101× 101× 101×   27× 27× 27× 27× 23×   27× 18×     27× 199× 199× 199×   12×   187×       14×   41×                 41×       41×   41× 41× 41× 41×   75× 75× 75× 41×     34×   75×   82× 164× 164× 164×     27× 27× 27× 25× 101× 101×     27×        
define(["require", "exports", "../primitives/rect", "../utility/base-util", "./hierarchical-tree"], function (require, exports, rect_1, base_util_1, hierarchical_tree_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MindMap = (function () {
        function MindMap() {
            this.isAnimation = false;
        }
        MindMap.prototype.destroy = function () {
        };
        MindMap.prototype.getModuleName = function () {
            return 'MindMapChart';
        };
        MindMap.prototype.updateLayout = function (nodes, nameTable, layoutProp, viewPort, uniqueId, root) {
            var isRoot = this.checkRoot(nodes, layoutProp, uniqueId, root, nameTable);
            if (isRoot) {
                layoutProp.fixedNode = isRoot;
            }
            else {
                for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
                    var node = nodes_1[_i];
                    Eif (!node.excludeFromLayout) {
                        Eif (!node.inEdges || !node.inEdges.length) {
                            layoutProp.fixedNode = node.id;
                            break;
                        }
                    }
                }
            }
            var rootNode = nameTable[layoutProp.fixedNode];
            var fistLevelNodes = this.findFirstLevelNodes(rootNode, layoutProp, nameTable);
            var leftNodes = [];
            var rightNodes = [];
            var getMindmapBranch = base_util_1.getFunction(layoutProp.getBranch);
            getMindmapBranch = getMindmapBranch || base_util_1.getFunction(this.getBranch);
            for (var _a = 0, fistLevelNodes_1 = fistLevelNodes; _a < fistLevelNodes_1.length; _a++) {
                var node = fistLevelNodes_1[_a];
                var align = getMindmapBranch(node, fistLevelNodes);
                align = node && node.branch ? node.branch : align;
                (align === 'Left') ? leftNodes.push(node) : rightNodes.push(node);
            }
            var viewPortBounds = new rect_1.Rect(0, 0, viewPort.x, viewPort.y);
            nameTable[layoutProp.fixedNode].offsetX = viewPortBounds.x + viewPortBounds.width / 2;
            nameTable[layoutProp.fixedNode].offsetY = viewPortBounds.y + viewPortBounds.height / 2;
            if (leftNodes.length) {
                this.updateMindMapBranch(nodes, rightNodes, nameTable, layoutProp, viewPort, uniqueId, 'Left');
            }
            if (rightNodes.length) {
                this.updateMindMapBranch(nodes, leftNodes, nameTable, layoutProp, viewPort, uniqueId, 'Right');
            }
        };
        MindMap.prototype.checkRoot = function (nodes, layoutProp, uniqueId, root, nameTable) {
            for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
                var node = nodes_2[_i];
                Eif (!node.excludeFromLayout) {
                    if (node.data && (node.data["" + uniqueId].toString() === root || node.data["" + uniqueId].toString()
                        === layoutProp.root)) {
                        return node.id;
                    }
                    else if (!node.data && node.id === layoutProp.root) {
                        return node.id;
                    }
                }
            }
            return '';
        };
        MindMap.prototype.updateMindMapBranch = function (nodes, excludeNodes, nameTable, layoutProp, viewPort, uniqueId, side) {
            var layout = {
                type: 'HierarchicalTree',
                horizontalSpacing: layoutProp.verticalSpacing, verticalSpacing: layoutProp.horizontalSpacing,
                verticalAlignment: layoutProp.verticalAlignment, horizontalAlignment: layoutProp.horizontalAlignment,
                fixedNode: layoutProp.fixedNode, getLayoutInfo: base_util_1.getFunction(layoutProp.getLayoutInfo),
                layoutInfo: layoutProp.layoutInfo, margin: layoutProp.margin,
                orientation: layoutProp.orientation,
                root: layoutProp.fixedNode
            };
            Iif (layout.orientation === 'Vertical') {
                layout.orientation = (side === 'Left') ? 'TopToBottom' : 'BottomToTop';
            }
            else {
                layout.orientation = (side === 'Left') ? 'LeftToRight' : 'RightToLeft';
            }
            this.excludeFromLayout(excludeNodes, nameTable, true);
            var mapLayout = new hierarchical_tree_1.HierarchicalTree();
            mapLayout.updateLayout(nodes, nameTable, layout, viewPort, uniqueId);
            this.excludeFromLayout(excludeNodes, nameTable, false);
        };
        MindMap.prototype.getBranch = function (obj, firstLevelNodes) {
            var side;
            var i = firstLevelNodes.indexOf(obj);
            if (i % 2 === 0) {
                side = 'Left';
            }
            else {
                side = 'Right';
            }
            return side;
        };
        MindMap.prototype.excludeFromLayout = function (newCollection, nameTable, exclude) {
            for (var _i = 0, newCollection_1 = newCollection; _i < newCollection_1.length; _i++) {
                var newcol = newCollection_1[_i];
                var node = nameTable[newcol.id];
                node.excludeFromLayout = exclude;
            }
        };
        MindMap.prototype.findFirstLevelNodes = function (node, layout, nameTable) {
            var parentNode;
            var fistLevelNodes = [];
            if (node && node.outEdges.length) {
                for (var _i = 0, _a = node.outEdges; _i < _a.length; _i++) {
                    var outEdge = _a[_i];
                    fistLevelNodes.push(nameTable[nameTable["" + outEdge].targetID]);
                }
            }
            return fistLevelNodes;
        };
        return MindMap;
    }());
    exports.MindMap = MindMap;
});