
    ;3h<8                        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.BarPlot() 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 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 )BarPlotz
    Creates a bar 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.

    Demos: bar_plot
    NT   valueF) colorverticalgrouptitletooltipx_titley_titlex_label_angley_label_anglecolor_legend_titlegroup_titlecolor_legend_positionheightwidthy_limcaptioninteractivelabel
show_label	containerscale	min_widtheveryinputsvisibleelem_idelem_classesrenderkeypreserved_by_keysortshow_actions_buttonc                   || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        t#        |t$              rd}t'        j(                  d       t#        |t$              rt'        j(                  d       d}|| _        || _        |"| _        |#| _        ||d}t2        $| i  ||||||||||| |!||       y)a2  
        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot. If a callable is provided, the function will be called whenever the app loads to set the initial value of the plot.
            x: Column corresponding to the x axis.
            y: Column corresponding to the y axis.
            color: The column to determine the bar color. Must be categorical (discrete values).
            vertical: If True, the bars will be displayed vertically. If False, the x and y axis will be switched, displaying the bars horizontally. Default is True.
            group: The column with which to split the overall plot into smaller subplots.
            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 over a bar.
            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 (in degrees) of the x axis labels. Positive values are clockwise, and negative values are counter-clockwise.
            y_label_angle: The angle (in degrees) of the y axis labels. 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.
            group_title: The label displayed on top of the subplot columns (or rows if vertical=True). Use an empty string to omit.
            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.
            height: The height of the plot in pixels.
            width: The width of the plot in pixels. If None, expands to fit.
            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.
            show_label: Whether the label should be displayed.
            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.
            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.
            sort: Specifies the sorting axis as either "x", "y", "-x" or "-y". If None, no sorting is applied.
            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-   r.   r/   r0   r1   r*   r+   )xyr   r   r   r   r   r   r   r   r   r   r   r   r"   r#   interactive_chart
isinstancestrwarningswarnr!   r    r2   r3   super__init__)%selfr   r5   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/   r0   r1   r2   r3   	__class__s%                                       Z/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/bar_plot.pyr=   zBarPlot.__init__    s3   j 
 
&
**"4&%:"
!,eS!EMMR fc"MMT F
	#6 =Z/J!%- 	 	
    c                     y)Nplot r>   s    r@   get_block_namezBarPlot.get_block_name   s    rA   c                   ddl }|dn|}|r||dni }|xs |}|	xs |}	|s+||}}d| d}||	}}	|rd |j                  di |ini }|}d}n d| d}d}|rd |j                  di |ini }t        d|j	                  ||t        j                  |      |
|j                  |
	      n|j                         |r||nd
      |j                  ||	t        j                  |      ||j                  |	      n|j                         |s||nd
      d|}i }|r||d<   |r||d<   |r||d<   |rf|xs d}| |   j                         j                         }t        t        t        |                  }|d||dt        j                  ||      d|d<   |r||d<     |j                  |       j!                         j"                  di |j$                  dddi|}|r|j'                         }|S )z!Helper for creating the bar plot.r   NT)fieldr   zsum(z):Qrowcolumn)
labelAngle)r   r(   axisr2   )r5   r6   r   r    r!   bottomnominal)domainrange)positionr   )rH   typer(   legendr   r   
backgroundtransparentrD   )altairRowColumndictXr   create_scaleAxisYuniquetolistlistrP   lencreate_legendChartmark_barencode
propertiesr$   )r   r5   r6   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r2   altorientationx_lim	encodingsrf   rO   range_charts                               r@   create_plotzBarPlot.create_plot   s}   F 	)1d{@E<2,Q,Q aqAqcA&WG=H5'#''"8K"89bKEEqcAECN8ZSZZ%>+%>?TVK 
ee --e4 , XXX7XXZ%$*:T   ee --e4 , XXX7XXZ!)d.>TD  
& '
	* 
"'Jw#)Jx "'Jw$9$EX!5\((*113F%F,-F!$*V<$222:L	"Ig #*Ii  CIIeXZV!! Z@ $1@ 5?@ 	 %%'ErA   c                    |S )a3  
        Parameters:
            payload: The data to display in a bar plot.
        Returns:
            (Rarely used) passes the data displayed in the bar plot as an AltairPlotData dataclass, which includes the plot information as a JSON string, as well as the type of plot (in this case, "bar").
        rD   )r>   payloads     r@   
preprocesszBarPlot.preprocess  s	     rA   c                N   ||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(                        }t+        d|j-                         d      S )a  
        Parameters:
            value: Expects a pandas DataFrame containing the data to display in the bar 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 bar 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, "bar").
        z6No value provided for required parameters `x` and `y`.)r   r5   r6   r   r   r   r   r   r   r   r   r   r   r   r   r"   r$   r    r!   r2   rV   bar)rR   rC   rl   )r5   r6   
ValueErrorrm   r   r   r   r   r   r   r   r   r   r   r   r   r"   r7   r    r!   r2   r   to_json)r>   r   rl   s      r@   postprocesszBarPlot.postprocess$  s     =L66>TVV^UVV  ffff**]]****LLLLLL,,,,#66"&"<"<((**..;;**) ! 
. 8%--/OOrA   c                     y )NrD   rE   s    r@   example_payloadzBarPlot.example_payloadI  s    rA   c                f    dd l } |j                  | j                  g d| j                  g di      S )Nr   )         )         )pandas	DataFramer5   r6   )r>   pds     r@   example_valuezBarPlot.example_valueL  s'    r||TVVY	BCCrA   )NNN)Fr   zpd.DataFrame | Callable | Noner5   
str | Noner6   r   r   r   r   boolr   r   r   r   r   list[str] | str | Noner   r   r   r   r   float | Noner   r   r   r   r   r   r   pLiteral['left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right', 'none'] | Noner    
int | Noner!   r   r"   list[int] | Noner#   r   r$   bool | Noner%   zstr | I18nData | Noner&   r   r'   r   r(   r   r)   intr*   zTimer | float | Noner+   z7Component | Sequence[Component] | set[Component] | Noner,   r   r-   r   r.   r   r/   r   r0   z(int | str | tuple[int | str, ...] | Noner1   r   r2   $Literal['x', 'y', '-x', '-y'] | Noner3   r   )returnr9   )NTNNNNNNNNNNNNNTN)(r   zpd.DataFramer5   r9   r6   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   r2   r   )ro   r   r   r   )r   zpd.DataFrame | Noner   zAltairPlotData | None)r   r   )__name__
__module____qualname____doc__r   
data_modelr=   rF   staticmethodrm   rp   ru   rw   r   __classcell__)r?   s   @r@   r   r      sp     J 15	F
 !  *.""&*&*)-"& ! "&"#''+"& &*JN"/38<3:59$)aF
-F
 F
 	F
 F
 F
 F
 F
 (F
 F
 F
 $F
 $F
 'F
   !F
" #F
: ;F
< =F
>  ?F
@ AF
B !CF
D %EF
F  GF
H IF
J KF
L MF
N $OF
P HQF
R SF
T UF
V -WF
X YF
Z 6[F
\ 1]F
^ 3_F
` "aF
P 
 !  *.""&*&*)-"& ! "&#'59?mmm m 	m
 m m m (m m m $m $m 'm  m m6 7m8 9m:  ;m< !=m> 3?m m^#PJDrA   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   rD   rA   r@   <module>r      sR     "  . . . 0 , C C  ' 
yDd yD yDrA   