
    ,hR                     n    d Z ddlmZmZmZmZ ddlmZ  G d de      Z G d de	      Z
 G d d	e      Zy
)ah  Category-related objects.

The |category.Categories| object is returned by ``Plot.categories`` and contains zero or
more |category.Category| objects, each representing one of the category labels
associated with the plot. Categories can be hierarchical, so there are members allowing
discovery of the depth of that hierarchy and providing means to navigate it.
    )absolute_importdivisionprint_functionunicode_literals)Sequencec                   p     e Zd ZdZ fdZd Zd Zd Zed        Z	ed        Z
ed        Zd	 Zd
 Z xZS )
Categoriesz
    A sequence of |category.Category| objects, each representing a category
    label on the chart. Provides properties for dealing with hierarchical
    categories.
    c                 8    t         t        |           || _        y N)superr	   __init___xChart)selfxChart	__class__s     U/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/chart/category.pyr   zCategories.__init__   s    j$(*    c                 L    | j                   j                  |   }t        ||      S r   )r   cat_ptsCategory)r   idxpts      r   __getitem__zCategories.__getitem__   s#    \\!!#&C  r   c              #   z   K   | j                   j                  }t        |      D ]  \  }}t        ||        y wr   )r   r   	enumerater   )r   r   r   r   s       r   __iter__zCategories.__iter__   s:     ,,&& ) 	$GC2s##	$s   9;c                 .    | j                   j                  S r   )r   cat_pt_countr   s    r   __len__zCategories.__len__$   s    
 ||(((r   c                 x    | j                   j                  }|y|j                  yt        |j                        S )z
        Return an integer representing the number of hierarchical levels in
        this category collection. Returns 1 for non-hierarchical categories
        and 0 if no categories are present (generally meaning no series are
        present).
        r      )r   catmultiLvlStrReflenlvls)r   r#   s     r   depthzCategories.depth+   s8     ll;%388}r   c                 Z   | j                   j                  }|y|j                  $t        | D cg c]  }|j                  f c}      S t        | j                         D cg c].  }t        t        |      D cg c]  }|j                   c}      0 c}}      S c c}w c c}w c c}}w )a  
        Return a sequence of tuples, each containing the flattened hierarchy
        of category labels for a leaf category. Each tuple is in parent ->
        child order, e.g. ``('US', 'CA', 'San Francisco')``, with the leaf
        category appearing last. If this categories collection is
        non-hierarchical, each tuple will contain only a leaf category label.
        If the plot has no series (and therefore no categories), an empty
        tuple is returned.
         )r   r#   r$   tuplelabel_iter_flattened_categoriesreversed)r   r#   categoryflat_cats       r   flattened_labelszCategories.flattened_labels:   s     ll;%DA8>>+ABB !% ? ? A hx6HI(x~~IJ
 	
 B Js   B"B'
9B"	B'
"B'
c                     | j                   j                  }|g S |j                  D cg c]  }t        |       c}S c c}w )a  
        Return a sequence of |CategoryLevel| objects representing the
        hierarchy of this category collection. The sequence is empty when the
        category collection is not hierarchical, that is, contains only
        leaf-level categories. The levels are ordered from the leaf level to
        the root level; so the first level will contain the same categories
        as this category collection.
        )r   r#   r&   CategoryLevel)r   r#   lvls      r   levelszCategories.levelsS   s:     ll;I.1hh7sc"777s   >c              #   v   K   | j                   }|sy|d   |dd }}|D ]  }| j                  |f|        yw)aw  
        Generate a ``tuple`` object for each leaf category in this
        collection, containing the leaf category followed by its "parent"
        categories, e.g. ``('San Francisco', 'CA', 'USA'). Each tuple will be
        the same length as the number of levels (excepting certain edge
        cases which I believe always indicate a chart construction error).
        Nr   r"   )r4   
_parentage)r   r4   
leaf_levelremaining_levelsr.   s        r   r,   z%Categories._iter_flattened_categoriesb   sP      '-ay&*$
" 	AH//8+/?@@	As   79c                     |st        |      S |d   st        |      S |d   |dd }}|d   }|d   }|D ]  }|j                  |j                  kD  r n|}! t        |      |fz   }| j                  ||      S )a  
        Return a tuple formed by recursively concatenating *categories* with
        its next ancestor from *levels*. The idx value of the first category
        in *categories* determines parentage in all levels. The returned
        sequence is in child -> parent order. A parent category is the
        Category object in a next level having the maximum idx value not
        exceeding that of the leaf category.
        r   r"   N)r*   r   r6   )	r   
categoriesr4   parent_levelr8   	leaf_nodeparentr.   extended_categoriess	            r   r6   zCategories._parentageq   s     $$ ay$$)/F12J&qM	
 a$ 	H||imm+F	
 $J/6);24DEEr   )__name__
__module____qualname____doc__r   r   r   r    propertyr'   r0   r4   r,   r6   __classcell__)r   s   @r   r	   r	      sd    !$
)   
 
0 8 8AFr   r	   c                   >    e Zd ZdZd ZddZed        Zed        Zy)r   z
    An extension of `str` that provides the category label as its string
    value, and additional attributes representing other aspects of the
    category.
    c                 b    |dn|j                   j                  }t        j                  | |      S )N )vtextstr__new__)clsr   argscategory_labels       r   rK   zCategory.__new__   s&    !zrttyy{{3//r   Nc                 .    |x| _         | _        || _        y)z
        *idx* is a required attribute of a c:pt element, but must be
        specified when pt is None, as when a "placeholder" category is
        created to represent a missing c:pt element.
        N)_element_pt_idx)r   r   r   s      r   r   zCategory.__init__   s     $&%	r   c                 ^    | j                   | j                  S | j                   j                  S )a  
        Return an integer representing the index reference of this category.
        For a leaf node, the index identifies the category. For a parent (or
        other ancestor) category, the index specifies the first leaf category
        that ancestor encloses.
        )rQ   rR   r   r   s    r   r   zCategory.idx   s&     8899xx||r   c                     t        |       S )z@
        Return the label of this category as a string.
        )rJ   r   s    r   r+   zCategory.label   s    
 4yr   r   )	r?   r@   rA   rB   rK   r   rC   r   r+   r)   r   r   r   r      s9    0 	 	  r   r   c                   "    e Zd ZdZd Zd Zd Zy)r2   a   
    A sequence of |category.Category| objects representing a single level in
    a hierarchical category collection. This object is only used when the
    categories are hierarchical, meaning they have more than one level and
    higher level categories group those at lower levels.
    c                      |x| _         | _        y r   )rP   _lvl)r   r3   s     r   r   zCategoryLevel.__init__   s    $''	r   c                 F    t        | j                  j                  |         S r   )r   rW   pt_lst)r   offsets     r   r   zCategoryLevel.__getitem__   s    		((011r   c                 @    t        | j                  j                        S r   )r%   rW   rY   r   s    r   r    zCategoryLevel.__len__   s    499##$$r   N)r?   r@   rA   rB   r   r   r    r)   r   r   r2   r2      s    (2%r   r2   N)rB   
__future__r   r   r   r   pptx.compatr   r	   rJ   r   r2   r)   r   r   <module>r^      s@    S R  @F @FF%s %P%H %r   