MCPcopy
hub / github.com/pydata/xarray / _build_datatree_displays

Function _build_datatree_displays

xarray/core/formatting_html.py:481–539  ·  view source on GitHub ↗
(tree: DataTree)

Source from the content-addressed store, hash-verified

479
480
481def _build_datatree_displays(tree: DataTree) -> dict[str, _DataTreeDisplay]:
482 displayed_line_count = 0
483 html_line_count = 0
484 displays: dict[str, _DataTreeDisplay] = {}
485 item_count_cache: dict[int, int] = {}
486 root = True
487 collapsed = False
488 disabled = False
489
490 html_limit = OPTIONS["display_max_html_elements"]
491 uncollapsed_limit = OPTIONS["display_max_items"]
492
493 too_many_items_section = collapsible_section(
494 "<em>Too many items to display (display_max_html_elements exceeded)</em>",
495 enabled=False,
496 collapsed=True,
497 span_grid=True,
498 )
499
500 for node in tree.subtree: # breadth-first
501 parent = node.parent
502 if parent is not None:
503 parent_display = displays.get(parent.path)
504 if parent_display is not None and parent_display.disabled:
505 break # no need to build display
506
507 item_count = _tree_item_count(node, item_count_cache)
508
509 sections, node_line_count = _datatree_node_sections(node, root)
510 new_displayed_count = displayed_line_count + node_line_count
511 new_html_count = html_line_count + node_line_count
512
513 disabled = not root and (disabled or new_html_count > html_limit)
514 if disabled:
515 sections = [too_many_items_section]
516 collapsed = True
517 else:
518 html_line_count = new_html_count
519
520 collapsed = not root and (collapsed or new_displayed_count > uncollapsed_limit)
521 if not collapsed:
522 displayed_line_count = new_displayed_count
523
524 displays[node.path] = _DataTreeDisplay(
525 node, sections, item_count, collapsed, disabled
526 )
527 root = False
528
529 # If any node is collapsed, ensure its immediate siblings are also collapsed
530 for display in displays.values():
531 if not display.disabled:
532 if any(
533 displays[child.path].collapsed
534 for child in display.node.children.values()
535 ):
536 for child in display.node.children.values():
537 displays[child.path].collapsed = True
538

Callers 1

datatree_reprFunction · 0.85

Calls 6

collapsible_sectionFunction · 0.85
_tree_item_countFunction · 0.85
_datatree_node_sectionsFunction · 0.85
_DataTreeDisplayClass · 0.85
getMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…