
    gC                    .   U d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mc mZ ddlmZmZ ddlmZmZmZmZ ddlmZ ddlmZ dd	lmZ erdd
lmZ ddlmZ ddl m!Z! ddl"m#Z#  e$ejJ                        Z&de'd<   h dZ(de'd<   h dZ)de'd<   dZ*de'd<   dZ+de'd<   dZ,de'd<   g dZ-de'd<    G d d      Z.	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&dZ/	 	 	 	 	 	 	 	 	 	 d'd Z0	 	 	 	 	 	 	 	 d(d!Z1	 	 	 	 	 	 	 	 d)d"Z2	 	 	 	 	 	 	 	 	 	 d*d#Z3d+d$Z4	 	 d,	 	 	 	 	 	 	 	 	 	 	 d-d%Z5y).z+A wrapper for simple PyDeck scatter charts.    )annotationsN)TYPE_CHECKINGAnyFinalcast)configdataframe_util)ColorIntColorTupleis_color_liketo_int_color_tuple)StreamlitAPIException)DeckGlJsonChart)gather_metrics)
Collection)	DataFrame)Data)DeltaGeneratorzFinal[dict[str, Any]]_DEFAULT_MAP>   LATlatLATITUDElatituder   _DEFAULT_LAT_COL_NAMES>   LONlon	LONGITUDE	longitude_DEFAULT_LON_COL_NAMES)      r      _DEFAULT_COLORd   _DEFAULT_SIZE   _DEFAULT_ZOOM_LEVEL)ih     Z   -   g     6@g     &@g     @g/$@g"~?g"~?gI+?gI+?gI+?gI+?gI+?gI+?g{Gzt?g~jth?gMbP?gMb@?gMb0?_ZOOM_LEVELSc                  z    e Zd Z ed      	 dddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zed	d       Zy)
MapMixinmapNT)r   r   colorsizezoomuse_container_widthwidthheightc          	         d}
t               }t        ||||||
|      }t        |||||	       | j                  j	                  d|      S )a	  Display a map with a scatterplot overlaid onto it.

        This is a wrapper around ``st.pydeck_chart`` to quickly create
        scatterplot charts on top of a map, with auto-centering and auto-zoom.

        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
        ----------
        data : Anything supported by st.dataframe
            The data to be plotted.

        latitude : str or None
            The name of the column containing the latitude coordinates of
            the datapoints in the chart.

            If None, the latitude data will come from any column named 'lat',
            'latitude', 'LAT', or 'LATITUDE'.

        longitude : str or None
            The name of the column containing the longitude coordinates of
            the datapoints in the chart.

            If None, the longitude data will come from any column named 'lon',
            'longitude', 'LON', or 'LONGITUDE'.

        color : str or tuple or None
            The color of the circles representing each datapoint.

            Can be:

            - None, to use the default color.
            - A hex string like "#ffaa00" or "#ffaa0088".
            - An RGB or RGBA tuple with the red, green, blue, and alpha
              components specified as ints from 0 to 255 or floats from 0.0 to
              1.0.
            - The name of the column to use for the color. Cells in this column
              should contain colors represented as a hex string or color tuple,
              as described above.

        size : str or float or None
            The size of the circles representing each point, in meters.

            This can be:

            - None, to use the default size.
            - A number like 100, to specify a single size to use for all
              datapoints.
            - The name of the column to use for the size. This allows each
              datapoint to be represented by a circle of a different size.

        zoom : int
            Zoom level as specified in
            https://wiki.openstreetmap.org/wiki/Zoom_levels.

        use_container_width : bool
            Whether to override the map's native width with the width of
            the parent container. If ``use_container_width`` is ``True``
            (default), Streamlit sets the width of the map 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.

        Examples
        --------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(
        ...     np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
        ...     columns=["lat", "lon"],
        ... )
        >>> st.map(df)

        .. output::
           https://doc-map.streamlit.app/
           height: 600px

        You can also customize the size and color of the datapoints:

        >>> st.map(df, size=20, color="#0044ff")

        And finally, you can choose different columns to use for the latitude
        and longitude components, as well as set size and color of each
        datapoint dynamically based on other columns:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(
        ...     {
        ...         "col1": np.random.randn(1000) / 50 + 37.76,
        ...         "col2": np.random.randn(1000) / 50 + -122.4,
        ...         "col3": np.random.randn(1000) * 100,
        ...         "col4": np.random.rand(1000, 4).tolist(),
        ...     }
        ... )
        >>>
        >>> st.map(df, latitude="col1", longitude="col2", size="col3", color="col4")

        .. output::
           https://doc-map-color.streamlit.app/
           height: 600px

        N)r3   r4   deck_gl_json_chart)DeckGlJsonChartPrototo_deckgl_jsonmarshalldg_enqueue)selfdatar   r   r/   r0   r1   r2   r3   r4   	map_style	map_protodeck_gl_jsons                K/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/map.pyr.   zMapMixin.mapN   s[    D 	(*	%(ItUIt
 	|%8f	
 ww 4i@@    c                    t        d|       S )zGet our DeltaGenerator.r   )r   )r<   s    rA   r:   zMapMixin.dg   s     $d++rB   )N)r=   r   r   
str | Noner   rD   r/   zNone | str | Colorr0   None | str | floatr1   
int | Noner2   boolr3   rF   r4   rF   returnr   )rH   r   )__name__
__module____qualname__r   r.   propertyr:    rB   rA   r-   r-   M   s    E iA  $ $$(#'$( !iAiA 	iA
 iA "iA !iA iA "iA iA iA 
iA iAV , ,rB   r-   c           	        | t        j                  t              S t        | d      r%| j                  rt        j                  t              S t        j                  |       }t        |d|t              }t        |d|t              }	t        ||t              \  }
}t        ||t              \  }}t        ||	||hD cg c]  }|| c}      }||   }t        |||      }t        |||	|      \  }}}t!        j"                  t              }||d   d<   ||d   d<   ||d   d<   dd|	 d| d	|
d
d||j%                  d      dg|d<   |r%t'        j(                  d      st+        d      ||d<   t        j                  |      S c c}w )Nemptyr   r   initialViewStater1   ScatterplotLayerz@@=[, ]   metersrecords)z@@typegetPosition	getRadiusradiusMinPixelsradiusUnitsgetFillColorr=   layerszmapbox.tokenziYou need a Mapbox token in order to select a map type. Refer to the docs for st.map for more information.mapStyle)jsondumpsr   hasattrrO   r	   convert_anything_to_pandas_df_get_lat_or_lon_col_namer   r   _get_value_and_col_namer%   r#   sorted_convert_color_arg_or_column_get_viewport_detailscopydeepcopyto_dictr   
get_optionr   )r=   r   r   r0   r/   r>   r1   dflat_col_namelon_col_namesize_argsize_col_name	color_argcolor_col_namecused_columns
center_lat
center_londefaults                      rA   r8   r8      s    |zz,''
 tW$**zz,''		5	5d	;B+B
CAWXL+
K4L 6b$NHm 7E> RI~  #L-P	
P} P	
L 
L	B,RNKI#8
L,$ D*j mmL)G.8G
+/9G,*.G' )!,r,qA! #%JJy)	

GH   0'E  (
::gM	
s   ;Fc                   t        |t              r|| j                  v r|}nd}|D ]  }|| j                  v s|} n |ndj                  t	        t
        t        |                  }dj                  t	        t
        t        | j                                    }t        d| d| d|       |}t        | |   j                         j                        rt        d| d      |S )z=Returns the column name to be used for latitude or longitude.NrR   zMap data must contain a z column named: z. Existing columns: zColumn zB is not allowed to contain null values, such as NaN, NaT, or None.)
isinstancestrcolumnsjoinr.   reprrd   listr   anyisnullarray)	r=   human_readable_namecol_name_from_userdefault_col_namescol_namecandidate_col_namerr   formatted_allowed_col_nameformmated_col_namess	            rA   rb   rb   G  s     $c*/AT\\/Q% ""ADLL %&" #
 %)-3tVDU=V3W)X&"&))Cd4<<6H,I"J'*+>*?-..BCVBWY 
 *H 4>  "(()#hZ  $ $
 	

 OrB   c                t    t        |t              r|| j                  v r|}d| }||fS d}||}||fS |}||fS )a  Take a value_or_name passed in by the Streamlit developer and return a PyDeck
    argument and column name for that property.

    This is used for the size and color properties of the chart.

    Example:
    - If the user passes size=None, this returns the default size value and no column.
    - If the user passes size=42, this returns 42 and no column.
    - If the user passes size="my_col_123", this returns "@@=my_col_123" and "my_col_123".
    z@@=N)rx   ry   rz   )r=   value_or_namedefault_valuer   
pydeck_args        rA   rc   rc   u  sh    $ -%-4<<*G 8*%
 x  &J x 'JxrB   c                :   d}|t        | |         dkD  rSt        | |   j                  d         r8| j                  dd|f   j	                  t
              | j                  dd|f<   nt        d| d      t        |t              sJ |}|S |t        |      }|S )aR  Converts color to a format accepted by PyDeck.

    For example:
    - If color_arg is "#fff", then returns (255, 255, 255, 255).
    - If color_col_name is "my_col_123", then it converts everything in column my_col_123 to
      an accepted color format such as (0, 100, 200, 255).

    NOTE: This function mutates the data argument.
    Nr   zColumn "z*" does not appear to contain valid colors.)	lenr   iatlocr.   r   r   rx   ry   )r=   rp   rq   color_arg_outs       rA   re   re     s     15M!tN#$q(]4;O;S;STU;V-W*.((1n3D*E*I*I"+DHHQ&' (>**TU 
 )S)))!
  
	*95rB   c                *   | |   j                         }| |   j                         }| |   j                         }| |   j                         }||z   dz  }||z   dz  }	t        ||z
        }
t        ||z
        }||
|kD  r|
}n|}t        |      }|||	fS )z3Auto-set viewport when not fully specified by user.g       @)minmaxabs_get_zoom_level)r=   rl   rm   r1   min_latmax_latmin_lonmax_lonrt   ru   	range_lon	range_latlongitude_distances                rA   rf   rf     s     < $$&G< $$&G< $$&G< $$&GG#s*JG#s*JGg%&IGg%&I|y !*!*12Z''rB   c                    t        t        t              dz
        D ]$  }t        |dz      | cxk  rt        |   k  s |c S  & t        S )a9  Get the zoom level for a given distance in degrees.

    See https://wiki.openstreetmap.org/wiki/Zoom_levels for reference.

    Parameters
    ----------
    distance : float
        How many degrees of longitude should fit in the map.

    Returns
    -------
    int
        The zoom level, from 0 to 20.

       )ranger   r+   r'   )distanceis     rA   r   r     sI      3|$q()A<\!_<H = *
 rB   c                R    || _         || _        |r|| _        |r|| _        d| _        y )N )r^   r2   r3   r4   id)pydeck_protopydeck_jsonr2   r4   r3   s        rA   r9   r9     s1     $L':L$"$LOrB   )r=   r   r   rD   r   rD   r0   rE   r/   zNone | str | Collection[float]r>   rD   r1   rF   rH   ry   )
r=   r   r   ry   r   rD   r   zset[str]rH   ry   )r=   r   r   r   r   r   rH   ztuple[Any, str | None])r=   r   rp   zstr | Colorrq   rD   rH   zNone | str | IntColorTuple)
r=   r   rl   ry   rm   ry   r1   rF   rH   ztuple[int, float, float])r   floatrH   int)NN)r   r7   r   ry   r2   rG   r4   rF   r3   rF   rH   None)6__doc__
__future__r   rg   r^   typingr   r   r   r   %streamlit.elements.deck_gl_json_chartelementsr6   	streamlitr   r	   !streamlit.elements.lib.color_utilr
   r   r   r   streamlit.errorsr   #streamlit.proto.DeckGlJsonChart_pb2r   r7   streamlit.runtime.metrics_utilr   collections.abcr   pandasr   streamlit.dataframe_utilr   streamlit.delta_generatorr   dict	EMPTY_MAPr   __annotations__r   r   r#   r%   r'   r+   r-   r8   rb   rc   re   rf   r   r9   rM   rB   rA   <module>r      s   2 "   2 2 B B ,  3 W 9* -8 '++=+G+G&H# H !G  F H  H) )u  U e 2p, p,fD
D	D 
D 	D
 *D D D 	DN+
++ #+  	+
 	+\ 
     	 @$
$$ $  	$N(
(#&(69(AK((.8 &  	
  
rB   