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);
}
*/
}
}
Aggregations