POC: create InsetIndicator
patch
#27996
Draft
+210
−65
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.
PR summary
#19768 (comment) suggested that we should have some kind of container for the output of
indicate_inset[_zoom]
. #23424 (comment) suggested that it should be its own patch, drawn as a single path to avoid double-alpha where the box and connectors overlap. This PR is my attempt to implement that. In draft for now because I want to get feedback on the approach before spending time on the documentation/typing side of things.The new patch object inherits from
Rectangle
since that is the minimum that is always created. The connectors are no longer added to the axes directly but are children of this patch and available to the user via theconnectors
property. The user can therefore update properties of individual connectors: the current doctring specifically mentions updating the visibility of these, but a user might also reasonably want a different colour or linestyle for the connectors than for the box.The logic from
indicate_inset_zoom
that decides where the box should be is now methodInsetIndicator._bounds_from_inset_ax
so we can reuse it. Whenever theconnectors
attribute is accessed (including at draw) the box bounds and position of connectors (if any) get updated using the current inset axes x- and y-limits. This therefore closes #19768 and we can do things likelinewidth and linestyle for the connectors are now inherited from the parent patch when the connectors are created. Within the
draw
method, we check which connectors have the same style properties (currently four specific properties - maybe there is a better way). Those that do are drawn with the rectangle as a compound path. This therefore closes #23424.This also inadvertently fixes #23425 since I haven't implemented
get_window_extent
orget_tight_bbox
, so constrained layout will only get the tight bbox of the rectangle. I'm unclear where those methods get used outside of layout engines, so do they need to be implemented here?Currently if I do e.g.
set_edgecolor
on theInsetIndicator
patch, whether that affects the connectors depends on whether they have been accessed yet, and probably shouldn't. So that part needs a bit more thought/work.PR checklist