Skip to content

Conversation

@lucasb-eyer
Copy link

This is mainly for mpld3, exporting figure-level text objects (such as fig.suptitle) would never get exported. It looks like figure-level text objects (and objects in general) was completely missing here. This adds text objects, I might add more in the future.

The alternative was to put figure text objects into the first axis object, but that's extremely hacky, so I went for the larger but proper fix instead.

It will fix this issue: mpld3/mpld3#296 (comment)

I did this together with gpt-5.1-codex, not alone. Here is what it has to say:

  • Exporter now emits figure-level text (suptitle + fig.text) via a dedicated draw_figure_text call before crawling axes; figure transforms passed directly to process_transform instead of shoving text into the first axes.
  • Renderer API gains a draw_figure_text hook (no-op default in base) so non-mpld3 renderers don’t break; FakeRenderer already implements it.
  • Figure JSON now carries a texts array and MPLD3Renderer serializes figure-level text entries with proper coordinates/attrs; tests cover presence/positions of exported figure texts.

This is mainly for mpld3, exporting figure-level text objects (such as
fig.suptitle) would never get exported. It looks like figure-level text
objects (and objects in general) was completely missing here. This adds
text objects, I might add more in the future.

The alternative was to put figure text objects into the first axis
object, but that's extremely hacky, so I went for the larger but proper
fix instead.

I did this together with gpt-5.1-codex, not alone. Here is what it has
to say:

- Exporter now emits figure-level text (suptitle + fig.text) via a dedicated draw_figure_text call before crawling axes; figure transforms passed directly to process_transform instead of shoving text into the first axes.
- Renderer API gains a draw_figure_text hook (no-op default in base) so non-mpld3 renderers don’t break; FakeRenderer already implements it.
- Figure JSON now carries a texts array and MPLD3Renderer serializes figure-level text entries with proper coordinates/attrs; tests cover presence/positions of exported figure texts.
lucasb-eyer added a commit to lucasb-eyer/mpld3 that referenced this pull request Nov 28, 2025
This fixes issues such as mpld3#296
and maybe more, about figure-level text (such as fig.suptitle) not appearing.

It requires the corresponding mplexporter PR to land first, and only
then I should also update the submodule commit to that here:
mpld3/mplexporter#70

It also sets up support for figure-level transforms, which we'll need to
support more figure-level objects in the future.

I put the compiled js files in a separate commit for ease of reviewing.

This, too, was co-developed with gpt-5.1-codex, but I was heavily
involved. Here is how it summarizes the changes:

- Export figure-level text (suptitle + fig.text) into the mpld3 figure JSON (texts array) via the vendored exporter/renderer, rather than shoving it into an axes.
- JS core updated to handle figure-level coordinates/text: Coordinates can work with a figure, Figure renders figuretexts into a dedicated group, and Text can draw without an axes.
- Added tests asserting figure-level texts are exported and included in the figure dict; rebuilt the JS bundle accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant