@ -40,7 +40,7 @@ def setcluster(cluster):
class Diagram :
class Diagram :
__directions = ( " TB " , " BT " , " LR " , " RL " )
__directions = ( " TB " , " BT " , " LR " , " RL " )
__curvestyles = ( " ortho " , " curved " )
__curvestyles = ( " ortho " , " curved " )
__outformats = ( " png " , " jpg " , " svg " , " pdf " )
__outformats = ( " png " , " jpg " , " svg " , " pdf " , " dot " )
# fmt: off
# fmt: off
_default_graph_attrs = {
_default_graph_attrs = {
@ -127,6 +127,11 @@ class Diagram:
raise ValueError ( f ' " { curvestyle } " is not a valid curvestyle ' )
raise ValueError ( f ' " { curvestyle } " is not a valid curvestyle ' )
self . dot . graph_attr [ " splines " ] = curvestyle
self . dot . graph_attr [ " splines " ] = curvestyle
if isinstance ( outformat , list ) :
for one_format in outformat :
if not self . _validate_outformat ( one_format ) :
raise ValueError ( f ' " { one_format } " is not a valid output format ' )
else :
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
@ -155,25 +160,13 @@ class Diagram:
return self . dot . pipe ( format = " png " )
return self . dot . pipe ( format = " png " )
def _validate_direction ( self , direction : str ) - > bool :
def _validate_direction ( self , direction : str ) - > bool :
direction = direction . upper ( )
return direction . upper ( ) in self . __directions
for v in self . __directions :
if v == direction :
return True
return False
def _validate_curvestyle ( self , curvestyle : str ) - > bool :
def _validate_curvestyle ( self , curvestyle : str ) - > bool :
curvestyle = curvestyle . lower ( )
return curvestyle . lower ( ) in self . __curvestyles
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 ( )
return outformat . lower ( ) in self . __outformats
for v in self . __outformats :
if v == outformat :
return True
return False
def node ( self , nodeid : str , label : str , * * attrs ) - > None :
def node ( self , nodeid : str , label : str , * * attrs ) - > None :
""" Create a new node. """
""" Create a new node. """
@ -188,6 +181,10 @@ class Diagram:
self . dot . subgraph ( dot )
self . dot . subgraph ( dot )
def render ( self ) - > None :
def render ( self ) - > None :
if isinstance ( self . outformat , list ) :
for one_format in self . outformat :
self . dot . render ( format = one_format , view = self . show , quiet = True )
else :
self . dot . render ( format = self . outformat , view = self . show , quiet = True )
self . dot . render ( format = self . outformat , view = self . show , quiet = True )
@ -263,8 +260,7 @@ class Cluster:
def _validate_direction ( self , direction : str ) :
def _validate_direction ( self , direction : str ) :
direction = direction . upper ( )
direction = direction . upper ( )
for v in self . __directions :
if direction in self . __directions :
if v == direction :
return True
return True
return False
return False