Skip to content

Add output_dpi option (port of upstream PR #379)#4

Merged
SomethingNew71 merged 2 commits into
port-321-stdin-stdoutfrom
port-379-output-dpi
May 5, 2026
Merged

Add output_dpi option (port of upstream PR #379)#4
SomethingNew71 merged 2 commits into
port-321-stdin-stdoutfrom
port-379-output-dpi

Conversation

@SomethingNew71
Copy link
Copy Markdown

Summary

Ports upstream PR #379 — exposes Graphviz's dpi graph attribute as a top-level WireViz YAML option, letting users render higher-resolution PNGs without changing CLI invocations.

Usage

options:
  output_dpi: 192   # 2x default → 4x pixel area in the PNG

connectors:
  ...

Default is 96.0, matching Graphviz's own default for non-PostScript renderers, so existing harnesses render at the exact same pixel dimensions they always have.

What changed

File Change
DataClasses.py New Options.output_dpi: Optional[float] = 96.0 field
Harness.py Passes dpi=str(self.options.output_dpi) into the Graphviz graph attrs in create_graph()
docs/syntax.md Documents the new option
examples/*.gv, tutorial/*.gv (23 files) Rebaselined — every .gv now carries dpi=96.0

Why the .gv rebaseline ships with this PR

Every .gv gets a single new line (dpi=96.0) on the graph attr. Without committing the rebaselined .gv files, every future build_examples.py compare run would show 23 files changed on first rebuild and force contributors to mentally filter out "oh that's just the dpi attribute." The PNG/SVG/HTML outputs are environment-dependent (graphviz version) and intentionally left as the original baseline, per the project's "owner will rebuild" convention. ex08.gv is also intentionally left at baseline because it still contains absolute image paths from the original maintainer's machine that would be worse to overwrite.

Verification

  • Default DPI: a demo harness PNG renders at 428×195 — matches pre-PR baseline.
  • output_dpi: 192: the same harness renders at 857×391 — exactly 2× linear scale, 4× pixel area, as expected.
  • build_examples.py runs cleanly across all 14 examples + 8 tutorials + 2 demos.

Differences from upstream PR wireviz#379

  • Trivial port — the upstream patch applied cleanly with only stylistic tweaks (consistent string quoting, removed extra spaces around =).
  • Added an explanatory comment on the Options.output_dpi field linking to the Graphviz docs.

Test plan

  • CI workflow passes
  • output_dpi: 192 produces 2× resolution PNG vs default
  • No visual regressions at default DPI

🤖 Generated with Claude Code

Exposes the Graphviz "dpi" graph attribute as a top-level WireViz YAML
option. Useful for boosting the resolution of PNG output beyond the
graphviz default of 96 DPI:

    options:
      output_dpi: 192   # 2x default — 4x pixel area in the PNG

Defaults to 96.0, matching graphviz's own default for non-PostScript
renderers, so existing harnesses render at the same pixel dimensions
they always have.

Files:
* DataClasses.py — Options.output_dpi: Optional[float] = 96.0
* Harness.py — pass dpi=str(self.options.output_dpi) into the graph attr
* docs/syntax.md — documents the new option under "options"
* examples/*.gv, tutorial/*.gv — rebaselined: every .gv now carries
  ``dpi=96.0``. The .png / .svg / .html outputs are environment-
  dependent (graphviz version) and intentionally left untouched, per
  CONTRIBUTING.md's "owner will rebuild" policy. ex08.gv is also
  intentionally left as baseline because it still contains absolute
  image paths from the original maintainer's machine.

Verified:
* Default DPI: demo PNG renders at 428x195 (matches pre-PR baseline).
* output_dpi=192: same harness renders at 857x391 — exactly 2x linear
  scale, 4x pixel area, as expected.
* build_examples.py runs cleanly across all examples.

Ported from wireviz#379 (originally
targeting upstream `dev` by Tobias Falk / @tobiasfalk).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new output_dpi configuration option to WireViz, enabling control over Graphviz output resolution and size units. The changes span documentation, data structures, and graph generation logic, with updates to all example and tutorial files. A review comment identifies a potential issue where null values could be incorrectly passed as the string "None" to Graphviz and suggests passing the raw value instead.

Comment thread src/wireviz/Harness.py Outdated
bgcolor=wv_colors.translate_color(self.options.bgcolor, "HEX"),
nodesep="0.33",
fontname=self.options.fontname,
dpi=str(self.options.output_dpi),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using str(self.options.output_dpi) will result in the literal string "None" being passed to Graphviz if output_dpi is explicitly set to null in the YAML configuration, which is likely invalid. Since the graphviz library handles None by omitting the attribute and automatically converts numeric types to strings, passing the value directly is more robust and allows users to opt-out of an explicit DPI setting if desired.

Suggested change
dpi=str(self.options.output_dpi),
dpi=self.options.output_dpi,

@SomethingNew71
Copy link
Copy Markdown
Author

@tobiasfalk — heads up, your upstream #379 (output_dpi option) is being incorporated here.

Context: We use WireViz to document Classic Mini Cooper wiring harnesses at Classic Mini DIY and are building a GUI on top of it. Upstream wireviz/WireViz looks abandoned (no real master commits since v0.4.1 in 2021, the dev refactor has been sitting unreleased for over a year), so we're forking and pulling in the open PRs we want.

This one was a near-faithful port — only stylistic tweaks (consistent string quoting, an explanatory comment linking to the Graphviz dpi docs). The default of 96.0 keeps existing harnesses rendering at identical pixel dimensions; verified that output_dpi: 192 produces exactly 2× linear scale in the PNG.

Commit attribution links back to your PR. Thanks for the work.

Addresses gemini-code-assist feedback on
#4 — the prior
``dpi=str(self.options.output_dpi)`` would emit the literal string
``"None"`` if a user set ``output_dpi: null`` in YAML, which Graphviz
treats as an invalid value.

The reviewer's exact suggestion (``dpi=self.options.output_dpi`` —
relying on graphviz auto-coercion of numerics) doesn't quite work
either: the graphviz Python lib filters None but does NOT auto-convert
ints/floats to strings (``dpi=192`` raises
``TypeError: expected string or bytes-like object, got 'int'``).

So compromise: build the graph attr dict, conditionally include the
dpi key only when output_dpi is not None, and stringify it ourselves.
Verified:

* ``output_dpi: 96.0`` (default) — emits ``dpi=96.0`` as before; all
  example .gv baselines remain byte-identical.
* ``output_dpi: 192``        — emits ``dpi=192``; PNG renders at 2x
  scale (857x391 vs 428x195 default).
* ``output_dpi: null``       — no dpi attr emitted; PNG renders at
  Graphviz's renderer default (96 for PNG → matches default-scale).

Also updates the DataClasses.Options.output_dpi comment to document
the null-as-defer-to-graphviz semantic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@SomethingNew71 SomethingNew71 merged commit 3d925b2 into port-321-stdin-stdout May 5, 2026
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.

1 participant