
    	/gO	                       d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlZddlZddlZd	d
lmZ d	dlmZ eeegej2                  Zg dZ G d d      Zed        Zd 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% 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* G d' d(e       Z+ G d) d*e+      Z, G d+ d,e+      Z- G d- d.e+      Z. G d/ d0e.      Z/ G d1 d2e.      Z0 G d3 d4e.      Z1 G d5 d6e+      Z2 G d7 d8e.      Z3 G d9 d:e.      Z4 G d; d<e.      Z5 G d= d>e.      Z6 G d? d@e.      Z7 G dA dBe+      Z8 G dC dDe+      Z9 G dE dFe+      Z: G dG dHe+      Z; G dI dJe+      Z< G dK dLe+      Z= G dM dNe+      Z> G dO dPe=      Z? G dQ dRe+      Z@ G dS dTe+      ZA G dU dVe+      ZB G dW dXe+      ZC G dY dZe+      ZD G d[ d\eD      ZE G d] d^eE      ZF G d_ d`eD      ZG G da dbeD      ZH G dc ddeD      ZI G de dfeG      ZJdg ZKej                  j                  eK       y)hz
The streams module defines the streams API that allows visualizations to
generate and respond to events, originating either in Python on the
server-side or in Javascript in the Jupyter notebook (client-side).
    N)defaultdict)contextmanager)partial)groupby)Number)FunctionType   )util)UniformNdMapping)	top_righttop_leftbottom_leftbottom_rightrightlefttopbottomc                       e Zd Zy)_SkipTriggerN)__name__
__module____qualname__     1lib/python3.12/site-packages/holoviews/streams.pyr   r   $   s    r   r   c              #   t   K   | D ]	  }d|_          	 d | D ]	  }d|_          y# | D ]	  }d|_          w xY ww)aV  
    Temporarily declares the streams as being in a triggered state.
    Needed by DynamicMap to determine whether to memoize on a Callable,
    i.e. if a stream has memoization disabled and is in triggered state
    Callable should disable lookup in the memoization cache. This is
    done by the dynamicmap_memoization context manager.
    TNF)_triggering)streamsstreams     r   triggering_streamsr    '   sF      ! 'F!&F gF!&F s   8% 858c                    i }| j                         D ]^  \  }}t        j                  j                  |      }t	        |t        j
                        r|j                  |||<   Qt        d|d       t        j                  |      S )z1Converts a streams dictionary into a streams listzCannot handle value z in streams dictionary)
itemsparamparameterizedtransform_reference
isinstance	Parameterowner	TypeErrorParamsfrom_params)r   paramskvs       r   streams_list_from_dictr/   9   sz    F133A6a)agg.AF1I21%7MNOO   f%%r   c                   @    e Zd ZdZ ej
                         Z ee      Z	e
d        Ze
d        Zd Ze
d        Z	 	 d fd	Zd Zed        Zdd	Zd
 ZddZd Zd Zed        Zej2                  d        Zd Zed        Zed        Zd Zd Zd Zd Z d Z! xZ"S )Streama,  
    A Stream is simply a parameterized object with parameters that
    change over time in response to update events and may trigger
    downstream events on its subscribers. The Stream parameters can be
    updated using the update method, which will optionally trigger the
    stream. This will notify the subscribers which may be supplied as
    a list of callables or added later using the add_subscriber
    method. The subscribers will be passed a dictionary mapping of the
    parameters of the stream, which are available on the instance as
    the ``contents``.

    Depending on the plotting backend certain streams may
    interactively subscribe to events and changes by the plotting
    backend. For this purpose use the LinkedStream baseclass, which
    enables the linked option by default. A source for the linking may
    be supplied to the constructor in the form of another viewable
    object specifying which part of a plot the data should come from.

    The transient option allows treating stream events as discrete
    updates, resetting the parameters to their default after the
    stream has been triggered. A downstream callback can therefore
    determine whether a stream is active by checking whether the
    stream values match the default (usually None).

    The Stream class is meant for subclassing and subclasses should
    generally add one or more parameters but may also override the
    transform and reset method to preprocess parameters before they
    are passed to subscribers and reset them using custom logic
    respectively.
    c                    dt        j                  |      i}|j                         D ]  \  }}t        |d      }t	        |t         j
                        r|||<   4t	        |t              rt        j                  di |||<   ]t	        |t              rt        j                  di |||<   t	        |t              rt        j                  di |||<   t	        |t              rt        j                  di |||<   t	        |t              rt        j                  di |||<   t	        |t              rt        j                  di |||<   ,t	        |t               rt        j"                  di |||<   Vt	        |t$        j&                        rt        j(                  di |||<   t        j
                  di |||<    t+        |t,        f|      S )a6  
        Utility to quickly and easily declare Stream classes. Designed
        for interactive use such as notebooks and shouldn't replace
        parameterized class definitions in source code that is imported.

        Takes a stream class name and a set of keywords where each
        keyword becomes a parameter. If the value is already a
        parameter, it is simply used otherwise the appropriate parameter
        type is inferred and declared, using the value as the default.

        Supported types: bool, int, float, str, dict, tuple and list
        name)defaultTr4   constantr   )r#   Stringr"   dictr&   r'   boolBooleanintIntegerfloatr   strDicttupleTuplelistListnpndarrayArraytyper1   )clsr3   kwargsr,   r-   r.   kwss          r   definezStream.defineo   sr    %,,t45LLNDAqq40C!U__-q	At$!MM0C0q	As#!MM0C0q	Au%!LL/3/q	As#!LL/3/q	At$!JJ--q	Au%!KK.#.q	At$!JJ--q	Arzz*!KK.#.q	!OO2c2q	+ #0 D6)V,,r   c           	         t        |      D cg c]  }|j                  j                          }}|D cg c]  }|D ]  }|  }}}|D cg c]  \  }}|	 }	}}g }
|D ]L  \  }}|	j                  |      }	 |j                  ||f      }|dkD  s1||kD  s7||
vs<|
j                  |       N |
rt        d|
       t        t              }|D ]:  }|j                          |j                  D ]  \  }}||   j                  |        < t        |j                         d       }t        j                  |D cg c]  \  }}|D ]  }|  c}}}      }t        |      5  |D ]  } |di t        |        	 ddd       |D ]<  }t        j                   |      5  |j"                  r|j%                          ddd       > yc c}w c c}}w c c}}w # t        $ r d}Y ]w xY wc c}}}w # 1 sw Y   uxY w# 1 sw Y   xY w)aC  
        Given a list of streams, collect all the stream parameters into
        a dictionary and pass it to the union set of subscribers.

        Passing multiple streams at once to trigger can be useful when a
        subscriber may be set multiple times across streams but only
        needs to be called once.
        r	   z Parameter name clashes for keys c                     | d   S Nr   r   xs    r   <lambda>z Stream.trigger.<locals>.<lambda>   s    QRSTQUr   keyNr   )setcontentsr"   count	Exceptionappendprintr   rB   _on_trigger_subscriberssortedr
   unique_iteratorr    r8   disable_constant	transientreset)rH   r   r   r"   kvskvunionr-   _klistkey_clashesr.   	key_countvalue_countsubscriber_precedence
precedence
subscribersorted_subscriberssubscribersss                       r   triggerzStream.trigger   s    8;7|D|V&&(|D$3ussu3$%utq!u%DAqAI #kk1a&1 1}[!8Qk=Q""1%  4[ODE !,D 1F *0*=*=&
J%j188D +>  $$9$?$?$A~V**DV ,BDV.![5@ -.5@ -.DV ,B C  ()
)T%[) * ) F&&v.##LLN /. ? E3%     ,B )(
 /.s@   !G
GG9G?G-&G4"H G*)G*4G= H		c                      y)z'Called when a stream has been triggeredNr   selfs    r   rZ   zStream._on_trigger   s    r   c           
         t        t              }g g }}|D ]  }t        |t              r|j                  }t        |t
              rnt        |t        j                        r#t        |j                  |j                  g      }nMt        |t        j                        rt        |      }n&t        j                  |      rt        |d      st        |      }nt        |t               rt        |d      r|j"                  }t%        |d         t%        |j'                  di       j)                               z   }|j'                  di       j+                         D 	ci c]  \  }}	|	j                  |	j                  f|  }
}}	t        ||
      }nAt        j,                  j/                  |      }|rt        |      }n|j1                  |       t        |t              rt3        |j,                        }t        |j4                        ||   z  }|rpt7        |j,                        j8                  }t        j:                  j                  j=                  dt?        |D 	cg c]  }	|	j                   c}	       d| d       ||xx   t        |j4                        z  cc<   |j1                  |        ||fS c c}	}w c c}	w )	zy
        Processes a list of streams promoting Parameterized objects and
        methods to Param based streams.
        _dinfodependencieskw)
parametersrename)rw   zThe z parameter(s) on the z object have already been supplied in another stream. Ensure that the supplied streams only specify each parameter once, otherwise multiple events will be triggered when the parameter changes.) r   rT   r&   r   funcr1   r#   r'   r*   r(   r3   Parameterizedr
   is_param_methodhasattrParamMethodr   rt   rB   getvaluesr"   r$   resolve_refrX   idrw   rG   r   mainwarningr\   )rH   r   parameterizedsvalidinvalidrn   deps
dep_paramsr-   prx   pidoverlappnames                 r   _process_streamszStream._process_streams   s?    %S)RwA!W%FF!V$Au/177QVVH-Au2231I%%a(q(+NA|,H1Exx!$~"67$txxb?Q?X?X?Z:[[
;?88D";M;S;S;UV;U41a177AFF+Q.;UVj@**66q9$/ANN1%!V$)q||,~c/BB 1::EJJ$$,,vw&?w!qvvw&?@A B""' )OO s#s1<<'88#LLOO P g~1 W '@s   #J< Kc                    |g }|i }|dnt        j                  |      | _        g | _        |D ]  }| j	                  |        || _        || _        d| _        i | _        t        | (  di | | j                  |      | _        |>|| j                  v r| j                  |   j                  |        y| g| j                  |<   yy)a  
        The rename argument allows multiple streams with similar event
        state to be used by remapping parameter names.

        Source is an optional argument specifying the HoloViews
        datastructure that the stream receives events from, as supported
        by the plotting backend.

        Some streams are configured to automatically link to the source
        plot, to disable this set linked=False
        NFr   )weakrefref_sourcer[   add_subscriberlinkedr_   r   	_metadatasuper__init___validate_rename_renameregistryrX   )	rr   rx   sourcerm   r   r_   r,   rk   	__class__s	           r   r   zStream.__init__   s     K>F%~t7;;v3F%J
+ & " !
 "6",,V4&f%,,T2)-f%	 r   c                 8     t        |       di | j                  S )z>Return new stream with identical properties and no subscribersr   )rG   rU   rq   s    r   clonezStream.clone,  s    tDz*DMM**r   c                 d    t        | j                  d       D cg c]  \  }}|	 c}}S c c}}w )z&Property returning the subscriber listc                     | d   S rN   r   rO   s    r   rQ   z$Stream.subscribers.<locals>.<lambda>3  s    adr   rR   )r\   r[   )rr   r   rn   s      r   rm   zStream.subscribers0  s/     %T%6%6NKLKdaKLLLs   ,c                 &   g d}||vrt        d|       |dk(  r
g }|| _        y|dk(  r.| j                  D cg c]  \  }}|dkD  s||f }}}|| _        y| j                  D cg c]  \  }}|dk  s||f }}}|| _        yc c}}w c c}}w )az  
        Clear all subscribers registered to this stream.

        The default policy of 'all' clears all subscribers. If policy is
        set to 'user', only subscribers defined by the user are cleared
        (precedence between zero and one). A policy of 'internal' clears
        subscribers with precedence greater than unity used internally
        by HoloViews.
        )alluserinternalz/Policy for clearing subscribers must be one of r   r   r	   N)
ValueErrorr[   )rr   policypolicies	remainingr   rn   s         r   clearzStream.clear6  s     /!NxjYZZU?I
 &	 v.2.?.?I.?FQ1q5!Q.?II & /3.?.?J.?FQ16!Q.?IJ% JJs   BB(B6Bc                     t        j                  |       5  | j                  j                  d      j	                         D ]"  \  }}|dk7  st        | ||j                         $ 	 ddd       y# 1 sw Y   yxY w)z=
        Resets stream parameters to their defaults.
        existingr3   N)r
   r^   r#   objectsr"   setattrr4   )rr   r-   r   s      r   r`   zStream.resetL  s[     ""4(

**:6<<>1;D!QYY/ ? )((s   5A/A//A8c                 j    t        |      st        d      | j                  j                  ||f       y)a  
        Register a callable subscriber to this stream which will be
        invoked either when event is called or when this stream is
        passed to the trigger classmethod.

        Precedence allows the subscriber ordering to be
        controlled. Users should only add subscribers with precedence
        between zero and one while HoloViews itself reserves the use of
        higher precedence values. Subscribers with high precedence are
        invoked later than ones with low precedence.
        zSubscriber must be a callable.N)callabler)   r[   rX   )rr   rk   rj   s      r   r   zStream.add_subscriberV  s1     
#<==  *j!9:r   c                     | j                   D cg c]
  }|dk7  s	| }}|j                         D ]1  \  }}||vrt        d|d      ||k7  s||v s$t        d|d       |S c c}w )Nr3   Cannot rename   as it is not a stream parameterCannot rename to 7 as it clashes with a stream parameter of the same name)r#   r"   KeyError)rr   mappingr-   param_namesr.   s        r   r   zStream._validate_renameg  s    "&**<*QVq*<MMODAq#u4TUVVAv!{*!21% 8C  C D D	 $  =s
   
A&A&c                    | j                   j                         j                         D ci c]  \  }}|dk7  s|| }}} | j                  d|| j                  r| j	                         nd| j
                  d|S c c}}w )z
        The rename method allows stream parameters to be allocated to
        new names to avoid clashes with other stream parameters of the
        same name. Returns a new clone of the stream instance with the
        specified name mapping.
        r3   N)rx   r   r   r   )r#   r   r"   r   r   r   )rr   r   r-   r.   r,   s        r   rx   zStream.renamer  s~     $(::#4#4#6#<#<#>N#>41a!v+!Q$#>Nt~~ <W8<dlln$%)[[<4:< 	< Os
   A>A>c                 >    | j                   r| j                         S d S N)r   rq   s    r   r   zStream.source~  s    !%t||~747r   c                    | j                   U| j                  | j                      }| |v r|j                  |        |s%| j                  j                  | j                          |d | _        y t        j                  |      | _        || j                  v r| j                  |   j                  |        y | g| j                  |<   y r   )r   r   removepopr   r   r   rX   )rr   r   source_lists      r   r   zStream.source  s    ;;"--4K{"""4(!!$++.>DL{{6*T]]"MM&!((.%)FDMM&!r   c                     i S )z
        Method that can be overwritten by subclasses to process the
        parameter values before renaming is applied. Returns a
        dictionary of transformed parameters.
        r   rq   s    r   	transformzStream.transform  s	     	r   c                 P   | j                   j                         j                         D ci c]  \  }}|dk7  s|| }}}|j                         D ci c]>  \  }}| j                  j	                  |d      | j                  j	                  ||      |@ c}}S c c}}w c c}}w )Nr3   T)r#   r   r"   r   r~   )rr   r-   r.   filtereds       r   rU   zStream.contents  s    %)ZZ%6%6%8%>%>%@P%@TQAKAqD%@P8@8H :8Hfq!<<##At,8   A&)8H : 	: Q:s   BBAB"c                     | j                   S )z
        The object the memoization hash is computed from. By default
        returns the stream contents but can be overridden to provide
        a custom hash key.
        )rU   rq   s    r   hashkeyzStream.hashkey  s     }}r   c                     t        j                  |       5   | j                  j                  di | ddd       y# 1 sw Y   yxY w)z`
        Sets the stream parameters which are expected to be declared
        constant.
        Nr   )r
   r^   r#   update)rr   rI   s     r   _set_stream_parameterszStream._set_stream_parameters  s5    
 ""4(DJJ'' )((s	   <Ac                 ^     | j                   di |}|t        ur| j                  | g       yy)zD
        Update the stream parameters and trigger an event.
        Nr   )r   r   ro   )rr   rI   skips      r   eventzStream.event  s2     t{{$V$|#LL$  $r   c                 |     | j                   di | | j                         }|t        S  | j                   di | y)a5  
        The update method updates the stream parameters (without any
        renaming applied) in response to some event. If the stream has a
        custom transform method, this is applied to transform the
        parameter values accordingly.

        To update and trigger, use the event method.
        Nr   )r   r   r   )rr   rI   transformeds      r   r   zStream.update  sB     	$##-f-nn&###2k2r   c                     | j                   j                  }dj                  d | j                  j	                         j                         D              }| j                  s| d| dS | d| j                  d| dS )N,c              3   :   K   | ]  \  }}|d k7  r	| d|  yw)r3   =Nr   ).0r-   r.   s      r   	<genexpr>z"Stream.__repr__.<locals>.<genexpr>  s-      T(Cfq!qF{ Cq,(C   ()z, )r   r   joinr#   r   r"   r   )rr   cls_namerI   s      r   __repr__zStream.__repr__  s}    >>** T(,

(9(9(;(A(A(CT T||Zq**Zq 06(!<<r   c                     t        |       S r   )reprrq   s    r   __str__zStream.__str__  s    Dzr   )NNNFF)r   )r   )#r   r   r   __doc__r   WeakKeyDictionaryr   r   r8   
_callbacksclassmethodrK   ro   rZ   r   r   r   propertyrm   r   r`   r   r   rx   r   setterr   rU   r   r   r   r   r   r   __classcell__r   s   @r   r1   r1   E   s!   D )w((*H T"J &- &-R ,# ,#^6 / /d KP */X+ M M
&,0;"
< 8 8 ]]+ +& : :
  (!3=r   r1   c                   @    e Zd ZdZ ej
                  ddd      Zd Zy)Counterzp
    Simple stream that automatically increments an integer counter
    parameter every time it is updated.
    r   T)r   N)r4   r6   boundsc                 $    d| j                   dz   iS )Ncounterr	   )r   rq   s    r   r   zCounter.transform  s    4<<!+,,r   N)r   r   r   r   r#   r<   r   r   r   r   r   r   r     s"    
 emmAYGG-r   r   c                   j     e Zd ZdZ ej
                  ddd      Zd
 fd	Zd Zd Z	e
d	        Z xZS )Pipez
    A Stream used to pipe arbitrary data to a callback.
    Unlike other streams memoization can be disabled for a
    Pipe stream (and is disabled by default).
    NT@
        Arbitrary data being streamed to a DynamicMap callback.r4   r6   docc                 6    t        |   dd|i| d| _        y )Ndatar   r   )r   r   _memoize_counter)rr   r   memoizer,   r   s       r   r   zPipe.__init__  s     -d-f- !r   c                 (    | j                  |       y)zf
        A convenience method to send an event with data without
        supplying a keyword.
        )r   N)r   )rr   r   s     r   sendz	Pipe.send  s    
 	


r   c                 .    | xj                   dz  c_         y Nr	   r   rq   s    r   rZ   zPipe._on_trigger  s    "r   c                     d| j                   iS )N_memoize_keyr   rq   s    r   r   zPipe.hashkey  s     5 566r   )NF)r   r   r   r   r#   r'   r   r   r   rZ   r   r   r   r   s   @r   r   r     sH     5??4$ =C DD"# 7 7r   r   c                   z     e Zd ZdZ ej
                  ddd      Zd fd	Zd Zd Z	d	 Z
 fd
Zed        Z xZS )Buffera  
    Buffer allows streaming and accumulating incoming chunks of rows
    from tabular datasets. The data may be in the form of a pandas
    DataFrame, 2D arrays of rows and columns or dictionaries of column
    arrays. Buffer will accumulate the last N rows, where N is defined
    by the specified ``length``. The accumulated data is then made
    available via the ``data`` parameter.

    A Buffer may also be instantiated with a streamz.StreamingDataFrame
    or a streamz.StreamingSeries, it will automatically subscribe to
    events emitted by a streamz object.

    When streaming a DataFrame will reset the DataFrame index by
    default making it available to HoloViews elements as dimensions,
    this may be disabled by setting index=False.

    The ``following`` argument determines whether any plot which is
    subscribed to this stream will update the axis ranges when an
    update is pushed. This makes it possible to control whether zooming
    is allowed while streaming.
    NTr   r   c                 l   t        |t        j                        r|}n-t        |t        j                        r|j
                  dk7  rt        d      |}nt        |t              rlt        d |j                         D              st        d      t        |j                         D ch c]  }t        |       c}      dkD  rt        d      |}nz	 ddlm}m}	 d	}
|
rt        |	f      st        d      t        ||	      r|j!                         }|j"                  }|j$                  j'                  | j(                         || _        ||d<   t-        | \  di | || _        || _        d| _        d| _        || _        y c c}w # t        $ r  	 dd
lm}m}	 d	}
n# t        $ r d}
Y nw xY wY w xY w)N   z-Only 2D array data may be streamed by Buffer.c              3   P   K   | ]  }t        |t        j                           y wr   )r&   rD   rE   )r   r.   s     r   r   z"Buffer.__init__.<locals>.<genexpr>(  s     H-Qz!RZZ0-s   $&z*Data in dictionary must be of array types.r	   z2Columns in dictionary must all be the same length.r   )StreamingDataFrameStreamingSeriesT)	DataFrameSeriesFzhBuffer must be initialized with pandas DataFrame, streamz.StreamingDataFrame or streamz.StreamingSeries.r   r   )r&   pdr   rD   rE   ndimr   r8   r   r   lenstreamz.dataframer   r   ImportErrorr   to_frameexampler   sinkr   sdfr   r   length	following_chunk_length_count_index)rr   r   r
  indexr  r,   r  r.   r   r   loadedr   s              r   r   zBuffer.__init__   s   dBLL)Gbjj)yyA~ !PQQGd#H$++-HH !MNNdkkm4mc!fm459 !UVVG#Q D3E2W!X  "Z [ [D/2}}llGKKTYY'DH v"6""? 5  ## "F" #"F##s<   )F
F
 
	F3
FF3F-*F3,F--F32F3c           	         t              t        | j                        k7  rBt        dt        | j                        j                   dt              j                   d      t	        t
        j                        rzj                  dk7  rt        d      j                  d   | j                  j                  d   k7  r6t        d| j                  j                  d    dj                  d    d      yt	        t        j                        rvt        j                        t        | j                  j                        k7  rAt        d	t        | j                  j                         dt        j                               t	        t              rt!        fd
| j                  D              rIt        d	t#        | j                  j%                                dt#        j%                                      t'        j)                         D ch c]  }t'        |       c}      dkD  rt        d      yyc c}w )z@ Verify consistency of dataframes that pass through this stream zInput expected to be of type z, got .r   z+Streamed array data must be two-dimensionalr	   z%Streamed array data expected to have z columns, got zInput expected to have columns c              3   &   K   | ]  }|v 
 y wr   r   )r   crP   s     r   r   z Buffer.verify.<locals>.<genexpr>Y  s     1y!1A:ys   z7Input columns expected to have the same number of rows.N)rG   r   r)   r   r&   rD   rE   r  r   shaper  r   rB   columns
IndexErrorr8   anyr\   keysr  r   )rr   rP   r.   s    ` r   verifyzBuffer.verifyL  s   7d499o%;DO<T<T;UU[\`ab\c\l\l[mmnopp2::&vv{ !NOOtyyq11 #HYZI[H\ ](()
|1"6 7 7 2 2<<(T!))_TYYEVEV@W-W>tDIIDUDU?V>WW]^bcdclcl^m]nopp4 1tyy11 #B6$))..JZC[B\\bcijkjpjpjrcsbt!uvvahhj1jc!fj12Q6  "8 9 9 7 ! 2s   I c                    t        | j                  t        j                        r| j                  ddddf   }nt        | j                  t        j
                        r| j                  j                  dd }nJt        | j                  t              r0| j                  j                         D ci c]  \  }}||dd  }}}t        j                  |       5  | _        ddd       | j                         yc c}}w # 1 sw Y   !xY w)zClears the data in the streamNr   )r&   r   rD   rE   r  r   ilocr8   r"   r
   r^   r   )rr   r   r-   r.   s       r   r   zBuffer.clear`  s    dii,99QU#D		2<<099>>"1%D		4()-):;):AAq!uH):D;""4(DI )		$ <((s   0C:D  D	c                 $   t        |t        j                        rt        |      }| j                  s#t        j
                  | j                  |g      }n4|| j                  k  r6| j                  | j                  |z
   d }t        j
                  ||g      }n|| j                  kD  r|| j                   d }nt        |t        j                        rt        |      }| j                  s#t        j                  | j                  |g      }ny|| j                  k  r@| j                  j                  | j                  |z
   d }t        j                  ||g      }n*|| j                  kD  r|j                  | j                   d }nt        |t              r|rt        t        t        |j                                           }i }|j                         D ]  \  }}| j                  s(t        j
                  | j                  |   |g      ||<   :|| j                  k  r;| j                  |   | j                  |z
   d }t        j
                  ||g      ||<   || j                  kD  r|| j                   d ||<   |||<    |}| _        |S )z^
        Concatenate and slice the accepted data types to the defined
        length.
        N)r&   rD   rE   r  r
  concatenater   r  r   concatr  r8   nextiterr   r"   r  )rr   r   data_length
prev_chunknew_datar-   r.   s          r   _concatzBuffer._concatm  s   
 dBJJ'd)K;;~~tyy$&78t{{*!YY[)@'A'BC
~~z4&89t{{*T[[LM*bll+d)K;;yy$))T!23t{{*!YY^^dkk+.E,F,GH
yy*d!34t{{*yy$++/d#d4#678KH

1{{"$..$))A,1B"CHQK 4;;.!%1K0G.H.I!JJ"$..*a"AHQK 4;;."#T[[LM"2HQK"#HQK % D(r   c                     |j                  d      }|:| j                  |       | j                  |      |d<   | xj                  dz  c_        t	        |   di |S )zU
        Overrides update to concatenate streamed data up to defined length.
        r   r	   r   )r~   r  r%  r  r   r   )rr   rI   r   r   s      r   r   zBuffer.update  sW     zz&!KK!\\$/F6NKK1Kw~'''r   c                 6    d| j                   | j                  fiS )Nhash)r  r   rq   s    r   r   zBuffer.hashkey  s    d&;&;<==r   )i  TT)r   r   r   r   r#   r'   r   r   r  r   r%  r   r   r   r   r   s   @r   r   r     sT    , 5??4$ =C DD)X9(
&R	( > >r   r   c                       e Zd ZdZ ej
                  ej                  ej                  j                  fdddd      Z ej                  g dd      Z
d fd	Zd	 Zed
        Zd Zd Zd Zed        Zd Zd Zed        Z xZS )r*   z
    A Stream that watches the changes in the parameters of the supplied
    Parameterized objects and triggers when they change.
    TF?
        Parameterized instance to watch for parameter changes.)class_r6   
allow_None
allow_refsr   2
        Parameters on the parameterized to watch.r   c                    |-|j                   D cg c]  }|dk7  s	|j                   |    }}n8|D cg c]-  }t        |t         j                        r|n|j                   |   / }}d|v rsi }|D cg c]  }|j                   }}|d   j	                         D ]=  \  }	}
t        |	t
              r|
||	<   |j                  |D ci c]  }||	f|
	 c}       ? ||d<   d|vrD|D ]?  }t        |j                  t        t        f      s$|j                  j                  s;d|d<   A || _
        t        | 0  d	||d| d| _        g | _        g | _        |rd }t!        t#        ||      |      D ]v  \  }}t%        |      }|d   j                  j                   j'                  | j(                  |D cg c]  }|j*                   c}      }| j                  j-                  |       x y y c c}w c c}w c c}w c c}w c c}w )
Nr3   rx   r   T)r$   rw   r   c                 ,    t        | j                        S r   r   r(   rO   s    r   rQ   z!Params.__init__.<locals>.<lambda>  s    bkr   rR   r   )r#   r&   r'   r(   r"   r@   r   LinkedStreamr*   r   _watch_onlyr   r   r   _events	_watchersr   r\   rB   watch_watcherr3   rX   )rr   r$   rw   r6  
watch_onlyr,   r   rx   ownersr-   r.   okeyfnrd   groupwatcherr   s                   r   r   zParams.__init__  s
   :G:M:M]:MQQRV\Q\---a0:MJ] $./#-a  *!U__=!=CVCVWXCYY#-  / vF'12z!aggzF2x(..01a' !F1IMMf"=fAq619f"=>	 1
  &F86!aggf'=>177>>'+F8$   &V}VvV !)E#F:5$AuM5U(....44T]]UZD[UZPQQVVUZD[\%%g. N 3 ^/
 3
 #>$ E\s!   
G.G.2G33G8G=
5Hc                     | j                   D ]'  }|j                  j                  j                  |       ) | j                   j	                          y)zStop watching parameters.N)r5  instr#   unwatchr   )rr   r=  s     r   r@  zParams.unwatch  s8    ~~GLL&&w/ &r   c                 r   d }g }t        t        |j                         |      |      D ]}  \  }}t        |      }t	        d |D              }|&|D cg c]  \  }}|j
                   }	}}|D 
ci c]  \  }
}|j
                  |
 }}
}|j                   | ||	fd|i|        |S c c}}w c c}}
w )zReturns Params streams given a dictionary of parameters

        Args:
            params (dict): Dictionary of parameters

        Returns:
            List of Params streams
        c                 2    t        | d   j                        S r   r1  rO   s    r   rQ   z$Params.from_params.<locals>.<lambda>  s    2adjj>r   rR   c              3   :   K   | ]  \  }}|j                     y wr   )r(   )r   rd   r   s      r   r   z%Params.from_params.<locals>.<genexpr>  s     2EDAqEr   rx   )r   r\   r"   rB   r   r3   rX   )rH   r,   rI   key_fnr   rd   r<  r?  r   namesnrx   s               r   r+   zParams.from_params  s     *v||~6 BFKHAuKE2E22D|(-.1QVVE.,12EDAqaffaiEF2NN3tUD6DVDE L  /2s   B-4B3c                    | j                   D cg c]  }|j                   }}|j                         D ]H  \  }}t        |t              r|d   n|}||vrt        d|d      ||k7  s6||v s;t        d|d       |S c c}w )Nr	   r   r   r   r   )rw   r3   r"   r&   r@   r   )rr   r   r   pnamesr-   r.   rF  s          r   r   zParams._validate_rename  s    "&//2/Q!&&/2MMODAq"1e,!!Au4TUVVAv!v+!21% 8C  C D D $  3s   Bc                 p    	 t        |      | _        | j                  | g       g | _        y # g | _        w xY wr   )rB   r4  ro   )rr   eventss     r   r7  zParams._watcher   s/    	<DLLL$ DL2DLs   ", 	5c                 h    t        d | j                  D              r| xj                  dz  c_        y y )Nc              3   :   K   | ]  }|j                   d k(    yw)	triggeredN)rG   )r   es     r   r   z%Params._on_trigger.<locals>.<genexpr>  s     ;lqvv$lr   r	   )r  r4  r   rq   s    r   rZ   zParams._on_trigger  s*    ;dll;;!!Q&! <r   c                    i }| j                   D ]  }|j                  |j                  f}| j                  j	                  ||j                        }dj                  t        t        |j                              |g      }| j                  j	                  |d      t        |j                  |j                        ||<    | j                  |d<   |S )N Tr   )
rw   r(   r3   r   r~   r   r>   r   getattrr   )rr   r   r   pkeyr   rS   s         r   r   zParams.hashkey  s    AGGQVV$DLL$$T1662E((C177,e45C||d+7&qww7 ! #'"7"7r   c                      y r   r   rq   s    r   r`   zParams.reset  s    r   c                    | j                   rt        t              }| j                   j                         D ]  \  \  }}}||v s||   ||   |<    |j                         D ]D  \  }}t	        |t
              r |j                  di | ) |j                  j                  di | F y t	        | j                  t
              r | j                  j                  di | y  | j                  j                  j                  di | y Nr   )	r   r   r8   r"   r&   r1   r   r#   r$   )rr   rI   owner_updatesr(   r   rnameupdatess          r   r   zParams.update  s    <<'-M)-););)=%F?28-M%(/ *> #0"5"5"7weV, ELL+7+&EKK&&11	 #8
 **F3%D%%//+D$$++5f5r   c           	         | j                   ri S | j                  D ci c]9  }|j                  |j                  ft	        |j                  |j                        ; }}|j                         D ci c]E  \  \  }}}| j                  j                  ||fd      | j                  j                  ||f|      |G c}}}S c c}w c c}}}w NT)r3  rw   r(   r3   rQ  r"   r   r~   )rr   r   r   r:  rF  r.   s         r   rU   zParams.contents+  s    IIMYAQWWaff%wqww'??Y@H@P ?@P96Aq1<<##QFD1=   !Q+Q.@P ? 	? Z?s   >C 1A
C)NNTF)r   r   r   r   r#   ClassSelectorrz   r$   ParameterizedMetaclassrC   rw   r   r@  r   r+   r   r7  rZ   r   r   r`   r   rU   r   r   s   @r   r*   r*     s    
 (E''0C0C050C0C0Z0Z0\15$SX _BCM
 B <5 6J!/F  *	' 	 	6" ? ?r   r*   c                        e Zd ZdZ ej
                  ej                  ej                  j                  fddd      Z ej                  g dd      Z
d fd	Z xZS )	r}   z
    A Stream that watches the parameter dependencies on a method of
    a parameterized class and triggers when one of the parameters
    change.
    Tr*  )r+  r6   r,  r   r.  r   c                 V   t        j                  |      s"t        dt        |      j                   d      |}t        j
                  |      }|s<|j                  j                  |j                        D cg c]  }|j                   }}d|d<   t        | (  |||fi | y c c}w )NzDParamMethod stream expects a method on a parameterized class, found r  Tr8  )r
   r{   r   rG   r   get_method_ownerr#   method_dependenciespobjr   r   )rr   r$   rw   r6  r,   methodr   r   s          r   r   zParamMethod.__init__D  s    ##M2 ;;?;N;W;W:XXY[ \ \--m<*7*=*=*Q*QRXRaRa*bc*bQ!&&*bJc#|
EDVD ds   9B&rZ  )r   r   r   r   r#   r[  rz   r$   r\  rC   rw   r   r   r   s   @r   r}   r}   5  sm     (E''0C0C050C0C0Z0Z0\15$ MBCM
 B <5 6J
E 
Er   r}   c                   h     e Zd ZdZd fd	Zd Zd Zd Zd Ze	d        Z
d Zed	        Zd
 Z xZS )Derivedz
    A Stream that watches the parameters of one or more input streams and produces
    a result that is a pure function of the input stream values.

    If exclusive=True, then all streams except the most recently updated are cleared.
    c                     t        |   di | g | _        t               | _        | j                  |       || _        | j                          y rU  )r   r   input_streamsrT   	_updating_register_streams	exclusiver   )rr   rf  ri  r,   r   s       r   r   zDerived.__init__X  sB    "6"}-"r   c                 4    |D ]  }| j                  |        y)zJ
        Register callbacks to watch for changes to input streams
        N_register_stream)rr   r   r   s      r   rh  zDerived._register_streams`  s     F!!&) r   c                      t         j                        }|f fd	}|j                  |        j                  j                  |       y )Nc                    | j                   v ry j                  rzt        j                        D ]b  \  }}| |k7  s|j	                          j                   j                  |       	 |j                          j                   j                  |       d j                          y # j                   j                  |       w xY wr   )rg  ri  	enumeraterf  r`   addr   r   )stream_indexrI   jinput_streamrr   s       r   perform_updatez0Derived._register_stream.<locals>.perform_updatej  s    t~~- ~~'01C1C'DOA|#q($**,**1-5(..0 NN11!4 (E JJL !NN11!4s   *B((C)r  rf  r   rX   )rr   r   irt  s   `   r   rl  zDerived._register_streamg  s?    ""#() 	  	n-!!&)r   c                     | j                   D ]  }d|_        |j                           | j                   j                          y)zT
        Unregister callbacks on input streams and clear input streams list
        N)rf  r   r   rr   r   s     r   _unregister_input_streamsz!Derived._unregister_input_streams}  s8     ((F FMLLN ) 	  "r   c                 &    | j                  |       y)z(
        Add a new input stream
        Nrk  rw  s     r   append_input_streamzDerived.append_input_stream  s     	f%r   c                     i S )aq  
        Dict of constants for this instance that should be passed to transform_function

        Constant values must not change in response to changes in the values of the
        input streams. They may, however, change in response to other stream property
        updates. For example, these values may change if the Stream's source element
        changes
        r   rq   s    r   	constantszDerived.constants  s	     	r   c                     | j                   D cg c]  }|j                   }}| j                  || j                        S c c}w r   )rf  rU   transform_functionr|  )rr   rn   stream_valuess      r   r   zDerived.transform  s?    -1-?-?@-?-?@&&}dnnEE As   A c                     t         )a  
        Pure function that transforms input stream param values into the param values
        of this Derived stream.

        Args:
            stream_values: list of dict
                Current values of the stream params for each input_stream
            constants: dict
                Constants as returned by the constants property of an instance of this
                stream type.

        Returns: dict
            dict of new Stream values where the keys match this stream's params
        )NotImplementedError)rH   r  r|  s      r   r~  zDerived.transform_function  s
      "!r   c                 $    | j                          y r   )rx  rq   s    r   __del__zDerived.__del__  s    &&(r   )F)r   r   r   r   r   rh  rl  rx  rz  r   r|  r   r   r~  r  r   r   s   @r   rd  rd  Q  sT    **,#& 	 	F " "")r   rd  c                   b     e Zd ZdZ ej
                  dd      Z fdZd Zd Z	d Z
d	 Z xZS )
HistoryzR
    A Stream that maintains a history of the values of a single input stream
    TzB
        List containing the historical values of the input streamr6   r   c                     t        |   di | || _        | j                          | j                  j	                          y rU  )r   r   rs  _register_input_streamr   )rr   rs  r,   r   s      r   r   zHistory.__init__  s;    "6"(##% 	!r   c                 j     t        |       | j                  j                         fi | j                  S r   )rG   rs  r   rU   rq   s    r   r   zHistory.clone  s+    tDz$++113Et}}EEr   c                 "    | j                   d d = y r   )r   rq   s    r   clear_historyzHistory.clear_history  s    KKNr   c                 F      fd} j                   j                  |       y)zH
        Register callback on input_stream to watch for changes
        c                  \    j                   j                  |        j                          y r   )r   rX   r   )rI   rr   s    r   rt  z6History._register_input_stream.<locals>.perform_update  s    KKv&JJLr   N)rs  r   )rr   rt  s   ` r   r  zHistory._register_input_stream  s    	 	((8r   c                 x    d | j                   _        | j                   j                          | j                  d d = y r   )rs  r   r   r   rq   s    r   r  zHistory.__del__  s-    #' !KKNr   )r   r   r   r   r#   rC   r   r   r   r  r  r  r   r   s   @r   r  r    s=     UZZ ,E FF"F9r   r  c                       e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Zd fd	Z	d Z
d Zed        Z fdZed	        Zed
        Zej$                  d        Z xZS )SelectionExprNTr5   c                 f   ddl m} ddlm} ddlm} |j                  dd       | _        || _        t        ||      r ||       t        ||      rt        |j                  |      s&t        ||      st        dt        |       d|       | j                  |      }t        | <  d
||dd	| y )Nr	   
DynamicMap)Element)initialize_dynamic
index_colszThe source of SelectionExpr must be an instance of an Element subclass or a DynamicMap that returns such an instance. Received value of type z: T)r   rf  ri  r   )core.spacesr  elementr  plotting.utilr  r   _index_colsinclude_regionr&   
issubclassrG   r   _build_selection_streamsr   r   )	rr   r   r  r,   r  r  r  rf  r   s	           r   r   zSelectionExpr.__init__  s    +$5!::lD9,fj)v&FJ/Jv{{G4Tfg.448L>F8M  55f= 	
$	
JP	
r   c                 N     t        |       | j                  fi | j                  S r   )rG   r   rU   rq   s    r   r   zSelectionExpr.clone  s     tDz$++777r   c                     ddl m} t        ||      r|j                  }n|}|rMg }|j                  D ]:  }t        |      }t        |t              rd |d<   |j                   |di |       < |S g S )Nr   r  )r   r  r   )holoviews.core.spacesr  r&   rG   _selection_streamsr8   Selection1DrX   )rr   r   r  element_typerf  r   rI   s          r   r  z&SelectionExpr._build_selection_streams  su    4fj)!;;L!LM&99V,fk2&*F7O$$V%5f%56	 :
 ! Ir   c                 J    | j                   | j                  | j                  dS )N)r   r  r  )r   r  r  rq   s    r   r|  zSelectionExpr.constants
  s'     kk**"11
 	
r   c                     | j                   D ].  }t        |t              s|j                  s!| j                  r. y  t
        |          S r   )rf  r&   r  r   r  r   r   rr   r   r   s     r   r   zSelectionExpr.transform  sA    ((F6;/F4F4F(( ) w ""r   c                 r   |d   }|d   }|t        d d d       S ddlm} t        ||      r|j	                         d   }n|}d }d }d }	|D ]2  }
t        |
|d         } |j
                  d	i |}| y |\  }}}	|2 n |j                  d d d   D ]  }| ||      } t        |||r|	      S d       S )
Nr   r  selection_exprbboxregion_elementr   r  r  )r  r   )r8   r  r  r&   r   $_get_selection_expr_for_stream_value_transforms)rH   r  r|  hvobjr  r  r  r  r  r  stream_valuer,   	selectionexpr_transforms                 r   r~  z SelectionExpr.transform_function  s   (#"#34=t$tMM4 eZ(llnR(GG)L,9\3JKFDDDNvNI 3<0ND.) * &11$B$7N)!/!? 8 )-;>
 	
 BF
 	
r   c                 @    t         j                  j                  |       S r   )r1   r   fgetrq   s    r   r   zSelectionExpr.sourceB  s    }}!!$''r   c                    | j                          t        j                  j                  | |       | j                  | j	                  | j                        }ng }| j                  d d d        | j                  |       y )Nr  )rx  r1   r   fsetr  r   rh  )rr   valuerf  s      r   r   zSelectionExpr.sourceF  sw     	&&( 	4' ;;" 99$++FMM 	 	 	
 	}-r   )T)r   r   r   r#   r'   r  r?   r  r  r   r   r  r   r|  r   r   r~  r   r   r   r   s   @r   r  r    s    $U__TDAN5::dT2D$U__TDAN
08" 
 
# %
 %
N ( ( ]]. .r   r  c                        e Zd Z ej                  dd      Z ej                  dd      Z	 	 d fd	Zed        Z	 fdZ
ed        Z xZS )	SelectionExprSequenceNTr5   c                     || _         || _        t        |fd|j                  d      i|}t	        |      | _        | j
                  g}t        |   d||d| y )Nr  )r   rf  r   )moder  r  r   r  history_streamr   r   )rr   r   r  r  r,   sel_exprrf  r   s          r   r   zSelectionExprSequence.__init__c  sv     	, 
%zz,7

 &h/,,- 	
	
:@	
r   c                 J    | j                   | j                  | j                  dS )Nr   r  r  r  rq   s    r   r|  zSelectionExprSequence.constantst  s%     kkII"11
 	
r   c                 \    | j                   d   j                          t        |           y rN   )rf  r  r   r`   )rr   r   s    r   r`   zSelectionExprSequence.reset|  s#    1++-r   c                 T   ddl m} |d   }|d   }|d   }d }d }|d   d   D ]o  }	|	|	d   }
|
s|	d	   }||d
k(  r|dk(  r|
 }n|
}n|dk(  r||
z  }n|dk(  r||
z  }n||
 z  }t        ||      r|j                  }n|}|j	                  |||      }q t        ||r|      S d       S )Nr	   r  r  r   r  r   r   r  r  	overwriteinverse	intersectrc   )r  r  )r  r  r&   rG   _merge_regionsr8   )rH   r  r|  r  r  r   r  combined_selection_exprcombined_region_elementselection_contentsr  r  el_types                r   r~  z(SelectionExprSequence.transform_function  s   + 8$"#34"&"&"/"28"<!)/0@AN!/0@AN '.$+2E9$/=o+.<+$'>9''>9''N?:' &*- ++ &-&<&<''#7 #=> 26D2
 	
JN
 	
r   )r  T)r   r   r   r#   r'   r  r  r   r   r|  r`   r   r~  r   r   s   @r   r  r  _  sa    $U__TDAN$U__TDAN  +
" 
 
 +
 +
r   r  c                        e Zd Z ej                  dd      Zd
 fd	Zed        Zej                  d        Zed        Z
 fdZed	        Z xZS )CrossFilterSetNTr5   c                 f    || _         || _        t        |      }|dk(  }t        |   |fd|i| y )Nr  ri  )_moder  rB   r   r   )rr   selection_streamsr  r  r,   rf  ri  r   s          r   r   zCrossFilterSet.__init__  sG    
%./K'		
%.	
28	
r   c                     | j                   S r   )r  rq   s    r   r  zCrossFilterSet.mode  s    zzr   c                 z    || j                   k7  r,|| _         | j                          | j                   dk(  | _        y y )Nr  )r  r`   ri  )rr   r.   s     r   r  zCrossFilterSet.mode  s2    

?DJJJL!ZZ;6DN r   c                 4    | j                   | j                  dS )N)r  r  )r  r  rq   s    r   r|  zCrossFilterSet.constants  s     II**
 	
r   c                 d    t         |           | j                  D ]  }|j                           y r   )r   r`   rf  r  s     r   r`   zCrossFilterSet.reset  s%    ((FLLN )r   c                    ddl m} |d   }|D cg c]  }|d   	 }}|D cg c]  }||	 }}d }t        |      dkD  r|rt        |      dkD  rt        j                  d |D         }	|d   }
 |d      }|
j
                  |_        t        |
j                        |_        t        |j                  d   t        |	      f	      |j                  d<   n|d   }|dd  D ]  }||z  }	 t        |
      S c c}w c c}w )Nr	   )dimr  r  r   c              3   X   K   | ]"  }t        |j                  d    d   d          $ yw)r   argsr   N)rT   ops)r   exprs     r   r   z4CrossFilterSet.transform_function.<locals>.<genexpr>  s(     R/$#dhhqk&1!45/s   (*newr   )r  )r  )	util.transformr  r  rT   intersection	dimensionrB   r  r8   )rH   r  r|  r  r  svselection_exprsr  r  valsolds              r   r~  z!CrossFilterSet.transform_function  s   '|,
 ;HH-B2./-H,;PODt?O4OP!#'!+++R/RTD)!,C%(ZN/2}}N,)-cggN&,01C1CA1FdSWj],[N&&q)!0!3+AB/D%3d%:N 0 >22% IPs   C3C8C8)r   r  N)r   r   r   r#   r'   r  r   r   r  r   r|  r`   r   r~  r   r   s   @r   r  r    ss    $U__TDAN
   
[[7 7 
 

 3 3r   r  c                   $     e Zd ZdZd fd	Z xZS )r2  z
    A LinkedStream indicates is automatically linked to plot interactions
    on a backend via a Renderer. Not all backends may support dynamically
    supplying stream data.
    c                     |t         vrt        d|dt                t        |   dd|i| || _        || _        || _        y )NzInvalid popup_position: z; expect one of r   r   )POPUP_POSITIONSr   r   r   popuppopup_positionpopup_anchor)rr   r   r  r  r  r,   r   s         r   r   zLinkedStream.__init__  s^    0*>*< =!!0 13 
 	11&1
,(r   )TNr   N)r   r   r   r   r   r   r   s   @r   r2  r2    s    
) 
)r   r2  c                   <    e Zd ZdZ ej
                  eddd      Zy)PointerXa1  
    A pointer position along the x-axis in data coordinates which may be
    a numeric or categorical dimension.

    With the appropriate plotting backend, this corresponds to the
    position of the mouse/trackpad cursor. If the pointer is outside the
    plot bounds, the position is set to None.
    NTA
           Pointer position along the x-axis in data coordinatesr+  r4   r6   r   )r   r   r   r   r#   r[  pointer_typesrP   r   r   r   r  r    s)     	=$%) 0D	EAr   r  c                   <    e Zd ZdZ ej
                  eddd      Zy)PointerYa2  
    A pointer position along the y-axis in data coordinates which may be
    a numeric or categorical dimension.

    With the appropriate plotting backend, this corresponds to the
    position of the mouse/trackpad pointer. If the pointer is outside
    the plot bounds, the position is set to None.
    NTA
           Pointer position along the y-axis in data coordinatesr  )r   r   r   r   r#   r[  r  yr   r   r   r  r    s)     	=$%) 0D	EAr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)	PointerXYa=  
    A pointer position along the x- and y-axes in data coordinates which
    may numeric or categorical dimensions.

    With the appropriate plotting backend, this corresponds to the
    position of the mouse/trackpad pointer. If the pointer is outside
    the plot bounds, the position values are set to None.
    NTr  r  r  	r   r   r   r   r#   r[  r  rP   r  r   r   r   r  r  !  sK     	=$%) 0D	EA 	=$%) 0D	EAr   r  c                       e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Z ej                  ddd	      Z
y)
Drawze
    A series of updating x/y-positions when drawing, together with the
    current stroke count
    NTr  r  r  r   z_
       The current drawing stroke count. Increments every time a new
       stroke is started.r   )r   r   r   r   r#   r[  r  rP   r  r<   stroke_countr   r   r   r  r  4  sg     	=$%) 0D	EA 	=$%) 0D	EA !5==T @ Lr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)	SingleTapzH
    The x/y-position of a single tap or click in data coordinates.
    NTr  r  r  r  r   r   r   r  r  E  sK     	=$%) 0D	EA 	=$%) 0D	EAr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)TapzA
    The x/y-position of a tap or click in data coordinates.
    NTr  r  r  r  r   r   r   r  r  R  K     	=$%) 0D	EA 	=$%) 0D	EAr   r  c                   d    e Zd ZdZ ej
                  ddd      Z ej
                  ddd      Zy)MultiAxisTapzB
    The x/y-positions of a tap or click in data coordinates.
    NTzB
           Pointer positions along the x-axes in data coordinatesr   zB
           Pointer positions along the y-axes in data coordinates)r   r   r   r   r#   r?   xsysr   r   r   r  r  _  sA     
D4 6E 
FB 
D4 6E 
FBr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)	DoubleTapzI
    The x/y-position of a double-tap or -click in data coordinates.
    NTr  r  r  r  r   r   r   r   r   k  r  r   r   c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)PressUpzH
    The x/y position of a mouse pressup event in data coordinates.
    NTr  r  r  r  r   r   r   r  r  w  r  r   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)PanEndzFThe x/y position of a the end of a pan event in data coordinates.
    NTr  r  r  r  r   r   r   r  r    sI    =$%) 0D	EA 	=$%) 0D	EAr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)
MouseEnter`
    The x/y-position where the mouse/cursor entered the plot area
    in data coordinates.
    NTr  r  r  r  r   r   r   r  r    K     	=$%) 0D	EA 	=$%) 0D	EAr   r  c                   h    e Zd ZdZ ej
                  eddd      Z ej
                  eddd      Zy)
MouseLeaver  NTr  r  r  r  r   r   r   r
  r
    r  r   r
  c                       e Zd ZdZ ej
                  ddd      Z ej
                  ddd      Z ej                  ddd      Z	d	 Z
y)
PlotSizezF
    Returns the dimensions of a plot once it has been displayed.
    NTzThe width of the plot in pixelsr   z The height of the plot in pixelsg      ?zL
       Scale factor to scale width and height values reported by the streamc                     | j                   r"t        | j                   | j                  z        nd | j                  r$t        | j                  | j                  z        dS d dS )N)widthheight)r  r;   scaler  rq   s    r   r   zPlotSize.transform  sU    :>**#djj4::56$;?;;#dkkDJJ67R 	RLPR 	Rr   )r   r   r   r   r#   r<   r  r  r   r  r   r   r   r   r  r    sT     EMM$;\]EU]]4$<^_FELLt :O PERr   r  c                   <    e Zd Z ej                  ddg dd      Zy)
SelectModereplaceT)r  rX   r  subtractz
        Defines what should happen when a new selection is made. The
        default is to replace the existing selection. Other options
        are to append to theselection, intersect with it or subtract
        from it.)r4   r6   r   r   N)r   r   r   r#   Selectorr  r   r   r   r  r    s!    5>>)d E6<Dr   r  c                   h    e Zd ZdZ ej
                  dddd      Z ej
                  dddd      Zy)RangeXYz>
    Axis ranges along x- and y-axis in data coordinates.
    Nr   T8
      Range of the x-axis of a plot in data coordinatesr4   r
  r6   r   8
      Range of the y-axis of a plot in data coordinates)r   r   r   r   r#   rA   x_rangey_ranger   r   r   r  r    sC     ekk$q4 F; <G ekk$q4 F; <Gr   r  c                   N     e Zd ZdZ ej
                  dddd      Z fdZ xZS )RangeXz6
    Axis range along x-axis in data coordinates.
    Nr   Tr  r  c                 H    |j                  dd        t        |   di | y )Nr  r   r   r   r   rr   rI   r   s     r   r   zRangeX._set_stream_parameters  !    

9d#&00r   )	r   r   r   r   r#   rA   r  r   r   r   s   @r   r  r    0     ekk$q4 F; <G1 1r   r  c                   N     e Zd ZdZ ej
                  dddd      Z fdZ xZS )RangeYz6
    Axis range along y-axis in data coordinates.
    Nr   Tr  r  c                 H    |j                  dd        t        |   di | y )Nr  r   r   r!  s     r   r   zRangeY._set_stream_parameters  r"  r   )	r   r   r   r   r#   rA   r  r   r   r   s   @r   r%  r%    r#  r   r%  c                   >    e Zd ZdZ ej
                  ddddd      Zy)BoundsXYz}
    A stream representing the bounds of a box selection as an
    tuple of the left, bottom, right and top coordinates.
    NT   <
        Bounds defined as (left, bottom, right, top) tuple.r4   r6   r
  r,  r   )r   r   r   r   r#   rA   r   r   r   r   r(  r(    s(    
 U[[Q$( /?@Fr   r(  c                   8    e Zd ZdZ ej
                  dd      Zy)Lassozg
    A stream representing a lasso selection in 2D space as a two-column
    array of coordinates.
    TzE
        The coordinates of the lasso geometry as a two-column array.r  N)r   r   r   r   r#   rF   geometryr   r   r   r-  r-    s"    
 u{{D /H IHr   r-  c                       e Zd ZdZ ej
                  ddddd      Z ej                  ee	fddd      Z
 ej                  ee	fddd	      Zy)
SelectionXYz
    A stream representing the selection along the x-axis and y-axis.
    Unlike a BoundsXY stream, this stream returns range or categorical
    selections.
    NTr)  r*  r+  zy
      The current selection along the x-axis, either a numerical range
      defined as a tuple or a list of categories.)r+  r,  r6   r   zy
      The current selection along the y-axis, either a numerical range
      defined as a tuple or a list of categories.)r   r   r   r   r#   rA   r   r[  r@   rB   x_selectiony_selectionr   r   r   r0  r0     sp     U[[Q$( /?@F &%%%eT]t/3 :56K
 &%%%eT]t/3 :56Kr   r0  c                   >    e Zd ZdZ ej
                  ddddd      Zy)BoundsXzp
    A stream representing the bounds of a box selection as an
    tuple of the left and right coordinates.
    NTr   z/
        Bounds defined as (left, right) tuple.r+  )r   r   r   r   r#   rA   boundsxr   r   r   r4  r4    '    
 ekk$a%) 023Gr   r4  c                   >    e Zd ZdZ ej
                  ddddd      Zy)BoundsYzp
    A stream representing the bounds of a box selection as an
    tuple of the bottom and top coordinates.
    NTr   z/
        Bounds defined as (bottom, top) tuple.r+  )r   r   r   r   r#   rA   boundsyr   r   r   r8  r8  !  r6  r   r8  c                   <    e Zd ZdZ ej
                  g ddd      Zy)r  zI
    A stream representing a 1D selection of objects by their index.
    Tz)
        Indices into a 1D datastructure.)r4   r,  r6   r   N)r   r   r   r   r#   rC   r  r   r   r   r  r  ,  s%     EJJrdT H, -Er   r  c                   L     e Zd ZdZ ej
                  ddd      Z fdZ xZS )	PlotResetzI
    A stream signalling when a plot reset event has been triggered.
    FTz2
        Whether a reset event is being signalled.r   c                 B    t        |   | g|i t        |d       y )NT)r_   )r   r   r8   )rr   r  r,   r   s      r   r   zPlotReset.__init__=  s!    EEVt(DEr   )	r   r   r   r   r#   r:   	resettingr   r   r   s   @r   r<  r<  5  s0     ed A5 6IF Fr   r<  c                   8    e Zd ZdZ ej
                  dd      Zy)	CDSStreamzC
    A Stream that syncs a bokeh ColumnDataSource with python.
    T
        Data synced from Bokeh ColumnDataSource supplied as a
        dictionary of columns, where each column is a list of values
        (for point-like data) or list of lists of values (for
        path-like data).r  N)r   r   r   r   r#   r?   r   r   r   r   r@  r@  A  s      5::t * Dr   r@  c                   p     e Zd ZdZ ej
                  dd      Z	 	 d fd	Zed        Z	ed        Z
 xZS )		PointDrawah  
    Attaches a PointDrawTool and syncs the datasource.

    add: boolean
        Whether to allow adding new Points

    drag: boolean
        Whether to enable dragging of Points

    empty_value: int/float/string/None
        The value to insert on non-position columns when adding a new polygon

    num_objects: int
        The number of polygons that can be drawn before overwriting
        the oldest polygon.

    styles: dict
        A dictionary specifying lists of styles to cycle over whenever
        a new Point glyph is drawn.

    tooltip: str
        An optional tooltip to override the default
    TrA  r  c                     |i }|| _         || _        || _        || _        || _        || _        || _        t        |   di | y rU  )rp  dragempty_valuenum_objectsstylestooltipr   r   )	rr   rF  rp  rE  rG  rH  rI  r,   r   s	           r   r   zPointDraw.__init__l  sP    >F	&&"6"r   c                     | j                   }t        |t              r|j                  }| j                  s|j                  g d       S |j                  | j                  d       S )Nr   )r   r&   r   lastr   r   )rr   r   s     r   r  zPointDraw.elementy  sP    f./[[Fyy<<t<,,||DII$|//r   c                 ,     ddl m}  | fd g      S )Nr	   r  c                      j                   S r   r  r  rI   rr   s     r   rQ   z#PointDraw.dynamic.<locals>.<lambda>  	    $,,r   r   r  r  rr   r  s   ` r   dynamiczPointDraw.dynamic      +>OOr   )NTTr   NNr   r   r   r   r#   r?   r   r   r   r  rU  r   r   s   @r   rC  rC  M  sZ    0 5::t * D KL&*# 0 0 P Pr   rC  c                   L     e Zd ZdZ ej
                  dd      Zd fd	Z xZS )	CurveEditz
    Attaches a PointDraw to the plot which allows editing the Curve when selected.

    style: dict
        A dictionary specifying the style of the vertices.

    tooltip: str
        An optional tooltip to override the default
    TrA  r  c                 \    |i }|xs ddi| _         || _        t        t        |   di | y )Nsize
   r   )stylerI  r   rC  r   )rr   r]  rI  r,   r   s       r   r   zCurveEdit.__init__  s6    =E*vrl
i'1&1r   )NN	r   r   r   r   r#   r?   r   r   r   r   s   @r   rY  rY    s+     5::t * D2 2r   rY  c                   r     e Zd ZdZ ej
                  dd      Z	 	 	 d fd	Zed        Z	ed        Z
 xZS )	PolyDrawaJ  
    Attaches a PolyDrawTool and syncs the datasource.

    drag: boolean
        Whether to enable dragging of polygons and paths

    empty_value: int/float/string/None
        The value to insert on non-position columns when adding a new polygon

    num_objects: int
        The number of polygons that can be drawn before overwriting
        the oldest polygon.

    show_vertices: boolean
        Whether to show the vertices when a polygon is selected

    styles: dict
        A dictionary specifying lists of styles to cycle over whenever
        a new Poly glyph is drawn.

    tooltip: str
        An optional tooltip to override the default

    vertex_style: dict
        A dictionary specifying the style options for the vertices.
        The usual bokeh style options apply, e.g. fill_color,
        line_alpha, size, etc.
    TrA  r  c                     |i }|i }|| _         || _        || _        || _        || _        || _        || _        t        	|    di | y rU  )	rE  rF  rG  show_verticesvertex_stylerH  rI  r   r   )
rr   rF  rE  rG  rb  rc  rH  rI  r,   r   s
            r   r   zPolyDraw.__init__  s_     >FL	&&*("6"r   c                 F   | j                   }t        |t              r|j                  }| j                  }|s|j                  g d       S t        | j                        }|j                  \  }}|j                  |j                  d}t        t        ||d                  D cg c]3  }| j                  D ci c]  }|j                  ||      ||   |    c}5 }}}|j                  j                  r|j                  ndg}	|j                  ||	d       S c c}w c c}}w )NrK  r  r  r   multitabulardatatyper   )r   r&   r   rL  r   r   rB   kdimsr3   ranger  r~   	interfacemultirh  )
rr   r   r   colsrP   r  lookupru  r  rh  s
             r   r  zPolyDraw.element  s   f./[[Fyy<<t<,,DII||1aff-s4Q=1242A 8<yyAy!Aq!471:-yA2 	 4&,&6&6&<&<6??>BR||D8|== B 4s   $D7 DDDc                 ,     ddl m}  | fd g      S )Nr	   r  c                      j                   S r   rO  rP  s     r   rQ   z"PolyDraw.dynamic.<locals>.<lambda>  rQ  r   rR  rS  rT  s   ` r   rU  zPolyDraw.dynamic  rV  r   )NTr   FNNNrW  r   s   @r   r`  r`    s]    : 5::t * D AB@D#  > > P Pr   r`  c                   l     e Zd ZdZ ej
                  dd      Zd fd	Zed        Z	ed        Z
 xZS )	FreehandDrawa  
    Attaches a FreehandDrawTool and syncs the datasource.

    empty_value: int/float/string/None
        The value to insert on non-position columns when adding a new polygon

    num_objects: int
        The number of polygons that can be drawn before overwriting
        the oldest polygon.

    styles: dict
        A dictionary specifying lists of styles to cycle over whenever
        a new freehand glyph is drawn.

    tooltip: str
        An optional tooltip to override the default
    TrA  r  c                 d    |i }|| _         || _        || _        || _        t	        |   di | y rU  rF  rG  rH  rI  r   r   rr   rF  rG  rH  rI  r,   r   s         r   r   zFreehandDraw.__init__  ;    >F&&"6"r   c                    | j                   }t        |t              r|j                  }| j                  }|s|j                  g d       S t        | j                        }|j                  \  }}|j                  |j                  d}t        t        ||d                  D cg c]3  }| j                  D ci c]  }|j                  ||      ||   |    c}5 }}}|j                  |d       S c c}w c c}}w )NrK  re  r   )r   r&   r   rL  r   r   rB   ri  r3   rj  r  r~   )	rr   r   r   rm  rP   r  rn  ru  r  s	            r   r  zFreehandDraw.element  s    f./[[Fyy<<t<,,DII||1aff-s4Q=1242A 8<yyAy!Aq!471:-yA2 	 4||DT|** B 4s   $C77 C2C72C7c                 ,     ddl m}  | fd g      S )Nr	   r  c                      j                   S r   rO  rP  s     r   rQ   z&FreehandDraw.dynamic.<locals>.<lambda>!  rQ  r   rR  rS  rT  s   ` r   rU  zFreehandDraw.dynamic  rV  r   Nr   NNrW  r   s   @r   rr  rr    sP    $ 5::t * D# + + P Pr   rr  c                   l     e Zd ZdZ ej
                  dd      Zd fd	Zed        Z	ed        Z
 xZS )	BoxEdita  
    Attaches a BoxEditTool and syncs the datasource.

    empty_value: int/float/string/None
        The value to insert on non-position columns when adding a new box

    num_objects: int
        The number of boxes that can be drawn before overwriting the
        oldest drawn box.

    styles: dict
        A dictionary specifying lists of styles to cycle over whenever
        a new box glyph is drawn.

    tooltip: str
        An optional tooltip to override the default
    TrA  r  c                 d    |i }|| _         || _        || _        || _        t	        |   di | y rU  rt  ru  s         r   r   zBoxEdit.__init__>  rv  r   c           	      6   ddl m}m} | j                  }t	        |t
              r|j                  }| j                  s|j                  g       S g d|j                  D cg c]  }|j                   c}z   }t	        ||      r't        fd|D              |j                  d       S g }t        t        d   d   d   d	               D ]  \  }\  }}	}
}|||	|	g}|
|||
g}t	        ||      r"|j                  |       |j                  |
       |j                  D cg c]  }|j                     |    }}|j                  ||g|        |j                  j                   r|j"                  nd
g}|j                  ||d       S c c}w c c}w )Nr	   )Polygons
Rectangles)x0y0x1y1c              3   (   K   | ]	  }|     y wr   r   )r   dr   s     r   r   z"BoxEdit.element.<locals>.<genexpr>S  s     /$Qa$s   rK  r  r  r  r  rf  rg  )r  r  r  r   r&   r   rL  r   r   vdimsr3   r@   ro  ziprX   rk  rl  rh  )rr   r  r  r   vddimspathsru  r  r  r  r  r  r  r  rh  r   s                   @r   r  zBoxEdit.elementG  s   1f./[[Fyy<<##'6<<(H<R<(HHfj)/$//D<<<..#,SdT$ZdUYZ^U_-`#aABBb"b!Bb"b!B&(+		"		"/5||<|DM!$|D<LL"b4) $b '-&6&6&<&<6??>BR||EH|>> )I =s   "F%Fc                 ,     ddl m}  | fd g      S )Nr	   r  c                      j                   S r   rO  rP  s     r   rQ   z!BoxEdit.dynamic.<locals>.<lambda>d  rQ  r   rR  rS  rT  s   ` r   rU  zBoxEdit.dynamica  rV  r   rz  rW  r   s   @r   r|  r|  %  sP    $ 5::t * D# ? ?2 P Pr   r|  c                   L     e Zd ZdZ ej
                  dd      Zd fd	Z xZS )PolyEdita  
    Attaches a PolyEditTool and syncs the datasource.

    shared: boolean
        Whether PolyEditTools should be shared between multiple elements

    tooltip: str
        An optional tooltip to override the default

    vertex_style: dict
        A dictionary specifying the style options for the vertices.
        The usual bokeh style options apply, e.g. fill_color,
        line_alpha, size, etc.
    TrA  r  c                 >    |i }|| _         t        |   dd|i| y )Nrc  r   )sharedr   r   )rr   rc  r  r,   r   s       r   r   zPolyEdit.__init__~  s*    L=l=f=r   rZ  r^  r   s   @r   r  r  h  s+     5::t * D> >r   r  c                 R    t        | t              r| j                  j                  S | S r   )r&   r   r#   r   )objs    r   _streams_transformr    s    #tyy~~Jr   )Nr   r   collectionsr   
contextlibr   	functoolsr   	itertoolsr   numbersr   typesr   numpyrD   pandasr  r#   corer
   core.ndmappingr   r>   r@   datetime_typesr  r  r   r    r/   rz   r1   r   r   r   r*   r}   rd  r  r  r  r  r2  r  r  r  r  r  r  r  r   r  r  r  r
  r  r  r  r  r%  r(  r-  r0  r4  r8  r  r<  r@  rC  rY  r`  rr  r|  r  r  reactiveregister_reference_transformr   r   r   <module>r     s    # %         , e:d&9&9:	   ' '"	&UU   Up	-f 	-76 7:^>T ^>DI?V I?ZE& E8^)f ^)B"f "JE.G E.PM
G M
`<3W <3~)6 )(E| EE| E E E&9 "E	 E
E) 
E	F< 	F
E	 
E
Ei 
E	EY 	EE EE ER| R" 	<l 	<
1\ 
1
1\ 
1@| @IL I6( 6,3l 33l 3-, -	F 	F	 	8P	 8Px2	 24GPy GPT4P9 4Pp?Pi ?PF>x >:  + +,> ?r   