Search in sources :

Example 1 with AttributeStatement

use of org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement 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 2 with AttributeStatement

use of org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement in project elk by eclipse.

the class DotImporter method transform.

/*---------- Transformation Dot to KGraph ----------*/
/**
 * Transform a Dot graph to a KNode.
 *
 * @param statements
 *            a list of Dot statements
 * @param parent
 *            a KNode
 * @param transData
 *            transformation data instance
 * @param nodeProps
 *            properties that are applied to all nodes
 * @param edgeProps
 *            properties that are applied to all edges
 */
private void transform(final List<Statement> statements, final ElkNode parent, final IDotTransformationData<GraphvizModel, ElkNode> transData, final IPropertyHolder nodeProps, final IPropertyHolder edgeProps) {
    DotSwitch<Object> statementSwitch = new DotSwitch<Object>() {

        public Object caseNodeStatement(final NodeStatement statement) {
            transformNode(statement, parent, transData, nodeProps);
            return null;
        }

        public Object caseEdgeStatement(final EdgeStatement statement) {
            transformEdge(statement, parent, transData, edgeProps);
            return null;
        }

        public Object caseSubgraph(final Subgraph subgraph) {
            ElkNode subElkNode = parent;
            if (subgraph.getName() != null && subgraph.getName().startsWith("cluster")) {
                subElkNode = transformNode(subgraph.getName(), parent, transData);
                if (subElkNode.getProperty(PROP_STATEMENT) != null) {
                    transData.log("Discarding cluster subgraph \"" + subgraph.getName() + "\" since its id is already used.");
                    return null;
                } else {
                    // the subgraph inherits all settings of its parent
                    subElkNode.copyProperties(parent);
                    subElkNode.setProperty(PROP_STATEMENT, subgraph);
                }
            }
            MapPropertyHolder subNodeProps = new MapPropertyHolder();
            subNodeProps.copyProperties(nodeProps);
            MapPropertyHolder subEdgeProps = new MapPropertyHolder();
            subEdgeProps.copyProperties(edgeProps);
            transform(subgraph.getStatements(), subElkNode, transData, subNodeProps, subEdgeProps);
            return null;
        }

        public Object caseAttributeStatement(final AttributeStatement statement) {
            switch(statement.getType()) {
                case GRAPH:
                    for (Attribute attr : statement.getAttributes()) {
                        caseAttribute(attr);
                    }
                    break;
                case NODE:
                    for (Attribute attr : statement.getAttributes()) {
                        transformAttribute(nodeProps, attr, transData);
                    }
                    break;
                case EDGE:
                    for (Attribute attr : statement.getAttributes()) {
                        transformAttribute(edgeProps, attr, transData);
                    }
                    break;
            }
            return null;
        }

        public Object caseAttribute(final Attribute attribute) {
            if (Attributes.MARGIN.equals(attribute.getName())) {
                ElkPadding padding = parent.getProperty(CoreOptions.PADDING);
                if (attribute.getValue().indexOf(',') >= 0) {
                    KVector value = new KVector();
                    try {
                        value.parse(attribute.getValue());
                        padding.setLeft((float) value.x);
                        padding.setRight((float) value.x);
                        padding.setTop((float) value.y);
                        padding.setBottom((float) value.y);
                    } catch (IllegalArgumentException exception) {
                        transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
                    }
                } else {
                    try {
                        float value = Float.parseFloat(trimValue(attribute));
                        padding.setLeft(value);
                        padding.setRight(value);
                        padding.setTop(value);
                        padding.setBottom(value);
                    } catch (NumberFormatException exception) {
                        transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
                    }
                }
            } else {
                transformAttribute(parent, attribute, transData);
            }
            return null;
        }
    };
    for (Statement statement : statements) {
        statementSwitch.doSwitch(statement);
    }
}
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) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) Statement(org.eclipse.elk.alg.graphviz.dot.dot.Statement) MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) DotSwitch(org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch)

Example 3 with AttributeStatement

use of org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement in project elk by eclipse.

the class AbstractGraphvizDotSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == DotPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case DotPackage.ATTRIBUTE:
                if (rule == grammarAccess.getStatementRule() || rule == grammarAccess.getAttributeRule()) {
                    sequence_Attribute(context, (Attribute) semanticObject);
                    return;
                } else if (rule == grammarAccess.getListAttributeRule()) {
                    sequence_ListAttribute(context, (Attribute) semanticObject);
                    return;
                } else
                    break;
            case DotPackage.ATTRIBUTE_STATEMENT:
                sequence_AttributeStatement(context, (AttributeStatement) semanticObject);
                return;
            case DotPackage.EDGE_STATEMENT:
                sequence_EdgeStatement(context, (EdgeStatement) semanticObject);
                return;
            case DotPackage.EDGE_TARGET:
                sequence_EdgeTarget(context, (EdgeTarget) semanticObject);
                return;
            case DotPackage.GRAPH:
                sequence_Graph(context, (Graph) semanticObject);
                return;
            case DotPackage.GRAPHVIZ_MODEL:
                sequence_GraphvizModel(context, (GraphvizModel) semanticObject);
                return;
            case DotPackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
            case DotPackage.NODE_STATEMENT:
                sequence_NodeStatement(context, (NodeStatement) semanticObject);
                return;
            case DotPackage.PORT:
                sequence_Port(context, (Port) semanticObject);
                return;
            case DotPackage.SUBGRAPH:
                sequence_Subgraph(context, (Subgraph) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) Node(org.eclipse.elk.alg.graphviz.dot.dot.Node) Port(org.eclipse.elk.alg.graphviz.dot.dot.Port) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) EPackage(org.eclipse.emf.ecore.EPackage) GraphvizModel(org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel) Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) EdgeTarget(org.eclipse.elk.alg.graphviz.dot.dot.EdgeTarget) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) Parameter(org.eclipse.xtext.Parameter)

Example 4 with AttributeStatement

use of org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement in project elk by eclipse.

the class LayoutDotExporter method setGraphAttributes.

@Override
protected void setGraphAttributes(final List<Statement> statements, final ElkNode parentNode, final IDotTransformationData<ElkNode, GraphvizModel> transData) {
    Command command = transData.getProperty(COMMAND);
    AttributeStatement graphAttrStatement = DotFactory.eINSTANCE.createAttributeStatement();
    graphAttrStatement.setType(AttributeType.GRAPH);
    List<Attribute> graphAttrs = graphAttrStatement.getAttributes();
    statements.add(graphAttrStatement);
    setGeneralNodeAttributes(statements);
    List<Attribute> edgeAttrs = setGeneralEdgeAttributes(statements);
    // set minimal spacing
    Double spacing = parentNode.getProperty(CoreOptions.SPACING_NODE_NODE);
    if (spacing == null || spacing < 0) {
        switch(command) {
            case CIRCO:
            case FDP:
            case NEATO:
                spacing = DEF_SPACING_LARGE;
                break;
            case TWOPI:
                spacing = DEF_SPACING_XLARGE;
                break;
            default:
                spacing = DEF_SPACING_SMALL;
        }
    }
    switch(command) {
        case DOT:
            graphAttrs.add(createAttribute(Attributes.NODESEP, spacing / DPI));
            double rankSepFactor = parentNode.getProperty(GraphvizMetaDataProvider.LAYER_SPACING_FACTOR);
            graphAttrs.add(createAttribute(Attributes.RANKSEP, rankSepFactor * spacing / DPI));
            // set layout direction
            switch(parentNode.getProperty(CoreOptions.DIRECTION)) {
                case UP:
                    graphAttrs.add(createAttribute(Attributes.RANKDIR, "BT"));
                    break;
                case LEFT:
                    graphAttrs.add(createAttribute(Attributes.RANKDIR, "RL"));
                    break;
                case RIGHT:
                    graphAttrs.add(createAttribute(Attributes.RANKDIR, "LR"));
                    break;
                default:
                    // DOWN
                    graphAttrs.add(createAttribute(Attributes.RANKDIR, "TB"));
            }
            // set iterations limit
            Double iterationsFactor = parentNode.getProperty(GraphvizMetaDataProvider.ITERATIONS_FACTOR);
            if (iterationsFactor != null && iterationsFactor > 0) {
                graphAttrs.add(createAttribute(Attributes.CROSSMIN_LIMIT, iterationsFactor));
                if (iterationsFactor < 1) {
                    double simplexLimit = iterationsFactor * NSLIMIT_BASE;
                    graphAttrs.add(createAttribute(Attributes.SIMPLEX_LIMIT, simplexLimit));
                }
            }
            // enable compound mode
            if (parentNode.getProperty(CoreOptions.HIERARCHY_HANDLING) == HierarchyHandling.INCLUDE_CHILDREN) {
                graphAttrs.add(createAttribute(Attributes.COMPOUND, "true"));
            }
            break;
        case TWOPI:
            graphAttrs.add(createAttribute(Attributes.RANKSEP, spacing / DPI));
            break;
        case CIRCO:
            graphAttrs.add(createAttribute(Attributes.MINDIST, spacing / DPI));
            break;
        case NEATO:
            edgeAttrs.add(createAttribute(Attributes.EDGELEN, spacing / DPI));
            // configure initial placement of nodes
            Integer seed = parentNode.getProperty(CoreOptions.RANDOM_SEED);
            if (seed == null) {
                seed = 1;
            } else if (seed == 0) {
                seed = -1;
            } else if (seed < 0) {
                seed = -seed;
            }
            graphAttrs.add(createAttribute(Attributes.START, "random" + seed));
            // set epsilon value
            Double epsilon = parentNode.getProperty(GraphvizMetaDataProvider.EPSILON);
            if (epsilon != null && epsilon > 0) {
                graphAttrs.add(createAttribute(Attributes.EPSILON, epsilon));
            }
            // set distance model
            NeatoModel model = parentNode.getProperty(GraphvizMetaDataProvider.NEATO_MODEL);
            if (model != NeatoModel.SHORTPATH) {
                graphAttrs.add(createAttribute(Attributes.NEATO_MODEL, model.literal()));
            }
            break;
        case FDP:
            graphAttrs.add(createAttribute(Attributes.SPRING_CONSTANT, spacing / DPI));
            break;
    }
    if (command == Command.NEATO || command == Command.FDP) {
        // set maximum number of iterations
        Integer maxiter = parentNode.getProperty(GraphvizMetaDataProvider.MAXITER);
        if (maxiter != null && maxiter > 0) {
            graphAttrs.add(createAttribute(Attributes.MAXITER, maxiter));
        }
    }
    if (command != Command.DOT) {
        // enable or disable node overlap avoidance
        OverlapMode mode = parentNode.getProperty(GraphvizMetaDataProvider.OVERLAP_MODE);
        if (mode != OverlapMode.NONE) {
            graphAttrs.add(createAttribute(Attributes.OVERLAP, mode.literal()));
            graphAttrs.add(createAttribute(Attributes.SEP, "\"+" + Math.round(spacing / 2) + "\""));
        }
        // enable or disable connected component packing
        Boolean pack = parentNode.getProperty(CoreOptions.SEPARATE_CONNECTED_COMPONENTS);
        if (command == Command.TWOPI || pack != null && pack.booleanValue()) {
            graphAttrs.add(createAttribute(Attributes.PACK, spacing.intValue()));
        }
    }
    // configure edge routing
    EdgeRouting edgeRouting = parentNode.getProperty(CoreOptions.EDGE_ROUTING);
    String splineMode;
    switch(edgeRouting) {
        case POLYLINE:
            splineMode = "polyline";
            break;
        case ORTHOGONAL:
            splineMode = "ortho";
            break;
        default:
            splineMode = "spline";
            transData.setProperty(USE_SPLINES, true);
    }
    graphAttrs.add(createAttribute(Attributes.SPLINES, splineMode));
    // enable edge concentration
    if (parentNode.getProperty(GraphvizMetaDataProvider.CONCENTRATE)) {
        graphAttrs.add(createAttribute(Attributes.CONCENTRATE, "true"));
    }
}
Also used : OverlapMode(org.eclipse.elk.alg.graphviz.dot.transform.OverlapMode) NeatoModel(org.eclipse.elk.alg.graphviz.dot.transform.NeatoModel) Command(org.eclipse.elk.alg.graphviz.dot.transform.Command) Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) EdgeRouting(org.eclipse.elk.core.options.EdgeRouting)

Example 5 with AttributeStatement

use of org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement in project elk by eclipse.

the class DotExporter method setGeneralNodeAttributes.

/**
 * Sets general attributes for nodes.
 *
 * @param statements
 *            the statement list for adding attributes
 * @return the list of node attributes
 */
protected List<Attribute> setGeneralNodeAttributes(final List<Statement> statements) {
    AttributeStatement nodeAttrStatement = DotFactory.eINSTANCE.createAttributeStatement();
    nodeAttrStatement.setType(AttributeType.NODE);
    List<Attribute> nodeAttrs = nodeAttrStatement.getAttributes();
    statements.add(nodeAttrStatement);
    nodeAttrs.add(createAttribute(Attributes.SHAPE, "box"));
    nodeAttrs.add(createAttribute(Attributes.FIXEDSIZE, "true"));
    return nodeAttrs;
}
Also used : Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)

Aggregations

Attribute (org.eclipse.elk.alg.graphviz.dot.dot.Attribute)6 AttributeStatement (org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)6 EdgeStatement (org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)3 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)3 Subgraph (org.eclipse.elk.alg.graphviz.dot.dot.Subgraph)3 Statement (org.eclipse.elk.alg.graphviz.dot.dot.Statement)2 ElkPadding (org.eclipse.elk.core.math.ElkPadding)2 KVector (org.eclipse.elk.core.math.KVector)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 NoSuchElementException (java.util.NoSuchElementException)1 StringTokenizer (java.util.StringTokenizer)1 EdgeTarget (org.eclipse.elk.alg.graphviz.dot.dot.EdgeTarget)1 Graph (org.eclipse.elk.alg.graphviz.dot.dot.Graph)1 GraphvizModel (org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel)1 Node (org.eclipse.elk.alg.graphviz.dot.dot.Node)1 Port (org.eclipse.elk.alg.graphviz.dot.dot.Port)1 DotSwitch (org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch)1 Command (org.eclipse.elk.alg.graphviz.dot.transform.Command)1 NeatoModel (org.eclipse.elk.alg.graphviz.dot.transform.NeatoModel)1 OverlapMode (org.eclipse.elk.alg.graphviz.dot.transform.OverlapMode)1