a
    ¦¾de[Y  ã                   @   s"  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ ddlT ddlmZmZ ddlmZmZmZmZmZmZ ddlmZm Z  dd	lm!Z! dd
l"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+ e,e)e*e+d�Z-ddl.m/Z0 ddddddddddœ	ddddddddddœ	dœZ1zddl2m3Z3 W n e4�yT   dZ3Y n0 ddddddddddœ	Z5G d d!„ d!eƒZ6G d"d#„ d#ƒZ7ed$d%d&d'ƒZ8G d(d)„ d)e ƒZ9eee9ƒƒZ:G d*d+„ d+e6ƒZ;G d,d-„ d-e;ƒZ<G d.d/„ d/e<ƒZ=eee=ƒƒZ>dd0l?m@Z@ G d1d2„ d2e@ƒZAG d3d4„ d4e6ƒZBdS )5z3.3.0é    )Úcolors)ÚsimpleSplit)ÚisNumberÚisNumberOrNoneÚOneOfÚisColorOrNoneÚisStringÚisTextAnchorÚisBoxAnchorÚ	isBooleanÚNoneOrÚisInstanceOfÚisNoneOrStringÚisNoneOrCallableÚisSubclassOf)Ú*)ÚstringWidthÚgetAscentDescent)ÚDrawingÚGroupÚCircleÚRectÚStringÚSTATE_DEFAULTS)ÚWidgetÚ
PropHolder)Ú
DirectDraw)ÚXPreformattedÚFlowable)ÚParagraphStyleÚPropertySet)ÚTA_LEFTÚTA_RIGHTÚ	TA_CENTER)ÚstartÚendÚmiddleé   )Ú	text2PathÚnÚneÚeÚseÚsÚswÚwÚnw)	r   é-   éZ   é‡   é´   éá   i  i;  éÓÿÿÿ©ÚxÚy)ÚDirectDrawFlowableNr$   r%   r&   )	r/   r0   r.   r+   r*   r,   r)   r-   Úcc                $   @   sÜ  e Zd ZdZeeedd�eedd�eedd�eedd�eedd�eedd�eedd�eed	d�eed
d�ee	ddddƒdd�eedd�eedd�eedd�ee
dd�ee
dd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eed d!d"�eeeeƒd#ƒd$d!d"�eeeeƒd#ƒd%d!d"�eeeeƒeeƒfƒd&d!d"�d'�Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>S )?ÚLabelzïA text label to attach to something else, such as a chart axis.

    This allows you to specify an offset, angle and many anchor
    properties relative to the label's origin.  It allows, for example,
    angled multiline axis labels.
    Ú ©Údesczdelta x - offsetzdelta y - offsetzDangle of label: default (0), 90 is vertical, 180 is upside down, etczanchoring point of the labelzborder color of the boxzborder widthzthe filling color of the boxÚnormalÚantiÚloÚhiz"one of ('normal','anti','lo','hi')zlabel text colorzlabel text border colorzlabel text border widthzthe actual text to displayzthe name of the font usedzthe size of the fontzthe width of the labelz#maximum width the label can grow tozthe height of the textz0the anchoring point of the text inside the labelú True if the label is to be drawnzpadding at top of boxzpadding at left of boxzpadding at right of boxzpadding at bottom of boxz^If True then the font's Ascent & Descent will be used to compute default heights and baseline.zDAn instance of CustomDrawChanger to modify the behavior at draw timeé   )r?   Z_advancedUsageZNoneOrDirectDrawzA DirectDrawFlowable instancez=A Flowable class for direct drawing (default is XPreformattedz-A style or style class for a ddfKlass or None)r8   r9   ÚdxÚdyÚangleÚ	boxAnchorÚboxStrokeColorÚboxStrokeWidthÚboxFillColorÚ	boxTargetÚ	fillColorÚstrokeColorÚstrokeWidthÚtextÚfontNameÚfontSizeÚleadingÚwidthÚmaxWidthÚheightÚ
textAnchorÚvisibleÚ
topPaddingÚleftPaddingÚrightPaddingÚbottomPaddingÚuseAscentDescentÚcustomDrawChangerÚddfÚddfKlassÚddfStylec                  K   sf   | j f i |¤Ž | j ddddddddddddd dd d d d d d td td td d	d
ddtd d d� d S )NzMulti-Line
Stringr;   r   ç      à?r@   rN   rR   rS   gš™™™™™¹?r$   rE   F)Ú_textrI   rH   r8   r9   rF   rG   rZ   r[   r\   r]   rK   rJ   rM   rO   rL   rT   rU   rV   rW   rN   rR   rS   rP   rX   rY   r^   r`   ra   rb   )Z_setKeywordsr   r:   )ÚselfÚkw© rg   ú]/var/www/sistema_ama/venv/lib/python3.9/site-packages/reportlab/graphics/charts/textlabels.pyÚ__init__M   sB    âzLabel.__init__c                 C   s
   || _ dS )zpSet the text property.  May contain embedded newline characters.
        Called by the containing chart or axis.N)rd   )re   rQ   rg   rg   rh   ÚsetTextp   s    zLabel.setTextc                 C   s   || _ || _dS )z‰Set the origin.  This would be the tick mark or bar top relative to
        which it is defined.  Called by the containing chart or axis.Nr7   )re   r8   r9   rg   rg   rh   Ú	setOriginv   s    zLabel.setOriginc                 C   sl   t ddƒ}| tdddtjd�¡ tƒ }| dd¡ d|_d|_d|_	d	|_
tj|_| d
¡ | |¡ |S )zyThis shows a label positioned with its top right corner
        at the top centre of the drawing, and rotated 45 degrees.éÈ   éd   r2   é   )rN   r*   r1   r   iìÿÿÿzAnother
Multi-Line
String)r   Úaddr   r   Zgreenr<   rk   rI   rH   rF   rG   rJ   rj   )re   ÚdZlabrg   rg   rh   Údemo}   s    


z
Label.democ                 C   st   | j }|dv rp| j}t|d d ƒd d }|d s`|| d }t|ƒdkr`||dkrZdp\d }t|d	  | }|S )
z,hook for allowing special box anchor effects)ZautoxZautoyih  g     €F@r1   r2   rn   r   r6   éÿÿÿÿ)rI   rH   ÚintÚabsÚ_A2BA)re   ÚbarH   ÚnaÚdarg   rg   rh   Ú_getBoxAnchor’   s    zLabel._getBoxAnchorc                 C   s<   | j r2t| j| jƒ\| _| _| j| j| j  | _nd| _d S )Ng«ªªªªªê?)r^   r   rR   rS   Ú_ascentÚ_descentÚ_baselineRatio©re   rg   rg   rh   Ú_getBaseLineRatioŸ   s    zLabel._getBaseLineRatioc                 C   sØ   | j p|| j | j | _| j| j | j | _| j| j | j | _|  	¡ }|dv r\| j | _
n$|dv rt| j| j | _
nd| j | _
| j
| j | _|dv r¦| j| j | _n |dv r¸| j| _n| j d | _| j| j | _d S )N)r)   r*   r0   )r-   r.   r,   rc   )r*   r+   r,   )r0   r/   r.   )rW   rZ   r]   Ú_heightÚ_widthr[   r\   Ú_ewidthÚ_eheightry   Ú_topÚ_bottomÚ_leftÚ_right)re   ÚobjHrI   rg   rg   rh   Ú_computeSizeEnd¦   s     
zLabel._computeSizeEndc                    s|  t ˆ dd ƒ}|sÊg ˆ _tˆ jˆ jˆ jˆ jƒˆ _ˆ jstˆ j	ˆ j
 ˆ _ˆ jr|‡ fdd„ˆ jD ƒˆ _ˆ  jtˆ jƒ7  _nˆ jˆ _ˆ  ¡  ˆ jr”ˆ jˆ _n"ˆ jrªˆ jˆ j ˆ _nˆ jd ˆ _ˆ jtˆ jƒ }�n¤ˆ jd u rÜtdƒ‚tdˆ jˆ jˆ jˆ jd�}ˆ j�stf i |¤Ž}ndtˆ jtƒ�r0ˆ jjf i |¤Ž}nBtˆ jtƒ�r^tˆ jtƒ�r^ˆ jf i |¤Ž}nt dtˆ jƒ› �ƒ‚|ˆ _!ˆ  ¡  ˆ j�ržd	|_"ˆ jˆ j |_nˆ j�r¬ˆ jnˆ jd |_|jˆ _ˆ  #¡ }ˆ j�pÒd
}|dk�rt$|_%|ˆ j|d�}| &|d
¡\}}ˆ j�p|j'}t(| |_%|ˆ j|d� ˆ _)}| &|d
¡\}}ˆ j�sfˆ j	ˆ j
 ˆ _ˆ  j|j'7  _nˆ jˆ _ˆ  *|¡ d S )Nra   c                    s   g | ]}t |ˆ jˆ jƒ‘qS rg   )r   rR   rS   )Ú.0Úliner}   rg   rh   Ú
<listcomp>Ä   ó    z%Label.computeSize.<locals>.<listcomp>g333333ó?z[DirectDrawFlowable class is not available you need the rlextra package as well as reportlabzxlabel-generated)ÚnamerR   rS   rN   rO   zddfStyle has invalid type Tiÿÿÿr$   )Ústyle)+ÚgetattrZ_lineWidthsr   rd   rR   rS   rV   Ú_linesrU   r[   r\   r€   Úmaxr~   rT   Ú_leadingr^   rz   r{   Úlenr`   ÚRuntimeErrorÚdictrN   rO   rb   r   Ú
isinstancer    ÚcloneÚtypeÚ
issubclassÚ
ValueErrorÚ_styleZautoLeadingÚ_getTextAnchorr!   Ú	alignmentÚwrapZ
_width_maxÚ_ta2alÚ_ddfObjrˆ   )re   ra   r‡   ZstyÚtaZaWÚobjÚ_rg   r}   rh   ÚcomputeSize»   sn    

û

zLabel.computeSizec                 C   s   | j }|dkrt|  ¡  }|S )z/This can be overridden to allow special effectsZboxauto)rX   Ú_BA2TAry   )re   r¡   rg   rg   rh   rœ   ÿ   s    zLabel._getTextAnchorc                 C   s  | j }|pd| _ |  ¡  || _ tƒ }| | j| j | j| j ¡ | | j	¡ t
| dd ƒ}|rd| j}nJ| j| j| j  }|  ¡ }|dkrŽ| j}n |dkr¨| j| jd  }n| j}| jsÀ| jrö| jrö| t| j| j | j| j | j| j| j| j| jd�¡ |�r4tƒ }| || j| j ¡ | |  | j¡¡ | |¡ nÌ| j| j | j!  }}	}
| j"| j#| j  }}}t
| di ƒ}|�r¸| j$D ]<}t%||||	|
|ƒ}||_||_"||_#| |¡ ||8 }�qxnH| j$D ]@}t&||||d�}||_'|	|_ |
|_!||_| |¡ ||8 }�q¾|S )	Nr=   ra   r$   r&   rc   )rO   rP   rN   Ú	_svgAttrs)r¦   )(rd   r¤   r   Ú	translater8   rF   r9   rG   ÚrotaterH   r�   r…   rƒ   r’   r|   rœ   r�   r†   rL   rJ   rK   ro   r   r[   r„   r]   r€   r   r‚   r`   r    rN   rR   rS   rO   rP   r�   Ú
_text2Pathr   rX   )re   rd   Úgra   r8   r9   rX   Zg1rN   rR   rS   rO   rP   rT   ZsvgAttrsrŠ   r-   rg   rg   rh   Ú_rawDraw  sf    

ú	



zLabel._rawDrawc              	   C   sJ   t | dd ƒ}|r>|d| ƒ z|  ¡ W |d| ƒ S |d| ƒ 0 n|  ¡ S d S )Nr_   TF)r�   r«   )re   r_   rg   rg   rh   ÚdrawD  s    

þz
Label.drawN)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚAttrMapÚAttrMapValuer   r
   r   r   r   r   r	   r   r   r   r   r   r   r    r   Ú_attrMapri   rj   rk   rq   ry   r~   rˆ   r¤   rœ   r«   r¬   rg   rg   rg   rh   r<   !   sZ   	

























á"#D?r<   c                   @   sò   e Zd Zeeedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eedd�eeƒdeedd�eedd�eedd�eedd�eedd�eedd�ee	dd�ee
dd�d�Zdd„ Zdd„ Zd	d
„ ZdS )ÚLabelDecoratorr=   r>   rD   )r8   r9   rF   rG   rH   rI   rJ   rK   rL   rN   rO   rP   r?   rR   rS   rT   rU   rV   rW   rX   rY   c                 C   s6   d| _ d| _| j ¡ D ]}t| |ƒst| |d ƒ qd S )Nr$   r/   )rX   rI   r³   ÚkeysÚhasattrÚsetattr©re   Úarg   rg   rh   ri   g  s    zLabelDecorator.__init__c                 C   s>   |j \}}}}}}}	}
}}}}| |jj| ¡ | |¡ d S ©N)Z_callOutInforj   ÚcategoryAxisZcategoryNamesro   )re   ÚlÚLÚchartrª   ZrowNoZcolNor8   r9   rU   rW   Zx00Zy00Zx0Zy0rg   rg   rh   Údecoratem  s    zLabelDecorator.decoratec                 C   sJ   t ƒ }| j ¡ D ](\}}|d u r,t||d ƒ}t|||ƒ q|  ||¡ d S rº   )r<   Ú__dict__Úitemsr�   r·   r¿   )re   r¼   r½   r¹   Úvrg   rg   rh   Ú__call__r  s
    zLabelDecorator.__call__N)r­   r®   r¯   r±   r²   r   r
   r   r   r	   r   r³   ri   r¿   rÃ   rg   rg   rg   rh   r´   O  s2   


















ìr´   ÚhighÚlowÚbarÚaxisc                   @   sL   e Zd Zeeedd�eedd�eedd�eedd�d�Zdd„ Zd	d
„ Z	dS )ÚLabelOffsetzWhere to base +ve offsetr>   zValue for positive elementszWhere to base -ve offsetzValue for negative elements)ÚposModeÚposÚnegModeÚnegc                 C   s   d | _ | _d | _| _d S )NrÇ   r   )rÉ   rË   rÊ   rÌ   r}   rg   rg   rh   ri   �  s    zLabelOffset.__init__c           
      C   s–   |j }|j}|j}|dkr(| j}| j}n| j}| j}|r@|j}n|j}|rŽ|rV|j}	n|j}	|dkrp|	|j	 }n|dkr~|	}n|dkrŽ|	| }|| S )Nr   rÄ   rÅ   rÆ   )
Z_flipXYr»   ZjoinAxisrÉ   rÊ   rË   rÌ   Ú_xZ_yÚ_length)
re   r¾   ÚvalZflipXYÚAZjAÚmodeÚdeltarÂ   Z_vrg   rg   rh   Ú	_getValue…  s,    zLabelOffset._getValueN)
r­   r®   r¯   r±   r²   ÚisOffsetModer   r³   ri   rÓ   rg   rg   rg   rh   rÈ   z  s   



ürÈ   c                   @   s.   e Zd Zeed�Zdd„ Zdd„ Zdd„ ZdS )	ÚPMVLabel©ÚBASEc                 K   s   t j| fi |¤Ž d| _d S ©Nr   )r<   ri   Ú_pmv©re   Úkwdsrg   rg   rh   ri   §  s    zPMVLabel.__init__c              
   C   s4   t  | ¡}| jdk r0dddddddd	d
dœ	| }|S )Nr   r,   r-   r.   r+   r;   r/   r*   r)   r0   )	r0   r)   r*   r/   r;   r+   r.   r-   r,   )r<   ry   rÙ   r¸   rg   rg   rh   ry   «  s    
&zPMVLabel._getBoxAnchorc                 C   s(   t  | ¡}| jdk r$ddddœ| }|S )Nr   r%   r&   r$   )r$   r&   r%   )r<   rœ   rÙ   r¸   rg   rg   rh   rœ   °  s    
zPMVLabel._getTextAnchorN)	r­   r®   r¯   r±   r<   r³   ri   ry   rœ   rg   rg   rg   rh   rÕ   ¢  s   ÿrÕ   c                   @   sj   e Zd ZdZeeeedd�eedd�ee	dd�ee	dd�ee
dd�eedd	d
ddƒdd�d�Zdd„ ZdS )ÚBarChartLabelúF
    An extended Label allowing for nudging, lines visibility etc
    zNon-zero for a drawn liner>   zColor for a drawn linezNone or fixed draw ends +/-zNone or fixed draw starts +/-zNon-zero sign dependent nudger@   rA   rB   rC   Zmidz(one of ('normal','anti','lo','hi','mid'))r×   ÚlineStrokeWidthÚlineStrokeColorÚfixedEndÚ
fixedStartÚnudgerM   c                 K   s4   t j| fi |¤Ž d| _d | _d  | _| _d| _d S rØ   )rÕ   ri   rÞ   rß   rá   rà   râ   rÚ   rg   rg   rh   ri   Ã  s
    zBarChartLabel.__init__N)r­   r®   r¯   r°   r±   rÕ   r²   r   r   ÚNoneOrInstanceOfLabelOffsetr   r   r³   ri   rg   rg   rg   rh   rÜ   µ  s   




ù
rÜ   c                   @   s,   e Zd ZdZeeeedd�d�Zdd„ Z	dS )ÚNA_LabelrÝ   zText to be used for N/A valuesr>   )r×   rQ   c                 C   s   t  | ¡ d| _d S )Nzn/a)rÜ   ri   rQ   r}   rg   rg   rh   ri   Ò  s    
zNA_Label.__init__N)
r­   r®   r¯   r°   r±   rÜ   r²   r   r³   ri   rg   rg   rg   rh   rä   Ê  s   
þrä   )ÚCustomDrawChangerc                   @   s"   e Zd Zejfdd„Zdd„ ZdS )ÚRedNegativeChangerc                 C   s   t  | ¡ || _d S rº   )rå   ri   rN   )re   rN   rg   rg   rh   ri   Ù  s    
zRedNegativeChanger.__init__c                 C   s&   i }|j  d¡r"|j|d< | j|_|S )Nú-rN   )rd   Ú
startswithrN   )re   r¢   ÚRrg   rg   rh   Ú_changerÜ  s
    
zRedNegativeChanger._changerN)r­   r®   r¯   r   Zredri   rê   rg   rg   rg   rh   ræ   Ø  s   ræ   c                   @   s"   e Zd ZdZeed�Zdd„ ZdS )ÚXLabelz=like label but uses XPreFormatted/Paragraph to draw the _textrÖ   c                 O   s:   t j| g|¢R i |¤Ž | dt¡| _| d| j¡| _d S )Nra   ZdirectDrawClass)r<   ri   Úpopr   ra   r`   )re   ÚargsrÛ   rg   rg   rh   ri   ç  s    zXLabel.__init__N)
r­   r®   r¯   r°   r±   r<   r³   ri   r¤   r«   rg   rg   rg   rh   rë   ã  s   
/rë   )CÚ__version__Zreportlab.libr   Zreportlab.lib.utilsr   Zreportlab.lib.validatorsr   r   r   r   r   r	   r
   r   r   r   r   r   r   Zreportlab.lib.attrmapZreportlab.pdfbase.pdfmetricsr   r   Zreportlab.graphics.shapesr   r   r   r   r   r   Zreportlab.graphics.widgetbaser   r   r   Zreportlab.platypusr   r   Zreportlab.lib.stylesr   r    Zreportlab.lib.enumsr!   r"   r#   r•   rŸ   Úutilsr(   r©   ru   Zrlextra.graphics.canvasadapterr:   ÚImportErrorr¥   r<   r´   rÔ   rÈ   rã   rÕ   rÜ   rä   ZNoneOrInstanceOfNA_LabelZreportlab.graphics.charts.utilsrå   ræ   rë   rg   rg   rg   rh   Ú<module>   sF   < þ
  0*&