
    ;3huB                        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 dd	lmZ er
ddlZdd
lmZ  e        G d de             Zy)zgr.ScatterPlot() component.    )annotationsN)CallableSequence)TYPE_CHECKINGAnyLiteral)document)	Component)
AltairPlotAltairPlotDataPlot)I18nData)Timerc            %          e Zd ZdZeZ	 	 	 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ddd#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZdd	Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Z	ddZ
	 	 	 	 ddZddZddZ xZS )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   valueF)#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preserved_by_keyshow_actions_buttonc       #        8   || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        t'        |t(              rd}t+        j,                  d       t'        |t(              rt+        j,                  d       d}|| _        || _        || _        || _        |&| _        ||d}t8        '| u  ||||||||| |!|"|#|$|%       y)a  
        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot, 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.
            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: 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.
            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)r   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   )xyr   r   r   r   r   r   r   r   r   r   r    r   r!   r   r"   r'   interactive_chart
isinstancestrwarningswarnr$   r#   r%   r&   r6   super__init__)(selfr   r8   r9   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   r2   r3   r4   r5   r6   	__class__s(                                          ^/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/scatter_plot.pyr@   zScatterPlot.__init__    sC   b 
	

**"4%:"!2$8!"4%:"!,eS!EMMR fc"MMT F


#6 =Z/J!%- 	 	
    c                     y)Nplot rA   s    rC   get_block_namezScatterPlot.get_block_name   s    rD   c           	     >   ddl }ddlm} |dn|}|j                  ||xs |t	        j
                  |      |
|j                  |
      n|j                               |j                  ||	xs |t	        j
                  |      ||j                  |      n|j                               d}i }|r||d<   |r||d	<   |r||d
<   |r || |         r-| |   j                         | |   j                         g}ddg}d}n@| |   j                         j                         }t        t        t        |                  }d}|xs d}||t	        j                  ||      ||dd|d<   |r||d<   |r+| || |         rdndt	        j                  ||      d|d<   |r+| || |         rdndt	        j                  ||      d|d<     |j!                  |       j#                  d      j$                  di |j&                  dddi|}|r|j)                         }|S )z%Helper for creating the scatter plot.r   N)is_numeric_dtypeT)
labelAngle)r   r.   axis)r8   r9   r   r#   r$      quantitativenominalbottom)positionr   )domainrange)fieldtypelegendr.   r   r   )rU   rV   rW   r   r   )clip
backgroundtransparentrG   )altairpandas.api.typesrK   Xr   create_scaleAxisYminmaxuniquetolistlistrT   lencreate_legendChart
mark_pointencode
propertiesr(   )r   r8   r9   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r(   altrK   	encodingsrk   rS   range_type_charts                                  rC   create_plotzScatterPlot.create_plot   s}   x 	5)1d{l --e4 , XXX7XXZ   l --e4 , XXX7XXZ  
	$ 
"'Jw#)Jx "'Jwe-,**,eEl.>.>.@AQ&u,,.557eCK01!$9$EX!$222:L %+V<"Ig #*Ii *:5;*GY$2219J!If *:5<*Hi$222:L"Ig CIIeZTZ"V!! Z@ $1@ 5?@ 	 %%'ErD   c                    |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").
        rG   )rA   payloads     rC   
preprocesszScatterPlot.preprocessR  s	     rD   c                   |t        |t              r|S | j                  | j                  t	        d      | j                  || j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j                   | j"                  | j$                  | j&                  | j(                  | j*                  | j,                  | j.                  | j0                        }t3        d|j5                         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").
        z6No value provided for required parameters `x` and `y`.)r   r8   r9   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r(   r#   r$   r%   r&   r[   scatter)rV   rF   rp   )r;   dictr8   r9   
ValueErrorrq   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r:   r#   r$   r%   r&   r   to_json)rA   r   rp   s      rC   postprocesszScatterPlot.postprocess[  s    =Jud3L66>TVV^UVV  ffff******LLLLLL,,,,#66"44#55"&"<"<!%!:!:"&"<"<..;;******/ ! 
4 8%--/SSrD   c                     y )NrG   rH   s    rC   example_payloadzScatterPlot.example_payload  s    rD   c                f    dd l } |j                  | j                  g d| j                  g di      S )Nr   )rN         )         )pandas	DataFramer8   r9   )rA   pds     rC   example_valuezScatterPlot.example_value  s'    r||TVVY	BCCrD   )NNN)Lr   zpd.DataFrame | Callable | Noner8   
str | Noner9   r   r   r   r   r   r   r   r   r   r   list[str] | str | Noner   r   r   r   r   float | Noner   r   r   r   r   r   r   r   r    pLiteral['left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right', 'none'] | Noner!   r   r"   r   r#   
int | Noner$   r   r%   list[int | float] | Noner&   r   r'   r   r(   bool | Noner)   zstr | I18nData | Noner*   zTimer | float | Noner+   z7Component | Sequence[Component] | set[Component] | Noner,   r   r-   boolr.   r   r/   intr0   r   r1   r   r2   r   r3   r   r4   z(int | str | tuple[int | str, ...] | Noner5   r   r6   r   )returnr<   )NNNNNNNNNNNNNNNNNNNT).r   zpd.DataFramer8   r<   r9   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$   r   r%   r   r&   r   r(   r   )rs   AltairPlotData | Noner   r   )r   zpd.DataFrame | dict | Noner   zAltairPlotData | dict | None)r   r   )__name__
__module____qualname____doc__r   
data_modelr@   rI   staticmethodrq   rt   rz   r|   r   __classcell__)rB   s   @rC   r   r      s     J 15	d
 !  *.""&*&*)-(,)-   ! *.*."#''+&*JN"& "/38<3:$)Sd
-d
 d
 	d
 d
 d
 d
 d
 (d
 d
 d
 $d
 $d
 'd
  &!d
" '#d
$ %d
<=d
T Ud
l md
n od
p (qd
r (sd
t ud
v !wd
x %yd
z ${d
| H}d
~  d
@ Ad
B Cd
D Ed
F Gd
H Id
J -Kd
L Md
N 6Od
P 1Qd
R "Sd
L 
 !  *.""&*&*)-(,)-   ! *.*.#'qFFF F 	F
 F F F (F F F $F $F 'F &F 'F  !F89FP QFh iFj kFl (mFn (oFp !qF FP(T/(T	%(TTDrD   r   )r   
__future__r   r=   collections.abcr   r   typingr   r   r   gradio_client.documentationr	   gradio.components.baser
   gradio.components.plotr   r   r   gradio.i18nr   r   r   gradio.componentsr   r   rG   rD   rC   <module>r      sR    ! "  . . . 0 , C C  ' 
uD$ uD uDrD   