Skip to content

Chore: decouple figure class #677

Description

@cvanelteren

The figure class is currently doing too many things. Code could be separated more cleanly by adding interface to sub tasks.

Will need to think about how to do this. The changes would need to not yield user facing changes. API must remain the same. Will update this as I get a better overview.

After looking at this for a while. I think these are prime candidates:

  • SubplotManager: (standalone, only needs gridspec)
  • PanelManager: SubplotManager, gridspec
  • SharingManager: LayoutManager (border axes)
  • LabelsManager: LayoutManager (coords), SharingManager (share levels)
  • LayoutManager: LabelsManager (alignment calls in auto_layout)

The idea is to compose rather to inherent to build building blocks over complex inheritance.

EDIT: Added short description of what each component would need.

Panel placement and GridSpec integration

PanelManager → SubplotManager, GridSpec

Manage panel creation, registration, stacking, spans, and parent–panel relationships.
Use SubplotManager for axes ownership/iteration and GridSpec for allocating or resizing
panel slots.

Border-aware axis sharing

SharingManager → LayoutManager

Own share-level normalization, compatible-axis grouping, limit sharing, and tick-label
visibility. Query LayoutManager for current border axes so labels remain only on the
appropriate outer edges, including panels.

Shared-label positioning

LabelsManager → LayoutManager, SharingManager

Manage super, spanning, subset, and explicitly shared labels. Obtain coordinates and
bounding-box offsets from LayoutManager, and use effective share levels/groups from
SharingManager to decide which labels exist and which axes they represent.

Automatic layout orchestration

LayoutManager → LabelsManager

Own auto_layout, renderer access, border-axis discovery, aspect adjustment, and tight-
layout passes. Invoke LabelsManager alignment after each geometry-changing pass so
labels reflect final axes positions.

Key limitation: LabelsManager ↔ LayoutManager creates a circular dependency. Prefer
making LayoutManager a geometry service and letting Figure.auto_layout() coordinate
layout passes and LabelsManager.align(...) calls. This keeps both managers
independently testable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions