Exemplo n.º 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();
  }
Exemplo n.º 2
0
  /**
   * Places the given end label of the given edge starting at the given node.
   *
   * @param node source node of the edge.
   * @param edge the edge whose end label to place.
   * @param label the end label to place.
   * @param labelSpacing space between objects and labels.
   */
  private void placeEndLabel(
      final LNode node, final LEdge edge, final LLabel label, final double labelSpacing) {

    // Get the nearest port (source port for tail labels, target port for head labels)
    LPort port = null;

    if (label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.TAIL) {
      port = edge.getSource();
    } else if (label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.HEAD) {
      port = edge.getTarget();
    }

    // Initialize offset with zero if no offset was present
    if (!northOffset.containsKey(port.getNode())) {
      northOffset.put(port.getNode(), 0.0);
    }
    if (!southOffset.containsKey(port.getNode())) {
      southOffset.put(port.getNode(), 0.0);
    }
    if (!portLabelOffsetHint.containsKey(port)) {
      portLabelOffsetHint.put(port, 0.0);
    }

    // Calculate end label position based on side choice
    // Port side undefined can be left out, because there would be no reasonable
    // way of handling them
    if (label.getProperty(InternalProperties.LABEL_SIDE) == LabelSide.ABOVE) {
      placeEndLabelUpwards(node, label, port, labelSpacing);
    } else {
      placeEndLabelDownwards(node, label, port, labelSpacing);
    }
  }