Drawing

Algorithms

jgrapht.algorithms.drawing.circular_layout_2d(graph, area, radius, vertex_comparator_cb=None)[source]

Circular 2d layout.

The algorithm places the graph vertices on a circle evenly spaced. The vertices are iterated based on the iteration order of the vertex set of the graph. The order can be adjusted by providing an external comparator.

Parameters
  • graph – the graph to draw

  • area – the two dimensional area as a tuple (minx, miny, width, height)

  • radius – radius of the circle

  • vertex_comparator_cb – a vertex comparator. Should be a function which accepts two vertices v1, v2 and return -1, 0, 1 depending of whether v1 < v2, v1 == v2, or v1 > v2 in the ordering

Returns

a 2d layout model as an instance of jgrapht.types.LayoutModel2D.

jgrapht.algorithms.drawing.fruchterman_reingold_indexed_layout_2d(graph, area, iterations=100, normalization_factor=0.5, seed=None, theta=0.5, tolerance=None)[source]

Fruchterman and Reingold Force-Directed Placement.

The algorithm belongs in the broad category of force directed graph drawing algorithms and is described in the paper:

  • Thomas M. J. Fruchterman and Edward M. Reingold. Graph drawing by force-directed placement. Software: Practice and experience, 21(11):1129–1164, 1991.

This implementation uses the Barnes-Hut indexing technique with a QuadTree. The Barnes-Hut indexing technique is described in the following paper:

  • J. Barnes and P. Hut. A hierarchical O(N log N) force-calculation algorithm. Nature. 324(4):446–449, 1986.

An inverse linear temperature model is used for the annealing schedule.

Parameters
  • graph – the graph to draw

  • area – the two dimensional area as a tuple (minx, miny, width, height)

  • iterations – number of iterations

  • normalization_factor – normalization factor when calculating optimal distance

  • seed – seed for the random number generator. If None the system time is used

  • theta – parameter for approximation using the Barnes-Hut technique

Parram tolerance

tolerance used when comparing floating point values

Returns

a 2d layout model as an instance of jgrapht.types.LayoutModel2D.

jgrapht.algorithms.drawing.fruchterman_reingold_layout_2d(graph, area, iterations=100, normalization_factor=0.5, seed=None)[source]

Fruchterman and Reingold Force-Directed Placement.

The algorithm belongs in the broad category of force directed graph drawing algorithms and is described in the paper:

  • Thomas M. J. Fruchterman and Edward M. Reingold. Graph drawing by force-directed placement. Software: Practice and experience, 21(11):1129–1164, 1991.

An inverse linear temperature model is used for the annealing schedule.

Parameters
  • graph – the graph to draw

  • area – the two dimensional area as a tuple (minx, miny, width, height)

  • iterations – number of iterations

  • normalization_factor – normalization factor when calculating optimal distance

  • seed – seed for the random number generator. If None the system time is used

Returns

a 2d layout model as an instance of jgrapht.types.LayoutModel2D.

jgrapht.algorithms.drawing.random_layout_2d(graph, area, seed=None)[source]

Random 2d layout.

The algorithm assigns vertex coordinates uniformly at random.

Parameters
  • graph – the graph to draw

  • area – the two dimensional area as a tuple (minx, miny, width, height)

  • seed – seed for the random number generator. If None the system time is used

Returns

a 2d layout model as an instance of jgrapht.types.LayoutModel2D.

Types

The result of the 2D drawing algorithms are instances of the following class.

class jgrapht.types.LayoutModel2D[source]

A 2D Layout Model.

abstract area()[source]

The 2D drawable area.

abstract get_vertex_location(vertex)[source]

Get the location of a vertex.

abstract is_fixed(vertex, fixed)[source]

Check if a vertex is fixed.

abstract set_fixed(vertex, fixed)[source]

Set the fixed status of a vertex.

abstract set_vertex_location(vertex, point_2d)[source]

Set the location of a vertex.