U
    tdz$                     @   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 )zConstructs 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 nt|| || }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   