MCPcopy Create free account
hub / github.com/scanny/python-pptx / Category

Class Category

src/pptx/chart/data.py:509–622  ·  view source on GitHub ↗

A chart category, primarily having a label to be displayed on the category axis, but also able to be configured in a hierarchy for support of multi-level category charts.

Source from the content-addressed store, hash-verified

507
508
509class Category(object):
510 """
511 A chart category, primarily having a label to be displayed on the
512 category axis, but also able to be configured in a hierarchy for support
513 of multi-level category charts.
514 """
515
516 def __init__(self, label, parent):
517 super(Category, self).__init__()
518 self._label = label
519 self._parent = parent
520 self._sub_categories = []
521
522 def add_sub_category(self, label):
523 """
524 Return a newly created |data.Category| object having *label* and
525 appended to the end of the sub-category sequence for this category.
526 """
527 category = Category(label, self)
528 self._sub_categories.append(category)
529 return category
530
531 @property
532 def depth(self):
533 """
534 The number of hierarchy levels rooted at this category node. Returns
535 1 if this category has no sub-categories.
536 """
537 sub_categories = self._sub_categories
538 if not sub_categories:
539 return 1
540 first_depth = sub_categories[0].depth
541 for category in sub_categories[1:]:
542 if category.depth != first_depth:
543 raise ValueError("category depth not uniform")
544 return first_depth + 1
545
546 @property
547 def idx(self):
548 """
549 The offset of this category in the overall sequence of leaf
550 categories. A non-leaf category gets the index of its first
551 sub-category.
552 """
553 return self._parent.index(self)
554
555 def index(self, sub_category):
556 """
557 The offset of *sub_category* in the overall sequence of leaf
558 categories.
559 """
560 index = self._parent.index(self)
561 for this_sub_category in self._sub_categories:
562 if sub_category is this_sub_category:
563 return index
564 index += this_sub_category.leaf_count
565 raise ValueError("sub_category not in this category")
566

Callers 13

given_a_Category_objectFunction · 0.90
it_knows_its_labelMethod · 0.90
add_sub_fixtureMethod · 0.90
depth_fixtureMethod · 0.90
depth_raises_fixtureMethod · 0.90
excel_date_fixtureMethod · 0.90
idx_fixtureMethod · 0.90
index_fixtureMethod · 0.90
leaf_fixtureMethod · 0.90
num_str_fixtureMethod · 0.90
subs_fixtureMethod · 0.90
add_categoryMethod · 0.70

Calls

no outgoing calls

Tested by 10

it_knows_its_labelMethod · 0.72
add_sub_fixtureMethod · 0.72
depth_fixtureMethod · 0.72
depth_raises_fixtureMethod · 0.72
excel_date_fixtureMethod · 0.72
idx_fixtureMethod · 0.72
index_fixtureMethod · 0.72
leaf_fixtureMethod · 0.72
num_str_fixtureMethod · 0.72
subs_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…