Add output_dpi option (port of upstream PR #379)#4
Conversation
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>
There was a problem hiding this comment.
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.
| bgcolor=wv_colors.translate_color(self.options.bgcolor, "HEX"), | ||
| nodesep="0.33", | ||
| fontname=self.options.fontname, | ||
| dpi=str(self.options.output_dpi), |
There was a problem hiding this comment.
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.
| dpi=str(self.options.output_dpi), | |
| dpi=self.options.output_dpi, |
|
@tobiasfalk — heads up, your upstream #379 ( 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 This one was a near-faithful port — only stylistic tweaks (consistent string quoting, an explanatory comment linking to the Graphviz 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>
Summary
Ports upstream PR #379 — exposes Graphviz's
dpigraph attribute as a top-level WireViz YAML option, letting users render higher-resolution PNGs without changing CLI invocations.Usage
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
DataClasses.pyOptions.output_dpi: Optional[float] = 96.0fieldHarness.pydpi=str(self.options.output_dpi)into the Graphviz graph attrs increate_graph()docs/syntax.mdexamples/*.gv,tutorial/*.gv(23 files).gvnow carriesdpi=96.0Why the .gv rebaseline ships with this PR
Every
.gvgets a single new line (dpi=96.0) on thegraphattr. Without committing the rebaselined.gvfiles, every futurebuild_examples.py comparerun 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.gvis 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
output_dpi: 192: the same harness renders at 857×391 — exactly 2× linear scale, 4× pixel area, as expected.build_examples.pyruns cleanly across all 14 examples + 8 tutorials + 2 demos.Differences from upstream PR wireviz#379
=).Options.output_dpifield linking to the Graphviz docs.Test plan
output_dpi: 192produces 2× resolution PNG vs default🤖 Generated with Claude Code