a
    Df                     @   s   d dl Z d dlmZ d dlZddlm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dS )    N)defaultdict   )dimension_sanitizerc                       sj   e Zd ZdZe ZeeZ	dZ
d fdd	Zedd Zedd	 Zed
d Zdd Zdd Z  ZS )Linka  
    A Link defines some connection between a source and target object
    in their visualization. It is quite similar to a Stream as it
    allows defining callbacks in response to some change or event on
    the source object, however, unlike a Stream, it does not transfer
    data and make it available to user defined subscribers. Instead
    a Link directly causes some action to occur on the target, for JS
    based backends this usually means that a corresponding JS callback
    will effect some change on the target in response to a change on
    the source.

    A Link must define a source object which is what triggers events,
    but must not define a target. It is also possible to define bi-
    directional links between the source and target object.
    FNc                    s   |d u rt t| j d| jr>|d u r>t t| j d|d u rJd nt|| _|d u rbd nt|| _t j	f i | | 
  d S )Nz must define a sourcez must define a target.)
ValueErrortype__name___requires_targetweakrefref_source_targetsuper__init__link)selfsourcetargetparams	__class__ e/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/plotting/links.pyr   $   s    zLink.__init__c                 C   s   || j | | < dS )zu
        Register a LinkCallback providing the implementation for
        the Link for a particular backend.
        N)
_callbacks)clsbackendcallbackr   r   r   register_callback0   s    zLink.register_callbackc                 C   s   | j r|   S d S N)r   r   r   r   r   r   8   s    zLink.sourcec                 C   s   | j r|   S d S r   )r   r   r   r   r   r   <   s    zLink.targetc                 C   s   | j | jv r| j| j  }dd | j  D }|D ]R}dd |j  D }t|t| u r4|j | j u r4|j| ju r4||kr4 dS q4| j| j  |  n| g| j| j < dS )z$
        Registers the Link
        c                 S   s   i | ]\}}|d kr||qS namer   .0kvr   r   r   
<dictcomp>F   s   zLink.link.<locals>.<dictcomp>c                 S   s   i | ]\}}|d kr||qS r    r   r"   r   r   r   r&   I   s   N)r   registryparamvaluesitemsr   r   append)r   linksr   r   Zlink_paramsr   r   r   r   @   s"    
z	Link.linkc                 C   s*   | j | j}| |v r&|||  dS )z&
        Unregisters the Link
        N)r'   getr   popindex)r   r,   r   r   r   unlinkR   s    zLink.unlink)N)r   
__module____qualname____doc__r
   WeakKeyDictionaryr'   r   dictr   r	   r   classmethodr   propertyr   r   r   r0   __classcell__r   r   r   r   r   	   s   


r   c                   @   sJ   e Zd ZdZejdgddgddZejdddd	Zejddd
d	Z	dZ
dS )RangeToolLinka  
    The RangeToolLink sets up a link between a RangeTool on the source
    plot and the axes on the target plot. It is useful for exploring
    a subset of a larger dataset in more detail. By default it will
    link along the x-axis but using the axes parameter both axes may
    be linked to the tool.

    Example of how to use RangeToolLink can be found here:
    https://www.holoviews.org/gallery/demos/bokeh/timeseries_range_tool.html
    xyz(
        Which axes to link the tool to.)defaultZobjectsdocNr   z+
        (start, end) bounds for the x-axis)r<   lengthr=   z+
        (start, end) bounds for the y-axisT)r   r1   r2   r3   r(   ZListSelectorZaxesTupleZboundsxZboundsyr	   r   r   r   r   r9   [   s
   r9   c                   @   s   e Zd ZdZdZdS )DataLinkz
    DataLink defines a link in the data between two objects allowing
    them to be selected together. In order for a DataLink to be
    established the source and target data must be of the same length.
    TNr   r1   r2   r3   r	   r   r   r   r   r@   s   s   r@   c                   @   s   e Zd ZdZdZdS )SelectionLinkz:
    Links the selection between two glyph renderers.
    TNrA   r   r   r   r   rB   }   s   rB   c                       s0   e Zd ZdZejg dZdZ fddZ  Z	S )VertexTableLinkzm
    Defines a Link between a Path type and a Table that will
    display the vertices of selected path.
    )r<   Tc                    sD   d|vr*dd |  d d D }||d< t j||fi | d S )Nvertex_columnsc                 S   s   g | ]}t |jqS r   )r   r!   )r#   dr   r   r   
<listcomp>       z,VertexTableLink.__init__.<locals>.<listcomp>r   )
dimensionsr   r   )r   r   r   r   rH   r   r   r   r      s    zVertexTableLink.__init__)
r   r1   r2   r3   r(   ListrD   r	   r   r8   r   r   r   r   rC      s   rC   c                   @   s   e Zd ZdZdZdS )RectanglesTableLinkz0
    Links a Rectangles element to a Table.
    TNrA   r   r   r   r   rJ      s   rJ   )r
   collectionsr   r(   Z	core.utilr   ZParameterizedr   r9   r@   rB   rC   rJ   r   r   r   r   <module>   s   R
