[SC-15023] feat(figures): add title field for figures and route to caption registry#514
Conversation
Adds a `title` attribute to `Figure` so test authors can caption
charts/figures the same way they already can for tables. Test functions
can now return `{"My Chart Title": fig, ...}` (mirroring the existing
dict-of-tables convention) and the title flows through to the platform's
document media registry as `Figure N. <title>`.
Also fixes `ResultTable` serialization so its existing `title` field
actually reaches the caption registry: the registry reads
`metadata.caption` but the library was only sending `metadata.title`.
We now emit both keys (`title` kept for back-compat).
Backend/frontend already read `metadata.caption` and render captions
via the existing DocumentMediaCaption component, so no platform changes
are required.
- Figure: new optional `title`, serialized as `metadata.caption`
- ResultTable.serialize: emit `metadata.caption` alongside `metadata.title`
- FigureOutputHandler: accept `{title: fig, ...}` dicts
- Docstrings on Figure, ResultTable, and @vm.test updated
- Example notebook (implement_custom_tests) showcases titled figures
- Unit tests for new serialization + dict-of-figures handler
Refs: sc-15023
Amp-Thread-ID: https://ampcode.com/threads/T-019e3c3a-c2d2-7722-923c-e0df20ab6c97
Co-authored-by: Amp <amp@ampcode.com>
PR SummaryThis PR enhances the functionality for handling figure and table titles within the ValidMind platform. The changes focus on improving how titles are serialized into metadata as captions for both figures and tables, ensuring that they are properly rendered in the document media registry (e.g., 'Figure N. <title>' and 'Table N. <title>'). Key changes include:
These enhancements improve the clarity and utility of model documentation by providing clear, user-defined captions, and maintain backward compatibility with previous implementations. Test Suggestions
|
juanmleng
left a comment
There was a problem hiding this comment.
Really cool @johnwalz97!
What and why?
Adds a
titlefield toFigureso test authors can caption charts/figures the same way they already can for tables. Closes the gap between regular text blocks (where CKEditor figures already support captions) and test-driven blocks (where the validmind library had no way to set one).Test functions can now return
{"My Chart Title": fig, ...}— mirroring the existing dict-of-tables convention — and the title flows through to the platform's document media registry asFigure N. <title>.Also fixes a quiet bug for tables:
ResultTable.titlewas serialized asmetadata.title, but the backend caption registry readsmetadata.caption. We now emit both keys, so table titles actually reach the registry.Before: test-driven figures had no caption-registry entry; tables had a
titlebut it was only rendered as an inline<h4>heading and never reached the "Table N. " auto-numbered caption.After: both figures and tables flow titles into the registry and get auto-numbered captions in the doc.
No backend, frontend, or CKEditor changes are required — that plumbing already reads
metadata.captionand renders captions via the existingDocumentMediaCaptioncomponent.How to test
pytest tests/test_results.py— 4 new tests cover the new serialization + dict-of-figures handler (28/28 pass locally).{"My Cool Chart": some_plotly_fig}and log the result against a model with theglobal_media_captions_enabledorg setting on. The figure should render withFigure N. My Cool Chartunderneath it.notebooks/how_to/tests/custom_tests/implement_custom_tests.ipynb(theComplexOutputtest) now showcases titled figures end-to-end.What needs special review?
ResultTable.serialize()now emits bothtitleandcaptionin metadata. Worth confirming no downstream consumer (e.g. docs export, PDF generation) chokes on the extra key. None found in backend code search, but flagging for visibility.FigureOutputHandler.can_handlenow claims dicts whose values are all figure-like. It's ordered beforeTableOutputHandlerin the handler list, so dict-of-DataFrames continues to be handled by the table handler.Dependencies, breaking changes, and deployment notes
titleis a new optional field onFigurewith a default; the dict-of-figures syntax is additive.global_media_captions_enabled.Release notes
Custom tests can now title figures the same way they already title tables. Return
{"My Chart Title": fig}from a test (or passtitle="…"toFigure/ResultTable) and the title will be rendered asFigure N. My Chart Titlein the document's caption registry.Checklist