B
    ò¶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.
    ©g        g        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   ú:/tmp/pip-unpacked-wheel-tvo012g9/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.)ÚmtransformsZAffine2DÚ	translateÚmapÚpoints_to_pixelsr   )r	   Úrendererr   r   r   Ú_offset_transform    s    z$AbstractPathEffect._offset_transformc             C   sl   |  ¡ }| dd¡}|r$|jf |Ž xB| ¡ D ]6\}}t|d| dƒ}t|ƒs\td |¡ƒ‚||ƒ 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}| ||||¡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 )N)Ú	__class__r#   )r	   r-   r   r   r   Úcopy_with_path_effect_   s    z(PathEffectRenderer.copy_with_path_effectNc             C   s(   x"| j D ]}| | j||||¡ qW d S )N)r,   r$   r#   )r	   r   r%   r&   r'   Úpath_effectr   r   r   r$   b   s    zPathEffectRenderer.draw_pathc       	      O   s`   t | jƒdkr(tj| ||||f|ž|ŽS x2| jD ](}|  |g¡}|j||||f|ž|Ž q0W d S )Né   )Úlenr,   r   Údraw_markersr/   )	r	   r   Zmarker_pathZmarker_transÚpathÚargsÚkwargsr0   r   r   r   r   r3   g   s    

zPathEffectRenderer.draw_markersc             O   s\   t | jƒdkr&tj| |||f|ž|ŽS x0| jD ]&}|  |g¡}|j|||f|ž|Ž q.W d S )Nr1   )r2   r,   r   Údraw_path_collectionr/   )r	   r   Zmaster_transformÚpathsr5   r6   r0   r   r   r   r   r7   z   s    
z'PathEffectRenderer.draw_path_collectionc             C   s@   |   ||||||¡\}}	| ¡ }
| d¡ | j|||	|
d� d S )Ng        )r'   )Z_get_text_path_transformZget_rgbÚset_linewidthr$   )r	   r   ÚxÚyÚsÚpropZangleZismathr4   Z	transformÚcolorr   r   r   Ú_draw_text_as_path�   s
    
z%PathEffectRenderer._draw_text_as_pathc             C   s$   |dkrt | j|ƒS t | |¡S d S )N)ZflipyZget_canvas_width_heightÚnew_gcr   Z
_text2pathÚheightÚwidth)r   r#   ÚobjectÚ__getattribute__)r	   Únamer   r   r   rD   •   s    z#PathEffectRenderer.__getattribute__)N)r(   r)   r*   r+   r   r/   r$   r3   r7   r?   rD   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(   r)   r*   r+   r   r   r   r   rF   �   s   rF   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 )N)Úsuperr$   )r	   r   r   r%   r&   r'   )r.   r   r   r$   ¬   s    z3_subclass_with_normal.<locals>.withEffect.draw_path)r(   r)   r*   r$   Ú__classcell__r   r   )r.   r   Ú
withEffect«   s   rI   Ú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(   r*   r+   r$   )Úeffect_classrI   r   r   r   Ú_subclass_with_normal¦   s     rL   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   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)rG   r   Ú_gc)r	   r
   r6   )r.   r   r   r   Ç   s    zStroke.__init__c             C   sF   |  ¡ }| |¡ |  || j¡}| ||||  |¡ |¡ | ¡  dS )zDraw the path with updated gc.N)r@   Úcopy_propertiesr    rO   r$   r   Úrestore)r	   r   r   r%   r&   r'   Úgc0r   r   r   r$   Ð   s    
zStroke.draw_path)rN   )r(   r)   r*   r+   r   r$   rH   r   r   )r.   r   rM   Ä   s   	rM   )rK   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 ƒ  |¡ |dkr|| _nt |¡| _|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, 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`.

        Ng333333Ó?)rG   r   Ú_shadow_rgbFaceÚmcolorsÚto_rgbaÚ_alphaÚ_rhorO   )r	   r
   Úshadow_rgbFaceÚalphaÚrhor6   )r.   r   r   r   à   s    zSimplePatchShadow.__init__c             C   sª   |  ¡ }| |¡ | jdkrP|p"ddd… \}}}	|| j || j |	| j f}
n| j}
| d¡ | | j¡ | d¡ |  || j	¡}| 
||||  |¡ |
¡ | ¡  dS )z
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.
        N)g      ð?g      ð?g      ð?é   Únoner   )r@   rP   rX   r\   Úset_foregroundÚ	set_alphar[   r9   r    rO   r$   r   rQ   )r	   r   r   r%   r&   r'   rR   ÚrÚgÚbr]   r   r   r   r$     s    



zSimplePatchShadow.draw_path)rT   NNrW   )r(   r)   r*   r+   r   r$   rH   r   r   )r.   r   rS   Ý   s
     #rS   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.©rU   rV   r   ç333333Ó?c                s>   t ƒ  |¡ |dk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)rG   r   Ú_shadow_colorrY   rZ   r[   r\   rO   )r	   r
   Zshadow_colorr^   r_   r6   )r.   r   r   r   %  s    zSimpleLineShadow.__init__c             C   s¢   |  ¡ }| |¡ | jdkrT| ¡ p&ddd… \}}}	|| j || j |	| j f}
n| j}
| |
¡ | | j¡ |  || j	¡}| 
||||  |¡ ¡ | ¡  dS )z
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.
        N)g      ð?g      ð?g      ð?r`   )r@   rP   rj   Zget_foregroundr\   rb   rc   r[   r    rO   r$   r   rQ   )r	   r   r   r%   r&   r'   rR   rd   re   rf   r]   r   r   r   r$   C  s    


zSimpleLineShadow.draw_path)rh   r   ri   ri   )r(   r)   r*   r+   r   r$   rH   r   r   )r.   r   rg   "  s    rg   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚPathPatchEffectza
    Draws a `.PathPatch` instance whose Path comes from the original
    PathEffect artist.
    ©r   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)rG   r   ÚmpatchesZ	PathPatchÚpatch)r	   r
   r6   )r.   r   r   r   a  s    zPathPatchEffect.__init__c             C   sV   || j _| j  ||  |¡ ¡ | j  | ¡ ¡ | ¡ }|rF| j j|Ž  | j  |¡ d S )N)	rn   Ú_pathZset_transformr   Z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$   p  s    zPathPatchEffect.draw_path)rl   )r(   r)   r*   r+   r   r$   rH   r   r   )r.   r   rk   [  s   rk   N)r+   Zmatplotlib.backend_basesr   Z
matplotlibr   rY   r   rm   r   r   r   r"   rF   rL   rM   Z
withStrokerS   ZwithSimplePatchShadowrg   rk   r   r   r   r   Ú<module>   s   7W	
B
9