Skip to content

Add optional tweak per node with name placeholder#357

Open
kvid wants to merge 1 commit into
devfrom
issue349tweak
Open

Add optional tweak per node with name placeholder#357
kvid wants to merge 1 commit into
devfrom
issue349tweak

Conversation

@kvid
Copy link
Copy Markdown
Collaborator

@kvid kvid commented May 22, 2024

Implements feature suggested in #349

@kvid
Copy link
Copy Markdown
Collaborator Author

kvid commented May 22, 2024

See my newly extended #270 (comment) for a use case with example YAML input for this PR.

@kvid kvid linked an issue May 22, 2024 that may be closed by this pull request
@martinrieder
Copy link
Copy Markdown
Contributor

martinrieder commented May 23, 2024

#349 (comment)

Great to see this implemented! Now I understand how you intended to do that search & replace, though I still do not understand what the placeholder would be needed for. I think that it might make sense to have a prefix to an auto-generated designator though... What is the advantage of having a user-defined ID here?

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.

@kvid kvid force-pushed the issue349tweak branch from 3564614 to b82c7fe Compare May 29, 2024 22:19
@martinrieder
Copy link
Copy Markdown
Contributor

martinrieder commented May 30, 2024

I wrote:

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.

@kvid :
Would it make sense to include some additional examples for these tweaks with the PR, i.e. a simplified version of #325?
In case that you want to leave them undocumented (refer to Graphviz docs), should there be an additional testing folder for the GH actions to capture any issues?

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.

@kvid
Copy link
Copy Markdown
Collaborator Author

kvid commented May 30, 2024

@martinrieder wrote:

[...]

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.

True

@kvid : Would it make sense to include some additional examples for these tweaks with the PR, i.e. a simplified version of #325?

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.

In case that you want to leave them undocumented (refer to Graphviz docs),

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.

should there be an additional testing folder for the GH actions to capture any issues?

#251 will add test folders that might be what you seek.

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.

See #63

@martinrieder
Copy link
Copy Markdown
Contributor

In case that you want to leave them undocumented (refer to Graphviz docs),

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.

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.

@Crestless8
Copy link
Copy Markdown

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.

SomethingNew71 added a commit to ClassicMiniDIY/WireViz that referenced this pull request May 5, 2026
…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>
SomethingNew71 added a commit to ClassicMiniDIY/WireViz that referenced this pull request May 5, 2026
Per-connector / per-cable tweak with name placeholder (port of upstream PR wireviz#357)
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.

[feature] Add tweak option per node

3 participants