U
    }hN0                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ ddl	m
Z
 G dd	 d	Zed
Zed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 )    N)closing)isclass)StringIO)Template   )config_contextc                   @   s    e Zd ZdZdd Zdd ZdS )
_IDCounterz&Generate sequential ids with a prefix.c                 C   s   || _ d| _d S )Nr   )prefixcount)selfr	    r   F/tmp/pip-unpacked-wheel-ig1s1lm8/sklearn/utils/_estimator_html_repr.py__init__   s    z_IDCounter.__init__c                 C   s    |  j d7  _ | j d| j  S )N   -)r
   r	   r   r   r   r   get_id   s    z_IDCounter.get_idN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   
   s   r   zsk-container-idzsk-estimator-idc                   @   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krD|d kr0dt| }|d krDdt| }|| _|| _d S )N)parallelserialN)kind
estimatorsr   lenr   r   )r   r   r   r   r   r   r   r   r   r   6   s    
z_VisualBlock.__init__c                 C   s   | S r   r   r   r   r   r   _sk_visual_block_F   s    z_VisualBlock._sk_visual_block_)r   r   r   r   r   r!   r   r   r   r   r      s     r   sk-label-containersk-labelFc           	      C   s   |  d| d| d t|}|dk	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_ESTIMATOR_ID_COUNTERr   )	outnamer   outer_classinner_classr$   Zlabel_classZchecked_strZest_idr   r   r   _write_label_htmlJ   s    	
(r1   c              	   C   s   t | drBz
|  W S  tk
r@   td| | jjt| d Y S X t| tr\td| | | dS | dkrttd| dddS t | drt| sdd | j	d	d

 D }|rtddd |D dd |D dd |D dS td| | jjt| dS )z7Generate information about how to display an estimator.r!   single)r   r   NNone
get_paramsc                 S   s4   g | ],\}}t |d rt |drt|s||fqS )r4   Zfit)hasattrr   .0keyestr   r   r   
<listcomp>~   s
   
 
 z%_get_visual_block.<locals>.<listcomp>F)deepr   c                 S   s   g | ]\}}|qS r   r   r7   _r9   r   r   r   r:      s     c                 S   s"   g | ]\}}| d |j j qS )z: )	__class__r   r6   r   r   r   r:      s     c                 S   s   g | ]\}}t |qS r   )r+   r<   r   r   r   r:      s     )r5   r!   	Exceptionr   r>   r   r+   
isinstancer   r4   items)	estimatorr   r   r   r   _get_visual_blockh   sH    


   rC   c              	   C   s&  |rt |}ntdd t |}W 5 Q R X |jdkr|p>|j}|rHdnd}| d| d |rnt| || |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r"t| |j|j	dd|d dS )zCWrite estimator to html in serial, parallel, or by itself (single).T)Zprint_changed_only)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'   r2   zsk-itemzsk-estimator)r/   r0   r$   N)rC   r   r   r   r(   r1   zipr   r   r   _write_estimator_htmlr   )r-   rB   Zestimator_labelZestimator_label_details
first_callZ	est_blockZdashed_wrappedZdash_clsr   Z	est_infosr9   r.   r   Zserial_blockr   r   r   rE      s<    



rE   uT  
#$id {
  color: black;
}
#$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: 0;
  bottom: 0;
  left: 50%;
  z-index: 0;
}
#$id div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: white;
  padding-right: 0.2em;
  padding-left: 0.2em;
  position: relative;
}
#$id div.sk-item {
  position: relative;
  z-index: 1;
}
#$id div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: white;
  position: relative;
}
#$id div.sk-item::before, #$id div.sk-parallel-item::before {
  content: "";
  position: absolute;
  border-left: 1px solid gray;
  box-sizing: border-box;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: -1;
}
#$id div.sk-parallel-item {
  display: flex;
  flex-direction: column;
  z-index: 1;
  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;
}
#$id div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  display: inline-block;
  line-height: 1.2em;
}
#$id div.sk-label-container {
  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 }t }tt}|j|d}t| }d}|d| d| dt	
| d| d	 t|| | jj|dd	 |d
 | }|W  5 Q R  S Q R X 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.
    )idzIn a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.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)rF   r'   N)r   r   _CONTAINER_ID_COUNTERr   r   _STYLE
substituter+   r(   r)   r*   rE   r>   r   getvalue)rB   r-   Zcontainer_idZstyle_templateZstyle_with_idZestimator_strZfallback_msgZhtml_outputr   r   r   estimator_html_reprq  s(    "
rM   )r"   r#   F)F)r)   
contextlibr   inspectr   ior   stringr   r%   r   r   rI   r,   r   r1   rC   rE   replacerJ   rM   r   r   r   r   <module>   s:   4   
, 
, 0   0   3