
    :Qg)                     R    	 d dl mZ d dlmZ dZ G d de      Zy# e$ r dZY w xY w)    NTFc                   8    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	y)
PlotMethodsNc                     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	        | |      } ||      }||j                  |       y	|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figs         M/var/www/html/answerous/venv/lib/python3.12/site-packages/camelot/plotting.py__call__zPlotMethods.__call__   s    ( DEE<<9$)=%(NtfTU&VWW\\X%$2C*C%(MdVST&UVVdD)% KK!
    c           
      
   t        j                         }|j                  dd      }g g }}|j                  D ]t  }|j	                  |d   |d   g       |j	                  |d   |d   g       |j                  t        j                  |d   |d   f|d   |d   z
  |d   |d   z
               v |j                  t        |      dz
  t        |      dz          |j                  t        |      dz
  t        |      dz          |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ts          r   textzPlotMethods.text2   s     jjl__S_1RB 	TAIIqtQqTl#IIqtQqTl#LL**AaD!A$<1!adQqTkRS	T 	CGbL#b'B,/
CGbL#b'B,/
r   c                 @   t        j                         }|j                  dd      }|j                  D ]f  }|D ]]  }|j                  rJ|j                  |j                  d   |j                  d   g|j                  d   |j                  d   g       |j                  rJ|j                  |j                  d   |j                  d   g|j                  d   |j                  d   g       |j                  rJ|j                  |j                  d   |j                  d   g|j                  d   |j                  d   g       |j                  s|j                  |j                  d   |j                  d   g|j                  d   |j                  d   g       ` i |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   r0   rowcells         r   gridzPlotMethods.gridJ   sJ    jjl__S_1;; 		PC P99GGTWWQZ4twwqz4771:6NO::GGTWWQZ4twwqz4771:6NO88GGTWWQZ4twwqz4771:6NO;;GGTWWQZ4twwqz4771:6NOP		P 
r   c           
         	 |j                   \  }}d}t        j                         }|j                  dd      }g g }}|s|j                  D ]v  }	|j                  |	d   |	d   g       |j                  |	d	   |	d
   g       |j                  t        j                  |	d   |	d	   f|	d   |	d   z
  |	d
   |	d	   z
  d             x |j                         D ]  }	|j                  t        j                  |	d   |	d	   f|	d   |	d   z
  |	d
   |	d	   z
  dd             |rI|j                  |	d   |	d   g       |j                  |	d	   |	d
   g       |j                  t        |      dz
  t        |      dz          |j                  t        |      dz
  t        |      dz           |r|j!                  |       |S # t        $ r d|j                  di}}d}Y w xY w)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)fillrF   r#   )_image	TypeError_bboxr$   r%   r&   r'   r(   r)   r*   r+   keysr,   r-   r.   r/   imshow)
r   r   img
table_bbox_FOR_LATTICEr   r0   r1   r2   r3   s
             r   contourzPlotMethods.contoure   s   	!#llOCL jjl__S_1RB[[ 		1Q41,'		1Q41,'%%1qtadQqTk1Q4!A$;f " 
	8ALL!!qT1Q4L!A$1+qtad{e
  		1Q41,'		1Q41,'CGbL#b'B,7CGbL#b'B,7
	8 IIcN
?  	!#ekk4%8C L	!s   F; ;GGc           
         t        j                         }|j                  dd      }g g }}|j                  D ]v  }|j	                  |d   |d   g       |j	                  |d   |d   g       |j                  t        j                  |d   |d   f|d   |d   z
  |d   |d   z
  d	             x |j                  t        |      d
z
  t        |      d
z          |j                  t        |      d
z
  t        |      d
z          |j                  D ]@  }|j                  |j                  |j                  g|j                  |j                   g       B |S )zGenerates a plot for relevant textedges.

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

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

        r   r   r   r   r    r!   r"   rD   rE   r#   )r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   
_textedgesr8   xy0y1)r   r   r   r0   r1   r2   r3   tes           r   r   zPlotMethods.textedge   s2    jjl__S_1RB 	AIIqtQqTl#IIqtQqTl#LL!!1Q41,!qtQqTAaD[PVW	 	CGbL#b'B,/
CGbL#b'B,/"" 	2BGGRTT244L255"%%.1	2 
r   c                 P   |j                   \  }}t        j                         }|j                  dd      }g }g }|j	                         D ]4  }||   D ]*  }	|j                  |	d          |j                  |	d          , 6 |j                  ||d       |j                  |       |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)rI   r$   r%   r&   rL   appendr8   rM   )
r   r   rN   rO   r   r0   x_coordy_coordkcoords
             r   r
   zPlotMethods.joint   s      ,,Zjjl__S_1" 	)A#A )uQx(uQx()	) 	$'
		#
r   c                    t        j                         }|j                  dd      }|j                  \  }}|D ]$  }|j	                  |d   |d   g|d   |d   g       & |D ]$  }|j	                  |d   |d   g|d   |d   g       & |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&   	_segmentsr8   )r   r   r   r0   vertical
horizontalvhs           r   r   zPlotMethods.line   s     jjl__S_1$* 	0AGGQqT1Q4L1Q41,/	0 	0AGGQqT1Q4L1Q41,/	0
r   )r4   N)
__name__
__module____qualname__r   r4   rB   rQ   r   r
   r    r   r   r   r      s'    #J06/b:4r   r   )	matplotlib.pyplotpyplotr$   matplotlib.patchesr*   r   r   objectr   rh   r   r   <module>rm      s;   #( HU& U  Hs    &&