
    ȯeiao                    x   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mZ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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. d dl/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 erd dl6m7Z7 d dl8Z9d dl:m;Z< d dl=m>Z> d dl?m@Z@  e!        ed   ZAdeBd<   eeAeCeA   eDeEeAf   ddf   ZFdeBd<   e	d   ZGdeBd<   h dZHd eBd!<    e)eI      ZJd"eBd#<    G d$ d%ed&'      ZK G d( d)ed&'      ZLe G d* d+             ZM	 	 	 	 d1d,ZNd2d-ZOd3d.ZP G d/ d0      ZQy)4    )annotationsN)	dataclass)	TYPE_CHECKINGAnyFinalLiteral	TypeAlias	TypedDictUnioncastoverload)Required)	type_util)make_deprecated_name_warningshow_deprecation_warning)current_form_id)HeightLayoutConfigWidthvalidate_heightvalidate_width)check_widget_policies) configure_streamlit_plotly_theme)Keycompute_and_register_element_idto_key)StreamlitAPIException)
get_logger)PlotlyChart)gather_metrics)get_script_run_ctx)WidgetCallbackregister_widget)AttributeDictionary)Iterable)
BaseFigure)DeltaGenerator)z	go.Figurezgo.Datar	   _AtomicFigureOrDatar&   zmpl.figure.FigureFigureOrData)lassopointsboxSelectionMode>   r,   r*   r+   zFinal[set[SelectionMode]]_SELECTION_MODESr   _LOGGERc                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)	PlotlySelectionStateat	  
    The schema for the Plotly 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.

    Attributes
    ----------
    points : list[dict[str, Any]]
        The selected data points in the chart, including the data points
        selected by the box and lasso mode. The data includes the values
        associated to each point and a point index used to populate
        ``point_indices``. If additional information has been assigned to your
        points, such as size or legend group, this is also included.

    point_indices : list[int]
        The numerical indices of all selected data points in the chart. The
        details of each identified point are included in ``points``.

    box : list[dict[str, Any]]
        The metadata related to the box selection. This includes the
        coordinates of the selected area.

    lasso : list[dict[str, Any]]
        The metadata related to the lasso selection. This includes the
        coordinates of the selected area.

    Example
    -------
    When working with more complicated graphs, the ``points`` attribute
    displays additional information. Try selecting points in the following
    example:

    >>> import plotly.express as px
    >>> import streamlit as st
    >>>
    >>> df = px.data.iris()
    >>> fig = px.scatter(
    ...     df,
    ...     x="sepal_width",
    ...     y="sepal_length",
    ...     color="species",
    ...     size="petal_length",
    ...     hover_data=["petal_width"],
    ... )
    >>>
    >>> event = st.plotly_chart(fig, key="iris", on_select="rerun")
    >>>
    >>> event.selection

    .. output::
        https://doc-chart-events-plotly-selection-state.streamlit.app
        height: 600px

    This is an example of the selection state when selecting a single point:

    >>> {
    >>>   "points": [
    >>>     {
    >>>       "curve_number": 2,
    >>>       "point_number": 9,
    >>>       "point_index": 9,
    >>>       "x": 3.6,
    >>>       "y": 7.2,
    >>>       "customdata": [
    >>>         2.5
    >>>       ],
    >>>       "marker_size": 6.1,
    >>>       "legendgroup": "virginica"
    >>>     }
    >>>   ],
    >>>   "point_indices": [
    >>>     9
    >>>   ],
    >>>   "box": [],
    >>>   "lasso": []
    >>> }

    zRequired[list[dict[str, Any]]]r+   zRequired[list[int]]point_indicesr,   r*   N__name__
__module____qualname____doc____annotations__     a/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/elements/plotly_chart.pyr1   r1   \   s#    Ob +*&&	''))r:   r1   F)totalc                      e Zd ZU dZded<   y)PlotlyStatea  
    The schema for the Plotly chart 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 ``PlotlySelectionState`` dictionary
        schema.

    Example
    -------
    Try selecting points by any of the three available methods (direct click,
    box, or lasso). The current selection state is available through Session
    State or as the output of the chart function.

    >>> import plotly.express as px
    >>> import streamlit as st
    >>>
    >>> df = px.data.iris()
    >>> fig = px.scatter(df, x="sepal_width", y="sepal_length")
    >>>
    >>> event = st.plotly_chart(fig, key="iris", on_select="rerun")
    >>>
    >>> event

    .. output::
        https://doc-chart-events-plotly-state.streamlit.app
        height: 600px

    zRequired[PlotlySelectionState]	selectionNr3   r9   r:   r;   r>   r>      s    %N .-r:   r>   c                       e Zd ZdZddZddZy)PlotlyChartSelectionSerdeziPlotlyChartSelectionSerde is used to serialize and deserialize the Plotly Chart
    selection state.
    c                    dg g g g di}||n't        dt        t        j                  |                  }d|vr|}t        dt        |            S )Nr?   )r+   r2   r,   r*   r>   )r   r$   jsonloads)selfui_valueempty_selection_stateselection_states       r;   deserializez%PlotlyChartSelectionSerde.deserialize   sk    !#	.
  "m%8H9M%NO 	 o-3OM#6#GHHr:   c                8    t        j                  |t              S )N)default)rC   dumpsstr)rE   rH   s     r;   	serializez#PlotlyChartSelectionSerde.serialize   s    zz/377r:   N)rF   z
str | Nonereturnr>   )rH   r>   rO   rM   )r4   r5   r6   r7   rI   rN   r9   r:   r;   rA   rA      s    I*8r:   rA   c                   t        | t              r| h}nt        |       }|j                  t              st        d|  dt               g }|D ]  }|dk(  r*|j                  t        j                  j                         2|dk(  r*|j                  t        j                  j                         a|dk(  sg|j                  t        j                  j                          t        |      S )z2Parse and check the user provided selection modes.zInvalid selection mode: z. Valid options are: r+   r*   r,   )
isinstancerM   setissubsetr.   r   appendPlotlyChartProtor-   POINTSLASSOBOX)selection_modeselection_mode_setparsed_selection_modesmodes       r;   parse_selection_moder]      s     .#&,- !0&&'78#&~&6 7""2!35
 	

  " N8"))*:*H*H*O*OPW_"))*:*H*H*N*NOU]"))*:*H*H*L*LMN %&&r:   c                L   | dk7  r| S d}t        |t              r"|j                  di       j                  d      }n	 |j                  j                  }|&t        |t        t        f      r|dkD  rt        |      S y# t
        t        f$ r t        j                  d       Y Ow xY w)a6  Resolve "content" width by inspecting the figure's layout width.

    For content width, we check if the plotly figure has an explicit width
    in its layout. If so, we use that as a pixel width. If not, we default
    to 700 pixels which matches the plotly.js default width.

    Args
    ----
    width : Width
        The original width parameter
    figure : Any
        The plotly figure object (Figure, dict, or other supported formats)

    Returns
    -------
    Width
        The resolved width (either original width, figure width as pixels, or 700)
    contentNlayoutwidthz!Could not parse width from figurer   i  )rQ   dictgetr`   ra   AttributeError	TypeErrorr/   debugintfloat)ra   figurefigure_widths      r;   _resolve_content_widthrk     s    ( 	
 L&$zz(B/33G<	?!==..L
 	 |c5\21<    	* 	?MM=>	?   A< <$B#"B#c                L   | dk7  r| S d}t        |t              r"|j                  di       j                  d      }n	 |j                  j                  }|&t        |t        t        f      r|dkD  rt        |      S y# t
        t        f$ r t        j                  d       Y Ow xY w)aC  Resolve "content" height by inspecting the figure's layout height.

    For content height, we check if the plotly figure has an explicit height
    in its layout. If so, we use that as a pixel height. If not, we default
    to 450 pixels which matches the plotly.js default height.

    Args
    ----
    height : Height
        The original height parameter
    figure : Any
        The plotly figure object (Figure, dict, or other supported formats)

    Returns
    -------
    Height
        The resolved height (either original height, figure height as pixels, or 450)
    r_   Nr`   heightz"Could not parse height from figurer   i  )rQ   rb   rc   r`   rn   rd   re   r/   rf   rg   rh   )rn   ri   figure_heights      r;   _resolve_content_heightrp   I  s    ( 
 M&$

8R044X>	@"MM00M
 	!}sEl3A=!!  	* 	@MM>?	@rl   c            
         e Zd Ze	 d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d       Zedd       Zy)PlotlyMixinNstretchr_   	streamlit)r+   r,   r*   )ra   rn   themekeyrY   c                    y Nr9   
rE   figure_or_datause_container_widthra   rn   ru   rv   	on_selectrY   kwargss
             r;   plotly_chartzPlotlyMixin.plotly_charty  s    " r:   rerun)ra   rn   ru   rv   r|   rY   c                    y rx   r9   ry   s
             r;   r~   zPlotlyMixin.plotly_chart  s    " r:   r~   ignore)ra   rn   ru   rv   r|   rY   configc                  |2t        t        ddddd      d       |rd	}nt        |t              sd
}t	        |d       t        |d       ddl}ddl}|
rt        d       |dvrt        d| d      |dvrt        |      st        d| d      t        |      }|dk7  }|r4t        |      }t        | j                  ||rt        d|      nddd|       t        j                  |d      r|j                   j#                  |      }n|j                   j%                  |d      }t'               }|xs d|_        t+        | j                        |_        |	xs i }	|j.                  j1                  |d      |_        t5        j6                  |	      |_        t;               }t=        d|d| j                  |j2                  |j8                  |||||      |_        tA        ||      }tC        ||      }|r|jD                  jG                  tI        |             tK               }tM        |j>                  t        |      r|nd|jN                  |jP                  |d      }tS        ||       }| j                  jU                  d||!       |jV                  S tS        ||       }| j                  jU                  d||!      S )"a8%  Display an interactive Plotly chart.

        `Plotly <https://plot.ly/python>`_ is a charting library for Python.
        The arguments to this function closely follow the ones for Plotly's
        ``plot()`` function.

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

        .. Important::
            You must install ``plotly>=4.0.0`` to use this command. Your app's
            performance may be enhanced by installing ``orjson`` as well. You
            can install all charting dependencies (except Bokeh) as an extra
            with Streamlit:

            .. code-block:: shell

               pip install streamlit[charts]

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

            The Plotly ``Figure`` or ``Data`` object to render. See
            https://plot.ly/python/ for examples of graph descriptions.

            .. note::
                If your chart contains more than 1000 data points, Plotly will
                use a WebGL renderer to display the chart. Different browsers
                have different limits on the number of WebGL contexts per page.
                If you have multiple WebGL contexts on a page, you may need to
                switch to SVG rendering mode. You can do this by setting
                ``render_mode="svg"`` within the figure. For example, the
                following code defines a Plotly Express line chart that will
                render in SVG mode when passed to ``st.plotly_chart``:
                ``px.line(df, x="x", y="y", render_mode="svg")``.

        width : "stretch", "content", 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.
            - ``"content"``: The width of the element matches the width of its
              content, but doesn't exceed 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 : "content", "stretch", or int
            The height of the chart element. This can be one of the following:

            - ``"content"`` (default): The height of the element matches the
              height of its content.
            - ``"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.
            - 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.

        use_container_width : bool or None
            Whether to override the figure's native width with the width of
            the parent container. This can be one of the following:

            - ``None`` (default): Streamlit will use the value of ``width``.
            - ``True``: Streamlit sets the width of the figure to match the
              width of the parent container.
            - ``False``: Streamlit sets the width of the figure 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"``.

        theme : "streamlit" or None
            The theme of the chart. If ``theme`` is ``"streamlit"`` (default),
            Streamlit uses its own design default. If ``theme`` is ``None``,
            Streamlit falls back to the default behavior of the library.

            The ``"streamlit"`` theme can be partially customized through the
            configuration options ``theme.chartCategoricalColors`` and
            ``theme.chartSequentialColors``. Font configuration options are
            also applied.

        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.

        on_select : "ignore" or "rerun" or callable
            How the figure should respond to user selection events. This
            controls whether or not the figure 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.plotly_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.plotly_chart`` will return the selection data
              as a dictionary.

        selection_mode : "points", "box", "lasso" or an Iterable of these
            The selection mode of the chart. This can be one of the following:

            - ``"points"``: The chart will allow selections based on individual
              data points.
            - ``"box"``: The chart will allow selections based on rectangular
              areas.
            - ``"lasso"``: The chart will allow selections based on freeform
              areas.
            - An ``Iterable`` of the above options: The chart will allow
              selections based on the modes specified.

            All selections modes are activated by default.

        config : dict or None
            A dictionary of Plotly configuration options. This is passed to
            Plotly's ``show()`` function. For more information about Plotly
            configuration options, see Plotly's documentation on `Configuration
            in Python <https://plotly.com/python/configuration-options/>`_.

        **kwargs
            Additional arguments accepted by Plotly's ``plot()`` function.

            This supports ``config``, a dictionary of Plotly configuration
            options. For more information about Plotly configuration options,
            see Plotly's documentation on `Configuration in Python
            <https://plotly.com/python/configuration-options/>`_.

            .. deprecated::
               ``**kwargs`` are deprecated and will be removed in a future
               release. Use ``config`` instead.

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

        Examples
        --------
        **Example 1: Basic Plotly chart**

        The example below comes from the examples at https://plot.ly/python.
        Note that ``plotly.figure_factory`` requires ``scipy`` to run.

        >>> import plotly.figure_factory as ff
        >>> import streamlit as st
        >>> from numpy.random import default_rng as rng
        >>>
        >>> hist_data = [
        ...     rng(0).standard_normal(200) - 2,
        ...     rng(1).standard_normal(200),
        ...     rng(2).standard_normal(200) + 2,
        ... ]
        >>> group_labels = ["Group 1", "Group 2", "Group 3"]
        >>>
        >>> fig = ff.create_distplot(
        ...     hist_data, group_labels, bin_size=[0.1, 0.25, 0.5]
        ... )
        >>>
        >>> st.plotly_chart(fig)

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

        **Example 2: Plotly Chart with configuration**

        By default, Plotly charts have scroll zoom enabled. If you have a
        longer page and want to avoid conflicts between page scrolling and
        zooming, you can use Plotly's configuration options to disable scroll
        zoom. In the following example, scroll zoom is disabled, but the zoom
        buttons are still enabled in the modebar.

        >>> import plotly.graph_objects as go
        >>> import streamlit as st
        >>>
        >>> fig = go.Figure()
        >>> fig.add_trace(
        ...     go.Scatter(
        ...         x=[1, 2, 3, 4, 5],
        ...         y=[1, 3, 2, 5, 4]
        ...     )
        ... )
        >>>
        >>> st.plotly_chart(fig, config = {'scrollZoom': False})

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

        Nr{   ra   z
2025-12-31znFor `use_container_width=True`, use `width='stretch'`. For `use_container_width=False`, use `width='content'`.F)include_st_prefix)show_in_browserrs   r_   T)allow_contentr   zVariable keyword arguments for `st.plotly_chart` have been deprecated and will be removed in a future release. Use the `config` argument instead to specify Plotly configuration options.)rt   NzYou set theme="us   " while Streamlit charts only support theme=”streamlit” or theme=None to fallback to the default library theme.)r   r   zYou have passed zH to `on_select`. But only 'ignore', 'rerun', or a callable is supported.r   r"   )	on_changedefault_valuewrites_allowedenable_check_callback_ruleszmatplotlib.figure.Figure)validate_figure )validater~   )
user_keykey_as_main_identitydgplotly_specplotly_configrY   is_selection_activatedru   ra   rn   string_value)on_change_handlerdeserializer
serializerctx
value_type)ra   rn   )layout_config),r   r   rQ   rg   r   r   	plotly.ioplotly.toolsr   callabler   r   r   r   r   is_typetoolsmpl_to_plotly!return_figure_from_figure_or_datarU   ru   r   form_idioto_jsonspecrC   rL   r   r!   r   idrk   rp   rY   extendr]   rA   r#   rI   rN   r   _enqueuevalue)rE   rz   r{   ra   rn   ru   rv   r|   rY   r   r}   plotlyr   is_callbackri   plotly_chart_protor   final_widthfinal_heightserdewidget_stater   s                         r;   r~   zPlotlyMixin.plotly_chart  s   L *$,) N&+ !&
 #!s+!uD1d3 $ ++'!% )! !  //8K'"9+ .7 7 
 Sk!*h!6! #9-K!?J$/;PT"$,7 ^-GH\\//?F\\CC D F ./#(;B %4TWW%="2"())"3"3FU"3"K$(JJv$6! "
 !@!&ww*//,33)#9!
 -UF;.vv>!--44$^4 ./E*"%%/7	/B)".. ??)L ){<PMGG 2-    %%%$;|Lww.m   
 	
r:   c                    t        d|       S )zGet our DeltaGenerator.r'   )r   )rE   s    r;   r   zPlotlyMixin.dg  s     $d++r:   rx   )rz   r)   r{   bool | Nonera   r   rn   r   ru   Literal['streamlit'] | Nonerv   
Key | Noner|   zLiteral['ignore']rY   'SelectionMode | Iterable[SelectionMode]r}   r   rO   r'   )rz   r)   r{   r   ra   r   rn   r   ru   r   rv   r   r|   z!Literal['rerun'] | WidgetCallbackrY   r   r}   r   rO   r>   )rz   r)   r{   r   ra   r   rn   r   ru   r   rv   r   r|   z+Literal['rerun', 'ignore'] | WidgetCallbackrY   r   r   zdict[str, Any] | Noner}   r   rO   zDeltaGenerator | PlotlyState)rO   r'   )r4   r5   r6   r   r~   r    propertyr   r9   r:   r;   rr   rr   x  s    ,0
 !"-8C
$ )
   +  % @   
! $  ,0
 !"-87>C
$ )
   +  5 @   
! $ N# ,0f

 !"-8AIC

 )-f
$f
 )f

 f
 f
 +f
 f
 ?f
 @f
 &f
  !f
" 
&#f
 $f
P , ,r:   rr   )rY   r   rO   z-set[PlotlyChartProto.SelectionMode.ValueType])ra   r   ri   r   rO   r   )rn   r   ri   r   rO   r   )R
__future__r   rC   dataclassesr   typingr   r   r   r   r	   r
   r   r   r   typing_extensionsr   rt   r   streamlit.deprecation_utilr   r   !streamlit.elements.lib.form_utilsr   #streamlit.elements.lib.layout_utilsr   r   r   r   r   streamlit.elements.lib.policiesr   -streamlit.elements.lib.streamlit_plotly_themer   streamlit.elements.lib.utilsr   r   r   streamlit.errorsr   streamlit.loggerr   streamlit.proto.PlotlyChart_pb2r   rU   streamlit.runtime.metrics_utilr    7streamlit.runtime.scriptrunner_utils.script_run_contextr!   streamlit.runtime.stater"   r#   streamlit.utilr$   collections.abcr%   
matplotlibmplplotly.graph_objs
graph_objsgoplotly.basedatatypesr&   streamlit.delta_generatorr'   r(   r8   listrb   rM   r)   r-   r.   r4   r/   r1   r>   rA   r]   rk   rp   rr   r9   r:   r;   <module>r      sb   #  !
 
 
 '  >  B V U 2 ' K 9 V C .("/8 ! "!&" Y   	 	!	!"	i 	 ##;<y <.H + HH% %U*9E U*p(.)5 (.V 8 8 8<';'2'8,^,^S, S,r:   