
    LegD                     b    d dl mZ ddlmZ  G d d          Zd ZddZ G d	 d
e          ZdS )    )defaultdict   )Storec                       e Zd ZdZi Z eg           Z ee                                          Zi Z	i Z
ed             Zed             Zed             Zed             ZdS )KeywordSettingsz_
    Base class for options settings used to specified collections of
    keyword options.
    c                     dS )zh
        Allows updating options depending on class attributes
        and unvalidated options.
        N )clsoptionsitemss      7lib/python3.11/site-packages/holoviews/util/settings.pyupdate_optionszKeywordSettings.update_options   s          c                 j   |                      ||          }| j        D ]}||v r||         }| j        |         t          t                    rnt          t
                    rt          |t
                    st          d|d          t	          |                                          t	                                                    z
  }|rt          d|d|d           fd|                                D             }|reg }|                                D ],\  }	}
|	                    d|
d|d|	d|	                    -t          d	
                    |                    nt          t                    r>|vr:|| j        v r | j        |         ||           nft          d|d
|d           t          t                    r9d         |cxk    rd         k    s n ||fz   }t           dj        |           |||<   |                     |||          S )z;Given a keyword specification, validate and compute optionszValue z not a dict typez	Keywords z for z option not one of c                 H    i | ]\  }}t          ||                   ||S r	   )
isinstance).0kvalloweds      r   
<dictcomp>z/KeywordSettings.get_options.<locals>.<dictcomp>-   sH     "D "D "D41a)3Awqz)B)B"D!Q "D "D "Dr   z
 option's z attribute not of type 
z	 for key z not one of r      z-Value {!r} for key {!r} not between {} and {})r   defaultsr   r   setdict
ValueErrorkeysr   appendjoinlistcustom_exceptionstupleformat	_validate)r
   r   r   warnfnkeywordvalue
disallowed
wrong_typeerrorsr   r   infor   s               @r   get_optionszKeywordSettings.get_options   s    $$We44| 	) 	)G%g+g.gs++ hd.. h%eT22 M()K%)K)K)KLLL!$UZZ\\!2!2S5H5H!HJ! q()oZ)o)o)o)ofm)o)oppp"D "D "D "D5;;== "D "D "DJ! <!##-#3#3#5#5 ~ ~CAa"MM*|1*|*|W*|*|RS*|*|nuvwnx*|*|}}}}(6):):;;;	<
  .. h53G3G#"7776-g6ugwOOOO()d%)d)dG)d)d[b)d)deee// h#AJ%====71:==== 'w6()_)X)_ae)fggg#( }}WeV444r   c                      t          d          )z-Allows subclasses to check options are valid.z*KeywordSettings is an abstract base class.)NotImplementedError)r
   r   r   r&   s       r   r%   zKeywordSettings._validate@   s     ""NOOOr   c                 h   t          t          |                    d                              }|r|                                }d}|                                | j        v r|                                }n$t          d|                                           |                                                                }t          |          dk    r| j        D ]X}|                    |          rA|dt          |                                                    }|	                    |            n+Yt          d|                                d                    | d| }	 |
                    t          d| d                     n # t          $ r t          d|           w xY w||S )	zJ
        Given the keyword string, parse a dictionary of options.
        =NzInvalid keyword: r   zdict()zCould not evaluate keyword: )r!   reversedsplitpopstripr   SyntaxErrorlenendswithr   updateeval	Exception)	r
   liner   unprocessedchunkkeyr(   optionr'   s	            r   extract_keywordsz KeywordSettings.extract_keywordsF   s   
 8DJJsOO4455 	LOO%%EC{{}}++kkmm!"Eekkmm"E"EFFFOO%%++--E;1$$!k O OF~~f--  %mF|m 4 : : < <#**6222
 &&M%++--:K&M&MNNN&&u&&GLT"4'"4"4"4556666 L L L!"J"J"JKKKL+  	L. s   (&F F,N)__name__
__module____qualname____doc__r   r   r   r   r   r"   hiddenclassmethodr   r-   r%   rC   r	   r   r   r   r      s         
 GtBxxHtHNN$$%%G  F   [ 5 5 [5B P P [P
   [  r   r   c                      g } t           j        D ]i|                                t           j                 }d |j                            d          d         j        D             }| fd|D             z  } j| S )Nc                     g | ]
}|d k    |S )defaultr	   )r   modes     r   
<listcomp>z!list_backends.<locals>.<listcomp>l   s,     ( ( ($Y&& &&&r   existingrM   c                     g | ]	} d | 
S ):r	   )r   rM   backends     r   rN   z!list_backends.<locals>.<listcomp>n   s'    ;;;T(($((;;;r   )r   	renderersr   paramobjects)backendsrenderermodesrR   s      @r   list_backendsrY   g   s    H? < <   ?7+( ((."8"8"D"DV"L"T ( ( (;;;;U;;;;Or   Nc                 6   |4t           j        }|t           j        v rt           j        |         j        nd}n7|                    d          }t          |          dk    r|n	|d         df\  }}|t           j        v rt           j        |         j        |          S g S )zI
    Returns list of supported formats for a particular
    backend.
    NrQ   r   r   rL   )r   current_backendrS   rM   r5   r9   mode_formats)format_typerR   rM   r5   s       r   list_formatsr^   r   s    
 '075?0J0Juw',,PTc""!$UQU1Xy4I%/!!w'4[AA	r   c                      e Zd ZdZ e            ddg ed           ed          ddgd ed	          fd ed	          fd
hd ed	          fd ed	          fd
hddgg dd dD             dZ eg d          Z	g dZ
g dZi Z ee          ZdZd
Zg Zd Zd ZeedZdZedd            Zed             Zed             Ze	 	 dd            Zed             Zed             Zed             Zed d            Zd
S )!OutputSettingsz<
    Class for controlling display and output settings.
    TFfigholomapembedliver   infNr   )leftbottomrighttoptop_left	top_rightbottom_leftbottom_rightleft_topleft_bottom	right_topright_bottomc                     i | ]
}|t           S r	   )str)r   r   s     r   r   zOutputSettings.<dictcomp>   s0     "O "O "O&' #$S "O "O "Or   )
widthheightpaddingmarginz	max-widthz	min-widthz
max-heightz
min-heightoutlinefloat)rR   centerra   rb   widgetsfps
max_framesmax_branchessizedpifilenamer,   widget_locationcss))rR   N)rz   T)ra   N)rb   N)r{   N)r|   N)r}   i  )r   N)r   N)r   N)r,   F)r   N)r   N)r}   r,   r   )
ra   rb   r   r|   r   r   widget_moderM   r   rz   c                 (    t          d| d          )NzFormat z! does not appear to be supported.)r=   r(   r'   r   s      r   missing_dependency_exceptionz+OutputSettings.missing_dependency_exception   s    L%LLLMMMr   c                 j    | t           j        v rt          d| d          t          d| d          )NzBackend z? not available. Has it been loaded with the notebook_extension?z does not exist)r`   backend_listr   r   s      r   missing_backend_exceptionz(OutputSettings.missing_backend_exception   sD    N///ppppqqq@@@@AAAr   )rb   rR   c                 b   g d}d}d}d}d}d}d| j         d         z  }d	}	d
}
d| j         d         z  }d| j         d         z  }d}d}|||||||	|
||||g}g d}|r>dd                    d |D                       z  }d                    |g|z   |z             S d                    ||z             S )N)z-Helper used to set HoloViews display options.z<Arguments are supplied as a series of keywords in any order: z,backend      : The backend used by HoloViewsz'fig          : The static figure formatz,holomap      : The display type for holomapsz*widgets      : The widget mode for widgetsz8fps          : The frames per second used for animationsz=max_frames   : The max number of frames rendered (default %r)r}   z6size         : The percentage size of displayed outputz-dpi          : The rendered dpi of the figurezCfilename    : The filename of the saved output, if any (default %r)r   zJinfo    : The information to page about the displayed objects (default %r)r,   zHcss     : Optional css style attributes to apply to the figure image tagzBwidget_location : The position of the widgets relative to the plotrR   ra   rb   r{   r|   r}   r   r   r   r,   r   r   z
output(%s)
z, c              3       K   | ]	}d |z  V  
dS )z%s=NoneNr	   )r   kws     r   	<genexpr>z5OutputSettings._generate_docstring.<locals>.<genexpr>   s&      8[8[BR8[8[8[8[8[8[r   r   )r   r    )r
   	signatureintrorR   ra   rb   r{   r|   r}   r   r   r   r,   r   r   descriptionskeywordsdoc_signatures                     r   _generate_docstringz"OutputSettings._generate_docstring   s   U U U@;@>KU\23
I@Z|J/0\,v&'[^gwZXtS/CQ Q Q 	3,tyy8[8[RZ8[8[8[/[/[[M99m_u4|CDDD99U\1222r   c                 J    ddl mm} g d} |fd|D                       S )Nr   )	Parameter	Signaturer   c                 2    g | ]} |j                   S r	   )KEYWORD_ONLY)r   r   r   s     r   rN   z6OutputSettings._generate_signature.<locals>.<listcomp>   s(    SSSB))B	(>??SSSr   )inspectr   r   )r
   r   r   r   s      @r   _generate_signaturez"OutputSettings._generate_signature   sT    00000000Q Q QySSSS(SSSTTTr   c                 *   dt           j        v rnTd|v rP|d         t           j        vr<d|d         ddt           j        z   }|t          d|            n ||           t           j        }t           j        |                             |          S )z1Validation of edge cases and incompatible optionshtmlra   z Requesting output figure format  znot in display formats Nz	Warning: )r   display_formatsprintr[   rS   validate)r
   r   r   r&   msgrR   s         r   r%   zOutputSettings._validate   s     U***e^^eE4I I IGeElGGGHu/DHHIC~'#''((((s'w'00999r   c                     |r|rt          d          t          j        st          d          t          j        }|t          j        v rWt          j        |         }|dz   |j        z   }	 fd|j                                                                        D             }
n	d }|dz   }	i }
|}t          t          j
                  }	 |C|                    d          d                                         }                     |i           }                     |i |          }d|v r|d         }d|vr|dz  }n|	}|                    d          d         }t          j        |         } fd	|j                                                                        D             }|t          _
                             ||           n# t           $ rs}|t          _
                             |           |t          j        vrt          d
|d|d          t%          d|            |rt%          |           Y d }~d S d }~ww xY w|||r |||           |t          _
                             ||           |                    d          d         |k    r/                     |                                |
|	           d S d S d S )Nz<Please either specify a string to parse or keyword argumentszNo plotting extension is currently loaded. Ensure you load an plotting extension with hv.extension or import it explicitly from holoviews.plotting before using hv.output.rQ   c                 .    i | ]\  }}|j         v ||S r	   render_paramsr   r   r   r
   s      r   r   z)OutputSettings.output.<locals>.<dictcomp>  s6     6 6 6DAq3#444 a444r   :default#r   rR   c                 .    i | ]\  }}|j         v ||S r	   r   r   s      r   r   z)OutputSettings.output.<locals>.<dictcomp>6  s6     8 8 8da !S%6 6 6  6 6 6r   z The selected plotting extension z; has not been loaded, ensure you load it with hv.extension(z) before using hv.output.zError: )r   r   rS   r[   rM   rT   valuesr   r   r`   r   r5   r7   rC   r-   _set_render_optionsr=   set_backendr   )r
   r>   cellcell_runnerhelp_promptr&   kwargsprev_backendprev_rendererprev_backend_specprev_paramsrR   prev_restorer   backend_specrW   r   es   `                 r   outputzOutputSettings.output
  sX     	KF 	K : ; ; ; 	K J K K K ,5?**!OL9M ,S 01C C6 6 6 6M,?,F,F,H,H,N,N,P,P 6 6 6KK !M ,Z 7KN233#	zz#q)//11--dB77oofb&99G G##&y1l** J.L0"((--a0Gw/H8 8 8 8hn.C.C.E.E.K.K.M.M 8 8 8M &-N"##G\:::: 	 	 	%1N"OOL)))eo--  ".G ". ".6=". ". ". / / / -A--    #k"""FFFFF	 6KKX666 &2N"##M<@@@!!#&&q)\99---''5FGGGGG  :9s   C:G 
H>A(H99H>c                     |                     dt          j                  }|                    d          }t	          |          dk    r|n	|d         df\  }}d|vr|dz  }d|v rt          d           |d= t          j        }t          j        |         }|dz   |j        z   }	d	D ]}
t          |
|           j	        |
<   |t          j        vr||d<   |S t           j        |                   } fd
 j                                        D              j        |	<    j        D ]}||vr j        |         ||<   d	D ]:}
|                     |
           j	        |
         vr j	        |
         d         ||
<   ;||d<   ||d<   |S )za
        Switch default options and backend if new backend is supplied in
        items.
        rR   rQ   r   r   rL   r   r~   z=Warning: The max_branches option is now deprecated. Ignoring.)ra   rb   c                 .    i | ]\  }}|j         v ||S r	   )
rememberedr   s      r   r   z1OutputSettings.update_options.<locals>.<dictcomp>v  s8     3K 3K 3KDAq673>6I6I 45a6I6I6Ir   rM   )getr   r[   r5   r9   r   rS   rM   r^   r   r   _backend_optionsr   r   r   r   )r
   r   r   r   r5   rR   rM   r   rW   r   pbackend_optionsopts   `            r   r   zOutputSettings.update_optionsU  s    yyE,ABB""3''!$UQU1Xy4Il""J&LU""QRRRn% ,?<0(,X]: $ 	; 	;A)!\::CKNN %/))!-GIN s3LABB3K 3K 3K 3KCKDUDUDWDW 3K 3K 3K./ > 	9 	9C/))'*|C'8$ $ 	7 	7A""1%%S[^;;%([^A%6" &2	""&r   c                      | _         t          j        }|t          j        v r<t	           fd j        D                        _                             |           d S d  j        d<                        d            d S )Nc                 ,    i | ]}|j         |         S r	   )r   )r   r   r
   s     r   r   z-OutputSettings.initialize.<locals>.<dictcomp>  s!    KKKq3<?KKKr   rR   )r   r   r[   rS   r   r   r   r   )r
   r   rR   s   `  r   
initializezOutputSettings.initialize  s    ''eo%%KKKKCNKKKLLCKOOG$$$$$%)CK	"OOD!!!!!r   c                 P    t           j        | _        t          j        |           d S N)r   r[   last_backendset_current_backend)r
   rR   s     r   r   zOutputSettings.set_backend  s$     0!'*****r   c                    |r|                     d          d         }nt          j        }|                     |           dv rd         d<   t          j        |         }fd| j        D             } |j        j        di | dS )z2
        Set options on current Renderer.
        rQ   r   r{   r   c                 *    i | ]}|v ||         S r	   r	   )r   r   r   s     r   r   z6OutputSettings._set_render_options.<locals>.<dictcomp>  s$    SSSAa7ll!WQZlllr   Nr	   )r5   r   r[   r   rS   r   rT   r;   )r
   r   rR   rW   render_optionss    `   r   r   z"OutputSettings._set_render_options  s    
  	,mmC((+GG+G   %,Y%7GM"?7+SSSS1BSSS///////r   )F)NNNNNr   )rD   rE   rF   rG   rY   r^   ry   r   r   r   r   r   r   r   r   _disable_info_outputr   r   r   r   r"   nbagg_counterrI   r   r   r%   r   r   r   r   r   r	   r   r   r`   r`      s        
 "/"&!-e!4!4!-i!8!8")6!2"#UU5\\!2"#UU5\\!2"&"#UU5\\!2"#UU5\\!2"&"&$0 $0 $0"O "O,N"O "O "O!P PG* t 5 5 5 6 6H  433JI I IM G"{4(( ! LLN N NB B B $@$=? ? M3 3 3 [3: U U [U : : [:" 6:(,GH GH GH [GHT 1 1 [1h " " [" + + [+
 0 0 0 [0 0 0r   r`   r   )collectionsr   corer   r   rY   r^   r`   r	   r   r   <module>r      s    # # # # # #      ] ] ] ] ] ] ] ]B     &f0 f0 f0 f0 f0_ f0 f0 f0 f0 f0r   