teachpyx.tools.graphviz_helper

teachpyx.tools.graphviz_helper.draw_graph_graphviz(vertices: List[Tuple[int, str]], edges: List[Tuple[int, int, str]], image: str | None = None, engine: str = 'dot') str[source][source]

Draws a graph using Graphviz.

Paramètres:
  • edges – see below

  • vertices – see below

  • image – output image, None, just returns the output

  • enginedot or neato

Renvoie:

Graphviz output or the dot text if image is None

The function creates a file <image>.gv if image is not None.

edges = [(1,2, label, color), (3,4), (1,3)]  # edges list
vertices = [(1, label, color), (2)]  # vertices list
image = "image_name.png"
teachpyx.tools.graphviz_helper.edges2gv(vertices: List[Tuple[int, str]], edges: List[Tuple[int, int, str]]) str[source][source]

Converts a graph into a Graphviz file format.

Paramètres:
  • edges – see below

  • vertices – see below

Renvoie:

gv format

The function creates a file <image>.gv.

<<<

from teachpyx.tools.graphviz_helper import edges2gv

gv = edges2gv([(1, "eee", "red")], [(1, 2, "blue"), (3, 4), (1, 3)])
print(gv)

>>>

    digraph{
    "1" [label="eee",fillcolor=red,color=red];
    2 ;
    3 ;
    4 ;
    "1" -> "2" [label="blue"];
    "3" -> "4";
    "1" -> "3";
    }
teachpyx.tools.graphviz_helper.find_graphviz_dot(exc: bool = True) str[source][source]

Determines the path to graphviz (on Windows), the function tests the existence of versions 34 to 45 assuming it was installed in a standard folder: C:\Program Files\MiKTeX 2.9\miktex\bin\x64.

Paramètres:

exc – raise exception of be silent

Renvoie:

path to dot

Lève:

FileNotFoundError – if graphviz not found

teachpyx.tools.graphviz_helper.find_in_PATH(prog: str) str | None[source][source]

Looks into every path mentioned in %PATH% a specific file, it raises an exception if not found.

Paramètres:

prog – program to look for

Renvoie:

path

teachpyx.tools.graphviz_helper.run_graphviz(filename: str, image: str, engine: str = 'dot') str[source][source]

Run Graphviz.

Paramètres:
  • filename – filename which contains the graph definition

  • image – output image

  • enginedot or neato

Renvoie:

output of graphviz