edgegraph.output.plaintext.basic_render

Contents

edgegraph.output.plaintext.basic_render#

edgegraph.output.plaintext.basic_render(uni, rfunc=None, sort=None)#

Perform a very basic rendering of a graph into a string.

This function does not do any proper graph traversals; instead, simply works down the list of vertices in the given universe.

If specified, rfunc should be a callable object accepting one argument and returning a string. It will be given each vertex, and expected to return the user’s choice of how they wish that vertex to be rendered. Likewise, if specified, sort should be a callable accepting one argument and returning a comparison key for use in sorted().

The intended usage is as follows:

>>> from edgegraph.builder import randgraph
>>> from edgegraph.output import plaintext
>>> graph = randgraph.randgraph()
>>> asci = plaintext.basic_render(graph)
>>> print(asci, rfunc=lambda v: v.i)
7 -> 5
4 -> 6
14 -> 14, 7, 13
11 -> 1, 11, 4
8 -> 14, 8
0 -> 12
3 -> 5
5 -> 0
12 -> 3, 1
1 -> 8
9 -> 4
6 -> 7
2 -> 13
10 -> 7, 10, 8
13 -> 7

Todo

figure out what to do to make this pass doctest… if graph is randomized, graph is different every time –> test fails

Parameters:
  • uni (Universe) – The universe to render.

  • rfunc (Callable | None) – Callable render function, if any.

  • sort (Callable | None) – Callable sorting key function, if any.

Returns:

Multi-line output of the rendering operation, or None if the universe is empty.

Return type:

str | None