Search in sources :

Example 1 with 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 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;
}
Also used : Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute)

Example 2 with 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;
}
Also used : Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute)

Example 3 with 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);
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) ElkNode(org.eclipse.elk.graph.ElkNode) Node(org.eclipse.elk.alg.graphviz.dot.dot.Node) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 4 with Attribute

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;
}
Also used : Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)

Example 5 with Attribute

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));
        }
    }
}
Also used : Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVectorChain(org.eclipse.elk.core.math.KVectorChain) KVector(org.eclipse.elk.core.math.KVector) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)

Aggregations

Attribute (org.eclipse.elk.alg.graphviz.dot.dot.Attribute)17 KVector (org.eclipse.elk.core.math.KVector)8 ElkNode (org.eclipse.elk.graph.ElkNode)8 AttributeStatement (org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)7 EdgeStatement (org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)7 Node (org.eclipse.elk.alg.graphviz.dot.dot.Node)5 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)5 Subgraph (org.eclipse.elk.alg.graphviz.dot.dot.Subgraph)5 EdgeTarget (org.eclipse.elk.alg.graphviz.dot.dot.EdgeTarget)3 Statement (org.eclipse.elk.alg.graphviz.dot.dot.Statement)3 ElkPadding (org.eclipse.elk.core.math.ElkPadding)3 ElkEdge (org.eclipse.elk.graph.ElkEdge)3 NoSuchElementException (java.util.NoSuchElementException)2 StringTokenizer (java.util.StringTokenizer)2 ElkLabel (org.eclipse.elk.graph.ElkLabel)2 LinkedList (java.util.LinkedList)1 Graph (org.eclipse.elk.alg.graphviz.dot.dot.Graph)1 GraphvizModel (org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel)1 Port (org.eclipse.elk.alg.graphviz.dot.dot.Port)1 DotSwitch (org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch)1