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

redesigned dot export process (not done)

parent 941b448d
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
Pipeline #
Showing with 186 additions and 43 deletions
package kieker.analysis.util.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 java.util.function.Function;
import java.util.stream.Collectors;
import kieker.analysis.util.graph.Direction;
import kieker.analysis.util.graph.Edge;
import kieker.analysis.util.graph.Element;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.Vertex;
import kieker.analysis.util.graph.export.AbstractTransformer;
import kieker.analysis.util.graph.util.dot.DotGraphWriter;
import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute;
class DotElementExporter extends AbstractTransformer<Void> {
protected final DotGraphWriter dotGraphWriter;
protected final DotExportConfiguration configuration;
protected DotElementExporter(final Graph graph, final DotGraphWriter dotGraphWriter) {
protected DotElementExporter(final Graph graph, final DotGraphWriter dotGraphWriter, final DotExportConfiguration configuration) {
super(graph);
this.dotGraphWriter = dotGraphWriter;
this.configuration = configuration;
}
@Override
......@@ -31,19 +33,16 @@ class DotElementExporter extends AbstractTransformer<Void> {
dotGraphWriter.addClusterStart(vertex.getId().toString());
Map<String, String> attributes = transformProperties(vertex);
attributes.putAll(transformProperties(childGraph));
for (Entry<String, String> attribute : attributes.entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey(), attribute.getValue());
for (Entry<DotClusterAttribute, Function<Vertex, String>> attribute : configuration.getClusterAttributes().entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey().toString(), attribute.getValue().apply(vertex));
}
transformDefaultElementProperties(childGraph);
DotElementExporter childGraphWriter = new DotElementExporter(childGraph, dotGraphWriter);
DotElementExporter childGraphWriter = new DotElementExporter(childGraph, dotGraphWriter, configuration);
childGraphWriter.transform();
dotGraphWriter.addClusterStop();
} else {
dotGraphWriter.addNode(vertex.getId().toString(), transformProperties(vertex));
dotGraphWriter.addNode(vertex.getId().toString(), getAttributes(vertex));
}
} catch (IOException e) {
handleIOException(e);
......@@ -55,45 +54,28 @@ class DotElementExporter extends AbstractTransformer<Void> {
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));
dotGraphWriter.addEdge(sourceId, targetId, getAttributes(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());
}
protected Map<String, String> getAttributes(final Edge edge) {
return configuration.getEdgeAttributes().entrySet().stream().collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().apply(edge)));
}
return properties;
protected Map<String, String> getAttributes(final Vertex vertex) {
return configuration.getNodeAttributes().entrySet().stream().collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().apply(vertex)));
}
@Override
......
package kieker.analysis.util.graph.export.dot;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Function;
import kieker.analysis.util.graph.Edge;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.Vertex;
import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute;
public class DotExportConfiguration {
final private Map<DotGraphAttribute, Function<Graph, String>> graphAttributes = new EnumMap<>(DotGraphAttribute.class);
final private Map<DotNodeAttribute, Function<Graph, String>> defaultNodeAttributes = new EnumMap<>(DotNodeAttribute.class);
final private Map<DotEdgeAttribute, Function<Graph, String>> defaultEdgeAttributes = new EnumMap<>(DotEdgeAttribute.class);
final private Map<DotNodeAttribute, Function<Vertex, String>> nodeAttributes = new EnumMap<>(DotNodeAttribute.class);
final private Map<DotEdgeAttribute, Function<Edge, String>> edgeAttributes = new EnumMap<>(DotEdgeAttribute.class);
final private Map<DotClusterAttribute, Function<Vertex, String>> clusterAttributes = new EnumMap<>(DotClusterAttribute.class);
public Map<DotGraphAttribute, Function<Graph, String>> getGraphAttributes() {
return graphAttributes;
}
public Map<DotNodeAttribute, Function<Graph, String>> getDefaultNodeAttributes() {
return defaultNodeAttributes;
}
public Map<DotEdgeAttribute, Function<Graph, String>> getDefaultEdgeAttributes() {
return defaultEdgeAttributes;
}
public Map<DotNodeAttribute, Function<Vertex, String>> getNodeAttributes() {
return nodeAttributes;
}
public Map<DotEdgeAttribute, Function<Edge, String>> getEdgeAttributes() {
return edgeAttributes;
}
public Map<DotClusterAttribute, Function<Vertex, String>> getClusterAttributes() {
return clusterAttributes;
}
}
......@@ -2,25 +2,48 @@ package kieker.analysis.util.graph.export.dot;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import kieker.analysis.util.graph.Graph;
import kieker.analysis.util.graph.util.dot.DotGraphWriter;
import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute;
import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute;
public class DotExporter extends DotElementExporter {
public DotExporter(final Graph graph, final Writer writer) {
super(graph, new DotGraphWriter(writer));
this(graph, writer, new DotExportConfiguration());
}
public DotExporter(final Graph graph, final Writer writer, final DotExportConfiguration configuration) {
super(graph, new DotGraphWriter(writer), configuration);
}
@Override
protected void beforeTransformation() {
try {
dotGraphWriter.start(graph.getName());
for (Entry<String, String> attribute : transformProperties(graph).entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey(), attribute.getValue());
for (Entry<DotGraphAttribute, Function<Graph, String>> attribute : configuration.getGraphAttributes().entrySet()) {
dotGraphWriter.addGraphAttribute(attribute.getKey().toString(), attribute.getValue().apply(graph));
}
Map<String, String> defaultNodeAttributes = new HashMap<>();
for (Entry<DotNodeAttribute, Function<Graph, String>> attribute : configuration.getDefaultNodeAttributes().entrySet()) {
defaultNodeAttributes.put(attribute.getKey().toString(), attribute.getValue().apply(graph));
}
dotGraphWriter.addDefaultNodeAttributes(defaultNodeAttributes);
Map<String, String> defaultEdgeAttributes = new HashMap<>();
for (Entry<DotEdgeAttribute, Function<Graph, String>> attribute : configuration.getDefaultEdgeAttributes().entrySet()) {
defaultEdgeAttributes.put(attribute.getKey().toString(), attribute.getValue().apply(graph));
}
transformDefaultElementProperties(graph);
dotGraphWriter.addDefaultEdgeAttributes(defaultEdgeAttributes);
} catch (IOException e) {
handleIOException(e);
}
......
package kieker.analysis.util.graph.util.dot.attributes;
public enum DotClusterAttribute {
LABEL("label");
private final String attribute;
private DotClusterAttribute(final String attribute) {
this.attribute = attribute;
}
@Override
public String toString() {
return this.attribute;
}
}
package kieker.analysis.util.graph.util.dot.attributes;
public enum DotEdgeAttribute {
LABEL("label"), ARROWHEAD("arrowhead"), ARROWSIZE("arrowsize"), ARROWTAIL("arrowtail");
private final String attribute;
private DotEdgeAttribute(final String attribute) {
this.attribute = attribute;
}
@Override
public String toString() {
return this.attribute;
}
}
package kieker.analysis.util.graph.util.dot.attributes;
public enum DotGraphAttribute {
LABEL("label"), RANKDIR("rankdir");
private final String attribute;
private DotGraphAttribute(final String attribute) {
this.attribute = attribute;
}
@Override
public String toString() {
return this.attribute;
}
}
package kieker.analysis.util.graph.util.dot.attributes;
public enum DotNodeAttribute {
LABEL("label"), SHAPE("shape");
private final String attribute;
private DotNodeAttribute(final String attribute) {
this.attribute = attribute;
}
@Override
public String toString() {
return this.attribute;
}
}
package kieker.analysis.util.graph.util.dot.attributes;
public enum DotSubgraphAttribute {
;
private final String attribute;
private DotSubgraphAttribute(final String attribute) {
this.attribute = attribute;
}
@Override
public String toString() {
return this.attribute;
}
}
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