L iG@UdZddlmZddlZddlZddlmZmZmZm Z ddl m Z m Z ddl mZmZddlmZddlmZmZmZmZdd lmZmZmZmZmZdd lmZdd lm Z!dd l"m#Z#erdd l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+e,ejZZ.de/d<hdZ0de/d<hdZ1de/d<dZ2de/d<dZ3de/d<dZ4de/d<gdZ5de/d<Gd d!Z6 d)d"Z7 d*d#Z8 d+d$Z9 d,d%Z: d-d&Z;d.d'Z< d/d(Z=y)0z+A wrapper for simple PyDeck scatter charts.) annotationsN) TYPE_CHECKINGAnyFinalcast)configdataframe_util)make_deprecated_name_warningshow_deprecation_warning)deck_gl_json_chart)Color IntColorTuple is_color_liketo_int_color_tuple)HeightWithoutContent LayoutConfigWidthWithoutContentvalidate_heightvalidate_width)StreamlitAPIException)DeckGlJsonChart)gather_metrics) Collection) DataFrame)Data)DeltaGeneratorzFinal[dict[str, Any]] _DEFAULT_MAP>LATlatLATITUDElatituder_DEFAULT_LAT_COL_NAMES>LONlon LONGITUDE longitude_DEFAULT_LON_COL_NAMES)r_DEFAULT_COLORd _DEFAULT_SIZE _DEFAULT_ZOOM_LEVEL)ihZ-g6@g&@g@g/$@g"~?g"~?gI +?gI +?gI +?gI +?gI +?gI +?g{Gzt?g~jth?gMbP?gMb@?gMb0? _ZOOM_LEVELSc zeZdZed dddddddddd d dZed dZy) MapMixinmapNstretchi)r!r&colorsizezoomwidthheightuse_container_widthc | ttdddddd| rd}t|d t|d t } t ||||||} t | | t|| } |jjd | | S) aDisplay 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, a service called Carto_ provides the map tiles to render map content. If you're using advanced PyDeck features you may need to obtain an API key from Carto first. You can do that as ``pydeck.Deck(api_keys={"carto": YOUR_KEY})`` or by setting the CARTO_API_KEY environment variable. See `PyDeck's documentation`_ for more information. Another common provider for map tiles is Mapbox_. If you prefer to use that, you'll need to create an account at https://mapbox.com and specify your Mapbox key when creating the ``pydeck.Deck`` object. You can do that as ``pydeck.Deck(api_keys={"mapbox": YOUR_KEY})`` or by setting the MAPBOX_API_KEY environment variable. .. _Carto: https://carto.com .. _Mapbox: https://mapbox.com .. _PyDeck's documentation: https://deckgl.readthedocs.io/en/latest/deck.html Carto and Mapbox are third-party products and Streamlit accepts no responsibility or liability of any kind for Carto or Mapbox, or for any content or information made available by Carto or Mapbox. The use of Carto or Mapbox is governed by their respective Terms of Use. 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. width : "stretch" or int The width of the chart element. This can be one of the following: - ``"stretch"`` (default): The width of the element matches the width of the parent container. - An integer specifying the width in pixels: The element has a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container. height : "stretch" or int The height of the chart element. This can be one of the following: - An integer specifying the height in pixels: The element has a fixed height. If the content is larger than the specified height, scrolling is enabled. This is ``500`` by default. - ``"stretch"``: The height of the element matches the height of its content or the height of the parent container, whichever is larger. If the element is not in a parent container, the height of the element matches the height of its content. use_container_width : bool or None Whether to override the map's native width with the width of the parent container. This can be one of the following: - ``None`` (default): Streamlit will use the map's default behavior. - ``True``: Streamlit sets the width of the map to match the width of the parent container. - ``False``: Streamlit sets the width of the map to fit its contents according to the plotting library, up to the width of the parent container. .. deprecated:: ``use_container_width`` is deprecated and will be removed in a future release. For ``use_container_width=True``, use ``width="stretch"``. Examples -------- >>> import pandas as pd >>> import streamlit as st >>> from numpy.random import default_rng as rng >>> >>> df = pd.DataFrame( >>> rng(0).standard_normal((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 pandas as pd >>> import streamlit as st >>> from numpy.random import default_rng as rng >>> >>> df = pd.DataFrame( ... { ... "col1": rng(0).standard_normal(1000) / 50 + 37.76, ... "col2": rng(1).standard_normal(1000) / 50 + -122.4, ... "col3": rng(2).standard_normal(1000) * 100, ... "col4": rng(3).standard_normal((1000, 4)).tolist(), ... } ... ) >>> >>> st.map(df, latitude="col1", longitude="col2", size="col3", color="col4") .. output:: https://doc-map-color.streamlit.app/ height: 600px r=r;z 2025-12-31zqFor `use_container_width=True`, use `width='stretch'`. For `use_container_width=False`, specify an integer width.F)include_st_prefix)show_in_browserr7) allow_content)r;r<r ) layout_config) r r rrDeckGlJsonChartPrototo_deckgl_jsonmarshallrdg_enqueue) selfdatar!r&r8r9r:r;r<r= map_proto deck_gl_jsonrBs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/map.pyr6z MapMixin.mapYsV  * $,) Q&+ !& #! uE2e4(* %dHiudS L)$5@ ww )=   ctd|S)zGet our DeltaGenerator.r)r)rHs rLrFz MapMixin.dg!s$d++rM)N)rIrr! str | Noner&rOr8zNone | str | Colorr9None | str | floatr: int | Noner;rr<rr=z bool | Nonereturnr)rRr)__name__ __module__ __qualname__rr6propertyrFrMrLr5r5XsEE  $ $$(#'%.'*+/E E  E  E " E !E E #E %E )E  E E N,,rMr5c |tjtSt|dr%|jrtjtSt j |}t|d|t}t|d|t}t||t\} } t||t\} } t||| | hD cgc]} | | c} }||}t|| | }t||||\}}}t!j"t}||dd<||dd<||dd<dd|d|d | d d ||j%d d g|d<tj|Scc} w)Nemptyr!r&initialViewStater:ScatterplotLayerz@@=[, ]metersrecords)z@@type getPosition getRadiusradiusMinPixels radiusUnits getFillColorrIlayers)jsondumpsrhasattrrYr 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_detailscopydeepcopyto_dict)rIrr$r9r8r:df lat_col_name lon_col_namesize_arg size_col_name color_argcolor_col_namec used_columnsconverted_color_arg center_lat center_londefaults rLrDrD's |zz,'' tW$**zz,''  5 5d ;B+B CAWXL+ K4L6b$ NHm 7E> RI~#L-P }  L L B6r9nU#8 L,$ D*jmmL)G.8G  +/9G  ,*.G ')!,r,qA! #/JJy)  GH ::g = s; Ect|tr||jvr|}nd}|D]}||jvs|}n|ndjt t t |}djt t t|j}td|d|d||}t||jjrtd|d|S)z=Returns the column name to be used for latitude or longitude.Nr\zMap data must contain a z column named: z. Existing columns: zColumn zB is not allowed to contain null values, such as NaN, NaT, or None.) isinstancestrcolumnsjoinr6reprrmlistranyisnaarray) rIhuman_readable_namecol_name_from_userdefault_col_namescol_namecandidate_col_namerzformatted_allowed_col_nameformmated_col_namess rLrkrkes$c*/AT\\/Q%"" ADLL %&"   %)-3tVDU=V3W)X &"&))Cd4<<6H,I"J '*+>*?-..BCVBWY & 4>   & &'#hZ $ $  OrMclt|tr||jvr |}d|}||fSd}||n|}||fS)aTake 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)rrr)rI value_or_name default_valuer pydeck_args rLrlrlsU$-%-4<<*G 8*% x  &3&;] x rMcd}|vt||dkDrVt||jdr;|jdd|fj t |jdd|f<|}|St d|d| t |}|S)aRConverts 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. NrzColumn "z*" does not appear to contain valid colors.)lenriatlocr6rr)rIrxry color_arg_outs rLrnrns15M! tN# $q (]4;O;S;STU;V-W*.((1n3D*E*I*I"+DHHQ& '" (>**TU   *95 rMc.||j}||j}||j}||j}||zdz }||zdz } t||z } t||z } |t| | } t| }||| fS)z3Auto-set viewport when not fully specified by user.g@)minmaxabs_get_zoom_level) rIrtrur:min_latmax_latmin_lonmax_lonr}r~ range_lon range_latlongitude_distances rLroros< $$&G< $$&G< $$&G< $$&GG#s*JG#s*JGg%&IGg%&I | I612 Z ''rMctttdz D]$}t|dz|cxkrt|ks |cS&tS)a9Get 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. )rangerr3r/)distanceis rLrrsN 3|$q( ) A  <\!_ <H = rMc^||_d|_tjd}|r||_yy)zMarshall a map proto with the given pydeck JSON specification. Layout configuration (width, height, etc.) is handled by the LayoutConfig system and not through proto fields. z mapbox.tokenN)rgidr get_option mapbox_token) pydeck_proto pydeck_jsonrs rLrErEs3$LLO$$^4L$0 !rM)rIrrrOr$rOr9rPr8zNone | str | Collection[float]r:rQrRr) rIrrrrrOrzset[str]rRr)rIrrrrrrRztuple[str, str | None])rIrrxrryrOrRzNone | str | IntColorTuple) rIrrtrrurr:rQrRztuple[int, float, float])rfloatrRint)rrCrrrRNone)>__doc__ __future__rrprgtypingrrrr streamlitrr streamlit.deprecation_utilr r streamlit.elementsr !streamlit.elements.lib.color_utilr rrr#streamlit.elements.lib.layout_utilsrrrrrstreamlit.errorsr#streamlit.proto.DeckGlJsonChart_pb2rrCstreamlit.runtime.metrics_utilrcollections.abcrpandasrstreamlit.dataframe_utilrstreamlit.delta_generatorrdict EMPTY_MAPr__annotations__r"r'r+r-r/r3r5rDrkrlrnrorrErWrMrLrs2" 22,2 3W9* -8'++=+G+G&H #H!GF HH)) uU e2L,L,^; ; ; ;  ; * ;  ; ;|* **#* *  *Z      :" """ "J( (#&(69(AK(((01&11 1rM