o
    až}Zn>  ã                   @   s”  d Z dZddlZddlmZmZ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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#m$Z$m%Z%m&Z& dd
l'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 G dd„ de-ƒZ6G dd„ de,ƒZ7dd„ Z8dd„ Z9dd„ Z:dd„ Z;e<dkrÈddl=m>Z> e8ƒ Z?e>e?dƒ e9ƒ Z?e>e?dƒ e:ƒ Z?e>e?dƒ dS dS ) z3.3.0z£Doughnut chart

Produces a circular chart like the doughnut charts produced by Excel.
Can handle multiple series (which produce concentric 'rings' in the chart).

é    N)ÚsinÚcosÚpi)Úcolors)ÚisColorÚisNumberÚisListOfNumbersOrNoneÚisListOfNumbersÚisColorOrNoneÚisStringÚisListOfStringsOrNoneÚOneOfÚ
SequenceOfÚ	isBooleanÚisListOfColorsÚisNoneOrListOfNoneOrStringsÚisNoneOrListOfNoneOrNumbersÚisNumberOrNone)Ú*)ÚCanvas)ÚGroupÚDrawingÚLineÚRectÚPolygonÚEllipseÚWedgeÚStringÚ
SolidShapeÚUserNodeÚSTATE_DEFAULTS)ÚWidgetÚTypedPropertyCollectionÚ
PropHolder)ÚAbstractPieChartÚWedgePropertiesÚ_addWedgeLabelÚfixLabelOverlaps)ÚLabel)ÚMarker)Úreducec                   @   s   e Zd ZdZeed�ZdS )ÚSectorPropertiesa4  This holds descriptive information about the sectors in a doughnut chart.

    It is not to be confused with the 'sector itself'; this just holds
    a recipe for how to format one, and does not allow you to hack the
    angles.  It can format a genuine Sector object for you with its
    format method.
    )ÚBASEN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚAttrMapr%   Ú_attrMap© r3   r3   úT/var/www/html/env/lib/python3.10/site-packages/reportlab/graphics/charts/doughnut.pyr+   "   s    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ddd�eedd�eed	d�eed
dƒdd�eddd�eedd�eeddd�eeddd�ee	dd�d�Z
dd„ Zdd„ Zddd„Zdd„ Zdd„ ZdS ) ÚDoughnutz-X position of the chart within its container.)Údescz-Y position of the chart within its container.z:width of doughnut bounding box. Need not be same as width.z=height of doughnut bounding box.  Need not be same as height.Nz8list of numbers defining sector sizes; need not sum to 1z2optional list of labels to use for each data pointz6angle of first slice; like the compass, 0 is due NorthÚ	clockwiseÚanticlockwisez'clockwise' or 'anticlockwise'z'collection of sector descriptor objectsz6If true(default) use String not super duper WedgeLabelzFIf true check and attempt to fix
 standard label overlaps(default off)é   )r6   ÚadvancedUsagezAIf true attempt to make chart with labels along side and pointerszhNone or the fraction of the radius to be used as the inner hole.
If not a suitable default will be used.)ÚxÚyÚwidthÚheightÚdataÚlabelsÚ
startAngleÚ	directionÚslicesÚsimpleLabelsÚcheckLabelOverlapÚ
sideLabelsÚinnerRadiusFractionc                 C   s¼   d| _ d| _d| _d| _ddg| _d | _d| _d| _d| _d| _	d| _
d | _ttƒ| _tj| jd _tj| jd _tj| jd _tj| jd _tj| jd _tj| jd	 _tj| jd
 _d S )Nr   éd   r9   éZ   r7   é   é   é   é   é   )r;   r<   r=   r>   r?   r@   rA   rB   rD   rE   rF   rG   r"   r+   rC   r   ÚdarkcyanÚ	fillColorÚ
bluevioletÚblueÚcyanÚpinkÚmagentaÚyellow)Úselfr3   r3   r4   Ú__init__@   s(   

zDoughnut.__init__c                 C   sö   t ddƒ}tƒ }d|_d|_d|_d|_g d¢|_g d¢|_d|j_	d|jd	 _
d
|jd	 _	d
d
g|jd	 _d|jd	 _tj|jd	 _tj|jd _tj|jd _tj|jd
 _tj|jd	 _tj|jd _tj|jd _tj|jd _| |¡ |S )NéÈ   rH   é2   é
   éP   ©r[   é   é   é(   rZ   é<   ©ÚaÚbÚcÚdÚeÚfç      à?rK   rJ   g      ü?r   r9   rL   rM   rN   )r   r5   r;   r<   r=   r>   r?   r@   rC   ÚstrokeWidthÚpopoutÚstrokeDashArrayÚlabelRadiusr   ÚredÚ	fontColorrO   rP   rQ   rR   rS   Ú
aquamarineÚ	cadetblueÚ
lightcoralÚadd)rW   rf   Údnr3   r3   r4   ÚdemoX   s.   



zDoughnut.democ                 C   sP   ddl m} tt||dƒƒ}t|ƒdkr!ttd| fdd„|ƒƒp't|ƒdg S )Nr   )rs   g:Œ0âŽyE>g     €v@c                 S   s   ||  S ©Nr3   )r;   rh   r3   r3   r4   Ú<lambda>w   s    z(Doughnut.normalizeData.<locals>.<lambda>)Úoperatorrs   Úfloatr*   ÚabsÚlistÚmapÚlen)rW   r?   rs   Úsumr3   r3   r4   ÚnormalizeDatat   s   4zDoughnut.normalizeDatac           1      C   sŒ  t | jttfƒr3t | jd ttfƒr3g }g }| jD ]}|  |¡}| |¡ | t|ƒ¡ qt|ƒ| _n|  | j¡}t|ƒ}|| _| j	}g }|j}| j
d u rkg }t |ttfƒs\dg| }nK|D ]}	t|ƒdg|	  }q^n<| j
}t |ttfƒs‰|t|ƒ }
|
dkrˆt|ƒdg|
  }nd}|D ]}	||	7 }q�|t|ƒ }
|
dkr§t|ƒdg|
  }| jd }| jd }| j| }| j| }| jdkrÃd}nd}tƒ }| j}t| jƒ}| j}t | jd ttfƒ�r$t| jƒ}|d u rô|d | }|d | }n|| }|| }|| | }|| | }t|ƒD �]\}}t|ƒD �]	\}
}|||  }t|| ƒdk �r-|}�q||k �r7|}|}n|}|}|}| j|
|  } ||}!}"| jdk�rn|| d }#|#t d	 }$| j}%||%t|$ƒ  }!||%t|$ƒ  }"|||  }&|&| }'|||  }(|(| })t |ttfƒ�r—t|!|"|)|||'|(|&d
�}*nt|!|"|)|||'|(|&dd�	}*| j|*_| j|*_| j|*_| j|*_| |*¡ |dk�r| j �r| j!�r|  "|
d¡}+|+�r|| d }#|#t d	 }$| j#},||, }-||, }.|d| j t|$ƒ |,  }/|d| j t|$ƒ |,  }0t$| |+|#|/|0| ƒ}|�r|/|0|#|-|.|!|"| %¡ dœ|_&||ƒ �q�q�n|d u �r2|d }|d }n|| }|| }t|ƒD ]ð\}
}|||  }t|| ƒdk �rU|}�q>||k �r_|}|}n|}|}|}| j|
|  } ||}!}"| jdk�r–|| d }#|#t d	 }$| j}%||%t|$ƒ  }!||%t|$ƒ  }"|dk�r¨t|!|"||||||d
�}*n|dk�rºt|!|"||||||dd�	}*| j|*_| j|*_| j|*_| j|*_| |*¡ ||
 �r-| j �r-| j!�r-|| d }#|#t d	 }$| j#},|d| j t|$ƒ |,  }/|d| j t|$ƒ |,  }0||, }-||, }.t$| ||
 |#|/|0| ƒ}|�r)|/|0|#|-|.|!|"| %¡ dœ|_&||ƒ �q>|�r9|�r9t'|ƒ |D ]}| |¡ �q;|S )Nr   Ú g       @r8   r9   éÿÿÿÿg      @gñhãˆµøä>g     €f@)ÚyradiusÚradius1Úyradius1T)r‚   rƒ   r„   Úannularri   )r;   r<   ÚangleÚrxÚryÚcxÚcyÚbounds)(Ú
isinstancer?   r{   Útupler   Úappendr}   ÚmaxÚ_seriesCountrE   r@   r=   r>   r;   r<   rB   r   rA   rC   rG   Ú	enumeraterz   rk   r   r   r   r   rP   ÚstrokeColorrj   rl   rs   ÚvisibleÚlabel_visibleÚgetSeriesNamerm   r&   Ú	getBoundsÚ	_origdatar'   )1rW   ÚnormDataÚnÚlÚtrE   ÚLÚL_addr@   ÚmÚiÚtlabÚxradiusr‚   ÚcenterxÚcenteryÚwhichWayÚgrA   Ú
styleCountÚirfÚndataÚyirÚxirÚydrÚxdrÚsnÚseriesr†   ÚendAngleÚa1Úa2ÚsectorStyler‰   rŠ   ÚaverageAngleÚaveAngleRadiansÚpopdistanceÚyr1ÚyrÚxr1ÚxrÚ	theSectorÚtextrm   r‡   rˆ   ÚlabelXÚlabelYr3   r3   r4   ÚmakeSectorsy   s<  $



ÿ€










þ€Åÿ
@





þ€zDoughnut.makeSectorsc                 C   s   t ƒ }| |  ¡ ¡ |S rv   )r   rs   r¾   )rW   r¥   r3   r3   r4   ÚdrawD  s   zDoughnut.drawrv   )r-   r.   r/   r1   ÚAttrMapValuer   r   r   r   r   r2   rX   ru   r   r¾   r¿   r3   r3   r3   r4   r5   -   s0    








ÿò
 Lr5   c                  C   sÄ   t ddƒ} tƒ }tddddddd�}tj|_d|_|  |¡ tddddd	dd�}tj|_d|_|  |¡ tdddd	d
dd�}tj	|_d|_|  |¡ tdddd
ddd�}tj
|_d|_|  |¡ | S )z-Make up something from the individual Sectorsé�  rY   é–   r   éx   rH   )r¢   r£   ÚradiusÚstartangledegreesÚendangledegreesrƒ   Néð   i  ih  )r   r   r   r   rn   rP   r’   rs   ÚgreenrR   Úgray)rf   r¥   Ús1Ús2Ús3Ús4r3   r3   r4   Úsample1J  s&   




rÎ   c                  C   s@   t ddƒ} tƒ }d|_d|_d|_d|_g d¢|_|  |¡ | S )zMake a simple demorÁ   rZ   é,  r]   )r   r5   r;   r<   r=   r>   r?   rs   ©rf   rt   r3   r3   r4   Úsample2c  s   


rÑ   c                  C   sR   t ddƒ} tƒ }d|_d|_d|_d|_g d¢g d¢g|_g d¢|_|  |¡ | S )zMake a more complex demorÁ   rZ   rÏ   r]   ©r[   r^   r_   r`   rb   )	r   r5   r;   r<   r=   r>   r?   r@   rs   rÐ   r3   r3   r4   Úsample3s  s   


rÓ   c                  C   sX   t ddƒ} tƒ }d|_d|_d|_d|_g d¢g d¢g|_g d¢|_d|_|  	|¡ | S )z2Make a more complex demo with Label Overlap fixingrÁ   rZ   rÏ   r]   rÒ   rb   T)
r   r5   r;   r<   r=   r>   r?   r@   rE   rs   rÐ   r3   r3   r4   Úsample4ƒ  s   


rÔ   Ú__main__)Ú
drawToFilezdoughnut1.pdfzdoughnut2.pdfzdoughnut3.pdf)@Ú__version__r0   ÚcopyÚmathr   r   r   Úreportlab.libr   Úreportlab.lib.validatorsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Úreportlab.lib.attrmapÚreportlab.pdfgen.canvasr   Úreportlab.graphics.shapesr   r   r   r   r   r   r   r   r   r   r    Úreportlab.graphics.widgetbaser!   r"   r#   Ú#reportlab.graphics.charts.piechartsr$   r%   r&   r'   Ú$reportlab.graphics.charts.textlabelsr(   Ú"reportlab.graphics.widgets.markersr)   Ú	functoolsr*   r+   r5   rÎ   rÑ   rÓ   rÔ   r-   Úreportlab.graphics.renderPDFrÖ   rf   r3   r3   r3   r4   Ú<module>   s>   @4  

ø