Sugiyama Layout#
We recommend using plugin versions of this layout instead, such as from igraph
graphistry.layout.sugiyama.sugiyamaLayout module#
- class graphistry.layout.sugiyama.sugiyamaLayout.SugiyamaLayout(g)#
Bases:
object
The classic Sugiyama layout aka layered layout.
Excellent explanation: https://www.youtube.com/watch?v=Z0RGCWxvCxA
- Attributes
- dirvh (int): the current aligment state for alignment policy:
dirvh=0 -> dirh=+1, dirv=-1: leftmost upper dirvh=1 -> dirh=-1, dirv=-1: rightmost upper dirvh=2 -> dirh=+1, dirv=+1: leftmost lower dirvh=3 -> dirh=-1, dirv=+1: rightmost lower
order_iter (int): the default number of layer placement iterations
order_attr (str): set attribute name used for layer ordering
xspace (int): horizontal space between vertices in a layer
yspace (int): vertical space between layers
dw (int): default width of a vertex
dh (int): default height of a vertex
g (GraphBase): the graph component reference
layers (list[sugiyama.layer.Layer]): the list of layers
layoutVertices (dict): associate vertex (possibly dummy) with their sugiyama attributes
ctrls (dict): associate edge with all its vertices (including dummies)
dag (bool): the current acyclic state
init_done (bool): True if things were initialized
Example
g = nx.generators.connected_watts_strogatz_graph(1000, 2, 0.3) # render SugiyamaLayout.draw(g) # positions positions_dictionary = SugiyamaLayout.arrange(g)
- Parameters:
g (GraphBase)
- static arrange(obj, iteration_count=1.5, source_column='source', target_column='target', layout_direction=0, topological_coordinates=False, root=None, include_levels=False)#
Returns the positions from a Sugiyama layout iteration.
- Parameters:
layout_direction –
0: top-to-bottom
1: right-to-left
2: bottom-to-top
3: left-to-right
obj (DataFrame | Graph) – can be a Sugiyama graph or a Pandas frame.
iteration_count – increase the value for diminished crossings
source_column – if a Pandas frame is given, the name of the column with the source of the edges
target_column – if a Pandas frame is given, the name of the column with the target of the edges
topological_coordinates – whether to use coordinates with the x-values in the [0,1] range and the y-value equal to the layer index.
include_levels – whether the tree-level is included together with the coordinates. If so, you get a triple (x,y,level).
root – optional list of roots.
- Returns
a dictionary of positions.
- create_dummies(e)#
Creates and defines all dummy vertices for edge e.
- ctrls: Dict[Vertex, LayoutVertex]#
- property dirh#
- property dirv#
- property dirvh#
- draw_step()#
Iterator that computes all vertices coordinates and edge routing after just one step (one layer after the other from top to bottom to top). Use it only for “animation” or debugging purpose.
- dummyctrl(r, control_vertices)#
Creates a DummyVertex at layer r inserted in the ctrl dict of the associated edge and layer.
- Arguments
r (int): layer value
ctrl (dict): the edge’s control vertices
- Returns
sugiyama.DummyVertex : the created DummyVertex.
- static ensure_root_is_vertex(g, root)#
Turns the given list of roots (names or data) to actual vertices in the given graph.
- Parameters:
g (Graph) – the graph wherein the given roots names are supposed to be
root (object) – the data or the vertex
- Returns:
the list of vertices to use as roots
- find_nearest_layer(start_vertex)#
- static graph_from_pandas(df, source_column='source', target_column='target')#
- static has_cycles(obj, source_column='source', target_column='target')#
- Parameters:
obj (DataFrame | Graph)
- initialize(root=None)#
Initializes the layout algorithm.
- Parameters:
root (Vertex): a vertex to be used as root
- layout(iteration_count=1.5, topological_coordinates=False, layout_direction=0)#
Compute every node coordinates after converging to optimal ordering by N rounds, and finally perform the edge routing.
- Parameters:
topological_coordinates – whether to use ( [0,1], layer index) coordinates
- layoutVertices#
The map from vertex to LayoutVertex.
- layout_edges()#
Basic edge routing applied only for edges with dummy points. Enhanced edge routing can be performed by using the appropriate
- ordering_step(oneway=False)#
iterator that computes all vertices ordering in their layers (one layer after the other from top to bottom, to top again unless oneway is True).
- set_coordinates()#
Computes all vertex coordinates using Brandes & Kopf algorithm. See https://www.semanticscholar.org/paper/Fast-and-Simple-Horizontal-Coordinate-Assignment-Brandes-Köpf/69cb129a8963b21775d6382d15b0b447b01eb1f8
- set_topological_coordinates(layout_direction=0)#
- xspace: int#
- yspace: int#