-
Notifications
You must be signed in to change notification settings - Fork 43
Freeze labels for Python-only formatters #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lucasb-eyer
wants to merge
7
commits into
mpld3:master
Choose a base branch
from
lucasb-eyer:lb-pyonly-ticklabels
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
line-style was previously ignored for line collections, this fixes it. Note that I did not add support for offset in line-style, which has not existed in the first place, and I have no need for it. There's a corresponding commit/PR in mpld3 coming. This was done together with gpt-5.1-codex (but I reviewed and edited a lot), here is what it has to say: Handle collection dasharrays in exporter - derive dash arrays from collection linestyles/dashes - carry dasharrays through export and render_path_collection so hlines/vlines/grid keep their patterns
This will allow to render both major and minor gridlines in mpld3, which fixes the following issue: mpld3/mpld3#527 As per usual, disclaimer that I co-developed this with gpt-5.1-codex, having it figure out the issues and give implementation recommendations, with me testing, verifying, and tidying up the code. Here's what it has to say, especially wrt the change in API call: - include minor tick values/length and minor grid style in axis props so minor ticks/grids render in mpld3 - read grid color/linewidth/linestyle from tick kwargs (and rcParams fallback) instead of inspecting gridlines[0], avoiding the get_gridlines(which=…) API that isn’t available on matplotlib 3.10” Rationale for the kw/rc approach: `Axis.get_gridlines()` doesn’t accept `which` on matplotlib 3.10, so probing `gridlines[0]` for minor/major fails. Pulling style from the tick keyword dict (which matplotlib populates with `grid_*` fields when you call `ax.grid(...)`) plus `rcParams` defaults gives the same style without needing `get_gridlines(which=…)`, keeping compatibility and matching user-set grid styles. (I verified, indeed get_gridlines does not allow specifying which ones - seems like an omission in matplotlib API to me)
Minor ticklabels were missing altogether,
The previous fix to make FuncFormatter work, in https://github.com/mpld3/mplexporter/pull/67/files and mpld3/mpld3@e7fa282 had two issues still: 1) the mpl FuncFormatter API also takes the index as second argument, which was missing. 2) it exported `tickvalues` only in the FixedLocator case, so these were missing for non-fixed FuncFormatter and hence the FuncFormatter codepath, which also requires them to be present, was never hit with non-fixed locators. Also add a test, and let tests import `matplotlib` via the backend-setting mechanism, not only `plt`. This fixes both. Again, this was figured out and helped with gpt-codex and my careful review+cleanup. Codex even identified the two original commits I'm linking above :)
Treat Python-only formatters (FuncFormatter, and formatter subclasses) as export-time only by precomputing tick labels and exporting tickvalues, so mpld3 doesn’t drop custom formatter subclasses. This unifies FuncFormatter and non-matplotlib Formatter subclasses under a single check, preserving existing d3 behavior for built-in formatters like Date/Log/Scalar. Adds tests for custom formatters in both exporter copies. As a disclaimer, as usual, I noticed an issue in my use, and fixed it together with gpt-5.2-codex, manually reviewing and cleaning up the changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Note: this PR builds on top of my other PRs. Only the last commit is unique, the leading commits will disappear once #73 - #75 are merged and I rebase.
Treat Python-only formatters (FuncFormatter, and formatter subclasses) as export-time only by precomputing tick labels and exporting tickvalues, so mpld3 doesn’t drop custom formatter subclasses.
This unifies FuncFormatter and non-matplotlib Formatter subclasses under a single check, preserving existing d3 behavior for built-in formatters like Date/Log/Scalar.
Adds tests for custom formatters in both exporter copies.
As a disclaimer, as usual, I noticed an issue in my use, and fixed it together with gpt-5.2-codex, manually reviewing and cleaning up the changes.