U
    tdE1                     @   s   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZ ddlmZ d	Ze ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )z1
Drawers for various edge styles in graph plots.
    )atan2cospisin)AbstractEdgeDrawer)clampAttributeCollectorBase)euclidean_distance)get_bezier_control_points_for_curved_edge!intersect_bezier_curve_and_circle   )
find_cairo)AbstractCairoEdgeDrawerAlphaVaryingEdgeDrawerCairoArrowEdgeDrawerDarkToLightEdgeDrawerLightToDarkEdgeDrawerTaperedEdgeDrawerc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r   z+Cairo-specific abstract edge drawer object.c                 C   s   || _ || _|  | _dS )zConstructs the edge drawer.

        @param context: a Cairo context on which the edges will be drawn.
        @param palette: the palette that can be used to map integer color
            indices to colors when drawing edges
        N)contextpalette_construct_visual_edge_builderVisualEdgeBuilderselfr   r    r   R/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/drawing/cairo/edge.py__init__!   s    z AbstractCairoEdgeDrawer.__init__c                    s   G  fdddt }|S )ztConstruct the visual edge builder that will collect the visual
        attributes of an edge when it is being drawn.c                       sN   e Zd ZdZdZdZdZd jjfZ	d j
fZdZd jjfZdZd	ZdZdS )
zQAbstractCairoEdgeDrawer._construct_visual_edge_builder.<locals>.VisualEdgeBuilderzOBuilder that collects some visual properties of an edge for
            drawingZedge_      ?z#444        Nblackg      (@z
sans-serif)__name__
__module____qualname____doc__Z_kwds_prefix
arrow_sizearrow_widthr   getcolorZ_curvature_to_floatcurvedlabelZlabel_colorZ
label_sizeZfontwidthr   r   r   r   r   0   s   
r   r   )r   r   r   r,   r   r   ,   s    z6AbstractCairoEdgeDrawer._construct_visual_edge_builderc                 C   s   | j }|j|j  ||j |jd }|jd ttd | d  }|jd t	td | d  }|
|||d dtd  |  dS )aS  Draws a loop edge.

        The default implementation draws a small circle.

        @param edge: the edge to be drawn. Visual properties of the edge
          are defined by the attributes of this object.
        @param vertex: the vertex to which the edge is attached. Visual
          properties are given again as attributes.
        g      ?r             @r      N)r   set_source_rgbar(   set_line_widthr+   sizepositionr   r   r   arcstroke)r   edgeZvertexctxZradiusZcenter_xZcenter_yr   r   r   draw_loop_edgeA   s    

z&AbstractCairoEdgeDrawer.draw_loop_edgec                 C   s   ||kr|  ||S | j}|j|j  ||j |j|j  |jr|j|j \}}\}}t	|||||j\}	}
|j
|	d |	d |
d |
d f|j  n|j|j  |  dS )a  Draws an undirected edge.

        The default implementation of this method draws undirected edges
        as straight lines. Loop edges are drawn as small circles.

        @param edge: the edge to be drawn. Visual properties of the edge
          are defined by the attributes of this object.
        @param src_vertex: the source vertex. Visual properties are given
          again as attributes.
        @param dest_vertex: the target vertex. Visual properties are given
          again as attributes.
        r   r   N)r8   r   r0   r(   r1   r+   move_tor3   r)   r   curve_toline_tor5   )r   r6   
src_vertexdest_vertexr7   x1y1x2y2aux1aux2r   r   r   draw_undirected_edgeT   s$        *z,AbstractCairoEdgeDrawer.draw_undirected_edgeN)r!   r"   r#   r$   r   r   r8   rD   r   r   r   r   r      s
   r   c                   @   s   e Zd ZdZdd ZdS )r   zoEdge drawer implementation that draws undirected edges as
    straight lines and directed edges as arrows.
    c                 C   s  ||kr|  ||S | j}|j|j \}}\}}|j|j \}	}
\}}|j|j  ||j ||| |jrt	|||||j\}}|\}}|\}}t
|	|
|||||||jd 	\}}t|| || }d|j }d|j }||t|t|    ||t|t|    f||t|t|    ||t|t|    fg}|d d |d d  d |d d |d d  d  }}|d d |d d  |d d |d d   }}d|	 | d |jd ||
   d|
 | d |jd ||	   f}|	d|  d |jd ||
   |
d|  d |jd ||	   f}||d  | ||d  |  }|tdd||d  }|d ||  |d ||  f}||d |d |d |d || n|j|||||j\}}t|| || }d|j }d|j }||t|t|    ||t|t|    f||t|t|    ||t|t|    fg}|d d |d d  d |d d |d d  d  }}||| |  ||| |j|d   |j|d   ||| |  d S )	Nr.   g      .@g      $@r   r   r/   g      @g      ?)r8   r   r3   r0   r(   r1   r+   r9   r)   r   r   r2   r   r%   r&   r   r   r   r
   r:   shapeintersection_pointr;   r5   fill)r   r6   r<   r=   r7   r>   r?   r@   rA   Zx_srcZy_srcZx_destZy_destrB   rC   Zxc1Zyc1Zxc2Zyc2angler%   r&   
aux_pointsZx_arrow_midZy_arrow_midZx_arrow_base_vecZy_arrow_base_vecZoffset_lengthr   r   r   draw_directed_edgez   s            



&    

z'CairoArrowEdgeDrawer.draw_directed_edgeNr!   r"   r#   r$   rJ   r   r   r   r   r   u   s   r   c                   @   s   e Zd ZdZdd ZdS )r   zEdge drawer implementation that draws undirected edges as
    straight lines and directed edges as tapered lines that are
    wider at the source and narrow at the destination.
    c           
      C   s>  ||kr|  ||S |j|j }}|j|d |d |d |d |j}| j}|j|j  ||j	 t
|d |d  |d |d  }|jd }|d |t|td    |d |t|td    f|d |t|td    |d |t|td    fg}	|j|  |j|	d   |j|	d   |j|  |  d S )Nr   r   g      @r/   )r8   r3   rE   rF   r2   r   r0   r(   r1   r+   r   r   r   r   r9   r;   rG   )
r   r6   r<   r=   src_posdest_posr7   rH   r%   rI   r   r   r   rJ      s6        "



z$TaperedEdgeDrawer.draw_directed_edgeNrK   r   r   r   r   r      s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r   zEdge drawer implementation that draws undirected edges as
    straight lines and directed edges by varying the alpha value
    of the specified edge color between the source and the destination.
    c                    s:   t  || tt|ddf| _tt|ddf| _d S Nr   r   )superr   r   floatalpha_at_srcalpha_at_dest)r   r   r   rQ   rR   	__class__r   r   r   $  s    zAlphaVaryingEdgeDrawer.__init__c           
      C   s   ||kr|  ||S |j|j }}| j}t|d |d |d |d }|jd d | j }|d d | j }	|jd|  |jd|	  |	| |
|j |j|  |j|  |  d S )Nr   r      )r   )r   )r8   r3   r   cairoZLinearGradientr(   rQ   rR   Zadd_color_stop_rgbaZ
set_sourcer1   r+   r9   r;   r5   )
r   r6   r<   r=   rL   rM   r7   ZlgZ
edge_colorZedge_color_endr   r   r   rJ   )  s     


z)AlphaVaryingEdgeDrawer.draw_directed_edge)r!   r"   r#   r$   r   rJ   __classcell__r   r   rS   r   r     s   r   c                       s    e Zd ZdZ fddZ  ZS )r   a  Edge drawer implementation that draws undirected edges as
    straight lines and directed edges by using an alpha value of
    zero (total transparency) at the source and an alpha value of
    one (full opacity) at the destination. The alpha value is
    interpolated in-between.
    c                    s   t  ||dd d S rN   rO   r   r   rS   r   r   r   G  s    zLightToDarkEdgeDrawer.__init__r!   r"   r#   r$   r   rW   r   r   rS   r   r   ?  s   r   c                       s    e Zd ZdZ fddZ  ZS )r   a  Edge drawer implementation that draws undirected edges as
    straight lines and directed edges by using an alpha value of
    one (full opacity) at the source and an alpha value of zero
    (total transparency) at the destination. The alpha value is
    interpolated in-between.
    c                    s   t  ||dd d S )Nr   r   rX   r   rS   r   r   r   S  s    zDarkToLightEdgeDrawer.__init__rY   r   r   rS   r   r   K  s   r   N)r$   mathr   r   r   r   Zigraph.drawing.baseclassesr   Zigraph.drawing.colorsr   Zigraph.drawing.metamagicr	   Zigraph.drawing.utilsr
   r   r   utilsr   __all__rV   r   r   r   r   r   r   r   r   r   r   <module>   s   	W )!