
    ;3h@                        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 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.LinePlot() component    )annotationsN)CallableSequence)TYPE_CHECKINGAnyLiteral)document)	Component)
AltairPlotAltairPlotDataPlot)Events)I18nData)Timerc            #          e Zd ZdZeZej                  g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 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 )LinePlotz
    Creates a line 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: live_dashboard
    NT   valueF)!colorstroke_dashoverlay_pointtitletooltipx_titley_titlex_label_angley_label_anglecolor_legend_titlestroke_dash_legend_titlecolor_legend_positionstroke_dash_legend_positionheightwidthx_limy_limcaptionlabel
show_label	containerscale	min_widtheveryinputsvisibleelem_idelem_classesrenderkeypreserved_by_keyshow_actions_buttoninteractivec       !        x   || _         || _        || _        || _        ||n|||fD %cg c]  }%|%s|%	 c}%| _        || _        |	| _        |
| _        || _        || _	        || _
        || _        || _        || _        || _        || _        || _        || _        t%        |t&              rd}t)        j*                  d       t%        |t&              rt)        j*                  d       d}|| _        || _        |#| _        ||d}t2        &| i  |||||||||| |!|"||       |$t)        j*                  d       yyc c}%w )a  
        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot.
            x: Column corresponding to the x axis. Can be grouped if datetime, e.g. 'yearmonth(date)' or 'minuteseconds(date)' with a column name 'date'. Any time unit supported by altair can be used.
            y: Column corresponding to the y axis. Can be aggregated, e.g. 'sum(price)' or 'count(price)' with a column name 'price'. Any aggregation function supported by altair can be used.
            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.
            stroke_dash: The column to determine the symbol used to draw the line, e.g. dashed lines, dashed lines with points.
            overlay_point: Whether to draw a point on the line for each (x, y) coordinate pair.
            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. Set to [] to disable tooltips.
            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. Positive values are clockwise, and negative values are counter-clockwise.
            y_label_angle: The angle for 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.
            stroke_dash_legend_title: The title given to the stroke_dash legend. By default, uses the value of the stroke_dash 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.
            stroke_dash_legend_position: The position of the stoke_dash 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: Deprecated.
            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.
            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   r,   r-   zThe `interactive` parameter is deprecated and will be removed in a future version. The LinePlot component is always interactive.)xyr   r   r   r   r   r   r   r   r   r   r    r!   r   r$   r%   r&   
isinstancestrwarningswarnr#   r"   r4   super__init__)'selfr   r7   r8   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   elem	__class__s'                                         [/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/line_plot.pyr>   zLinePlot.__init__#   ss   D 
&*G1a-0X$SW0X 	 
**"4(@%%:"+F(*

eS!EMMR fc"MMT F
#6 =Z/J!%- 	 	
  "MM@ #] 1Ys
   D7D7c                     y)Nplot r?   s    rB   get_block_namezLinePlot.get_block_name   s        c           
        ddl }|j                  ||xs |t        j                  |      |
|j	                  |
      n|j	                               |j                  ||	xs |t        j                  |      ||j	                  |      n|j	                               d}i }|r||d<   |r||d<   |r||d<   |rf|xs d	}| |   j                         j                         }t        t        t        |                  }|d
||dt        j                  ||      d|d<   |r|t        j                  |xs d	|      d}n|j                  |j                        }|r||d<    |j                  |       j                  d)i |}|j!                  d      j                  |r|j                  |j                        n|j                  d            }|j#                  d      j                  |      }|j%                  d||fD cg c]  }|s|	 c}ddd      }|j'                  |      }|j                  |j)                  ||j                  d      |j                  d                  }|s|j%                  dddd      }|j'                  |      }|j                  |j)                  ||j                  d      |j                  d            |j)                  ||j                  d      |j                  d                  } ||z   j*                  d)d d!i|}|j-                  d"g|j/                  d#d$d%&      d'(      } |j'                  |       }|S c c}w )*z%Helper for creating the scatter plot.r   N)
labelAngle)r   r*   axis)r7   r8   r   r"   r#   bottomnominal)domainrange)positionr   )fieldtyper*   legendr   )rQ   rS   r   T)clip)opacity)
strokeDash	mouseovermouseoutF)onfieldsnearestclearempty      )size)rY   r[   r\   r]      d   )rU   r`   
backgroundtransparentr7   grayg333333?none)fillfillOpacitystrokebrush)	encodingsmarknamerE   )altairXr   create_scaleAxisYuniquetolistlistrO   lencreate_legendr   	UndefinedChartencode
mark_point	mark_lineselection_point
add_params	condition
propertiesselection_intervalBrushConfig)!r   r7   r8   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   altrk   r   rN   range_stroke_dash_encodingchartpointslinesc	highlighthighlight_pts	selections!                                    rB   create_plotzLinePlot.create_plot   sv   \ 	 l --e4 , XXX7XXZ   l --e4 , XXX7XXZ  
	$ 
"'Jw#)Jx "'Jw$9$EX!5\((*113F%F,-F!$*V<$222:L	"Ig $$228DH2$  $'99S]]#; #*Ii '		% ''4)4!!t!,330=CIIcmm,399Q< 4 
 T*11=Q1R'' %{39!qA9 ( 
	 ""9-y#))A,		!E  
 // 	 0 M &&}5F]]mSYYq\399Q<P]]=#))C.#))A,O # F
 ,++S}S
S**ef#fM + 
	
   +A :s   M
M
c                    |S )a6  
        Parameters:
            payload: The data to display in a line plot.
        Returns:
            (Rarely used) passes the data displayed in the line plot as an AltairPlotData dataclass, which includes the plot information as a JSON string, as well as the type of plot (in this case, "line").
        rE   )r?   payloads     rB   
preprocesszLinePlot.preprocessQ  s	     rH   c                n   |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,                        }t/        d|j1                         d      S )a  
        Parameters:
            value: Expects a pandas DataFrame containing the data to display in the line 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 line 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, "line").
        z6No value provided for required parameters `x` and `y`.)r   r7   r8   r   r   r   r   r   r   r   r   r   r    r   r!   r$   r%   r   r"   r#   rn   line)rR   rD   r   )r9   dictr7   r8   
ValueErrorr   r   r   r   r   r   r   r   r   r   r    r   r!   r$   r%   r   r"   r#   r   to_json)r?   r   r   s      rB   postprocesszLinePlot.postprocessZ  s     =Jud3L66>TVV^UVV  ffff**,,**LLLLLL,,,,#66"&"<"<%)%B%B(,(H(H****((;;**) ! 
. 8%--/PPrH   c                     y )NrE   rF   s    rB   example_payloadzLinePlot.example_payload  s    rH   c                f    dd l } |j                  | j                  g d| j                  g di      S )Nr   )ra   r_      )r^         )pandas	DataFramer7   r8   )r?   pds     rB   example_valuezLinePlot.example_value  s'    r||TVVY	BCCrH   )NNN)Hr   zpd.DataFrame | Callable | Noner7   
str | Noner8   r   r   r   r   r   r   bool | Noner   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!   r   r"   
int | Noner#   r   r$   list[int] | Noner%   r   r&   str | I18nData | Noner'   r   r(   r   r)   boolr*   r   r+   intr,   zTimer | float | Noner-   z7Component | Sequence[Component] | set[Component] | Noner.   r   r/   r   r0   r   r1   r   r2   z(int | str | tuple[int | str, ...] | Noner3   r   r4   r   r5   r   )returnr:   )NNNNNNNNNNNNNNNNN)(r   zpd.DataFramer7   r:   r8   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   AltairPlotData | Noner   r   )r   zpd.DataFrame | dict | Noner   zAltairPlotData | dict | None)r   r   )__name__
__module____qualname____doc__r   
data_modelr   selectEVENTSr>   rG   staticmethodr   r   r   r   r   __classcell__)rA   s   @rB   r   r      s     Jmm_F 15	Y !"&%) *.""&*&*)-/3  ! "&"&)-'+"& &*JN"/38<3:$)#'yY-Y Y 	Y Y  Y #Y Y (Y Y Y $Y $Y 'Y  #-!Y" #Y:&;YR SYT UYV  WYX  YYZ '[Y\ %]Y^  _Y` aYb cYd eYf $gYh HiYj kYl mYn -oYp qYr 6sYt 1uYv "wYx !yYv 
 !"&%) *.""&*&*)-/3  ! "&"&UMMM M 	M
  M #M M (M M M $M $M 'M #-M M6&7MN OMP QMR  SMT  UM M^%Q/%Q	%%QNDrH   r   )r   
__future__r   r;   collections.abcr   r   typingr   r   r   gradio_client.documentationr	   gradio.components.baser
   gradio.components.plotr   r   r   gradio.eventsr   gradio.i18nr   r   r   gradio.componentsr   r   rE   rH   rB   <module>r      sU     "  . . . 0 , C C    ' 
pDt pD pDrH   