Add na.plt.dimension for mechanical-drawing distance annotations#186
Merged
Conversation
Add a `dimension` function to `named_arrays.plt` that annotates the distance between two 2D points like a mechanical drawing: extension lines from each point out to a dimension line with arrowheads at both ends, plus an auto-rotated label. The `offset` parameter displaces the dimension line perpendicular to the segment (sign selects the side) so the annotation can be moved clear of other components. Extension lines are gray and stop short of each point by a configurable `gap` fraction. The default label is the measured length rounded to `decimals` places. A unitless `offset` inherits the coordinate unit so the default `offset=0` works with unitful points. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #186 +/- ##
==========================================
+ Coverage 97.23% 97.24% +0.01%
==========================================
Files 105 105
Lines 14129 14210 +81
==========================================
+ Hits 13738 13819 +81
Misses 391 391
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The second example block uses np.array but no block imported numpy, breaking the docs build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The displacement direction and label rotation were computed in data coordinates, so with a non-equal aspect ratio the dimension line did not look perpendicular to the segment and the label was tilted at the wrong angle. Compute the perpendicular direction and label angle in display coordinates via a snapshot of the data-to-display scale ratio (sy/sx) per axes, while keeping the offset magnitude in data coordinates. With an equal aspect ratio the ratio is 1 and the behavior is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Center the label vertically on the dimension line, draw it on a background matching the axes face color, and raise its zorder so the label cleanly masks the dimension line behind it, as in a mechanical drawing. The defaults can still be overridden via kwargs_text. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When rotate=False, the label is drawn horizontally instead of being rotated to match the dimension line angle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the None->gca() default out of _display_aspect and _facecolor and into dimension, so the helpers always receive a concrete axes. This removes the per-helper None branches (which were not covered by tests) and the default is exercised once by the new test_dimension_default_ax. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
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.
Summary
Adds a
dimensionfunction tonamed_arrays.pltthat annotates the distance between two 2D points like a mechanical drawing: extension lines from each point out to a dimension line with arrowheads at both ends, plus a label that auto-rotates to align with the dimension line.Key features
offsetdisplaces the dimension line perpendicular to thea→bsegment; the sign selects the side, so the annotation can be moved clear of other components in the drawing. A unitlessoffsetinherits the coordinate unit, so the defaultoffset=0works with unitful points.gapfraction (default0.1), matching mechanical-drawing convention.|b - a|, rounded todecimalsplaces (default2).componentsviacartesian_nd, likeannotate.kwargs_extension,kwargs_dimension,kwargs_text, andarrowstyle.Built as a pure composition over the existing
plot,annotate, andtextwrappers, following thebrace_verticalpattern.Tests
Adds
test_dimensiontotests/test_plt.pycovering scalar, vectorized, nested-component, unitful/unitless, default-offset, anddecimalscases (24 parametrized cases, all passing).🤖 Generated with Claude Code