Ë
    úmxií2  ã                  ó0  — U d dl mZ d dlZd dlmZmZmZmZmZ ddl	m
Z
mZ ddlmZ er d dlZej                  dk\  rd dlmZ nd dlmZ ed	   Zd
ed<   e	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Ze	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Ze	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Ze	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Z	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 dd„Zd„ Zdd„Zy) é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚLiteralÚcastÚoverloadé   )Úimport_vl_convertÚvl_version_for_vl_convert)Úspec_to_html)é   é
   )Ú	TypeAlias)ÚhtmlÚjsonÚpngÚsvgÚpdfÚvegaú	vega-liter   ÚMimeBundleFormatc                 ó   — y ©N© ©	ÚspecÚformatÚmodeÚvega_versionÚvegaembed_versionÚvegalite_versionÚembed_optionsÚengineÚkwargss	            úN/home/htdocs/ttos/venv/lib/python3.12/site-packages/altair/utils/mimebundle.pyÚspec_to_mimebundler&      s   € ð !$ó    c                 ó   — y r   r   r   s	            r%   r&   r&   "   ó   € ð r'   c                 ó   — y r   r   r   s	            r%   r&   r&   .   r)   r'   c                 ó   — y r   r   r   s	            r%   r&   r&   :   s   € ð -0r'   c           	     óà  — ddl m}	 ddlm}
m} |dk7  rd}t        |«      ‚|} |«       r
 |
| «      } d}|€|	j                  j                  di «      }n|}t        |«      }|d	v r<t        | t        d
|«      |f||j                  dd«      |j                  dd«      dœ|¤ŽS |dk(  rt        | f|||||dœ|¤Ž}d|iS |dk(  r|€d}t        |«      ‚d|d   › d�| iS |dk(  rd| iS d}t        |«      ‚)aE  
    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'
    embed_options : dict (optional)
        The vegaEmbed options dictionary. Defaults to the embed options set with
        alt.renderers.set_embed_options().
        (See https://github.com/vega/vega-embed for details)
    engine: string {'vl-convert'}
        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 vl-convert package
    r   )Ú	renderers)Úcompile_with_vegafusionÚusing_vegafusionr   zmode must be 'vega-lite'r   Nr"   >   r   r   r   r   ú$Literal['png', 'svg', 'pdf', 'vega']ÚformatLocaleÚtimeFormatLocale)r#   Úformat_localeÚtime_format_localer   )r   r   r    r!   r"   z	text/htmlzMust specify vegalite_versionzapplication/vnd.vegalite.vz+jsonr   zapplication/jsonzPformat must be one of ['html', 'json', 'png', 'svg', 'pdf', 'vega', 'vega-lite'])Úaltairr-   Úaltair.utils.displayr.   r/   Ú
ValueErrorÚoptionsÚgetÚpreprocess_embed_optionsÚ_spec_to_mimebundle_with_enginer   r   )r   r   r   r   r    r!   r"   r#   r$   r-   r.   r/   ÚmsgÚinternal_modeÚfinal_embed_optionsr   s                   r%   r&   r&   F   sn  € õd !ßNàˆ{ÒØ(ˆÜ˜‹oÐà26€MÙÔÙ& tÓ,ˆØˆð ÐØ'×/Ñ/×3Ñ3°OÀRÓHÑà+Ðä,Ð-@ÓA€MàÐ.Ñ.Ü.ØÜÐ7¸Ó@Øð
ð Ø'×+Ñ+¨N¸DÓAØ,×0Ñ0Ð1CÀTÓJñ
ð ñ
ð 	
ð 
�6Ò	ÜØð
àØ%Ø/Ø-Ø'ñ
ð ñ
ˆð ˜TÐ"Ð"Ø	�;Ò	ØÐ#Ø1ˆCÜ˜S“/Ð!Ø,Ð-=¸aÑ-@Ð,AÀÐGÈÐNÐNØ	�6Ò	Ø" DÐ)Ð)ðIð 	ô ˜‹oÐr'   c                ó  — |j                  dd«      }t        ||«      }|dk(  �rWt        «       }t        «       }	|dk(  r"|dk(  r| }
d|
iS |j	                  | |	¬«      }
d|
iS |dk(  r6|dk(  r|j                  | ||¬«      }d
|iS |j                  | |	||¬	«      }d
|iS |dk(  r}|j                  dd«      }d}|j                  d|«      }|dk(  r|j                  | ||||¬«      }n|j                  | |	||||¬«      }||z  }t        |«      \  }}d|id||z  ||z  dœifS |dk(  rJ|j                  dd«      }|dk(  r|j                  | |||¬«      }d|iS |j                  | |	|||¬«      }d|iS d|›�}t        |«      ‚d|›�}t        |«      ‚)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'}
        the conversion engine to use
    format_locale : str or dict
        d3-format locale name or dictionary. Defaults to "en-US" for United States English.
        See https://github.com/d3/d3-format/tree/main/locale for available names and example
        definitions.
    time_format_locale : str or dict
        d3-time-format locale name or dictionary. Defaults to "en-US" for United States English.
        See https://github.com/d3/d3-time-format/tree/main/locale for available names and example
        definitions.
    **kwargs :
        Additional arguments will be passed to the conversion function
    r#   NÚ	vlconvertr   )Ú
vl_versionzapplication/vnd.vega.v6+jsonr   )r3   r4   )rA   r3   r4   zimage/svg+xmlr   Úscale_factorr	   éH   Úppi)ÚscalerD   r3   r4   )rA   rE   rD   r3   r4   z	image/png)ÚwidthÚheightr   )rE   r3   r4   )rA   rE   r3   r4   zapplication/pdfzUnexpected format zUnexpected normalized_engine )ÚpopÚ_validate_normalize_enginer
   r   Úvegalite_to_vegaÚvega_to_svgÚvegalite_to_svgr9   Úvega_to_pngÚvegalite_to_pngÚ_pngxyÚvega_to_pdfÚvegalite_to_pdfr7   )r   r   r   r3   r4   r$   r#   Únormalized_engineÚvlcrA   Úvgr   rE   Údefault_ppirD   r   ÚfactorÚwÚhr   r<   s                        r%   r;   r;   °   sU  € ðD �Z‰Z˜ $Ó'€FÜ2°6¸6ÓBÐà˜KÓ'ÜÓ!ˆÜ.Ó0ˆ
Ø�VÒØ�vŠ~Ø�ð 3°BÐ7Ð7ð ×)Ñ)¨$¸:Ð)ÓF�Ø2°BÐ7Ð7Ø�uŠ_Ø�vŠ~Ø—o‘oØØ"/Ø'9ð &ó �ð $ SÐ)Ð)ð ×)Ñ)ØØ)Ø"/Ø'9ð	 *ó �ð $ SÐ)Ð)Ø�uŠ_Ø—J‘J˜~¨qÓ1ˆEàˆKØ—*‘*˜U KÓ0ˆCØ�vŠ~Ø—o‘oØØØØ"/Ø'9ð &ó ‘ð ×)Ñ)ØØ)ØØØ"/Ø'9ð *ó �ð ˜;Ñ&ˆFÜ˜#“;‰DˆAˆqØ Ð%Ø q¨6¡z¸QÀ¹ZÑHð(ð ð ð �uŠ_Ø—J‘J˜~¨qÓ1ˆEØ�vŠ~Ø—o‘oØØØ"/Ø'9ð	 &ó �ð & sÐ+Ð+ð ×)Ñ)ØØ)ØØ"/Ø'9ð *ó �ð & sÐ+Ð+ð ' v jÐ1ˆCÜ˜S“/Ð!ð .Ð.?Ð-BÐCˆÜ˜‹oÐr'   c                ó"  — 	 t        «       }| €dn/| j                  «       j                  dd«      j                  dd«      }|dk(  r|€d}t	        |«      ‚|S |€|�d}|S d|›d�}t	        |«      ‚d	| ›d
�}t	        |«      ‚# t        $ r d}Y Œ�w xY w)zõ
    Helper to validate and normalize the user-provided engine.

    engine : {None, 'vl-convert'}
        the user-provided engine string
    format : string {'png', 'svg', 'pdf', 'vega'}
        the format of the mimebundle to be returned
    Nú-Ú Ú_r@   zIThe 'vl-convert' conversion engine requires the vl-convert-python packagezSaving charts in z… format requires the vl-convert-python package: see https://altair-viz.github.io/user_guide/saving_charts.html#png-svg-and-pdf-formatzInvalid conversion engine z. Expected vl-convert)r
   ÚImportErrorÚlowerÚreplacer7   )r#   r   rS   rR   r<   s        r%   rI   rI   &  sÖ   € ðÜÓ!ˆð �‰ F§L¡L£N×$:Ñ$:¸3ÀÓ$C×$KÑ$KÈCÐQSÓ$Tð ð
 ˜KÒ'Øˆ;Ø]ˆCÜ˜S“/Ð!ð Ðð 
Ð	"Øˆ?Ø +Ðð Ðð $ F :ð .hð hð ô ˜S“/Ð!à*¨6¨*Ð4IÐJˆÜ˜‹oÐøô1 ò ØŠðús   ‚
B  Â BÂBc                ób   — | j                  d«      }t        j                  d| |dz   |dz    «      S )zU
    Read the (width, height) from a PNG header.

    Taken from IPython.display
    s   IHDRz>iié   é   )ÚindexÚstructÚunpack)ÚdataÚihdrs     r%   rO   rO   Q  s2   € ð �:‰:�gÓ€Dä�=‰=˜  T¨A¡X°°r±	Ð :Ó;Ð;r'   c                ó.  — | xs i j                  «       } | j                  dd«      }t        |t        «      rt	        «       }|j                  |«      | d<   | j                  dd«      }t        |t        «      rt	        «       }|j                  |«      | d<   | S )a  
    Preprocess embed options to a form compatible with Vega Embed.

    Parameters
    ----------
    embed_options : dict
        The embed options dictionary to preprocess.

    Returns
    -------
    embed_opts : dict
        The preprocessed embed options dictionary.
    r1   Nr2   )Úcopyr9   Ú
isinstanceÚstrr
   Úget_format_localeÚget_time_format_locale)r"   r3   rS   r4   s       r%   r:   r:   \  sš   € ð #Ò( b×.Ñ.Ó0€Mð "×%Ñ% n°dÓ;€MÜ�-¤Ô%ÜÓ!ˆØ(+×(=Ñ(=¸mÓ(Lˆ�nÑ%à&×*Ñ*Ð+=¸tÓDÐÜÐ$¤cÔ*ÜÓ!ˆØ,/×,FÑ,FØó-
ˆÐ(Ñ)ð Ðr'   )......)r   údict[str, Any]r   zLiteral['json', 'vega-lite']r   úLiteral['vega-lite'] | Noner   ú
str | Noner    rp   r!   rp   r"   údict[str, Any] | Noner#   úLiteral['vl-convert'] | NoneÚreturnzdict[str, dict[str, Any]])r   rn   r   zLiteral['html']r   ro   r   rp   r    rp   r!   rp   r"   rq   r#   rr   rs   zdict[str, str])r   rn   r   zLiteral['pdf', 'svg', 'vega']r   ro   r   rp   r    rp   r!   rp   r"   rq   r#   rr   rs   rn   )r   rn   r   zLiteral['png']r   ro   r   rp   r    rp   r!   rp   r"   rq   r#   rr   rs   z%tuple[dict[str, Any], dict[str, Any]])NNNNNN)r   rn   r   r   r   ro   r   rp   r    rp   r!   rp   r"   rq   r#   rr   rs   z6dict[str, Any] | tuple[dict[str, Any], dict[str, Any]])NN)r   Údictr   r0   r   zLiteral['vega-lite', 'vega']r3   ústr | dict | Noner4   ru   rs   r   )r#   rr   r   r0   rs   rk   )r"   rt   rs   rt   )Ú
__future__r   rd   Útypingr   r   r   r   r   Ú
_importersr
   r   r   r   ÚsysÚversion_infor   Útyping_extensionsr   Ú__annotations__r&   r;   rI   rO   r:   r   r'   r%   ú<module>r}      s/  ðÞ "ã ß >Õ >ç DÝ áÛà
×Ñ˜7Ò"Þ$å/à%Ø<ñÐ �)ó ð
 
ð ),Ø"Ø$'Ø#&Ø+.Ø+.ð
$Ø
ð
$à(ð
$ð &ð
$ð ð	
$ð
 "ð
$ð !ð
$ð )ð
$ð )ð
$ð ò
$ó 
ð
$ð 
ð ),Ø"Ø$'Ø#&Ø+.Ø+.ð
Ø
ð
àð
ð &ð
ð ð	
ð
 "ð
ð !ð
ð )ð
ð )ð
ð ò
ó 
ð
ð 
ð ),Ø"Ø$'Ø#&Ø+.Ø+.ð
Ø
ð
à)ð
ð &ð
ð ð	
ð
 "ð
ð !ð
ð )ð
ð )ð
ð ò
ó 
ð
ð 
ð ),Ø"Ø$'Ø#&Ø+.Ø+.ð
0Ø
ð
0àð
0ð &ð
0ð ð	
0ð
 "ð
0ð !ð
0ð )ð
0ð )ð
0ð +ò
0ó 
ð
0ð )-Ø#Ø$(Ø#'Ø+/Ø+/ðgØ
ðgàðgð &ðgð ð	gð
 "ðgð !ðgð )ðgð )ðgð <ógð\ (,Ø,0ðsØ
ðsà0ðsð 'ðsð %ð	sð
 *ðsð 	ósðl(Ø(ð(à0ð(ð 	ó(òV<ôr'   