
    &ej"                     \   U d Z ddlZddlZddlmZmZmZmZ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 ddlmZ ddlmZ dd	lmZ dd
lmZ er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(Zde'j)        _*        n# e+$ r Y nw xY w ee,          Z-ee.d<   ed         Z/ee.d<   h dZ0e	e/         e.d<   e
d         Z1ee.d<   e
e1ee1         ee2e1f         ddf         Z3ee.d<    G d d          Z4dede3de5de/de
ded         f         ded dfd!Z6ej7        d"eded d#fd$            Z8d%e2d e2fd&Z9dS )'z$Streamlit support for Plotly charts.    N)TYPE_CHECKINGAnyDictListSetUnioncast)FinalLiteral	TypeAlias)	type_util)StreamlitAPIException)
get_logger)PlotlyChart)caching)gather_metrics)
BaseFigure)DeltaGenerator	streamlitLOGGER)r   privatepublicsecretSharingMode>   r   r   r   r   SHARING_MODES)	go.Figurezgo.Data_AtomicFigureOrDatar   matplotlib.figure.FigureFigureOrDatac                       e Zd Z ed          	 	 	 ddededededed         f         d	e	d
dfd            Z
edd            ZdS )PlotlyMixinplotly_chartFr   figure_or_datause_container_widthsharingthemeNkwargsreturnr   c                     t                      }|dk    r|dk    rt          d| d          t          |||||fi | | j                            d|          S )a	  Display an interactive Plotly chart.

        Plotly is a charting library for Python. The arguments to this function
        closely follow the ones for Plotly's `plot()` function. You can find
        more about Plotly at https://plot.ly/python.

        To show Plotly charts in Streamlit, call `st.plotly_chart` wherever you
        would call Plotly's `py.plot` or `py.iplot`.

        Parameters
        ----------
        figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,            dict/list of plotly.graph_objs.Figure/Data

            See https://plot.ly/python/ for examples of graph descriptions.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over the figure's native `width` value.

        sharing : "streamlit", "private", "secret", or "public"
            Use "streamlit" to insert the plot and all its dependencies
            directly in the Streamlit app using plotly's offline mode (default).
            Use any other sharing mode to send the chart to Plotly chart studio, which
            requires an account. See https://plot.ly/python/chart-studio/ for more information.

        theme : "streamlit" or None
            The theme of the chart. Currently, we only support "streamlit" for the Streamlit
            defined design or None to fallback to the default behavior of the library.

        **kwargs
            Any argument accepted by Plotly's `plot()` function.

        Example
        -------
        The example below comes straight from the examples at
        https://plot.ly/python:

        >>> import streamlit as st
        >>> import numpy as np
        >>> import plotly.figure_factory as ff
        >>>
        >>> # Add histogram data
        >>> x1 = np.random.randn(200) - 2
        >>> x2 = np.random.randn(200)
        >>> x3 = np.random.randn(200) + 2
        >>>
        >>> # Group data together
        >>> hist_data = [x1, x2, x3]
        >>>
        >>> group_labels = ['Group 1', 'Group 2', 'Group 3']
        >>>
        >>> # Create distplot with custom bin_size
        >>> fig = ff.create_distplot(
        ...         hist_data, group_labels, bin_size=[.1, .25, .5])
        >>>
        >>> # Plot!
        >>> st.plotly_chart(fig, use_container_width=True)

        .. output::
           https://doc-plotly-chart.streamlit.app/
           height: 400px

        r   NzYou set theme="us   " while Streamlit charts only support theme=”streamlit” or theme=None to fallback to the default library theme.r"   )PlotlyChartProtor   marshalldg_enqueue)selfr#   r$   r%   r&   r'   plotly_chart_protos          ?lib/python3.11/site-packages/streamlit/elements/plotly_chart.pyr"   zPlotlyMixin.plotly_chartQ   s    Z .//KETMM' ]%  ]  ]  ]   		
 	
 	
 	
 	
 w0BCCC    c                 "    t          d|           S )zGet our DeltaGenerator.r   )r	   )r.   s    r0   r,   zPlotlyMixin.dg   s     $d+++r1   )Fr   r   )r(   r   )__name__
__module____qualname__r   r   boolr   r   r   r   r"   propertyr,    r1   r0   r!   r!   P   s        ^N## %**3>YD YD$YD "YD 	YD
 T7;//0YD YD 
YD YD YD $#YDv , , , X, , ,r1   r!   protor#   r$   r%   r&   r'   r(   c                    ddl }t          j        |d          r|j                            |          }n|j                            |d          }t          |t                    r|                                t          vrt          d|z            || _        |dk    rddl}t          |                    di                     }|                    d	|                    d
d                     |                    d|                    dd                     |j                            |d          | j        _        t)          j        |          | j        _        n$t/          |f|dd|}	t1          |	          | _        |pd| _        dS )zXMarshall a proto with a Plotly spec.

    See DeltaGenerator.plotly_chart for docs.
    r   Nr   T)validate_figurez)Invalid sharing mode for Plotly chart: %sr   configshowLink	show_linkFlinkText	link_text)validate)r%   	auto_open )plotly.toolsr   is_typetoolsmpl_to_plotly!return_figure_from_figure_or_data
isinstancestrlowerr   
ValueErrorr$   	plotly.iodictget
setdefaultioto_jsonfigurespecjsondumpsr<   _plot_to_url_or_load_cached_url_get_embed_urlurlr&   )
r9   r#   r$   r%   r&   r'   plotlyrS   r<   rY   s
             r0   r+   r+      s     )CDD 
++N;; ??D @ 
 
 gs## Pw}}m'K'KDwNOOO 3E+fjj2..//*fjje&D&DEEE*fjje&D&DEEE"I--fu-EE"j00 .
#u
 
8>
 
 #3''	+2EKKKr1   argsr   c                  X    	 ddl m} n# t          $ r	 ddlm} Y nw xY w |j        | i |S )zCall plotly.plot wrapped in st.cache.

    This is so we don't unnecessarily upload data to Plotly's SASS if nothing
    changed since the previous upload.
    r   N)chart_studio.plotlyrZ   ImportErrorplotly.plotlyplot)r[   r'   plys      r0   rW   rW      sh    $))))))) $ $ $########$ 38T$V$$$s   	 rY   c                     t           j                            |           }|                    |j        dz             }t           j                            |          S )Nz.embed)path)urllibparseurlparse_replacerc   
urlunparse)rY   
parsed_urlparsed_embed_urls      r0   rX   rX      sN    &&s++J "**
(0J*KK<""#3444r1   ):__doc__rU   urllib.parserd   typingr   r   r   r   r   r   r	   typing_extensionsr
   r   r   r   r   streamlit.errorsr   streamlit.loggerr   streamlit.proto.PlotlyChart_pb2r   r*    streamlit.runtime.legacy_cachingr   streamlit.runtime.metrics_utilr   
matplotlibplotly.graph_objs
graph_objsgoplotly.basedatatypesr   streamlit.delta_generatorr   rM   rQ   pio-streamlit.elements.lib.streamlit_plotly_theme	templatesdefaultModuleNotFoundErrorr3   r   __annotations__r   r   r   rJ   r   r!   r6   r+   cacherW   rX   r8   r1   r0   <module>r      s;   + * *      C C C C C C C C C C C C C C C C C C 7 7 7 7 7 7 7 7 7 7       2 2 2 2 2 2 ' ' ' ' ' ' K K K K K K 4 4 4 4 4 4 9 9 9 9 9 9 9""""""//////888888		8888'CM 	 	 	 	D	
 
8$$ $ $ $ !KLY L L L	# 	# 	#s; 	 	 	 "'" Y     	 	!	!" 	i 	 	 	`, `, `, `, `, `, `, `,F// / / 	/
 w{++,/ / 
/ / / /d 	%3 %# %+ % % % %	5 	5 	5 	5 	5 	5 	5 	5s   %A< <BB