o
    7 hp3                     @  s$  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z ddlmZ ddlmZmZ dd	lmZ G d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdd ZG d d! d!eZd"S )#zPlot-related objects.

A plot is known as a chart group in the MS API. A chart can have more than one plot overlayed on
each other, such as a line plot layered over a bar plot.
    )annotations)
Categories)
DataLabels)SeriesCollection)XL_CHART_TYPE)qn)	ST_BarDirST_Grouping)lazypropertyc                      s   e Zd ZdZ fddZedd Zedd Zedd	 Z	ed
d Z
e
jdd Z
edd Zedd Zejdd Z  ZS )	_BasePlotz
    A distinct plot that appears in the plot area of a chart. A chart may
    have more than one plot, in which case they appear as superimposed
    layers, such as a line plot appearing on top of a bar chart.
    c                   s   t t|   || _|| _d S N)superr   __init___element_chart)selfxChartchart	__class__ W/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/chart/plot.pyr      s   
z_BasePlot.__init__c                 C  
   t | jS )a  
        Returns a |category.Categories| sequence object containing
        a |category.Category| object for each of the category labels
        associated with this plot. The |category.Category| class derives from
        ``str``, so the returned value can be treated as a simple sequence of
        strings for the common case where all you need is the labels in the
        order they appear on the chart. |category.Categories| provides
        additional properties for dealing with hierarchical categories when
        required.
        )r   r   r   r   r   r   
categories   s   
z_BasePlot.categoriesc                 C  s   | j S )z:
        The |Chart| object containing this plot.
        )r   r   r   r   r   r   ,   s   z_BasePlot.chartc                 C  s    | j j}|du rtdt|S )z
        |DataLabels| instance providing properties and methods on the
        collection of data labels associated with this plot.
        Nz9plot has no data labels, set has_data_labels = True first)r   dLbls
ValueErrorr   )r   r   r   r   r   data_labels3   s   z_BasePlot.data_labelsc                 C  s   | j jduS )z
        Read/write boolean, |True| if the series has data labels. Assigning
        |True| causes data labels to be added to the plot. Assigning False
        removes any existing data labels.
        N)r   r   r   r   r   r   has_data_labels>   s   z_BasePlot.has_data_labelsc                 C  s@   t |du r| j  dS | jjdu r| j }d|j_dS dS )aZ  
        Add, remove, or leave alone the ``<c:dLbls>`` child element depending
        on current state and assigned *value*. If *value* is |True| and no
        ``<c:dLbls>`` element is present, a new default element is added with
        default child elements and settings. When |False|, any existing dLbls
        element is removed.
        FNT)boolr   _remove_dLblsr   
_add_dLblsshowValval)r   valuer   r   r   r   r   G   s   	
c                 C  r   )z
        A sequence of |Series| objects representing the series in this plot,
        in the order they appear in the plot.
        )r   r   r   r   r   r   seriesW   s   
z_BasePlot.seriesc                 C     | j j}|du r
dS |jS )a  
        Read/write boolean value specifying whether to use a different color
        for each of the points in this plot. Only effective when there is
        a single series; PowerPoint automatically varies color by series when
        more than one series is present.
        NT)r   
varyColorsr#   )r   r'   r   r   r   vary_by_categories_   s   z_BasePlot.vary_by_categoriesc                 C  s   t || j _d S r   )r   r   get_or_add_varyColorsr#   r   r$   r   r   r   r(   l   s   )__name__
__module____qualname____doc__r   r
   r   propertyr   r   r   setterr%   r(   __classcell__r   r   r   r   r      s&    







r   c                   @     e Zd ZdZdS )AreaPlotz
    An area plot.
    Nr+   r,   r-   r.   r   r   r   r   r3   q       r3   c                   @  r2   )
Area3DPlotz$
    A 3-dimensional area plot.
    Nr4   r   r   r   r   r6   w   r5   r6   c                   @  sD   e Zd ZdZedd Zejdd Zedd Zejdd ZdS )	BarPlotz!
    A bar chart-style plot.
    c                 C  r&   )z
        Width of gap between bar(s) of each category, as an integer
        percentage of the bar width. The default value for a new bar chart is
        150, representing 150% or 1.5 times the width of a single bar.
        N   )r   gapWidthr#   )r   r9   r   r   r   	gap_width      zBarPlot.gap_widthc                 C  s   | j  }||_d S r   )r   get_or_add_gapWidthr#   )r   r$   r9   r   r   r   r:      s   

c                 C  r&   )a  
        Read/write int value in range -100..100 specifying a percentage of
        the bar width by which to overlap adjacent bars in a multi-series bar
        chart. Default is 0. A setting of -100 creates a gap of a full bar
        width and a setting of 100 causes all the bars in a category to be
        superimposed. A stacked bar plot has overlap of 100 by default.
        Nr   )r   overlapr#   )r   r=   r   r   r   r=      s   	zBarPlot.overlapc                 C  s&   |dkr| j   dS || j  _dS )z
        Set the value of the ``<c:overlap>`` child element to *int_value*,
        or remove the overlap element if *int_value* is 0.
        r   N)r   _remove_overlapget_or_add_overlapr#   r*   r   r   r   r=      s   
N)r+   r,   r-   r.   r/   r:   r0   r=   r   r   r   r   r7   }   s    


r7   c                   @  s*   e Zd ZdZedd Zejdd ZdS )
BubblePlotz
    A bubble chart plot.
    c                 C  r&   )z
        An integer between 0 and 300 inclusive indicating the percentage of
        the default size at which bubbles should be displayed. Assigning
        |None| produces the same behavior as assigning `100`.
        Nd   )r   bubbleScaler#   )r   rB   r   r   r   bubble_scale   r;   zBubblePlot.bubble_scalec                 C  s,   | j }|  |d u rd S | }||_d S r   )r   _remove_bubbleScale_add_bubbleScaler#   )r   r$   bubbleChartrB   r   r   r   rC      s   
N)r+   r,   r-   r.   r/   rC   r0   r   r   r   r   r@      s    
r@   c                   @  r2   )DoughnutPlotz
    An doughnut plot.
    Nr4   r   r   r   r   rG      r5   rG   c                   @  r2   )LinePlotz"
    A line chart-style plot.
    Nr4   r   r   r   r   rH      r5   rH   c                   @  r2   )PiePlotz!
    A pie chart-style plot.
    Nr4   r   r   r   r   rI      r5   rI   c                   @  r2   )	RadarPlotz
    A radar-style plot.
    Nr4   r   r   r   r   rJ      r5   rJ   c                   @  r2   )XyPlotz
    An XY (scatter) plot.
    Nr4   r   r   r   r   rK      r5   rK   c                 C  s~   z+t dtt dtt dtt dtt dtt dtt dtt dtt d	t	i	| j
 }W n ty9   td
| j
 w || |S )zk
    Return an instance of the appropriate subclass of _BasePlot based on the
    tagname of *xChart*.
    zc:areaChartzc:area3DChartz
c:barChartzc:bubbleChartzc:doughnutChartzc:lineChartz
c:pieChartzc:radarChartzc:scatterChartzunsupported plot type %s)r   r3   r6   r7   r@   rG   rH   rI   rJ   rK   tagKeyErrorr   )r   r   ZPlotClsr   r   r   PlotFactory   s"   

rN   c                   @  s   e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd ZdS )PlotTypeInspectorz
    "One-shot" service object that knows how to identify the type of a plot
    as a member of the XL_CHART_TYPE enumeration.
    c              
   C  s\   z| j | j| j| j| j| j| j| j| jd	|j	j
 }W ||S  ty-   td|j	j
 w )zo
        Return the member of :ref:`XlChartType` that corresponds to the chart
        type of *plot*.
        )	r3   r6   r7   r@   rG   rH   rI   rJ   rK   z#chart_type() not implemented for %s)_differentiate_area_chart_type!_differentiate_area_3d_chart_type_differentiate_bar_chart_type _differentiate_bubble_chart_type"_differentiate_doughnut_chart_type_differentiate_line_chart_type_differentiate_pie_chart_type_differentiate_radar_chart_type_differentiate_xy_chart_typer   r+   rM   NotImplementedError)clsplotZchart_type_methodr   r   r   
chart_type  s&   

zPlotTypeInspector.chart_typec                 C  $   t jtjt jtjt jtji|jj	 S r   )
r	   STANDARDXLTHREE_D_AREASTACKEDTHREE_D_AREA_STACKEDPERCENT_STACKEDTHREE_D_AREA_STACKED_100r   grouping_valrZ   r[   r   r   r   rQ        z3PlotTypeInspector._differentiate_area_3d_chart_typec                 C  r]   r   )
r	   r^   r_   AREAra   AREA_STACKEDrc   AREA_STACKED_100r   re   rf   r   r   r   rP   #  rg   z0PlotTypeInspector._differentiate_area_chart_typec                 C  sv   |j }|jjtjkrtjtjtj	tj
tjtji|j S |jjtjkr3tjtjtj	tjtjtji|j S td|jj )Nz"invalid barChart.barDir value '%s')r   barDirr#   r   BARr	   	CLUSTEREDr_   BAR_CLUSTEREDra   BAR_STACKEDrc   BAR_STACKED_100re   COLCOLUMN_CLUSTEREDCOLUMN_STACKEDCOLUMN_STACKED_100r   )rZ   r[   ZbarChartr   r   r   rR   +  s    z/PlotTypeInspector._differentiate_bar_chart_typec                 C  s6   dd }|j }||}|d u rtjS |jrtjS tjS )Nc                 S  s   |  d}|r|d S d S )Nzc:ser/c:bubble3Dr   xpath)rF   resultsr   r   r   first_bubble3D>  s   
zJPlotTypeInspector._differentiate_bubble_chart_type.<locals>.first_bubble3D)r   r_   BUBBLEr#   BUBBLE_THREE_D_EFFECT)rZ   r[   rx   rF   bubble3Dr   r   r   rS   <  s   z2PlotTypeInspector._differentiate_bubble_chart_typec                 C      |j }|d}|rtjS tjS Nz./c:ser/c:explosion)r   rv   r_   DOUGHNUT_EXPLODEDDOUGHNUT)rZ   r[   ZdoughnutChart	explosionr   r   r   rT   K     
z4PlotTypeInspector._differentiate_doughnut_chart_typec                   s`   |j   fdd}| rtjtjtjtjtjtji|j j	 S tjtj
tjtjtjtji|j j	 S )Nc                    s     d} | r	dS dS )Nz$c:ser/c:marker/c:symbol[@val="none"]FTru   matchesZ	lineChartr   r   has_line_markersU  s   
zJPlotTypeInspector._differentiate_line_chart_type.<locals>.has_line_markers)r   r	   r^   r_   LINE_MARKERSra   LINE_MARKERS_STACKEDrc   LINE_MARKERS_STACKED_100re   LINELINE_STACKEDLINE_STACKED_100)rZ   r[   r   r   r   r   rU   Q  s   z0PlotTypeInspector._differentiate_line_chart_typec                 C  r|   r}   )r   rv   r_   PIE_EXPLODEDPIE)rZ   r[   ZpieChartr   r   r   r   rV   h  r   z/PlotTypeInspector._differentiate_pie_chart_typec                   sT   |j   dd d} fdd}|d u rtjS |dkr!tjS | r'tjS tjS )Nzc:radarStyler   r#   c                    (     d} | r| d ddkrdS dS Nzc:ser/c:marker/c:symbolr   r#   noneTFrv   getr   Z
radarChartr   r   	noMarkerss     
zDPlotTypeInspector._differentiate_radar_chart_type.<locals>.noMarkersZfilled)r   rv   r   r_   RADARRADAR_FILLEDRADAR_MARKERS)rZ   r[   Zradar_styler   r   r   r   rW   n  s   z1PlotTypeInspector._differentiate_radar_chart_typec                   sx   |j   fdd} fdd} dd d}|dkr,| r#tjS | r)tjS tjS |d	kr9| r6tjS tjS tjS )
Nc                     s   t  dS )Nzc:ser/c:spPr/a:ln/a:noFill)r   rv   r   ZscatterChartr   r   noLine  s   z>PlotTypeInspector._differentiate_xy_chart_type.<locals>.noLinec                    r   r   r   )symbolsr   r   r   r     r   zAPlotTypeInspector._differentiate_xy_chart_type.<locals>.noMarkerszc:scatterStyler   r#   Z
lineMarkerZsmoothMarker)	r   rv   r   r_   
XY_SCATTERXY_SCATTER_LINES_NO_MARKERSXY_SCATTER_LINESXY_SCATTER_SMOOTH_NO_MARKERSXY_SCATTER_SMOOTH)rZ   r[   r   r   Zscatter_styler   r   r   rX     s   z.PlotTypeInspector._differentiate_xy_chart_typeN)r+   r,   r-   r.   classmethodr\   rQ   rP   rR   rS   rT   rU   rV   rW   rX   r   r   r   r   rO      s,    








rO   N) r.   
__future__r   Zpptx.chart.categoryr   Zpptx.chart.datalabelr   pptx.chart.seriesr   pptx.enum.chartr   r_   pptx.oxml.nsr   pptx.oxml.simpletypesr   r	   	pptx.utilr
   objectr   r3   r6   r7   r@   rG   rH   rI   rJ   rK   rN   rO   r   r   r   r   <module>   s*    _0