a
    Df3E                     @   sP  d dl mZ d dlZd dlZddlmZmZmZ ddl	m
Z
 ddlmZ G dd de
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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
eZdS )'    )NumberN   )	DimensionElement	Element2D)Dataset)datetime_typesc                   @   s   e Zd ZdZdS )VectorizedAnnotationFN)__name__
__module____qualname__Z_auto_indexable_1d r   r   i/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/element/annotation.pyr	      s   r	   c                   @   s.   e Zd ZejedgddZejd ddZdS )VLinesx   r   defaultboundsTr   constantN	r
   r   r   paramListr   kdimsStringgroupr   r   r   r   r      s   r   c                   @   s.   e Zd ZejedgddZejd ddZdS )HLinesyr   r   Tr   Nr   r   r   r   r   r      s   r   c                   @   s4   e Zd ZejededgddZejd ddZdS )HSpansZy0y1r   r   r   Tr   Nr   r   r   r   r   r       s   r    c                   @   s4   e Zd ZejededgddZejd ddZdS )VSpansZx0x1r"   r   Tr   Nr   r   r   r   r   r#   $   s   r#   c                       sr   e Zd ZdZejededgddZejd ddZ	dZ
 fdd	Zd
d Zdd Zd fdd	Zdd Z  ZS )
Annotationay  
    An Annotation is a special type of element that is designed to be
    overlaid on top of any arbitrary 2D element. Annotations have
    neither key nor value dimensions allowing them to be overlaid over
    any type of data.

    Note that one or more Annotations *can* be displayed without being
    overlaid on top of any other data. In such instances (by default)
    they will be displayed using the unit axis limits (0.0-1.0 in both
    directions) unless an explicit 'extents' parameter is
    supplied. The extents of the bottom Annotation in the Overlay is
    used when multiple Annotations are displayed together.
    r   r   r"   r   Tr   c                    s   t  j|fi | d S Nsuper__init__selfdataparams	__class__r   r   r)   C   s    zAnnotation.__init__c                 C   s   dS )Nr   r   )r+   r   r   r   __len__F   s    zAnnotation.__len__c                 C   s   ||   v r| |S t|tr,t|dkr:|td f}nt|dkrN|  S tdd |D srt| j	j
 dt|d t| j \}}|j|j }}|j|j }}| j| j||||fdS )Nr   r   c                 s   s   | ]}t |tV  qd S r&   )
isinstanceslice).0kr   r   r   	<genexpr>P       z)Annotation.__getitem__.<locals>.<genexpr>z only support slice indexing)Zextents)Z
dimensionsdimension_valuesr1   tuplelenr2   cloneallKeyErrorr/   r
   r   startstopr,   )r+   keyZxkeyZykeyZxstartZxstopZystartZystopr   r   r   __getitem__I   s    
zAnnotation.__getitem__c                    sp   |  |}|dkr6tt| jr(| jn| j| gS |dkr`t| jrNg S t| jd gS t |S dS P  Return the values along the requested dimension.

        Args:
            dimension: The dimension to return values for
            expanded (bool, optional): Whether to expand values
            flat (bool, optional): Whether to flatten array

        Returns:
            NumPy array of values along the requested dimension
        r   r   N)get_dimension_indexnparrayZisscalarr,   r(   r7   r+   	dimensionexpandedflatindexr.   r   r   r7   X   s    
$"zAnnotation.dimension_valuesc                    s   t  dkr"t d tr" d  t| dt| j d g  fddt| j fi |	 D }d|vrx| j
|d< | j i |S )Nr   r   _Z__pos_paramsc                    s*   i | ]"\}}|d t   vr||qS r&   )r9   )r3   r4   vargsZpos_argsr   r   
<dictcomp>r   s   z$Annotation.clone.<locals>.<dictcomp>id)r9   r1   r8   getattrtyper
   dictr   valuesitemsrP   r/   )r+   rN   	overridessettingsr   rM   r   r:   m   s    *
zAnnotation.clone)TT)r
   r   r   __doc__r   r   r   r   r   r   Z_auxiliary_componentr)   r0   r@   r7   r:   __classcell__r   r   r.   r   r%   -   s   r%   c                       sX   e Zd ZdZejd ddZejdefe	 ddZ
dgZ fdd	Zd fd
d	Z  ZS )VLinez/Vertical line annotation at the given position.Tr   r   zI
       The x-position of the VLine which make be numeric or a timestamp.r   class_docr   c                    s@   t |tjr$|jdkr$t|d }t j|fd|i| d S )Nr   r   r   r1   rD   ZndarraysizeZ
atleast_1dr(   r)   )r+   r   r-   r.   r   r   r)      s    zVLine.__init__c                    sF   |  |}|dkr t| jgS |dkr6ttjgS t |S dS rA   rC   rD   rE   r,   nanr(   r7   rF   r.   r   r   r7      s    
zVLine.dimension_values)TT)r
   r   r   rX   r   r   r   ClassSelectorr   r   r   Z_VLine__pos_paramsr)   r7   rY   r   r   r.   r   rZ   y   s   rZ   c                       sX   e Zd ZdZejd ddZejdefe	 ddZ
dgZ fdd	Zd fd
d	Z  ZS )HLinez1Horizontal line annotation at the given position.Tr   r   zI
       The y-position of the HLine which make be numeric or a timestamp.r[   r   c                    s@   t |tjr$|jdkr$t|d }t j|fd|i| d S )Nr   r   r   r^   )r+   r   r-   r.   r   r   r)      s    zHLine.__init__c                    sF   |  |}|dkr ttjgS |dkr6t| jgS t |S dS rA   rC   rD   rE   ra   r,   r(   r7   rF   r.   r   r   r7      s    
zHLine.dimension_values)TT)r
   r   r   rX   r   r   r   rb   r   r   r   Z_HLine__pos_paramsr)   r7   rY   r   r   r.   r   rc      s   rc   c                       sN   e Zd ZdZejddZejddZddgZd fdd	Z	e
d	d
 Z  ZS )Slopez1A line drawn with arbitrary slope and y-interceptr   )r   slopey_interceptNc                    s&   t  j||ff||||d| d S )N)rf   rg   r   vdimsr'   )r+   rf   rg   r   rh   r-   r.   r   r   r)      s    zSlope.__init__c                    sV    fddt dD \}}tj||ddd}|d d }|d d }| ||fi |S )aZ  Returns a Slope element given an element of x/y-coordinates

        Computes the slope and y-intercept from an element containing
        x- and y-coordinates.

        Args:
            element: Element to compute slope from
            kwargs: Keyword arguments to pass to the Slope element

        Returns:
            Slope element
        c                 3   s   | ]}  |V  qd S r&   )r7   )r3   ielementr   r   r5      r6   z%Slope.from_scatter.<locals>.<genexpr>r   r   T)fullr   )rangerD   Zpolyfit)clsrk   kwargsr   r   parZgradientrg   r   rj   r   from_scatter   s
    zSlope.from_scatter)NN)r
   r   r   rX   r   r   rf   rg   Z_Slope__pos_paramsr)   classmethodrq   rY   r   r   r.   r   re      s   re   c                       sv   e Zd ZdZejd ddZejdefe	 dddZ
ejdefe	 dddZdd	gZd fdd	Zd fdd	Z  ZS )VSpanz/Vertical span annotation at the given position.Tr   r   zO
       The start x-position of the VSpan which must be numeric or a timestamp.r   r\   Z
allow_Noner]   zM
       The end x-position of the VSpan which must be numeric or a timestamp.r$   x2Nc                    s"   t  j||gf||d| d S )N)r$   ru   r'   )r+   r$   ru   r-   r.   r   r   r)      s    zVSpan.__init__c                    sH   |  |}|dkrt| jS |dkr8ttjtjgS t |S dS rA   r`   rF   r.   r   r   r7      s    
zVSpan.dimension_values)NN)TT)r
   r   r   rX   r   r   r   rb   r   r   r$   ru   Z_VSpan__pos_paramsr)   r7   rY   r   r   r.   r   rs      s   rs   c                       sv   e Zd ZdZejd ddZejdefe	 dddZ
ejdefe	 dddZdd	gZd fdd	Zd fdd	Z  ZS )HSpanz1Horizontal span annotation at the given position.Tr   r   zO
       The start y-position of the VSpan which must be numeric or a timestamp.rt   zM
       The end y-position of the VSpan which must be numeric or a timestamp.r!   y2Nc                    s"   t  j||gf||d| d S )N)r!   rw   r'   )r+   r!   rw   r-   r.   r   r   r)     s    zHSpan.__init__c                    sH   |  |}|dkr$ttjtjgS |dkr8t| jS t |S dS rA   rd   rF   r.   r   r   r7     s    
zHSpan.dimension_values)NN)TT)r
   r   r   rX   r   r   r   rb   r   r   r!   rw   Z_HSpan__pos_paramsr)   r7   rY   r   r   r.   r   rv     s   rv   c                       sF   e Zd ZdZejd ddZ fddZdddZd fd	d
	Z	  Z
S )Splinea  
    Draw a spline using the given handle coordinates and handle
    codes. The constructor accepts a tuple in format (coords, codes).

    Follows format of matplotlib spline definitions as used in
    matplotlib.path.Path with the following codes:

    Path.STOP     : 0
    Path.MOVETO   : 1
    Path.LINETO   : 2
    Path.CURVE3   : 3
    Path.CURVE4   : 4
    Path.CLOSEPLOY: 79
    Tr   c                    s   t  j|fi | d S r&   r'   )r+   Zspline_pointsr-   r.   r   r   r)   >  s    zSpline.__init__Nc                 O   s   t j| |||g|R i |S )a  Clones the object, overriding data and parameters.

        Args:
            data: New data replacing the existing data
            shared_data (bool, optional): Whether to use existing data
            new_type (optional): Type to cast object to
            *args: Additional arguments to pass to constructor
            **overrides: New keyword arguments to pass to constructor

        Returns:
            Cloned Spline
        )r   r:   )r+   r,   Zshared_datanew_typerN   rV   r   r   r   r:   A  s
    zSpline.clonec                    s@   |  |  dv r0t fdd| jd D S t |S dS )rB   )r   r   c                    s   g | ]}|  qS r   r   )r3   ZpointrJ   r   r   
<listcomp>^  r6   z+Spline.dimension_values.<locals>.<listcomp>r   N)rC   rD   rE   r,   r(   r7   )r+   rG   rH   rI   r.   rz   r   r7   Q  s    
zSpline.dimension_values)NTN)TT)r
   r   r   rX   r   r   r   r)   r:   r7   rY   r   r   r.   r   rx   ,  s
   
rx   c                       s   e Zd ZdZejdefe ddZejdefe ddZ	ej
dddZejd	g d
ddZejdg dddZejdddZej
d ddZg dZd fdd	Z fddZd fdd	Z  ZS )Arrowz
    Draw an arrow to the given xy position with optional text at
    distance 'points' away. The direction of the arrow may be
    specified as well as the arrow head style.
    r   I
       The x-position of the arrow which make be numeric or a timestamp.r[   I
       The y-position of the arrow which make be numeric or a timestamp. zText associated with the arrow.r   r]   <)r   ^>rL   z|
        The cardinal direction in which the arrow is pointing. Accepted
        arrow directions are '<', '^', '>' and 'v'.r   Zobjectsr]   ->)-r   z-[z-|>z<->z<|-|>z{
        The arrowstyle used to draw the arrow. Accepted arrow styles are
        '-', '->', '-[', '-|>', '<->' and '<|-|>'(   z!Font size of arrow text (if any).Tr   r   r   text	directionpoints
arrowstylec           	   	      s6   ||||||f}t  j|f||||||d| d S )Nr   r'   )	r+   r   r   r   r   r   r   r-   infor.   r   r   r)     s    zArrow.__init__c                    sD   t  | t| jdkr@| j\}}\}}}}||||||f| _dS )zg
        Add compatibility for unpickling old Arrow types with different
        .data format.
           N)r(   __setstate__r9   r,   )r+   dr   r   r   r   r   r   r.   r   r   r     s    zArrow.__setstate__c                    sF   |  |}|dkr t| jgS |dkr6t| jgS t |S dS rA   )rC   rD   rE   r   r   r(   r7   rF   r.   r   r   r7     s    
zArrow.dimension_values)r   r   r   r   )TT)r
   r   r   rX   r   rb   r   r   r   r   r   r   ObjectSelectorr   r   r   r   Z_Arrow__pos_paramsr)   r   r7   rY   r   r   r.   r   r|   d  s&     	
r|   c                       s   e Zd ZdZejdeefe ddZ	ejdeefe ddZ
ejdddZejd	d
dZejdddZejdg dddZejdg dddZejd ddZg dZd fdd	Z  ZS )Textzl
    Draw a text annotation at the specified position with custom
    fontsize, alignment and rotation.
    r   r}   r[   r~   r   zThe text to be displayed.r      zFont size of the text.zText rotation angle in degrees.center)leftrightr   zx
       The horizontal alignment position of the displayed text. Allowed values
       are 'left', 'right' and 'center'.r   )topZbottomr   zv
       The vertical alignment position of the displayed text. Allowed values
       are 'center', 'top' and 'bottom'.Tr   )r   r   r   fontsizehalignvalignrotationc           
   
      s:   |||||||f}	t  j|	f|||||||d| d S )N)r   r   r   r   r   r   r   r'   )
r+   r   r   r   r   r   r   r   r-   r   r.   r   r   r)     s    zText.__init__)r   r   r   r   )r
   r   r   rX   r   rb   r   strr   r   r   r   r   r   r   r   r   r   r   Z_Text__pos_paramsr)   rY   r   r   r.   r   r     s"     r   c                       s.   e Zd ZdZejd ddZ fddZ  ZS )Divzv
    The Div element represents a div DOM node in an HTML document defined
    as a string containing valid HTML.
    Tr   c                    s@   |d u rd}t |ts(tdt|j t j|fi | d S )Nr   z;Div element html data must be a string type, found %s type.)r1   r   
ValueErrorrR   r
   r(   r)   r*   r.   r   r   r)     s    
zDiv.__init__)	r
   r   r   rX   r   r   r   r)   rY   r   r   r.   r   r     s   r   c                   @   sR   e Zd ZdZejededgddddZejd ddZ	ejed	gd
ddZ
dS )Labelsz
    Labels represents a collection of text labels associated with 2D
    coordinates. Unlike the Text annotation, Labels is a Dataset type
    which allows drawing vectorized labels from tabular or gridded
    data.
    r   r   r"   Tzs
        The label of the x- and y-dimension of the Labels element in form
        of a string or dimension object.)r   r   r   r]   r   ZLabel)r   NzE
        Defines the value dimension corresponding to the label text.)r   r   r]   N)r
   r   r   rX   r   r   r   r   r   r   rh   r   r   r   r   r     s   r   )Znumbersr   numpyrD   r   corer   r   r   Z	core.datar   Z	core.utilr   r	   r   r   r    r#   r%   rZ   rc   re   rs   rv   rx   r|   r   r   r   r   r   r   r   <module>   s*   	L##$$%8H(