o
    h`l                     @   s   d Z ddlZddlmZmZ ddlmZm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e
ZeZG dd deZej					dddZdS )a$  
Tables drawing.

.. note::
    The table implementation in Matplotlib is lightly maintained. For a more
    featureful table implementation, you may wish to try `blume
    <https://github.com/swfiua/blume>`_.

Use the factory function `~matplotlib.table.table` to create a ready-made
table from texts. If you need more control, use the `.Table` class and its
methods.

The table consists of a grid of cells, which are indexed by (row, column).
The cell (0, 0) is positioned at the top left.

Thanks to John Gill for providing the class and table.
    N   )_api
_docstring)Artistallow_rasterization)	Rectangle)Text)Bbox)Path)_is_pandas_dataframec                       s   e Zd ZdZdZ	 dZdedddZdd	d
ddddd fdd
Z fddZ fddZ	dd Z
dd Zdd Zdd Ze fddZdd  Zd!d" Zd#d$ Zejd%d& Zed'd( Zejd)d( Zd*d+ Z  ZS ),Cellz
    A cell is a `.Rectangle` with some associated `.Text`.

    As a user, you'll most likely not creates cells yourself. Instead, you
    should use either the `~matplotlib.table.table` factory function or
    `.Table.add_cell`.
    g?BRTL BTRL)openclosed
horizontalverticalkwTrightNr   )	edgecolor	facecolorfilltextlocfontpropertiesvisible_edgesc             	      sR   t  j||||||d | d |
| _|| _t|d |d d||	|dd| _dS )a  
        Parameters
        ----------
        xy : 2-tuple
            The position of the bottom left corner of the cell.
        width : float
            The cell width.
        height : float
            The cell height.
        edgecolor : :mpltype:`color`, default: 'k'
            The color of the cell border.
        facecolor : :mpltype:`color`, default: 'w'
            The cell facecolor.
        fill : bool, default: True
            Whether the cell background is filled.
        text : str, optional
            The cell text.
        loc : {'right', 'center', 'left'}
            The alignment of the text within the cell.
        fontproperties : dict, optional
            A dict defining the font properties of the text. Supported keys and
            values are the keyword arguments accepted by `.FontProperties`.
        visible_edges : {'closed', 'open', 'horizontal', 'vertical'} or substring of 'BRTL'
            The cell edges to be drawn with a line: a substring of 'BRTL'
            (bottom, right, top, left), or one of 'open' (no edges drawn),
            'closed' (all edges drawn), 'horizontal' (bottom and top),
            'vertical' (right and left).
        )widthheightr   r   r   Fr   r   center)xyclip_onr   r   horizontalalignmentverticalalignmentN)super__init__set_clip_onr   _locr   _text)selfxyr   r    r   r   r   r   r   r   r   	__class__ d/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/table.pyr(   :   s   '
zCell.__init__c                    s   t  | d| _d S NT)r'   set_transformstale)r,   tr.   r0   r1   r3   l   s   
zCell.set_transformc                    s   t  | | j| d S N)r'   
set_figurer+   )r,   figr.   r0   r1   r7   q   s   zCell.set_figurec                 C      | j S )z!Return the cell `.Text` instance.)r+   r,   r0   r0   r1   get_textu   s   zCell.get_textc                 C      | j | d| _dS )zSet the text fontsize.TN)r+   set_fontsizer4   )r,   sizer0   r0   r1   r=   y   s   
zCell.set_fontsizec                 C   s
   | j  S )zReturn the cell fontsize.)r+   get_fontsizer:   r0   r0   r1   r?   ~      
zCell.get_fontsizec                 C   sZ   |   }| |}|dkr+||  kr+|d8 }| | | |}|dkr+||  ks|S )z9Shrink font size until the text fits into the cell width.r   )r?   get_required_width	get_widthr=   )r,   rendererfontsizerequiredr0   r0   r1   auto_set_font_size   s   


zCell.auto_set_font_sizec                    s8   |   sd S t | | | | j| d| _d S )NF)get_visibler'   draw_set_text_positionr+   r4   r,   rC   r.   r0   r1   rH      s   

z	Cell.drawc                 C   s   |  |}|j|jd  }| j }|dkr|j|jd  }n|dkr-|j|j| j  }n|j|jd| j   }| j||f dS )z.Set text up so it is drawn in the right place.   r!   leftr   N)	get_window_extenty0r    r+   get_horizontalalignmentx0r   PADset_position)r,   rC   bboxr#   r   r"   r0   r0   r1   rI      s   

zCell._set_text_positionc                 C   s   | j ||   jS )zY
        Return the text bounds as *(x, y, width, height)* in table coordinates.
        )r+   rM   transformedget_data_transforminvertedboundsrJ   r0   r0   r1   get_text_bounds   s   
zCell.get_text_boundsc                 C   s$   |  |\}}}}|dd| j   S )z/Return the minimal required width for the cell.      ?g       @)rX   rQ   )r,   rC   lbr   hr0   r0   r1   rA      s   zCell.get_required_widthc                 K   r<   )zk
        Update the text properties.

        Valid keyword arguments are:

        %(Text:kwdoc)s
        TN)r+   _internal_updater4   )r,   kwargsr0   r0   r1   set_text_props   s   	
zCell.set_text_propsc                 C   r9   )a"  
        The cell edges to be drawn with a line.

        Reading this property returns a substring of 'BRTL' (bottom, right,
        top, left').

        When setting this property, you can use a substring of 'BRTL' or one
        of {'open', 'closed', 'horizontal', 'vertical'}.
        )_visible_edgesr:   r0   r0   r1   r      s   zCell.visible_edgesc                    sr   |d u r	 j  _n+| jv r j|  _nt fdd|D r1td|d jd j | _d _d S )Nc                 3   s    | ]}| j vV  qd S r6   _edges.0edger:   r0   r1   	<genexpr>       z%Cell.visible_edges.<locals>.<genexpr>z=Invalid edge param {}, must only be one of {} or string of {}z, T)rb   r`   _edge_aliasesany
ValueErrorformatjoinr4   r,   valuer0   r:   r1   r      s   




c                    sj   t jg}| fdd jD  t j|dd vrt j|d< t ddgddgddgddgddgg|dd	S )
z*Return a `.Path` for the `.visible_edges`.c                 3   s&    | ]}| j v rtjntjV  qd S r6   )r`   r
   LINETOMOVETOrc   r:   r0   r1   rf      s
    
z Cell.get_path.<locals>.<genexpr>r   N        rY   T)readonly)r
   rp   extendrb   	CLOSEPOLY)r,   codesr0   r:   r1   get_path   s   
 zCell.get_path)__name__
__module____qualname____doc__rQ   rb   rh   r(   r3   r7   r;   r=   r?   rF   r   rH   rI   rX   rA   r   interpdr_   propertyr   setterrw   __classcell__r0   r0   r.   r1   r   '   sF    2



r   c                       sZ  e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!d"d#d$d%iZ	 dZd&Z	 dT fd(d)	Zd*d+ Zd,d- Z	d.d/ Z
ed0d1 Zejd2d1 Zd3d4 Zed5d6 Zd7d8 Zd9d: Zd;d< ZdUd=d>Zd?d@ ZdAdB ZdCdD ZdVdFdGZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS Z  ZS )WTableaD  
    A table of cells.

    The table consists of a grid of cells, which are indexed by (row, column).

    For a simple table, you'll have a full grid of cells with indices from
    (0, 0) to (num_rows-1, num_cols-1), in which the cell (0, 0) is positioned
    at the top left. However, you can also add cells with negative indices.
    You don't have to add a cell to every grid position, so you can create
    tables that have holes.

    *Note*: You'll usually not create an empty table from scratch. Instead use
    `~matplotlib.table.table` to create a table from data.
    bestr   zupper rightr   z
upper leftrK   z
lower left   zlower right   zcenter left   zcenter right   zlower center   zupper center   r!   	   z	top right
   ztop left   zbottom left   zbottom right   r      rL      top   bottom   g{Gz?Nc                    s   t    t|tr || jvrtd|d| j| j| }| |j	dd || _
|| _|| _|  | |j i | _d| _g | _d| _| | | d dS )a(  
        Parameters
        ----------
        ax : `~matplotlib.axes.Axes`
            The `~.axes.Axes` to plot the table into.
        loc : str, optional
            The position of the cell with respect to *ax*. This must be one of
            the `~.Table.codes`.
        bbox : `.Bbox` or [xmin, ymin, width, height], optional
            A bounding box to draw the table into. If this is not *None*, this
            overrides *loc*.

        Other Parameters
        ----------------
        **kwargs
            `.Artist` properties.
        z3Unrecognized location {!r}. Valid locations are
	{}z
	FrootNT)r'   r(   
isinstancestrrv   rj   rk   rl   r7   
get_figure_axesr*   _bbox_unstale_viewLimr3   	transAxes_cellsrb   _autoColumns_autoFontsizer]   r)   )r,   axr   rS   r^   r.   r0   r1   r(     s(   




zTable.__init__c                 O   s0   d}t |g|R d| ji|}|| ||f< |S )aV  
        Create a cell and add it to the table.

        Parameters
        ----------
        row : int
            Row index.
        col : int
            Column index.
        *args, **kwargs
            All other parameters are passed on to `Cell`.

        Returns
        -------
        `.Cell`
            The created cell.

        )r   r   r   )r   edges)r,   rowcolargsr^   r-   cellr0   r0   r1   add_cellD  s   zTable.add_cellc              
   C   s   t jt|d z|d |d }}W n ty# } ztd|d}~ww || jdd ||   |	d || j
||f< d| _dS )	z8
        Set a custom cell in a given position.
        )r   r   r   z0Only tuples length 2 are accepted as coordinatesNFr   T)r   check_isinstancer   	ExceptionKeyErrorr7   r   r3   get_transformr)   r   r4   )r,   positionr   r   r   errr0   r0   r1   __setitem__\  s   

zTable.__setitem__c                 C   s
   | j | S )z-Retrieve a custom cell from a given position.r   )r,   r   r0   r0   r1   __getitem__l  r@   zTable.__getitem__c                 C   r9   )a  
        The default value of `~.Cell.visible_edges` for newly added
        cells using `.add_cell`.

        Notes
        -----
        This setting does currently only affect newly created cells using
        `.add_cell`.

        To change existing cells, you have to set their edges explicitly::

            for c in tab.get_celld().values():
                c.visible_edges = 'horizontal'

        ra   r:   r0   r0   r1   r   p  s   zTable.edgesc                 C   s   || _ d| _d S r2   )rb   r4   rm   r0   r0   r1   r        
c                 C   s&   | j d | jddj | jjj d S )Ng      R@Tr   g333333?)FONTSIZEr   dpir   rS   r    r:   r0   r0   r1   _approx_text_height  s
   zTable._approx_text_heightc                 C   s   |d u r| j dd }|d u rtd|  sd S |jd|  d | | t| jD ]
}| j| 	| q-|
d d| _d S )NTr   zNo renderer definedtable)gidF)r   _get_rendererRuntimeErrorrG   
open_groupget_gid_update_positionssortedr   rH   close_groupr4   )r,   rC   keyr0   r0   r1   rH     s   


z
Table.drawc                    s4    fdd| j  D }t|}||   S )z
        Get a bbox, in axes coordinates for the cells.

        Only include those in the range (0, 0) to (maxRow, maxCol).
        c                    .   g | ]\\}}}|d kr|d kr|  qS r   rM   rd   r   r   r   rC   r0   r1   
<listcomp>  
    
z(Table._get_grid_bbox.<locals>.<listcomp>)r   itemsr	   unionrT   r   rV   )r,   rC   boxesrS   r0   r   r1   _get_grid_bbox  s
   

zTable._get_grid_bboxc                    sh   |  |r	di fS | jdd   d ur0 fdd| j D }t|}||j|j	i fS di fS )NFTr   c                    r   r   r   r   r   r0   r1   r     r   z"Table.contains.<locals>.<listcomp>)
_different_canvasr   r   r   r   r	   r   containsr"   r#   )r,   
mouseeventr   rS   r0   r   r1   r     s   


zTable.containsc                 C   s   t | j S )z*Return the Artists contained by the table.)listr   valuesr:   r0   r0   r1   get_children  s   zTable.get_childrenc                    sD    d u r| j dd  |    fdd| j D }t|S )NTr   c                    s   g | ]}|  qS r0   r   rd   r   r   r0   r1   r     s    z+Table.get_window_extent.<locals>.<listcomp>)r   r   r   r   r   r	   r   )r,   rC   r   r0   r   r1   rM     s   


zTable.get_window_extentc                 C   s   i }i }| j  D ]$\\}}}||d}t|| ||< ||d}t|| ||< q	d}i }	t|D ]}||	|< ||| 7 }q6d}
i }t|ddD ]}|
||< |
|| 7 }
qM| j  D ]\\}}}||	|  |||  q_dS )zV
        Calculate row heights and column widths; position cells accordingly.
        rr   r   T)reverseN)	r   r   
setdefaultmax
get_heightrB   r   set_xset_y)r,   widthsheightsr   r   r   r    r   xposleftsyposbottomsr0   r0   r1   _do_cell_alignment  s*   zTable._do_cell_alignmentc                 C   sB   t |}t |jt jstd|D ]}| j| qd| _dS )z
        Automatically set the widths of given columns to optimal sizes.

        Parameters
        ----------
        col : int or sequence of ints
            The indices of the columns to auto-scale.
        z'col must be an int or sequence of ints.TN)	np
atleast_1d
issubdtypedtypeinteger	TypeErrorr   appendr4   )r,   r   col1dr   r0   r0   r1   auto_set_column_width  s   
	
zTable.auto_set_column_widthc                    sJ    fdd| j  D }tfdd|D dd}|D ]}|| qdS )z#Automatically set width for column.c                    s    g | ]\}}|d   kr|qS )r   r0   )rd   r   r   )r   r0   r1   r     s     z0Table._auto_set_column_width.<locals>.<listcomp>c                 3   s    | ]}|  V  qd S r6   )rA   r   r   r0   r1   rf     rg   z/Table._auto_set_column_width.<locals>.<genexpr>r   )defaultN)r   r   r   	set_width)r,   r   rC   cells	max_widthr   r0   )r   rC   r1   _auto_set_column_width  s   zTable._auto_set_column_widthTc                 C   s   || _ d| _dS )zAutomatically set font size.TN)r   r4   rm   r0   r0   r1   rF     r   zTable.auto_set_font_sizec                 C   s   t | jdkr	d S tt| j  }g }| j D ]\}}|d | jv r'q||}t	||}|
| q| j D ]}|| q<d S )Nr   r   )lenr   nextiterr   r?   r   r   rF   minr   r=   )r,   rC   rD   r   r   r   r>   r0   r0   r1   _auto_set_font_size  s   

zTable._auto_set_font_sizec                 C   s8   | j  D ]}|| |  || |  qdS )z<Scale column widths by *xscale* and row heights by *yscale*.N)r   r   r   rB   
set_heightr   )r,   xscaleyscalecr0   r0   r1   scale  s   zTable.scalec                 C   s$   | j  D ]}|| qd| _dS )a>  
        Set the font size, in points, of the cell text.

        Parameters
        ----------
        size : float

        Notes
        -----
        As long as auto font size has not been disabled, the value will be
        clipped such that the text fits horizontally into the cell.

        You can disable this behavior using `.auto_set_font_size`.

        >>> the_table.auto_set_font_size(False)
        >>> the_table.set_fontsize(20)

        However, there is no automatic scaling of the row height so that the
        text may exceed the cell boundary.
        TN)r   r   r=   r4   )r,   r>   r   r0   r0   r1   r=      s   
zTable.set_fontsizec                 C   sB   | j  D ]}| | }}|||  |||  qdS )z-Move all the artists by ox, oy (axes coords).N)r   r   get_xget_yr   r   )r,   oxoyr   r"   r#   r0   r0   r1   _offset9  s
   zTable._offsetc                  C   s4  | j D ]}| || q| jr| | |   | |}|j\}}}}| jd urVt| jt	r8| jj\}}	}
}n| j\}}	}
}| 
|
| ||  || }|	| }|   ntt| j\}}}}}}}}}}}}}}}}}}d|d  | }d|d  | }| j|||fv r| j| }| j|||||fv rd|| | j  }| j||||fv rd|| | j  }| j|||fv r| j| }| j|||fv rd|d  | }| j|||fv rd|d  | }| j|||fv r||  }| j|||fv rd| }| j|||fv rd| }| j|||fv r||  }| || d S )Ng      ?rK   r   rY   )r   r   r   r   r   r   rW   r   r   r	   r   ranger   rv   r*   AXESPADr   ) r,   rC   r   rS   rZ   r[   r   r\   rlrbrwrhr   r   BESTURULLLLRCLCRLCUCCTRTLBLBRRLTBr0   r0   r1   r   @  sR   








zTable._update_positionsc                 C   r9   )a  
        Return a dict of cells in the table mapping *(row, column)* to
        `.Cell`\s.

        Notes
        -----
        You can also directly index into the Table object to access individual
        cells::

            cell = table[row, col]

        r   r:   r0   r0   r1   	get_celldz  s   zTable.get_celld)NNr6   )T) rx   ry   rz   r{   rv   r   r   r(   r   r   r   r}   r   r~   r   r   rH   r   r   r   rM   r   r   r   rF   r   r   r=   r   r   r  r   r0   r0   r.   r1   r      s    	
,



	
:r   r   rL   r!   r   r   c                 K   s  |du r|du rt d|du r"t|}t|d }dg| g| }t|rA|du r.|j}nt d|du r:|j}nt d|j}t|}t|d }|D ]}t||kr]t d| dqM|durt||krpt d	| d
|D ]}t||krt d| dqrnd| g| }|du rd| g| }d}|du r|durdg| }|d }n|du rd| }|durt||krt d| d}|du r|	durdg| }nd}n|	du rd| }	|du rd| g| }t| ||fi |}||_| }t	|D ]"}t	|D ]}|j
|| ||| ||| | || | |d qq|dur@t	|D ]}|j
d||| ||| |	| |
d q*|durlt	|D ]}|j
|| d|pUd||| || |d qI|dkrl|d d|v rx||d  | | |S )a	  
    Add a table to an `~.axes.Axes`.

    At least one of *cellText* or *cellColours* must be specified. These
    parameters must be 2D lists, in which the outer lists define the rows and
    the inner list define the column values per row. Each row must have the
    same number of elements.

    The table can optionally have row and column headers, which are configured
    using *rowLabels*, *rowColours*, *rowLoc* and *colLabels*, *colColours*,
    *colLoc* respectively.

    For finer grained control over tables, use the `.Table` class and add it to
    the Axes with `.Axes.add_table`.

    Parameters
    ----------
    cellText : 2D list of str or pandas.DataFrame, optional
        The texts to place into the table cells.

        *Note*: Line breaks in the strings are currently not accounted for and
        will result in the text exceeding the cell boundaries.

    cellColours : 2D list of :mpltype:`color`, optional
        The background colors of the cells.

    cellLoc : {'right', 'center', 'left'}
        The alignment of the text within the cells.

    colWidths : list of float, optional
        The column widths in units of the axes. If not given, all columns will
        have a width of *1 / ncols*.

    rowLabels : list of str, optional
        The text of the row header cells.

    rowColours : list of :mpltype:`color`, optional
        The colors of the row header cells.

    rowLoc : {'left', 'center', 'right'}
        The text alignment of the row header cells.

    colLabels : list of str, optional
        The text of the column header cells.

    colColours : list of :mpltype:`color`, optional
        The colors of the column header cells.

    colLoc : {'center', 'left', 'right'}
        The text alignment of the column header cells.

    loc : str, default: 'bottom'
        The position of the cell with respect to *ax*. This must be one of
        the `~.Table.codes`.

    bbox : `.Bbox` or [xmin, ymin, width, height], optional
        A bounding box to draw the table into. If this is not *None*, this
        overrides *loc*.

    edges : {'closed', 'open', 'horizontal', 'vertical'} or substring of 'BRTL'
        The cell edges to be drawn with a line. See also
        `~.Cell.visible_edges`.

    Returns
    -------
    `~matplotlib.table.Table`
        The created table.

    Other Parameters
    ----------------
    **kwargs
        `.Table` properties.

    %(Table:kwdoc)s
    NzZAt least one argument from "cellColours" or "cellText" must be provided to create a table.r   r   z3rowLabels cannot be used alongside Pandas DataFramez3colLabels cannot be used alongside Pandas DataFramez!Each row in 'cellText' must have z columnsz'cellColours' must have z rowsz$Each row in 'cellColours' must have r   rY   z'rowLabels' must be of length r   )r   r    r   r   r   rq   gV瞯<rD   )rj   r   r   indexcolumnsr   r   r   r   r   r   r   r=   	add_table)r   cellTextcellColourscellLoc	colWidths	rowLabels
rowColoursrowLoc	colLabels
colColourscolLocr   rS   r   r^   rowscolsr   rowLabelWidthoffsetr   r    r   r0   r0   r1   r     s   T













r   )NNr   NNNrL   NNr!   r   Nr   )r{   numpyr   r   r   r   artistr   r   patchesr   r   r   
transformsr	   pathr
   cbookr   r   
CustomCellr   r|   r   r0   r0   r0   r1   <module>   s.    F   