o
    i 5                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ	 G dd dZ
G dd	 d	eZG d
d de
Zdd ZG dd de
ZeedZG dd de
ZeedZG dd de
ZG dd de
ZdS )z
Defines classes for path effects. The path effects are supported in `~.Text`,
`~.Line2D` and `~.Patch`.

.. seealso::
   :doc:`/tutorials/advanced/patheffects_guide`
    )RendererBase)colors)patches)
transformsc                   @   s4   e Zd ZdZdddZdd Zdd Zdd
dZd	S )AbstractPathEffectz
    A base class for path effects.

    Subclasses should override the ``draw_path`` method to add effect
    functionality.
            r   c                 C   s
   || _ dS )z
        Parameters
        ----------
        offset : pair of floats
            The offset to apply to the path, measured in points.
        N)_offset)selfoffset r   Q/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/matplotlib/patheffects.py__init__   s   
zAbstractPathEffect.__init__c                 C   s   t  jt|j| j S )z(Apply the offset to the given transform.)mtransformsAffine2D	translatemappoints_to_pixelsr	   )r
   rendererr   r   r   _offset_transform    s   z$AbstractPathEffect._offset_transformc                 C   sl   |  }|dd}|r|jdi | | D ]\}}t|d| d}t|s/td||| q|S )z
        Update the given GraphicsCollection with the given
        dictionary of properties. The keys in the dictionary are used to
        identify the appropriate set_ method on the gc.

        dashesNset_zUnknown property {0}r   )copypop
set_dashesitemsgetattrcallableAttributeErrorformat)r
   gcnew_gc_dictr   kv
set_methodr   r   r   
_update_gc%   s   
zAbstractPathEffect._update_gcNc                 C   s    t |tr|j}|||||S )z
        Derived should override this method. The arguments are the same
        as :meth:`matplotlib.backend_bases.RendererBase.draw_path`
        except the first argument is a renderer.

        )
isinstancePathEffectRenderer	_renderer	draw_pathr
   r   r    tpathaffinergbFacer   r   r   r)   9   s   
zAbstractPathEffect.draw_path)r   N)__name__
__module____qualname____doc__r   r   r%   r)   r   r   r   r   r      s    
	r   c                   @   sJ   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dS )r'   aw  
    Implements a Renderer which contains another renderer.

    This proxy then intercepts draw calls, calling the appropriate
    :class:`AbstractPathEffect` draw method.

    .. note::
        Not all methods have been overridden on this RendererBase subclass.
        It may be necessary to add further methods to extend the PathEffects
        capabilities further.
    c                 C   s   || _ || _dS )z
        Parameters
        ----------
        path_effects : iterable of :class:`AbstractPathEffect`
            The path effects which this renderer represents.
        renderer : `matplotlib.backend_bases.RendererBase` subclass

        N)_path_effectsr(   )r
   path_effectsr   r   r   r   r   S   s   	
zPathEffectRenderer.__init__c                 C   s   |  || jS r.   )	__class__r(   )r
   r4   r   r   r   copy_with_path_effect_   s   z(PathEffectRenderer.copy_with_path_effectNc                 C   s$   | j D ]}|| j|||| qd S r.   )r3   r)   r(   )r
   r    r+   r,   r-   path_effectr   r   r   r)   b   s
   
zPathEffectRenderer.draw_pathc           	      O   sh   t | jdkrtj| ||||g|R i |S | jD ]}| |g}|j||||g|R i | qd S N   )lenr3   r   draw_markersr6   )	r
   r    marker_pathmarker_transpathargskwargsr7   r   r   r   r   r;   g   s    

zPathEffectRenderer.draw_markersc                 O   sd   t | jdkrtj| |||g|R i |S | jD ]}| |g}|j|||g|R i | qd S r8   )r:   r3   r   draw_path_collectionr6   )r
   r    master_transformpathsr?   r@   r7   r   r   r   r   rA   z   s    
z'PathEffectRenderer.draw_path_collectionc                 C   s@   |  ||||||\}}	| }
|d | j|||	|
d d S )Nr   )r-   )_get_text_path_transformget_rgbset_linewidthr)   )r
   r    xyspropangleismathr>   	transformcolorr   r   r   _draw_text_as_path   s   
z%PathEffectRenderer._draw_text_as_pathc                 C   s    |dv r
t | j|S t| |S )N)flipyget_canvas_width_heightnew_gcr   
_text2pathheightwidth)r   r(   object__getattribute__)r
   namer   r   r   rW      s   z#PathEffectRenderer.__getattribute__r.   )r/   r0   r1   r2   r   r6   r)   r;   rA   rO   rW   r   r   r   r   r'   F   s    
r'   c                   @   s   e Zd ZdZdS )Normalz
    The "identity" PathEffect.

    The Normal PathEffect's sole purpose is to draw the original artist with
    no special path effect.
    N)r/   r0   r1   r2   r   r   r   r   rY      s    rY   c                 C   s\   G dd d| }d| j  |_ d| j  |_d| j  d| j  d| j  d|_| jj|j_|S )zO
    Create a PathEffect class combining *effect_class* and a normal draw.
    c                       s   e Zd Z fddZ  ZS )z)_subclass_with_normal.<locals>.withEffectc                    s(   t  ||||| ||||| d S r.   )superr)   r*   r5   r   r   r)      s   z3_subclass_with_normal.<locals>.withEffect.draw_path)r/   r0   r1   r)   __classcell__r   r   r[   r   
withEffect   s    r]   withz*
    A shortcut PathEffect for applying `.z` and then
    drawing the original Artist.

    With this class you can use ::

        artist.set_path_effects([path_effects.withzN()])

    as a shortcut for ::

        artist.set_path_effects([path_effects.zA(),
                                 path_effects.Normal()])
    )r/   r1   r2   r)   )effect_classr]   r   r   r   _subclass_with_normal   s   

r`   c                       *   e Zd ZdZd fdd	Zdd Z  ZS )Strokez0A line based PathEffect which re-draws a stroke.r   r   c                    s   t  | || _dS )z
        The path will be stroked with its gc updated with the given
        keyword arguments, i.e., the keyword arguments should be valid
        gc parameter values.
        N)rZ   r   _gcr
   r   r@   r[   r   r   r      s   
zStroke.__init__c                 C   sF   |  }|| | || j}||||| | | |  dS )zDraw the path with updated gc.N)rR   copy_propertiesr%   rd   r)   r   restore)r
   r   r    r+   r,   r-   gc0r   r   r   r)      s   
zStroke.draw_pathrc   r/   r0   r1   r2   r   r)   r\   r   r   r[   r   rb      s    	rb   )r_   c                       s0   e Zd ZdZ			d	 fdd	Zdd Z  ZS )
SimplePatchShadowz#A simple shadow via a filled patch.   N333333?c                    sJ   t  | |du r|| _nt|| _|du rd}|| _|| _|| _dS )a  
        Parameters
        ----------
        offset : pair of floats
            The offset of the shadow in points.
        shadow_rgbFace : color
            The shadow color.
        alpha : float, default: 0.3
            The alpha transparency of the created shadow patch.
            http://matplotlib.1069221.n5.nabble.com/path-effects-question-td27630.html
        rho : float, default: 0.3
            A scale factor to apply to the rgbFace color if `shadow_rgbFace`
            is not specified.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.

        Nro   )rZ   r   _shadow_rgbFacemcolorsto_rgba_alpha_rhord   )r
   r   shadow_rgbFacealpharhor@   r[   r   r   r      s   
zSimplePatchShadow.__init__c                 C   s   |  }|| | jdu r(|pddd \}}}	|| j || j |	| j f}
n| j}
|d || j |d | || j	}|
|||| | |
 |  dS )
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.
        N      ?rz   rz      noner   )rR   rf   rp   rt   set_foreground	set_alphars   rF   r%   rd   r)   r   rg   r
   r   r    r+   r,   r-   rh   rgbru   r   r   r   r)     s   



zSimplePatchShadow.draw_path)rl   NNro   rj   r   r   r[   r   rk      s    %rk   c                       s.   e Zd ZdZ		d	 fdd	Zdd Z  ZS )
SimpleLineShadowzA simple shadow via a line.rl   r"   ro   c                    s>   t  | |du r|| _nt|| _|| _|| _|| _dS )a  
        Parameters
        ----------
        offset : pair of floats
            The offset to apply to the path, in points.
        shadow_color : color, default: 'black'
            The shadow color.
            A value of ``None`` takes the original artist's color
            with a scale factor of *rho*.
        alpha : float, default: 0.3
            The alpha transparency of the created shadow patch.
        rho : float, default: 0.3
            A scale factor to apply to the rgbFace color if `shadow_rgbFace`
            is ``None``.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.
        N)rZ   r   _shadow_colorrq   rr   rs   rt   rd   )r
   r   shadow_colorrv   rw   r@   r[   r   r   r   %  s   
zSimpleLineShadow.__init__c                 C   s   |  }|| | jdu r*| pddd \}}}	|| j || j |	| j f}
n| j}
||
 || j | || j	}|
|||| |  |  dS )rx   Nry   r{   )rR   rf   r   get_foregroundrt   r}   r~   rs   r%   rd   r)   r   rg   r   r   r   r   r)   C  s   


zSimpleLineShadow.draw_path)rl   r"   ro   ro   rj   r   r   r[   r   r   "  s    r   c                       ra   )PathPatchEffectza
    Draws a `.PathPatch` instance whose Path comes from the original
    PathEffect artist.
    rc   c                    s&   t  j|d tjg fi || _dS )a  
        Parameters
        ----------
        offset : pair of floats
            The offset to apply to the path, in points.
        **kwargs
            All keyword arguments are passed through to the
            :class:`~matplotlib.patches.PathPatch` constructor. The
            properties which cannot be overridden are "path", "clip_box"
            "transform" and "clip_path".
        )r   N)rZ   r   mpatches	PathPatchpatchre   r[   r   r   r   a  s   zPathPatchEffect.__init__c                 C   sV   || j _| j || |  | j |  | }|r#| j j|  | j | d S r.   )	r   _pathset_transformr   set_clip_boxget_clip_rectangleget_clip_pathset_clip_pathdraw)r
   r   r    r+   r,   r-   	clip_pathr   r   r   r)   p  s   zPathPatchEffect.draw_pathri   rj   r   r   r[   r   r   [  s    r   N)r2   matplotlib.backend_basesr   
matplotlibr   rq   r   r   r   r   r   r'   rY   r`   rb   
withStrokerk   withSimplePatchShadowr   r   r   r   r   r   <module>   s    7W	

B9