
    ch2                    X   % S SK Jr  S SKrS SKJrJrJrJrJr  SSK	J
r
Jr  SSKJr  \(       a!  S SKr\R                  S:  a  S SKJr  OS SKJr  \S	   rS
\S'   \      S                 SS jj5       r\      S                 SS jj5       r\      S                 SS jj5       r\      S                 SS jj5       r      S                 SS jjr  S           SS jjr      SS jrS rSS jrg)     )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                    g N 	specformatmodevega_versionvegaembed_versionvegalite_versionembed_optionsenginekwargss	            jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\altair/utils/mimebundle.pyspec_to_mimebundler&      s     !$    c                    g r   r   r   s	            r%   r&   r&   "        r'   c                    g r   r   r   s	            r%   r&   r&   .   r)   r'   c                    g r   r   r   s	            r%   r&   r&   :   s     -0r'   c           	        SSK Jn	  SSKJn
Jn  US:w  a  Sn[        U5      eUnU" 5       (       a
  U
" U 5      n SnUc  U	R                  R                  S0 5      nOUn[        U5      nUS	;   aC  [        U [        [        S
   U5      U4UUR                  SS5      UR                  SS5      S.UD6$ US:X  a  [        U 4UUUUUS.UD6nSU0$ US:X  a  Uc  Sn[        U5      eSUS    S3U 0$ US:X  a  SU 0$ Sn[        U5      e)a  
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   )r   r   r   r   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.   r/   msginternal_modefinal_embed_optionsr   s                   r%   r&   r&   F   sv   d !N{(o26M&t, '//33ORH+,-@AM...45v>
 '++NDA,001CTJ
 
 	
 
6	
%/-'
 
 T""	;	#1CS/!,-=a-@,AGNN	6	"D))I 	 or'   c           	        UR                  SS5      n[        Xa5      nUS:X  GaI  [        5       n[        5       n	US:X  a  US:X  a  U n
SU
0$ UR	                  X	S9n
SU
0$ US:X  a1  US:X  a  UR                  U UUS9nS
U0$ UR                  U U	UUS	9nS
U0$ US:X  aw  UR                  SS5      nSnUR                  SU5      nUS:X  a  UR                  U UUUUS9nOUR                  U U	UUUUS9nX-  n[        U5      u  nnSU0SUU-  UU-  S.04$ US:X  aE  UR                  SS5      nUS:X  a  UR                  U UUUS9nSU0$ UR                  U U	UUUS9nSU0$ SU< 3n[        U5      eSU< 3n[        U5      e)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.v5+jsonr   )r2   r3   )r@   r2   r3   zimage/svg+xmlr   scale_factorr	   H   ppi)scalerC   r2   r3   )r@   rD   rC   r2   r3   z	image/png)widthheightr   )rD   r2   r3   )r@   rD   r2   r3   zapplication/pdfzUnexpected format zUnexpected normalized_engine )pop_validate_normalize_enginer
   r   vegalite_to_vegavega_to_svgvegalite_to_svgr8   vega_to_pngvegalite_to_png_pngxyvega_to_pdfvegalite_to_pdfr6   )r   r   r   r2   r3   r$   r#   normalized_enginevlcr@   vgr   rD   default_ppirC   r   factorwhr   r;   s                        r%   r:   r:      sO   D ZZ$'F26BK'!.0
Vv~ 3B77 ))$)F2B77u_v~oo"/'9 &  $S)) )))"/'9	 *  $S))u_JJ~q1EK**UK0Cv~oo"/'9 &  )))"/'9 *  &F#;DAq%q6zQZH(   u_JJ~q1Ev~oo"/'9	 &  &s++ )))"/'9 *  &s++ 'vj1CS/! ..?-BCor'   c                4    [        5       nU c  SO/U R                  5       R                  SS5      R                  SS5      nUS:X  a  Uc  Sn[	        U5      e U$ Uc  Ub  SnU$ SU< S3n[	        U5      eS	U < S
3n[	        U5      e! [         a    Sn Nf = f)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replacer6   )r#   r   rR   rQ   r;   s        r%   rH   rH   &  s    ! FLLN$:$:3$C$K$KCQS$T 
 K';]CS/!   
	"? +  $F: .h h  S/!*6*4IJo1  s   
B BBc                b    U R                  S5      n[        R                  " SXS-   US-    5      $ )zI
read the (width, height) from a PNG header.

Taken from IPython.display
s   IHDRz>ii      )indexstructunpack)dataihdrs     r%   rN   rN   Q  s0     ::gD==AXr	 :;;r'   c                L   U =(       d    0 R                  5       n U R                  SS5      n[        U[        5      (       a  [	        5       nUR                  U5      U S'   U R                  SS5      n[        U[        5      (       a  [	        5       nUR                  U5      U S'   U $ )z
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.
r0   Nr1   )copyr8   
isinstancestrr
   get_format_localeget_time_format_locale)r"   r2   rR   r3   s       r%   r9   r9   \  s     #(b..0M "%%nd;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    ro   r!   ro   r"   dict[str, Any] | Noner#   Literal['vl-convert'] | Nonereturnzdict[str, dict[str, Any]])r   rm   r   zLiteral['html']r   rn   r   ro   r    ro   r!   ro   r"   rp   r#   rq   rr   zdict[str, str])r   rm   r   zLiteral['pdf', 'svg', 'vega']r   rn   r   ro   r    ro   r!   ro   r"   rp   r#   rq   rr   rm   )r   rm   r   zLiteral['png']r   rn   r   ro   r    ro   r!   ro   r"   rp   r#   rq   rr   z%tuple[dict[str, Any], dict[str, Any]])NNNNNN)r   rm   r   r   r   rn   r   ro   r    ro   r!   ro   r"   rp   r#   rq   rr   z6dict[str, Any] | tuple[dict[str, Any], dict[str, Any]])NN)r   dictr   $Literal['png', 'svg', 'pdf', 'vega']r   zLiteral['vega-lite', 'vega']r2   str | dict | Noner3   ru   rr   r   )r#   rq   r   rt   rr   rj   )r"   rs   rr   rs   )
__future__r   rc   typingr   r   r   r   r   
_importersr
   r   r   r   sysversion_infor   typing_extensionsr   __annotations__r&   r:   rH   rN   r9   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'   