U
    Ñtœdz$  ã                   @   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mZmZmZ ddlmZmZmZmZ dZeƒ ZG dd	„ d	eƒZd
S )z:Drawers for various edge styles in Matplotlib graph plots.é    )Úatan2ÚcosÚpiÚsin)ÚAbstractEdgeDrawer©ÚAttributeCollectorBase)Úfind_plotlyÚformat_path_stepÚ
format_arcÚformat_rgba)ÚPointÚeuclidean_distanceÚ)get_bezier_control_points_for_curved_edgeÚ!intersect_bezier_curve_and_circle)ÚPlotlyEdgeDrawerc                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r   z0Matplotlib-specific abstract edge drawer object.c                 C   s   || _ || _|  ¡ | _dS )zýConstructs the edge drawer.

        @param context: a plotly Figure object 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   úS/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/drawing/plotly/edge.pyÚ__init__   s    zPlotlyEdgeDrawer.__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                       sF   e Zd ZdZdZdZdZdZd” jfZ	dZ
d” jjfZd	Zd
ZdZdS )zJPlotlyEdgeDrawer._construct_visual_edge_builder.<locals>.VisualEdgeBuilderzOBuilder that collects some visual properties of an edge for
            drawingZedge_gyé&1¬|?gffffffö?z#444g        NÚblackg      (@z
sans-serifç       @)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z_kwds_prefixÚ
arrow_sizeÚarrow_widthÚcolorZ_curvature_to_floatÚcurvedÚlabelr   ÚgetZlabel_colorZ
label_sizeZfontÚwidthr   ©r   r   r   r   ,   s   
r   r   )r   r   r   r'   r   r   (   s    z/PlotlyEdgeDrawer._construct_visual_edge_builderc                 C   sz  ||kr|   ||¡S | j}|j|j \}}\}}|j|j \}	}
\}}td||gƒg}|j�r t|||||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   }}t|	|
|||jƒ\}}||d  | ||d  |  }|tdd||ƒd  }|d ||  |d ||  f}| td||||ggƒ¡ nÖ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  }}| td	t||ƒƒ¡ d
 |¡}td|t|jƒ|jd�}| |¡ tjj||d d |d d |g||d d |d d |gt|jƒdd�}| |¡ d S )NÚMr   g      .@g      $@r   é   é   ÚCÚLú Úpath©Útyper.   Z
line_colorÚ
line_widthÚlines)ÚxÚyZ	fillcolorÚmode)Údraw_loop_edger   Úpositionr
   r#   r   r   Úsizer   r    r!   r   r   r   r   Úappendr   ÚjoinÚdictr   r"   r&   Ú	add_shapeÚplotlyZgraph_objectsZScatterZ	add_trace)r   ÚedgeÚ
src_vertexÚdest_vertexÚfigÚx1Úy1Úx2Úy2Zx_srcZy_srcZx_destZy_destr.   Úaux1Úaux2Zxc1Zyc1Zxc2Zyc2Zangler    r!   Z
aux_pointsZx_arrow_midZy_arrow_midZx_arrow_base_vecZy_arrow_base_vecZoffset_lengthÚstrokeZ	arrowheadr   r   r   Údraw_directed_edge=   s¬    ÿ        ÿ

þþûþþ
þÿþ

þþûþþÿ
ü
üz#PlotlyEdgeDrawer.draw_directed_edgec              	   C   sˆ   | j }|jd }|jd ttd ƒ| d  }|jd ttd ƒ| d  }tdt||f|d |d ddd�|j|j	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   r)   r.   g     €v@)Ztheta1Ztheta2r/   N)r   r8   r7   r   r   r   r;   r   r"   r&   r<   )r   r>   ZvertexrA   ZradiusZcenter_xZcenter_yrH   r   r   r   r6   ¿   s"    

ûözPlotlyEdgeDrawer.draw_loop_edgec                 C   s¶   ||kr|   ||¡S | j}td|jƒg}|jrt|j|j \}}\}}	t||||	|jƒ\}
}| td|
||jgƒ¡ n| td|jƒ¡ d |¡}td|t	|j
ƒ|jd�}| |¡ 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+   r,   r-   r.   r/   N)r6   r   r
   r7   r#   r   r9   r:   r;   r   r"   r&   r<   )r   r>   r?   r@   rA   r.   rB   rC   rD   rE   rF   rG   rH   r   r   r   Údraw_undirected_edgeÛ   s6    
þÿþÿ
üz%PlotlyEdgeDrawer.draw_undirected_edgeN)	r   r   r   r   r   r   rI   r6   rK   r   r   r   r   r      s    r   N)r   Úmathr   r   r   r   Zigraph.drawing.baseclassesr   Zigraph.drawing.metamagicr   Zigraph.drawing.plotly.utilsr	   r
   r   r   Zigraph.drawing.utilsr   r   r   r   Ú__all__r=   r   r   r   r   r   Ú<module>   s   