Skip to content
Snippets Groups Projects
Commit b2c6b624 authored by Sören Henning's avatar Sören Henning
Browse files

worked on graph exporting

parent 9eb005db
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
Pipeline #
Showing with 161 additions and 188 deletions
package kieker.analysis.graph;
public abstract interface GraphElement extends Element {
public void remove();
public Object getId();
}
package kieker.analysis.graph.export.dot;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import kieker.analysis.graph.Direction;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Element;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
import kieker.analysis.graph.export.AbstractTransformer;
import kieker.analysis.graph.util.dot.DotGraphWriter;
class DotElementExporter extends AbstractTransformer<Void> {
protected final DotGraphWriter dotGraphWriter;
protected DotElementExporter(final Graph graph, final DotGraphWriter dotGraphWriter) {
super(graph);
this.dotGraphWriter = dotGraphWriter;
}
@Override
protected void transformVertex(final Vertex vertex) {
try {
if (vertex.hasChildGraph()) {
Graph childGraph = vertex.getChildGraph();
dotGraphWriter.addClusterStart(childGraph.getName());
Map<String, String> attributes = transformProperties(vertex);
attributes.putAll(transformProperties(childGraph));
for (Entry<String, String> attribute : attributes.entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey(), attribute.getValue());
}
transformDefaultElementProperties(childGraph);
DotElementExporter childGraphWriter = new DotElementExporter(childGraph, dotGraphWriter);
childGraphWriter.transform();
dotGraphWriter.addClusterStop();
} else {
dotGraphWriter.addNode(vertex.getId().toString(), transformProperties(vertex));
}
} catch (IOException e) {
handleIOException(e);
}
}
@Override
protected void transformEdge(final Edge edge) {
try {
final String sourceId = edge.getVertex(Direction.OUT).getId().toString();
final String targetId = edge.getVertex(Direction.IN).getId().toString();
dotGraphWriter.addEdge(sourceId, targetId, transformProperties(edge));
} catch (IOException e) {
handleIOException(e);
}
}
protected void transformDefaultElementProperties(final Graph graph) throws IOException {
final Object defaultNodeProperties = graph.getProperty(DotExportPropertyTokens.DEFAULT_NODE_PROPERTIES);
if (defaultNodeProperties instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, String> defaultNodeAttributes = (Map<String, String>) defaultNodeProperties;
dotGraphWriter.addDefaultNodeAttributes(defaultNodeAttributes);
}
final Object defaultEdgeProperties = graph.getProperty(DotExportPropertyTokens.DEFAULT_EDGE_PROPERTIES);
if (defaultEdgeProperties instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, String> defaultEdgeAttributes = (Map<String, String>) defaultEdgeProperties;
dotGraphWriter.addDefaultEdgeAttributes(defaultEdgeAttributes);
}
}
protected void handleIOException(final IOException ioException) {
throw new IllegalStateException(ioException);
}
protected Map<String, String> transformProperties(final Element element) {
final Set<String> propertyKeys = element.getPropertyKeys();
final Map<String, String> properties = new HashMap<>(propertyKeys.size(), 1);
for (final String propertyKey : propertyKeys) {
if (propertyKey.equals(DotExportPropertyTokens.DEFAULT_NODE_PROPERTIES) || propertyKey.equals(DotExportPropertyTokens.DEFAULT_EDGE_PROPERTIES)) {
break;
}
properties.put(propertyKey, element.getProperty(propertyKey).toString());
}
return properties;
}
@Override
protected void beforeTransformation() {
// Do nothing
}
@Override
protected void afterTransformation() {
// Do nothing
}
@Override
protected Void getTransformation() {
return null;
}
}
package kieker.analysis.graph.export.dot;
import java.io.IOException;
import kieker.analysis.graph.Direction;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
import kieker.analysis.graph.export.AbstractTransformer;
import kieker.analysis.graph.util.dot.DotGraphWriter;
class DotElementWriter extends AbstractTransformer<Void> {
protected final DotGraphWriter dotWriter;
protected DotElementWriter(final Graph graph, final DotGraphWriter dotWriter) {
super(graph);
this.dotWriter = dotWriter;
}
@Override
protected void transformVertex(final Vertex vertex) {
try {
if (vertex.hasChildGraph()) {
Graph childGraph = vertex.getChildGraph();
dotWriter.addClusterStart(childGraph.getName());
// TODO more stuff
DotElementWriter dotWriter2 = new DotElementWriter(childGraph, dotWriter);
dotWriter2.transform();
dotWriter.addClusterStop();
} else {
dotWriter.addNode(vertex.getId().toString(), null); // TODO
}
} catch (IOException e) {
handleIOException(e);
}
}
@Override
protected void transformEdge(final Edge edge) {
try {
String sourceId = edge.getVertex(Direction.OUT).getId().toString();
String targetId = edge.getVertex(Direction.IN).getId().toString();
dotWriter.addEdge(sourceId, targetId); // TODO
} catch (IOException e) {
handleIOException(e);
}
}
protected void handleIOException(final IOException ioException) {
// TODO Handle IO Exception
}
@Override
protected void beforeTransformation() {
// Do nothing
}
@Override
protected void afterTransformation() {
// Do nothing
}
@Override
protected Void getTransformation() {
return null;
}
}
package kieker.analysis.graph.export.dot;
public final class DotExportPropertyTokens {
public static final String DEFAULT_NODE_PROPERTIES = "__DEFAULT_NODE_PROPERTIES";
public static final String DEFAULT_EDGE_PROPERTIES = "__DEFAULT_EDGE_PROPERTIES";
}
package kieker.analysis.graph.export.dot;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.Writer;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.util.dot.DotGraphWriter;
public class DotExporter {
public class DotExporter extends DotElementExporter {
public void export(final Graph graph, final OutputStream outputStream) {
GraphTransformer graphTransformer = new GraphTransformer(graph);
// TODO Receiving a dot object would be (maybe) better
String dotString = graphTransformer.transform();
public DotExporter(final Graph graph, final Writer writer) {
super(graph, new DotGraphWriter(writer));
}
PrintWriter printWriter = new PrintWriter(outputStream);
printWriter.write(dotString);
printWriter.close();
@Override
protected void beforeTransformation() {
try {
dotGraphWriter.start(graph.getName());
for (String attributeKey : graph.getPropertyKeys()) {
dotGraphWriter.addGraphAttribute(attributeKey, graph.getProperty(attributeKey));
}
transformDefaultElementProperties(graph);
} catch (IOException e) {
handleIOException(e);
}
}
@Override
protected void afterTransformation() {
try {
dotGraphWriter.finish();
} catch (IOException e) {
handleIOException(e);
}
}
}
package kieker.analysis.graph.export.dot;
import java.io.IOException;
import java.io.Writer;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.util.dot.DotGraphWriter;
public class DotWriter extends DotElementWriter {
public DotWriter(final Graph graph, final Writer writer) {
super(graph, new DotGraphWriter(writer));
}
@Override
protected void beforeTransformation() {
try {
dotWriter.start(graph.getName());
// TODO more stuff
} catch (IOException e) {
handleIOException(e);
}
}
@Override
protected void afterTransformation() {
try {
dotWriter.finish();
} catch (IOException e) {
handleIOException(e);
}
}
}
package kieker.analysis.graph.export.dot;
import kieker.analysis.graph.Direction;
import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex;
import kieker.analysis.graph.export.AbstractTransformer;
import kieker.analysis.util.DotBuilder;
//TODO remove
public class GraphTransformer extends AbstractTransformer<String> {
private final DotBuilder dotBuilder;
public GraphTransformer(final Graph graph) {
super(graph);
dotBuilder = new DotBuilder(graph.getName());
}
public GraphTransformer(final Graph graph, final boolean isCluster) {
super(graph);
dotBuilder = new DotBuilder("cluster_" + graph.getName(), "subgraph");
}
@Override
protected void transformVertex(final Vertex vertex) {
if (vertex.hasChildGraph()) {
Graph childGraph = vertex.getChildGraph();
GraphTransformer graphTransformer = new GraphTransformer(childGraph, false);
String childGraphString = graphTransformer.transform();
dotBuilder.addSubgraph(childGraphString);
// TODO Add style, label, etc
} else {
dotBuilder.addNode(vertex.getId().toString());
// TODO Add style, label, etc
}
}
@Override
protected void transformEdge(final Edge edge) {
String sourceId = edge.getVertex(Direction.OUT).getId().toString();
String targetId = edge.getVertex(Direction.IN).getId().toString();
dotBuilder.addEdge(sourceId, targetId);
// TODO Add style, label, etc
}
@Override
protected String getTransformation() {
return dotBuilder.get();
}
@Override
protected void beforeTransformation() {
// TODO Auto-generated method stub
}
@Override
protected void afterTransformation() {
// TODO Auto-generated method stub
}
}
......@@ -13,6 +13,7 @@ import org.graphdrawing.graphml.ObjectFactory;
import kieker.analysis.graph.Graph;
//TODO remove
public class GraphMLExporter {
private static final Boolean FORMATTED_OUTPUT = Boolean.TRUE;
......
......@@ -9,7 +9,7 @@ import com.google.common.base.Joiner;
/**
* Simple class for building and representing dot graph files.
*
* @deprecated use {@link DotGraphWriter.DotWriter} instead.
* @deprecated use {@link DotExporter.DotWriter} instead.
*
* @author Sören Henning
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment