Add optional tweak per node with name placeholder#357
Conversation
|
See my newly extended #270 (comment) for a use case with example YAML input for this PR. |
I also realized that the templates and examples do not contain any tweaks. The automated checks would only confirm that this PR does not break any of them. |
|
I wrote:
@kvid : Taking the latter thought a bit further, I come to think of it as regression testing for solved issues... Quite a bit of work to implement though. |
|
@martinrieder wrote:
True
It would perhaps be nice with an example, but bear in mind that tweaks are mainly needed for workarounds when the ordinary functionality is not sufficient or contains errors, or to test possible new features. Hopefully, such needs will be resolved by extending the ordinary functionality in the future.
Creating tweaks does require knowledge of the Graphviz syntax, and that is a too large subject to cover in the WireViz documentation, so referring to Graphviz docs is needed.
#251 will add test folders that might be what you seek.
See #63 |
I would put some notes into syntax.md and amend those to my PR #386 then. We have seen a few requests about clustering. That is something that I would still like to add, besides the hint about the image attributes. |
Implements feature suggested in #349
|
Being able to do an invisible connector and using autogenerate would be greatly appreciated. The only way it currently works is to enumerate each virtual connector explicitly which is clunky and adds a lot of code. |
…stream PR wireviz#357) Connectors and cables can now carry their own ``tweak:`` block with the same ``override`` / ``append`` shape as the global one. The harness folds per-node tweaks into the global tweak at instantiation, with an optional placeholder substring rewritten to the node's actual designator — making it practical to author a single tweak template and apply it to many components. Example: tweak: placeholder: "@@" connectors: X1: pinlabels: [A, B] tweak: append: - "@@_extra [color=red, style=dashed];" renders X1's per-node tweak as ``X1_extra [color=red, style=dashed];`` in the .gv source. The same connector definition reused for X2 would produce ``X2_extra ...``. Placeholder semantics: * Per-node ``tweak.placeholder`` overrides the global ``tweak.placeholder``. * An empty string at the per-node level explicitly opts out of substitution for that node. * ``None`` (the default) falls back to the global placeholder. * When neither is set, no substitution happens — bare strings are appended/overridden as-written. Implementation: * DataClasses.py — ``Tweak`` gains ``placeholder: Optional[str] = None``. ``Connector`` and ``Cable`` gain ``tweak: Optional[Tweak] = None``, with ``__post_init__`` coercing a dict literal into a Tweak instance. * Harness.py — new ``Harness._extend_tweak(node)`` method, called from ``add_connector()`` and ``add_cable()``, performs the placeholder substitution and merges into ``self.tweak``. Raises ``ValueError`` if two nodes contribute conflicting overrides for the same key. * docs/syntax.md — documents per-connector / per-cable tweak fields and the new placeholder semantics. Adapted from wireviz#357 (originally by @kvid, targeting upstream ``dev``). Renamed ``extend_tweak`` to ``_extend_tweak`` to mark it private; otherwise faithful to the original logic. ``make_list`` is already in master's wv_bom so no helper backport needed. Verified: * Smoke test with placeholder ``@@`` and per-connector + per-cable ``append:`` blocks produces ``X1_extra``, ``W1_label``, ``cable W1`` in the rendered .gv (the @@'s are substituted). * build_examples.py: deterministic outputs (.gv, .bom.tsv) byte- identical to baseline (no existing example uses the new syntax, so no new substitutions fire). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per-connector / per-cable tweak with name placeholder (port of upstream PR wireviz#357)
Implements feature suggested in #349