
    -e?S              	         d Z ddlmZ ddlZ ej        e          ZddlmZm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZ ddl m!Z! ddl"m#Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0 er&ddlm1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z:m;Z< ddl%m=Z= dZ>e G d dee.e'e&                      Z?dS )z` Provide a base class for all objects (called Bokeh Models) that can go in
a Bokeh |Document|.

    )annotationsN)	Parameter	Signatureisclass)TYPE_CHECKINGAnyIterable   )
properties)HasProps_default_resolverabstract)	type_link)without_property_validation)ObjectRefRepRef
Serializer)ID)Event)default)EventCallbackManagerPropertyCallbackManager)make_id   )	html_reprprocess_example)HasDocumentRefcollect_models(visit_value_and_its_immediate_references)Setter)SelectorType)Document)DocumentPatchedEvent)Callback
CustomCode)PropertyCallback)Modelc                      e Zd ZU dZdZi Ze fd            Zded<   dddY fdZ	dZ fdZ
d[dZeZd\dZed]d            Z ej        ej        d          Zded<    ej        ej        d          Zded<    ej        ej         ej         ej        d                    d          Z ej        ej         ej         ej        d                    d          Z ej        ej        d          Z ej        d d!"          Zd#ed$<   ed^d&            Zee d_d*                        Z!d`d/Z"dadbd5Z#dcd7Z$dd fd9Z%ded;Z&dfd?Z'dgdAZ(dhdEZ)di fdIZ*	 djdk fdPZ+dldSZ,ed\dT            Z-d\dUZ.d[dVZ/dmdXZ0 xZ1S )nr'   zG Base class for all objects stored in Bokeh |Document| instances.

     c                N   t                                                       | j                            d          rid| j        v sJ t          |                       d |                                 D             }t          |          | j        _	        t          |            d S d S )Nbokeh.models__init__c                    g | ]
}|d          S )r   r)   ).0xs     1lib/python3.11/site-packages/bokeh/model/model.py
<listcomp>z+Model.__init_subclass__.<locals>.<listcomp>T   s    :::1!A$:::    )
parameters)super__init_subclass__
__module__
startswith__dict__strr3   r   r,   __signature__r   )clsr3   	__class__s     r0   r5   zModel.__init_subclass__N   s    !!###>$$^44 	!---s3xx---::)9)9:::J)2j)I)I)ICL&C     		! 	!r2   r   _idNidargsr   r?   	ID | Nonekwargsreturnc                   t                                          |           }||s|rt          d          ||_        nt	                      |_        |S )Nz7'id' cannot be used together with property initializers)r4   __new__
ValueErrorr=   r   )r;   r?   r@   rB   objr<   s        r0   rE   zModel.__new__Z   sX    ggooc"" > \v \ !Z[[[CGGiiCG
r2   Nonec                    |rt          d          d|v rt          d           t                      j        di | t          j        |            d S )Nz$positional arguments are not allowedr?   z initializing 'id' is not allowedr)   )rF   r4   r,   default_themeapply_to_model)selfr@   rB   r<   s      r0   r,   zModel.__init__h   sg     	ECDDD6>>?@@@""6"""$T*****r2   r9   c                4    | j         j        }| d| j        dS )Nz(id=z, ...))r<   __name__r?   )rL   names     r0   __str__zModel.__str__q   s%    ~&--DG----r2   c                T    d| _         d| _        | j                                         dS )z; Clean up references to the document and property

        N)	_document_temp_document_property_valuesclearrL   s    r0   destroyzModel.destroyw   s.     "##%%%%%r2   c                    | j         S N)r=   rV   s    r0   r?   zModel.id   s	    xr2   a  
    An arbitrary, user-supplied name for this model.

    This name can be useful when querying the document to retrieve specific
    Bokeh models.

    .. code:: python

        >>> plot.circle([1,2,3], [4,5,6], name="temp")
        >>> plot.select(name="temp")
        [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]

    .. note::
        No uniqueness guarantees or other conditions are enforced on any names
        that are provided, nor is the name used directly by Bokeh for any
        reason.

    )helpz
str | NonerO   a  
    An optional list of arbitrary, user-supplied values to attach to this
    model.

    This data can be useful when querying the document to retrieve specific
    Bokeh models:

    .. code:: python

        >>> r = plot.circle([1,2,3], [4,5,6])
        >>> r.tags = ["foo", 10]
        >>> plot.select(tags=['foo', 10])
        [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]

    Or simply a convenient way to attach any necessary metadata to a model
    that can be accessed by ``CustomJS`` callbacks, etc.

    .. note::
        No uniqueness guarantees or other conditions are enforced on any tags
        that are provided, nor are the tags used directly by Bokeh for any
        reason.

    z	list[Any]tagszbokeh.models.callbacks.CallbackaQ  
    A mapping of event names to lists of ``CustomJS`` callbacks.

    Typically, rather then modifying this property directly, callbacks should be
    added using the ``Model.js_on_event`` method:

    .. code:: python

        callback = CustomJS(code="console.log('tap event occurred')")
        plot.js_on_event('tap', callback)
    a  
    A mapping of attribute names to lists of ``CustomJS`` callbacks, to be set up on
    BokehJS side when the document is created.

    Typically, rather then modifying this property directly, callbacks should be
    added using the ``Model.js_on_change`` method:

    .. code:: python

        callback = CustomJS(code="console.log('stuff')")
        plot.x_range.js_on_change('start', callback)

    z
    Collection of events that are subscribed to by Python callbacks. This is
    the set of events that will be communicated from BokehJS back to Python
    for this model.
    Ta  
    Indicates whether this model should be synchronized back to a Bokeh server when
    updated in a web browser. Setting to ``False`` may be useful to reduce network
    traffic when dealing with frequently updated objects whose updated values we
    don't need.

    .. note::
        Setting this property to ``False`` will prevent any ``on_change()`` callbacks
        on this object from triggering. However, any JS-side callbacks will still
        work.

    )r   rZ   boolsyncabler   c                ,    t          | j                  S )Nr>   )r   r=   rV   s    r0   refz	Model.ref   s    dhr2   r;   type[Model]list[Parameter]c                <   g }d}t          | j                  D ]}|                     |          }|                    | d          }|d}t	          |t
                    rt          |          dhk    r|d         }| j                            d          rt	          |t                    rJ t          |t          j        |rt          j        n|          }|r~t          |j                  }|                    d|||j        f           h d	}g }	t          |                                           t          | j                  z
  |z
  }
|
D ]}|                     |          }|                    | d          }t	          |t
                    rt          |          dhk    r|d         }| j                            d          rt	          |t                    rJ t          |t          j        |          }~t          |j                  }|	                    |||j        f           | j                                        D ];\  }\  }}t          |t          j        
          }|	                    |||f           <|	                    d            ||	z   S )z Generate Python ``Parameter`` values suitable for functions that are
        derived from the glyph.

        Returns:
            list(Parameter)

        FT)no_evalNfieldr+   )rO   kindr   r   >   subscribed_eventsjs_event_callbacksjs_property_callbacks)rO   re   c                    | d         j         S )Nr   )rO   )r/   s    r0   <lambda>z"Model.parameters.<locals>.<lambda>+  s    !	 r2   )key)reversed_argslookupclass_default
isinstancedictsetr6   r7   r'   r   POSITIONAL_OR_KEYWORDemptyr   propertyinsert__doc__r   KEYWORD_ONLYappend
_extra_kwsitemssort)r;   
arg_paramsno_more_defaultsarg
descriptorr   paramtyp	omissionskwarg_paramskwskwdocs                r0   r3   zModel.parameters   s    
 CI&& 	C 	CCCJ ..sD.AAG#'  '4(( +S\\gY-F-F!'* ~((88 6%gu555554+;H		  E  J/00Ca%j.@!ABBBB YXX	#..""##c#)nn4y@ 	B 	BBBJ ..sD.AAG '4(( +S\\gY-F-F!'* ~((88 6%gu55555+  E
 J/00CZ-? @AAAA!n2244 	3 	3NB
c+  E S 1222211222L((r2   eventstr | type[Event]	callbacksJSEventCallbackc                   t          |t                    rt          j        |          j        }nDt          |t
                    rt          |t                    r|j        }nt          d|           t          | j	        
                    |g                     }|D ]}||vr|                    |           || j	        |<   d S )Nz/expected string event name or event class, got )rp   r9   r   cls_for
event_nametype
issubclassrF   listrg   getry   )rL   r   r   r   all_callbackscallbacks         r0   js_on_eventzModel.js_on_event/  s    eS!! 	Xu--8JJt$$ 	XE5)A)A 	X)JJVuVVWWWT488RHHII! 	/ 	/H},,$$X....;
+++r2   attrother
other_attrattr_selectorint | str | Nonec                   |                      |d          }|t          |d| d          t          |t                    st          d|z            |                     |d          }|t          |d|d          dd	lm} |d
|dnd} |t          |          d|j         d|j         |           }	|                     ||	           dS )a   Link two Bokeh model properties using JavaScript.

        This is a convenience method that simplifies adding a
        :class:`~bokeh.models.CustomJS` callback to update one Bokeh model
        property whenever another changes value.

        Args:

            attr (str) :
                The name of a Bokeh property on this model

            other (Model):
                A Bokeh model to link to self.attr

            other_attr (str) :
                The property on ``other`` to link together

            attr_selector (Union[int, str]) :
                The index to link an item in a subscriptable ``attr``

        Added in version 1.1

        Raises:

            ValueError

        Examples:

            This code with ``js_link``:

            .. code :: python

                select.js_link('value', plot, 'sizing_mode')

            is equivalent to the following:

            .. code:: python

                from bokeh.models import CustomJS
                select.js_on_change('value',
                    CustomJS(args=dict(other=plot),
                             code="other.sizing_mode = this.value"
                    )
                )

            Additionally, to use attr_selector to attach the left side of a range slider to a plot's x_range:

            .. code :: python

                range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)

            which is equivalent to:

            .. code :: python

                from bokeh.models import CustomJS
                range_slider.js_on_change('value',
                    CustomJS(args=dict(other=plot.x_range),
                             code="other.start = this.value[0]"
                    )
                )

        FraisesNz is not a property of self ()z 'other' is not a Bokeh model: %rz is not a property of other (r   )CustomJS[] )r   zother.z = this.)r@   code)	rn   rF   rp   r'   bokeh.modelsr   rq   rO   js_on_change)
rL   r   r   r   r   r   other_descriptorr   selectorcbs
             r0   js_linkzModel.js_link?  s(   @ [[e[44
MMDMMMNNN%'' 	I?%GHHH <<
5<AA#
UU5UUUVVV))))))-:-F)}))))BX4e,,,3v<L<Q3v3v[e[j3vlt3v3vwww$#####r2   JSChangeCallbackc                    t          |          dk    rt          d          ddlm t	          fd|D                       st          d          |                     |d          }|
d	|j         }d
 | j                                        D             }|| j        vr
g | j        |<   |D ]2}|| j        |         v r| j        |         	                    |           3| 
                    d|| j                   dS )a   Attach a :class:`~bokeh.models.CustomJS` callback to an arbitrary
        BokehJS model event.

        On the BokehJS side, change events for model properties have the
        form ``"change:property_name"``. As a convenience, if the event name
        passed to this method is also the name of a property on the model,
        then it will be prefixed with ``"change:"`` automatically:

        .. code:: python

            # these two are equivalent
            source.js_on_change('data', callback)
            source.js_on_change('change:data', callback)

        However, there are other kinds of events that can be useful to respond
        to, in addition to property change events. For example to run a
        callback whenever data is streamed to a ``ColumnDataSource``, use the
        ``"stream"`` event on the source:

        .. code:: python

            source.js_on_change('streaming', callback)

        r   zRjs_on_change takes an event name and one or more callbacks, got only one parameter)r%   c              3  8   K   | ]}t          |          V  d S rY   )rp   )r.   r/   r%   s     r0   	<genexpr>z%Model.js_on_change.<locals>.<genexpr>  s-      @@:a,,@@@@@@r2   z0not all callback values are CustomCode instancesFr   Nzchange:c                .    i | ]\  }}|d  |D             S )c                    g | ]}|S r)   r)   )r.   r   s     r0   r1   z1Model.js_on_change.<locals>.<dictcomp>.<listcomp>  s    $$$"2$$$r2   r)   )r.   kcbss      r0   
<dictcomp>z&Model.js_on_change.<locals>.<dictcomp>  s-    VVVCq$$$$$VVVr2   rh   )lenrF   bokeh.models.callbacksr%   allrn   rO   rh   r{   ry   trigger)rL   r   r   r   oldr   r%   s         @r0   r   zModel.js_on_change  s9   2 y>>Qqrrr 	655555@@@@i@@@@@ 	QOPPP[[u[55
!/jo//EVV43M3S3S3U3UVVV22202D&u-! 	? 	?H45e<<<&u-44X>>>>,c43MNNNNNr2   r&   c                p    |                      |          } t                      j        |j        g|R   dS )a   Add a callback on this object to trigger when ``attr`` changes.

        Args:
            attr (str) : an attribute name on this object
            *callbacks (callable) : callback functions to register

        Returns:
            None

        Examples:

            .. code-block:: python

                widget.on_change('value', callback1, callback2, ..., callback_n)

        N)rn   r4   	on_changerO   )rL   r   r   r   r<   s       r0   r   zModel.on_change  s=    " [[&&
*/6I666666r2   
set[Model]c                :    t          t          |                     S )zE Returns all ``Models`` that this object has references to.

        )rr   r   rV   s    r0   
referenceszModel.references  s     >$''(((r2   r   r!   Iterable[Model]c                J    ddl m}  ||                                 |          S )z Query this object and all of its references for objects that
        match the given selector.

        Args:
            selector (JSON-like) :

        Returns:
            seq[Model]

        r
   )find)
core.queryr   r   )rL   r   r   s      r0   selectzModel.select  s2     	&%%%%%tDOO%%x000r2   Model | Nonec                    t          |                     |                    }t          |          dk    rt          d| d|          t          |          dk    rdS |d         S )a5   Query this object and all of its references for objects that
        match the given selector.  Raises an error if more than one object
        is found.  Returns single matching object, or None if nothing is found
        Args:
            selector (JSON-like) :

        Returns:
            Model
        r   z$Found more than one object matching z: r   N)r   r   r   rF   )rL   r   results      r0   
select_onezModel.select_one  sl     dkk(++,,v;;??ZHZZPVZZ[[[v;;!4ayr2   type[Model] | SelectorTypeupdatesdict[str, Any]c                    t          |          r%t          |t                    rt          |          }|                     |          D ]-}|                                D ]\  }}t          |||           .dS )z Update objects that match a given selector with the specified
        attribute/value updates.

        Args:
            selector (JSON-like) :
            updates (dict) :

        Returns:
            None

        )r   N)r   r   r'   rq   r   r{   setattr)rL   r   r   rG   rk   vals         r0   
set_selectzModel.set_select  s     8 	+He!<!< 	+***H;;x(( 	' 	'C#MMOO ' 'SS#&&&&'	' 	'r2   
serializerr   r   c                    |                     | | j                   t                                          |          }t	          d|d         | j                  }|                    d          }|||d<   |S )NobjectrO   )r   rO   r?   
attributes)add_refr_   r4   to_serializabler   r?   r   )rL   r   	super_reprepr   r<   s        r0   r   zModel.to_serializable
  s~    4***GG++J77	6"w
 
 
 ]]<00
! *C
r2   r   newhintDocumentPatchedEvent | NonesetterSetter | Nonec                4   |Sddfd}| j         Dt          ||           t          ||           dk    r| j        j                                         |                     |          }t                                          |j        ||||           dS )z


        Nr   _r   c                    dz  d S )Nr   r)   )r   dirty_counts    r0   
mark_dirtyz!Model.trigger.<locals>.mark_dirty(  s    q r2   )r   r   )r   r   )	rR   r   documentmodels
invalidatern   r4   r   rO   )
rL   r   r   r   r   r   r   r   r   r<   s
           @r0   r   zModel.trigger  s     <K! ! ! ! ! ! ~)8jIII8jIII??M(33555[[&&

cVLLLLLr2   r   r"   c                    | j         |u rdS | j         t          d| d          |j                            |            || _         |                                  dS )z Attach a model to a Bokeh |Document|.

        This private interface should only ever called by the Document
        implementation to set the private ._document field properly

        Nz0Models must be owned by only a single document, z is already in a doc)r   RuntimeErrorthemerK   _update_event_callbacks)rL   r   s     r0   _attach_documentzModel._attach_document4  sn     =CF=$nRVnnnooo	  &&&$$&&&&&r2   c                ,    t          j                     d S rY   )r   clear_extensions)r;   s    r0   _clear_extensionszModel._clear_extensionsE  s    *,,,,,r2   c                <    d| _         t          j        |            dS )z Detach a model from a Bokeh |Document|.

        This private interface should only ever called by the Document
        implementation to unset the private ._document field properly

        N)r   rJ   rK   rV   s    r0   _detach_documentzModel._detach_documentI  s"     $T*****r2   c                     t          |           S rY   )r   rV   s    r0   _repr_html_zModel._repr_html_S  s    r2   
int | Nonec                    d S rY   r)   rV   s    r0   _sphinx_height_hintzModel._sphinx_height_hintV  s    tr2   )r@   r   r?   rA   rB   r   rC   r'   )r@   r   rB   r   rC   rH   )rC   r9   )rC   rH   )rC   r   )rC   r   )r;   r`   rC   ra   )r   r   r   r   rC   rH   rY   )
r   r9   r   r'   r   r9   r   r   rC   rH   )r   r9   r   r   rC   rH   )r   r9   r   r&   rC   rH   )rC   r   )r   r!   rC   r   )r   r!   rC   r   )r   r   r   r   rC   rH   )r   r   rC   r   )NN)r   r9   r   r   r   r   r   r   r   r   rC   rH   )r   r"   rC   rH   )rC   r   )2rN   r6   __qualname__rw   rm   rz   classmethodr5   __annotations__rE   r,   rP   __repr__rW   ru   r?   pNullableStringrO   ListAnyRefr[   DictInstancerg   rh   Setrf   Boolr]   r_   r   r3   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r<   s   @r0   r'   r'   A   s          EJ! ! ! ! [! GGG15        + + + + + +. . . . H& & & &    X "qz!( 2 	 	 	D 	 	 	 	& afQX - 	 	 	D 	 	 	 	0  &!&<]1^1^*_*_ 
g 
	 
	 
	 #AF18VQVJAJ?`4a4a-b-b j 	 	 	 ah . 	 	 	 QVD 0 	 	 	H 	 	 	 	       X 
  H) H) H) !  [H)T< < < < P$ P$ P$ P$ P$d,O ,O ,O ,O\7 7 7 7 7 7() ) ) )1 1 1 1   "' ' ' '$     " OSM M M M M M M4' ' ' '" - - - [-+ + + +          r2   r'   )@rw   
__future__r   logging	getLoggerrN   loginspectr   r   r   typingr   r   r	   corer   r   core.has_propsr   r   r   core.property._sphinxr   core.property.validationr   core.serializationr   r   r   
core.typesr   eventsr   themesr   rJ   util.callback_managerr   r   util.serializationr   docsr   r   utilr   r   r   r    r   r!   r   r"   document.eventsr#   models.callbacksr$   r   r%   r   r&   __all__r'   r)   r2   r0   <module>r     sY    # " " " " " g!! 2 1 1 1 1 1 1 1 1 1 / / / / / / / / / / # " " " " " B B B B B B B B B B - - - - - - B B B B B B > > > > > > > > > >             - - - - - - Q Q Q Q Q Q Q Q ( ( ( ( ( ( , , , , , , , , Z Z Z Z Z Z Z Z Z Z 9''''''))))))######666666^^^^^^^^888888 
U U U U UHn&=?S U U 
U U Ur2   