a
    ;ZaZ,                     @   s   d dl mZ d dl mZ d dlmZ d dlmZ d dlZd dlZddl	m
Z
 G dd	 d	ZdddZdd ZdddZdddddZdd ZdS )    )closing)suppress)StringIO)TemplateN   )config_contextc                   @   s*   e Zd ZdZddddddZdd ZdS )	_VisualBlocka  HTML Representation of Estimator

    Parameters
    ----------
    kind : {'serial', 'parallel', 'single'}
        kind of HTML block

    estimators : list of estimators or `_VisualBlock`s or a single estimator
        If kind != 'single', then `estimators` is a list of
        estimators.
        If kind == 'single', then `estimators` is a single estimator.

    names : list of str, default=None
        If kind != 'single', then `names` corresponds to estimators.
        If kind == 'single', then `names` is a single string corresponding to
        the single estimator.

    name_details : list of str, str, or None, default=None
        If kind != 'single', then `name_details` corresponds to `names`.
        If kind == 'single', then `name_details` is a single string
        corresponding to the single estimator.

    dash_wrapped : bool, default=True
        If true, wrapped HTML element will be wrapped with a dashed border.
        Only active when kind != 'single'.
    NT)namesname_detailsdash_wrappedc                C   sT   || _ || _|| _| j dv rD|d u r0dt| }|d u rDdt| }|| _|| _d S )N)parallelserialN)kind
estimatorsr   lenr	   r
   )selfr   r   r	   r
   r    r   Alib/python3.9/site-packages/sklearn/utils/_estimator_html_repr.py__init__'   s    
z_VisualBlock.__init__c                 C   s   | S r   r   )r   r   r   r   _sk_visual_block_7   s    z_VisualBlock._sk_visual_block_)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   sk-label-containersk-labelFc           	      C   s   |  d| d| d t|}|durtt|}d}|rDdnd}t }|  d| d	| d
| d| d| d| d n|  d| d |  d dS )z@Write labeled html with or without a dropdown with named detailsz<div class="z"><div class="z sk-toggleable">Nz/sk-toggleable__label sk-toggleable__label-arrowchecked z><input class="sk-toggleable__control sk-hidden--visually" id="z" type="checkbox" z><label for="z	" class="">z1</label><div class="sk-toggleable__content"><pre>z</pre></div>z<label>z</label></div></div>)writehtmlescapestruuiduuid4)	outnamer
   outer_classinner_classr   Zlabel_classZchecked_strZest_idr   r   r   _write_label_html;   s0    	
r+   c                 C   s   t t |  W  d   S 1 s&0    Y  t| trJtd| | | dS | du rbtd| dddS t| drg }|   D ]$\}}d|vr|t|dr||	| q|t
|rtd|ddS td| | jjt| dS )	z7Generate information about how to display an estimator.Nsingle)r	   r
   None
get_params__r   )r	   )r   AttributeErrorr   
isinstancer$   r   hasattrr.   itemsappendr   	__class__r   )	estimatorr   keyvaluer   r   r   _get_visual_blockY   s*    
&

r9   c                 C   s<  |rt |}n2tdd t |}W d   n1 s60    Y  |jdv r|pT|j}|r^dnd}| d| d |rt| || |j}| d	| d t|j|j|j	}	|	D ]T\}
}}|d
krt
| |
|| q| d td
|
gdd}t
| ||| | d q| d n$|jdkr8t| |j|j	dd|d dS )zCWrite estimator to html in serial, parallel, or by itself (single).T)Zprint_changed_onlyN)r   r   z sk-dashed-wrappedr   z<div class="sk-itemr   z<div class="sk-r   z<div class="sk-parallel-item">F)r   z</div>r    r,   zsk-itemzsk-estimator)r)   r*   r   )r9   r   r   r   r!   r+   zipr   r	   r
   _write_estimator_htmlr   )r'   r6   Zestimator_labelZestimator_label_details
first_callZ	est_blockZdashed_wrappedZdash_clsr   Z	est_infosZestr(   r
   Zserial_blockr   r   r   r;   w   s<    
&

r;   u<  
#$id {
  color: black;
  background-color: white;
}
#$id pre{
  padding: 0;
}
#$id div.sk-toggleable {
  background-color: white;
}
#$id label.sk-toggleable__label {
  cursor: pointer;
  display: block;
  width: 100%;
  margin-bottom: 0;
  padding: 0.3em;
  box-sizing: border-box;
  text-align: center;
}
#$id label.sk-toggleable__label-arrow:before {
  content: "▸";
  float: left;
  margin-right: 0.25em;
  color: #696969;
}
#$id label.sk-toggleable__label-arrow:hover:before {
  color: black;
}
#$id div.sk-estimator:hover label.sk-toggleable__label-arrow:before {
  color: black;
}
#$id div.sk-toggleable__content {
  max-height: 0;
  max-width: 0;
  overflow: hidden;
  text-align: left;
  background-color: #f0f8ff;
}
#$id div.sk-toggleable__content pre {
  margin: 0.2em;
  color: black;
  border-radius: 0.25em;
  background-color: #f0f8ff;
}
#$id input.sk-toggleable__control:checked~div.sk-toggleable__content {
  max-height: 200px;
  max-width: 100%;
  overflow: auto;
}
#$id input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
  content: "▾";
}
#$id div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: #d4ebff;
}
#$id div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: #d4ebff;
}
#$id input.sk-hidden--visually {
  border: 0;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}
#$id div.sk-estimator {
  font-family: monospace;
  background-color: #f0f8ff;
  border: 1px dotted black;
  border-radius: 0.25em;
  box-sizing: border-box;
  margin-bottom: 0.5em;
}
#$id div.sk-estimator:hover {
  background-color: #d4ebff;
}
#$id div.sk-parallel-item::after {
  content: "";
  width: 100%;
  border-bottom: 1px solid gray;
  flex-grow: 1;
}
#$id div.sk-label:hover label.sk-toggleable__label {
  background-color: #d4ebff;
}
#$id div.sk-serial::before {
  content: "";
  position: absolute;
  border-left: 1px solid gray;
  box-sizing: border-box;
  top: 2em;
  bottom: 0;
  left: 50%;
}
#$id div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: white;
  padding-right: 0.2em;
  padding-left: 0.2em;
}
#$id div.sk-item {
  z-index: 1;
}
#$id div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: white;
}
#$id div.sk-parallel::before {
  content: "";
  position: absolute;
  border-left: 1px solid gray;
  box-sizing: border-box;
  top: 2em;
  bottom: 0;
  left: 50%;
}
#$id div.sk-parallel-item {
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: white;
}
#$id div.sk-parallel-item:first-child::after {
  align-self: flex-end;
  width: 50%;
}
#$id div.sk-parallel-item:last-child::after {
  align-self: flex-start;
  width: 50%;
}
#$id div.sk-parallel-item:only-child::after {
  width: 0;
}
#$id div.sk-dashed-wrapped {
  border: 1px dashed gray;
  margin: 0 0.4em 0.5em 0.4em;
  box-sizing: border-box;
  padding-bottom: 0.4em;
  background-color: white;
  position: relative;
}
#$id div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  background-color: white;
  display: inline-block;
  line-height: 1.2em;
}
#$id div.sk-label-container {
  position: relative;
  z-index: 2;
  text-align: center;
}
#$id div.sk-container {
  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`
     but bootstrap.min.css set `[hidden] { display: none !important; }`
     so we also need the `!important` here to be able to override the
     default hidden behavior on the sphinx rendered scikit-learn.org.
     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
  display: inline-block !important;
  position: relative;
}
#$id div.sk-text-repr-fallback {
  display: none;
}
z  r   
c                 C   s   t t }dtt  }tt}|j|d}t| }d}|d| d| dt	
| d| d	 t|| | jj|d	d
 |d | }|W  d   S 1 s0    Y  dS )a2  Build a HTML representation of an estimator.

    Read more in the :ref:`User Guide <visualizing_composite_estimators>`.

    Parameters
    ----------
    estimator : estimator object
        The estimator to visualize.

    Returns
    -------
    html: str
        HTML representation of estimator.
    zsk-)idzCPlease rerun this cell to show the HTML repr or trust the notebook.z<style>z</style><div id="zC" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>z	</pre><b>z+</b></div><div class="sk-container" hidden>T)r<   r    N)r   r   r$   r%   r&   r   _STYLEZ
substituter!   r"   r#   r;   r5   r   getvalue)r6   r'   Zcontainer_idZstyle_templateZstyle_with_idZestimator_strZfallback_msgZhtml_outputr   r   r   estimator_html_reprX  s4    
rA   )r   r   F)F)
contextlibr   r   ior   stringr   r%   r"   r   r   r   r+   r9   r;   replacer?   rA   r   r   r   r   <module>   s2   4   
 
, 0  2  6