use of org.eclipse.elk.alg.graphviz.dot.dot.Attribute in project elk by eclipse.
the class DotExporter method createAttribute.
/**
* Create an attribute with given name and value for the Dot graph.
*
* @param name name of the attribute
* @param value value of the attribute
* @return instance of a Dot attribute
*/
public static Attribute createAttribute(final String name, final String value) {
Attribute attribute = DotFactory.eINSTANCE.createAttribute();
attribute.setName(name);
attribute.setValue(value);
return attribute;
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Attribute in project elk by eclipse.
the class DotExporter method createAttribute.
/**
* Create an attribute with given name and integer value for the Dot graph.
*
* @param name name of the attribute
* @param value value of the attribute
* @return instance of a Dot attribute
*/
public static Attribute createAttribute(final String name, final int value) {
Attribute attribute = DotFactory.eINSTANCE.createAttribute();
attribute.setName(name);
attribute.setValue("\"" + value + "\"");
return attribute;
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Attribute in project elk by eclipse.
the class DotExporter method transformNodes.
/**
* Transform the child nodes of the given parent node.
*
* @param parent a parent node
* @param statements the list to which new statements are added
* @param offset offset of the parent node in the whole graph
* @param transData transformation data
*/
private void transformNodes(final ElkNode parent, final List<Statement> statements, final KVector offset, final IDotTransformationData<ElkNode, GraphvizModel> transData) {
// set attributes for the whole graph
setGraphAttributes(statements, parent, transData);
// create nodes and subgraphs
boolean hierarchy = transData.getProperty(HIERARCHY);
boolean transformNodeLayout = transData.getProperty(TRANSFORM_NODE_LAYOUT);
boolean transformNodeLabels = transData.getProperty(TRANSFORM_NODE_LABELS);
for (ElkNode childNode : parent.getChildren()) {
NodeStatement nodeStatement = DotFactory.eINSTANCE.createNodeStatement();
List<Attribute> attributes = nodeStatement.getAttributes();
String nodeID;
// if hierarchy mode is active, create a subgraph, else a regular node
if (hierarchy && !childNode.getChildren().isEmpty()) {
String clusterNodeID = getNodeID(childNode, NodeType.CLUSTER, transData);
Subgraph subgraph = DotFactory.eINSTANCE.createSubgraph();
subgraph.setName(clusterNodeID);
statements.add(subgraph);
// transform child nodes recursively
ElkPadding padding = childNode.getProperty(CoreOptions.PADDING);
double subgraphx = childNode.getX() + padding.getLeft();
double subgraphy = childNode.getY() + padding.getTop();
transformNodes(childNode, subgraph.getStatements(), new KVector(offset).add(subgraphx, subgraphy), transData);
// create a dummy node for compound edges
nodeID = getNodeID(childNode, NodeType.DUMMY, transData);
attributes.add(createAttribute(Attributes.STYLE, "invis"));
attributes.add(createAttribute(Attributes.WIDTH, 0));
attributes.add(createAttribute(Attributes.HEIGHT, 0));
subgraph.getStatements().add(nodeStatement);
} else {
nodeID = getNodeID(childNode, NodeType.NODE, transData);
// set width and height
ElkUtil.resizeNode(childNode);
if (childNode.getWidth() > 0) {
attributes.add(createAttribute(Attributes.WIDTH, childNode.getWidth() / DPI));
}
if (childNode.getHeight() > 0) {
attributes.add(createAttribute(Attributes.HEIGHT, childNode.getHeight() / DPI));
}
if (transformNodeLabels && !childNode.getLabels().isEmpty() && childNode.getLabels().get(0).getText().length() > 0) {
attributes.add(createAttribute(Attributes.LABEL, createString(childNode.getLabels().get(0).getText())));
}
// add node position if interactive layout is chosen
if (transformNodeLayout && (childNode.getX() != 0 || childNode.getY() != 0)) {
double xpos = (childNode.getX() + childNode.getWidth() / 2 + offset.x);
double ypos = (childNode.getY() + childNode.getHeight() / 2 + offset.y);
String posString = "\"" + Double.toString(xpos) + "," + Double.toString(ypos) + "\"";
attributes.add(createAttribute(Attributes.POS, posString));
}
statements.add(nodeStatement);
}
Node node = DotFactory.eINSTANCE.createNode();
node.setName(nodeID);
nodeStatement.setNode(node);
}
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Attribute in project elk by eclipse.
the class DotExporter method setGeneralEdgeAttributes.
/**
* Sets general attributes for edges.
*
* @param statements
* the statement list for adding attributes
* @return the list of edge attributes
*/
protected List<Attribute> setGeneralEdgeAttributes(final List<Statement> statements) {
AttributeStatement edgeAttrStatement = DotFactory.eINSTANCE.createAttributeStatement();
edgeAttrStatement.setType(AttributeType.EDGE);
List<Attribute> edgeAttrs = edgeAttrStatement.getAttributes();
statements.add(edgeAttrStatement);
edgeAttrs.add(createAttribute(Attributes.EDGEDIR, "none"));
return edgeAttrs;
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Attribute in project elk by eclipse.
the class DotImporter method applyLayout.
/**
* Apply layout to an edge and its labels.
*
* @param edge an edge
* @param offset its offset in the graph
* @param graph the Graphviz graph
*/
private void applyLayout(final ElkEdge edge, final KVector offset, final Graph graph) {
EdgeStatement edgeStatement = (EdgeStatement) edge.getProperty(PROP_STATEMENT);
if (edgeStatement.eContainer() == null) {
// this can happen when an edge with multiple target declarations was found
graph.getStatements().add(edgeStatement);
}
// transfer edge bend points and source / target points
List<Attribute> attributes = edgeStatement.getAttributes();
removeAttributes(attributes, Attributes.POS);
if (!edge.getSections().isEmpty()) {
StringBuilder bendpointString = new StringBuilder("\"");
KVectorChain vectorChain = ElkUtil.createVectorChain(edge.getSections().get(0));
ListIterator<KVector> chainIter = vectorChain.listIterator();
while (chainIter.hasNext()) {
KVector point = chainIter.next().add(offset);
bendpointString.append(point.x);
bendpointString.append(',');
bendpointString.append(point.y);
if (chainIter.hasNext()) {
bendpointString.append(' ');
}
}
bendpointString.append('\"');
attributes.add(DotExporter.createAttribute(Attributes.POS, bendpointString.toString()));
}
// transfer label positions
for (ElkLabel label : edge.getLabels()) {
String attrKey = null;
switch(label.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT)) {
case CENTER:
attrKey = Attributes.LABELPOS;
break;
case HEAD:
attrKey = Attributes.HEADLP;
break;
case TAIL:
attrKey = Attributes.TAILLP;
break;
}
if (attrKey != null) {
removeAttributes(attributes, attrKey);
double xpos = label.getX() + label.getWidth() / 2 + offset.x;
double ypos = label.getY() + label.getHeight() / 2 + offset.y;
String posString = "\"" + Double.toString(xpos) + "," + Double.toString(ypos) + "\"";
attributes.add(DotExporter.createAttribute(attrKey, posString));
}
}
}
Aggregations