/** * Traverse tree recursively and generate dot code for vertices. * * @param n The root node. * @param eoiCounter The counter for the execution order index. * @param nodeIds The map containing the node IDs. * @param ps The stream on which the generated code will be printed. * @param includeWeights Determines whether to include weights or not. */ private static void dotVerticesFromSubTree( final AbstractCallTreeNode<?> n, final AtomicInteger eoiCounter, final Map<AbstractCallTreeNode<?>, Integer> nodeIds, final PrintStream ps, final boolean includeWeights) { final int thisId = nodeIds.get(n); for (final WeightedDirectedCallTreeEdge<?> child : n.getChildEdges()) { final StringBuilder strBuild = new StringBuilder(1024); final int childId = nodeIds.get(child.getTarget()); strBuild .append('\n') .append(thisId) .append("->") .append(childId) .append("[style=solid,arrowhead=none"); if (includeWeights) { strBuild.append(",label=\"").append(child.getTargetWeight().get()).append('"'); } else if (eoiCounter != null) { strBuild.append(",label=\"").append(eoiCounter.getAndIncrement()).append(".\""); } strBuild.append(" ]"); ps.println(strBuild.toString()); AbstractCallTreeFilter.dotVerticesFromSubTree( child.getTarget(), eoiCounter, nodeIds, ps, includeWeights); } }
/** * Traverse tree recursively and generate dot code for edges. * * @param n The root node to start with. * @param nodeIds The map containing the node IDs. * @param nextNodeId The counter for the IDs of the nodes. * @param ps The stream in which the dot code will be written. * @param shortLabels Determines whether to use short labels or not. */ private static void dotEdgesFromSubTree( final AbstractCallTreeNode<?> n, final Map<AbstractCallTreeNode<?>, Integer> nodeIds, final AtomicInteger nextNodeId, final PrintStream ps, final boolean shortLabels) { final StringBuilder strBuild = new StringBuilder(64); nodeIds.put(n, nextNodeId.get()); strBuild .append(nextNodeId.getAndIncrement()) .append("[label =\"") .append( n.isRootNode() ? SystemModelRepository.ROOT_NODE_LABEL // NOCS : AbstractCallTreeFilter.nodeLabel(n, shortLabels)) // NOCS .append("\",shape=" + DotFactory.DOT_SHAPE_NONE + "];"); ps.println(strBuild.toString()); for (final WeightedDirectedCallTreeEdge<?> child : n.getChildEdges()) { AbstractCallTreeFilter.dotEdgesFromSubTree( child.getTarget(), nodeIds, nextNodeId, ps, shortLabels); } }