Skip to content

Fix AutoLayoutAlgorithm re-evaluation and add nested gallery sample#23

Merged
Malcolmnixon merged 2 commits into
mainfrom
fix/auto-algorithm-nested-container-fast-path
Jul 15, 2026
Merged

Fix AutoLayoutAlgorithm re-evaluation and add nested gallery sample#23
Malcolmnixon merged 2 commits into
mainfrom
fix/auto-algorithm-nested-container-fast-path

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

This pull request significantly improves the handling and documentation of the "auto" layout algorithm option, ensuring that nested container scopes inherit and independently re-evaluate "auto" at every level, rather than resolving it once at the root. It fixes several bugs related to option inheritance and registry resolution, expands test coverage for these cases, and enhances the gallery documentation and test suite with new diagrams and explanations.

Core algorithm and bug fixes:

  • The AutoLayoutAlgorithm now builds its internal HierarchicalLayoutAlgorithm with a recursion registry that includes itself, allowing "auto" to be re-evaluated at every nested scope rather than being resolved once and locked in. This fixes bugs where nested scopes inheriting "auto" would previously throw exceptions or default to a fixed leaf algorithm. [1] [2] [3]
  • Regression tests are added and updated to prove that both the fast path (single-group delegation) and multi-group split path correctly handle "auto" inheritance and re-classification at all levels, ensuring no exceptions are thrown and the intended routing occurs. [1] [2]

Gallery and documentation updates:

  • A new example diagram (auto-deep-nested-mixed-connectivity.svg) and corresponding test are added to illustrate and verify that three-level nested containers with mixed connectivity are independently re-classified at each scope when inheriting "auto". [1] [2] [3] [4] [5]

Test and infrastructure improvements:

  • The gallery index generator is updated to use proper Markdown table formatting, preventing rendering issues.

Malcolm Nixon and others added 2 commits July 15, 2026 19:07
Fixes a KeyNotFoundException thrown when a graph explicitly declares
CoreOptions.Algorithm = auto and any nested container's own children
scope inherits that value without re-declaring an algorithm override.

Root cause: AutoLayoutAlgorithm's internal HierarchicalLayoutAlgorithm
instance was built with a leaf-only registry (layered + containment),
deliberately excluding auto to avoid infinite self-reference. When a
hierarchical-routed group's cascaded options still resolved
Algorithm=auto (the normal way a caller selects auto), the nested
engine's own top-scope resolution tried to resolve auto against that
leaf-only registry and threw.

An earlier fix in this area worked around the exception by resetting
Algorithm to the layered default before handing options to the nested
engine. That masked the crash but broke CoreOptions.Algorithm's
documented inheritance semantics: it locked in a single concrete
choice at the boundary and cascaded that fixed choice to every
descendant scope, instead of letting auto keep re-evaluating
connectivity at each level. A container whose own children mixed a
connected component with an unrelated singleton no longer got auto's
distinct layered/containment routing - it was silently flattened to
plain layered for the whole scope.

The real fix: register the AutoLayoutAlgorithm instance itself under
its own auto identifier in the registry its internal
HierarchicalLayoutAlgorithm recurses with. When a nested scope's
cascaded effective options resolve to auto, the recursion registry
now resolves back to this same instance instead of throwing,
re-running the full component classification (connected -> layered,
singleton -> containment, container -> hierarchical) at that scope -
exactly as if a caller had selected auto for it directly. This let the
two prior "reset Algorithm to layered" workarounds (single-group fast
path and multi-group split path) be reverted to their original
zero-copy, unmodified-options form, since the fix is now purely
additive at the registry level. A raw HierarchicalLayoutAlgorithm
constructed independently of AutoLayoutAlgorithm still has zero
knowledge of auto, preserving its documented independence.

Adds a regression test proving auto is re-evaluated (not just
non-throwing) at a nested scope with mixed connected/unconnected
children, alongside the existing non-throw regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nerated table

Adds AutoDeepNestedMixedConnectivity to the gallery: a three-level-deep
container whose middle and innermost scopes each mix a connected pair
with an unrelated singleton, none re-declaring CoreOptions.Algorithm.
Visually demonstrates the AutoLayoutAlgorithm fix: every level
correctly re-evaluates auto's connectivity classification instead of
being locked to a single fixed leaf algorithm.

While regenerating the gallery, found and fixed the recurring
docs/gallery/README.md blank-table-line bug at its actual source.
GalleryIndex.BuildTopIndex() called the shared AppendParagraph helper
(which always appends a trailing blank line) separately for the
table's header row and its separator row, so every regeneration
reintroduced a blank line between them - silently undoing any manual
fix applied directly to the committed Markdown, since the generator
itself was never corrected. The header and separator rows are now
written directly, matching how the data rows already were, so the
table is emitted as one contiguous Markdown block on every future
regeneration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Malcolmnixon Malcolmnixon added the bug Something isn't working label Jul 15, 2026
@Malcolmnixon
Malcolmnixon merged commit cb17753 into main Jul 15, 2026
6 checks passed
@Malcolmnixon
Malcolmnixon deleted the fix/auto-algorithm-nested-container-fast-path branch July 15, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant