U
    ꥡcg                     @   s4   d dl Z d dlZddlmZ d
ddZddd	ZdS )    N   )spec_to_mimebundlewc              	   C   sF   t | tst | tjr8t| |}|| W 5 Q R X n
| | dS )zUWrite content to fp, whether fp is a string, a pathlib Path or a
    file-like objectN)
isinstancestrpathlibPurePathopenwrite)fpcontentmodef r   5/tmp/pip-unpacked-wheel-y9_o96ar/altair/utils/save.pywrite_file_or_filename   s    r   chromec                 K   s  |dkri }|dkri }|dkr\t |tr:|dd }n"t |tjrT|jd}ntd|  }|dkrd|kr~|d }n d|kr|d dd }nd	}|d
krtd	||d	kr|dkrtd|dkrt
j|f|}t||dd n|dkr0tf ||||||||d|}t||d dd n|dkrtf |||||||	|
d|}|dkrxt||d dd n0|dkrt||d dd nt||d dd ntd	|dS )a  Save a chart to file in a variety of formats

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

    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'].
        If not specified, the format will be determined from the filename.
    mode : string (optional)
        Either 'vega' or 'vegalite'. 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 'vegalite'.
    vega_version : string
        For html output, the version of vega.js to use
    vegalite_version : string
        For html output, the version of vegalite.js to use
    vegaembed_version : string
        For html output, the version of vegaembed.js to use
    embed_options : dict
        The vegaEmbed options dictionary. Default is {}
        (See https://github.com/vega/vega-embed for details)
    json_kwds : dict
        Additional keyword arguments are passed to the output method
        associated with the specified format.
    webdriver : string {'chrome' | 'firefox'}
        Webdriver to use for png or svg output
    scale_factor : float
        scale_factor to use to change size/resolution of png or svg output
    **kwargs :
        additional kwargs passed to spec_to_mimebundle.
    N.z?must specify file format: ['png', 'svg', 'pdf', 'html', 'json']r   z$schema/	vega-lite)Zvegar   z,mode must be 'vega' or 'vega-lite', not '{}'zmust specify vega-lite versionjsonr   )r   html)specformatr   vega_versionvegalite_versionvegaembed_versionembed_options	json_kwdsz	text/html)pngsvgpdf)r   r   r   r   r   r   	webdriverscale_factorr!   z	image/pngwbr#   zapplication/pdfzimage/svg+xmlzunrecognized format: '{}')r   r   splitr   r   suffixlstrip
ValueErrorZto_dictr   r   dumpsr   r   )Zchartr   r   r   r   r   r   r   r    r$   r%   kwargsr   Z	json_spec
mimebundler   r   r   save   sv    2


	
	

r.   )r   )NNNNNr   r   )r   r   r-   r   r   r.   r   r   r   r   <module>   s   
       