|
@@ -39,6 +39,7 @@ def setcluster(cluster): |
|
|
|
|
|
|
|
|
class Diagram: |
|
|
class Diagram: |
|
|
__directions = ("TB", "BT", "LR", "RL") |
|
|
__directions = ("TB", "BT", "LR", "RL") |
|
|
|
|
|
__curvestyles = ("ortho", "curved") |
|
|
__outformats = ("png", "jpg", "svg", "pdf") |
|
|
__outformats = ("png", "jpg", "svg", "pdf") |
|
|
|
|
|
|
|
|
# fmt: off |
|
|
# fmt: off |
|
@@ -78,6 +79,7 @@ class Diagram: |
|
|
name: str = "", |
|
|
name: str = "", |
|
|
filename: str = "", |
|
|
filename: str = "", |
|
|
direction: str = "LR", |
|
|
direction: str = "LR", |
|
|
|
|
|
curvestyle: str = "ortho", |
|
|
outformat: str = "png", |
|
|
outformat: str = "png", |
|
|
show: bool = True, |
|
|
show: bool = True, |
|
|
graph_attr: dict = {}, |
|
|
graph_attr: dict = {}, |
|
@@ -91,6 +93,7 @@ class Diagram: |
|
|
:param filename: The output filename, without the extension (.png). |
|
|
:param filename: The output filename, without the extension (.png). |
|
|
If not given, it will be generated from the name. |
|
|
If not given, it will be generated from the name. |
|
|
:param direction: Data flow direction. Default is 'left to right'. |
|
|
:param direction: Data flow direction. Default is 'left to right'. |
|
|
|
|
|
:param curvestyle: Curve bending style. One of "ortho" or "curved". |
|
|
:param outformat: Output file format. Default is 'png'. |
|
|
:param outformat: Output file format. Default is 'png'. |
|
|
:param show: Open generated image after save if true, just only save otherwise. |
|
|
:param show: Open generated image after save if true, just only save otherwise. |
|
|
:param graph_attr: Provide graph_attr dot config attributes. |
|
|
:param graph_attr: Provide graph_attr dot config attributes. |
|
@@ -117,6 +120,10 @@ class Diagram: |
|
|
raise ValueError(f'"{direction}" is not a valid direction') |
|
|
raise ValueError(f'"{direction}" is not a valid direction') |
|
|
self.dot.graph_attr["rankdir"] = direction |
|
|
self.dot.graph_attr["rankdir"] = direction |
|
|
|
|
|
|
|
|
|
|
|
if not self._validate_curvestyle(curvestyle): |
|
|
|
|
|
raise ValueError(f'"{curvestyle}" is not a valid curvestyle') |
|
|
|
|
|
self.dot.graph_attr["splines"] = curvestyle |
|
|
|
|
|
|
|
|
if not self._validate_outformat(outformat): |
|
|
if not self._validate_outformat(outformat): |
|
|
raise ValueError(f'"{outformat}" is not a valid output format') |
|
|
raise ValueError(f'"{outformat}" is not a valid output format') |
|
|
self.outformat = outformat |
|
|
self.outformat = outformat |
|
@@ -151,6 +158,13 @@ class Diagram: |
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def _validate_curvestyle(self, curvestyle: str) -> bool: |
|
|
|
|
|
curvestyle = curvestyle.lower() |
|
|
|
|
|
for v in self.__curvestyles: |
|
|
|
|
|
if v == curvestyle: |
|
|
|
|
|
return True |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
def _validate_outformat(self, outformat: str) -> bool: |
|
|
def _validate_outformat(self, outformat: str) -> bool: |
|
|
outformat = outformat.lower() |
|
|
outformat = outformat.lower() |
|
|
for v in self.__outformats: |
|
|
for v in self.__outformats: |
|
|