o
    e+!                     @   sP   d dl mZ d dlmZ ddlZ					dddZdd Zd	d
 Zdd ZdS )   )spec_to_html)import_vl_convert    Nc                 K   s   ddl m}m}	 |dkrtd|	 r|| } d}|dv r)t| ||fd|i|S |dkr>t| f||||d	|}
d
|
iS |dkrS|du rJtdd|d | iS |dkr[d| iS td)at  Convert a vega-lite specification to a mimebundle

    The mimebundle type is controlled by the ``format`` argument, which can be
    one of the following ['html', 'json', 'png', 'svg', 'pdf', 'vega', 'vega-lite']

    Parameters
    ----------
    spec : dict
        a dictionary representing a vega-lite plot spec
    format : string {'html', 'json', 'png', 'svg', 'pdf', 'vega', 'vega-lite'}
        the file format to be saved.
    mode : string {'vega-lite'}
        The rendering mode.
    vega_version : string
        The version of vega.js to use
    vegaembed_version : string
        The version of vegaembed.js to use
    vegalite_version : string
        The version of vegalite.js to use. Only required if mode=='vega-lite'
    engine: string {'vl-convert', 'altair_saver'}
        the conversion engine to use for 'png', 'svg', 'pdf', and 'vega' formats
    **kwargs :
        Additional arguments will be passed to the generating function

    Returns
    -------
    output : dict
        a mime-bundle representing the image

    Note
    ----
    The png, svg, pdf, and vega outputs require the altair_saver package
    r   )compile_with_vegafusionusing_vegafusionz	vega-litezmode must be 'vega-lite'vega)pngsvgpdfr   enginehtml)modevega_versionvegaembed_versionvegalite_versionz	text/htmlNzMust specify vegalite_versionz!application/vnd.vegalite.v{}+jsonjsonzapplication/jsonzPformat must be one of ['html', 'json', 'png', 'svg', 'pdf', 'vega', 'vega-lite'])Zaltair.utils.displayr   r   
ValueError_spec_to_mimebundle_with_enginer   format)specr   r   r   r   r   r   kwargsr   r   r    r   GD:\Projects\ConvertPro\env\Lib\site-packages\altair/utils/mimebundle.pyspec_to_mimebundle   sF   ,r   c                 K   s|  | dd}t||}|dkrt }ddlm} d|ddd }|dkr=|dkr2| }	d
|	iS |j| |d	}	d
|	iS |dkrY|dkrN|| }
d|
iS |j	| |d	}
d|
iS |dkr|
dd}d}|
d|}|dkrx|j| ||d}n	|j| |||d}|| }t|\}}d|id|| || difS tdj|d|dkrddl}|j| |fd|i|S tdj|d)a  Helper for Vega-Lite to mimebundle conversions that require an engine

    Parameters
    ----------
    spec : dict
        a dictionary representing a vega-lite plot spec
    format : string {'png', 'svg', 'pdf', 'vega'}
        the format of the mimebundle to be returned
    mode : string {'vega-lite', 'vega'}
        The rendering mode.
    engine: string {'vl-convert', 'altair_saver'}
        the conversion engine to use
    **kwargs :
        Additional arguments will be passed to the conversion function
    r   N	vlconvert   )SCHEMA_VERSION_.r   )
vl_versionzapplication/vnd.vega.v5+jsonr	   zimage/svg+xmlr   Zscale_factorr   H   ppi)scaler!   )r   r"   r!   z	image/png)widthheightzUnexpected format {fmt!r}fmtaltairsaverr   r   z$Unexpected normalized_engine {eng!r})Zeng)pop_validate_normalize_enginer   Zvegaliter   joinsplitZvegalite_to_vegaZvega_to_svgZvegalite_to_svggetZvega_to_pngZvegalite_to_png_pngxyr   r   altair_saverrender)r   r   r   r   r   normalized_enginevlcr   r   vgr	   r"   Zdefault_ppir!   r   factorwhr.   r   r   r   r   U   s\   


r   c                 C   s$  zt  }W n ty   d}Y nw zddl}W n ty"   d}Y nw | du r)dn|  dddd}|dkrO|du rAtd|dkrMtd	j|d
|S |dkr]|du r[td|S |du r|durm|dkrmd}|S |durud}|S |dkrtdj|d
tdj|d
tdj| dd)zHelper to validate and normalize the user-provided engine

    engine : {None, 'vl-convert', 'altair_saver'}
        the user-provided engine string
    format : string {'png', 'svg', 'pdf', 'vega'}
        the format of the mimebundle to be returned
    Nr   - r   r   zIThe 'vl-convert' conversion engine requires the vl-convert-python packager
   zmThe 'vl-convert' conversion engine does not support the {fmt!r} format.
Use the 'altair_saver' engine insteadr%   r'   zFThe 'altair_saver' conversion engine requires the altair_saver packagezqSaving charts in {fmt!r} format requires the altair_saver package: see http://github.com/altair-viz/altair_saver/zSaving charts in {fmt!r} format requires the vl-convert-python or altair_saver package: see http://github.com/altair-viz/altair_saver/z?Invalid conversion engine {engine!r}. Expected one of {valid!r})z
vl-convertr.   )r   Zvalid)r   ImportErrorr.   lowerreplacer   r   )r   r   r1   r.   r0   r   r   r   r)      sj   	
"r)   c                 C   s&   |  d}td| |d |d  S )zOread the (width, height) from a PNG header

    Taken from IPython.display
    s   IHDRz>ii      )indexstructunpack)dataZihdrr   r   r   r-      s   
r-   )NNNNN)	r   r   Z
_importersr   r>   r   r   r)   r-   r   r   r   r   <module>   s    
OOB