o
    e                     @  s   d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
ZddlZddl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 ed e G dd deeeeZG dd dZdS )zgr.Plot() component.    )annotationsN)
ModuleType)AnyCallableLiteral)documentset_documentation_group)JSONSerializable)processing_utils)IOComponent	_Keywords)warn_style_method_deprecation)
Changeable	Clearable	componentc                   @  sr   e Zd ZdZ	d%dddddddddd	d&ddZdd Zeejddddddfd'ddZ	d(d!d"Z
d%d)d#d$ZdS )*Plota  
    Used to display various kinds of plots (matplotlib, plotly, or bokeh are supported)
    Preprocessing: this component does *not* accept input.
    Postprocessing: expects either a {matplotlib.figure.Figure}, a {plotly.graph_objects._figure.Figure}, or a {dict} corresponding to a bokeh plot (json_item format)

    Demos: altair_plot, outbreak_forecast, blocks_kinematics, stock_forecast, map_airbnb
    Guides: plot-component-for-maps
    NT   )	labelevery
show_label	containerscale	min_widthvisibleelem_idelem_classesvalueCallable | None | pd.DataFramer   
str | Noner   float | Noner   bool | Noner   boolr   
int | Noner   intr   r   r   list[str] | str | Nonec       	         K  s,   t j| f||||||||	|
|d
| dS )a  
        Parameters:
            value: Optionally, supply a default plot object to display, must be a matplotlib, plotly, altair, or bokeh figure, or a callable. If callable, the function will be called whenever the app loads to set the initial value of the component.
            label: component name in interface.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            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 width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            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.
        )
r   r   r   r   r   r   r   r   r   r   N)r   __init__)selfr   r   r   r   r   r   r   r   r   r   kwargs r(   FD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/plot.pyr%   !   s    
zPlot.__init__c                 C  s@   z	dd l }|j}W n ty   d }Y nw | j|dt| S )Nr   )r   bokeh_version)bokeh__version__ImportErrorr   r   
get_config)r&   r+   r*   r(   r(   r)   r.   L   s   
zPlot.get_config(Any | Literal[_Keywords.NO_VALUE] | Nonec              	   C  s   ||||||| dd}|S )Nupdate)r   r   r   r   r   r   r   Z__type__r(   )r   r   r   r   r   r   r   Zupdated_configr(   r(   r)   r0   Y   s   
zPlot.updatereturndict[str, str] | Nonec                 C  s   ddl }|du r
dS t|t|jjfrd}t|}n$d|jv r0d}ddlm	} t
||}nd|jv }|r9dnd}| }||dS )	zx
        Parameters:
            y: plot data
        Returns:
            plot type mapped to plot base64 data
        r   N
matplotlibr+   )	json_itemaltairZplotly)typeZplot)Zmatplotlib.figure
isinstancer   ZfigureZFigurer
   Zencode_plot_to_base64
__module__Zbokeh.embedr4   jsondumpsto_json)r&   yr3   ZdtypeZout_yr4   Z	is_altairr(   r(   r)   postprocesso   s   


zPlot.postprocessc                 C  s   t   |dur
|| _| S )zc
        This method is deprecated. Please set these arguments in the constructor instead.
        N)r   r   )r&   r   r(   r(   r)   style   s   z
Plot.style)N)r   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r!   r   r   r   r$   )r   r/   r   r   r   r    r   r    r   r"   r   r"   r   r    )r1   r2   )r   r    )__name__r8   __qualname____doc__r%   r.   staticmethodr   ZNO_VALUEr0   r=   r>   r(   r(   r(   r)   r      s4    +
r   c                   @  s$   e Zd Zedd Zedd ZdS )
AltairPlotc                 C  s0   | dkrd }|S | rd| ini } d|i| }|S )NnoneZorienttitler(   )positionrE   Zlegendr(   r(   r)   create_legend   s   zAltairPlot.create_legendc                 C  s   | rt j| dS t jS )N)domain)altZScale	Undefined)limitr(   r(   r)   create_scale   s   zAltairPlot.create_scaleN)r?   r8   r@   rB   rG   rL   r(   r(   r(   r)   rC      s
    
	rC   )rA   
__future__r   r9   typesr   typingr   r   r   r5   rI   ZpandaspdZgradio_client.documentationr   r   Zgradio_client.serializingr	   Zgradior
   Zgradio.components.baser   r   Zgradio.deprecationr   Zgradio.eventsr   r   r   rC   r(   r(   r(   r)   <module>   s"    {