o
    e~#g&@                     @  s   d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZmZ er@ddlZdd	lmZ e G d
d deZdS )zgr.ScatterPlot() component.    )annotationsN)CallableSequence)TYPE_CHECKINGAnyLiteral)document)	Component)
AltairPlotAltairPlotDataPlot)Timerc                $      s   e Zd ZdZeZ			dOddddddddddddddddddddddddddddddddddd"dP fd9d:ZdQd=d>Ze																				dRdSd@dAZ	dTdDdEZ
dUdHdIZdVdKdLZdVdMdNZ  ZS )WScatterPlotz
    Creates a scatter plot component to display data from a pandas DataFrame (as output). As this component does
    not accept user input, it is rarely used as an input component.

    Guides: creating-a-dashboard-from-bigquery-data
    NT   F)"colorsizeshapetitletooltipx_titley_titlex_label_angley_label_anglecolor_legend_titlesize_legend_titleshape_legend_titlecolor_legend_positionsize_legend_positionshape_legend_positionheightwidthx_limy_limcaptioninteractivelabeleveryinputs
show_label	containerscale	min_widthvisibleelem_idelem_classesrenderkeyshow_actions_buttonvaluepd.DataFrame | Callable | Nonex
str | Noneyr   r   r   r   r   list[str] | str | Noner   r   r   float | Noner   r   r   r   r   pLiteral['left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right', 'none'] | Noner   r   r   
int | Noner    r!   list[int | float] | Noner"   r#   r$   bool | Noner%   r&   Timer | float | Noner'   7Component | Sequence[Component] | set[Component] | Noner(   r)   boolr*   r+   intr,   r-   r.   r/   r0   int | str | Noner1   c       "   &        s   || _ || _|| _|| _|| _|| _|| _|	| _|
| _|| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _t|trEd}td t|trQtd d}|| _|| _|| _|| _|%| _|du rj|du rjd}t j||||||||| |!|"|#|$d dS )au  
        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot, or a callable. If callable, the function will be called whenever the app loads to set the initial value of the component.
            x: Column corresponding to the x axis.
            y: Column corresponding to the y axis.
            color: The column to determine the point color. If the column contains numeric data, gradio will interpolate the column data so that small values correspond to light colors and large values correspond to dark values.
            size: The column used to determine the point size. Should contain numeric data so that gradio can map the data to the point size.
            shape: The column used to determine the point shape. Should contain categorical data. Gradio will map each unique value to a different shape.
            title: The title to display on top of the chart.
            tooltip: The column (or list of columns) to display on the tooltip when a user hovers a point on the plot.
            x_title: The title given to the x-axis. By default, uses the value of the x parameter.
            y_title: The title given to the y-axis. By default, uses the value of the y parameter.
            x_label_angle:  The angle for the x axis labels rotation. Positive values are clockwise, and negative values are counter-clockwise.
            y_label_angle:  The angle for the y axis labels rotation. Positive values are clockwise, and negative values are counter-clockwise.
            color_legend_title: The title given to the color legend. By default, uses the value of color parameter.
            size_legend_title: The title given to the size legend. By default, uses the value of the size parameter.
            shape_legend_title: The title given to the shape legend. By default, uses the value of the shape parameter.
            color_legend_position: The position of the color legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
            size_legend_position: The position of the size legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
            shape_legend_position: The position of the shape legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
            height: The height of the plot in pixels.
            width: The width of the plot in pixels. If None, expands to fit.
            x_lim: A tuple or list containing the limits for the x-axis, specified as [x_min, x_max].
            y_lim: A tuple of list containing the limits for the y-axis, specified as [y_min, y_max].
            caption: The (optional) caption to display below the plot.
            interactive: Whether users should be able to interact with the plot by panning or zooming with their mouse or trackpad.
            label: The (optional) label to display on the top left corner of the plot.
            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: Whether the label should be displayed.
            visible: Whether the plot should be visible.
            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: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
            show_actions_button: Whether to show the actions button on the top right corner of the plot.
        Nz@Width should be an integer, not a string. Setting width to None.zBHeight should be an integer, not a string. Setting height to None.F)r2   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   )r4   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   interactive_chart
isinstancestrwarningswarnr    r   r!   r"   r1   super__init__)&selfr2   r4   r6   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/   r0   r1   	__class__ /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/gradio/components/scatter_plot.pyrH      sf   o


zScatterPlot.__init__returnrD   c                 C  s   dS )NplotrL   rI   rL   rL   rM   get_block_name      zScatterPlot.get_block_namepd.DataFramec                 C  s  ddl }ddlm} |du rdn|}|j||p|t||
dur&|j|
dn| d|j||	p1|t||dur?|j|dn| dd}i }|rO||d< |rU||d	< |r[||d
< |r|| | rv| |  | | 	 g}ddg}d}n| | 
  }ttt|}d}|pd}||tj||d||dd|d< |r||d< |r||| | rdndtj||dd|d< |r||| | rdndtj||dd|d< || jddjdi |jdddi|}|r| }|S )z%Helper for creating the scatter plot.r   N)is_numeric_dtypeT)
labelAngle)r   r*   axis)r4   r6   r   r   r       quantitativenominalbottom)positionr   )domainrange)fieldtypelegendr*   r   r   )r^   r_   r`   r   r   )clip
backgroundtransparentrL   )altairpandas.api.typesrT   Xr
   create_scaleAxisYminmaxuniquetolistlistr]   lencreate_legendChart
mark_pointencode
propertiesr$   )r2   r4   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   altrT   	encodingsrt   r\   range_type_chartrL   rL   rM   create_plot   s   <


zScatterPlot.create_plotpayloadAltairPlotData | Nonec                 C  s   |S )a?  
        Parameters:
            payload: The data to display in a scatter plot.
        Returns:
            (Rarely used) passes the data displayed in the scatter plot as an AltairPlotData dataclass, which includes the plot information as a JSON string, as well as the type of plot (in this case, "scatter").
        rL   )rI   r{   rL   rL   rM   
preprocessN  s   zScatterPlot.preprocesspd.DataFrame | dict | NoneAltairPlotData | dict | Nonec                 C  s  |du s	t |tr|S | jdu s| jdu rtd| jdi d|d| jd| jd| jd| jd| jd	| j	d
| j
d| jd| jd| jd| jd| jd| jd| jd| jd| jd| jd| jd| jd| jd| jd| j}td| ddS )a  
        Parameters:
            value: Expects a pandas DataFrame containing the data to display in the scatter plot. The DataFrame should contain at least two columns, one for the x-axis (corresponding to this component's `x` argument) and one for the y-axis (corresponding to `y`).
        Returns:
            The data to display in a scatter plot, in the form of an AltairPlotData dataclass, which includes the plot information as a JSON string, as well as the type of plot (in this case, "scatter").
        Nz6No value provided for required parameters `x` and `y`.r2   r4   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r   r    r!   r"   rd   scatter)r_   rO   ry   rL   )rC   dictr4   r6   
ValueErrorrz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   r   r    r!   r"   r   to_json)rI   r2   ry   rL   rL   rM   postprocessW  sh   

	
zScatterPlot.postprocessr   c                 C  s   d S )NrL   rP   rL   rL   rM   example_payload  rR   zScatterPlot.example_payloadc                 C  s&   dd l }|| jg d| jg diS )Nr   )rW         )         )pandas	DataFramer4   r6   )rI   pdrL   rL   rM   example_value  s   zScatterPlot.example_value)NNN)Jr2   r3   r4   r5   r6   r5   r   r5   r   r5   r   r5   r   r5   r   r7   r   r5   r   r5   r   r8   r   r8   r   r5   r   r5   r   r5   r   r9   r   r9   r   r9   r   r:   r    r:   r!   r;   r"   r;   r#   r5   r$   r<   r%   r5   r&   r=   r'   r>   r(   r<   r)   r?   r*   r:   r+   r@   r,   r?   r-   r5   r.   r7   r/   r?   r0   rA   r1   r?   )rN   rD   )NNNNNNNNNNNNNNNNNNNT).r2   rS   r4   rD   r6   rD   r   r5   r   r5   r   r5   r   r5   r   r7   r   r5   r   r5   r   r8   r   r8   r   r5   r   r5   r   r5   r   r9   r   r9   r   r9   r   r:   r    r:   r!   r;   r"   r;   r$   r<   )r{   r|   rN   r|   )r2   r~   rN   r   )rN   r   )__name__
__module____qualname____doc__r   
data_modelrH   rQ   staticmethodrz   r}   r   r   r   __classcell__rL   rL   rJ   rM   r      s     
$ 
	
	
*r   )r   
__future__r   rE   collections.abcr   r   typingr   r   r   gradio_client.documentationr   gradio.components.baser	   gradio.components.plotr
   r   r   r   r   gradio.componentsr   r   rL   rL   rL   rM   <module>   s    