o
    eI                     @  s~   d Z ddlmZ ddl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mZ ed e G d	d
 d
eZdS )zgr.LinePlot() component    )annotations)CallableLiteralN)documentset_documentation_group)	_Keywords)
AltairPlotPlot	componentc                      s  e Zd ZdZ			dAd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dB fd/d0Z fd1d2ZdCd5d6Zeej	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dDd8d9Z
e																		dEdFd;d<ZdGd?d@Z  ZS )HLinePlotz
    Create a line plot.

    Preprocessing: this component does *not* accept input.
    Postprocessing: expects a pandas dataframe with the data to plot.

    Demos: line_plot, live_dashboard
    NT   )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interactivelabel
show_label	containerscale	min_widtheveryvisibleelem_idelem_classesvaluepd.DataFrame | Callable | Nonex
str | Noneyr   r   r   bool | Noner   r   list[str] | str | Noner   r   r   float | Noner   r   r   r   pLiteral['left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right', 'none'] | Noner   r   
int | Noner   r   list[int] | Noner   r   r   r    r!   r"   boolr#   r$   intr%   r&   r'   r(   c                   s   || _ || _|| _|| _|| _|| _|	| _|
| _|| _|| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _t j||||||||||d
 dS )a  
        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot.
            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.
            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.
            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.
            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.
            show_label: Whether the label should be displayed.
            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.
            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.
        )
r)   r    r!   r"   r#   r$   r&   r'   r(   r%   N)r+   r-   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   interactive_chartr   r   super__init__) selfr)   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(   	__class__ KD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/line_plot.pyr8      sB   X
zLinePlot.__init__c                   s   t   }| j|d< |S )Nr   )r7   
get_configr   )r9   configr:   r<   r=   r>      s   

zLinePlot.get_configreturnstrc                 C  s   dS )Nplotr<   )r9   r<   r<   r=   get_block_name   s   zLinePlot.get_block_name1pd.DataFrame | dict | Literal[_Keywords.NO_VALUE]c                 C  s   |||||||||	|
||||||||||g}t |rAt| tjs$td|du s,|du r0tdtj| g|R  }d| dd} ||||||| |dd	}|S )	aI  Update an existing plot component.

        If updating any of the plot properties (color, size, etc) the value, x, and y parameters must be specified.

        Parameters:
            value: The pandas dataframe containing the data to display in a scatter plot.
            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.
            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.
            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 legend. By default, uses the value of stroke 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.
            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 in the top left corner of the plot.
            show_label: Whether the label should be displayed.
            visible: Whether the plot should be visible.
        zIn order to update plot properties the value parameter must be provided, and it must be a Dataframe. Please pass a value parameter to gr.LinePlot.update.NzIn order to update plot properties, the x and y axis data must be specified. Please pass valid values for x an y to gr.LinePlot.update.altairlinetyperB   chartupdate)	r    r!   r"   r#   r$   r&   r)   r   Z__type__)any
isinstancepdZ	DataFrame
ValueErrorr   create_plotto_json)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&   
propertiesrI   Zupdated_configr<   r<   r=   rJ      sV   UzLinePlot.updatepd.DataFramec                 C  s  |du rdn|}t j||p|t||
durt j|
dnt  dt j||	p'|t||dur5t j|dnt  dd}i }|rE||d< |rK||d< |rQ||d< |rv| |   }tt	t
|}|d	||d
tj||po|dd|d< d}|rt||grt jdddd ||fD dd}|r|tj||p|dd}nt t j}|r||d< t | jdi |}|jddj|rt t jnt dd}|jddj|d}|r||}|jt |t dt dd}|| jdddi|}|r| }|S )z%Helper for creating the scatter plot.NT)Z
labelAngle)r   r#   Zaxis)r+   r-   r   r   r   Znominal)domainrange)positionr   )fieldrH   r#   legendr   singleZ	mouseoverc                 S  s   g | ]}|r|qS r<   r<   ).0cr<   r<   r=   
<listcomp>  s    z(LinePlot.create_plot.<locals>.<listcomp>)rH   onfieldsZnearest)rV   rW   r   )Zclipr   )Zopacity)Z
strokeDash      )size
backgroundtransparentr<   )altXr   Zcreate_scaleZAxisYuniquetolistlistrT   lenZcreate_legendrK   Z	selectionr)   	UndefinedZChartencodeZ
mark_pointZ	mark_lineZadd_selection	conditionrQ   r   )r)   r+   r-   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	encodingsrQ   rS   Zrange_	highlightrI   Zpointslinesr<   r<   r=   rO   %  s   /
	
zLinePlot.create_plotpd.DataFrame | dict | Nonedict[str, str] | 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| ddS )Nz6No value provided for required parameters `x` and `y`.r)   r+   r-   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   rF   rG   r<   )rL   dictr+   r-   rN   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   rP   )r9   r-   rI   r<   r<   r=   postprocess  s`   
	
zLinePlot.postprocess)NNN)>r)   r*   r+   r,   r-   r,   r   r,   r   r,   r   r.   r   r,   r   r/   r   r,   r   r,   r   r0   r   r0   r   r,   r   r,   r   r1   r   r1   r   r2   r   r2   r   r3   r   r3   r   r,   r   r.   r    r,   r!   r.   r"   r4   r#   r2   r$   r5   r%   r0   r&   r4   r'   r,   r(   r/   )r@   rA   )8r)   rD   r+   r,   r-   r,   r   r,   r   r,   r   r.   r   r,   r   r/   r   r,   r   r,   r   r0   r   r0   r   r,   r   r,   r   r1   r   r1   r   r2   r   r2   r   r3   r   r3   r   r.   r   r,   r    r,   r!   r.   r"   r.   r#   r2   r$   r2   r&   r.   )NNNNNNNNNNNNNNNNNN)*r)   rR   r+   rA   r-   rA   r   r,   r   r,   r   r.   r   r,   r   r/   r   r,   r   r,   r   r0   r   r0   r   r,   r   r,   r   r1   r   r1   r   r2   r   r2   r   r3   r   r3   r   r.   )r-   rp   r@   rq   )__name__
__module____qualname____doc__r8   r>   rC   staticmethodr   ZNO_VALUErJ   rO   rs   __classcell__r<   r<   r:   r=   r      s    z
  r   )rw   
__future__r   typingr   r   rE   rc   ZpandasrM   Zgradio_client.documentationr   r   Zgradio.components.baser   Zgradio.components.plotr   r	   r   r<   r<   r<   r=   <module>   s    