o
    j)                     @   sL   zd dl mZ d dlmZ W n ey   dZY nw dZG dd deZdS )    NFTc                   @   sF   e Zd ZdddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dS )PlotMethodstextNc                 C   s|   t std|jdkr|dv rtd| d|jdkr(|dv r(td| dt| |}||}|d	ur<|| d	S |S )
ad  Plot elements found on PDF page based on kind
        specified, useful for debugging and playing with different
        parameters to get the best output.

        Parameters
        ----------
        table: camelot.core.Table
            A Camelot Table.
        kind : str, optional (default: 'text')
            {'text', 'grid', 'contour', 'joint', 'line'}
            The element type for which a plot should be generated.
        filepath: str, optional (default: None)
            Absolute path for saving the generated plot.

        Returns
        -------
        fig : matplotlib.fig.Figure

        z$matplotlib is required for plotting.lattice)textedgez&Lattice flavor does not support kind=''stream)jointlinez%Stream flavor does not support kind='N)_HAS_MPLImportErrorflavorNotImplementedErrorgetattrsavefig)selftablekindfilenameplot_methodfig r   V/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/site-packages/camelot/plotting.py__call__   s   

zPlotMethods.__call__c              
   C   s   t  }|jddd}g g }}|jD ]4}||d |d g ||d |d g |t|d |d f|d |d  |d |d   q|t	|d t
|d  |t	|d t
|d  |S )	zGenerates a plot for all text elements present
        on the PDF page.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        o   equalaspectr            
   )pltfigureadd_subplot_textextend	add_patchpatches	Rectangleset_xlimminmaxset_ylim)r   r   r   axxsystr   r   r   r   2   s   

:zPlotMethods.textc                 C   s   t  }|jddd}|jD ]k}|D ]f}|jr-||jd |jd g|jd |jd g |jrF||j	d |j
d g|j	d |j
d g |jr_||jd |j
d g|jd |j
d g |jrx||jd |j	d g|jd |j	d g qq|S )zGenerates a plot for the detected table grids
        on the PDF page.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        r   r   r   r   r   )r!   r"   r#   cellsleftplotlbltrightrbrttopbottom)r   r   r   r-   rowcellr   r   r   gridJ   s   
,,,,	zPlotMethods.gridc           
   
   C   s  z	|j \}}d}W n ty   d|jdi}}d}Y nw t }|jddd}g g }}|si|jD ]6}	||	d |	d g ||	d	 |	d
 g |t	j
|	d |	d	 f|	d |	d  |	d
 |	d	  dd q2| D ]U}	|t	j
|	d |	d	 f|	d |	d  |	d
 |	d	  ddd |s||	d |	d g ||	d	 |	d
 g |t|d t|d  |t|d t|d  qm|r|| |S )zGenerates a plot for all table boundaries present
        on the PDF page.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        TNFr   r   r   r   r   r   r   bluecolorred)fillr@   r    )_image	TypeError_bboxr!   r"   r#   r$   r%   r&   r'   r(   keysr)   r*   r+   r,   imshow)
r   r   img
table_bbox_FOR_LATTICEr   r-   r.   r/   r0   r   r   r   contoure   sD   


,.
zPlotMethods.contourc              	   C   s   t  }|jddd}g g }}|jD ]6}||d |d g ||d |d g |tj|d |d f|d |d  |d |d  dd	 q|t	|d
 t
|d
  |t	|d
 t
|d
  |jD ]}||j|jg|j|jg qi|S )zGenerates a plot for relevant textedges.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        r   r   r   r   r   r   r   r>   r?   r    )r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   
_textedgesr3   xy0y1)r   r   r   r-   r.   r/   r0   ter   r   r   r      s   

4
zPlotMethods.textedgec           
      C   s|   |j \}}t }|jddd}g }g }| D ]}|| D ]}	||	d  ||	d  qq|||d || |S )zGenerates a plot for all line intersections present
        on the PDF page.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        r   r   r   r   r   ro)rC   r!   r"   r#   rF   appendr3   rG   )
r   r   rH   rI   r   r-   x_coordy_coordkcoordr   r   r   r      s   

zPlotMethods.jointc                 C   s   t  }|jddd}|j\}}|D ]}||d |d g|d |d g q|D ]}||d |d g|d |d g q)|S )zGenerates a plot for all line segments present
        on the PDF page.

        Parameters
        ----------
        table : camelot.core.Table

        Returns
        -------
        fig : matplotlib.fig.Figure

        r   r   r   r   r   r   r   )r!   r"   r#   	_segmentsr3   )r   r   r   r-   vertical
horizontalvhr   r   r   r	      s   
&&zPlotMethods.line)r   N)
__name__
__module____qualname__r   r   r=   rK   r   r   r	   r   r   r   r   r      s    
%1r   )	matplotlib.pyplotpyplotr!   matplotlib.patchesr'   r   r
   objectr   r   r   r   r   <module>   s   