
    &e&                        U d dl mZ d dlmZ d dlmZmZmZ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 d d	lmZ d d
lmZmZ er
d dlZd dlmZ eddeee df         Z!ee"d<   eeee df         Z#ee"d<   e
d         Z$ee"d<    ed           G d d                      Z% G d d          Z&de de fdZ'de!de fdZ(de#de fdZ)d e$de#de%fd!Z*de#de+fd"Z,dS )#    )	dataclass)dedent)TYPE_CHECKINGOptionalUnioncast)Literal	TypeAlias) get_label_visibility_proto_value)StreamlitAPIException)Metric)gather_metrics)
clean_text)LabelVisibilitymaybe_raise_label_warningsN)DeltaGeneratorz
np.integerznp.floatingValueDelta)normalinverseoff
DeltaColorT)frozenc                   $    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__     9lib/python3.11/site-packages/streamlit/elements/metric.pyr   r   '   s*         ....666666r#   r   c                       e Zd Z ed          	 	 	 	 ddedededed	ee         d
e	ddfd            Z
edd            ZdS )MetricMixinmetricNr   visiblelabelvaluedeltadelta_colorhelplabel_visibilityreturnr   c                    t          ||           t                      }t          |          |_        t	          |          |_        t          |          |_        |t          |          |_	        t          t          t          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
            Markdown and supports the following elements: Bold, Italics,
            Strikethroughs, Inline Code, Emojis, and Links.

            This also supports:

            * Emoji shortcodes, such as ``:+1:``  and ``:sunglasses:``.
              For a list of all supported codes,
              see https://share.streamlit.io/streamlit/emoji-shortcodes.

            * LaTeX expressions, by wrapping them in "$" or "$$" (the "$$"
              must be on their own lines). Supported LaTeX functions are listed
              at https://katex.org/docs/supported.html.

            * Colored text, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet, gray/grey, rainbow.

            Unsupported 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``.
        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
            An optional tooltip that gets displayed next to the metric label.
        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. If "hidden", the label doesn't show but there
            is still empty space for it (equivalent to label="").
            If "collapsed", both the label and the space are removed. Default is
            "visible".

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

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

        ``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

        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

        Nr'   )r   MetricProto_parse_valuebody_parse_labelr)   _parse_deltar+   r   r-   $_determine_delta_color_and_directionr   r   r   r   r   r   r.   r*   dg_enqueue)	selfr)   r*   r+   r,   r-   r.   metric_protocolor_and_directions	            r$   r'   zMetricMixin.metric.   s    J 	#5*:;;;"}}(//)%00)%00 &tLBZ4455u
 
 16!4!>.N/
 /
%+ w,777r#   c                 "    t          d|           S )Nr   )r   )r9   s    r$   r7   zMetricMixin.dg   s    $d+++r#   )Nr   Nr(   )r/   r   )r   r   r    r   strr   r   r   r   r   r'   propertyr7   r"   r#   r$   r&   r&   -   s        ^H
 "*",5v8 v8v8 v8 	v8
  v8 smv8 *v8 
v8 v8 v8 v8p , , , X, , ,r#   r&   r)   r/   c           
          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)   s    r$   r4   r4      si    eS!! 
VE

 V VT%[[)9)9 V V V
 
 	
 Lr#   r*   c           
      B   | dS t          | t                    s*t          | t                    st          | t                    rt          |           S t	          | d          r	 t          |                                 t                    s't          |                                 t                    r!t          |                                           S n# t          $ r Y nw xY wt          dt          |            dt          t          |                      d          )Nu   —itemr@   rA   z|, which is not an accepted type. value only accepts: int, float, str, or None. Please convert the value to an accepted type.)	rB   intfloatr=   hasattrrF   	ExceptionrC   rD   )r*   s    r$   r2   r2      s   }u% 
E5!9!9 
Zs=S=S 
5zz			 	%**,,.. )*UZZ\\32O2O )5::<<((() 	 	 	D	 	9CJJ 	9 	9Se%5%5 	9 	9 	9  s   $A.C 
C! C!r+   c           
      J   | | 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@   rA   z|, which is not an accepted type. delta only accepts: int, float, str, or None. Please convert the value to an accepted type.)rB   r=   r   rG   rH   rC   rD   r+   s    r$   r5   r5      s    }r% 	
e}}	E3		 
:eU#;#; 
5zz=E

 = =T%[[)9)9 = = =
 
 	
r#   r,   c                 B   | dvr t          dt          |            d          ||dk    r/t          t          j        j        t          j        j                  S t          |          rS| dk    rt          j        j	        }n)| dk    rt          j        j
        }nt          j        j        }t          j        j        }nR| dk    rt          j        j
        }n)| dk    rt          j        j	        }nt          j        j        }t          j        j        }t          ||          S )N>   r   r   r   r@   zS' is not an accepted value. delta_color only accepts: 'normal', 'inverse', or 'off'rL   )r   r   r   r   )r   r=   r   r1   MetricColorGRAYMetricDirectionNONE_is_negative_deltaREDGREENDOWNUP)r,   r+   cd_colorcd_directions       r$   r6   r6      s5    666#,K   , , ,
 
 	

 }&).!16
 
 
 	

 %   6(""".2HHI%%".4HH".3H"27(""".4HHI%%".2HH".3H"25"   r#   c                 `    t          t          |                                         d          S )N-)r   r=   
startswithrM   s    r$   rS   rS     s$    #e**((---r#   )-dataclassesr   textwrapr   typingr   r   r   r   typing_extensionsr	   r
   streamlit.elements.utilsr   streamlit.errorsr   streamlit.proto.Metric_pb2r   r1   streamlit.runtime.metrics_utilr   streamlit.string_utilr   streamlit.type_utilr   r   numpynpstreamlit.delta_generatorr   rH   rG   r=   r   r!   r   r   r   r&   r4   r2   r5   r6   boolrS   r"   r#   r$   <module>rk      s   " ! ! ! ! ! !       7 7 7 7 7 7 7 7 7 7 7 7 0 0 0 0 0 0 0 0 E E E E E E 2 2 2 2 2 2 < < < < < < 9 9 9 9 9 9 , , , , , , K K K K K K K K 9888888 }eS#tKLy L L LS$./y / / / :;
I ; ; ; $7 7 7 7 7 7 7 7
|, |, |, |, |, |, |, |,~      #    ,
 
# 
 
 
 
$$$ $ $ $ $N.e . . . . . . .r#   