A sequence of |data.Category| objects, also having certain hierarchical graph behaviors for support of multi-level (nested) categories.
| 340 | |
| 341 | |
| 342 | class Categories(Sequence): |
| 343 | """ |
| 344 | A sequence of |data.Category| objects, also having certain hierarchical |
| 345 | graph behaviors for support of multi-level (nested) categories. |
| 346 | """ |
| 347 | |
| 348 | def __init__(self): |
| 349 | super(Categories, self).__init__() |
| 350 | self._categories = [] |
| 351 | self._number_format = None |
| 352 | |
| 353 | def __getitem__(self, idx): |
| 354 | return self._categories.__getitem__(idx) |
| 355 | |
| 356 | def __len__(self): |
| 357 | """ |
| 358 | Return the count of the highest level of category in this sequence. |
| 359 | If it contains hierarchical (multi-level) categories, this number |
| 360 | will differ from :attr:`category_count`, which is the number of leaf |
| 361 | nodes. |
| 362 | """ |
| 363 | return self._categories.__len__() |
| 364 | |
| 365 | def add_category(self, label): |
| 366 | """ |
| 367 | Return a newly created |data.Category| object having *label* and |
| 368 | appended to the end of this category sequence. *label* can be |
| 369 | a string, a number, a datetime.date, or datetime.datetime object. All |
| 370 | category labels in a chart must be the same type. All category labels |
| 371 | in a chart having multi-level categories must be strings. |
| 372 | |
| 373 | Creating a chart from chart data having date categories will cause |
| 374 | the chart to have a |DateAxis| for its category axis. |
| 375 | """ |
| 376 | category = Category(label, self) |
| 377 | self._categories.append(category) |
| 378 | return category |
| 379 | |
| 380 | @property |
| 381 | def are_dates(self): |
| 382 | """ |
| 383 | Return |True| if the first category in this collection has a date |
| 384 | label (as opposed to str or numeric). A date label is one of type |
| 385 | datetime.date or datetime.datetime. Returns |False| otherwise, |
| 386 | including when this category collection is empty. It also returns |
| 387 | False when this category collection is hierarchical, because |
| 388 | hierarchical categories can only be written as string labels. |
| 389 | """ |
| 390 | if self.depth != 1: |
| 391 | return False |
| 392 | first_cat_label = self[0].label |
| 393 | date_types = (datetime.date, datetime.datetime) |
| 394 | if isinstance(first_cat_label, date_types): |
| 395 | return True |
| 396 | return False |
| 397 | |
| 398 | @property |
| 399 | def are_numeric(self): |
no outgoing calls
searching dependent graphs…