
    i&                     :    S r SSKrSSKrSSKJr   " S S\5      rg)a
  
altgraph.Dot - Interface to the dot language
============================================

The :py:mod:`~altgraph.Dot` module provides a simple interface to the
file format used in the
`graphviz <http://www.research.att.com/sw/tools/graphviz/>`_
program. The module is intended to offload the most tedious part of the process
(the **dot** file generation) while transparently exposing most of its
features.

To display the graphs or to generate image files the
`graphviz <http://www.research.att.com/sw/tools/graphviz/>`_
package needs to be installed on the system, moreover the :command:`dot` and
:command:`dotty` programs must be accesible in the program path so that they
can be ran from processes spawned within the module.

Example usage
-------------

Here is a typical usage::

    from altgraph import Graph, Dot

    # create a graph
    edges = [ (1,2), (1,3), (3,4), (3,5), (4,5), (5,4) ]
    graph = Graph.Graph(edges)

    # create a dot representation of the graph
    dot = Dot.Dot(graph)

    # display the graph
    dot.display()

    # save the dot representation into the mydot.dot file
    dot.save_dot(file_name='mydot.dot')

    # save dot file as gif image into the graph.gif file
    dot.save_img(file_name='graph', file_type='gif')

Directed graph and non-directed graph
-------------------------------------

Dot class can use for both directed graph and non-directed graph
by passing ``graphtype`` parameter.

Example::

    # create directed graph(default)
    dot = Dot.Dot(graph, graphtype="digraph")

    # create non-directed graph
    dot = Dot.Dot(graph, graphtype="graph")

Customizing the output
----------------------

The graph drawing process may be customized by passing
valid :command:`dot` parameters for the nodes and edges. For a list of all
parameters see the `graphviz <http://www.research.att.com/sw/tools/graphviz/>`_
documentation.

Example::

    # customizing the way the overall graph is drawn
    dot.style(size='10,10', rankdir='RL', page='5, 5' , ranksep=0.75)

    # customizing node drawing
    dot.node_style(1, label='BASE_NODE',shape='box', color='blue' )
    dot.node_style(2, style='filled', fillcolor='red')

    # customizing edge drawing
    dot.edge_style(1, 2, style='dotted')
    dot.edge_style(3, 5, arrowhead='dot', label='binds', labelangle='90')
    dot.edge_style(4, 5, arrowsize=2, style='bold')


.. note::

   dotty (invoked via :py:func:`~altgraph.Dot.display`) may not be able to
   display all graphics styles. To verify the output save it to an image file
   and look at it that way.

Valid attributes
----------------

    - dot styles, passed via the :py:meth:`Dot.style` method::

        rankdir = 'LR'   (draws the graph horizontally, left to right)
        ranksep = number (rank separation in inches)

    - node attributes, passed via the :py:meth:`Dot.node_style` method::

        style = 'filled' | 'invisible' | 'diagonals' | 'rounded'
        shape = 'box' | 'ellipse' | 'circle' | 'point' | 'triangle'

    - edge attributes, passed via the :py:meth:`Dot.edge_style` method::

        style     = 'dashed' | 'dotted' | 'solid' | 'invis' | 'bold'
        arrowhead = 'box' | 'crow' | 'diamond' | 'dot' | 'inv' | 'none'
            | 'tee' | 'vee'
        weight    = number (the larger the number the closer the nodes will be)

    - valid `graphviz colors
        <http://www.research.att.com/~erg/graphviz/info/colors.html>`_

    - for more details on how to control the graph drawing process see the
      `graphviz reference
        <http://www.research.att.com/sw/tools/graphviz/refs.html>`_.
    N)
GraphErrorc                   x    \ rS rSrSr          SS jrS rSS jrS rS r	S	 r
S
 rS rSS jrSS jrSrg)Dotu   a  
A  class providing a **graphviz** (dot language) representation
allowing a fine grained control over how the graph is being
displayed.

If the :command:`dot` and :command:`dotty` programs are not in the current
system path their location needs to be specified in the contructor.
Nc                   ^ U0 sU l         U l        U
S;   d   eXl        SU l        SU l        XxU	sU l        U l        U l        0 0 sU l        U l	        Ub  Uc  UnUb	  Uc  U4S jnUc  Sn[        5       mU HI  nUc  0 nOU" U5      nUc  M  0 U R                  U'   U R                  " U40 UD6  TR                  U5        MK     Uby  T Hr  nU4S jU" U5       5        HY  nUc  0 nOU" X5      nUc  M  XR                  ;  a  0 U R                  U'   0 U R                  U   U'   U R                  " X40 UD6  M[     Mt     gg)z
Initialization.
)graphdigraphztmp_dot.dotztmp_neo.dotNc                 $    UR                  U 5      $ N)out_nbrs)noder   s     9C:\des-py\RoboSAPF\venv\Lib\site-packages\altgraph/Dot.pyedgefnDot.__init__.<locals>.edgefn   s    ~~d++     c              3   6   >#    U  H  oT;   d  M
  Uv   M     g 7fr   r   ).0nseens     r   	<genexpr>Dot.__init__.<locals>.<genexpr>   s     B1T	QQs   		)nameattrtypetemp_dottemp_neodotdottyneatonodesedgesset
node_styleadd
edge_style)selfr   r!   r   nodevisitoredgevisitorr   r   r   r    	graphtyper   styleheadtail	edgestyler   s                   @r   __init__Dot.__init__   sb      $R	490000	%%+.u($*dj "$R
DJE#( , =EuD"#D) #%

4 ..  BtBD"*$&	$/$;	 ,zz1/1DJJt,13

4(.@i@ C  r   c                     Xl         g)z
Changes the overall style
N)r   )r'   r   s     r   r+   	Dot.style   s	     	r   c                 f   US:X  a]  U R                  U R                  5        U R                  < SU R                  < SU R                  < 3n[        R
                  " U5        OU R                  U R                  5        U R                  < SU R                  < 3n[        R
                  " U5        g)z&
Displays the current graph via dotty
r     -o  N)save_dotr   r    r   ossystemr   )r'   mode	neato_cmdplot_cmds       r   displayDot.display   sm    
 7?MM$--()-T]]DMMRIIIi MM$--("jj$--8
		(r   c                 \    XR                   ;  a  0 U R                   U'   X R                  U'   g)z2
Modifies a node style to the dot representation.
N)r"   r!   )r'   r   kwargss      r   r$   Dot.node_style   s(     zz!!DJJt!

4r   c                 P    U R                    H  nU R                  " U40 UD6  M     g)z
Modifies all node styles
N)r!   r$   )r'   r?   r   s      r   all_node_styleDot.all_node_style   s#     JJDOOD+F+ r   c                     X R                   ;  a  [        SU< 35      e X R                  U   ;  a  0 U R                  U   U'   X0R                  U   U'   g! [         a    [        SU< SU< S35      ef = f)z3
Modifies an edge style to the dot representation.
zinvalid node zinvalid edge  z -> r5   N)r!   r   r"   KeyError)r'   r,   r-   r?   s       r   r&   Dot.edge_style   sv     zz!$899	G::d++)+

4 &%+JJtT" 	G$EFF	Gs   5A A5c              #   d  #    U R                   S:X  a  SU R                  < S3v   O=U R                   S:X  a  SU R                  < S3v   O[        SU R                   < 35      e[        U R                  R                  5       5       H  u  pU< SU< S3v   M     S	v   S
nSn[        U R                  R                  5       5       H<  u  pVSU< S3v   [        UR                  5       5       H  u  pX1U4-  v   M     Uv   M>     [        U R                  5       H  n[        U R                  U   5       Hl  nU R                   S:X  a  SU< SU< S3v   OSU< SU< S3v   [        U R                  U   U   R                  5       5       H  u  pX1U4-  v   M     Uv   Mn     M     Sv   g 7f)Nr	   zdigraph z {
r   zgraph zunsupported graphtype z="z";
z%s="%s",z];
z	"z" [z" -> "z" -- "z}
)r   r   r   sortedr   itemsr!   r"   )	r'   	attr_name
attr_valuecpattepatt	node_name	node_attrr,   r-   s	            r   iterdotDot.iterdot   sy    99	!&*ii11YY'!$(II// 499FGG &,DIIOO,=%>!I ):66 &?
  %+4::+;+;+=$> Iy )++)/	0A)B%	*555 *CK	 %? 4::&Dtzz$/099	)04d;; * 15d;;-3DJJt4DT4J4P4P4R-S)Ij"999 .T 1 ' s   F.F0c                 "    U R                  5       $ r   )rQ   )r'   s    r   __iter__Dot.__iter__  s    ||~r   c                     U(       d&  [         R                  " [        SSS9  U R                  n[	        US5       nU R                  5        H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)z4
Saves the current graph representation into a file
always pass a file_name   
stacklevelwN)warningswarnDeprecationWarningr   openrQ   write)r'   	file_namefpchunks       r   r6   Dot.save_dot  sV    
 MM,.GTUVI)S!R ( "!!s   )A,,
A:c                    U(       d  [         R                  " [        SSS9  SnUS:X  ai  U R                  U R                  5        U R
                  < SU R                  < SU R                  < 3n[        R                  " U5        U R                  nO'U R                  U R                  5        U R                  nU< SU< 3nU< S	U< SU R                  < SU< 3n[        R                  " U5        g
)z%
Saves the dot file as an image file
rW   rX   rY   outr    r4   r5   .z -TN)
r\   r]   r^   r6   r   r    r   r7   r8   r   )r'   ra   	file_typer9   r:   r;   
create_cmds          r   save_imgDot.save_img(  s    
 MM,.GTUVI7?MM$--()-T]]DMMRIIIi xxHMM$--(xxH()4	MM	

 			*r   )
r   r   r   r"   r   r    r!   r   r   r   )
NNNNNGr   r   r    r	   )r   r   )Ngifr   )__name__
__module____qualname____firstlineno____doc__r/   r+   r<   r$   rB   r&   rQ   rT   r6   rj   __static_attributes__r   r   r   r   r   u   s]     =A~",G&P r   r   )rr   r7   r\   altgraphr   objectr   r   r   r   <module>rv      s%   m\ 
  L& Lr   