
    g6O                       U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dl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# d dl$m%Z%m&Z& erd dl'm(Z(m)Z) d dl*m+Z+ d dl,m-Z- dd d d ddiZ.de/d<   e	d   Z0de/d<   ddhZ1de/d<   	 	 	 	 d+dZ2 G d  d!e
d"#      Z3 G d$ d%e
d"#      Z4e G d& d'             Z5 G d( d)      Z6d,d*Z7y)-    )annotationsN)	dataclass)TYPE_CHECKINGAnyFinalLiteral	TypedDictcastoverload)	TypeAlias)config)AttributeDictionary)current_form_id)check_widget_policies)Keycompute_and_register_element_idto_key)StreamlitAPIException)DeckGlJsonChart)gather_metrics)get_script_run_ctx)WidgetCallbackregister_widget)IterableMapping)Deck)DeltaGeneratorinitialViewState   )latitude	longitudepitchzoomzFinal[Mapping[str, Any]]	EMPTY_MAP)single-objectmulti-objectr   SelectionModer%   r&   zFinal[set[SelectionMode]]_SELECTION_MODESc                   t        | t              r| h}nt        d|  dd      |j                  t              st        d|  dt               |j                  ddh      rt        d      g }|D ]`  } | dk(  r*|j                  t        j                  j                         2| dk(  s8|j                  t        j                  j                         b t        |      S )z2Parse and check the user provided selection modes.zInvalid selection mode: z. z=Selection mode must be a single value, but got a set instead.z. Valid options are: r%   r&   zPOnly one of `single-object` or `multi-object` can be selected as selection mode.)
isinstancestrr   issubsetr(   
issupersetappendPydeckProtor'   SINGLE_OBJECTMULTI_OBJECTset)selection_modeselection_mode_setparsed_selection_modess      Z/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/deck_gl_json_chart.pyparse_selection_moder7   A   s     .#&,- $&~&6b9K
 	

 &&'78#&~&6 7""2!35
 	

 $$o~%FG#^
 	
  ,_,"))+*C*C*Q*QR~-"))+*C*C*P*PQ	 -
 %&&    c                  &    e Zd ZU dZded<   ded<   y)PydeckSelectionStatea4  
    The schema for the PyDeck chart selection state.

    The selection state is stored in a dictionary-like object that supports
    both key and attribute notation. Selection states cannot be
    programmatically changed or set through Session State.

    You must define ``id`` in ``pydeck.Layer`` to ensure statefulness when
    using selections with ``st.pydeck_chart``.

    Attributes
    ----------
    indices : dict[str, list[int]]
        A dictionary of selected objects by layer. Each key in the dictionary
        is a layer id, and each value is a list of object indices within that
        layer.
    objects : dict[str, list[dict[str, Any]]]
        A dictionary of object attributes by layer. Each key in the dictionary
        is a layer id, and each value is a list of metadata dictionaries for
        the selected objects in that layer.

    Examples
    --------
    The following example has multi-object selection enabled. The chart
    displays US state capitals by population (2023 US Census estimate). You
    can access this `data
    <https://github.com/streamlit/docs/blob/main/python/api-examples-source/data/capitals.csv>`_
    from GitHub.

    >>> import streamlit as st
    >>> import pydeck
    >>> import pandas as pd
    >>>
    >>> capitals = pd.read_csv(
    ...     "capitals.csv",
    ...     header=0,
    ...     names=[
    ...         "Capital",
    ...         "State",
    ...         "Abbreviation",
    ...         "Latitude",
    ...         "Longitude",
    ...         "Population",
    ...     ],
    ... )
    >>> capitals["size"] = capitals.Population / 10
    >>>
    >>> point_layer = pydeck.Layer(
    ...     "ScatterplotLayer",
    ...     data=capitals,
    ...     id="capital-cities",
    ...     get_position=["Longitude", "Latitude"],
    ...     get_color="[255, 75, 75]",
    ...     pickable=True,
    ...     auto_highlight=True,
    ...     get_radius="size",
    ... )
    >>>
    >>> view_state = pydeck.ViewState(
    ...     latitude=40, longitude=-117, controller=True, zoom=2.4, pitch=30
    ... )
    >>>
    >>> chart = pydeck.Deck(
    ...     point_layer,
    ...     initial_view_state=view_state,
    ...     tooltip={"text": "{Capital}, {Abbreviation}\nPopulation: {Population}"},
    ... )
    >>>
    >>> event = st.pydeck_chart(chart, on_select="rerun", selection_mode="multi-object")
    >>>
    >>> event.selection

    .. output ::
        https://doc-pydeck-event-state-selections.streamlit.app/
        height: 700px

    This is an example of the selection state when selecting a single object
    from a layer with id, ``"captial-cities"``:

    >>> {
    >>>   "indices":{
    >>>     "capital-cities":[
    >>>       2
    >>>     ]
    >>>   },
    >>>   "objects":{
    >>>     "capital-cities":[
    >>>       {
    >>>         "Abbreviation":" AZ"
    >>>         "Capital":"Phoenix"
    >>>         "Latitude":33.448457
    >>>         "Longitude":-112.073844
    >>>         "Population":1650070
    >>>         "State":" Arizona"
    >>>         "size":165007.0
    >>>       }
    >>>     ]
    >>>   }
    >>> }

    zdict[str, list[int]]indiceszdict[str, list[dict[str, Any]]]objectsN__name__
__module____qualname____doc____annotations__ r8   r6   r:   r:   f   s    dL "!,,r8   r:   F)totalc                      e Zd ZU dZded<   y)PydeckStateaQ  
    The schema for the PyDeck event state.

    The event state is stored in a dictionary-like object that supports both
    key and attribute notation. Event states cannot be programmatically changed
    or set through Session State.

    Only selection events are supported at this time.

    Attributes
    ----------
    selection : dict
        The state of the ``on_select`` event. This attribute returns a
        dictionary-like object that supports both key and attribute notation.
        The attributes are described by the ``PydeckSelectionState``
        dictionary schema.

    r:   	selectionNr=   rC   r8   r6   rF   rF      s    & $#r8   rF   c                  "    e Zd ZdZdddZddZy)PydeckSelectionSerdezUPydeckSelectionSerde is used to serialize and deserialize the Pydeck selection state.c                    di i di}||nt        j                  |      }d|vr|}t        t        t	        |            S )NrG   )r;   r<   )jsonloadsr
   rF   r   )selfui_value	widget_idempty_selection_stateselection_states        r6   deserializez PydeckSelectionSerde.deserialize   sU    .
 &.%5!4::h;O 	 o-3OK!4_!EFFr8   c                8    t        j                  |t              S )N)default)rK   dumpsr+   )rM   rQ   s     r6   	serializezPydeckSelectionSerde.serialize   s    zz/377r8   N) )rN   z
str | NonerO   r+   returnrF   )rQ   rF   rX   r+   )r>   r?   r@   rA   rR   rV   rC   r8   r6   rI   rI      s    _G(8r8   rI   c            	          e Zd Ze	 dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed	      	 dddddd
dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedd       Zy)PydeckMixinNT)use_container_widthwidthheightkeyc                    y NrC   rM   
pydeck_objr[   r\   r]   r3   	on_selectr^   s           r6   pydeck_chartzPydeckMixin.pydeck_chart  s     r8   r%   rerun)r[   r\   r]   r3   rc   r^   c                    y r`   rC   ra   s           r6   rd   zPydeckMixin.pydeck_chart  s     r8   rd   ignorec          	        t               }t               }	|t        j                  t              }
n|j                         }
|
|_        ||_        |r||_        |r||_        t        |      }|rt        j                  |      |_
        t        j                  d      }|r||_        t        |      }|dk7  }|dvrt        |      st!        d| d      |r|j"                  j%                  t'        |             t        |      }t)        | j*                  ||rt-        t.        |      nddd|       t1        | j*                        |_        t5        d	|||||
|j2                  
      |_        t9               }t;        |j6                  |	|j<                  t        |      r|nd|j>                  d      }| j*                  jA                  d	|       t-        tB        |jD                        S | j*                  jA                  d	|      S )a  Draw a chart using the PyDeck library.

        This supports 3D maps, point clouds, and more! More info about PyDeck
        at https://deckgl.readthedocs.io/en/latest/.

        These docs are also quite useful:

        - DeckGL docs: https://github.com/uber/deck.gl/tree/master/docs
        - DeckGL JSON docs: https://github.com/uber/deck.gl/tree/master/modules/json

        When using this command, Mapbox provides the map tiles to render map
        content. Note that Mapbox is a third-party product and Streamlit accepts
        no responsibility or liability of any kind for Mapbox or for any content
        or information made available by Mapbox.

        Mapbox requires users to register and provide a token before users can
        request map tiles. Currently, Streamlit provides this token for you, but
        this could change at any time. We strongly recommend all users create and
        use their own personal Mapbox token to avoid any disruptions to their
        experience. You can do this with the ``mapbox.token`` config option. The
        use of Mapbox is governed by Mapbox's Terms of Use.

        To get a token for yourself, create an account at https://mapbox.com.
        For more info on how to set config options, see
        https://docs.streamlit.io/develop/api-reference/configuration/config.toml.

        Parameters
        ----------
        pydeck_obj : pydeck.Deck or None
            Object specifying the PyDeck chart to draw.
        use_container_width : bool
            Whether to override the figure's native width with the width of
            the parent container. If ``use_container_width`` is ``True`` (default),
            Streamlit sets the width of the figure to match the width of the parent
            container. If ``use_container_width`` is ``False``, Streamlit sets the
            width of the chart to fit its contents according to the plotting library,
            up to the width of the parent container.
        width : int or None
            Desired width of the chart expressed in pixels. If ``width`` is
            ``None`` (default), Streamlit sets the width of the chart to fit
            its contents according to the plotting library, up to the width of
            the parent container. If ``width`` is greater than the width of the
            parent container, Streamlit sets the chart width to match the width
            of the parent container.

            To use ``width``, you must set ``use_container_width=False``.
        height : int or None
            Desired height of the chart expressed in pixels. If ``height`` is
            ``None`` (default), Streamlit sets the height of the chart to fit
            its contents according to the plotting library.
        on_select : "ignore" or "rerun" or callable
            How the figure should respond to user selection events. This controls
            whether or not the chart behaves like an input widget.
            ``on_select`` can be one of the following:

            - ``"ignore"`` (default): Streamlit will not react to any selection
              events in the chart. The figure will not behave like an
              input widget.
            - ``"rerun"``: Streamlit will rerun the app when the user selects
              data in the chart. In this case, ``st.pydeck_chart`` will return
              the selection data as a dictionary.
            - A ``callable``: Streamlit will rerun the app and execute the callable
              as a callback function before the rest of the app. In this case,
              ``st.pydeck_chart`` will return the selection data as a
              dictionary.

            If ``on_select`` is not ``"ignore"``, all layers must have a
            declared ``id`` to keep the chart stateful across reruns.
        selection_mode : "single-object" or "multi-object"
            The selection mode of the chart. This can be one of the following:

            - ``"single-object"`` (default): Only one object can be selected at
              a time.
            - ``"multi-object"``: Multiple objects can be selected at a time.

        key : str
            An optional string to use for giving this element a stable
            identity. If ``key`` is ``None`` (default), this element's identity
            will be determined based on the values of the other parameters.

            Additionally, if selections are activated and ``key`` is provided,
            Streamlit will register the key in Session State to store the
            selection state. The selection state is read-only.

        Returns
        -------
        element or dict
            If ``on_select`` is ``"ignore"`` (default), this command returns an
            internal placeholder for the chart element. Otherwise, this method
            returns a dictionary-like object that supports both key and
            attribute notation. The attributes are described by the
            ``PydeckState`` dictionary schema.

        Example
        -------
        Here's a chart using a HexagonLayer and a ScatterplotLayer. It uses either the
        light or dark map style, based on which Streamlit theme is currently active:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>> import pydeck as pdk
        >>>
        >>> chart_data = pd.DataFrame(
        ...     np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
        ...     columns=["lat", "lon"],
        ... )
        >>>
        >>> st.pydeck_chart(
        ...     pdk.Deck(
        ...         map_style=None,
        ...         initial_view_state=pdk.ViewState(
        ...             latitude=37.76,
        ...             longitude=-122.4,
        ...             zoom=11,
        ...             pitch=50,
        ...         ),
        ...         layers=[
        ...             pdk.Layer(
        ...                 "HexagonLayer",
        ...                 data=chart_data,
        ...                 get_position="[lon, lat]",
        ...                 radius=200,
        ...                 elevation_scale=4,
        ...                 elevation_range=[0, 1000],
        ...                 pickable=True,
        ...                 extruded=True,
        ...             ),
        ...             pdk.Layer(
        ...                 "ScatterplotLayer",
        ...                 data=chart_data,
        ...                 get_position="[lon, lat]",
        ...                 get_color="[200, 30, 0, 160]",
        ...                 get_radius=200,
        ...             ),
        ...         ],
        ...     )
        ... )

        .. output::
           https://doc-pydeck-chart.streamlit.app/
           height: 530px

        .. note::
           To make the PyDeck chart's style consistent with Streamlit's theme,
           you can set ``map_style=None`` in the ``pydeck.Deck`` object.

        Nzmapbox.tokenrg   )rg   re   zYou have passed zH to `on_select`. But only 'ignore', 'rerun', or a callable is supported.F)	on_changedefault_valuewrites_allowedenable_check_callback_rulesdeck_gl_json_chart)user_keyis_selection_activatedr3   r[   specform_idstring_value)ctxdeserializeron_change_handler
serializer
value_type)#r/   r   rK   rU   r$   to_jsonr[   r\   r]   _get_pydeck_tooltiptooltipr   
get_optionmapbox_tokenr   callabler   r3   extendr7   r   dgr
   r   r   rq   r   idrI   r   rR   rV   _enqueuerF   value)rM   rb   r[   r\   r]   r3   rc   r^   pydeck_protors   rp   rz   r|   ro   is_callbackserdewidget_states                    r6   rd   zPydeckMixin.pydeck_chart!  s   @ #} "::i(D%%'D +>(!&L"(L%j1#'::g#6L ((8(4L%Sk!*h!6//8K'"9+-uv  "''../CN/ST #9-K!=H$~y9d"$,7 $3477#;L =$'=-$7$,,LO )*E*"../7	/B) ??)L GG1<@\%7%788ww 4lCCr8   c                    t        d|       S )zGet our DeltaGenerator.r   )r
   )rM   s    r6   r   zPydeckMixin.dg  s     $d++r8   r`   )rb   Deck | Noner[   boolr\   
int | Noner]   r   r3   zLiteral['single-object']rc   zLiteral['ignore']r^   
Key | NonerX   r   )rb   r   r[   r   r\   r   r]   r   r3   r'   rc   z!Literal['rerun'] | WidgetCallbackr^   r   rX   rF   )rb   r   r[   r   r\   r   r]   r   r3   r'   rc   z+Literal['rerun', 'ignore'] | WidgetCallbackr^   r   rX   zDeltaGenerator | PydeckState)rX   r   )r>   r?   r@   r   rd   r   propertyr   rC   r8   r6   rZ   rZ     s    #' %) !
  "	
  
 %  
   #'
 %) !(77>

 "	

 
 
 &
 5
 
 

 
 N# #'iD %) !(7AIiDiD "	iD
 iD iD &iD ?iD iD 
&iD $iDV , ,r8   rZ   c                    | y t        | dd       }|&t        |j                  t              r|j                  S t        | dd       }|-t        |t              rt	        t        t
        t
        f   |      S y )Ndeck_widget_tooltip)getattrr*   rz   dictr
   r+   )rb   desk_widgetrz   s      r6   ry   ry     ss     *mT:K:k.A.A4#H""" j*d3Gz'48DcNG,,r8   )r3   z'SelectionMode | Iterable[SelectionMode]rX   z(set[PydeckProto.SelectionMode.ValueType])rb   r   rX   zdict[str, str] | None)8
__future__r   rK   dataclassesr   typingr   r   r   r   r	   r
   r   typing_extensionsr   	streamlitr   "streamlit.elements.lib.event_utilsr   !streamlit.elements.lib.form_utilsr   streamlit.elements.lib.policiesr   streamlit.elements.lib.utilsr   r   r   streamlit.errorsr   #streamlit.proto.DeckGlJsonChart_pb2r   r/   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   streamlit.runtime.stater   r   collections.abcr   r   pydeckr   streamlit.delta_generatorr   r$   rB   r'   r(   r7   r:   rF   rI   rZ   ry   rC   r8   r6   <module>r      s    #  !   (  B = A U U 2 N 9 V
 18
 QQAN'	#  ##BCy C/ + "';"'-"'Jh-9E h-V$)5 $. 8 8 86L, L,^r8   