a
    DfxD                     @   sL   d dl mZ ddlmZ G dd dZdd Zdd	d
ZG dd deZdS )    )defaultdict   )Storec                   @   s`   e Zd ZdZi Zeg Zee Zi Z	i Z
edd Zedd Zedd Zedd	 Zd
S )KeywordSettingsz_
    Base class for options settings used to specified collections of
    keyword options.
    c                 C   s   dS )zh
        Allows updating options depending on class attributes
        and unvalidated options.
        N )clsoptionsitemsr   r   d/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/util/settings.pyupdate_options   s    zKeywordSettings.update_optionsc                    s  |  ||}| jD ]}||v r|| }| j|  t tr@n^t trt|tsftd|dt| t   }|rtd|d|d   fdd| D }|rg }| D ].\}	}
|	d|
d|d|	d	 |	  qtd

|nt trV| vrV|| jv r:| j| ||  ntd|d|d  nHt tr d |  kr d ksn ||f  }tdj| |||< q| |||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                    s$   i | ]\}}t | | s||qS r   )
isinstance.0kvallowedr   r
   
<dictcomp>-   s   z/KeywordSettings.get_options.<locals>.<dictcomp>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valueZ
disallowedZ
wrong_typeerrorsr   r   infor   r   r
   get_options   s8    

("
zKeywordSettings.get_optionsc                 C   s   t ddS )z-Allows subclasses to check options are valid.z*KeywordSettings is an abstract base class.N)NotImplementedError)r   r   r	   r"   r   r   r
   r!   @   s    zKeywordSettings._validatec           	      C   s
  t t|d}|r| }d}| | jv r<| }ntd|  |  }t|dkr| jD ]2}||rl|dt|   }|	|  qqltd| d  | d| }z|
td| d W q ty   td| dY q0 q|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	   Zunprocessedchunkkeyr$   optionr#   r   r   r
   extract_keywordsF   s*    



z KeywordSettings.extract_keywordsN)__name__
__module____qualname____doc__r   r   r   r	   r   r   hiddenclassmethodr   r'   r!   r:   r   r   r   r
   r      s   

!
r   c                     sZ   g } t jD ]J |   t j  }dd |jdd jD }|  fdd|D 7 } q
| S )Nc                 S   s   g | ]}|d kr|qS )defaultr   r   moder   r   r
   
<listcomp>l   s   z!list_backends.<locals>.<listcomp>existingrC   c                    s   g | ]}  d | qS ):r   rB   backendr   r
   rD   n       )r   	renderersr   paramZobjects)backendsrenderermodesr   rG   r
   list_backendsg   s    


rO   Nc                 C   sv   |du r*t j}|t jv r$t j| jnd}n*|d}t|dkrD|n
|d df\}}|t jv rnt j| j|  S g S dS )zI
    Returns list of supported formats for a particular
    backend.
    NrF   r   r   rA   )r   current_backendrJ   rC   r-   r1   Zmode_formats)Zformat_typerH   rC   r-   r   r   r
   list_formatsr   s    
 
rQ   c                   @   s2  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 dZeg dZ	g dZ
g dZi ZeeZdZd
Zg Zdd Zdd ZeedZdZed)ddZedd Zedd Zed*dd Zed!d" Zed#d$ Zed%d& Zed+d'd(Zd
S ),OutputSettingsz<
    Class for controlling display and output settings.
    TFfigholomapembedZliver   infNr   )leftZbottomrighttopZtop_leftZ	top_rightZbottom_leftZbottom_rightZleft_topZleft_bottomZ	right_topZright_bottomc                 C   s   i | ]
}|t qS r   )strr   r   r   r   r
   r      s   zOutputSettings.<dictcomp>)
widthheightpaddingmarginz	max-widthz	min-widthz
max-heightz
min-heightoutlinefloat)rH   centerrS   rT   widgetsfps
max_framesmax_branchessizedpifilenamer&   widget_locationcss))rH   N)rb   T)rS   N)rT   N)rc   N)rd   N)re   i  )rg   N)rh   N)ri   N)r&   F)rj   N)rk   N)re   r&   ri   )
rS   rT   rg   rd   rh   rk   widget_moderC   rj   rb   c                 C   s   t d| dd S )NzFormat z! does not appear to be supported.)r5   r$   r#   r   r   r   r
   missing_dependency_exception   s    z+OutputSettings.missing_dependency_exceptionc                 C   s0   | t jv rtd| dntd| dd S )NzBackend z? not available. Has it been loaded with the notebook_extension?z does not exist)rR   backend_listr   rm   r   r   r
   missing_backend_exception   s    
z(OutputSettings.missing_backend_exception)rT   rH   c                 C   s   g d}d}d}d}d}d}d| j d  }d	}	d
}
d| j d  }d| j d  }d}d}|||||||	|
||||g}g d}|rdddd |D  }d|g| | S d|| S d 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)re   z6size         : The percentage size of displayed outputz-dpi          : The rendered dpi of the figurezCfilename    : The filename of the saved output, if any (default %r)ri   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rH   rS   rT   rc   rd   re   rg   rh   ri   r&   rk   rj   z
output(%s)
z, c                 s   s   | ]}d | V  qdS )z%s=NoneNr   r   kwr   r   r
   	<genexpr>   rI   z5OutputSettings._generate_docstring.<locals>.<genexpr>r   )r   r   )r   	signatureZintrorH   rS   rT   rc   rd   re   rg   rh   ri   r&   rk   rj   ZdescriptionskeywordsZdoc_signaturer   r   r
   _generate_docstring   s6    
z"OutputSettings._generate_docstringc                    s.   ddl m m} g d}| fdd|D S )Nr   )	Parameter	Signaturerr   c                    s   g | ]} | j qS r   )KEYWORD_ONLYrs   ry   r   r
   rD      rI   z6OutputSettings._generate_signature.<locals>.<listcomp>)inspectry   rz   )r   rz   rw   r   r|   r
   _generate_signature   s    z"OutputSettings._generate_signaturec                 C   st   dt jv rnRd|v r^|d t jvr^d|d ddt j }|du rVtd|  n|| t j}t j| |S )z1Validation of edge cases and incompatible optionshtmlrS   z Requesting output figure format  znot in display formats Nz	Warning: )r   Zdisplay_formatsprintrP   rJ   validate)r   r   r	   r"   msgrH   r   r   r
   r!      s    

zOutputSettings._validatec              
      s  |r|rt dntjs t dtj}|tjv rftj| }|d |j }	 fdd|j  D }
nd }|d }	i }
|}tt	j
}z|d ur|dd  } |i } |i |}d	|v r|d	 }d|vr|d7 }n|	}|dd }tj| } fd
d|j  D }|t	_
 || W nx ty } z^|t	_
 | |tjvrnt d|d|d|td|  |rt| W Y d }~d S d }~0 0 |d ur|r||| |t	_
 || |dd |kr |  |
|	 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.rF   c                    s    i | ]\}}| j v r||qS r   render_paramsr   r   r   r
   r     s   
z)OutputSettings.output.<locals>.<dictcomp>:default#r   rH   c                    s    i | ]\}}| j v r||qS r   r   r   r   r   r
   r   6  s   
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   rJ   rP   rC   rK   valuesr	   r   rR   r   r-   r/   r:   r'   _set_render_optionsr5   set_backendr   )r   r6   cellZcell_runnerZhelp_promptr"   kwargsprev_backendZprev_rendererprev_backend_specZprev_paramsrH   Zprev_restorer   backend_specrM   r   er   r   r
   output
  sb    









zOutputSettings.outputc                    s>  | dtj}|d}t|dkr(|n
|d df\}}d|vrH|d7 }d|v r^td |d= tj}tj| }|d |j }	d	D ]}
t|
| j	|
< q|tjvr||d< |S t
 j| } fd
d j D  j|	<  jD ]}||vrވ j| ||< qd	D ]*}
| |
 j	|
 vr j	|
 d ||
< q||d< ||d< |S )za
        Switch default options and backend if new backend is supplied in
        items.
        rH   rF   r   r   rA   r   rf   z=Warning: The max_branches option is now deprecated. Ignoring.)rS   rT   c                    s    i | ]\}}| j v r||qS r   )
rememberedr   r   r   r
   r   v  s   
z1OutputSettings.update_options.<locals>.<dictcomp>rC   )getr   rP   r-   r1   r   rJ   rC   rQ   r   r   _backend_optionsr   r	   r   r   )r   r   r	   r   r-   rH   rC   r   rM   r   pZbackend_optionsoptr   r   r
   r   U  s6    
 


zOutputSettings.update_optionsc                    sT   | _ tj}|tjv r<t fdd jD  _ | nd  jd<  d  d S )Nc                    s   i | ]}| j | qS r   )r   r[   r   r   r
   r     rI   z-OutputSettings.initialize.<locals>.<dictcomp>rH   )ro   r   rP   rJ   r   r   r   r   )r   ro   rH   r   r   r
   
initialize  s    

zOutputSettings.initializec                 C   s   t j| _t | d S )N)r   rP   last_backendZset_current_backend)r   rH   r   r   r
   r     s    zOutputSettings.set_backendc                    sl   |r| dd }ntj}| | d v r8 d  d< tj| } fdd| jD }|jjf i | dS )z2
        Set options on current Renderer.
        rF   r   rc   rl   c                    s   i | ]}| v r| | qS r   r   r[   r   r   r
   r     rI   z6OutputSettings._set_render_options.<locals>.<dictcomp>N)r-   r   rP   r   rJ   r   rK   r3   )r   r   rH   rM   Zrender_optionsr   r   r
   r     s    

z"OutputSettings._set_render_options)F)NNNNN)N)r;   r<   r=   r>   rO   rQ   ra   r   r   r   r   r   r   r   r   Z_disable_info_outputr   ro   rn   rp   r   Znbagg_counterr@   rx   r~   r!   r   r   r   r   r   r   r   r   r
   rR      sd   





  J
4

rR   )N)collectionsr   corer   r   rO   rQ   rR   r   r   r   r
   <module>   s
   a
