Utils#
Submodules#
graphistry.layout.utils.dummyVertex module#
- class graphistry.layout.utils.dummyVertex.DummyVertex(r=None)#
Bases:
LayoutVertex
A DummyVertex is used for edges that span over several layers, it’s inserted in every inner layer.
- Attributes
view (viewclass): since a DummyVertex is acting as a Vertex, it must have a view.
ctrl (list[_sugiyama_attr]): the list of associated dummy vertices.
- inner(direction)#
True if a neighbor in the given direction is dummy.
- neighbors(direction)#
Reflect the Vertex method and returns the list of adjacent vertices (possibly dummy) in the given direction. :param direction: +1 for the next layer (children) and -1 (parents) for the previous
- Parameters:
direction (int)
graphistry.layout.utils.geometry module#
- graphistry.layout.utils.geometry.angle_between_vectors(p1, p2)#
- graphistry.layout.utils.geometry.lines_intersection(xy1, xy2, xy3, xy4)#
Returns the intersection of two lines.
- graphistry.layout.utils.geometry.new_point_at_distance(pt, distance, angle)#
- graphistry.layout.utils.geometry.rectangle_point_intersection(rec, p)#
Returns the intersection point between the Rectangle (w,h) that characterize the rec object and the line that goes from the recs’ object center to the ‘p’ point.
- graphistry.layout.utils.geometry.set_round_corner(e, pts)#
- graphistry.layout.utils.geometry.setcurve(e, pts, tgs=None)#
Returns the spline curve that path through the list of points P. The spline curve is a list of cubic bezier curves (nurbs) that have matching tangents at their extreme points. The method considered here is taken from “The NURBS book” (Les A. Piegl, Wayne Tiller, Springer, 1997) and implements a local interpolation rather than a global interpolation.
- Args:
e: pts: tgs:
Returns:
- graphistry.layout.utils.geometry.size_median(recs)#
- graphistry.layout.utils.geometry.tangents(P, n)#
graphistry.layout.utils.layer module#
- class graphistry.layout.utils.layer.Layer(iterable=(), /)#
Bases:
list
Layer is where Sugiyama layout organises vertices in hierarchical lists. The placement of a vertex is done by the Sugiyama class, but it highly relies on the ordering of vertices in each layer to reduce crossings. This ordering depends on the neighbors found in the upper or lower layers.
- Attributes:
layout (SugiyamaLayout): a reference to the sugiyama layout instance that contains this layer upper (Layer): a reference to the upper layer (layer-1) lower (Layer): a reference to the lower layer (layer+1) crossings (int) : number of crossings detected in this layer
- Methods:
setup (layout): set initial attributes values from provided layout nextlayer(): returns next layer in the current layout’s direction parameter. prevlayer(): returns previous layer in the current layout’s direction parameter. order(): compute optimal ordering of vertices within the layer.
- crossings = None#
- layout = None#
- lower = None#
- neighbors(v)#
neighbors refer to upper/lower adjacent nodes. Note that v.neighbors() provides neighbors of v in the graph, while this method provides the Vertex and DummyVertex adjacent to v in the upper or lower layer (depending on layout.dirv state).
- nextlayer()#
- order()#
- prevlayer()#
- setup(layout)#
- upper = None#
graphistry.layout.utils.layoutVertex module#
- class graphistry.layout.utils.layoutVertex.LayoutVertex(layer=None, is_dummy=0)#
Bases:
object
The Sugiyama layout adds new attributes to vertices. These attributes are stored in an internal _sugimyama_vertex_attr object.
- Attributes:
layer (int): layer number dummy (0/1): whether the vertex is a dummy pos (int): the index of the vertex within the layer x (list(float)): the list of computed horizontal coordinates of the vertex bar (float): the current barycenter of the vertex
- Parameters:
layer (int | None)
graphistry.layout.utils.poset module#
- class graphistry.layout.utils.poset.Poset(collection=[])#
Bases:
object
Poset class implements a set but allows to integrate over the elements in a deterministic way and to get specific objects in the set. Membership operator defaults to comparing __hash__ of objects but Poset allows to check for __cmp__/__eq__ membership by using contains__cmp__(obj)
- add(obj)#
- contains__cmp__(obj)#
- copy()#
- deepcopy()#
- difference(*args)#
- get(obj)#
- index(obj)#
- intersection(*args)#
- issubset(other)#
- issuperset(other)#
- remove(obj)#
- symmetric_difference(*args)#
- union(other)#
- update(other)#
graphistry.layout.utils.rectangle module#
- class graphistry.layout.utils.rectangle.Rectangle(w=1, h=1)#
Bases:
object
Rectangular region.
graphistry.layout.utils.routing module#
- graphistry.layout.utils.routing.route_with_lines(e, pts)#
Basic edge routing with lines. The layout pass has already provided to list of points through which the edge shall be drawn. We just compute the position where to adjust the tail and head.
- graphistry.layout.utils.routing.route_with_rounded_corners(e, pts)#
- graphistry.layout.utils.routing.route_with_splines(e, pts)#
Enhanced edge routing where ‘corners’ of the above polyline route are rounded with a Bezier curve.
Module contents#
graphistry.layout.graph.edge module#
- class graphistry.layout.graph.edge.Edge(x, y, w=1, data=None, connect=False)#
Bases:
EdgeBase
A graph edge.
- Attributes
data (object): an optional payload
w (int): an optional weight associated with the edge (default 1) used by Dijkstra to find min-flow paths.
feedback (bool): whether the Tarjan algorithm has inverted this edge to de-cycle the graph.
- Parameters:
w (int)
data (object)
- attach()#
Attach this edge to the edge collections of the vertices.
- data: object#
- detach()#
Removes this edge from the edge collections of the vertices.
- feedback: bool#
- w: int#
graphistry.layout.graph.edgeBase module#
graphistry.layout.graph.graph module#
- class graphistry.layout.graph.graph.Graph(vertices=None, edges=None, directed=True)#
Bases:
object
- N(v, f_io=0)#
- add_edge(e)#
add edge e and its vertices into the Graph possibly merging the associated graph_core components
- add_edges(edges)#
- Parameters:
edges (List)
- add_vertex(v)#
add vertex v into the Graph as a new component
- connected()#
returns the list of components
- deg_avg()#
the average degree of vertices
- deg_max()#
the maximum degree of vertices
- deg_min()#
the minimum degree of vertices
- edges()#
- eps()#
the graph epsilon value (norm/order), average number of edges per vertex.
- get_vertex_from_data(data)#
- get_vertices_count()#
- norm()#
the norm of the graph (number of edges)
- order()#
the order of the graph (number of vertices)
- path(x, y, f_io=0, hook=None)#
- remove_edge(e)#
remove edge e possibly spawning two new cores if the graph_core that contained e gets disconnected.
- remove_vertex(x)#
remove vertex v and all its edges.
- vertices()#
see graph_core
graphistry.layout.graph.graphBase module#
- class graphistry.layout.graph.graphBase.GraphBase(vertices=None, edges=None, directed=True)#
Bases:
object
A connected graph of Vertex/Edge objects. A GraphBase is a component of a Graph that contains a connected set of Vertex and Edges.
- Attributes:
verticesPoset (Poset[Vertex]): the partially ordered set of vertices of the graph. edgesPoset (Poset[Edge]): the partially ordered set of edges of the graph. loops (set[Edge]): the set of loop edges (of degree 0). directed (bool): indicates if the graph is considered oriented or not.
- N(v, f_io=0)#
- add_edge(e)#
add edge e. At least one of its vertex must belong to the graph, the other being added automatically.
- add_single_vertex(v)#
allow a GraphBase to hold a single vertex.
- complement(G)#
- constant_function(value)#
- contract(e)#
- deg_avg()#
the average degree of vertices
- deg_max()#
the maximum degree of vertices
- deg_min()#
the minimum degree of vertices
- dft(start_vertex=None)#
- dijkstra(x, f_io=0, hook=None)#
shortest weighted-edges paths between x and all other vertices by dijkstra’s algorithm with heap used as priority queue.
- edges(cond=None)#
generates an iterator over edges, with optional filter
- eps()#
the graph epsilon value (norm/order), average number of edges per vertex.
- get_scs_with_feedback(roots=None)#
Minimum FAS algorithm (feedback arc set) creating a DAG. Returns the set of strongly connected components (“scs”) by using Tarjan algorithm. These are maximal sets of vertices such that there is a path from each vertex to every other vertex. The algorithm performs a DFS from the provided list of root vertices. A cycle is of course a strongly connected component,but a strongly connected component can include several cycles. The Feedback Acyclic Set of edge to be removed/reversed is provided by marking the edges with a “feedback” flag. Complexity is O(V+E).
- Parameters:
roots
- Returns:
- leaves()#
returns the list of leaves (vertices with no outward edges).
- matrix(cond=None)#
This associativity matrix is like the adjacency matrix but antisymmetric. Returns the associativity matrix of the graph component
- Parameters:
cond – same a the condition function in vertices().
- Returns:
array
- norm()#
The size of the edge poset (number of edges).
- order()#
the order of the graph (number of vertices)
- partition()#
- path(x, y, f_io=0, hook=None)#
shortest path between vertices x and y by breadth-first descent, contrained by f_io direction if provided. The path is returned as a list of Vertex objects. If a hook function is provided, it is called at every vertex added to the path, passing the vertex object as argument.
- remove_edge(e)#
remove Edge e, asserting that the resulting graph is still connex.
- remove_vertex(x)#
remove Vertex x and all associated edges.
- roots()#
returns the list of roots (vertices with no inward edges).
- spans(vertices)#
- union_update(G)#
- vertices(cond=None)#
generates an iterator over vertices, with optional filter
graphistry.layout.graph.vertex module#
- class graphistry.layout.graph.vertex.Vertex(data=None)#
Bases:
VertexBase
Vertex class enhancing a VertexBase with graph-related features.
- Attributes
component (GraphBase): the component of connected vertices that contains this vertex. By default, a vertex belongs no component but when it is added in a graph, c points to the connected component in this graph. data (object) : an object associated with the vertex.
- property index#
graphistry.layout.graph.vertexBase module#
- class graphistry.layout.graph.vertexBase.VertexBase#
Bases:
object
Base class for vertices.
- Attributes
e (list[Edge]): list of edges associated with this vertex.
- degree()#
degree() : degree of the vertex (number of edges).
- detach()#
removes this vertex from all its edges and returns this list of edges.
- e_dir(dir)#
either e_in, e_out or all edges depending on provided direction parameter (>0 means outward).
- e_from(x)#
returns the Edge from vertex v directed toward this vertex.
- e_in()#
e_in() : list of edges directed toward this vertex.
- e_out()#
e_out(): list of edges directed outward this vertex.
- e_to(y)#
returns the Edge from this vertex directed toward vertex v.
- e_with(v)#
return the Edge with both this vertex and vertex v
- neighbors(direction=0)#
Returns the neighbors of this vertex. List of neighbor vertices in all directions (default) or in filtered f_io direction (>0 means outward).
- Parameters:
direction –
0: parent and children
-1: parents
+1: children
- Returns:
list of vertices