General html rep for anndata-similar objects #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add ObjectFormatter for full HTML repr customization
Builds on #2236
Summary
This PR introduces
ObjectFormatter, a new extension point that allows packages with fundamentally different structures (like SpatialData) to fully customize the HTML representation while reusing anndata's styling and infrastructure.Live Demo - See the SpatialData example (test case 20) alongside MuData and other examples.
Motivation
While
SectionFormatterworks well for packages that extend AnnData (like MuData with its.modsection), packages like SpatialData have completely different architectures:images,labels,points,shapes,tables)obs_names/var_names(usescoordinate_systemsinstead)Changes
New Extension Point:
ObjectFormatterAdded to
src/anndata/_repr/registry.py:New Configuration Classes
HeaderConfig- Customize type name, shape, badges, file path, README iconIndexPreviewConfig- Customize index preview section contentUpdated
generate_repr_htmlThe function now checks for registered
ObjectFormatters and uses them to control:HeaderConfig)IndexPreviewConfig)Visual Test: SpatialData Example
Added a comprehensive SpatialData test case demonstrating:
SpatialDataObjectFormatterfor full customizationSectionFormatters for each element type (images, labels, points, shapes, tables)Extension Points Summary
TypeFormatterSectionFormatterObjectFormatter