U
    td1                     @   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rd|krd
 kr d	k rdd
lm}	 |	dd}
|
dkrd}
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rg g d}|D ]\}r|d krq|	|}ttrdd D tdstdfddtfddD D }dtfdd|D  fdd|D }t|dkrt |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rt"	}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rt"}"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	rt|$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   
