
    ;3hm                       d Z ddlmZ ddl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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mZ  G d de      Z G d de      Z e        G d de             Z G d d      Zy)zgr.Plot() component.    )annotationsN)Sequence)
ModuleType)TYPE_CHECKINGAnyLiteral)document)processing_utils
wasm_utils)	Component)GradioModel)Events)I18nData)Timerc                  "    e Zd ZU ded<   ded<   y)PlotDataz2Literal['altair', 'bokeh', 'plotly', 'matplotlib']typestrplotN)__name__
__module____qualname____annotations__     V/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/plot.pyr   r      s    
<<
Ir   r   c                  &    e Zd ZU ded<   dZded<   y)AltairPlotDataz!Literal['bar', 'line', 'scatter']chartaltairzLiteral['altair']r   N)r   r   r   r   r   r   r   r   r   r      s    ,,&D
&r   r   c                       e Zd ZdZeZej                  gZ	 de	j                  rdnddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z fd
ZddZddZddZddZ xZS )Plota-  
    Creates a plot component to display various kinds of plots (matplotlib, plotly, altair, or bokeh plots are supported). As this component does
    not accept user input, it is rarely used as an input component.

    Demos: blocks_kinematics, stock_forecast
    Guides: plot-component-for-maps
    NpngwebpT   value)formatlabeleveryinputs
show_label	containerscale	min_widthvisibleelem_idelem_classesrenderkeypreserved_by_keyc               N    || _         t        | 	  |||||||	|
||||||       y)aU  
        Parameters:
            value: Optionally, supply a default plot object to display, must be a matplotlib, plotly, altair, or bokeh figure, or a callable. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
            format: File format in which to send matplotlib plots to the front end, such as 'jpg' or 'png'.
            label: the label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
            every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
            preserved_by_key: A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
        )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r&   N)r'   super__init__)selfr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   	__class__s                   r   r7   zPlot.__init__-   sI    N !%- 	 	
r   c                r    	 dd l }|j                  }t        |          }||d<   |S # t        $ r d }Y "w xY w)Nr   bokeh_version)bokeh__version__ImportErrorr6   
get_config)r8   r<   r;   configr9   s       r   r?   zPlot.get_configf   sJ    	!!--M #%"/  	! M	!s   ( 66c                    |S )a+  
        Parameters:
            payload: The data to display in the plot.
        Returns:
            (Rarely used) passes the data displayed in the plot as an PlotData dataclass, which includes the plot information as a JSON string, as well as the type of chart and the plotting library.
        r   )r8   payloads     r   
preprocesszPlot.preprocessr   s	     r   c                     y Nr   r8   s    r   example_payloadzPlot.example_payload{       r   c                     y rE   r   rF   s    r   example_valuezPlot.example_value~   rH   r   c                t   |yt        |t              r|S t        |t              sd|j                  v r#d}t	        j
                  || j                        }nVd|j                  v r$d}ddlm} t        j                   ||            }n$d|j                  v }|rdnd}|j                         }t        ||      S )	a9  
        Parameters:
            value: Expects plot data in one of these formats: a matplotlib.Figure, bokeh.Model, plotly.Figure, or altair.Chart object.
        Returns:
            PlotData: A dataclass containing the plot data as a JSON string, as well as the type of chart and the plotting library.
        N
matplotlibr<   r   )	json_itemr    plotly)r   r   )
isinstancer   r   r   r
   encode_plot_to_base64r'   bokeh.embedrM   jsondumpsto_json)r8   r&   dtypeout_yrM   	is_altairs         r   postprocesszPlot.postprocess   s     =eX&LeZ(LE<L<L,L E$::5$++NE(((E-JJy/0E E$4$44I )HxEMMOEU//r   rE   )r&   z
Any | Noner'   r   r(   zstr | I18nData | Noner)   zTimer | float | Noner*   z7Component | Sequence[Component] | set[Component] | Noner+   zbool | Noner,   boolr-   z
int | Noner.   intr/   rY   r0   z
str | Noner1   list[str] | str | Noner2   rY   r3   z(int | str | tuple[int | str, ...] | Noner4   r[   )rB   PlotData | Nonereturnr\   )r]   r   )r&   r   r]   r\   )r   r   r   __doc__r   
data_modelr   changeEVENTSr   IS_WASMr7   r?   rC   rG   rJ   rX   __classcell__)r9   s   @r   r"   r"       s    Jmm_F !7

  '+&*JN"& "/38<3:'7
7
 	7
 %7
 $7
 H7
  7
 7
 7
 7
 7
 7
  -!7
" #7
$ 6%7
& 1'7
r
0r   r"   c                  ,    e Zd Zed        Zed        Zy)
AltairPlotc                4    | dk(  rd }|S | rd| ini } d|i| }|S )Nnoneorienttitler   )positionri   legends      r   create_legendzAltairPlot.create_legend   s:    vF
  08(+RHu11Fr   c                J    dd l }| r|j                  |       S |j                  S )Nr   )domain)r    Scale	Undefined)limitalts     r   create_scalezAltairPlot.create_scale   s!    */syyy&BS]]Br   N)r   r   r   staticmethodrl   rs   r   r   r   re   re      s*      C Cr   re   )r^   
__future__r   rR   collections.abcr   typesr   typingr   r   r   gradio_client.documentationr	   gradior
   r   gradio.components.baser   gradio.data_classesr   gradio.eventsr   gradio.i18nr   gradio.componentsr   r   r   r"   re   r   r   r   <module>r      sw     "  $  . . 0 / , +    '{ 
'X '
 
w09 w0 w0tC Cr   