
    g
                     ,    d Z ddlmZmZmZ ddZddZy)zE
Helper module for the *bbox_inches* parameter in `.Figure.savefig`.
    )BboxTransformedBboxAffine2DNc                      j                    j                   j                  j                  g g t	                j
                  D ]  }|j                         }||j                   ||d             j                  |       |j                  d      j                         }|j                  |fd       d|j                  v rj                  |j                         nj                         d	d|_          fd}| j                  }t               j                  |      }| j                  z  }t!        j"                  ddg|j$                    _        |j'                  |j(                        \  }	}
 j                   j$                  |z  \  }}t!        j"                  |	 |
 ||       j                  _         j                  j+                          t-         j                  |       _          j.                  j1                  |	|z  |
|z   j                   j2                  |z   j                   j4                  |z         |S )
aO  
    Temporarily adjust the figure so that only the specified area
    (bbox_inches) is saved.

    It modifies fig.bbox, fig.bbox_inches,
    fig.transFigure._boxout, and fig.patch.  While the figure size
    changes, the scale of the original figure is conserved.  A
    function which restores the original values are returned.
    NF)originalc                     |S N )ar_poss      S/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/matplotlib/_tight_bbox.py<lambda>zadjust_bbox.<locals>.<lambda>   s    4     apply_aspectc                      y r	   r
   )poss    r   r   zadjust_bbox.<locals>.<lambda>%   s    r   c                  2   t        j                        D ]%  \  } }}| j                  |       |	u r| `|| _        ' _        _        j                  _        j                  j                          j                  j                  dddd       y )Nr      )zipaxesset_axes_locatorr   bboxbbox_inchestransFigure_boxout
invalidatepatch
set_bounds)
axlocaspectr   figlocator_list
old_aspectorigBboxorigBboxInchessentinels
      r   restore_bboxz!adjust_bbox.<locals>.restore_bbox'   s    "388\:F 	)OBV$!O"(	) (")""$		Q1a(r   r   r	   )r   r   r   r   objectr   get_axes_locatorr   appendget_positionfrozenr   __dict__dpir   scaler   from_boundssize	transformp0r   r   r   r   widthheight)r#   r   	fixed_dpir    locatorcurrent_posr)   tr	dpi_scalex0y0w1h1r   r$   r%   r&   r'   r(   s   `            @@@@@@r   adjust_bboxrA      s    xxH__Noo%%GJLxHhh 0%%'OOGB-.G$oouo5<<>
k?@R[[(boo.h'/0) ) GG				)	$BCGG#I&&q!?k.>.>?CO\\+..)FBXX]]Y&FB"..sRCR@COOOO s3CHIIb"r'",chhoo.BD r   c                 <    |\  }} |        t        | ||      }||fS )z
    A function that needs to be called when figure dpi changes during the
    drawing (e.g., rasterizing).  It recovers the bbox and re-adjust it with
    the new dpi.
    )rA   )r#   bbox_inches_restorer8   r   r)   r   s         r   process_figure_for_rasterizingrD   I   s+     !4KNCi0A>r   r	   )__doc__matplotlib.transformsr   r   r   rA   rD   r
   r   r   <module>rG      s    B A>Br   