a
    ìÝEb“/  ã                   @   s˜   d dl Zd dlmZ d dlmZmZ dd„ ZG dd„ dƒZ	G dd	„ d	eƒZ
G d
d„ dƒZG dd„ dejƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZdS )é    N)Úticker)ÚBboxÚ	Transformc              
   C   s@  g }| dd… | dd…  }t dƒt dddƒfD �]}| j| \}}|j| \}}|j| \}	}
|j| \}}|	||	kf|||k ffD ]²\}}| g ¡ |dd… |dd… A  ¡ \}|D ]|}|| |||  ||  ||   }|
|  krö|ksúqº qº||f| }t tj|| ddd… Ž ¡}|d  ||f¡ qºq†q0|S )aá  
    Find the points where a polyline crosses a bbox, and the crossing angles.

    Parameters
    ----------
    xys : (N, 2) array
        The polyline coordinates.
    bbox : `.Bbox`
        The bounding box.

    Returns
    -------
    list of ((float, float), float)
        Four separate lists of crossings, for the left, right, bottom, and top
        sides of the bbox, respectively.  For each list, the entries are the
        ``((x, y), ccw_angle_in_degrees)`` of the crossing, where an angle of 0
        means that the polyline is moving to the right at the crossing point.

        The entries are computed by linearly interpolating at each crossing
        between the nearest points on either side of the bbox edges.
    é   Néÿÿÿÿ)	ÚsliceÚTÚminÚmaxÚappendZnonzeroÚnpÚdegreesZarctan2)ZxysZbboxZ	crossingsZdxysÚslÚusÚvsZdusZdvsZuminZvminZumaxZvmaxZu0ZinsideZidxsÚidxÚvZcrossingÚtheta© r   úc/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/mpl_toolkits/axisartist/grid_finder.pyÚ_find_line_box_crossings   s$     
$r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚExtremeFinderSimplezU
    A helper class to figure out the range of grid lines that need to be drawn.
    c                 C   s   || _ || _dS )zy
        Parameters
        ----------
        nx, ny : int
            The number of samples in each direction.
        N©ÚnxÚny)Úselfr   r   r   r   r   Ú__init__6   s    zExtremeFinderSimple.__init__c           
      C   sb   t  t  ||| j¡t  ||| j¡¡\}}|t  |¡t  |¡ƒ\}}	|  | ¡ | ¡ |	 ¡ |	 ¡ ¡S )ai  
        Compute an approximation of the bounding box obtained by applying
        *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.

        The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
        and have *transform_xy* be the transform from axes coordinates to data
        coordinates; this method then returns the range of data coordinates
        that span the actual axes.

        The computation is done by sampling ``nx * ny`` equispaced points in
        the ``(x1, y1, x2, y2)`` box and finding the resulting points with
        extremal coordinates; then adding some padding to take into account the
        finite sampling.

        As each sampling step covers a relative range of *1/nx* or *1/ny*,
        the padding is computed by expanding the span covered by the extremal
        coordinates by these fractions.
        )	r   ZmeshgridÚlinspacer   r   ZravelÚ_add_padr	   r
   )
r   Útransform_xyÚx1Úy1Úx2Úy2ÚxÚyZxtZytr   r   r   Ú__call__@   s
    ÿzExtremeFinderSimple.__call__c                 C   s8   || | j  }|| | j }|| || || || fS )z,Perform the padding mentioned in `__call__`.r   )r   Zx_minZx_maxZy_minZy_maxZdxZdyr   r   r   r   X   s    zExtremeFinderSimple._add_padN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r   r   r   r   r   r   1   s   
r   c                       s8   e Zd ZdZd ZZ‡ fdd„Zdd„ Zdd„ Z‡  Z	S )	Ú_User2DTransformz.A transform defined by two user-set functions.é   c                    s   t ƒ  ¡  || _|| _dS )zÞ
        Parameters
        ----------
        forward, backward : callable
            The forward and backward transforms, taking ``x`` and ``y`` as
            separate arguments and returning ``(tr_x, tr_y)``.
        N)Úsuperr   Ú_forwardÚ	_backward)r   ÚforwardZbackward©Ú	__class__r   r   r   d   s    

z_User2DTransform.__init__c                 C   s   t  | jt  |¡Ž ¡S ©N)r   Z	transposer.   )r   Úvaluesr   r   r   Útransform_non_affiner   s    z%_User2DTransform.transform_non_affinec                 C   s   t | ƒ| j| jƒS r3   )Útyper/   r.   ©r   r   r   r   Úinvertedv   s    z_User2DTransform.inverted)
r'   r(   r)   r*   Z
input_dimsZoutput_dimsr   r5   r8   Ú__classcell__r   r   r1   r   r+   _   s
   r+   c                   @   sZ   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZeZ	dd„ Z
dd„ Zdd„ ZdS )Ú
GridFinderNc                 C   sv   |du rt ddƒ}|du r tƒ }|du r.tƒ }|du r<tƒ }|du rJtƒ }|| _|| _|| _|| _|| _|  |¡ dS )a  
        transform : transform from the image coordinate (which will be
        the transData of the axes to the world coordinate.

        or transform = (transform_xy, inv_transform_xy)

        locator1, locator2 : grid locator for 1st and 2nd axis.
        Né   )	r   ÚMaxNLocatorÚFormatterPrettyPrintÚextreme_finderÚgrid_locator1Úgrid_locator2Útick_formatter1Útick_formatter2Úset_transform)r   Ú	transformr>   r?   r@   rA   rB   r   r   r   r   |   s     
zGridFinder.__init__c              
   C   sZ  |   | j||||¡}|\}}}}	|  ||¡\}
}}|  ||	¡\}}}|
d|… | }|d|… | }|  ||||||	¡\}}|| d }|| d }t || || || || ¡}||||  |||
|¡|  ||||¡dœ}i  }|d d< dD ]&}|d d | }|  |||¡||< qði  }|d d< dD ](}|d d | }|  	|||¡||< �q,|S )	z˜
        lon_values, lat_values : list of grid values. if integer is given,
                           rough number of grids in each direction.
        Ng»½×Ùß|Û=)ÚextremesÚ	lon_linesÚ	lat_linesÚlonÚlatrH   Ztick_labels©ÚleftÚbottomÚrightÚtopÚtick_levelsrI   )
r>   Úinv_transform_xyr?   r@   Ú_get_raw_grid_linesr   Zfrom_extentsÚ_clip_grid_lines_and_find_ticksrA   rB   )r   r    r!   r"   r#   rE   Úlon_minÚlon_maxÚlat_minÚlat_maxZlon_levsZlon_nZ
lon_factorZlat_levsZlat_nZ
lat_factorÚ
lon_valuesÚ
lat_valuesrF   rG   ZddxZddyÚbbZ	grid_infoZ
tck_labelsÚ	directionÚlevsr   r   r   Úget_grid_infoœ   sJ    ý ÿÿú
ÿ
ÿzGridFinder.get_grid_infoc           	         sL   t  ||d¡‰t  ||d¡‰ ‡ ‡fdd„|D ƒ}‡‡fdd„|D ƒ}||fS )Néd   c                    s    g | ]}ˆ  t ˆ |¡ˆ ¡‘qS r   ©r   r   Z	full_like)Ú.0rH   )Úlats_ir   r   r   Ú
<listcomp>Ö   s   ÿz2GridFinder._get_raw_grid_lines.<locals>.<listcomp>c              	      s    g | ]}ˆ  ˆ t ˆ |¡¡‘qS r   r^   )r_   rI   )Úlons_ir   r   r   ra   Ø   s   ÿ)r   r   )	r   rW   rX   rS   rT   rU   rV   rF   rG   r   )r`   rb   r   r   rQ   Ï   s    ÿÿzGridFinder._get_raw_grid_linesc              	   C   sÌ   g g t g g g g d�t g g g g d�g dœ}|d }|d }t|||ƒD ]‚\\}}	}
}tt ||	g¡|ƒ}|d  |
¡ |d  ||	fg¡ t|g d¢ƒD ].\}}|D ] }||  |¡ ||  |¡ q¢q–qD|S )NrJ   )r4   ÚlevelsrO   Ú	tick_locsÚlinesrO   rd   rc   re   )rK   rM   rL   rN   )ÚdictÚzipr   r   Úcolumn_stackr   )r   re   r4   r[   rY   ÚgiZ
tck_levelsZtck_locsÚlxZlyr   ZlevZtcksZtckrZ   Útr   r   r   rR   Ý   s&    ûÿz*GridFinder._clip_grid_lines_and_find_ticksc                 C   sD   t |tƒr|| _n.t|ƒdkr8ttt|ƒƒr8t|Ž | _ntdƒ‚d S )Nr,   zF'aux_trans' must be either a Transform instance or a pair of callables)	Ú
isinstancer   Ú_aux_transformÚlenÚallÚmapÚcallabler+   Ú	TypeError)r   Z	aux_transr   r   r   rC   õ   s
    
zGridFinder.set_transformc                 C   s   | j S r3   )rm   r7   r   r   r   Úget_transformþ   s    zGridFinder.get_transformc                 C   s   | j  t ||g¡¡jS r3   )rm   rD   r   rh   r   ©r   r$   r%   r   r   r   r     s    zGridFinder.transform_xyc                 C   s   | j  ¡  t ||g¡¡jS r3   )rm   r8   rD   r   rh   r   rt   r   r   r   rP     s    
ÿzGridFinder.inv_transform_xyc                 K   s4   |D ]*}|dv r"t | ||| ƒ qtd| ƒ‚qd S )N)r>   r?   r@   rA   rB   zUnknown update property '%s')ÚsetattrÚ
ValueError)r   ÚkwÚkr   r   r   Úupdate
  s    zGridFinder.update)NNNNN)r'   r(   r)   r   r\   rQ   rR   rC   rs   Zupdate_transformr   rP   ry   r   r   r   r   r:   {   s        ú
 3	r:   c                       s*   e Zd Zd	‡ fdd„	Z‡ fdd„Z‡  ZS )
r<   é
   NTFc                    s"   t ƒ j|||||d� |  ¡  d S )N)ÚstepsÚintegerÚ	symmetricÚprune)r-   r   Úcreate_dummy_axis)r   Znbinsr{   Ztrimr|   r}   r~   r1   r   r   r     s    ÿzMaxNLocator.__init__c                    s"   t ƒ  ||¡}t |¡t|ƒdfS )Nr   )r-   Ztick_valuesr   Úarrayrn   ©r   Úv1Úv2Úlocsr1   r   r   r&   !  s    zMaxNLocator.__call__)rz   NTFFN©r'   r(   r)   r   r&   r9   r   r   r1   r   r<     s        ü
r<   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFixedLocatorc                 C   s
   || _ d S r3   )Ú_locs)r   r„   r   r   r   r   '  s    zFixedLocator.__init__c                    s:   t ˆ ˆgƒ\‰ ‰t ‡ ‡fdd„| jD ƒ¡}|t|ƒdfS )Nc                    s(   g | ] }ˆ |  krˆkrn q|‘qS r   r   )r_   Úl©r‚   rƒ   r   r   ra   ,  ó    z)FixedLocator.__call__.<locals>.<listcomp>r   )Úsortedr   r€   r‡   rn   r�   r   r‰   r   r&   *  s    zFixedLocator.__call__N©r'   r(   r)   r   r&   r   r   r   r   r†   &  s   r†   c                   @   s   e Zd Zddd„Zdd„ ZdS )r=   Tc                 C   s   t j|dd�| _| j ¡  d S )NF)ÚuseMathTextZ	useOffset)ÚmtickerZScalarFormatterÚ_fmtr   )r   r�   r   r   r   r   3  s    ÿzFormatterPrettyPrint.__init__c                 C   s   | j  |¡S r3   )r�   Zformat_ticks)r   rZ   Úfactorr4   r   r   r   r&   8  s    zFormatterPrettyPrint.__call__N)TrŒ   r   r   r   r   r=   2  s   
r=   c                       s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )ÚDictFormatterNc                    s   t ƒ  ¡  || _|| _dS )zq
        format_dict : dictionary for format strings to be used.
        formatter : fall-back formatter
        N)r-   r   Ú_format_dictÚ_fallback_formatter)r   Zformat_dictÚ	formatterr1   r   r   r   =  s    
zDictFormatter.__init__c                    s<   ˆ j rˆ   |||¡}ndgt|ƒ }‡ fdd„t||ƒD ƒS )zG
        factor is ignored if value is found in the dictionary
        Ú c                    s   g | ]\}}ˆ j  ||¡‘qS r   )r’   Úget)r_   rx   r   r7   r   r   ra   O  s   ÿz*DictFormatter.__call__.<locals>.<listcomp>)r“   rn   rg   )r   rZ   r�   r4   Zfallback_stringsr   r7   r   r&   F  s    ÿ
ÿzDictFormatter.__call__)Nr…   r   r   r1   r   r‘   <  s   	r‘   )Únumpyr   Z
matplotlibr   rŽ   Zmatplotlib.transformsr   r   r   r   r+   r:   r<   r†   r=   r‘   r   r   r   r   Ú<module>   s   *. 
