(
children: Mapping[str, DataTree], displays: dict[str, _DataTreeDisplay]
)
| 552 | |
| 553 | |
| 554 | def children_section( |
| 555 | children: Mapping[str, DataTree], displays: dict[str, _DataTreeDisplay] |
| 556 | ) -> str: |
| 557 | child_elements = [] |
| 558 | children_list = list(children.values()) |
| 559 | nchildren = len(children_list) |
| 560 | max_children = int(OPTIONS["display_max_children"]) |
| 561 | |
| 562 | if nchildren <= max_children: |
| 563 | # Render all children |
| 564 | for i, child in enumerate(children_list): |
| 565 | is_last = i == nchildren - 1 |
| 566 | child_elements.append(datatree_child_repr(child, displays, end=is_last)) |
| 567 | else: |
| 568 | # Truncate: show first ceil(max/2), ellipsis, last floor(max/2) |
| 569 | first_n = ceil(max_children / 2) |
| 570 | last_n = max_children - first_n |
| 571 | |
| 572 | child_elements.extend( |
| 573 | datatree_child_repr(children_list[i], displays, end=False) |
| 574 | for i in range(first_n) |
| 575 | ) |
| 576 | |
| 577 | child_elements.append(_ellipsis_element()) |
| 578 | |
| 579 | child_elements.extend( |
| 580 | datatree_child_repr(children_list[i], displays, end=(i == nchildren - 1)) |
| 581 | for i in range(nchildren - last_n, nchildren) |
| 582 | ) |
| 583 | |
| 584 | children_html = "".join(child_elements) |
| 585 | return f"<div class='xr-children'>{children_html}</div>" |
| 586 | |
| 587 | |
| 588 | def datatree_sections( |
no test coverage detected
searching dependent graphs…