
    Le                         d dl Z d dlmZ d dlZddlmZ  G d dej                  Z G d de          Z G d	 d
e          Z	 G d de          Z
 G d de          Z G d de          ZdS )    N)defaultdict   )dimension_sanitizerc                        e Zd ZdZ ej                    Z ee          Z	dZ
d
 fd	Zed             Zed             Zed             Zd Zd	 Z x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                 |   |$t          t          |           j         d          | j        r&|$t          t          |           j         d          |d nt	          j        |          | _        |d nt	          j        |          | _         t                      j	        d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__s       8lib/python3.11/site-packages/holoviews/plotting/links.pyr   zLink.__init__$   s    >T

 3JJJKKK  	MV^T

 3KKKLLL  &~tt7;v3F3F%~tt7;v3F3F""6"""		    c                 &    || j         |         | <   dS )zu
        Register a LinkCallback providing the implementation for
        the Link for a particular backend.
        N)
_callbacks)clsbackendcallbacks      r   register_callbackzLink.register_callback0   s     (0w$$$r   c                 <    | j         r|                                  nd S N)r   r   s    r   r   zLink.source8       !%7t||~~~47r   c                 <    | j         r|                                  nd S r#   )r   r$   s    r   r   zLink.target<   r%   r   c                    | j         | j        v r| j        | j                  }d | j                                                                        D             }|D ]z}d |j                                                                        D             }t          |          t          |           u r%|j         | j         u r|j        | j        u r	||k    r dS {| j        | j                                      |            dS | g| j        | j         <   dS )z$
        Registers the Link
        c                 &    i | ]\  }}|d k    ||S namer	   .0kvs      r   
<dictcomp>zLink.link.<locals>.<dictcomp>F   s-     M M MAV1r   c                 &    i | ]\  }}|d k    ||S r)   r	   r+   s      r   r/   zLink.link.<locals>.<dictcomp>I   s-     Q Q Q!QAKKAqKKKr   N)r   registryparamvaluesitemsr   r   append)r   linksr   r   link_paramss        r   r   z	Link.link@   s)    ;$-''M$+.EM M!%!2!2!4!4!:!:!<!<M M MF  Q Q%)Z%6%6%8%8%>%>%@%@Q Q QJJ$t**,,1K1Kt{22v7L7LFFM$+&--d33333*.DM$+&&&r   c                     | j                             | j                  }| |v r*|                    |                    |                      dS dS )z&
        Unregisters the Link
        N)r1   getr   popindex)r   r6   s     r   unlinkzLink.unlinkR   sO     !!$+..5==IIekk$''((((( =r   r#   )r   
__module____qualname____doc__r   WeakKeyDictionaryr1   r   dictr   r   r   classmethodr!   propertyr   r   r   r<   __classcell__r   s   @r   r   r   	   s         " )w(**H T""J 
 
 
 
 
 
 0 0 [0 8 8 X8 8 8 X80 0 0$) ) ) ) ) ) )r   r   c                       e Zd ZdZ ej        dgddgd          Z ej        ddd	          Z ej        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.)defaultobjectsdocNr   z+
        (start, end) bounds for the x-axis)rJ   lengthrL   z+
        (start, end) bounds for the y-axisT)r   r=   r>   r?   r2   ListSelectoraxesTupleboundsxboundsyr   r	   r   r   rG   rG   [   s        	 	 5sec3Z F+ , , ,D ek$q 7. / / /G ek$q 7. / / /G r   rG   c                       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   r=   r>   r?   r   r	   r   r   rT   rT   s   s"          r   rT   c                       e Zd ZdZdZdS )SelectionLinkz:
    Links the selection between two glyph renderers.
    TNrU   r	   r   r   rW   rW   }   "          r   rW   c                   H     e Zd ZdZ ej        g           ZdZ fdZ xZ	S )VertexTableLinkzm
    Defines a Link between a Path type and a Table that will
    display the vertices of selected path.
    )rJ   Tc                     d|vr+d |                                 d d         D             }||d<    t                      j        ||fi | d S )Nvertex_columnsc                 6    g | ]}t          |j                  S r	   )r   r*   )r,   ds     r   
<listcomp>z,VertexTableLink.__init__.<locals>.<listcomp>   s#    WWW!-af55WWWr   r   )
dimensionsr   r   )r   r   r   r   r`   r   s        r   r   zVertexTableLink.__init__   sk    6))WWv?P?P?R?RSUTUSU?VWWWJ'1F#$22622222r   )
r   r=   r>   r?   r2   Listr\   r   r   rD   rE   s   @r   rZ   rZ      s^         
  UZ+++N3 3 3 3 3 3 3 3 3r   rZ   c                       e Zd ZdZdZdS )RectanglesTableLinkz0
    Links a Rectangles element to a Table.
    TNrU   r	   r   r   rc   rc      rX   r   rc   )r   collectionsr   r2   	core.utilr   Parameterizedr   rG   rT   rW   rZ   rc   r	   r   r   <module>rg      sM    # # # # # #  + + + + + +O) O) O) O) O)5 O) O) O)d    D   0    t       D   3 3 3 3 3d 3 3 3"    $     r   