
    g                        d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZ ddlmZ erd d	lmZ 	 	 d	 	 	 	 	 	 	 	 	 dd
Z	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotationsN)IOTYPE_CHECKINGAnyLiteral)using_vegafusion)deprecated_warn)data_transformers   )spec_to_mimebundle)Pathc                    t        | t        t        j                  f      rAt        j                  |       j	                  ||      5 }|j                  |       ddd       y| j                  |       y# 1 sw Y   yxY w)zRWrite content to fp, whether fp is a string, a pathlib Path or a file-like object.modeencodingN)
isinstancestrpathlibr   openwrite)fpcontentr   r   fs        F/var/www/openai/venv/lib/python3.12/site-packages/altair/utils/save.pywrite_file_or_filenamer      sb     "sGLL)*\\"""x"@AGGG A@ 	 A@s   A44A=c                    | \t        |t        t        j                  f      r/t        j                  |      j                  j                  d      } nd}t        |      | dk7  r|rt        j                  dd       | S )z1Inspect the format argument in the save function..zGmust specify file format: ['png', 'svg', 'pdf', 'html', 'json', 'vega']htmlz-inline argument ignored for non HTML formats.r   )
stacklevel)	r   r   r   r   suffixlstrip
ValueErrorwarningswarn)formatr   inlinemsgs       r   set_inspect_format_argumentr(       sq     ~b3-.\\"%,,33C8F@  S/!FERSTM    c                    | (d|v r|d   } nd|v r|d   j                  d      d   } nd} | dk7  rd|  d}t        |      | dk(  r|d}t        |      | S )	z/Inspect the mode argument in the save function.r   z$schema/z	vega-litezmode must be 'vega-lite', not ''zmust specify vega-lite version)splitr"   )r   embed_optionsspecvegalite_versionr'   s        r   set_inspect_mode_argumentr2   4   s     |]" (D$	?((-b1DD{24&:o{/7.oKr)   c                   	
 j                  dd      x}rt        dd       xs i j                  dd      t              d
 
	fd}t	               r%t        j                         5   |        ddd       yt        j                  d	      5  t        j                         5   |        ddd       ddd       y# 1 sw Y   yxY w# 1 sw Y   xY w# 1 sw Y   yxY w)a  
    Save a chart to file in a variety of formats.

    Supported formats are [json, html, png, svg, pdf]

    Parameters
    ----------
    chart : alt.Chart
        the chart instance to save
    fp : string filename, pathlib.Path or file-like object
        file to which to write the chart.
    format : string (optional)
        the format to write: one of ['json', 'html', 'png', 'svg', 'pdf'].
        If not specified, the format will be determined from the filename.
    mode : string (optional)
        Must be 'vega-lite'. If not specified, then infer the mode from
        the '$schema' property of the spec, or the ``opt`` dictionary.
        If it's not specified in either of those places, then use 'vega-lite'.
    vega_version : string (optional)
        For html output, the version of vega.js to use
    vegalite_version : string (optional)
        For html output, the version of vegalite.js to use
    vegaembed_version : string (optional)
        For html output, the version of vegaembed.js to use
    embed_options : dict (optional)
        The vegaEmbed options dictionary. Default is {}
        (See https://github.com/vega/vega-embed for details)
    json_kwds : dict (optional)
        Additional keyword arguments are passed to the output method
        associated with the specified format.
    scale_factor : float (optional)
        scale_factor to use to change size/resolution of png or svg output
    engine: string {'vl-convert'}
        the conversion engine to use for 'png', 'svg', and 'pdf' formats
    inline: bool (optional)
        If False (default), the required JavaScript libraries are loaded
        from a CDN location in the resulting html file.
        If True, the required JavaScript libraries are inlined into the resulting
        html file so that it will work without an internet connection.
        The vl-convert-python package is required if True.
    **kwargs :
        additional kwargs passed to spec_to_mimebundle.
    	webdriverNzThe webdriver argument is not relevant for the new vl-convert engine which replaced altair_saver. The argument will be removed in a future release.z5.0.0)versionr   zutf-8c                    j                  ddi      } t        xs i |       }dk(  r&t        j                  | fi }t	        |d	       y dk(  r.rdd	<   t        d| |d
}t	        |d   d	       y dk(  r*t        d| |
d	}t	        |d   d   d       y dv r?t        d| |
d	}dk(  rt	        |d   d       y t	        |d   d	       y d d}t        |      )Npre_transformF)contextjsonwr   r   r&   template)r0   r%   r   vega_versionr1   vegaembed_versionr/   	json_kwdsz	text/htmlpng)	r0   r%   r   r<   r1   r=   r/   scale_factorenginer   z	image/pngwb)r   >   pdfsvgvegarC   zapplication/pdfzimage/svg+xmlzUnsupported format: 'r-    )to_dictr2   r9   dumpsr   r   r"   )r0   
inner_mode	json_specmb_htmlmb_pngmb_anyr'   chartr/   r   rA   r%   r   r&   r>   kwargsr   r@   r<   r=   r1   s          r   perform_savezsave.<locals>.perform_save   s   }}ou%=}>.-%2t-=

 V

4595I"2ysXNv%-z"( 
)!1"3+#
 
G #GK(sX u_' )!1"3+) F #2vay'=DI--' )!1"3+) F &r62C+D4P&/cH *&3CS/!r)   default)returnNone)popr	   getr(   r   r
   disable_max_rowsenable)rN   r   r<   r=   r%   r   r1   r/   r>   r@   rA   r&   rO   _rP   r   s   `````````````  @r   saverY   N   s    t JJ{D))q)@	
 RIzz*g.H(V<F>" >" >"@  //1N 21 %%i02C2T2T2VN 3W00 21 3W2V00s0   C,C2C&	C2C#&C/	+C22C;)r:   N)
r   str | Path | IOr   zstr | bytesr   r   r   
str | NonerR   rS   )r%   r[   r   rZ   r&   boolrR   r   )
r   Literal['vega-lite'] | Noner/   dict[str, Any]r0   r^   r1   r[   rR   zLiteral['vega-lite'])NNNNNr   NF)r   rZ   r<   r[   r=   r[   r%   z3Literal['json', 'html', 'png', 'svg', 'pdf'] | Noner   r]   r1   r[   r/   dict | Noner>   r_   r@   floatrA   zLiteral['vl-convert'] | Noner&   r\   rR   rS   )
__future__r   r9   r   r#   typingr   r   r   r   altair.utils._vegafusion_datar   altair.utils.deprecationr	   altair.vegalite.v5.datar
   
mimebundler   r   r   r(   r2   rY   rF   r)   r   <module>rg      sa   "    2 2 : 4 5 * 	  	
 
+59(
%!  !	
 > CG(,#'!%!+/RR R "	R
 @R &R !R R R R )R R 
Rr)   