L i9UddlmZddlmZddlmZddlmZmZm Z m Z m Z ddl m Z mZddlmZmZmZmZmZddlmZddlmZmZdd lmZdd lmZdd lm Z dd l!m"Z"m#Z#m$Z$erdd l%m&Z&e"e'zdzZ(de)d<e"e'zdzZ*de)d<e dZ+de)d<edGddZ,GddZ- d dZ.d!dZ/d"dZ0d#dZ1 d$dZ2d%dZ3y)&) annotations) dataclass)dedent) TYPE_CHECKINGAnyLiteral TypeAliascast)OptionSequenceconvert_anything_to_list)Height LayoutConfigWidthvalidate_heightvalidate_width)maybe_raise_label_warnings)LabelVisibility get_label_visibility_proto_value)StreamlitAPIException)Metric)gather_metrics) AnyNumber clean_text from_number)DeltaGeneratorNr ValueDelta)normalinverseoff DeltaColorT)frozenc"eZdZUded<ded<y)MetricColorAndDirectionz!MetricProto.MetricColor.ValueTypecolorz%MetricProto.MetricDirection.ValueType directionN)__name__ __module__ __qualname____annotations___/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/metric.pyr$r$0s ,,44r,r$c eZdZed d dddddddd d d Zed d Zy) MetricMixinmetricNvisibleFstretchcontentline)helplabel_visibilityborderwidthheight chart_data chart_typec *t||t} t|| _t || _t || _|| _|t|| _ ttdt||} | j| _| j| _t!|| j"_| Vg}t'| D]} |j)t+|t3|dkDr| j4j7|t9| | _t=| dt?|dtA|| }|jBjEd | | S#t,$r!}t/d|dt1|d|d}~wwxYw) uL 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 `_ or `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, decimal.Decimal, str, or None Value of the metric. ``None`` is rendered as a long dash. delta : int, float, decimal.Decimal, 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 aligned 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. height : "content", "stretch", or int The height of the metric 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. width : "stretch", "content", or int The width of the metric 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. chart_data : Iterable or None A sequence of numeric values to display as a sparkline chart. If this is ``None`` (default), no chart is displayed. The sequence can be anything supported by ``st.dataframe``, including a ``list`` or ``set``. If the sequence is dataframe-like, the first column will be used. Each value will be cast to ``float`` internally by default. chart_type : "line", "bar", or "area" The type of sparkline chart to display. This can be one of the following: - ``"line"`` (default): A simple sparkline. - ``"area"``: A sparkline with area shading. - ``"bar"``: A bar chart. 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 **Example 5: Show sparklines** To show trends over time, add sparklines. >>> import streamlit as st >>> from numpy.random import default_rng as rng >>> >>> changes = list(rng(4).standard_normal(20)) >>> data = [sum(changes[:i]) for i in range(20)] >>> delta = round(data[-1], 2) >>> >>> row = st.container(horizontal=True) >>> with row: >>> st.metric( ... "Line", 10, delta, chart_data=data, chart_type="line", border=True ... ) >>> st.metric( ... "Area", 10, delta, chart_data=data, chart_type="area", border=True ... ) >>> st.metric( ... "Bar", 10, delta, chart_data=data, chart_type="bar", border=True ... ) .. output:: https://doc-metric-example5.streamlit.app/ height: 300px Nr!zFOnly numeric values are supported for chart data sequence. The value ' ' is of type z" and cannot be converted to float.rT) allow_content)r8r9r0) layout_config)#r MetricProto _parse_valuebody _parse_labellabel _parse_deltadelta show_borderrr5$_determine_delta_color_and_directionr rr%r&rr6valuer appendfloat Exceptionrtypelenr:extend_parse_chart_typer;rrrdg_enqueue)selfrDrIrF delta_colorr5r6r7r8r9r:r; metric_protocolor_and_direction prepared_datavalexr?s r-r0zMetricMixin.metric7sj #5*:;"} (/ )%0 )%0 #)    &t L B z+6 7 166 !4!>!> .N / %%+  !)+M/ ; !((s4 =!A%''..}="3J"? d3uD1$5@ ww,mTT!/""%mDI;?88 sE(( F1F  Fctd|S)Nr)r )rSs r-rQzMetricMixin.dg5s$d++r,)Nr)rDstrrIrrFrrTr!r5z str | Noner6rr7boolr8rr9r r:zOptionSequence[Any] | Noner;Literal['line', 'bar', 'area']returnr)r^r)r'r(r)rr0propertyrQr+r,r-r/r/6sH "* {U ,5 "155;{U{U{U {U  {U{U*{U{U{U{U/{U3{U {U{Uz,,r,r/c|dk(rtjjS|dk(rtjjStjjS)Nbararea)r@ ChartTypeBARAREALINE)r;s r-rPrP:sJU$$(((V$$)))  % %%r,c\t|tstd|dt|d|S)N'r=zg, which is not an accepted type. label only accepts: str. Please convert the label to an accepted type.) isinstancer[ TypeErrorrM)rDs r-rCrCEs= eS !wmDK=1V V   Lr,cB|yt|tr|St|S)Nu—)rir[r)rIs r-rArANs$ }% u r,c^||dk(ryt|tr t|St|S)N)rir[rrrFs r-rErEVs/ } %e} u r,c|dvrtd|d||dk(r=ttjjtj j St|ru|dk(rtjj}n:|dk(rtjj}ntjj}tj j}nt|dk(rtjj}n:|dk(rtjj}ntjj}tj j}t||S)N>r rrrhzS' is not an accepted value. delta_color only accepts: 'normal', 'inverse', or 'off'rm)r%r&rr) rr$r@ MetricColorGRAYMetricDirectionNONE_is_negative_deltaREDGREENDOWNUP)rTrFcd_color cd_directions r-rHrH^s(66# }, ,   } &))..!1166  % ( ""..22H I %"..44H"..33H"2277 ( ""..44H I %"..22H"..33H"2255 " r,cHtt|jdS)N-)rr[ startswithrns r-rtrts #e*  ( ( --r,)r;r]r^zMetricProto.ChartType.ValueType)rDr[r^r[)rIrr^r[)rFrr^r[)rTr!rFrr^r$)rFrr^r\)4 __future__r dataclassesrtextwraprtypingrrrr r streamlit.dataframe_utilr r #streamlit.elements.lib.layout_utilsr rrrrstreamlit.elements.lib.policiesrstreamlit.elements.lib.utilsrrstreamlit.errorsrstreamlit.proto.Metric_pb2rr@streamlit.runtime.metrics_utilrstreamlit.string_utilrrrstreamlit.delta_generatorrr[rr*rr!r$r/rPrCrArErHrtr+r,r-rs#!??MG3<9DD8s?T)y)s?T)y) :; I; $555 A,A,H&.&$&$$ $$N.r,