o
    h@+                     @  sR  U d dl mZ d dl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 d dlmZ d d	lmZ d d
lmZ d dlmZ erYd dlZd dlmZ e
dde e!e"df Z#de$d< e
e e!e"df Z%de$d< e	d Z&de$d< eddG dd dZ'G dd dZ(d,ddZ)d-d!d"Z*d.d$d%Z+d/d'd(Z,d0d*d+Z-dS )1    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyLiteralUnioncast)	TypeAlias)maybe_raise_label_warnings)LabelVisibility get_label_visibility_proto_value)StreamlitAPIException)Metric)gather_metrics)
clean_textN)DeltaGeneratorznp.integer[Any]znp.floating[Any]r
   ValueDelta)normalinverseoff
DeltaColorT)frozenc                   @  s   e Zd ZU ded< ded< dS )MetricColorAndDirectionz!MetricProto.MetricColor.ValueTypecolorz%MetricProto.MetricDirection.ValueType	directionN)__name__
__module____qualname____annotations__ r!   r!   M/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/metric.pyr   ,   s   
 r   c                   @  s8   e Zd Zed					ddddZedddZdS )MetricMixinmetricNr   visibleFlabelstrvaluer   deltar   delta_colorr   help
str | Nonelabel_visibilityr   borderboolreturnr   c           
      C  s   t || t }t||_t||_t||_||_|dur#t	||_
ttdt||}	|	j|_|	j|_t||j_| jd|S )u  Display a metric in big bold font, with an optional indicator of how the metric changed.

        Tip: If you want to display a large number, it may be a good idea to
        shorten it using packages like `millify <https://github.com/azaitsev/millify>`_
        or `numerize <https://github.com/davidsa03/numerize>`_. E.g. ``1234`` can be
        displayed as ``1.2k`` using ``st.metric("Short number", millify(1234))``.

        Parameters
        ----------
        label : str
            The header or title for the metric. The label can optionally
            contain GitHub-flavored Markdown of the following types: Bold, Italics,
            Strikethroughs, Inline Code, Links, and Images. Images display like
            icons, with a max height equal to the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        value : int, float, str, or None
             Value of the metric. None is rendered as a long dash.

        delta : int, float, str, or None
            Indicator of how the metric changed, rendered with an arrow below
            the metric. If delta is negative (int/float) or starts with a minus
            sign (str), the arrow points down and the text is red; else the
            arrow points up and the text is green. If None (default), no delta
            indicator is shown.

        delta_color : "normal", "inverse", or "off"
             If "normal" (default), the delta indicator is shown as described
             above. If "inverse", it is red when positive and green when
             negative. This is useful when a negative change is considered
             good, e.g. if cost decreased. If "off", delta is  shown in gray
             regardless of its value.

        help : str or None
            A tooltip that gets displayed next to the metric label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        border : bool
            Whether to show a border around the metric container. If this is
            ``False`` (default), no border is shown. If this is ``True``, a
            border is shown.

        Examples
        --------
        **Example 1: Show a metric**

        >>> import streamlit as st
        >>>
        >>> st.metric(label="Temperature", value="70 °F", delta="1.2 °F")

        .. output::
            https://doc-metric-example1.streamlit.app/
            height: 210px

        **Example 2: Create a row of metrics**

        ``st.metric`` looks especially nice in combination with ``st.columns``.

        >>> import streamlit as st
        >>>
        >>> col1, col2, col3 = st.columns(3)
        >>> col1.metric("Temperature", "70 °F", "1.2 °F")
        >>> col2.metric("Wind", "9 mph", "-8%")
        >>> col3.metric("Humidity", "86%", "4%")

        .. output::
            https://doc-metric-example2.streamlit.app/
            height: 210px

        **Example 3: Modify the delta indicator**

        The delta indicator color can also be inverted or turned off.

        >>> import streamlit as st
        >>>
        >>> st.metric(label="Gas price", value=4, delta=-0.5, delta_color="inverse")
        >>>
        >>> st.metric(
        ...     label="Active developers", value=123, delta=123, delta_color="off"
        ... )

        .. output::
            https://doc-metric-example3.streamlit.app/
            height: 320px

        **Example 4: Create a grid of metric cards**

        Add borders to your metrics to create a dashboard look.

        >>> import streamlit as st
        >>>
        >>> a, b = st.columns(2)
        >>> c, d = st.columns(2)
        >>>
        >>> a.metric("Temperature", "30°F", "-9°F", border=True)
        >>> b.metric("Wind", "4 mph", "2 mph", border=True)
        >>>
        >>> c.metric("Humidity", "77%", "5%", border=True)
        >>> d.metric("Pressure", "30.34 inHg", "-2 inHg", border=True)

        .. output::
            https://doc-metric-example4.streamlit.app/
            height: 350px

        Nr   r$   )r   MetricProto_parse_valuebody_parse_labelr&   _parse_deltar)   show_borderr   r+   $_determine_delta_color_and_directionr	   r   r   r   r   r-   r(   dg_enqueue)
selfr&   r(   r)   r*   r+   r-   r.   metric_protocolor_and_directionr!   r!   r"   r$   3   s$    





zMetricMixin.metricc                 C  s
   t d| S )Nr   )r	   )r:   r!   r!   r"   r8      s   
zMetricMixin.dg)Nr   Nr%   F)r&   r'   r(   r   r)   r   r*   r   r+   r,   r-   r   r.   r/   r0   r   )r0   r   )r   r   r   r   r$   propertyr8   r!   r!   r!   r"   r#   2   s     r#   r&   r'   r0   c                 C  s0   t | tstdt|  dtt|  d| S )N'' is of type zg, which is not an accepted type. label only accepts: str. Please convert the label to an accepted type.)
isinstancer'   	TypeErrortype)r&   r!   r!   r"   r4      s
   
r4   r(   c                 C  s   | d u rdS t | tst | tst | trt| S t| dr?zt |  ts-t |  tr4t|  W S W n	 ty>   Y nw tdt|  dtt|  d)Nu   —itemr>   r?   z|, which is not an accepted type. value only accepts: int, float, str, or None. Please convert the value to an accepted type.)	r@   intfloatr'   hasattrrC   	ExceptionrA   rB   )r(   r!   r!   r"   r2      s   
r2   r)   c                 C  sd   | d u s| dkr
dS t | trt| S t | tst | tr!t| S tdt|  dtt|  d)N r>   r?   z|, which is not an accepted type. delta only accepts: int, float, str, or None. Please convert the value to an accepted type.)r@   r'   r   rD   rE   rA   rB   r)   r!   r!   r"   r5      s   
r5   r*   c                 C  s   | dvrt dt|  d|d u s|dkr ttjjtjjdS t|r?| dkr-tjj	}n| dkr6tjj
}ntjj}tjj}n| dkrHtjj
}n| dkrQtjj	}ntjj}tjj}t||dS )N>   r   r   r   r>   zS' is not an accepted value. delta_color only accepts: 'normal', 'inverse', or 'off'rH   )r   r   r   r   )r   r'   r   r1   MetricColorGRAYMetricDirectionNONE_is_negative_deltaREDGREENDOWNUP)r*   r)   cd_colorcd_directionr!   r!   r"   r7     s4   




r7   r/   c                 C  s   t t| dS )N-)r   r'   
startswithrI   r!   r!   r"   rN   +  s   rN   )r&   r'   r0   r'   )r(   r   r0   r'   )r)   r   r0   r'   )r*   r   r)   r   r0   r   )r)   r   r0   r/   ).
__future__r   dataclassesr   textwrapr   typingr   r   r   r   r	   typing_extensionsr
   streamlit.elements.lib.policiesr   streamlit.elements.lib.utilsr   r   streamlit.errorsr   streamlit.proto.Metric_pb2r   r1   streamlit.runtime.metrics_utilr   streamlit.string_utilr   numpynpstreamlit.delta_generatorr   rE   rD   r'   r   r    r   r   r   r#   r4   r2   r5   r7   rN   r!   r!   r!   r"   <module>   s4    
%
	

'