a
    Df\O                     @   s  d dl Z d dlmZ d dlZd dlmZmZ d dlmZ d dl	m
Z
 ddlmZmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZmZ dd
lmZmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' dddZ(G dd dej)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.Z0G dd de.Z1e*j23ee-fee,fee/fee0fee1fg dS )    N)getmro)RowTabs)PaneBase)
param_name   )
DynamicMapElementHoloMapLayoutOverlayStoreViewableElement)isscalar)CurvePathPointsPolygons
RectanglesTable)DataLinkRectanglesTableLinkSelectionLinkVertexTableLink)BoxEdit	CurveEdit	PointDrawPolyDrawPolyEditSelection1Dc                    s   |du rg } fdd}|S )a}  
    Turns a param.depends watch call into a preprocessor method, i.e.
    skips all downstream events triggered by it.
    NOTE: This is a temporary hack while the addition of preprocessors
          in param is under discussion. This only works for the first
          method which depends on a particular parameter.
          (see https://github.com/pyviz/param/issues/332)
    Nc                     s:   | d }d|j _ | i | d|j _g |j _g |j _d S )Nr   TF)paramZ_BATCH_WATCHZ	_watchersZ_events)argskwargsselffunction a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/annotators.pyinner    s    zpreprocess.<locals>.innerr&   )r%   currentr(   r&   r$   r'   
preprocess   s    	r*   c                   @   s   e Zd ZdZejddZejg ee	fddZ
ejdddZejd	d
dZejd	dddZejdddZejg ddZejdddddZejg ee	fddZejddiddZi Zedd Zedd Zedd Zdd Zd	S )annotatea\  
    The annotate function allows drawing, editing and annotating any
    given Element (if it is supported). The annotate function returns
    a Layout of the editable plot and an Overlay of table(s), which
    allow editing the data of the element. The edited and annotated
    data may be accessed using the element and selected properties.
    zThe current Annotator instance.)doc3
        Annotations to associate with each object.defaultclass_r,   T.
        Whether to add tool to edit vertices.r/   r,   NV
        The value to insert on annotation columns when drawing a new
        element.r   N/
        The maximum number of objects to draw.r/   Zboundsr,   8
        Whether to show vertices when drawing the Path.
        Transform(s) to apply to element when converting data to Table.
        The functions should accept the Annotator and the transformed
        element as input.  editablewidth.
        Opts to apply to the editor table(s)./
        Columns to annotate the Polygons with.nonselection_alpha      ?A
        Options to apply to vertices during drawing and editing.c                 C   s&   | j j}tjdkr"|jddgdS d S NZbokehTZhover)clonetools)	annotatorobjectr   current_backendopts)r#   	annotatedr&   r&   r'   rI   U   s    
zannotate.annotatedc                 C   s&   | j j}tjdkr"|jddgdS d S rB   )rE   selectedr   rG   rH   )r#   rJ   r&   r&   r'   rJ   [   s    
zannotate.selectedc                 G   s   g }g }|D ]}t |tr:|\}}|| |t|7 }qt |trf||j |dd |jD 7 }qt |ttfr|| qt	dt
|j qt|dd}t| | S )ac  Composes multiple annotator layouts and elements

        The composed Layout will contain all the elements in the
        supplied annotators and an overlay of all editor tables.

        Args:
            annotators: Annotator layouts or elements to compose

        Returns:
            A new layout consisting of the overlaid plots and tables
        c                 S   s   g | ]}|d  j qS r   rF   .0tr&   r&   r'   
<listcomp>w       z$annotate.compose.<locals>.<listcomp>z'Cannot compose %s type with annotators.	Annotatorgroup)
isinstancer   appendlistr+   ploteditorr
   r   
ValueErrortype__name__r   collate)cls
annotatorslayerstablesrE   ltsr&   r&   r'   composea   s"    


zannotate.composec                 K   s(  t |tr|n|g}g }d }|D ]}g }| j D ].\}}t ||r2|tt|||f q2|r|d urzd}	t|	t	|d d }||fi || _
tdd | j
jD dd}
| j
j|
 }|| q || q |d u rt |tr|n|}tdt|j t|dkr|d S | j| S )	NzAn annotate call may only annotate a single element. If you want to annotate multiple elements call annotate on each one separately and then use the annotate.compose method to combine them into a single layout.r   r   c                 S   s   g | ]}|d  j qS rK   rL   rM   r&   r&   r'   rP      rQ   z%annotate.__call__.<locals>.<listcomp>rR   rS   z2Could not find an Element to annotate on%s object.)rU   r   _annotator_typesitemsrV   r   r[   indexrZ   sortedrE   rY   rX   r\   lenrd   )r#   elementparamsoverlayr`   Zannotator_typematchesZeltypeatypemsgra   layoutobjr&   r&   r'   __call__   s4    

zannotate.__call__)r\   
__module____qualname____doc__r    	ParameterrE   ClassSelectordictrW   annotationsBooleanedit_verticesempty_valueIntegernum_objectsshow_verticesHookListtable_transformsDict
table_optsvertex_annotationsvertex_stylere   propertyrI   rJ   classmethodrd   rr   r&   r&   r&   r'   r+   *   s&   


r+   c                       sR  e Zd ZdZejg eefddZej	ddddddd	Z
ejd
dd	ZejeddZejd
dddZejg dd	Zej	ddddd	Zg Zi Zg dZeZeZdZedd Zedd Zedd Z d5 fdd	Z!e"ddd d!d" Z#d6d#d$Z$e%d7d%d&Z&d'd( Z'd8d)d*Z(d+d, Z)d9d-d.Z*ed/d0 Z+ed1d2 Z,ed3d4 Z-  Z.S ):rR   aV  
    An Annotator allows drawing, editing and annotating a specific
    type of element. Each Annotator consists of the `plot` to draw and
    edit the element and the `editor`, which contains a list of tables,
    which make it possible to annotate each object in the element with
    additional properties defined in the `annotations`.
    r-   r.   Tr9   皙?
responsive
min_heightpadding	framewise&
        Opts to apply to the element.r2   Nr3   z*
        The Element to edit and annotate.r0   r,   r4   r5   r6   r8   r:   r=   )ry   rF   r   gffffff?c                 C   s   dt jvrdS t|| jjjS )NZ	holoviewsF)sysmodulesrU   r    rF   r0   )r^   rq   r&   r&   r'   applies   s    
zAnnotator.appliesc                 C   s
   | j jjS N)r    rF   r0   r#   r&   r&   r'   _element_type   s    zAnnotator._element_typec                 C   s   | j jS r   )r   r\   r   r&   r&   r'   _object_name   s    zAnnotator._object_namec                    s   t  jdi | | || _t | _tt| j | jf| _	t
| j| _| jg| jjjd d < g | _|   | jj| jdd t| jd| _|   |   | j| j| j | j| j	g| jd d < d S )Nr   )
precedence)source)N)super__init___process_elementrF   r   
_table_rowr   r   namerY   r   	_get_plotrX   callbackinputsZ_tables_init_stream_streamZadd_subscriber_update_objectr   
_selection_update_table_update_linksr    Zwatch_update	_triggersrp   r#   rF   rk   	__class__r&   r'   r      s    zAnnotator.__init__ry   rF   default_optsc                 C   s   |  | jS r   )r   rF   r   r&   r&   r'   r      s    zAnnotator._get_plotc                 C   s   | j ||||S r   )rp   
_get_model)r#   r,   rootparentZcommr&   r&   r'   r      s    zAnnotator._get_modelc                 C   sR   |rF|j dkrFt|  | |j| _W d    n1 s<0    Y  |   d S )NrF   )r   r    discard_eventsr   newrF   r   )r#   eventr&   r&   r'   r      s    ,zAnnotator._updatec                 C   sT   t | dr| j  | | j| j| _| jrPt | dr@| j  t| j| j| _d S )N_link_selection_link)	hasattrr   unlink
_link_typerX   _table_selection_link_typer   r   r   r&   r&   r'   r     s
    zAnnotator._update_linksc                 C   sR   t | 4 t| jjdkr&| jd  | jj| _W d    n1 sD0    Y  d S )Nr   r&   )r    r   ri   r   r   rX   rj   rF   r#   datar&   r&   r'   r     s    
zAnnotator._update_objectc                 C   s^   | j }| jD ]}||}qt|t| jdjf ddi| j| _|   | jg| j	d d < d S )Nlabel
show_titleF)
rF   r   r   r   r   rH   r   r   r   r   )r#   rF   	transformr&   r&   r'   r     s    

zAnnotator._update_tablec                 C   s   | j |S r   )rp   select)r#   selectorr&   r&   r'   r     s    zAnnotator.selectc                 G   s`   g g  }}|D ]:}t |tr4||j ||j7 }qt |tr|| qtt| t	| S )a_  Composes multiple Annotator instances and elements

        The composed Panel will contain all the elements in the
        supplied Annotators and Tabs containing all editors.

        Args:
            annotators: Annotator objects or elements to compose

        Returns:
            A new Panel consisting of the overlaid plots and tables
        )
rU   rR   rV   rX   ra   r	   r   r   r]   r   )r^   r_   r`   ra   ar&   r&   r'   rd     s    


zAnnotator.composec                 C   s   t t| jj| jS r   )rW   ziprY   Z_namesr   r&   r&   r'   ra   0  s    zAnnotator.tablesc                 C   s   | j j| jj S r   )rF   Zilocr   rg   r   r&   r&   r'   rJ   4  s    zAnnotator.selected)N)NNN)N)N)N)/r\   rs   rt   ru   r    rw   rx   rW   ry   r   r   rv   r|   r	   rF   r}   r~   r   r   r   _tools_extra_optsr   r   r   r   r   priorityr   r   r   r   r   r   dependsr   r   r*   r   r   r   r   r   rd   ra   rJ   __classcell__r&   r&   r   r'   rR      sP   





	


rR   c                       s   e Zd ZdZejdddZejeddZ	ejdddZ
ejg eefdd	Zejd
diddZeZg dZd fdd	Zdd ZdddZ fddZdddZdd Zedd Z  ZS ) PathAnnotatorz
    Annotator which allows drawing and editing Paths and associating
    values with each path and each vertex of a path using a table.
    Tr1   r2   z*
        Path object to edit and annotate.r   r7   r>   r.   r?   r@   rA   )ry   r{   rF   r   r   Nc                    s>   t  | _t j|fi | | jt| j d| jf d S )N	 Vertices)r   _vertex_table_rowr   r   rY   rV   r   r   r   r   r&   r'   r   T  s
    zPathAnnotator.__init__c              	   C   sV   t | j}t| ji | j| j| d| j| jd| _| j	rRt
| j| d| jd| _d S )N Tool)r   r   r~   r   tooltipr   r|   z
 Edit Tool)r   r   r   )r   r   r   rX   r~   r   r   r|   r   r{   r   Z_vertex_streamr#   r   r&   r&   r'   r   Z  s    

zPathAnnotator._init_streamc           	         sx   d u st  | jsBt| jj}|d |d | j |d g }| jD ]J}| v rd|| qLt | jtr|| j|  nd} |t	 j
|d qL| jD ]D}| v rqnt | jtr| j|  }nd} |t	 j
|d q fdd|D }|r$t	dd | D d	kr$td
| dd | jD }tf |d d| j}|| j  jf i  fdd| D S )Nmultitabular)datatype Tc                    s   i | ]}| j |d dqS F)expanded)dimension_values)rN   crj   r&   r'   
<dictcomp>  s   z2PathAnnotator._process_element.<locals>.<dictcomp>c                 S   s   h | ]}t |qS r&   )ri   )rN   vr&   r&   r'   	<setcomp>  rQ   z1PathAnnotator._process_element.<locals>.<setcomp>r   ziannotations must refer to value dimensions which vary per path while at least one of %s varies by vertex.c                 S   s   g | ]
}| qS r&   r&   rN   Ztoolr&   r&   r'   rP     rQ   z2PathAnnotator._process_element.<locals>.<listcomp>)rD   Zcolor_indexc                    s(   i | ] \}}| j d jvr||qS rX   rH   getr"   rN   kr   r   r&   r'   r     s   )rU   r   rW   r   removerV   ry   rx   add_dimensionri   vdimsr   valuesrZ   r   r   updater   optionsrf   )	r#   rj   r   validatecolinitZ	poly_datarD   rH   r&   r   r'   r   g  s<    





"zPathAnnotator._process_elementc                    s4   t    t| dr| j  | | j| j| _d S )N_vertex_link)r   r   r   r   r   _vertex_table_linkrX   _vertex_tabler   r   r&   r'   r     s    
zPathAnnotator._update_linksc                 C   s   | j jd ur| j j}|jjdkrv|jrvt|jd trv|jD ]8}| jD ],}t|| sFt	|| rF|| d ||< qFq<t
|  || _W d    n1 s0    Y  d S )Nr   r   )r   rj   Z	interfacer   r   rU   rx   ry   r   ri   r    r   rF   )r#   r   rj   pathr   r&   r&   r'   r     s    

zPathAnnotator._update_objectc                    s   t | j}t| j}| j | jD ]}|  q  fdd|D }t||g |djf ddi| j| _	tg  j
t| j| ddjf ddi| j| _|   | j	g| jd d < | jg| jd d < d S )Nc                    s    i | ]}|t  j|d dqS r   )rW   r   )rN   r   tabler&   r'   r     s   z/PathAnnotator._update_table.<locals>.<dictcomp>r   r   Fr   )r   r   rW   ry   rF   r   r   rH   r   r   Zkdimsr   r   r   r   r   )r#   r   ry   r   Z
table_datar&   r   r'   r     s.    





zPathAnnotator._update_tablec                    s2   | j j  fddt| jj D }| j|S )Nc                    s   g | ]\}}| v r|qS r&   r&   )rN   iprg   r&   r'   rP     rQ   z*PathAnnotator.selected.<locals>.<listcomp>)r   rg   	enumerater   rj   splitrF   rC   r   r&   r   r'   rJ     s    zPathAnnotator.selected)N)N)N)r\   rs   rt   ru   r    rz   r{   rw   r   rF   r   rx   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   rJ   r   r&   r&   r   r'   r   :  s    
'
r   c                   @   s   e Zd ZdZejeddZdS )PolyAnnotatorz
    Annotator which allows drawing and editing Polygons and associating
    values with each polygon and each vertex of a Polygon using a table.
    z/
         Polygon element to edit and annotate.r   N)r\   rs   rt   ru   r    rw   r   rF   r&   r&   r&   r'   r     s   r   c                   @   s<   e Zd ZejdddddddZdZdZdd	 Zd
d Z	dS )_GeomAnnotatorTr9   r   r   r   r2   Nc                 C   s0   t | j}| j| ji | j| d| jd| _d S )Nr   )r   r   r~   r   r|   )r   r   _stream_typerX   r~   r|   r   r   r&   r&   r'   r     s
    

z_GeomAnnotator._init_streamc                    s    d u st  | js|   | jD ]@}| v r2q$t | jtrJ| j|  nd} |t j|d q$dd | jD }tf d|i| j}|	| j
  jf i  fdd| D S )Nr   Tc                 S   s   g | ]
}| qS r&   r&   r   r&   r&   r'   rP     rQ   z3_GeomAnnotator._process_element.<locals>.<listcomp>rD   c                    s(   i | ] \}}| j d jvr||qS r   r   r   rL   r&   r'   r     s   z3_GeomAnnotator._process_element.<locals>.<dictcomp>)rU   r   ry   rx   r   ri   r   r   r   r   r   r   rf   )r#   rF   r   r   rD   rH   r&   rL   r'   r     s    

z_GeomAnnotator._process_element)
r\   rs   rt   r    r   r   r   Z_GeomAnnotator__abstractr   r   r&   r&   r&   r'   r     s   r   c                   @   s<   e Zd ZdZejddddddddZejed	d
Z	e
ZdS )PointAnnotatorzu
    Annotator which allows drawing and editing Points and associating
    values with each point using a table.
    Tr9   r   
   )r   r   r   sizer   r   r2   -
        Points element to edit and annotate.r   N)r\   rs   rt   ru   r    r   r   rw   r   rF   r   r   r&   r&   r&   r'   r     s   r   c                   @   sT   e Zd ZdZejdddddddZejedd	Z	ejd
diddZ
eZdd ZdS )CurveAnnotatorzs
    Annotator which allows editing a Curve element and associating values
    with each vertex using a Table.
    Tr9   r   r   r   r2   r   r   r   r   rA   c                 C   s,   t | j}| j| ji | d| jd| _d S )Nr   )r   r   r   style)r   r   r   rX   r   r   r   r&   r&   r'   r     s
    
zCurveAnnotator._init_streamN)r\   rs   rt   ru   r    r   r   rw   r   rF   r   r   r   r   r&   r&   r&   r'   r     s   r   c                   @   s&   e Zd ZdZejeddZeZ	e
ZdS )RectangleAnnotatorzy
    Annotator which allows drawing and editing Rectangles and associating
    values with each point using a table.
    r   r   N)r\   rs   rt   ru   r    rw   r   rF   r   r   r   r   r&   r&   r&   r'   r     s   r   )N)4r   inspectr   r    Zpanel.layoutr   r   Z
panel.paner   Z
panel.utilr   corer   r	   r
   r   r   r   r   Z	core.utilr   rj   r   r   r   r   r   r   Zplotting.linksr   r   r   r   Zstreamsr   r   r   r   r   r   r*   ZParameterizedFunctionr+   rR   r   r   r   r   r   r   re   r   r&   r&   r&   r'   <module>   s6   $  
y ~%