U
    ÑtœdÂ1  ã                   @   sŠ   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ dZeƒ \ZZG dd„ deƒZdS )añ  
Drawing routines to draw graphs.

This module contains routines to draw graphs on:

  - Cairo surfaces (L{DefaultGraphDrawer})
  - Matplotlib axes (L{MatplotlibGraphDrawer})

It also contains routines to send an igraph graph directly to
(U{Cytoscape<http://www.cytoscape.org>}) using the
(U{CytoscapeRPC plugin<http://gforge.nbic.nl/projects/cytoscaperpc/>}), see
L{CytoscapeGraphDrawer}. L{CytoscapeGraphDrawer} can also fetch the current
network from Cytoscape and convert it to igraph format.
é    )Úwarn)Úconvex_hullÚ	VertexSeq)ÚAbstractGraphDrawer)ÚPointé   )ÚMatplotlibEdgeDrawer)ÚMatplotlibPolygonDrawer)Úfind_matplotlib)ÚMatplotlibVertexDrawer)ÚMatplotlibGraphDrawerc                   @   s6   e Zd ZdZddddddœZeefdd	„Zd
d„ ZdS )r   z/Graph drawer that uses a pyplot.Axes as contextÚsÚoÚnoneú^Úv)Z	rectangleÚcircleZhiddenztriangle-upztriangle-downc                 C   s   || _ || _|| _dS )aV  Constructs the graph drawer and associates it with the mpl Axes

        @param ax: the matplotlib Axes to draw into.
        @param vertex_drawer_factory: a factory method that returns an
            L{AbstractVertexDrawer} instance bound to the given Matplotlib axes.
            The factory method must take three parameters: the axes and the
            palette to be used for drawing colored vertices, and the layout of
            the graph. The default vertex drawer is L{MatplotlibVertexDrawer}.
        @param edge_drawer_factory: a factory method that returns an
            L{AbstractEdgeDrawer} instance bound to a given Matplotlib Axes.
            The factory method must take two parameters: the Axes and the palette
            to be used for drawing colored edges. The default edge drawer is
            L{MatplotlibEdgeDrawer}.
        N)ÚaxÚvertex_drawer_factoryÚedge_drawer_factory)Úselfr   r   r   © r   úX/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/drawing/matplotlib/graph.pyÚ__init__-   s    zMatplotlibGraphDrawer.__init__c           1   
      sJ  ddl m}m} |rtdtƒ ˆ ¡ }| j}| dd ¡}|  | 	dd ¡ˆ¡‰| 	dd ¡}	|	s„|	d krÂd|krÂdˆ 
¡ krÂˆ ¡ d	k rÂdd
lm}	 | 	dd¡}
|
dkr¨d}
t|
ƒ}
|	ˆd |
d�|d< |  ||ˆ¡}|  ||¡}| ˆj|¡‰| ˆj|¡‰d|k�rz|d }ddl m}m} t|tƒ�r4t| ¡ ƒ}nFt|||fƒ�rXdd„ t|ƒD ƒ}n"t|dƒ�rnt|ƒ}nti  ¡ ƒ}| 	dd¡�r’g g dœ}|D �]¾\‰}ˆ�r–|d k�r´�q–| 	|¡}tˆtƒ�rØdd„ ˆD ƒ‰tˆdƒ�sìtdƒ‚‡fdd„t‡fdd„ˆD ƒƒD ƒ}dt‡fdd„|D ƒƒ ‰‡fdd„|D ƒ}t|ƒdk�r²t |d Ž t |d Ž  }}ˆ||  !¡  }t |d  |d ƒ}|| || || || || || g}n*t dd„ t"|Ž D ƒŽ ‰ ‡ ‡fd d„|D ƒ}|d |d |d d!|d"  f}t#|ƒ}|j$|ˆ||d#� | 	dd¡�r–|d$  %t&j'd%dd||d&�¡ |d'  %t(|ƒ¡ �q–| 	dd¡�rz| )|d$ |d' ¡ |  *ˆ|¡}|  +ˆ|¡}ˆj‰	|d k�r°t"ˆ	ˆˆƒ}n‡‡‡	fd(d„|D ƒ}|j$}|D ]\}}} |||| ƒ �qÐˆj‰	|d k�rt"ˆˆƒ}n‡‡fd)d„|D ƒ}|D ]D\}} |j,d k�r6�q| 	d*|j-¡}!|j.| |j,fž|!d+d+d,œŽ �qˆj‰|d k�r€t"ˆˆƒ}"n‡‡fd-d„|D ƒ}"|�r¢|j/}n|j0}|"D ]2\}#}$|#j1\}%}&ˆ|% ˆ|&  }'}(||$|'|(ƒ �q¬| 	d.d ¡‰ˆd k	�rà‡‡‡fd/d„t2ˆ ¡ ƒD ƒ})|)D ]Æ\}*}$}#|#j1\}%}&ˆ|% ˆ|&  }'}(| 3|$|'|(¡\\}+},\}-}.i }/|-j4|/d0< |.j4|/d1< |$j5d k	�ržt|$j5d2d&�|/d3< d+|/d0< d+|/d1< |$j6�r¼| 7|$|'|(¡}0|0|/d4< |j.|+|,|*f|$j-|$j8d5œ|/—Ž �q|j9d6  :d¡ |j9d7  :d¡ |j9d8  :d¡ |j9d9  :d¡ | ;g ¡ | <g ¡ | =d¡ | >¡  d S ):Nr   )ÚVertexClusteringÚVertexCoverzOPositional arguments to plot functions are ignored and will be deprecated soon.ÚpaletteÚlayoutÚ	autocurveZedge_curvedZcurvedi'  )r   Tg      à?)Ú	attributeÚdefaultÚmark_groupsc                 s   s   | ]\}}||fV  qd S ©Nr   )Ú.0ÚcolorÚgroupr   r   r   Ú	<genexpr>ˆ   s     z-MatplotlibGraphDrawer.draw.<locals>.<genexpr>Ú__iter__ÚlegendF)ÚhandlesÚlabelsc                 S   s   g | ]
}|j ‘qS r   )Úindex)r#   Úvertexr   r   r   Ú
<listcomp>ž   s     z.MatplotlibGraphDrawer.draw.<locals>.<listcomp>z&group membership list must be iterablec                    s   g | ]}ˆ | ‘qS r   r   ©r#   Úi)r%   r   r   r-   £   s     c                    s   g | ]}ˆ | ‘qS r   r   ©r#   Úidx©r   r   r   r-   £   s     g      ô?c                 3   s   | ]}ˆ | j V  qd S r"   )Úsizer0   )Úvertex_builderr   r   r&   ¦   s     c                    s   g | ]}ˆ | ‘qS r   r   r0   r2   r   r   r-   ©   s     é   r   c                 S   s    g | ]}t |ƒtt|ƒƒ ‘qS r   )ÚsumÚfloatÚlen)r#   Úcoordsr   r   r   r-   ´   s     c                    s   g | ]}t |Ž  ˆ ˆ ¡‘qS r   )r   Ztowards)r#   Úpoint)ÚcenterÚcorner_radiusr   r   r-   ¶   s   ÿg      Ð?é   )r<   Ú	facecolorÚ	edgecolorr)   )r   r   )r>   r?   r*   c                 3   s$   | ]}ˆ| ˆ| ˆ | fV  qd S r"   r   r.   )r   r4   Úvsr   r   r&   â   s    c                 3   s   | ]}ˆ| ˆ | fV  qd S r"   r   r.   )r   r4   r   r   r&   ò   s     Zvertex_label_sizer;   )ÚfontsizeÚhaÚvac                 3   s   | ]}ˆ| ˆ | fV  qd S r"   r   r.   )Úedge_builderÚesr   r   r&     s     Z
edge_labelc                 3   s&   | ]}ˆ| ˆ | ˆj | fV  qd S r"   )rE   r.   )rD   Úgraphr*   r   r   r&     s    rB   rC   r   ZbboxÚrotation)rA   r$   ÚrightÚtopÚleftÚbottom)?Zigraph.clusteringr   r   r   ÚDeprecationWarningZis_directedr   ÚpopZensure_layoutÚgetZedge_attributesZecountZigraphr   r7   r   r   ZVisualVertexBuilderr@   ZVisualEdgeBuilderrE   Ú
isinstanceÚdictÚiterÚitemsÚ	enumerateÚhasattrr   Ú	TypeErrorr   Úmaxr8   r   Ú
normalizedÚzipr	   ÚdrawÚappendÚpltZ	RectangleÚstrr(   Z_determine_vertex_orderZ_determine_edge_orderÚlabelÚ
label_sizeÚtextZdraw_directed_edgeZdraw_undirected_edgeÚtupleÚrangeZget_label_positionÚvalueÚ
backgroundZalign_labelZget_label_rotationZlabel_colorZspinesZset_visibleZ
set_xticksZ
set_yticksZ
set_aspectZautoscale_view)1r   rF   ÚargsÚkwdsr   r   Zdirectedr   r   r   r    Zvertex_drawerZedge_drawerr!   Z
group_iterZlegend_infoZcolor_idr$   ZhullÚpolygonÚaÚbÚcÚnr>   ZdrawerZvertex_orderZ
edge_orderZvertex_coord_iterZdrawer_methodr,   Zvisual_vertexr9   r^   Zedge_coord_iterÚedgeZvisual_edgeÚsrcÚdestZ
src_vertexZdest_vertexZedge_label_iterr]   ÚxÚyZhalignZvalignZtext_kwargsrG   r   )
r;   r<   rD   rE   rF   r%   r*   r   r4   r@   r   rY   E   sn   ýÿþ
ý
üý


þ
$*ÿþ üûÿ	þ
ÿ
þþû




ÿ
ý

þ
  ÿýûú



zMatplotlibGraphDrawer.drawN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z_shape_dictr   r   r   rY   r   r   r   r   r   "   s   ûü
r   N)rs   Úwarningsr   Zigraph._igraphr   r   Zigraph.drawing.baseclassesr   Zigraph.drawing.utilsr   rk   r   rf   r	   Úutilsr
   r,   r   Ú__all__Ú_r[   r   r   r   r   r   Ú<module>   s   
