Search in sources :

Example 1 with Subgraph

use of org.jgrapht.graph.Subgraph in project jop by jop-devel.

the class TypeGraph method exportDOT.

/**
     * Write the type graph in DOT format.
     * @param w
     * @param classFilter If non-null, only classes matching this prefix will be exported
     * @throws IOException
     */
public void exportDOT(Writer w, String classFilter) throws IOException {
    Set<ClassInfo> subset = null;
    if (classFilter != null) {
        subset = new HashSet<ClassInfo>();
        subset.add(this.rootNode);
        for (ClassInfo ci : this.vertexSet()) {
            if (ci.getClassName().startsWith(classFilter)) {
                while (ci.getSuperClassInfo() != null) {
                    subset.add(ci);
                    ci = ci.getSuperClassInfo();
                }
            }
        }
    }
    Subgraph<ClassInfo, DefaultEdge, TypeGraph> subgraph = new Subgraph<ClassInfo, DefaultEdge, TypeGraph>(this, subset);
    AdvancedDOTExporter<ClassInfo, DefaultEdge> exporter = new AdvancedDOTExporter<ClassInfo, DefaultEdge>(new TgNodeLabeller(), null);
    exporter.exportDOTDiGraph(w, subgraph);
}
Also used : Subgraph(org.jgrapht.graph.Subgraph) DefaultEdge(org.jgrapht.graph.DefaultEdge) ClassInfo(com.jopdesign.common.ClassInfo)

Example 2 with Subgraph

use of org.jgrapht.graph.Subgraph in project candle-decompiler by bradsdavis.

the class DOTExporter method export.

// ~ Methods ----------------------------------------------------------------
/**
 * Exports a graph into a plain text file in DOT format.
 *
 * @param writer the writer to which the graph to be exported
 * @param g the graph to be exported
 */
public void export(Writer writer, Graph<V, E> g, List<Subgraph> subGraphs) {
    PrintWriter out = new PrintWriter(writer);
    String indent = "  ";
    String connector;
    if (g instanceof DirectedGraph<?, ?>) {
        out.println("digraph G {");
        connector = " -> ";
    } else {
        out.println("graph G {");
        connector = " -- ";
    }
    if (subGraphs != null) {
        for (Subgraph sub : subGraphs) {
            this.subgraphExporter.export(writer, sub);
        }
    }
    for (V v : g.vertexSet()) {
        out.print(indent + getVertexID(v));
        String labelName = null;
        if (vertexLabelProvider != null) {
            labelName = vertexLabelProvider.getVertexName(v);
        }
        Map<String, String> attributes = null;
        if (vertexAttributeProvider != null) {
            attributes = vertexAttributeProvider.getComponentAttributes(v);
        }
        renderAttributes(out, labelName, attributes);
        out.println(";");
    }
    for (E e : g.edgeSet()) {
        String source = getVertexID(g.getEdgeSource(e));
        String target = getVertexID(g.getEdgeTarget(e));
        out.print(indent + source + connector + target);
        String labelName = null;
        if (edgeLabelProvider != null) {
            labelName = edgeLabelProvider.getEdgeName(e);
        }
        Map<String, String> attributes = null;
        if (edgeAttributeProvider != null) {
            attributes = edgeAttributeProvider.getComponentAttributes(e);
        }
        renderAttributes(out, labelName, attributes);
        out.println(";");
    }
    out.println("}");
    out.flush();
}
Also used : DirectedGraph(org.jgrapht.DirectedGraph) Subgraph(org.jgrapht.graph.Subgraph) PrintWriter(java.io.PrintWriter)

Aggregations

Subgraph (org.jgrapht.graph.Subgraph)2 ClassInfo (com.jopdesign.common.ClassInfo)1 PrintWriter (java.io.PrintWriter)1 DirectedGraph (org.jgrapht.DirectedGraph)1 DefaultEdge (org.jgrapht.graph.DefaultEdge)1