Class KGraphUtil
java.lang.Object
de.cau.cs.kieler.klighd.kgraph.util.KGraphUtil
Utility methods to operate on KGraphs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA tree iterator that skips persistent entries ofEMapPropertyHolders. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatDefault minimal height for nodes.static final floatDefault minimal width for nodes. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.elk.core.options.PortSidecalcPortSide(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.static voidAdds a default label to the graph element based on theKIdentifier.static voidAdds some default values to the passed node.static voidAdds some default values to the passed port.static voidSets a default size to the passed element which is based onDEFAULT_MIN_WIDTHandDEFAULT_MIN_HEIGHTin conjunction with a scaling factor based on the type of the element.static KNodecontainedGraph(KEdge edge) Returns the graph the given edge belongs to.static KEdgeCreates an initialized edge.static KLabelCreates an intialized label and adds it to the given element.static KNodeCreates an initialized node.static KPortCreates an initialized port.static org.eclipse.elk.core.math.KVectorgetAbsolute(KGraphElement element) Returns the absolute position of the given element from the positions of itsKShapeLayoutparents.getAdjacentNodes(KNode node) Collects the adjacent nodes ofnodein a list.getConnectedEdges(KEdge edge) Deprecated.getConnectedEdges(Iterable<KEdge> edges) Deprecated.UsegetConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIteratorstatic Iterator<KGraphElement>getConnectedElements(KEdge edge, boolean addPorts) Deprecated.UsegetConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIteratorstatic Iterator<KGraphElement>getConnectedElements(KEdge kedge, SelectionIterator sourceIterator, SelectionIterator targetIterator) Determines theKEdgesthat are (transitively) connected tokedgeacross hierarchy boundaries via common ports.static KNodegetRootNodeOf(KNode node) Determines the root of the given node.static booleanisDescendant(KGraphElement child, KNode parent) Determines whether the given child element is a descendant of the parent node.static booleanisDescendant(KNode child, KNode parent) Determines whether the given child node is a descendant of the parent node.static booleanDetermines whether the given two nodes are siblings, that is if they have the same parent node.static voidpersistDataElements(KNode graph) Persists allEMapPropertyHolders of a KGraph by serializing the contained properties intoPersistentEntrytuples.static org.eclipse.elk.core.math.KVectortoAbsolute(org.eclipse.elk.core.math.KVector point, KNode parent) Converts the given relative point to an absolute location.static voidtoELKGraphCoordinateSystem(org.eclipse.elk.graph.ElkEdge elkedge, KInsets insets) Translates all coordinates of the given edge from KLighD's to ELK's coordinate system.static voidtoKGraphCoordinateSystem(org.eclipse.elk.graph.ElkEdge elkedge, KInsets insets) Translates all coordinates of the given edge from ELK's to KLighD's coordinate system.static org.eclipse.elk.core.math.KVectortoRelative(org.eclipse.elk.core.math.KVector point, KNode parent) Converts the given absolute point to a relative location.static voidEnsures that each element contained in the given graph is attributed correctly for usage in ELK.
-
Field Details
-
DEFAULT_MIN_WIDTH
public static final float DEFAULT_MIN_WIDTHDefault minimal width for nodes.- See Also:
-
DEFAULT_MIN_HEIGHT
public static final float DEFAULT_MIN_HEIGHTDefault minimal height for nodes.- See Also:
-
-
Method Details
-
createInitializedNode
Creates an initialized node. Its insets are set to zero.- Returns:
- initialized node.
-
createInitializedPort
Creates an initialized port. Its insets are set to zero.- Returns:
- initialized port.
-
createInitializedLabel
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
Creates an initialized edge. Its source and target point are set to zero.- Returns:
- the initialized edge.
-
validate
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
Adds a default label to the graph element based on theKIdentifier. 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
Sets a default size to the passed element which is based onDEFAULT_MIN_WIDTHandDEFAULT_MIN_HEIGHTin conjunction with a scaling factor based on the type of the element.- Parameters:
ele- the element to configure.
-
configureWithDefaultValues
Adds some default values to the passed node. This includes a reasonable size, a label based on the node'sKIdentifierand a inside center node label placement. Such default values are useful for fast test case generation.- Parameters:
node- a node of a graph
-
configureWithDefaultValues
Adds some default values to the passed port. This includes a reasonable size and a label based on the port'sKIdentifier. Such default values are useful for fast test case generation.- Parameters:
port- a port of a node of a graph
-
persistDataElements
Persists allEMapPropertyHolders of a KGraph by serializing the contained properties intoPersistentEntrytuples.- 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 pointparent- the parent node to which the point is relative to- Returns:
pointfor 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 pointparent- the parent node to which the point shall be made relative to- Returns:
pointfor convenience
-
getAbsolute
Returns the absolute position of the given element from the positions of itsKShapeLayoutparents.- 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 analyzedirection- the overall layout direction- Returns:
- the port side relative to its containing node
- Throws:
IllegalArgumentException- if the containing node isnull.
-
toKGraphCoordinateSystem
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
KNodethe 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 oftoKGraphCoordinateSystem(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
Deprecated.UsegetConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIteratorDetermines the edges that are (transitively) connected to the given edges across hierarchy boundaries via common ports. SeegetConnectedEdges(KEdge)for details. -
getConnectedEdges
Deprecated.UsegetConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIteratorDetermines 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 aKPort(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
Iteratorvisiting the given edge and all connected edges in a(n almost) breadth first search fashion
-
getConnectedElements
Deprecated.UsegetConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIteratorDetermines theElkGraphElementsthat are (transitively) connected toedgeacross hierarchy boundaries via common ports. Rational: MultipleKEdgesthat are pairwise connected by means of aKPort(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 elementsaddPorts- flag to determine, whether ports should be added to the selection or not- Returns:
- an
Iteratorvisiting the givenedgeand all connected edges in a(n almost) breadth first search fashion
-
getConnectedElements
public static Iterator<KGraphElement> getConnectedElements(KEdge kedge, SelectionIterator sourceIterator, SelectionIterator targetIterator) Determines theKEdgesthat are (transitively) connected tokedgeacross hierarchy boundaries via common ports. Rational: MultipleKEdgesthat are pairwise connected by means of aKPort(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- theKEdgecheck for connected elementssourceIterator- theSelectionIteratorto be used for iterating towards the tail of the selected edgetargetIterator- theSelectionIteratorto be used for iterating towards the head of the selected edge- Returns:
- an
Iteratorvisiting the givenkedgeand all connected elements determined by theSelectionIterators
-
isDescendant
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 nodeparent- a parent node- Returns:
trueifchildis a direct or indirect child ofparent.
-
isDescendant
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 elementparent- a parent node- Returns:
trueifchildis contained directly or indirectly inparent.
-
containedGraph
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
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:
trueif the two nodes have the same non-nullparent.
-
getRootNodeOf
Determines the root of the given node.- Parameters:
node- KNode, which root should be returned.- Returns:
- The root of the given node.
-
getAdjacentNodes
Collects the adjacent nodes ofnodein a list.- Parameters:
node- The node of which you want to know the adjacent nodes.- Returns:
- The adjacent nodes of the given node
-
getConnectedElements(KEdge, SelectionIterator, SelectionIterator)in combination withDefaultSelectionIterator