
    z	i~                       S SK Jr  S SKrS SKrS SKrS SKJrJrJrJ	r	  S SK
JrJr   S SKJr  Sr\	(       a  S SKJr  \" S5      r\" S	5      rS
/r1 Skr1 Skr      S               SS jjrg! \ a    Sr NOf = f)    )annotationsN)TypeVarCallablecastTYPE_CHECKING)	PyDiGraphPyGraph)ImageTF_S_Tgraphviz_draw>   dotfdpsfdpcirconeatotwopi>$   gdmppsdiar   figgd2gifjpejpgmifpclpdfpicpngps2svgvmlvtxcmaphpglimapjpegsvgzvmlzvrmlwbmpxdorxlibcanoncmapxismapplainimap_npcmapx_np	plain-extc           	        [         (       d  [        S5      e [        R                  " SS/[        R
                  " 5       SSS9  [        [        U R                  XU5      5      nUc  SnO!U[        ;  a  [        S	U S
[         35      eUnUc  Sn	O!U[        ;  a  [        SU S
[         35      eUn	U(       dc  [        R                  " U	SU/UR                  S5      SSSSS9n
[        R                   " U
R"                  5      n[$        R&                  " U5      nU$ [        R                  " U	SUSU/USSSS9  g! [         a    [        S5      ef = f)a  Draw a :class:`~rustworkx.PyGraph` or :class:`~rustworkx.PyDiGraph` object
using graphviz

.. note::

    This requires that pydot, pillow, and graphviz be installed. Pydot can
    be installed via pip with ``pip install pydot pillow`` however graphviz
    will need to be installed separately. You can refer to the
    Graphviz
    `documentation <https://graphviz.org/download/#executable-packages>`__
    for instructions on how to install it.

:param graph: The rustworkx graph object to draw, can be a
    :class:`~rustworkx.PyGraph` or a :class:`~rustworkx.PyDiGraph`
:param node_attr_fn: An optional callable object that will be passed the
    weight/data payload for every node in the graph and expected to return
    a dictionary of Graphviz node attributes to be associated with the node
    in the visualization. The key and value of this dictionary **must** be
    a string.
:param edge_attr_fn: An optional callable that will be passed the
    weight/data payload for each edge in the graph and expected to return a
    dictionary of Graphviz edge attributes to be associated with the edge
    in the visualization file. The key and value of this dictionary
    must be a string.
:param dict graph_attr: An optional dictionary that specifies any Graphviz
    graph attributes for the visualization. The key and value of this
    dictionary must be a string.
:param str filename: An optional path to write the visualization to. If
    specified the return type from this function will be ``None`` as the
    output image is saved to disk.
:param str image_type: The image file format to use for the generated
    visualization. The support image formats are:
    ``'canon'``, ``'cmap'``, ``'cmapx'``, ``'cmapx_np'``, ``'dia'``,
    ``'dot'``, ``'fig'``, ``'gd'``, ``'gd2'``, ``'gif'``, ``'hpgl'``,
    ``'imap'``, ``'imap_np'``, ``'ismap'``, ``'jpe'``, ``'jpeg'``,
    ``'jpg'``, ``'mif'``, ``'mp'``, ``'pcl'``, ``'pdf'``, ``'pic'``,
    ``'plain'``, ``'plain-ext'``, ``'png'``, ``'ps'``, ``'ps2'``,
    ``'svg'``, ``'svgz'``, ``'vml'``, ``'vmlz'``, ``'vrml'``, ``'vtx'``,
    ``'wbmp'``, ``'xdot'``, ``'xlib'``. It's worth noting that while these
    formats can all be used for generating image files when the ``filename``
    kwarg is specified, the Pillow library used for the returned object can
    not work with all these formats.
:param str method: The layout method/Graphviz command method to use for
    generating the visualization. Available options are ``'dot'``,
    ``'twopi'``, ``'neato'``, ``'circo'``, ``'fdp'``, and ``'sfdp'``.
    You can refer to the
    `Graphviz documentation <https://graphviz.org/documentation/>`__ for
    more details on the different layout methods. By default ``'dot'`` is
    used.

:returns: A ``PIL.Image`` object of the generated visualization, if
    ``filename`` is not specified. If ``filename`` is specified then
    ``None`` will be returned as the visualization was written to the
    path specified in ``filename``
:rtype: PIL.Image

.. jupyter-execute::

    import rustworkx as rx
    from rustworkx.visualization import graphviz_draw

    def node_attr(node):
      if node == 0:
        return {'color': 'yellow', 'fillcolor': 'yellow', 'style': 'filled'}
      if node % 2:
        return {'color': 'blue', 'fillcolor': 'blue', 'style': 'filled'}
      else:
        return {'color': 'red', 'fillcolor': 'red', 'style': 'filled'}

    graph = rx.generators.directed_star_graph(weights=list(range(32)))
    graphviz_draw(graph, node_attr_fn=node_attr, method='sfdp')

z^Pillow is necessary to use graphviz_draw() it can be installed with 'pip install pydot pillow'r   z-VT)cwdcheckcapture_outputzGraphviz could not be found or run. This function requires that Graphviz is installed. If you need to install Graphviz you can refer to: https://graphviz.org/download/#executable-packages for instructions.Nr!   z2The specified value for the image_type argument, 'z,' is not a valid choice. It must be one of: z.The specified value for the method argument, 'z-Tzutf-8F)inputr:   encodingr9   textz-outf8)r;   r9   r<   r=   )
HAS_PILLOWImportError
subprocessruntempfile
gettempdir	ExceptionRuntimeErrorr   strto_dotIMAGE_TYPES
ValueErrorMETHODSencodeioBytesIOstdoutr
   open)graphnode_attr_fnedge_attr_fn
graph_attrfilename
image_typemethoddot_stroutput_formatprog
dot_resultdot_bytes_imageimages                Z/home/james-whalen/.local/lib/python3.13/site-packages/rustworkx/visualization/graphviz.pyr   r   L   s   d :B
 	

DM##%		
 3\LMG[(<K-! 
 #~ @ I::AD  ^^4'..)

 **Z%6%67

?+4h7	
 e  

 	

s   ,D: :E)NNNNNN)rQ   z%'PyDiGraph[_S, _T] | PyGraph[_S, _T]'rR   z%Callable[[_S], dict[str, str]] | NonerS   z%Callable[[_T], dict[str, str]] | NonerT   zdict[str, str] | NonerU   
str | NonerV   r_   rW   r_   returnzImage | None)
__future__r   rA   rC   rM   typingr   r   r   r   	rustworkxr   r	   PILr
   r?   r@   r   r   __all__rK   rI   r        r^   <module>rh      s    #   	 9 9 (J T]T] 

;%T ;?:>(,!P0P7P 8P &	P
 P P P Pk  Js   A5 5B ?B 