U
    '1ei                    @   s  d Z d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mZmZ ddlT ddlmZ ddlmZmZmZmZmZmZmZm Z  ddl!m"Z"m#Z# dd	l$m%Z%m&Z&m'Z'm(Z( dd
l)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 dcddZ1ddddZ2deddZ3dd Z4G dd dZ5G dd dZ6G dd dZ7G dd dZ8G dd  d e"Z9G d!d" d"e&Z:G d#d$ d$e9Z;d%d& Z<d'd( Z=G d)d* d*Z>G d+d, d,e>Z?G d-d. d.e>e;Z@G d/d0 d0e?e;ZAG d1d2 d2ZBd3d4 ZCG d5d6 d6e9ZDG d7d8 d8e>eDZEd9d:d;d<d=d>d?d@dAdBdCdDgZFdEdFdEdGdEdGdEdEdGdEdGdEgZGdHdI ZHG dJdK dKeZIeI ZJdLZKG dMdN dNeEZLG dOdP dPe?eDZMG dQdR dRZNG dSdT dTeNeEZOG dUdV dVeMZPG dWdX dXeDZQG dYdZ dZeBZRG d[d\ d\eBZSG d]d^ d^ZTG d_d` d`eQeTeEZUG dadb dbeQeTeMZVdS )fz3.3.0a  Collection of axes for charts.

The current collection comprises axes for charts using cartesian
coordinate systems. All axes might have tick marks and labels.
There are two dichotomies for axes: one of X and Y flavours and
another of category and value flavours.

Category axes have an ordering but no metric. They are divided
into a number of equal-sized buckets. Their tick marks or labels,
if available, go BETWEEN the buckets, and the labels are placed
below to/left of the X/Y-axis, respectively.

  Value axes have an ordering AND metric. They correspond to a nu-
  meric quantity. Value axis have a real number quantity associated
  with it. The chart tells it where to go.
  The most basic axis divides the number line into equal spaces
  and has tickmarks and labels associated with each; later we
  will add variants where you can specify the sampling
  interval.

The charts using axis tell them where the labels should be placed.

Axes of complementary X/Y flavours can be connected to each other
in various ways, i.e. with a specific reference point, like an
x/value axis to a y/value (or category) axis. In this case the
connection can be either at the top or bottom of the former or
at any absolute value (specified in points) or at some value of
the former axes in its own coordinate system.
    )log10)isNumberisNumberOrNoneisListOfStringsOrNoneisListOfNumbersisListOfNumbersOrNoneisColorOrNoneOneOf	isBoolean
SequenceOfisStringEitherOr	ValidatorNoneOrisNormalDateisNoneOrCallable)*)
normalDate)DrawingLinePolyLineRectGroupSTATE_DEFAULTS_textBoxLimits_rotatedBoxLimits)WidgetTypedPropertyCollection)LabelPMVLabelXLabelDirectDrawFlowable)nextRoundNumber)
ShadedRect)Color)isSeqNc                 C   s   t | d d rH|r&|||fdd}n|fdd}tt|fdd| } tttdd | D } t| dkrp|S |tt|| }|r||||S |S )Nr   c                 S   s   || ||S N )Txspecialfuncr'   r'   B/tmp/pip-unpacked-wheel-109iniqw/reportlab/graphics/charts/axes.py<lambda>5       z"_findMinMaxValue.<locals>.<lambda>c                 S   s   | | S r&   r'   )r(   r)   r'   r'   r,   r-   7   r.   c                 S   s   t t|| S r&   )listmap)efr'   r'   r,   r-   8   r.   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|d k	r|qS r&   r'   .0r)   r'   r'   r,   
<listcomp>9   s      z/_findMinMaxValue.<locals>.<listcomp>.<listcomp>r'   r3   r'   r'   r,   r5   9   s     z$_findMinMaxValue.<locals>.<listcomp>)r%   r/   r0   filterlen)Vr)   defaultr+   r*   extraMinMaxValuesr2   rr'   r'   r,   _findMinMaxValue2   s     r<   c                 C   s   t | ||t||dS )zfind minimum over V[i][x]r*   r:   )r<   minr8   r)   r9   r*   r:   r'   r'   r,   _findMin>   s    r@   c                 C   s   t | ||t||dS )zfind maximum over V[i][x]r=   )r<   maxr?   r'   r'   r,   _findMaxB   s    rB   c                 C   s8   | D ].}zt ||krW  dS W q   Y  dS X qdS )ztrue if all values are intr      int)valuesvr'   r'   r,   _allIntF   s     rH   c                   @   s    e Zd ZdZdd Zdd ZdS )AxisLabelAnnotationaK  Create a grid like line using the given user value to draw the line
    v       value to use
    kwds may contain
    scaleValue  True/not given --> scale the value
                otherwise use the absolute value
    labelClass  the label class to use default Label
    all Label keywords are acceptable (including say _text)
    c                 K   s   || _ || _d S r&   _v_kwdsselfrG   kwdsr'   r'   r,   __init__X   s    zAxisLabelAnnotation.__init__c                 C   s   | j  }|dt}|dd}t|ds4|  |r>|jndd | j}|jr^|j	}|}n
|}|j
}||d< ||d< |f |S )	N
labelClass
scaleValueT_tickValuesc                 S   s   | S r&   r'   r)   r'   r'   r,   r-   b   r.   z.AxisLabelAnnotation.__call__.<locals>.<lambda>r)   y)rL   copypopr   hasattr_pseudo_configurescalerK   isYAxis_x_y)rN   axisrO   rQ   rR   svr)   rU   r'   r'   r,   __call__\   s    

zAxisLabelAnnotation.__call__N__name__
__module____qualname____doc__rP   r`   r'   r'   r'   r,   rI   O   s   rI   c                   @   s    e Zd ZdZdd Zdd ZdS )AxisLineAnnotationa  Create a grid like line using the given user value to draw the line
    kwds may contain
    startOffset if true v is offset from the default grid start position
    endOffset   if true v is offset from the default grid end position
    scaleValue  True/not given --> scale the value
                otherwise use the absolute value
    lo          lowest coordinate to draw default 0
    hi          highest coordinate to draw at default = length
    drawAtLimit True draw line at appropriate limit if its coordinate exceeds the lo, hi range
                False ignore if it's outside the range
    all Line keywords are acceptable
    c                 K   s   || _ || _d S r&   rJ   rM   r'   r'   r,   rP   z   s    zAxisLineAnnotation.__init__c                    s  | j  }|dd}|dd}|dd}|jrB|j}|j}n|j}|j}|dd }|dd }	|d ksv|	d krtt|dd d	d }
|
rt|
d
r|
 }
|
r|d kr|
d }|	d kr|
d }	n|d krd}|	d krd}	|d|j| }|dd| }t	||t
|| }}|dd}|j}|s6dd |_z| j}|rN|| }n|r\|| }||| |	| |dd }t|ds|  ||  |k s |kr|sW Rd S  |k r| n|  fdd|_||}| D ]\}}t||| qW 5 ||_X |S )NrR   T	endOffsetFstartOffsetstartendjoinAxisgetGridDimsr`   r   rC   hilodrawAtLimitc                 S   s   | S r&   r'   rT   r'   r'   r,   r-      r.   z-AxisLineAnnotation.__call__.<locals>.<lambda>parentrS   c                    s    S r&   r'   rT   dr'   r,   r-      r.   )rL   rV   rW   r[   r\   r]   getattrrX   _lengthr>   rA   _get_line_posrK   _getLineFuncrY   itemssetattr)rN   r^   rO   rR   rg   rh   offsd0sr1   dimrm   rn   ro   ZoaglprG   r+   Lkr'   rq   r,   r`   ~   sj    
  
  


 
zAxisLineAnnotation.__call__Nra   r'   r'   r'   r,   rf   m   s   rf   c                   @   s    e Zd ZdZdd Zdd ZdS )AxisBackgroundAnnotationa  Create a set of coloured bars on the background of a chart using axis ticks as the bar borders
    colors is a set of colors to use for the background bars. A colour of None is just a skip.
    Special effects if you pass a rect or Shaded rect instead.
    c                 K   s   || _ || _d S r&   )_colorsrL   )rN   colorsrO   r'   r'   r,   rP      s    z!AxisBackgroundAnnotation.__init__c              	   C   s@  | j }|sd S | j }|j}|r0|j}|j}n|j}|j}|dd }|dd }|d ksd|d krtt|dd dd }	|	rt|	dr|	 }	|	r|d kr|	d }|d kr|	d }n|d krd}|d krd}t|ds|	  t|dd }
|
sd S t
 }t|}||
d }tdt|
D ]}||
| }||d |  }|r4|rd|}|}|| }|| }n|}|}|| }|| }t|trt|||||d d	}nt|trt||||}|jD ]"}|d
krt||t|| qnFt|tr*t||||d
}|jD ]"}|d
krt||t|| q|| |}q|S )Nri   rj   rk   rl   r`   r   rC   rS   )Z	fillColorstrokeColor)r)   rU   widthheight)r   rL   rV   r[   r\   r]   rW   rs   rX   rY   r   r7   ru   range
isinstancer$   r   __dict__rx   r#   add)rN   r^   r   rO   r[   ry   rz   r{   r1   r|   tvGZncolorsZv0iZv1crU   r)   r   r   r;   r~   r'   r'   r,   r`      sz     
  
  
 





z!AxisBackgroundAnnotation.__call__Nra   r'   r'   r'   r,   r      s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TickLUz$lookup special cases for tick valuesc                 O   s   | dd| _|| _d S )Naccuracy:0yE>)rW   r   r(   )rN   r(   rO   r'   r'   r,   rP      s    zTickLU.__init__c                 C   s0   | j }| jD ]\}}t|| |k r dS qdS NTF)r   r(   absrN   tr   r)   rG   r'   r'   r,   __contains__   s
    zTickLU.__contains__c                 C   s@   | j }| jD ]"\}}t|| | j k r|  S qtd| d S )Nzcannot locate index %r)r   r(   r   
IndexErrorr   r'   r'   r,   __getitem__  s
    
zTickLU.__getitem__N)rb   rc   rd   re   rP   r   r   r'   r'   r'   r,   r      s   r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zd ddZdg i fddZ	ddg fddZ
ddg fddZd!ddZdd ZeeZdd ZeeZd"ddZdd Zdd ZdS )#_AxisGc                 C   s(   |  |}z|d }W n   Y nX |S Nr   )rZ   )rN   rG   r'   r'   r,   ru     s    
z_AxisG._get_line_posc                 C   s$   |  |}t|| j| || j| S r&   )ru   r   r]   )rN   r)   ri   rj   r'   r'   r,   _cxLine  s    
z_AxisG._cxLinec                 C   s$   |  |}t| j| || j| |S r&   )ru   r   r\   )rN   rU   ri   rj   r'   r'   r,   _cyLine  s    
z_AxisG._cyLinec           	      C   s\   |  |}| j| }| j| }t||t|| }}|| }t||||| ||| gddS NrC   )strokeLineJoin)ru   r]   r>   rA   r   )	rN   r)   ri   rj   _3d_dx_3d_dyy0y1x1r'   r'   r,   	_cxLine3d  s    


z_AxisG._cxLine3dc           	      C   s\   |  |}| j| }| j| }t||t|| }}|| }t|||| ||| |gddS r   )ru   r\   r>   rA   r   )	rN   rU   ri   rj   r   r   x0r   r   r'   r'   r,   	_cyLine3d$  s    


z_AxisG._cyLine3dNc                 C   sl   t |dd }|d k	rFt |dd }| jr,| jp0| j}|||||fddS | jrR| jpV| j}|||fddS d S )Nr   r   c                 S   s   || ||||dS )N)r   r   r'   )rG   r{   r1   r2   r   r   r'   r'   r,   r-   1  r.   z%_AxisG._getLineFunc.<locals>.<lambda>c                 S   s   || ||S r&   r'   )rG   r{   r1   r2   r'   r'   r,   r-   4  r.   )rs   r[   r   r   r   r   )rN   ri   rj   rp   r   r   r2   r'   r'   r,   rv   ,  s    z_AxisG._getLineFuncc                    s   |  |||
}t| ds |    rD| jr6 fddp@ fdd}nd }| jD ]r}||}|rh||rhqN||_||_||_||_||_	|	|_
||kr||  D ]\}}t||| q|| qNd S )NrS   c                    s
   | j  kS r&   )r   lexcluder'   r,   r-   ;  r.   z#_AxisG._makeLines.<locals>.<lambda>c                    s
   | j  kS r&   )r   r   r   r'   r,   r-   ;  r.   )rv   rX   rY   r[   rS   r   strokeWidthstrokeDashArrayr   strokeLineCapstrokeMiterLimitrw   rx   r   )rN   gri   rj   r   r   r   r   r   r   rp   r   specialsr+   Zexfr   r}   arG   r'   r   r,   
_makeLines6  s(    
 
 z_AxisG._makeLinesc           
      C   s   | j }| jpd}|r|r| jr| j}| j}|dks:|dkr|rNt|drN| }|rt|dkrb|d }|dkr|d }n|dkrd}|dkrd}|s|r| jr| j}	n| j}	| j	|||	 ||	 ||| j
| j| j| j||t| di d | j|||g d dS ))this is only called by a container objectr   Nr`   rC   Z_gridSpecials)rp   r   r   r   )gridStrokeColorgridStrokeWidthvisibleGrid	gridStartgridEndrX   r[   r\   r]   r   gridStrokeDashArraygridStrokeLineJoingridStrokeLineCapgridStrokeMiterLimitrs   _makeSubGrid)
rN   r   r|   rp   r   r   wr{   r1   ry   r'   r'   r,   makeGridL  s.    
  
   :z_AxisG.makeGridc                 C   s  t | ddr| jdksdS | j}| jp(d}|r2|s6dS | j}| j}|dksR|dkr|rft|drf| }|r|dkrz|d }|dkr|d }n|dkrd}|dkrd}|s|r| jr| j}	n| j	}	| 
 }
z4| j|||	 ||	 ||| j| j| j| j||d W 5 |
| _X dS )r   visibleSubGridr   Nr`   rC   )rp   r   )rs   
subTickNumsubGridStrokeColorsubGridStrokeWidthsubGridStart
subGridEndrX   r[   r\   r]   _calcSubTicksrS   r   subGridStrokeDashArraysubGridStrokeLineJoinsubGridStrokeLineCapsubGridStrokeMiterLimit)rN   r   r|   rp   r   r   r   r{   r1   ry   otvr'   r'   r,   r   b  s8     
   
  
 4z_AxisG._makeSubGridc                 C   s4   |d kr| j | jf| j }|d kr,|| j }||fS r&   )r\   r]   r[   rt   )rN   ri   rj   r'   r'   r,   rl   |  s
      
z_AxisG.getGridDimsc                 C   s8   t | dd dkrdS | jj}|d dkp6|d d dkS )N
_dataIndexrC   Tr   Y   ZAdjYrs   	__class__rb   rN   acnr'   r'   r,   r[     s     z_AxisG.isYAxisc                 C   s8   t | dd dkrdS | jj}|d dkp6|d d dkS )Nr   r   TX   NormalDateXr   r   r'   r'   r,   isXAxis  s     z_AxisG.isXAxisc                 C   s0   |d krt | dg  |D ]}|||  qd S )Nannotations)rs   r   )rN   r   Ar)   r'   r'   r,   addAnnotations  s     z_AxisG.addAnnotationsc                 C   s   t | dg d d  }i }dD ]P}g j}g j}|D ]"}t ||drJ|| q0|| q0|j||< |j|d d < q|d  |7  < |S )Nr   )early
beforeAxis	afterAxisbeforeTicks
afterTicksbeforeTickLabelsafterTickLabelslater   r   )rs   append__self__)rN   r   DrG   RPr   r'   r'   r,   _splitAnnotations  s    


z_AxisG._splitAnnotationsc                 C   s   t  }|  }| ||d  | jr| ||d  ||   | ||d  | ||d  ||   | ||d  | ||d  ||   | ||d  | ||d  |S )	Nr   r   r   r   r   r   r   r   )r   r   r   visibler   makeAxis	makeTicksmakeTickLabels)rN   r   r   r'   r'   r,   draw  s    z_AxisG.draw)N)NN)N)rb   rc   rd   ru   r   r   r   r   rv   r   r   r   rl   r[   propertyr   r   r   r   r'   r'   r'   r,   r     s"   



r   c                   @   s(   e Zd ZeeeedddZdd ZdS )CALabelz?where in the category range [0,1] the labels should be anchoreddesc)BASElabelPosFracc                 K   s   t j| f| | jdd d S )N      ?)r   )r   rP   _setKeywordsrN   kwr'   r'   r,   rP     s    zCALabel.__init__N)	rb   rc   rd   AttrMapr   AttrMapValuer   _attrMaprP   r'   r'   r'   r,   r     s   
r   c                *   @   s   e Zd 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dddee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dddeedddddeeddeeddeeddeeddedddeeddedddeeddeeddeed d!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dd.deed/deed0deed1d2d3d4d5eed6dd7%Zd8d9 Zd:d; ZdFd<d=Zd>d? Zd@dA ZdBdC ZdDdE ZdS )GCategoryAxisz+Abstract category axis, unusable in itself.rC   Display entire object, if true.r   Display axis line, if true.Display axis ticks, if true.Display axis labels, if true.Display axis grid, if true.Width of axis line and ticks.Color of axis line and ticks.Dash array used for axis line.r      #Line cap 0=butt, 1=round & 2=square$Line join 0=miter, 1=round & 2=bevel$miter limit control miter line joinsWidth of grid lines.Color of grid lines.Dash array used for grid lines.(Grid Line cap 0=butt, 1=round & 2=square)Grid Line join 0=miter, 1=round & 2=bevel)Grid miter limit control miter line joins#Start of grid lines wrt axis origin!End of grid lines wrt axis origin-if true draw gridlines after everything else.NHandle of the axis labels.zList of category names.Join both axes if true.*Position at which to join with other axis.#If true reverse category direction.parallelstackedparallel_3dz$How common category bars are plottedhighlowr^   axispmv*Like joinAxisMode, but for the axis labelszTick shift typicallyWidth of ticks if specified.Color of ticks if specified.z*extra inner space before start of the axisz'extra inner space after end of the axislist of annotations*extra line length before start of the axis'extra line length after end of the axisnonetopbothbottom'grid lines to skip top bottom both none#Callable to replace _drawInnerTicks)%r   visibleAxisvisibleTicksvisibleLabelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   drawGridLastlabelscategoryNamesrk   joinAxisPosreverseDirectionstylelabelAxisMode	tickShifttickStrokeWidthtickStrokeColorloPadhiPadr   loLLenhiLLenskipGridinnerTickDrawc                 C   s:  | j jdkstdd| _d| _d| _d| _d| _d| _d| _	d| _
d| _d| _d| _td | _td	 | _td
  | _| _td  | _| _td  | _| _d| _td | _td	 | _d  | _| _td
 | _td | _td | _tt| _d | _d | _ d | _!d | _"d| _#d| _$d| _%d | _&d| _'d| _(d| _)d| _*d| _+d S )Nr   z(Abstract Class CategoryAxis Instantiated2   d   r   rC   Fr   r   r   r   r         ?r^   r  ),r   rb   AssertionErrorr\   r]   rt   	_catCountr   r$  r%  r&  r   r'  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(  r)  rk   r*  joinAxisModer-  r+  r,  _labelTextFormatr.  r1  r2  r3  r4  rN   r'   r'   r,   rP     sL    







zCategoryAxis.__init__c                 C   s"   t || _t || _t || _d S r&   floatr\   r]   rt   rN   r)   rU   lengthr'   r'   r,   setPosition#  s    

zCategoryAxis.setPositionc                    sj   t ttt | _|p6| j| j | j t| jp2d | _	| 
  | jdkrf fddt| jD | _d S )NrC   r  c                    s"   g | ] t  fd dD qS )c                    s   g | ]}|  qS r'   r'   )r4   Zseriesr   r'   r,   r5   .  s     z5CategoryAxis.configure.<locals>.<listcomp>.<listcomp>)sum)r4   multiSeriesrD  r,   r5   .  s     z*CategoryAxis.configure.<locals>.<listcomp>)rA   r/   r0   r7   r;  rt   r1  r2  r@  	_barWidth_calcTickmarkPositionsr-  r   _pmv)rN   rG  barWidthr'   rF  r,   	configure)  s
    &
zCategoryAxis.configurec                 C   sP   | j }| jr"dd t|D | _n*| jr:ttd|| _ntt|d | _d S )Nc                 S   s   g | ]}|d  qS )r   r'   )r4   r   r'   r'   r,   r5   3  s     z7CategoryAxis._calcTickmarkPositions.<locals>.<listcomp>rC   )r;  r.  r   rS   r+  r/   )rN   nr'   r'   r,   rI  0  s    z#CategoryAxis._calcTickmarkPositionsc                 C   s   | j r| j| d }|S NrC   )r+  r;  rN   idxr'   r'   r,   _scale:  s     zCategoryAxis._scalec                 C   s   |  || jfS )z/Returns the position and width in drawing unitsloScalerH  rP  r'   r'   r,   rZ   >  s    zCategoryAxis.scalec                 C   s   |  |d| j  S )z-Returns the bar mid position in drawing unitsr   rS  rP  r'   r'   r,   midScaleB  s    zCategoryAxis.midScale)N)rb   rc   rd   re   Z_nodocr   r   r
   r   r   r   r	   r   r   r   r   rP   rC  rL  rI  rR  rZ   rU  r'   r'   r'   r,   r     s`   





























(6

r   c                 C   s   | j std| jj d S )Nz/Cannot connect to other axes (%s), but Y- ones.)r[   r:  r   rb   r^   r'   r'   r,   _assertYAxisF  s    rW  c                 C   s   | j std| jj d S )Nz/Cannot connect to other axes (%s), but X- ones.)r   r:  r   rb   rV  r'   r'   r,   _assertXAxisH  s    rX  c                   @   sT   e Zd ZdZedd Zedd Zdd Zdd	d
Zdd Z	dd Z
dddZdS )_XTicksr   c                 C   s   t | d| jS )Nr/  )rs   r   r>  r'   r'   r,   actualTickStrokeWidthN  s    z_XTicks.actualTickStrokeWidthc                 C   s   t | d| jS )Nr0  )rs   r   r>  r'   r'   r,   actualTickStrokeColorR  s    z_XTicks.actualTickStrokeColorc                 C   s   t | dd }|r || ||| n`|s(|r| j}| j}|rZ|rJ|sJ|| }n|rZ|sZ|| }| ||| | j|| j| j| j| j	 d S )Nr6  )	rs   rZ  _tickTweaksr   r[  r   r   r   r   )rN   tUtDr   ZitdZsWZtWr'   r'   r,   _drawTicksInnerV  s    
z_XTicks._drawTicksInnerNc                 C   s"   |pt  }| jr| ||| |S r&   )r   r%  r_  )rN   r]  r^  r   r'   r'   r,   
_drawTicksd  s    
z_XTicks._drawTicksc                 C   sH   t | ddrD| jdkrD|  }zd| _| ||| W 5 | `|| _X d S )NvisibleSubTicksr   rC   )rs   r   r   Z_subTickingrS   r_  )rN   r]  r^  r   r   r'   r'   r,   _drawSubTicksj  s    z_XTicks._drawSubTicksc                 C   s^   | j }zJ| t| dd| _ | | j| j}| t| ddt| dd| |W S || _ X d S NtickAxisModer^   	subTickHir   	subTickLo)r]   _labelAxisPosrs   r`  tickUptickDownrb  )rN   Zyoldr   r'   r'   r,   r   t  s    z_XTicks.makeTicksc                 C   s<   | j }|r6|p| j}|dkr"|jS |dkr6|j|j S | jS Nr  r  )rk   r-  r]   rt   rN   moder^   r'   r'   r,   rg  ~  s    
z_XTicks._labelAxisPos)N)N)rb   rc   rd   r\  r   rZ  r[  r_  r`  rb  r   rg  r'   r'   r'   r,   rY  K  s   




rY  c                   @   s   e Zd ZdddZdd ZdS )_YTicksNc                 C   s<   | j }|r6|p| j}|dkr"|jS |dkr6|j|j S | jS rj  )rk   r-  r\   rt   rk  r'   r'   r,   rg    s    
z_YTicks._labelAxisPosc                 C   s^   | j }zJ| t| dd| _ | | j| j}| t| ddt| dd| |W S || _ X d S rc  )r\   rg  rs   r`  	tickRighttickLeftrb  )rN   Zxoldr   r'   r'   r,   r     s    z_YTicks.makeTicks)N)rb   rc   rd   rg  r   r'   r'   r'   r,   rm    s   

rm  c                   @   s   e Zd ZdZeeeeddeeddeeddddd	d
ddZ	dZ
dd Zdd ZdddZdd Zdd Zdd Zdd Zd	S )XCategoryAxiszX/category axisTick length up the axis.r   Tick length down the axis.r!  r  valuepointsNIMode used for connecting axis ('bottom', 'top', 'value', 'points', None).)r   rh  ri  r<  r   c                 C   s*   t |  d| j_d| j_d| _d| _d S )NrN  r      )r   rP   r(  	boxAnchordyrh  ri  r>  r'   r'   r,   rP     s
    
zXCategoryAxis.__init__c                 C   sb   |  ddd | dg ddddd	g| _d
| j_d| jd _d| jd _tdd}||  |S )N   F      
      rz  (   r7  OneTwoThreeZFourZFiverN  r1   r   Z      r8  rC  rL  r)  r(  rx  angler   r   rN   rr   r'   r'   r,   demo  s    

zXCategoryAxis.democ                 C   sZ   t | |dkr|j| _n<|dkr2|j|j | _n$|dkrH||| _n|dkrV|| _dS )!Join with y-axis using some mode.r!  r  rs  rt  NrW  r]   rt   rZ   rN   ZyAxisrl  posr'   r'   r,   
joinToAxis  s    
zXCategoryAxis.joinToAxisc                 C   sF   | j }|rB| j}|dkr(| j||d n|dkrB| j||| jd d S )Nr!  r  rl  rs  rt  rl  r  rk   r<  r  r*  rN   jaZjamr'   r'   r,   _joinToAxis  s    zXCategoryAxis._joinToAxisc                 C   s   | j | j | || j  S )z'returns the x position in drawing units)r\   r1  rR  rH  rP  r'   r'   r,   rT    s    zXCategoryAxis.loScalec                 C   sf   t  }|   | js|S t| j| j | j| j| j | j | j}| j	|_	| j
|_
| j|_|| |S r&   r   r  r$  r   r\   r3  r]   rt   r4  r   r   r   r   rN   r   r^   r'   r'   r,   r     s     (
zXCategoryAxis.makeAxisc                 C   s(  t  }| js|S | j}|d k	r$| j}t|}| j}| j}|  }| j}| j	dkrX| j
nd }	t|D ]}
|rz||
 d }n|
}||krqd|
| }|| jkr| j| }n
| j|
 }|	r|j}|	|  }|_
|dk r|d9 }nd}|j}||
| |  }||||  ||| pd || qd|S Nr  rC   r    )r   r&  r)  r;  r7   r+  rH  rg  r\   r-  rJ  r   r(  ry  r   	setOriginsetTextr   )rN   r   r)  catCountrN  r+  rK  r]   r\   pmvr   iclabelZ_dyrG   lpfr)   r'   r'   r,   r     sD     
  

 
zXCategoryAxis.makeTickLabels)r!  Nrb   rc   rd   re   r   r   r   r   r	   r   r   rP   r  r  r  rT  r   r   r'   r'   r'   r,   rp    s(   		
	rp  c                   @   sz   e Zd ZdZeeeeddeeddeeddddZ	dZ
d	d
 Zdd ZdddZdd Zdd Zdd Zdd ZdS )YCategoryAxiszY/category axisTick length left of the axis.r   Tick length right of the axis.leftrightrs  rt  NIMode used for connecting axis ('left', 'right', 'value', 'points', None).)r   ro  rn  r<  rC   c                 C   s*   t |  d| j_d| j_d| _d| _d S )Nr1   rv  rw  r   )r   rP   r(  rx  dxro  rn  r>  r'   r'   r,   rP     s
    
zYCategoryAxis.__init__c                 C   s^   |  ddd | dg dddg| _d| j_d	| jd
 _d| jd
 _tdd}||  |S )Nr7  r~  P   )r~  r  rz  r  r  r  r1   r{   r  r  r  r8  r  r  r'   r'   r,   r  &  s    

zYCategoryAxis.demor  Nc                 C   sj   t | |dkr|jd | _nH|dkr:|j|j d | _n,|dkrT||d | _n|dkrf|d | _dS z!Join with x-axis using some mode.r        ?r  rs  rt  NrX  r\   rt   rZ   rN   ZxAxisrl  r  r'   r'   r,   r  3  s    zYCategoryAxis.joinToAxisc                 C   sF   | j }|rB| j}|dkr(| j||d n|dkrB| j||| jd d S N)r  r  r  r  r  r  r  r'   r'   r,   r  @  s    zYCategoryAxis._joinToAxisc                 C   s   | j | || j  S )z'Returns the y position in drawing units)r]   rR  rH  rP  r'   r'   r,   rT  I  s    zYCategoryAxis.loScalec                 C   sf   t  }|   | js|S t| j| j| j | j| j| j | j }| j	|_	| j
|_
| j|_|| |S r&   r   r  r$  r   r\   r]   r3  rt   r4  r   r   r   r   r  r'   r'   r,   r   M  s     (
zYCategoryAxis.makeAxisc                 C   s.  t  }| js|S | j}|d k	r*| j}t|}| j}| j}| j}|  }| j	}	| j
dkr^| jnd }
t|D ]}|r|| d }n|}||krqj|| }|| jkr| j| }n
| j| }|j}|	|| |  }|
r|j}|
|  }|_|dk r|d9 }nd}||| | ||| pd || qj|S r  )r   r&  r)  r;  r7   r+  rH  r(  rg  r]   r-  rJ  r   r   r  r  r  r   )rN   r   r)  r  rN  r+  rK  r(  r\   r]   r  r   r  r  r  rU   Z_dxrG   r'   r'   r,   r   Z  sF     
  

 
zYCategoryAxis.makeTickLabels)r  Nr  r'   r'   r'   r,   r    s(   		
	r  c                   @   s   e Zd ZdZdd ZdS )TickLabellerztAbstract base class which may be used to indicate a change
    in the call signature for callable label formats
    c                 C   s   dS )NzAbstract class instance calledr'   )rN   r^   rs  r'   r'   r,   r`     s    zTickLabeller.__call__Nrb   rc   rd   re   r`   r'   r'   r'   r,   r    s   r  c                 C   s   d|  S )Nz%.12gr'   rT   r'   r'   r,   r-     r.   r-   c                I   @   s  e Zd ZdZeeeeedf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ee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dddee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dddeed d!d"d#dedd$de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eee	dddd+fd,deeeee	dddd+fd-deeeeeedddd+fd.deed/d0d1d2d3eed4deed5d6d7d8eed/d9d:d0d;deed<deed=deed>deed d!d"d?deed@deddAdee	dBdee	dCdee	dDdee	dEdee	dFdeedGdeedHdee	ddee
ddeeddeedddddeedddddee	ddeeddeeddee	dIdee	dJdee
dKdee
dLdeedMdeed/dNd0dOdPeedQdeedRdeedSddTEZdUdV ZdWdX ZdYdZ Zd[d\ Zi fd]d^Zd_d` Zdadb Zdcdd Zdedf Zdgdh Zdidj Zdkdl Zdmdn Zdodp Zdqdr Zdsdt Z dudv Z!dwdx Z"dydz Z#dS ){	ValueAxisz(Abstract value axis, unusable in itself.nearzEnsure zero in range if true.r   r   r   r   r   r   r   r   r   r   rC   r  r  r  r  r  r  r  r  r	  r
  r  r  r  z)Minimum value for distance between ticks.zMaximum number of ticks.Nr  r  r  r^   r  z3Formatting string or function used for axis labels.zExtra Formatting string.zScaling for label tick values.zMinimum value on axis.zMaximum value on axis.zStep size used between ticks.z&List of step sizes used between ticks.ZemptyOKrn   rm   z.Fraction of interval to allow above and below.zSpace to allow above and below.zMSet to True to make the avoidBoundFrac calculations treat zero as non-specialr  r   ceilingfloorzHow to round the axis limitsz!Zero range axis limit preference.normalr  r  zHow values are plotted!ri   rj   zSkip high/low tick labels"Lowest label shift interval ratio.Minimum amount to shift.zspecial value for shiftz$Like joinAxisMode, but for the ticksr  r  r  r  zNumber of axis sub ticks, if >0zsub tick down or leftzsub tick up or rightz Display axis sub ticks, if true.zDisplay axis sub grid, if true.r  z Width of sub ticks if specified.z Color of sub ticks if specified.r  z?Ensure tick labels do not project beyond bounds of axis if truer  r!  r"  zMinimum required value range.r#  z*extra values to use in min max calculation)E	forceZeror   r$  r&  r%  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'  minimumTickSpacingmaximumTicksr(  r-  labelTextFormatlabelTextPostFormatlabelTextScalevalueMinvalueMax	valueStep
valueStepsavoidBoundFracavoidBoundSpaceabf_ignore_zero
rangeRound
zrangePrefr,  skipEndLorigShiftIPCorigShiftMinorigShiftSpecialValuerd  r+  r   r3  r4  r   rf  re  ra  r   r   r   r   r   r   r   r   r   r/  ZsubTickStrokeWidthZsubTickStrokeColorr0  keepTickLabelsInsider5  requiredRanger6  r:   c              D   K   s   | j jdkstd| jf | | jdddddddddddtd td td	 td
 td dtd td td	 td
 td d d ddddddtd	 td
 td dtd td d d ttdddd dd d d d d d d d dddddd d d dddddd dB d| j_d S )Nr  z%Abstract Class ValueAxis Instantiatedr   r7  r8  rC   r   r   r   r   r   r9  Fr~     r^   r  r  )B_configuredr\   r]   rt   r   r$  r&  r%  r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'  r   ra  r   rf  re  r   r   r   r   r   r   r   r   r(  r  r  r  r=  r-  r  r  r  r  r  r  r  r  r  r  r  r,  r  r  r  r  rd  r+  r3  r4  r  r:   )	r   rb   r:  r   r   r   r   r(  r  r   r'   r'   r,   rP     s    SzValueAxis.__init__c                 C   s"   t || _t || _t || _d S r&   r?  rA  r'   r'   r,   rC  .  s    

zValueAxis.setPositionc                 C   s   |  | |   dS )a=  Let the axis configure its scale and range based on the data.

        Called after setPosition. Let it look at a list of lists of
        numbers determine the tick mark intervals.  If valueMin,
        valueMax and valueStep are configured then it
        will use them; if any of them are set to None it
        will look at the data and make some sensible decision.
        You may override this to build custom axes with
        irregular intervals.  It creates an internal
        variable self._values, which is a list of numbers
        to use in plotting.
        N)	_setRange_configure_end)rN   
dataSeriesr'   r'   r,   rL  4  s    
zValueAxis.configurec                 C   s   |    |   d| _d S rO  )rI  _calcScaleFactorr  r>  r'   r'   r,   r  D  s    zValueAxis._configure_endc                 C   sT   z||f}|| }W n:   || _ || _|  \}}|||d f }||< Y nX |S )Nr   )	_valueMin	_valueMax_calcStepAndTickPositions)rN   r  r  cacheKr;   r  r(   r'   r'   r,   _getValueStepAndTicksI  s    zValueAxis._getValueStepAndTicksc                 C   s   | j }|dkr|| }||k rd||  }|d9 }t|| |}t|| |}|dkrp|dk rp|d | }d}n|dkr|dk r|| }d}| }| _| }| _||fS )Nr   r   r8  )r  r>   rA   
_cValueMin
_cValueMax)rN   r  r  rrr;   mr   y2r'   r'   r,   _preRangeAdjustT  s"    

zValueAxis._preRangeAdjustc           '      C   sX  | j  }}| j }}|dkr4t|| jd| j }| _|dkrTt|| jd| j }| _||kr|dkr|dkr|dkrt| dd}|dkr|}d}q|dk rd}|}qd}d}q| j dkrd}qd}n"|dkrd| }d}nd}d| }t| ddrt	t|d	d}d
}|||  }	|	| _
|| _|| j | _|	|fdd}
|dkr`t|| jd|
| jd }| _|dkrt|| jd|
| jd }| _| ||\}}| j}|}|}| j}|r|dkrtt|t|d||  k}|r|dk rd}n|dkrd}| j}t| dd }|o|}t|s,||f}t| dd}t|sJ||f}|dkoV|}|rp|dk}|dk}nd }}| j}|}|rt|s||f}t	| j}|p|p|}i }d}|r|dkr|d7 }d}|s|r| |||\}}}|r||d  }||d  }nd }}|rV|| | } t||d |  }t||d |  }|rf|d }!n|}!|| }"|d st|!|kr|!|"| kr|"}d}|r|d }!n|}!|| }"|d st|!|kr|!|"| kr|"}d}|r| |||\}}}|rF||d | k r.|d | }d}n||d | k}|d }|r||d | krp|d | }d}n||d | k}|d }q|r|s|| _nd| _|| _|| _| j}#| j}$|$dk	s|#dk	rL| j}%|   | j| j }}|%dks
t|%| dk rL|#r|#| j }&nd}&|$r>t|&|| |$ | j }&|  j|&8  _|    dS )zSet minimum and maximum axis values.

        The dataSeries argument is assumed to be a list of data
        vectors. Each vector is itself a list or tuple of numbers.

        Returns a min, max tuple.
        Nr   r  g{Gz?g{Gz333333?        Z_bubblePlotr  r9  c                 S   sT   z| d }W n t k
r(   td }Y nX ||| d 9 }|| | | | | | S )Nr  皙?r   )r   Z	bubbleMAx)r(   r)   r+   bubbleV	bubbleMaxrG   r'   r'   r,   r*     s    z$ValueAxis._setRange.<locals>.specialr=   r  rw  r  r  Fr  r   r  r   r  r~  rC   rM  ư>)!r  r  r@   r   r:   r  rB   r  rs   r@  Z_bubbleVZ
_bubbleMaxrt   Z_bubbleRadiusr  r  r  r>   r   r  r%   r  r  rA   _computedValueStepr  r  r  r  r  _calcValueStep
_valueStep_rangeAdjust)'rN   r  ZoMinr  ZoMaxr  Zzrpr  fracr  r*   r  cMincMaxr  abfZdo_rrZdo_abfZabfizZrrnZrrxabSZdo_absZaLZgor  iterr  r(   fuzzi0i1sfrG   ur  r  r  r  r'   r'   r,   r  h  s
   	

  

 
 

 
 





 
& 
&zValueAxis._setRangec                 C   s*   | j | _| j| _t| dr| `|   d S )N_subTickValues)r  r  r  r  rX   r  r  r>  r'   r'   r,   rY   
  s
    
 zValueAxis._pseudo_configurec                 C   s   dS )zOverride this if you want to alter the calculated range.

        E.g. if want a minumamum range of 30% or don't want 100%
        as the first point.
        Nr'   r>  r'   r'   r,   r    s    zValueAxis._rangeAdjustc                 C   s   dS )zOverride if you want to put slack at the ends of the axis
        eg if you don't want the last tick to be at the bottom etc
        Nr'   r>  r'   r'   r,   _adjustAxisTicks  s    zValueAxis._adjustAxisTicksc                 C   s   | j t| j| j  | _| jS zCalculate the axis' scale factor.
        This should be called only *after* the axis' range is set.
        Returns a number.
        )rt   r@  r  r  _scaleFactorr>  r'   r'   r,   r    s    zValueAxis._calcScaleFactorc                    s   t | dd   r| ` | _n|   | j | j}| j}d  }| j}tt|  }|  }|dkrz||| kr|d8 }n||| k r|d7 }tt|  }|  }|dkr||| k r|d7 }n||| kr|d8 }  fddt	||d D fS )Nr  r   r  rC   r  c                    s   g | ]}|  qS r'   r'   )r4   r   r  r'   r,   r5   <  s     z7ValueAxis._calcStepAndTickPositions.<locals>.<listcomp>)
rs   r  r  r  r  r  r  rE   r@  r   )rN   r  r  r  r  r  rG   r  r'   r  r,   r  &  s2     
  
 z#ValueAxis._calcStepAndTickPositionsc                 C   s   |   d S rO  )r  r>  r'   r'   r,   _calcTickPositions>  s    zValueAxis._calcTickPositionsc                 C   s  t | ds|   | j}t | ds| jj}|d d dkrFd}t}nd}dd }d	d
 |D }g j}t| j}t|}|dk rg | _	n8|dkr|d |d  }	nH|dkrt
|d |d  |d |d  }	n|dL }||d  ||  }	|	| }
| j|
 }| j|
 }|d |kr*|d|d |	  |d |k rJ||d |	  |	t|d  }	t|d d D ]N\}}t|D ]:}|||d |	  }||ksz||krqz|| qzqj|j| _	| j	| _|S )NrS   r  r   r   r   r   c                 S   s   | S r&   r'   rT   r'   r'   r,   r-   L  r.   z)ValueAxis._calcSubTicks.<locals>.<lambda>c                 S   s   g | ]}t |d dr|qS )_doSubTicksrC   )rs   )r4   r   r'   r'   r,   r5   N  s      z+ValueAxis._calcSubTicks.<locals>.<listcomp>r  rC      rM  )rX   rY   rS   r   rb   rE   r   r   r7   r  rA   r  r  insertr@  	enumerater   r   )rN   r   r   ZiFuzzZdCnvZOTVr(   Znstr   dstr  ZvnZvxr)   jr   r'   r'   r,   r   A  sN    


$

   zValueAxis._calcSubTicksc                 C   s2   t | dd| _| jr| jS |  | _|   | jS )zKCalculate a list of tick positions on the axis.  Returns a list of numbers.r  N)rs   rS   r   r  r>  r'   r'   r,   rI  k  s     
z ValueAxis._calcTickmarkPositionsc                 C   sR   | j dkrF| j| j }|tt| jd t| j| j  }t|| _	n| j | _	dS )8Calculate _valueStep for the axis or get from valueStep.NrC   )
r  r  r  r>   r@  r  rt   r  r"   r  )rN   rawRangerawIntervalr'   r'   r,   r  s  s
    
$zValueAxis._calcValueStepc                 C   s
   t | jS r&   )rH   rS   r>  r'   r'   r,   _allIntTicks|  s    zValueAxis._allIntTicksc                 C   s  t  }| js|S | j}|d kr6| jp2|  r0dp2t}n,|tkrL|  rLd}nt|drb|| j	 | j
}| j}| j| jg}| j}|  |d| < | j}| jdkr| jr| j}n| j}| jdkr|g}q||| j g}| jdkr|d= ng }t| j	}	|	d }
t| j	D ]\}}||	 }||kr,|| }n|| }|r|jr| |}|rz|D ]"}t|| dk rVd } qzqV|d k	r|d k	r|| }n|}t|tr|| }nbt|r|t|k r|| }nd	}n:t|d
rt|tr|| |}n||}ntd| |r"|| }|||< |j|  || | jrt| t r| j}|s|! \}}}}||k r|j"|j#| | d}||
kr|| j }|! \}}}}||kr|j"|j#| | d}|$| q|S )Nz%.0f
calcPlacesrC   r  ri   rj   r   r  r  r`   zInvalid labelTextFormat %s)r  )%r   r&  r=  r  r
  _defaultLabelFormatterstrrX   r  rS   r  r  r\   r]   r   rg  r(  r  r   rt   r7   r  r   rZ   r   r   r%   r  
ValueErrorr  r  r  
XValueAxisZ	getBoundscloner  r   )rN   r   r2   postZsclr  rr   r(  skZnticksZnticks1r   tickr  rG   Zskvr   txtZa_xr   r   r   r   Za_x1r'   r'   r,   r     s      











 



 





zValueAxis.makeTickLabelsc                 C   sZ   | j std|dkrd}| j| jf| j }| j}| jrH| }|| j7 }|||| j   S )zvConverts a numeric value to a plotarea position.
        The chart first configures the axis, then asks it to
        1Axis cannot scale numbers before it is configuredNr   )	r  r:  r\   r]   r   r  r+  rt   r  )rN   rs  orgr  r'   r'   r,   rZ     s     
zValueAxis.scale)$rb   rc   rd   re   r   r   r   r
   r	   r   r   r   r   r   r   r   r   rP   rC  rL  r  r  r  r  rY   r  r  r  r  r   r   rI  r  r
  r   rZ   r'   r'   r'   r,   r    s   

























"


























HX #*	Vr  c                   @   s   e Zd ZdZeeeeddeeddedddeeddd	d
dddee	dddZ
dZdd Zdd ZdddZdd Zdd ZdS )r  zX/value axisrq  r   rr  Nr  r!  r  rs  rt  ru  r  )r   rh  ri  rk   r<  r*  r   c                 K   sH   t j| f| d| j_d| j_d| j_d| _d| _d | _d | _	d | _
d S )NrN  r   rv  rw  )r  rP   r(  rx  r  ry  rh  ri  rk   r<  r*  r   r'   r'   r,   rP     s    zXValueAxis.__init__c                 C   s2   |  ddd | dg tdd}||  |S )Nr  r7     r}  r  r8  rC  rL  r   r   r  r'   r'   r,   r    s
    

zXValueAxis.democ                 C   sj   t | |dkr|jd | _nH|dkr:|j|j d | _n,|dkrT||d | _n|dkrf|d | _dS )r  r!  r  r  rs  rt  Nr  r  r'   r'   r,   r    s    zXValueAxis.joinToAxisc                 C   sJ   | j }|rF| jpd}|dkr,| j||d n|dkrF| j||| jd d S )Nr!  r  r  r  r  r  r  r'   r'   r,   r    s    
zXValueAxis._joinToAxisc                 C   sf   t  }|   | js|S t| j| j | j| j| j | j | j}| j	|_	| j
|_
| j|_|| |S r&   r  r  r'   r'   r,   r   "  s     (
zXValueAxis.makeAxis)r!  Nrb   rc   rd   re   r   r  r   r   r	   r   r   r   rP   r  r  r  r   r'   r'   r'   r,   r    s0   
	r  janfebmaraprmayjunjulaugsepoctnovdec      rz  c                 C   sH   |  d\}}t|}| }t|d }|t|d  ks@t||fS )a  This accepts and validates strings like "31-Dec" i.e. dates
    of no particular year.  29 Feb is allowed.  These can be used
    for recurring dates.  It returns a (dd, mm) pair where mm is the
    month integer.  If the text is not valid it raises an error.
    -rC   )splitrE   lower_monthsindex_maxDaysr:  )ZdmstrZdstrZmstrddmmr'   r'   r,   parseDayAndMonth;  s    r0  c                   @   s    e Zd ZdZdd Zdd ZdS )_isListOfDaysAndMonthszThis accepts and validates lists of strings like "31-Dec" i.e. dates
    of no particular year.  29 Feb is allowed.  These can be used
    for recurring dates.
    c                 C   sD   t |r<d}|D ]&}zt|\}}W q   d}Y qX q|S dS d S r   )r%   r0  )rN   r)   Zanswerelementr.  r/  r'   r'   r,   testN  s    z_isListOfDaysAndMonths.testc                 C   s   |S r&   r'   )rN   r)   r'   r'   r,   	normalizeZ  s    z _isListOfDaysAndMonths.normalizeN)rb   rc   rd   re   r3  r4  r'   r'   r'   r,   r1  I  s   r1  )rC   r  r           <   x         i,  ih  i  i  i  iX  i  iH  i  i8  i  i`	  c                   @   s   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dd	dee
ed
dddddee
ed
dddddeeddeee
eddeeddeeddddddZejZdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZdS )'NormalDateXValueAxiszAn X axis applying additional rules.

    Depending on the data and some built-in rules, the axis
    displays normalDate values as nicely formatted dates.

    The client chart should have NormalDate X values.
    z.Fractional amount used to adjust label spacingr   z$Flag for displaying months 'nicely'.z0Flag for enforced displaying of last date value.z1Flag for enforced displaying of first date value.zList of dates in format "31-Dec","1-Jan".  If present they will always be used for tick marks in the current year, rather than the dates chosen by the automatic algorithm. Hyphen compulsory, case of month optional.Nz3Label format string (e.g. '{mm}/{yy}') or function.r   r  r  zWeekday names.r6  zMonth names.zATrue if we are to assume daily data to be ticked at end of month.z/Actual tick values to use; no calculations donez@clear rather than delete close ticks when forced first/end datesr  r  r   r!  r"  )r   bottomAxisLabelSlack	niceMonthforceEndDateforceFirstDateforceDatesEachYearxLabelFormatdayOfWeekName	monthName	dailyFreqspecifiedTickDatesspecialTickClearr5  c                 K   s   t j| f| d| _d| _d| _d| _g | _d| _d| _ddddd	d
dg| _	ddddddddddddg| _
d| _d  | _| _d S )Nr  rC   r   z	{mm}/{yy}ZMondayZTuesdayZ	WednesdayZThursdayZFridayZSaturdayZSundayJanuaryFebruaryZMarchZAprilMayZJuneZJulyZAugustZ	SeptemberZOctoberZNovemberZDecember)r  rP   r=  r>  r?  r@  rA  rE  rB  rC  rD  rG  r  rF  r   r'   r'   r,   rP   }  s$        zNormalDateXValueAxis.__init__c                 C   s   |   }|| |S )z'Convert a scalar to a NormalDate value.)_valueClassr4  )rN   r)   rr   r'   r'   r,   
_scalar2ND  s    
zNormalDateXValueAxis._scalar2NDc              	   C   s\   t |tjs| |}tjtj }}z"| j| j t_t_|| j	W S || t_t_X dS )z(Create a formatted label for some value.N)
r   r   Z
NormalDaterL  Z_dayOfWeekNameZ
_monthNamerC  rD  ZformatMSrB  )rN   rG   rr   r  r'   r'   r,   _dateFormatter  s    
z#NormalDateXValueAxis._dateFormatterc           !   	      s  j  j}jttr(fddjs6|d n j}jsN|d n j}j}|j|j	|j
  }}}|j|j|j  }	}
}t|d|||pd| |	|
}t|d |d |d |d	 |}|d |d  }|d	 |d  }t||jpdj}||j  }g }g }j}jr fd
djD }fdd|D }jr||d kr|t|d |d   |d |d   |krjrd|d< n|d= |d= jr||d kr|t|d |d   |d |d   |krjrd|d< n|d= |d= ||fS jrtttj}| }| }g }g }|}||kr|D ]F\}}t !|||f}||krZ||krZ|"| |"| qZ|d7 }qLjr,||d kr,|#d| |#d| |t|d |d   |d |d   |kr,jr d|d< n|d= |d= jr||d kr|"| |"| |t|d |d   |d |d   |krjrd|d< n|d= |d= ||fS |||fdd}t$|}t%D ]}|| }||kr|| |kr|d }j&rF|' |dkr|pd }|rFjr>|| d|d _(||8 }z|' |d ' k} W n   d} Y nX || kr|| ||8 }qpjr|d |kr|d d|d _(|t|d |d   |d |d   |krjrd|d< n|d= |d= jrdj&rd|rd|t|d |d   |d |d   |krdjrXd|d< n|d= |d= z,|d r|d |d kr|d= |d= W n t)k
r   Y nX ||f  S qt*ddS )zComplex stuff...

        Needs explanation...

        Yes please says Andy :-(.  Modified on 19 June 2006 to attempt to allow
        a mode where one can specify recurring days and months.
        c                    s      | S r&   )rM  )r  r>  r'   r,   	formatter  s    z4NormalDateXValueAxis._xAxisTicker.<locals>.formatterr   rM  
r  rC   r  r  c                    s   g | ]} |qS r'   r'   r3   )VCr'   r,   r5     s     z5NormalDateXValueAxis._xAxisTicker.<locals>.<listcomp>c                    s   g | ]} |qS r'   r'   )r4   rr   )rN  r'   r,   r5     s     r  r  c                 S   s(   | d||   | d|||   d S r   )r  )r   xValsrN  ticksr(  r'   r'   r,   addTick  s    z2NormalDateXValueAxis._xAxisTicker.<locals>.addTickr6  z6Problem selecting NormalDate value axis tick positionsN)+rK  rt   rM  r   r  r  r  r(  fontNamefontSizeleading
textAnchorrx  r  r   r)  r   rA   r   r  r=  r  rF  r@  r@  rG  r?  rA  r/   r0   r0  yearr   NDr   r  r7   _NDINTMr>  monthr  r   r  )!rN   rQ  Z
axisLengthZ	firstDateZendDater(  rT  rU  rV  rW  rx  r  ZRBLZxLabelWZxLabelHr   WrR  r  ZforcedPartialDatesZ	firstYearZlastYearZyyyyr.  r/  ZtheDaterS  rN  rr   r~   r   r  Zwfdr'   )rP  rN  rN   r,   _xAxisTicker  s    
 
   D
D


.

.





.
.
z!NormalDateXValueAxis._xAxisTickerc                 C   sL   | j }|D ]<}tt|D ]*}|| \}}t||s|||f||< qq
dS )z1Convert all XValues to a standard normalDate typeN)rK  r   r7   r   )rN   datarP  r   r   r)   rU   r'   r'   r,   
_convertXV,  s    
zNormalDateXValueAxis._convertXVc           	      C   s   | j rtg }d}|d }|D ]*}| }||kr@|r<|| |}|}q|d }|d |krd|| | |\}}n| |\}}||fS )Nr   rM  )rE  r[  r   r]  )	rN   rQ  ZxEOMZpmZpxr)   r  stepsr(  r'   r'   r,   _getStepsAndLabels6  s"     
 
z'NormalDateXValueAxis._getStepsAndLabelsc           
      C   s   |  | t }|D ]}|D ]}||d  qqt|}|  | j}| |\}}| j| j }}	|d krt|d n||}|	d kr|d n||	}	||	 | _	| _
|| _|| _| jt|	|  | _|| _d| _d S )Nr   rM  rC   )r_  setr   r/   sortrK  ra  r  r  r  r  rS   r=  rt   r@  r  r  )
rN   r^  rQ  r)   ZdvrP  r`  r(  r  r  r'   r'   r,   rL  H  s$    
zNormalDateXValueAxis.configure)rb   rc   rd   re   r   r  r   r   r
   isListOfDaysAndMonthsr   r   r   r   r	   r   r   rY  rK  rP   rL  rM  r]  r_  ra  rL  r'   r'   r'   r,   r<  a  s0   







 
r<  c                
   @   s~   e Zd ZdZeeeeddeeddedddeedddee	d	dd
Z
dZdd Zdd ZdddZdd Zdd ZdS )
YValueAxiszY/value axisr  r   r  Nr  r  r  r  )r   ro  rn  rk   r<  r*  rC   c                 C   sD   t |  d| j_d| j_d| j_d| _d| _d | _d | _	d | _
d S )Nr1   rv  r   rw  )r  rP   r(  rx  r  ry  rn  ro  rk   r<  r*  r>  r'   r'   r,   rP   p  s    
zYValueAxis.__init__c                 C   s6   dg}|  ddd | | tdd}||  |S )N)r~  r  rz  *   r8  r~  r  r  r  )rN   r^  Zdrawingr'   r'   r,   r  ~  s    


zYValueAxis.demor  c                 C   sj   t | |dkr|jd | _nH|dkr:|j|j d | _n,|dkrT||d | _n|dkrf|d | _dS r  r  r  r'   r'   r,   r    s    zYValueAxis.joinToAxisc                 C   sF   | j }|rB| j}|dkr(| j||d n|dkrB| j||| jd d S r  r  r  r'   r'   r,   r    s    zYValueAxis._joinToAxisc                 C   sf   t  }|   | js|S t| j| j| j | j| j| j | j }| j	|_	| j
|_
| j|_|| |S r&   r  r  r'   r'   r,   r     s     (
zYValueAxis.makeAxis)r  Nr  r'   r'   r'   r,   re  ]  s0   	
	re  c                   @   s8   e Zd ZdZde Zde Zdd Zdd Zdd Zd	S )
TimeValueAxisr8  r7  c                 O   s   | j s| j| _ i | _d S r&   )r  timeLabelTextFormatter_saved_tickInforN   argsrO   r'   r'   r,   rP     s    zTimeValueAxis.__init__c                 C   s   | j dkr| j| j }|tt| jd t| j| j  }|| jkrR| j}d| _	n:|| j
krj| j
}d| _	n"|| jkr| j}d| _	n
d}d| _	|| _|dkrt|| }t|| | _n| j | _dS )r  NrC   dayshoursminutesseconds)r  r  r  r>   r@  r  rt   r  _dc_unit_hc_mc_unitdrE   r"   r  )rN   r  r	  rr   r'   r'   r,   r    s&    
$


zTimeValueAxis._calcValueStepc                    s6  | j }|t| jf}|| jkr,| j| }nt|fdd| jD }| jd }t|rj|fdd}ndd |D }tdd |D }|d	krd
| fdd}n~|| jkrdnd  fdd|D }	t|	r|| jkrdn|| j	krdnd}
 d||
f fdd}nd||f fdd}|| j|< ||S )Nc                    s   g | ]}|  qS r'   r'   r4   rG   )ufr'   r,   r5     s     z8TimeValueAxis.timeLabelTextFormatter.<locals>.<listcomp>r   c                 S   s   d| | |f S )Nz%.0f%sr'   )r)   rv  r{   r'   r'   r,   r-     r.   z6TimeValueAxis.timeLabelTextFormatter.<locals>.<lambda>c                 S   s   g | ]}d | qS )z%.10fr'   ru  r'   r'   r,   r5     s     c                 s   s*   | ]"}t |d |d d V  qdS )0.rC   N)r7   rstripr,  ru  r'   r'   r,   	<genexpr>  s     z7TimeValueAxis.timeLabelTextFormatter.<locals>.<genexpr>rC   z%%.%dfsc                 S   s   || |  S r&   r'   r)   rv  fmtr'   r'   r,   r-     r.   r7  r8  c                    s   g | ]}|t |   qS r'   rD   ru  )fmr'   r,   r5     s     hr  r{   z%%d%s%%d%%sc                 S   s,   |t | | t | | t | |  | f S r&   rD   )r)   rv  r}  r|  r'   r'   r,   r-     r.   z%%.%df%sc                 S   s   || |  S r&   r'   r{  r'   r'   r,   r-     r.   )
rt  tuplerS   ri  r@  rq  rH   rA   rp  rs  )rN   valr  r~   r|  r   r{   ZstvZstvlZfvs1r'   )r}  rv  r,   rh    s*    


 
z$TimeValueAxis.timeLabelTextFormatterN)	rb   rc   rd   rs  rr  rp  rP   r  rh  r'   r'   r'   r,   rg    s   rg  c                   @   s   e Zd Zdd ZdS )XTimeValueAxisc                 O   s(   t j| f|| tj| f|| d S r&   )r  rP   rg  rj  r'   r'   r,   rP     s    zXTimeValueAxis.__init__Nrb   rc   rd   rP   r'   r'   r'   r,   r    s   r  c                
   @   sd   e Zd ZdZeeeeddeeddeeddee	ee
fddeedddZd	d
 Zdd ZdS )AdjYValueAxiszA Y-axis applying additional rules.

    Depending on the data and some built-in rules, the axis
    may choose to adjust its range and origin.
    z+When true add percent sign to label values.r   r  r  z8Skip/Keep lowest tick label when true/false.
Or skiplistzadd this to the labels)r   leftAxisPercentleftAxisOrigShiftIPCleftAxisOrigShiftMinleftAxisSkipLL0labelVOffsetc                 K   s<   t j| f| d| _d| _d| _d| _d | _| _d | _d S )Nrz  rC   g333333?r6  r   )	re  rP   r  r  r  r  r  r  r  r   r'   r'   r,   rP     s    zAdjYValueAxis.__init__c              	   C   s  ddl m}m} | j| j }}| j}tt|fddddddd	d
g}|sP|g}| j| j	 }}|r|| |k r|||||ddd \}	}
|
|	 |k r|	|
 d }t
||d  |}	t||d  |}
|dkr|	dk r|
d |	 }
d}	n |dkr|	dk r|
|	 }
d}	|	|
 | _| _|| j| jd|| j|| jd\}}| j}|r|d |d  }t|sr||  }}n||d  }||d  }t| d|d }t| d|d }||d  |k r| j| | _|d | |k r| j| | _|| j| jd|| j|| jd\}}|d | _|d | _|| _| jdkr6|| _n| j| _t| jd dk r|   | j| j }}t| j| j || | j | j }| j| | _| jrt| jr| jD ]*}zd||< W n tk
r   Y nX qd|d< dS )z$Adjusts the value range of the axis.r   )find_good_gridrR  c                 S   s   | |kS r&   r'   )r)   r  r'   r'   r,   r-     r.   z,AdjYValueAxis._rangeAdjust.<locals>.<lambda>r   rw  r5  r     	   )rN  gridNr  r   r8  rC   )r)  rN  percentr  r  r  r  rM  r  r  )reportlab.graphics.charts.utilsr  rR  r  r  r  r/   r6   r  r  r>   rA   r  r  r  r%   rs   rS   r  r=  r   r  r  r  r  rt   r  r   )rN   r  rR  Zy_minZy_maxr  rN  r  r  r   r  Zymr(   r}   r  r  r  Z_nr\   ZvMaxZvMinr)   r'   r'   r,   r    sp    " "
  "



zAdjYValueAxis._rangeAdjustN)rb   rc   rd   re   r   re  r   r
   r   r   r   r   rP   r  r'   r'   r'   r,   r    s   



	r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
LogValueAxisc                 C   s&   | j tt| jt| j  | _| jS r  )rt   r@  
math_log10r  r  r  r>  r'   r'   r,   r  G  s    zLogValueAxis._calcScaleFactorc                 C   s*  | j }| j}t|| jd| jd}t|| jd| jd}|d kr@|}|d krL|}||krhtd| jj|f |dkrtd| jj	|f | j
}|rt|}t|}t|s||f}|d pd}	|d pd}
| j|	|
  }|| t| }||	| 8 }||
| 7 }t|d| }t|d| }|| _|| _d S )Nr   )r:   z7%s: valueMin=%r should not be greater than valueMax=%r!z0%s: valueMin=%r negative values are not allowed!rC   r~  )r  r  r@   r   r:   rB   r  r   Z_LogValueAxis__name__valueMinrb   r  r  r%   rt   r@  r>   rA   r  r  )rN   r  r  r  ZaMinZaMaxr  ZlMinZlMaxZa0Za1r}   r  r'   r'   r,   r  Q  s8       zLogValueAxis._setRangec           
      C   s"  t | j }}t | j }}| j}|rn|dkrJt|}||k rF|d n|}|dkrnt|}||krj|d n|}g j}t|}||k r|d7 }t|| d }	tt|	| j d}||	 | jkr|d7 }|| _||krq||kr|d|  ||7 }q||krd| | _||krd| | _|j	S )Nr  rC   r  r~  )
r  r  r  r  rE   r   rA   r  	_powerIncr   )
rN   r  r  r  r  r  r   r(   r   rN  r'   r'   r,   r   l  s:        

 

 
zLogValueAxis._calcTickPositionsc                 C   s\  t | ds|   | j}t | dsPg j}t| j}t| jd }t|}| j}|dkrdt	| j
 }d}| j
dkrxd}||k rt|| j
D ]0}	||	 d|  }
|
| jkr|
| jk r||
 q||7 }qxn~t| j
d |d }|r|| dkr|| }q
|d8 }qd}t|}d| }
|
| jkr*qH|
|kr<||
 ||7 }q|j| _| j| _|S )NrS   r  rC   r~  r  r   )rX   rY   rS   r   r  r  r  roundr  r@  r   r   r>   r   r  )rN   r   r(   r  r  r   r   Zfacri   r  rG   Zngr'   r'   r,   r     sJ    


 

 
zLogValueAxis._calcSubTicksN)rb   rc   rd   r  r  r   r   r'   r'   r'   r,   r  E  s   
r  c                   @   s   e Zd Zdd ZdS )LogAxisTickLabellerc                 C   sD   t |}t|dk r|d n|d }|dkr0dS |dkr<dS d| S )Nr   MbP?1rC   10z10<sup>%s</sup>)r  rE   )rN   r^   rs  r1   r'   r'   r,   r`     s      zLogAxisTickLabeller.__call__N)rb   rc   rd   r`   r'   r'   r'   r,   r    s   r  c                   @   s   e Zd ZdZdd ZdS )LogAxisTickLabellerSzZsimple log axis labeller tries to use integers
    and short forms else exponential formatc                 C   sz   t |}t|dk r|d n|d }|dkr0dS |dkrDd|d  ndd|  d  d }d| }t|t|k rv|S |S )Nr   r  r  rw  z0.rC   z%.0e)r  rE   r7   )rN   r^   rs  r1   pr{   ser'   r'   r,   r`     s     *zLogAxisTickLabellerS.__call__Nr  r'   r'   r'   r,   r    s   r  c                   @   s   e Zd Zdd ZdS )LogAxisLabellingSetupc                 C   sd   t d k	rXtt| _| jdkr6d| j_d| j_d| j_nd| j_d| j_d| j_t | _	nt
 | _	d S )NrC   r1   rv  r   rN  )r!   r   r    r(  r   rx  r  ry  r  r  r  r>  r'   r'   r,   rP     s    



zLogAxisLabellingSetup.__init__Nr  r'   r'   r'   r,   r    s   r  c                   @   s&   e Zd ZeedZdd Zdd ZdS )LogXValueAxisr   c                 C   s   t |  t|  d S r&   )r  rP   r  r>  r'   r'   r,   rP     s    
zLogXValueAxis.__init__c                 C   sZ   d}| j st||dkrd}|dkr<| j| jt| j  S | j| jt|t| j   S zConverts a numeric value to a Y position.

        The chart first configures the axis, then asks it to
        work out the x value for each point when plotting
        lines or bars.  You could override this to do
        logarithmic axes.
        r  Nr   r  )r  r:  r\   r  r  r  rN   rs  msgr'   r'   r,   rZ     s    	zLogXValueAxis.scaleN)rb   rc   rd   r   r  r   rP   rZ   r'   r'   r'   r,   r    s   
r  c                   @   s&   e Zd ZeedZdd Zdd ZdS )LogYValueAxisr  c                 C   s   t |  t|  d S r&   )re  rP   r  r>  r'   r'   r,   rP     s    
zLogYValueAxis.__init__c                 C   sZ   d}| j st||dkrd}|dkr<| j| jt| j  S | j| jt|t| j   S r  )r  r:  r]   r  r  r  r  r'   r'   r,   rZ     s    	zLogYValueAxis.scaleN)rb   rc   rd   r   re  r   rP   rZ   r'   r'   r'   r,   r    s   
r  )NN)NN)NN)W__version__re   mathr   r  Zreportlab.lib.validatorsr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   Zreportlab.lib.attrmapZreportlab.libr   Zreportlab.graphics.shapesr   r   r   r   r   r   r   r   Zreportlab.graphics.widgetbaser   r   Z$reportlab.graphics.charts.textlabelsr   r   r    r!   r  r"   Z reportlab.graphics.widgets.gridsr#   Zreportlab.lib.colorsr$   Zreportlab.lib.utilsr%   r<   r@   rB   rH   rI   rf   r   r   r   r   r   rW  rX  rY  rm  rp  r  r  r  r  r  r+  r-  r0  r1  rd  rZ  r<  re  rg  r  r  r  r  r  r  r  r  r'   r'   r'   r,   <module>   sr   D(


	GE - =qq    ]U }KBVl