o
    g                     @  sf   d dl mZ d dlmZ d dlZd dlZerd dlm	Z	 G dd dZ
dd	d
Zedkr1e  dS dS )    )annotations)TYPE_CHECKINGN)Iterablec                   @  s^   e Zd ZdZ			d'd(ddZd)ddZd*ddZd+d,ddZdd Zdd Z	d-d.d%d&Z
d S )/TablePlotterzg
    Layout some DataFrames in vertical/horizontal layout for explanation.
    Used in merging.rst
    Gz?      ?      @
cell_widthfloatcell_height	font_sizereturnNonec                 C  s   || _ || _|| _d S N)r	   r   r   )selfr	   r   r    r   W/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/pandas/util/_doctools.py__init__   s   
zTablePlotter.__init__dfpd.DataFrametuple[int, int]c                 C  s"   |j \}}||jj ||jj fS )zA
        Calculate table shape considering index levels.
        )shapecolumnsnlevelsindex)r   r   rowcolr   r   r   _shape   s   
zTablePlotter._shapec                   s   |r+t t fdd|D  |d }t  fdd|D  |d  }||fS t  fdd|D  |d g }t fdd|D  |d g }||fS )	zQ
        Calculate appropriate figure size based on left and right data.
        c                 3      | ]
}  |d  V  qdS r   Nr   .0r   r   r   r   	<genexpr>*       z*TablePlotter._get_cells.<locals>.<genexpr>r   c                 3  r      Nr    r!   r#   r   r   r$   +   r%   r'   c                      g | ]	}  |d  qS )r   r    r!   r#   r   r   
<listcomp>-       z+TablePlotter._get_cells.<locals>.<listcomp>c                   r(   )r'   r    r!   r#   r   r   r)   .   r*   )maxsumr   )r   leftrightverticalvcellshcellsr   r#   r   
_get_cells$   s   &$&&zTablePlotter._get_cellsr   TlabelsIterable[str]r/   boolc              	     s0  ddl m} ddlm} t|ts|g} fdd|D } |} |||\}}|r8 j|  j	| f}	n
 j|  j	| f}	|j
|	d}
|r|t||}t fdd|D }t fd	d|D }tt||D ]\}\}}|
||d|f } j|||d
| d qo||dd|df } j||dd| d |
jddddd |
S t fdd||g D }d
t| }|d|}d}t||D ]'\}} |}|
|d|||d  f } j||||d ||d 7 }q||d|df } j||d|d |
jddddd |
S )a  
        Plot left / right DataFrames in specified layout.

        Parameters
        ----------
        left : list of DataFrames before operation is applied
        right : DataFrame of operation result
        labels : list of str to be drawn as titles of left DataFrames
        vertical : bool, default True
            If True, use vertical layout. If False, use horizontal layout.
        r   )gridspecNc                   s   g | ]}  |qS r   )_convr!   r#   r   r   r)   B   s    z%TablePlotter.plot.<locals>.<listcomp>)figsizec                 3  r   r&   r    r!   r#   r   r   r$   Q   r%   z$TablePlotter.plot.<locals>.<genexpr>c                 3  r   r   r    r!   r#   r   r   r$   R   r%         ?)titleheightResultg?g?g?gffffff?)topbottomr-   r.   c                 3  r   r   r    r!   r#   r   r   r$   [   r%   r'   g333333?)
matplotlibr6   matplotlib.pyplotpyplot
isinstancelistr7   r2   r	   r   figureGridSpeclenr+   	enumeratezipadd_subplot_make_tablesubplotsubplots_adjustnpr   )r   r-   r.   r3   r/   r6   pltr1   r0   r8   figgsmax_left_colsmax_left_rowsi_left_labelaxmax_rowsr;   r   spr   r#   r   plot1   sF   


zTablePlotter.plotc                 C  s:   t |tjr|jdu r|jdd}n| }|d}|S )zF
        Convert each input to appropriate for table outplot.
        N )nameNaN)rB   pdSeriesr[   to_framefillna)r   datar   r   r   r7   l   s   

zTablePlotter._convc                   s        jj}|dkr dd j nt|D ]} |d|  j| q jj}|dkrW jd} fddtd|D }t|}|j _t	| g | _ S )Nr'   r   Indexc                   s   g | ]	} j |jqS r   )r   _get_level_values_values)r"   rS   ra   r   r   r)      s    z.TablePlotter._insert_index.<locals>.<listcomp>)
copyr   r   insertrangerc   r   r]   	DataFrameconcat)r   ra   idx_nlevelsrS   col_nlevelsr   valuescol_dfr   re   r   _insert_indexx   s"   

zTablePlotter._insert_indexNr:   strr;   float | Nonec                 C  s  |d u r| d d S ddlm} |jj}|jj}| |}|j||dd}|| j	 |d u r8dt
|d  }| }	|	d  D ]0\\}
}}|d	krR| d n|
|k r`||k r`| d n|
|k sh||k rm|d
 || qB|j|| j	d |d d S )NFr   )plotting	   )locr9   r'   celldz#AAAAAA)sizeoff)set_visiblepandasrr   r   r   r   ro   tableset_fontsizer   rF   
propertiesitemsset_facecolor
set_height	set_titleaxis)r   rV   r   r:   r;   rr   rk   rl   tbpropsrccellr   r   r   rJ      s,   


zTablePlotter._make_table)r   r   r   )r	   r
   r   r
   r   r
   r   r   )r   r   r   r   )r   r   )r   T)r3   r4   r/   r5   r   )r:   rp   r;   rq   r   r   )__name__
__module____qualname____doc__r   r   r2   rY   r7   ro   rJ   r   r   r   r   r      s    


;r   r   r   c                  C  s  dd l m}  t }tg dg dg dd}tddgdd	gd
}|j||gt||gddgdd |   tddgdd	gd}|j||gtj||gddddgdd |   tj	g d}tj	ddg}tjg dg dd|d}||_
|j||dgd |   d S )Nr   )
         )         )          )ABCr   r   r   r   )r   r   df1df2T)r3   r/   )XZr'   )r   F)r'   r   r'   r   )r'   r   )   r   )r   r   )r   r   r   r   )r'   r               )r   r         rs   r   )v1v2)r   df3)r3   )r@   rA   r   r]   ri   rY   rj   show
MultiIndexfrom_tuplesr   )rN   pr   r   r   idxcolumnr   r   r   main   s&   $r   __main__)r   r   )
__future__r   typingr   numpyrM   rz   r]   collections.abcr   r   r   r   r   r   r   r   <module>   s     
!
