Skip to content

feat: add drawing color and transparency controls - #102

Merged
john-boyer-phd merged 5 commits into
graph-algorithms:masterfrom
kevin-lozada-santos:codex/draw-color-controls
Sep 17, 2026
Merged

john-boyer-phd merged 5 commits into
graph-algorithms:masterfrom
kevin-lozada-santos:codex/draw-color-controls

Conversation

@kevin-lozada-santos

Copy link
Copy Markdown
Contributor

Resolves #101

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Changes

Added

  • examples/classic/draw_planar_colors.py: generates all seven K5-minus-edge_<property>.png variants, changing one requested option in each call.
  • tests/test_draw_colors.py: 26 real-renderer cases across the planarity.draw() and PGraph.draw() APIs. Checks artist colors, exported PNG alpha/background pixels, combined options without labels, default reset between calls, existing figure controls, and invalid colors/unknown keywords.

Updated

  • planarity/classic/planarity.pyx: supports facecolor, transparent, vertex_facecolor, vertex_bordercolor, vertex_label_facecolor, vertex_label_bordercolor, and edge_linecolor. Applies vertex colors at the PatchCollection level, where Matplotlib renders them. Explicit export colors remain effective even when savefig.facecolor is set by a user style.
  • planarity/classic/planarity_functions.py: documents all forwarded options.
  • README.md and examples/classic/output/K5-minus-edge.png: use the black vertex-border variant after visual comparison with the old example.

The background default uses the issue's explicit #f0f0f0 value (near-white); callers can request white explicitly. Vertex and edge colors retain their Matplotlib defaults when omitted, and label rectangles remain white with black borders. transparent=True makes the saved figure/axes backgrounds transparent, while retaining visible vertex/label colors; it is not a color-key operation. If saving later without outfileName, pass transparent to savefig() directly.

Removed

None.

Testing

  • Built the actual Cython extensions locally on Windows, Python 3.11.15, with Matplotlib 3.11.2 and Agg.
  • Baseline suite: 22 passed. New tests against baseline: 22 expected failures, 4 passing controls. Rebuilt candidate and ran the full suite: 48 passed.
  • Ran the sample from a clean output directory; all seven PNGs generated and were visually inspected. Transparency additionally checked using PNG alpha values, not its appearance on a white viewer.
  • git diff --check passes.
Reproduce the validation
python -m pip install -e . pytest matplotlib networkx
MPLBACKEND=Agg python -m pytest -q
# 48 passed
mkdir color-output
cd color-output
MPLBACKEND=Agg python ../examples/classic/draw_planar_colors.py

The sample produces one PNG per requested property. The README image is a byte-for-byte copy of the generated vertex-border variant.

This targets current master. PR #98's classic-to-express rename will overlap paths; this PR does not perform that rename. Local validation covers Python 3.11 on Windows; the upstream Python/Ubuntu matrix remains separate.

@john-boyer-phd john-boyer-phd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good, thanks Kevin. Just had to adapt the zorder so that the edges wouldn't overlap the vertex border color. Good catch updating the test with the new default facecolor.

@john-boyer-phd
john-boyer-phd merged commit f4419e5 into graph-algorithms:master Sep 17, 2026
5 checks passed
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.

Express API: Enable control of colors in draw() images

2 participants