Search in sources :

Example 11 with DagSubgraph

use of com.randomnoun.build.javaToGraphviz.dag.DagSubgraph in project java-to-graphviz by randomnoun.

the class DagStyleApplier method moveToSubgraph.

/**
 * Moves a node into a subgraph (and all that nodes children, and it's childrens children, and it's childrens childrens children and so on and so forth.
 *
 * <p>This is only going to work if we don't clear the DagNode.children collection when we're pruning nodes, which conveniently it appears we don't do.
 *
 * <p>Will rejig the subgraph hierarchy if a child is already in a subgraph
 *
 * @param sg
 * @param dag
 * @param node
 */
public void moveToSubgraph(DagSubgraph sg, DagElement sgEl, Dag dag, Map<DagNode, DagElement> dagNodesToElements, DagNode node) {
    if (dag.dagNodeToSubgraph.containsKey(node)) {
        // throw new IllegalStateException("subgraph already contains node");
        // logger.warn("moving node to new subgraph");
        dag.dagNodeToSubgraph.get(node).nodes.remove(node);
    }
    sg.nodes.add(node);
    dag.dagNodeToSubgraph.put(node, sg);
    for (DagNode child : node.children) {
        // if they're already in a subgraph, that subgraph should become a subgraph of this subgraph.
        // this should always be an immediate subgraph as we're traversing this in depth-first order
        // a node can only be in 1 subgraph at a time.
        DagSubgraph ssg = dag.dagNodeToSubgraph.get(child);
        moveToSubgraph(sg, sgEl, dag, dagNodesToElements, child);
    // @TODO maybe this still needs to happen
    /*
            if (ssg != null) {
                if (ssg.container == sg) {
                    logger.warn("we're already in the right subgraph");
                } else {
                    logger.warn("rejigging subgraphs"); // hoist the rigging
                    ssg.container.getSubgraphs().remove(ssg);
                    sg.subgraphs.add(ssg);
                }
            } else {
                moveToSubgraph(sg, sgEl, dag, dagNodesToElements, child);
            }
            */
    }
}
Also used : DagNode(com.randomnoun.build.javaToGraphviz.dag.DagNode) DagSubgraph(com.randomnoun.build.javaToGraphviz.dag.DagSubgraph)

Aggregations

DagNode (com.randomnoun.build.javaToGraphviz.dag.DagNode)11 DagSubgraph (com.randomnoun.build.javaToGraphviz.dag.DagSubgraph)11 DagEdge (com.randomnoun.build.javaToGraphviz.dag.DagEdge)6 ExitEdge (com.randomnoun.build.javaToGraphviz.dag.ExitEdge)4 DagElement (com.randomnoun.build.javaToGraphviz.dom.DagElement)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 CommentText (com.randomnoun.build.javaToGraphviz.comment.CommentText)2 GvComment (com.randomnoun.build.javaToGraphviz.comment.GvComment)2 GvEndGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndGraphComment)2 GvEndSubgraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndSubgraphComment)2 GvGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvGraphComment)2 GvKeepNodeComment (com.randomnoun.build.javaToGraphviz.comment.GvKeepNodeComment)2 GvLiteralComment (com.randomnoun.build.javaToGraphviz.comment.GvLiteralComment)2 GvOptionComment (com.randomnoun.build.javaToGraphviz.comment.GvOptionComment)2 GvSubgraphComment (com.randomnoun.build.javaToGraphviz.comment.GvSubgraphComment)2 ExceptionErrorHandler (com.randomnoun.build.javaToGraphviz.dom.StylesheetApplier.ExceptionErrorHandler)2 CSSOMParser (com.steadystate.css.parser.CSSOMParser)2 ArrayList (java.util.ArrayList)2 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)2 Node (org.jsoup.nodes.Node)2