U
    '1e[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 e4k
rV   dZ3Y nX 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 )?LabelzA 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   sb   | j f | | 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   H/tmp/pip-unpacked-wheel-109iniqw/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 )zSet 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   iz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k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kr\| j | _
n$|dkrt| j| j | _
nd| j | _
| j
| j | _|dkr| j| j | _n |dk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                    sp  t  dd }|sg  _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 krtdtd j j j jd} js
tf |}n\t jtr( jjf |}n>t jtrRt jtrR jf |}nt dt j | _!    jrd	|_" j j |_n jr jn jd |_|j _ # } jpd
}|dkrt$|_%| j|d}|&|d
\}} jp|j'}t(| |_%| j|d  _)}|&|d
\}} jsZ 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>   s     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   sB   t | dd }|r6|d|  z|  W S |d|  X 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 k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  s4   










 







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| 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 )BarChartLabelF
    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   s0   t j| f| 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   s4   t j| f|| |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*&