Пример #1
0
def determineCollapsedNodes(tipsToCollapse, keepVisibleNodeIds, renderInfo,
                            collapsedNodeInfo):

    for id in reversed(renderInfo.collapseOrder.ids):

        nodeInfo = renderInfo.nodeInfo[id]

        if (id not in keepVisibleNodeIds):

            toCollapse = True

            for colNode in collapsedNodeInfo:

                if (colNode['nodeId'] == id):
                    toCollapse = False
                    break

                if (util.isAncestor(
                        Storage(next=colNode['next'], back=colNode['back']),
                        Storage(next=nodeInfo['next'],
                                back=nodeInfo['back']))):
                    toCollapse = False
                    break

            if (toCollapse):

                tipsAlreadyCollapsedByDescendants = 0

                for colNode in collapsedNodeInfo:

                    if (util.isDescendant(
                            Storage(next=colNode['next'],
                                    back=colNode['back']),
                            Storage(next=nodeInfo['next'],
                                    back=nodeInfo['back']))):

                        tipsAlreadyCollapsedByDescendants += colNode[
                            'descendantTipCount']
                        collapsedNodeInfo.remove(colNode)

                tipsToCollapse = tipsToCollapse - nodeInfo[
                    'descendantTipCount'] + tipsAlreadyCollapsedByDescendants

                collapsedNodeInfo.append(nodeInfo)

                if (tipsAlreadyCollapsedByDescendants == 0):
                    tipsToCollapse += 1

                if (tipsToCollapse <= 0):
                    break
Пример #2
0
def replaceClade(db, session, request, auth):

    replacedNodeId = int(request.vars.replacedNodeId)
    replacingNodeId = int(request.vars.replacingNodeId)

    columnIndex = int(request.vars.columnIndex)

    treeState = session.TreeViewer.treeState[session.TreeViewer.treeType][
        session.TreeViewer.treeId]
    columnInfo = treeState.columns[columnIndex]

    replacedCladeRow = db(
        db[session.TreeViewer.strNodeTable].id == replacedNodeId).select()[0]

    tree = getattr(build, ''.join([session.TreeViewer.treeType,
                                   'Clade']))(db,
                                              treeState.columns[0].rootNodeId,
                                              Storage())
    replacingClade = getattr(
        build, ''.join([request.vars.replacingNodeTreeType,
                        'Clade']))(db, replacingNodeId, Storage())

    graftUtil.replaceClade(tree, replacedNodeId, replacingClade)

    if (session.TreeViewer.treeType == 'grafted'):

        for (collapsedNodeId,
             collapsedNodeData) in columnInfo.collapsedNodeStorage.items():

            if (util.isAncestor(replacedCladeRow, collapsedNodeData)):

                del columnInfo.collapsedNodeStorage[collapsedNodeId]

                if( ( ( len( treeState.columns ) - 1 ) > columnIndex ) and \
                      ( collapsedNodeId == treeState.columns[ columnIndex + 1 ].rootNodeId ) ):

                    while ((len(treeState.columns) - 1) > columnIndex):
                        treeState.columns.pop()

    graftUtil.postReplaceDBUpdate(db, session, request, auth, tree,
                                  replacedCladeRow, replacingClade)

    return dict()
Пример #3
0
def determineCollapsedNodes(session, renderInfo, tipsToCollapse, columnInfo):

    formerlyCollapsedNodeStorage = session.TreeViewer.treeState[
        session.TreeViewer.treeType][
            session.TreeViewer.treeId].formerlyCollapsedNodeStorage

    nodesToCollapseStorage = Storage()

    for id in reversed(renderInfo.collapseOrder.ids):

        nodeInfo = renderInfo.nodeInfo[id]

        if (id not in columnInfo.keepVisibleNodeStorage):

            toCollapse = True

            combined = dict(columnInfo.collapsedNodeStorage.items() +
                            nodesToCollapseStorage.items())

            for (nodeId, collapsedNodeData) in combined.items():

                if (nodeId == id):
                    toCollapse = False
                    break

                if (util.isAncestor(collapsedNodeData, nodeInfo)):
                    toCollapse = False
                    break

            if (toCollapse):

                tipsAlreadyCollapsedByDescendants = 0

                for (nodeId, collapsedNodeData
                     ) in columnInfo.collapsedNodeStorage.items():

                    if (util.isDescendant(
                            Storage(next=collapsedNodeData['next'],
                                    back=collapsedNodeData['back']),
                            Storage(next=nodeInfo['next'],
                                    back=nodeInfo['back']))):

                        tipsAlreadyCollapsedByDescendants += collapsedNodeData[
                            'descendantTipCount']

                        if nodeId not in formerlyCollapsedNodeStorage:
                            formerlyCollapsedNodeStorage[
                                nodeId] = columnInfo.collapsedNodeStorage[
                                    nodeId]
                        del columnInfo.collapsedNodeStorage[nodeId]

                tipsToCollapse = tipsToCollapse - nodeInfo[
                    'descendantTipCount'] + tipsAlreadyCollapsedByDescendants

                for (nodeId,
                     collapsedNodeData) in nodesToCollapseStorage.items():

                    if (util.isDescendant(
                            Storage(next=collapsedNodeData['next'],
                                    back=collapsedNodeData['back']),
                            Storage(next=nodeInfo['next'],
                                    back=nodeInfo['back']))):
                        del nodesToCollapseStorage[nodeId]

                nodesToCollapseStorage[id] = nodeInfo

                if (tipsAlreadyCollapsedByDescendants == 0):
                    tipsToCollapse += 1

                if (tipsToCollapse <= 0):
                    break

    return nodesToCollapseStorage