Search in sources :

Example 1 with OverlapMode

use of org.eclipse.elk.alg.graphviz.dot.transform.OverlapMode 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)

Aggregations

Attribute (org.eclipse.elk.alg.graphviz.dot.dot.Attribute)1 AttributeStatement (org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)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 EdgeRouting (org.eclipse.elk.core.options.EdgeRouting)1