Class KGraphUtil

java.lang.Object
de.cau.cs.kieler.klighd.kgraph.util.KGraphUtil

public final class KGraphUtil extends Object
Utility methods to operate on KGraphs.
  • Field Details

    • DEFAULT_MIN_WIDTH

      public static final float DEFAULT_MIN_WIDTH
      Default minimal width for nodes.
      See Also:
    • DEFAULT_MIN_HEIGHT

      public static final float DEFAULT_MIN_HEIGHT
      Default minimal height for nodes.
      See Also:
  • Method Details

    • createInitializedNode

      public static KNode createInitializedNode()
      Creates an initialized node. Its insets are set to zero.
      Returns:
      initialized node.
    • createInitializedPort

      public static KPort createInitializedPort()
      Creates an initialized port. Its insets are set to zero.
      Returns:
      initialized port.
    • createInitializedLabel

      public static KLabel createInitializedLabel(KLabeledGraphElement element)
      Creates an intialized label and adds it to the given element. Its insets are set to zero and its text is set to the empty string.
      Parameters:
      element - the element to add the label to.
      Returns:
      the initialized label.
    • createInitializedEdge

      public static KEdge createInitializedEdge()
      Creates an initialized edge. Its source and target point are set to zero.
      Returns:
      the initialized edge.
    • validate

      public static void validate(KNode graph)
      Ensures that each element contained in the given graph is attributed correctly for usage in ELK. KGraphElement
      Parameters:
      graph - the parent node of a graph
    • configureWithDefaultLabel

      public static void configureWithDefaultLabel(KLabeledGraphElement ele)
      Adds a default label to the graph element based on the KIdentifier. Depending on the elements type, hints on the placement of the label are set, e.g. a centered, inside label placement for atomic nodes.
      Parameters:
      ele - the element to configure.
    • configurWithDefaultSize

      public static void configurWithDefaultSize(KShapeLayout ele)
      Sets a default size to the passed element which is based on DEFAULT_MIN_WIDTH and DEFAULT_MIN_HEIGHT in conjunction with a scaling factor based on the type of the element.
      Parameters:
      ele - the element to configure.
    • configureWithDefaultValues

      public static void configureWithDefaultValues(KNode node)
      Adds some default values to the passed node. This includes a reasonable size, a label based on the node's KIdentifier and a inside center node label placement. Such default values are useful for fast test case generation.
      Parameters:
      node - a node of a graph
    • configureWithDefaultValues

      public static void configureWithDefaultValues(KPort port)
      Adds some default values to the passed port. This includes a reasonable size and a label based on the port's KIdentifier. Such default values are useful for fast test case generation.
      Parameters:
      port - a port of a node of a graph
    • persistDataElements

      public static void persistDataElements(KNode graph)
      Persists all EMapPropertyHolders of a KGraph by serializing the contained properties into PersistentEntry tuples.
      Parameters:
      graph - the root element of the graph to persist elements of.
    • toAbsolute

      public static org.eclipse.elk.core.math.KVector toAbsolute(org.eclipse.elk.core.math.KVector point, KNode parent)
      Converts the given relative point to an absolute location. The insets of the parent node are included in this calculation.
      Parameters:
      point - a relative point
      parent - the parent node to which the point is relative to
      Returns:
      point for convenience
    • toRelative

      public static org.eclipse.elk.core.math.KVector toRelative(org.eclipse.elk.core.math.KVector point, KNode parent)
      Converts the given absolute point to a relative location. The insets of the parent node are included in this calculation.
      Parameters:
      point - an absolute point
      parent - the parent node to which the point shall be made relative to
      Returns:
      point for convenience
    • getAbsolute

      public static org.eclipse.elk.core.math.KVector getAbsolute(KGraphElement element)
      Returns the absolute position of the given element from the positions of its KShapeLayout parents.
      Parameters:
      element - The element to which the point should be calculated.
      Returns:
      The absolute position of the element in the diagram.
    • calcPortSide

      public static org.eclipse.elk.core.options.PortSide calcPortSide(KPort port, org.eclipse.elk.core.options.Direction direction)
      Determines the port side for the given port from its relative position at its corresponding node.
      Parameters:
      port - port to analyze
      direction - the overall layout direction
      Returns:
      the port side relative to its containing node
      Throws:
      IllegalArgumentException - if the containing node is null.
    • toKGraphCoordinateSystem

      public static void toKGraphCoordinateSystem(org.eclipse.elk.graph.ElkEdge elkedge, KInsets insets)
      Translates all coordinates of the given edge from ELK's to KLighD's coordinate system. ELK uses an edge's containing node's top left corner as the point all edge coordinates will be relative to. KLighD uses either the source node's parent, or the source node itself. This method converts from ELK- to KLighD-compatible coordinates, including all routing information as well as junction points and labels.

      If insets are passed to the method, those should be the insets of the KNode the edge coordinates are relative to in the KLighD graph. In that case, the resulting edge coordinates will not be relative to that node's top left corner, but to the top left corner of its inset area, which is the way it works in KLighD.

      Parameters:
      elkedge - the edge whose layout information to change.
      insets - optional insets of the node the edge coordinates are relative to in the KLighD graph.
      Throws:
      IllegalArgumentException - if the edge does not have exactly one source and exactly one target.
    • toELKGraphCoordinateSystem

      public static void toELKGraphCoordinateSystem(org.eclipse.elk.graph.ElkEdge elkedge, KInsets insets)
      Translates all coordinates of the given edge from KLighD's to ELK's coordinate system. This is the inverse of toKGraphCoordinateSystem(ElkEdge, KInsets). See that method for details.
      Parameters:
      elkedge - the edge whose layout information to change.
      insets - optional insets of the node the edge coordinates are relative to in the KLighD graph.
      Throws:
      IllegalArgumentException - if the edge does not have exactly one source and exactly one target.
    • getConnectedEdges

      public static Iterator<KEdge> getConnectedEdges(Iterable<KEdge> edges)
      Determines the edges that are (transitively) connected to the given edges across hierarchy boundaries via common ports. See getConnectedEdges(KEdge) for details.
      Parameters:
      edges - an Iterable of edges that shall be checked
      Returns:
      an Iterator visiting the given edges and all (transitively) connected ones.
      See Also:
    • getConnectedEdges

      public static Iterator<KEdge> getConnectedEdges(KEdge edge)
      Determines the edges that are (transitively) connected to the given edge across hierarchy boundaries via common ports. Rational: Multiple edges that are pairwise connected by means of a KPort (target port of edge a == source port of edge b or vice versa) may form one logical connection. This kind of splitting might be already present in the view model, or is performed by the layout algorithm for decomposing a nested layout input graph into flat sub graphs.
      Parameters:
      edge - the edge check for connected edges
      Returns:
      an Iterator visiting the given edge and all connected edges in a(n almost) breadth first search fashion
    • getConnectedElements

      public static Iterator<KGraphElement> getConnectedElements(KEdge edge, boolean addPorts)
      Determines the ElkGraphElements that are (transitively) connected to edge across hierarchy boundaries via common ports. Rational: Multiple KEdges that are pairwise connected by means of a KPort (target port of edge a == source port of edge b or vice versa) may form one logical connection. This kind of splitting might be already present in the view model, or is performed by the layout algorithm for decomposing a nested layout input graph into flat sub graphs. This version allows to also include ports in the selection.
      Parameters:
      edge - the edge to check for connected elements
      addPorts - flag to determine, whether ports should be added to the selection or not
      Returns:
      an Iterator visiting the given edge and all connected edges in a(n almost) breadth first search fashion
    • getConnectedElements

      public static Iterator<KGraphElement> getConnectedElements(KEdge kedge, SelectionIterator sourceIterator, SelectionIterator targetIterator)
      Determines the KEdges that are (transitively) connected to kedge across hierarchy boundaries via common ports. Rational: Multiple KEdges that are pairwise connected by means of a KPort (target port of edge a == source port of edge b or vice versa) may form one logical connection. This kind of splitting might be already present in the view model, or is performed by the layout algorithm for decomposing a nested layout input graph into flat sub graphs.
      Parameters:
      kedge - the KEdge check for connected elements
      sourceIterator - the SelectionIterator to be used for iterating towards the tail of the selected edge
      targetIterator - the SelectionIterator to be used for iterating towards the head of the selected edge
      Returns:
      an Iterator visiting the given kedge and all connected elements determined by the SelectionIterators
    • isDescendant

      public static boolean isDescendant(KNode child, KNode parent)
      Determines whether the given child node is a descendant of the parent node. This method does not regard a node as its own descendant.
      Parameters:
      child - a child node
      parent - a parent node
      Returns:
      true if child is a direct or indirect child of parent.
    • isDescendant

      public static boolean isDescendant(KGraphElement child, KNode parent)
      Determines whether the given child element is a descendant of the parent node. This method does not regard a node as its own descendant.
      Parameters:
      child - a child element
      parent - a parent node
      Returns:
      true if child is contained directly or indirectly in parent.
    • containedGraph

      public static KNode containedGraph(KEdge edge)
      Returns the graph the given edge belongs to. If the target is a descendant of the source node, the latter is the contained graph. Otherwise, the source's parent is the contained node.
      Parameters:
      edge - the edge.
      Returns:
      the graph that contains the edge.
    • isSibling

      public static boolean isSibling(KNode node1, KNode node2)
      Determines whether the given two nodes are siblings, that is if they have the same parent node. If they do not have a parent node they are not considered siblings.
      Parameters:
      node1 - the first node.
      node2 - the second node.
      Returns:
      true if the two nodes have the same non-null parent.
    • getRootNodeOf

      public static KNode getRootNodeOf(KNode node)
      Determines the root of the given node.
      Parameters:
      node - KNode, which root should be returned.
      Returns:
      The root of the given node.
    • getAdjacentNodes

      public static List<KNode> getAdjacentNodes(KNode node)
      Collects the adjacent nodes of node in a list.
      Parameters:
      node - The node of which you want to know the adjacent nodes.
      Returns:
      The adjacent nodes of the given node