3
$ßL]ì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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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
:class:`~matplotlib.text.Text`, :class:`~matplotlib.lines.Line2D`
and :class:`~matplotlib.patches.Patch`.
é    )Ú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.

    ç        c             C   s   || _ tjƒ | _dS )z�
        Parameters
        ----------
        offset : pair of floats
            The offset to apply to the path, measured in points.
        N)Ú_offsetÚmtransformsZAffine2DÚ_offset_trans)ÚselfÚoffset© r   ú>/tmp/pip-install-edjban26/matplotlib/matplotlib/patheffects.pyÚ__init__   s    zAbstractPathEffect.__init__c             C   s6   |j | jd ƒ}|j | jd ƒ}|| jjƒ j||ƒ S )z(Apply the offset to the given transform.r   é   )Úpoints_to_pixelsr   r
   ÚclearÚ	translate)r   ÚrendererÚ	transformZoffset_xZoffset_yr   r   r   Ú_offset_transform   s    z$AbstractPathEffect._offset_transformc             C   sl   |j ƒ }|jddƒ}|r$|jf |Ž xB|jƒ D ]6\}}t|d| dƒ}t|ƒs\tdj|ƒƒ‚||ƒ q.W |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})ÚcopyÚpopZ
set_dashesÚitemsÚgetattrÚcallableÚAttributeErrorÚformat)r   ÚgcZnew_gc_dictr   ÚkÚvZ
set_methodr   r   r   Ú
_update_gc&   s    zAbstractPathEffect._update_gcNc             C   s    t |tƒr|j}|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'   :   s    
zAbstractPathEffect.draw_path©r   r   )r+   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r'   r   r   r   r   r      s
   

r   c               @   sZ   e Zd ZdZd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d„ ZdS )r%   ax  
    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 : :class:`matplotlib.backend_bases.RendererBase` instance

        N)Ú_path_effectsr&   )r   Úpath_effectsr   r   r   r   r   T   s    	zPathEffectRenderer.__init__c             C   s
   | j jƒ S )N)r&   Únew_gc)r   r   r   r   r2   `   s    zPathEffectRenderer.new_gcc             C   s   | j || jƒS )N)Ú	__class__r&   )r   r1   r   r   r   Úcopy_with_path_effectd   s    z(PathEffectRenderer.copy_with_path_effectNc             C   s(   x"| j D ]}|j| j||||ƒ qW d S )N)r0   r'   r&   )r   r    r(   r)   r*   Úpath_effectr   r   r   r'   g   s    zPathEffectRenderer.draw_pathc       	      O   s`   t | jƒdkr(tj| ||||f|ž|ŽS x2| jD ](}| j|gƒ}|j||||f|ž|Ž q0W d S )Nr   )Úlenr0   r   Údraw_markersr4   )	r   r    Zmarker_pathZmarker_transÚpathÚargsÚkwargsr5   r   r   r   r   r7   l   s    

zPathEffectRenderer.draw_markersc             O   s\   t | jƒdkr&tj| |||f|ž|ŽS x0| jD ]&}| j|gƒ}|j|||f|ž|Ž q.W d S )Nr   )r6   r0   r   Údraw_path_collectionr4   )r   r    Zmaster_transformÚpathsr9   r:   r5   r   r   r   r   r;      s    
z'PathEffectRenderer.draw_path_collectionc             C   s   | j j|ƒS )N)r&   r   )r   Zpointsr   r   r   r   ’   s    z#PathEffectRenderer.points_to_pixelsc             C   s@   | j ||||||ƒ\}}	|jƒ }
|jdƒ | j|||	|
d� d S )Ng        )r*   )Z_get_text_path_transformZget_rgbÚset_linewidthr'   )r   r    ÚxÚyÚsÚpropZangleZismathr8   r   Úcolorr   r   r   Ú_draw_text_as_path–   s
    
z%PathEffectRenderer._draw_text_as_pathc             C   s$   |dkrt | j|ƒS tj| |ƒS d S )NÚ
_text2pathÚflipyÚheightÚwidth)rD   rE   rF   rG   )r   r&   ÚobjectÚ__getattribute__)r   Únamer   r   r   rI   ž   s    z#PathEffectRenderer.__getattribute__)N)r,   r-   r.   r/   r   r2   r4   r'   r7   r;   r   rC   rI   r   r   r   r   r%   G   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,   r-   r.   r/   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 )	ÚStrokez0A line based PathEffect which re-draws a stroke.r   c                s   t ƒ j|ƒ || _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)Úsuperr   Ú_gc)r   r   r:   )r3   r   r   r   ±   s    zStroke.__init__c             C   sH   |j ƒ }|j|ƒ | j|| jƒ}| j||ƒ}|j||||ƒ |jƒ  dS )z0
        draw the path with updated gc.
        N)r2   Úcopy_propertiesr#   rN   r   r'   Úrestore)r   r   r    r(   r)   r*   Úgc0Ztransr   r   r   r'   º   s    
zStroke.draw_path©r   r   )rR   )r,   r-   r.   r/   r   r'   Ú__classcell__r   r   )r3   r   rL   ¯   s   	rL   c               @   s   e Zd ZdZdd„ ZdS )Ú
withStrokezy
    Adds a simple :class:`Stroke` and then draws the
    original Artist to avoid needing to call :class:`Normal`.

    c             C   s(   t j| |||||ƒ |j||||ƒ d S )N)rL   r'   )r   r   r    r(   r)   r*   r   r   r   r'   Ï   s    zwithStroke.draw_pathN)r,   r-   r.   r/   r'   r   r   r   r   rT   É   s   rT   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚSimplePatchShadowz#A simple shadow via a filled patch.é   Nç333333Ó?c                sJ   t ƒ j|ƒ |dkr|| _ntj|ƒ| _|dkr4d}|| _|| _|| _dS )a•  
        Parameters
        ----------
        offset : pair of floats
            The offset of the shadow in points.
        shadow_rgbFace : color
            The shadow color.
        alpha : float
            The alpha transparency of the created shadow patch.
            Default is 0.3.
            http://matplotlib.1069221.n5.nabble.com/path-effects-question-td27630.html
        rho : float
            A scale factor to apply to the rgbFace color if `shadow_rgbFace`
            is not specified. Default is 0.3.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.

        Ng333333Ó?)rM   r   Ú_shadow_rgbFaceÚmcolorsÚto_rgbaÚ_alphaÚ_rhorN   )r   r   Úshadow_rgbFaceÚalphaÚrhor:   )r3   r   r   r   Ö   s    zSimplePatchShadow.__init__c             C   s¬   | j ||ƒ}|jƒ }|j|ƒ | jdkr\|p.ddd… \}}	}
|| j |	| j |
| j f}n| j}|jdƒ |j| jƒ |jdƒ | j	|| j
ƒ}|j||||ƒ |jƒ  dS )z€
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.

        Nç      ð?é   Únoner   )r`   r`   r`   )r   r2   rO   rX   r\   Úset_foregroundÚ	set_alphar[   r=   r#   rN   r'   rP   )r   r   r    r(   r)   r*   Úaffine0rQ   ÚrÚgÚbr]   r   r   r   r'   ü   s    



zSimplePatchShadow.draw_pathéþÿÿÿ©rV   ri   )rj   NNrW   )r,   r-   r.   r/   r   r'   rS   r   r   )r3   r   rU   Ô   s
     $rU   c               @   s   e Zd ZdZdd„ ZdS )ÚwithSimplePatchShadowz„
    Adds a simple :class:`SimplePatchShadow` and then draws the
    original Artist to avoid needing to call :class:`Normal`.

    c             C   s(   t j| |||||ƒ |j||||ƒ d S )N)rU   r'   )r   r   r    r(   r)   r*   r   r   r   r'     s    zwithSimplePatchShadow.draw_pathN)r,   r-   r.   r/   r'   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.rV   r!   ç333333Ó?c                s>   t ƒ j|ƒ |dkr|| _ntj|ƒ| _|| _|| _|| _dS )a¼  
        Parameters
        ----------
        offset : pair of floats
            The offset to apply to the path, in points.
        shadow_color : color
            The shadow color. Default is black.
            A value of ``None`` takes the original artist's color
            with a scale factor of `rho`.
        alpha : float
            The alpha transparency of the created shadow patch.
            Default is 0.3.
        rho : float
            A scale factor to apply to the rgbFace color if `shadow_rgbFace`
            is ``None``. Default is 0.3.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.
        N)rM   r   Ú_shadow_colorrY   rZ   r[   r\   rN   )r   r   Zshadow_colorr^   r_   r:   )r3   r   r   r   $  s    zSimpleLineShadow.__init__c             C   sª   | j ||ƒ}|jƒ }|j|ƒ | jdkr`|jƒ p2ddd… \}}	}
|| j |	| j |
| j f}n| j}d}|j|ƒ |j| jƒ | j	|| j
ƒ}|j||||ƒ |jƒ  dS )z€
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.

        Nç      ð?ra   )ro   ro   ro   )r   r2   rO   rn   Zget_foregroundr\   rc   rd   r[   r#   rN   r'   rP   )r   r   r    r(   r)   r*   re   rQ   rf   rg   rh   r]   Z
fill_colorr   r   r   r'   C  s    


zSimpleLineShadow.draw_pathri   ©rV   ri   )rp   r!   rm   rm   )r,   r-   r.   r/   r   r'   rS   r   r   )r3   r   rl   "  s    rl   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	ÚPathPatchEffectz|
    Draws a :class:`~matplotlib.patches.PathPatch` instance whose Path
    comes from the original PathEffect artist.

    r   c                s"   t ƒ j|d� tjg f|Ž| _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)rM   r   ÚmpatchesZ	PathPatchÚpatch)r   r   r:   )r3   r   r   r   e  s    zPathPatchEffect.__init__c             C   sX   | j ||ƒ}|| j_| jj|ƒ | jj|jƒ ƒ |jƒ }|rH| jj|Ž  | jj|ƒ d S )N)	r   rs   Ú_pathZset_transformZset_clip_boxZget_clip_rectangleZget_clip_pathZset_clip_pathZdraw)r   r   r    r(   r)   r*   Z	clip_pathr   r   r   r'   t  s    zPathPatchEffect.draw_path©r   r   )ru   )r,   r-   r.   r/   r   r'   rS   r   r   )r3   r   rq   _  s   rq   N)r/   Zmatplotlib.backend_basesr   Z
matplotlibr   rY   r   rr   r   r	   rH   r   r%   rK   rL   rT   rU   rk   rl   rq   r   r   r   r   Ú<module>   s   :^
C=