Пример #1
0
  /** {@inheritDoc} */
  public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("End label placement", 1);

    double labelSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_LABEL);

    // Initialize the offset maps
    northOffset = Maps.newHashMap();
    southOffset = Maps.newHashMap();
    portLabelOffsetHint = Maps.newHashMap();

    for (Layer layer : layeredGraph.getLayers()) {
      for (LNode node : layer.getNodes()) {
        for (LEdge edge : node.getOutgoingEdges()) {
          for (LLabel label : edge.getLabels()) {
            // Only consider end labels
            if (label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.TAIL
                || label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT)
                    == EdgeLabelPlacement.HEAD) {

              placeEndLabel(node, edge, label, labelSpacing);
            }
          }
        }
      }
    }

    monitor.done();
  }
  /** {@inheritDoc} */
  public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Greedy switch crossing reduction", 1);

    greedySwitchType = graph.getProperty(Properties.GREEDY_SWITCH_TYPE);

    int layerCount = graph.getLayers().size();
    if (layerCount < 2 || greedySwitchType == GreedySwitchType.OFF) {
      progressMonitor.done();
      return;
    }

    initialize(graph);

    if (greedySwitchType.useBestOfUpOrDown()) {
      compareSweepingUpwardOrDownward();
    } else {
      sweepOneSidedOrTwoSided();
    }

    setAsGraph(bestNodeOrder);

    progressMonitor.done();
  }
  /** {@inheritDoc} */
  public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Linear segments node placement", 1);

    spacings = layeredGraph.getProperty(InternalProperties.SPACINGS);

    // sort the linear segments of the layered graph
    sortLinearSegments(layeredGraph);

    // create an unbalanced placement from the sorted segments
    createUnbalancedPlacement(layeredGraph);

    // balance the placement
    balancePlacement(layeredGraph);

    // post-process the placement for small corrections
    postProcess(layeredGraph);

    // release the created resources
    linearSegments = null;
    spacings = null;
    monitor.done();
  }
  /** {@inheritDoc} */
  public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Spline SelfLoop positioning", 1);

    /** Stores which loop placement strategy to choose. */
    final SelfLoopPlacement loopPlacement =
        layeredGraph.getProperty(Properties.SPLINE_SELF_LOOP_PLACEMENT);

    ////////////////////////////////////////////////////////
    // There are two main jobs to be done:
    // 1) Find a loop-side for each component.
    // 2) Position ports in the correct order around the node.
    ////////////////////////////////////////////////////////

    // Process all nodes on all layers.
    for (final Layer layer : layeredGraph) {
      for (final LNode node : layer) {

        // Read self-loops components.
        final List<ConnectedSelfLoopComponent> components =
            node.getProperty(InternalProperties.SPLINE_SELFLOOP_COMPONENTS);

        // Components to be distributed by the placement strategy.
        final List<ConnectedSelfLoopComponent> componentsToBePlaced = Lists.newArrayList();

        for (final ConnectedSelfLoopComponent component : components) {
          // Re-Add all hidden edges to their ports.
          component.unhideEdges();

          if (component.getConstrainedPorts().isEmpty()) {
            // If there is no constraint on any port, we have to process this component later
            componentsToBePlaced.add(component);
          } else {
            // If there is at least one port with a constraint to it's port-side,
            // we will set the port- and loop-sides by this constraint. (Job 1)
            setPortSideByConstraint(component);
            if (!component.getNonLoopPorts().isEmpty()) {
              // Position and re-add all ports to the node, that are part of a component
              // with at least one non-loop edge. (Job 2)
              addComponentWithNonLoopEdges(component);
            }
          }
        }

        // Now we have to find a loop-side (job 1) for the remaining components. They are all
        // stored in componentsToBePlaced. All these components don't have a port with a
        // constraint on it's portSide, so we can arrange them accordingly to the cosen strategy.
        switch (loopPlacement) {
          case EQUALLY_DISTRIBUTED:
            setPortSideSpreadEqually(componentsToBePlaced, node);
            break;
          case NORTH_SEQUENCE:
            for (final ConnectedSelfLoopComponent component : componentsToBePlaced) {
              component.setLoopSide(LoopSide.N, true);
            }
            break;
          case NORTH_STACKED:
            for (final ConnectedSelfLoopComponent component : componentsToBePlaced) {
              component.setLoopSide(LoopSide.N, true);
            }
            break;
          default:
            // Unknown strategy chosen.
            assert false;
            break;
        }

        // Position and re-add all ports to the node.
        // This is job 2)
        switch (loopPlacement) {
          case EQUALLY_DISTRIBUTED:
          case NORTH_STACKED:
            portStackedPositioning(components);
            break;
          case NORTH_SEQUENCE:
            portLinedPositioning(components);
            break;
          default:
            break;
        }
      }
    }
    monitor.done();
  }