-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add optional image to connectors and cables #153
Conversation
Adding helper function for each of these with a leading <tdX> tag that instructs nested_html_table() to inject attributes to the <td> tag.
Edit: This comment is obsolete. ------------------------------ examples/ex08.yml ------------------------------
index 8437aab..75b58a3 100644
@@ -8,6 +8,8 @@ connectors:
pinlabels: [Dot, Dash, Ground]
show_pincount: false
image: ../resources/stereo-phone-plug-TRS.png
+ image_scale: true
+ image_size: [100, 100, fixed]
caption: Tip, Ring, and Sleeve
cables:
@@ -19,6 +21,8 @@ cables:
wirecount: 3
shield: SN
image: ../resources/cable-WH+BN+GN+shield.png
+ image_scale: both
+ image_size: [0, 200]
caption: Cross-section
connections: Edit: The diff above was adjusted to fit a force-pushed minor change of the example. I don't think such scalings are useful in the example harness, but only for demonstrating scaling. |
- Stereo phone plug (a slight modification of a public domain image from https://openclipart.org/detail/192396/headphones-connctor ). - Cable cross-section drawn to match the wire colors in example 08. - Make the cable jacket and shield colors match the cross-section. - Images for embedding in the connector and cable nodes are stored in a new resources folder.
It specifies how an image will use any extra space available in its cell. Allowed values are one of these strings: - FALSE : keep image its natural size. (Default) - TRUE : scale image uniformly to fit. - WIDTH : expand image width to fill. - HEIGHT : expand image height to fill. - BOTH : expand both image width and height to fill. The value is sent to Graphviz as a scale attribute to the <img> tag. Note that there is normally no extra height in the image cell.
It is a list containing minimum width and minimum height of the image cell. To obtain more available space in the image cell, this size must be set greater than the natural size of the image.
When True, enclose the image cell in a table without borders to avoid narrow borders when the fixed width is less than the node width.
a3774d5
to
9a65223
Compare
src/wireviz/Harness.py
Outdated
connector.color, '<!-- colorbar -->' if connector.color else None], | ||
connector.color, html_colorbar(connector.color)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not against this change, but it probably should be a separate PR since it is unrelated to the image issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I put it here as a separate commit just to demonstrate the power of the new functionality.
@formatc1702 requested changes in his review of wireviz#153: - Lowercase attribute values - Nested image attributes - Avoid sending the whole node object as argument to helper functions - Simplify html_size_attr() - Move the resources folder
9a65223
to
204379a
Compare
I'm very happy with how this came out! See my only comment regarding a little cheat sheet for the [not so obvious] Since the end result of this PR is very straightforward (mainly just adding lines, not many changes to existing ones), I would like to squash it all into one commit if that is OK with you. Please let me know! Thanks a lot for this contribution. |
Please see my comments in 89b730b regarding the documentation. |
Thank's for testing my PR.
Your error above tells me WireViz was called with
In the YAML input above the embedded image is 'MDB_cable.png' with an underscore, but that does not fit with the error above where Graphviz is trying to embed "MDB cable.png" with a space. I have tried your YAML above with a copy of the cable image from example 08 renamed to 'MDB_cable.png' and I'm unable to reconstruct your reported error with this YAML input. However, if I put
If you mean enclosing the filename in quotes, that is already done. Take a look in the generated Please verify that you embed a different image file than the output image file, and also verify that the image file you embed still is a valid image and not an empty file because it might have been overwritten by Graphviz in one of your early experiments. |
You are right, I just wanted to make a quick test and using the output file was a quick but bad idea. |
Don't worry. You don't have to promise anything. You decide when things are ready for release. There are always things in our lives (like family, friends, etc.) that are far more important that a software project.
I had already pushed the
Are you sure you want to require PIL to be installed? My current implementation catch the
I had already done that. I just needed a clean way to pass the directory of the
I decided to trust the strong indicator I found and pushed your suggested changes. |
It is only used during initialization in the __post_init__() function and does not need to be a proper attribute of the Image dataclass. https://docs.python.org/3/library/dataclasses.html#init-only-variables
545ce9e
to
ede29cb
Compare
f7c244a
to
dabd4ba
Compare
One last thing, and this PR will finally be merged! |
I have implemented your request, but after testing it, I have some questions: Why do you want the run-time dependencies both in
|
TBH, I am not too familiar with the processes behind |
I read the same post yesterday that you link to, and I concluded there are different opinions about the reason behind
I will update both files when that is your request, even though I don't like this double specification of the exact same information. A new issue is a good idea, and I will probably create that later today. |
Yes, probably there are two of these views in our source code right now, clashing. I think the first argument, of removing |
Please let me know when you've added the PIL dependencies (even if they're still duplicated) and implemented your suggestion that I commented on. We've talked about this before, but I'd like to know your opinion, just to be sure we agree: |
As requested by the owner, it is added to both requirements.txt and setup.py - see also issue wireviz#172 about a possible redundancy/conflict.
I have committed these changes locally, but awaits your opinion about adding the exception - see #153 (comment). I agree #172 can be fully resolved later, but please read my #172 (comment) about removing the conflict before releasing v0.2. I also agree squashing this entire PR into one commit. Can you use this as commit message, or should I add something more? Suggested commit message:
|
I have replied to your comment regarding the exception (--> leave as is, let GraphViz issue a warning). Then let's get rid of that |
OK, I have now pushed my commits without the exception.
I'm not sure I would say the solution "has settled" when only one contributor has responded and his comment is not very conclusive, but rather a bit vague... 😞
Should I do the squash rebase to keep my authorship or will that be unchanged even if you do the squashing?
IMHO, removing a conflict in |
True. But nothing is stopping us from adding
AFAIK, authorship should be preserved. Let's try. If it does not work, I will roll back, you squash, and it will be a learning experience ;)
Fine, I agree. Let's keep things transparent and split it into a new PR. |
No, I believe the current state of this branch can be used. I have checked the raw logs from the latest 3.7 and 3.8 tests, and did not find any warning outputs. That indicates importing from PIL went OK when Since this PR is only a partial solution to #27, I assume you keep #27 open so the discussions about more advanced integration of images are not so easily forgotten.
OK
OK
Good. That was also one of the reasons behind the #172 issue. |
Honestly, right now I am happy with seeing the passing builds that you linked to. There's no plan to do exhaustive testing at this point; I'd rather release first and wait for eventual bug reports... we are still at a very early stage and, unless we can somehow automate more exhaustive testing (new issue?), I will not worry too much about it. While aiming for quality is a noble goal, I'd like to focus on moving things along quickly, the way we have been (at least before my holiday). I hope you understand. |
4782da4 was squashed and merged, preserving your authorship. Thanks for this valuable addition to WireViz! 🎉 |
Add optional image to connectors and cables (#153)
This image, with an optional caption below, is displayed in the lower
section of the connector/cable node in the diagram - just above the
notes if present.
This solves the basic part of issue #27, and is a continuation of
PR #137 that was closed due to changes in the base branch.