ó
    /j-jÀ<  ã                   óÀ   • S r SSKJr   SSKJr  SSKJr  SrSSK
Jr  SSK
Jr  SS	K
Jr  SS
 jr     SS jrS rS rS rSS jr " S S5      rg! \	 a    Sr NDf = f)z0Plotting functions usefull for visual debugging.é    )ÚLTTextLineVerticalNTFé   )Úbbox_from_str)Úbbox_from_textlines)Úget_textline_coordsc                 ó  • U R                  5       u  p4U R                  5       u  pVU R                  [        X1S   U-
  5      [	        XAS   U-   5      5        U R                  [        XQS   U-
  5      [	        XaS   U-   5      5        g)z,Ensure the ax limits include the input bbox.r   é   r   é   N)Úget_xlimÚget_ylimÚset_xlimÚminÚmaxÚset_ylim)ÚaxÚbboxÚmarginÚx0Úx1Úy0Úy1s          ÚM/home/mande/repo/quber/.venv/lib/python3.13/site-packages/camelot/plotting.pyÚextend_axe_limr      sp   € à�[‰[‹]�F€BØ�[‰[‹]�F€BØ‡K�K”�B˜Q™ &Ñ(Ó)¬3¨r¸±7¸VÑ3CÓ+DÔEØ‡K�K”�B˜Q™ &Ñ(Ó)¬3¨r¸±7¸VÑ3CÓ+DÕEó    c                 ó   • U R                  [        R                  " US   US   4US   US   -
  US   US   -
  UUUSS95        UR                  S5      u  p‰US:X  a  [	        US   US   5      n
O'US	:X  a  [        US   US   5      n
OS
US   US   -   -  n
S	SSS.nX¸   nU	S:X  a  [	        US   US   5      nO'U	S:X  a  [        US   US   5      nOS
US   US   -   -  nU R                  UU
UUSUU	[        USS9S9  g)a\  Utility drawing function to draw a box with an associated text label.

Parameters
----------
ax : matplotlib.axes.Axes
    matplotlib.axes.Axes (optional)
bbox : [type]
    boundingbox
text : string
    The text to be placed inside the box.
color : str, optional
    The color of the box, by default "black"
linewidth : int, optional
    The linewidth of the box, by default 3
linestyle : str, optional
    The matplotlib linestyle, by default "solid"
label_pos : str, optional
    The label postiion, by default "top,left"
fontsize : int, optional
    The fontsize of the text in the box, by default 12
r   r   r	   r
   F)ÚcolorÚ	linewidthÚ	linestyleÚfillÚ,ÚtopÚbottomç      à?Úcenter)r!   r"   r$   ÚrightÚleftÚblackgš™™™™™¹?)Ú	facecolorÚalpha)Úfontsizer   ÚverticalalignmentÚhorizontalalignmentr   N)Ú	add_patchÚpatchesÚ	RectangleÚsplitr   r   ÚtextÚdict)r   r   r1   r   r   r   Ú	label_posr*   ÚvlabelÚhlabelÚyÚlabel_align_swapÚvlabel_out_of_boxÚxs                 r   Údraw_labeled_bboxr:      sQ  € ð> ‡L�LÜ×ÒØ�!‰W�d˜1‘gÐØ�‰G�d˜1‘gÑØ�‰G�d˜1‘gÑØØØØñ	
ô
ð —_‘_ SÓ)�N€FØ�ƒÜ��Q‘˜˜a™Ó!‰Ø	�8Ó	Ü��Q‘˜˜a™Ó!‰à�4˜‘7˜T !™WÑ$Ñ%ˆð  (°5ÀHÑMÐØ(Ñ0ÐØ�ÓÜ��Q‘˜˜a™Ó!‰Ø	�6Ó	Ü��Q‘˜˜a™Ó!‰à�4˜‘7˜T !™WÑ$Ñ%ˆØ‡G�GØ	Ø	ØØØØ+Ø"Ü˜E¨Ñ-ð ò 	r   c                 ó€   • U R                  5       nUR                  USU R                  S   SU R                  S   4S9  g)z›Draw the content of the table's source pdf into the passed subplot.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)
r   r   )ÚextentN)Úget_pdf_imageÚimshowÚpdf_size)Útabler   Úimgs      r   Údraw_pdfrB   b   s=   € ð ×
Ñ
Ó
€CØ‡I�Iˆc˜1˜eŸn™n¨QÑ/°°E·N±NÀ1Ñ4EÐF€IÒGr   c                 óÞ   • U R                   (       a\  SSS.nUR                  5        HB  u  p4U R                   U   =(       d    /  H!  n[        U[        U5      U SU S3SSSS	S
9  M#     MD     gg)z˜Draw any user provided constraints (area, region, columns, etc).

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)
Útable_regionsÚtable_areas)ÚregionÚareaz: (Ú)ÚpurpleÚdottedr   úbottom,right)r   r   r   r3   N)Úparse_detailsÚitemsr:   r   )r@   r   Úzone_constraintsÚ	zone_nameÚzone_idÚzone_strs         r   Údraw_parse_constraintsrR   n   s„   € ð ××à%Ø!ñ
Ðð #3×"8Ñ"8Ö":ÑˆIà!×/Ñ/°Ñ8×>¸BÒ>�Ü!ØÜ! (Ó+Ø �k  X J¨aÐ0Ø"Ø&ØØ,ôó ?ò #;ð r   c                 ór  • [        U R                  5      nU R                   H‡  n[        U[        5      (       a  SOSnUR	                  [
        R                  " UR                  UR                  4UR                  UR                  -
  UR                  UR                  -
  USS95        M‰     [        X5        g)z‡Draw text, horizontal in blue, vertical in red.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)
ÚredÚbluegš™™™™™É?©r   r)   N)r   Ú	textlinesÚ
isinstancer   r-   r.   r/   r   r   r   r   r   )r@   r   r   Útr   s        r   Ú	draw_textrZ   ‰   s‡   € ô ˜uŸ™Ó/€DØ�_Œ_ˆÜ# AÔ'9×:Ñ:‘ÀˆØ
�‰Ü×ÒØ—‘�q—t‘t�˜aŸd™d Q§T¡T™k¨1¯4©4°!·$±$©;¸eÈ3ñö	
ñ ô �2Õr   c                 ó‚   • Uc%  [         R                  " 5       nUR                  SSS9n[        X5        [	        X5        U$ )z®Initialize plot and draw common components.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

Returns
-------
ax : matplotlib.axes.Axes
éo   Úequal)Úaspect)ÚpltÚfigureÚadd_subplotrB   rR   )r@   r   Úfigs      r   Úprepare_plotrc   œ   s;   € ð 
�zÜ�jŠj‹lˆØ�_‰_˜S¨ˆ_Ð1ˆÜˆUÔÜ˜5Ô%Ø€Ir   c                   ó¤   • \ rS rSrSrSS jrSS jr\SS j5       r\SS j5       r	\SS j5       r
\SS	 j5       r\SS
 j5       r\SS j5       rSrg)ÚPlotMethodsé°   z!Classmethod for plotting methods.Nc                 ó:  • [         (       d  [        S5      eUR                  S:X  a  US;   a  [        SU< 35      eUR                  S:w  a!  US;   a  [        UR                   SU< 35      e[	        X5      nUb  U" X5      nUR                  U5        gU" X5      $ )a2  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',
        'network_table_search'}
    The element type for which a plot should be generated.
filename: str, optional (default: None)
    Absolute path for saving the generated plot.
ax : matplotlib.axes.Axes (optional)

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

z$matplotlib is required for plotting.Úlattice)Útextedgez%Lattice flavor does not support kind=)Úlinez flavor does not support kind=N)Ú_HAS_MPLÚImportErrorÚflavorÚNotImplementedErrorÚgetattrÚsavefig)Úselfr@   ÚkindÚfilenamer   Úplot_methodrb   s          r   Ú__call__ÚPlotMethods.__call__³   s¤   € ÷. ŠxÜÐDÓEÐEà�<‰<˜9Ó$¨°Ó)=Ü%Ð(MÈdÉXÐ&VÓWÐWØ�<‰<˜9Ó$¨°Ó)9Ü%Ø—<‘<�.Ð >¸t¹hÐGóð ô ˜dÓ)ˆØÑÙ˜eÓ(ˆCØ�K‰K˜Ô!Øá˜5Ó%Ð%r   c                 óN   • [        X5      n[        X5        UR                  5       $ )zÄGenerate a plot for all text elements present on the PDF page.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

)rc   rZ   Ú
get_figure)rq   r@   r   s      r   r1   ÚPlotMethods.textÜ   s"   € ô ˜%Ó$ˆÜ�%ÔØ�}‰}‹Ðr   c                 óV  • [        X5      nU R                   GH~  nU GHs  nUR                  (       aJ  UR                  UR                  S   UR
                  S   /UR                  S   UR
                  S   /5        UR                  (       aJ  UR                  UR                  S   UR                  S   /UR                  S   UR                  S   /5        UR                  (       aJ  UR                  UR
                  S   UR                  S   /UR
                  S   UR                  S   /5        UR                  (       d  GM)  UR                  UR                  S   UR                  S   /UR                  S   UR                  S   /5        GMv     GM�     UR                  5       $ )zÃGenerate a plot for the detected table grids on the PDF page.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

r   r   )rc   Úcellsr&   ÚplotÚlbÚltr%   ÚrbÚrtr!   r"   rx   )r@   r   ÚrowÚcells       r   ÚgridÚPlotMethods.gridí   s2  € ô ˜%Ó$ˆØ—;•;ˆCÜ�Ø—9—9Ø—G‘G˜TŸW™W Q™Z¨¯©°©Ð4°t·w±w¸q±zÀ4Ç7Á7È1Á:Ð6NÔOØ—:—:Ø—G‘G˜TŸW™W Q™Z¨¯©°©Ð4°t·w±w¸q±zÀ4Ç7Á7È1Á:Ð6NÔOØ—8—8Ø—G‘G˜TŸW™W Q™Z¨¯©°©Ð4°t·w±w¸q±zÀ4Ç7Á7È1Á:Ð6NÔOØ—;—;’;Ø—G‘G˜TŸW™W Q™Z¨¯©°©Ð4°t·w±w¸q±zÀ4Ç7Á7È1Á:Ð6N×Oô ñ ð �}‰}‹Ðr   c           
      ó¬  • U R                   S:H  n[        X5      nU(       d  [        X5        UR                  [        R
                  " U R                  S   U R                  S   4U R                  S   U R                  S   -
  U R                  S   U R                  S   -
  SSS95        U(       d  [        XR                  5        UR                  5       $ )	zÇGenerate a plot for all table boundaries present on the PDF page.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

rh   r   r   r	   r
   FrT   )r   r   )	rm   rc   rZ   r-   r.   r/   Ú_bboxr   rx   )r@   r   Ú_for_lattices      r   ÚcontourÚPlotMethods.contour  s¬   € ð —|‘| yÑ0ˆÜ˜%Ó$ˆæÜ�eÔ à
�‰Ü×ÒØ—‘˜Q‘ §¡¨Q¡Ð0Ø—‘˜A‘ §¡¨Q¡Ñ/Ø—‘˜A‘ §¡¨Q¡Ñ/ØØñô	
ö Ü˜2Ÿ{™{Ô+Ø�}‰}‹Ðr   c                 óò  • [        X5      n[        X5        U R                  S:X  Gað  U R                  S    GHÌ  nUR	                  5       nUR                  [        R                  " UR                  UR                  4UR                  UR                  -
  UR                  UR                  -
  SSS95        [        UR                  R                  5       S S9 GH%  nUR                  U   n[        U5      nUR!                  5       u  pxUR#                  5       u  pš[%        ['        S U
5      5      n[%        ['        S	 U5      5      n[)        U5      nUR+                  Xg   US
-   [-        U5       SSSSS9  UR/                  Xg   /[-        U5      -  USSSSSSSSS9
  [1        ['        S U
5      5      nUR+                  US
-
  Xi   [-        U
5       SSSSS9  UR/                  UXi   /[-        U5      -  SSSSSSSSS9
  GM(     GMÏ     UR7                  5       $ U R2                   HA  nUR/                  UR4                  UR4                  /UR                  UR                  /5        MC     UR7                  5       $ )z­Generate a plot for relevant textedges.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

ÚnetworkÚnetwork_searchesrT   r#   rV   c                 ó4   • U R                   * U R                  4$ ©N)r   r   )Útextlines    r   Ú<lambda>Ú&PlotMethods.textedge.<locals>.<lambda>J  s   € ¨8¯;©;¨,¸¿¹Ñ)Dr   )Úkeyc                 ó   • U R                   $ rŽ   ©r   ©Útls    r   r�   r‘   P  ó   € ¨R¯UªUr   c                 ó   • U R                   $ rŽ   )r   r•   s    r   r�   r‘   Q  r—   r   é   r"   r$   é   Úgreen)r+   r,   r*   r   Úsolidr   ÚoNé   gš™™™™™é?)r   r   r   ÚmarkerÚmarkeredgecolorÚ	fillstyleÚ
markersizer)   c                 ó   • U R                   $ rŽ   r”   r•   s    r   r�   r‘   i  s   € °·²r   r%   rU   Úfullr
   )rc   rZ   rm   rL   Úmost_connected_textliner-   r.   r/   r   r   r   r   ÚsortedÚ_textline_to_alignmentsÚkeysr   Úmax_vÚmax_hÚlistÚmapr   r1   Úlenr|   r   Ú
_textedgesÚcoordrx   )r@   r   r‹   Úmost_connected_tlr–   Ú
alignmentsÚcoordsÚalignment_id_hÚtls_hÚalignment_id_vÚtls_vÚxsÚysÚtop_hÚleft_vÚtes                   r   ri   ÚPlotMethods.textedge*  s‡  € ô ˜%Ó$ˆÜ�%Ôà�<‰<˜9Ô$Ø ×.Ñ.Ð/AÕB�Ø$+×$CÑ$CÓ$EÐ!à—‘Ü×%Ò%Ø*×-Ñ-Ð/@×/CÑ/CÐDØ)×,Ñ,Ð/@×/CÑ/CÑCØ)×,Ñ,Ð/@×/CÑ/CÑCØ#Ø!ñôô !Ø×3Ñ3×8Ñ8Ó:ÙDõ�Bð ")×!@Ñ!@ÀÑ!D�JÜ0°Ó4�FØ,6×,<Ñ,<Ó,>Ñ)�NØ,6×,<Ñ,<Ó,>Ñ)�NÜœcÑ"2°EÓ:Ó;�BÜœcÑ"2°EÓ:Ó;�BÜ ›G�EØ—G‘GØÑ.Ø ™	Ü˜u›:˜,Ø*2Ø,4Ø!"Ø%ð ñ ð —G‘GØÑ/Ð0´3°r³7Ñ:ØØ%Ø")Ø"#Ø"Ø(/Ø"&Ø#$Ø!ð ñ ô !¤Ñ%5°uÓ!=Ó>�FØ—G‘GØ ™
ØÑ.Ü˜u›:˜,Ø*2Ø,3Ø!"Ø$ð ñ ð —G‘GØØÑ/Ð0´3°r³7Ñ:Ø$Ø")Ø"#Ø"Ø(.Ø"(Ø#$Ø!ð ô ôWñ CðL �}‰}‹Ðð ×&Ô&�Ø—‘˜Ÿ™ 2§8¡8Ð,¨r¯u©u°b·e±e¨nÖ=ñ 'à�}‰}‹Ðr   c                 óà   • [        X5      n/ n/ nU R                  S    H+  nUR                  US   5        UR                  US   5        M-     UR                  X#S5        UR	                  5       $ )zÉGenerate a plot for all line intersections present on the PDF page.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

Újointsr   r   Úro)rc   ÚparseÚappendr|   rx   )r@   r   Úx_coordÚy_coordr¯   s        r   ÚjointÚPlotMethods.joint„  sg   € ô ˜%Ó$ˆØˆØˆØ—[‘[ Ô*ˆEØ�N‰N˜5 ™8Ô$Ø�N‰N˜5 ™8Ö$ñ +ð 	�‰� $Ô'Ø�}‰}‹Ðr   c                 ó   • [        X5      nU R                  u  p#U H%  nUR                  US   US   /US   US   /5        M'     U H%  nUR                  US   US   /US   US   /5        M'     UR                  5       $ )zÄGenerate a plot for all line segments present on the PDF page.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

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

r   r	   r   r
   )rc   Ú	_segmentsr|   rx   )r@   r   ÚverticalÚ
horizontalÚvÚhs         r   rj   ÚPlotMethods.line›  s†   € ô ˜%Ó$ˆØ$Ÿ™ÑˆÛˆAØ�G‰G�Q�q‘T˜1˜Q™4�L 1 Q¡4¨¨1© ,Ö/ñ ãˆAØ�G‰G�Q�q‘T˜1˜Q™4�L 1 Q¡4¨¨1© ,Ö/ñ à�}‰}‹Ðr   c                 óì  • [        X5      nU R                  c  UR                  5       $ U R                  n[        US   5       H´  u  p4US   nUS   nUS   n[        U5       H‘  u  p‰U[	        U5      S-
  :H  n
[        UU	SU SU 3SU
(       a  S	OS
U
(       a  SOSSS9  UR                  [        R                  " U	S   U-
  U	S   U-
  4U	S
   U	S   -
  S
U-  -   U	S   U	S   -
  S
U-  -   SSSS95        M“     M¶     [        US   5       HY  u  p;[        UUS   SU 3SSSS9  [        UUS   SU 3SS
SS9  US    H#  nUR                  XÌ/US   S   US   S   /S S!9  M%     M[     UR                  5       $ )"zÈGenerate a plot illustrating the steps of the network table search.

Parameters
----------
table : camelot.core.Table
ax : matplotlib.axes.Axes (optional)

Returns
-------
fig : matplotlib.fig.Figure
Úbbox_searchesÚ	max_h_gapÚ	max_v_gapÚ
iterationsr   rY   z/irT   r™   r	   é   rš   zbottom,left)r   r   r*   r3   r   r
   ÚorangerJ   F)r   r   r   Úcol_searchesÚ	bbox_fullzbox body + header #rž   útop,left)r   r   r3   Ú	bbox_bodyz
box body #ÚcyanrK   Úcols_anchorsr›   )r   )
rc   rL   rx   Ú	enumerater­   r:   r-   r.   r/   r|   )r@   r   rL   Úbox_idÚbbox_searchrÏ   rÐ   rÑ   Ú	iterationr   ÚfinalÚ
col_searchÚ
col_anchors                r   Únetwork_table_searchÚ PlotMethods.network_table_search±  sò  € ô ˜%Ó$ˆØ×ÑÑ&Ø—=‘=“?Ð"Ø×+Ñ+ˆÜ#,¨]¸?Ñ-KÖ#LÑˆFØ# KÑ0ˆIØ# KÑ0ˆIØ$ \Ñ2ˆJÜ#,¨ZÖ#8‘�	Ø!¤S¨£_°qÑ%8Ñ8�ä!ØØØ˜�x˜r ) Ð-ØÞ#(™a¨aÞ#(™R¨aØ+òð —‘Ü×%Ò%Ø˜a™ 9Ñ,¨d°1©g¸	Ñ.AÐBØ˜Q™ $ q¡'Ñ)¨A°	©MÑ9Ø˜Q™ $ q¡'Ñ)¨A°	©MÑ9Ø&Ø"*Ø"ñö	ó $9ñ	 $Mô8 #,¨M¸.Ñ,IÖ"JÑˆFÜØØ˜;Ñ'Ø% f XÐ.ØØØ$òô ØØ˜;Ñ'Ø˜V˜HÐ%ØØØ(òð )¨Ô8�
ð —‘ØÐ,à" ;Ñ/°Ñ2Ø" ;Ñ/°Ñ2ðð "ð ó ó 9ñ# #Kð: �}‰}‹Ðr   © )r1   NNrŽ   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ru   r1   Ústaticmethodrƒ   rˆ   ri   rÄ   rj   rá   Ú__static_attributes__rã   r   r   re   re   °   sŽ   † Ù+ô'&ôRð" óó ðð4 óó ððB óWó ðWðr óó ðð, óó ðð* óIó óIr   re   )é
   )r'   r
   rœ   rÖ   é   rŽ   )rè   Úplaya.minerr   Úmatplotlib.patchesr.   Úmatplotlib.pyplotÚpyplotr_   rk   rl   Úutilsr   r   r   r   r:   rB   rR   rZ   rc   re   rã   r   r   Ú<module>rò      s|   ðÙ 6å *ðÝ(Ý#ð €Hå  Ý &Ý &ôFð ØØØØôEòP	Hòò6ô&÷(Kò KøðQ ó Ø‚Hðús   ŠA ÁAÁA