Repository navigation
feat: plot() draws arrowheads, parallel edges and loops; clearer option names - #51
Merged
Merged
Conversation
plot() drew a straight line from each vertex to each neighbour, so a directed graph looked like an undirected one, an undirected edge was drawn twice, parallel edges lay exactly on top of each other, and loops were not visible at all. Each edge is now drawn once, as an arc patch: - a directed graph has arrowheads, at the end vertex, stopping on the rim of the vertex marker - edges that join the same pair of vertices, whichever way they point, bow to either side, so parallel and antiparallel edges can all be seen - a loop is a circle at its vertex, sized in points, rotated and grown for the next one at that vertex, and not clipped by the axes - 3D plots have the same, following a rotation of the view - highlight_edge() and highlight_path() follow the arc The options are named vertex_opt, edge_opt, arrow_opt, text_opt, labels, color_components and force_2d. The 0.6.5 names (vopt, eopt, text, colorcomponents, force2d) still work, with a DeprecationWarning that names the replacement; both an old and its new name is a TypeError; the positional order is unchanged. text=False is labels=False and a text dict is text_opt. edge_opt keys that are not edge options (it took Line2D options) are reported rather than ignored. Without component colors every vertex and edge is now one color, where it had been each in turn from the color cycle. Drawing is about 2x slower than the lines it replaces: 3000 edges plot in 1.2 s and draw in 0.7 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
export(), dotfile() and the exporters took colorcomponents, which is the 0.6.5 name of a plot() option and has no underscore. They are new in 1.0 and not released, so this is a plain rename, with no deprecation. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 87 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #51 +/- ##
==========================================
+ Coverage 95.88% 96.41% +0.53%
==========================================
Files 3 3
Lines 1238 1339 +101
==========================================
+ Hits 1187 1291 +104
+ Misses 51 48 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
plot()now draws a directed graph with arrowheads, and makes parallel edges and loops visible. It also gets option names that say what they are.What was wrong
plot()drew a straight line from each vertex to each of its neighbours, so:Drawing
Each edge is drawn once, as a
FancyArrowPatch(Graph._edge_layout()decides the geometry):markersize)highlight_edge()/highlight_path()follow the arcOptions
voptvertex_opteoptedge_optarrow_opt, defaultdict(arrowstyle="-|>", mutation_scale=15)for a directed graphtextlabels: boolandtext_opt: dictcolorcomponentscolor_componentsforce2dforce_2dDeprecationWarningnaming the replacement; both an old and its new name is aTypeError; the positional order of the existing parameters is unchanged (the new ones are keyword-only).eoptwas passed toLine2D;edge_optgoes to a patch. Common keys carry over (color,linewidth,linestyle,alpha,label); a key that is not an edge option is reported with aUserWarninginstead of being silently dropped.colorcomponentsoption ofexport(),dotfile()and the exporters was new in 1.0, never released, so it is renamed outright (second commit).Behaviour changes
Tests
tests/test_plot_arrows.py(46): edges drawn once; head style and position for directed and undirected;arrow_optoverrides; arcs for parallel and antiparallel edges; loops (visible, headed, distinct, unclipped);edge_opt,vertex_opt,labels,text_opt, component colors,force_2d; every old name (warns, behaves the same, positional order, both-names error); 3D; highlight. Againstmain, 17 of the 19 drawing tests fail.test_plot_args.pymoves to the new names, so the suite emits no deprecation warnings from plot.Found on the way (not in this PR)
DGraph.nc, and soplot(),component()andsamecomponent(), loops forever for many directed graphs: the smallest is a 4-cycle (0->2->1->3->0), and a random 100-vertex digraph hangs. It is inDGraph._graphcolor's label merging, and is the same on 0.6.5. A separate fix is to follow.RTB: petercorke/robotics-toolbox-python#738 tracks adopting the new names.
🤖 Generated with Claude Code