Edge Layout / Routing

get_straight_edge_paths(edges, ...)

Edge routing using straight lines.

get_curved_edge_paths(edges, node_positions)

Edge routing using curved paths that avoid nodes and other edges.

get_bundled_edge_paths(edges, node_positions)

Edge routing with bundled edge paths.

netgraph.get_straight_edge_paths(edges, node_positions, edge_width)[source]

Edge routing using straight lines.

Computes the edge paths, such that edges are represented by straight lines connecting the source and target node. Bi-directional edges are offset from one another by one edge width.

Parameters:
edgeslist

The edges of the graph, with each edge being represented by a (source node ID, target node ID) tuple.

node_positionsdict

Dictionary mapping each node ID to (float x, float y) tuple, the node position.

edge_width: dict

Dictionary mapping each edge to a float, the edge width.

Returns:
edge_pathsdict

Dictionary mapping each edge to an array of (x, y) coordinates representing its path.

netgraph.get_curved_edge_paths(edges, node_positions, selfloop_radius=0.1, origin=array([0, 0]), scale=array([1, 1]), k=None, initial_temperature=0.01, total_iterations=50, node_size=0.0, bundle_parallel_edges=True)[source]

Edge routing using curved paths that avoid nodes and other edges.

Computes the edge paths, such that edges are represented by curved lines connecting the source and target node. Edges paths avoid nodes and each other. The edge layout is determined using the Fruchterman-Reingold algorithm.

Parameters:
edgeslist

The edges of the graph, with each edge being represented by a (source node ID, target node ID) tuple.

node_positionsdict

Dictionary mapping each node ID to (float x, float y) tuple, the node position.

selfloop_radiusfloat

The radius of the self-loops.

originnumpy.array

A (float x, float y) tuple corresponding to the lower left hand corner of the bounding box specifying the extent of the canvas.

scalenumpy.array

A (float x, float y) tuple representing the width and height of the bounding box specifying the extent of the canvas.

kfloat or None, default None

Spring constant, which controls the tautness of edges. Small values will result in straight connections, large values in bulging arcs. If None, initialized to: 0.1 * sqrt(area / total nodes).

total_iterationsint, default 50

Number of iterations in the Fruchterman-Reingold algorithm.

initial_temperature: float, default 1.

Temperature controls the maximum node displacement on each iteration. Temperature is decreased on each iteration to eventually force the algorithm into a particular solution. The size of the initial temperature determines how quickly that happens. Values should be much smaller than the values of scale.

node_sizefloat or dict

Dictionary mapping each node to a float, the node size. Used for node avoidance.

bundle_parallel_edges: boolean, default True

If True, parallel edges (including bi-directional edges) have the same path.

Returns:
edge_pathsdict

Dictionary mapping each edge to an array of (x, y) coordinates representing its path.

netgraph.get_bundled_edge_paths(edges, node_positions, k=1000.0, compatibility_threshold=0.05, total_cycles=5, total_iterations=50, step_size=0.04, straighten_by=0.0)[source]

Edge routing with bundled edge paths.

Uses the FDEB algorithm as proposed in [Holten2009]. This implementation follows the paper closely with the exception that instead of doubling the number of control point on each iteration (2n), a new control point is inserted between each existing pair of control points (2(n-1)+1), as proposed e.g. in Wu et al. (2015) [Wu2015].

Parameters:
edgeslist

The edges of the graph, with each edge being represented by a (source node ID, target node ID) tuple.

node_positionsdict

Dictionary mapping each node ID to (float x, float y) tuple, the node position.

kfloat, default 1000.

The stiffness of the springs that connect control points.

compatibility_thresholdfloat, default 0.05

Edge pairs with a lower compatibility score are not bundled together. Set to zero to bundle all edges with each other regardless of compatibility. Set to one to prevent bundling of any (non-identical) edges.

total_cyclesint, default 5

The number of cycles. The number of control points (P) is doubled each cycle.

total_iterationsint, default 50

Number of iterations (I) in the first cycle. Iterations are reduced by 1/3 with each cycle.

step_sizefloat, default 0.04

Maximum step size (S) in the first cycle. Step sizes are halved each cycle.

straighten_byfloat, default 0.

The amount of edge straightening applied after bundling. A small amount of straightening can help indicating the number of edges comprising a bundle by widening the bundle. If set to one, edges are fully un-bundled and plotted as stright lines.

Returns:
edge_pathsdict

Dictionary mapping each edge to an array of (x, y) coordinates representing its path.

References

[Holten2009]

Holten D and Van Wijk JJ. (2009) ‘Force-Directed edge bundling for graph visualization’, Computer Graphics Forum.

[Wu2015]

Wu J, Yu L, Yu H (2015) ‘Texture-based edge bundling: A web-based approach for interactively visualizing large graphs’, IEEE International Conference on Big Data.