-
Notifications
You must be signed in to change notification settings - Fork 229
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
Embed images in SVG output #189
Conversation
It seems GraphViz only links to the image in the SVG output. This might be problematic if the output is stored in a different directory from the input, or moved afterwards. Further investigation is required. |
@kvid I'd be interesting in your input on this topic. The solution would be complete if it wasn't for the fact that the SVG, and by extension, the HTML output, depend on having a working link to the original image file. The It seems that GraphViz does not offer a way to embed images? |
0bdf57b
to
911f3ee
Compare
Here are some new discoveries that might fix the above mentioned problem with embedded images.
@kvid do you think it's a reasonable approach to convert and inject the images into the output SVG file in this way? If so, this PR should only fix the relative path issue, and I'll begin another one to work on the encoding. |
I'm a bit busy these days, and are not able to contribute as often as I want.
That looks useful, but I don't think it's much in use. I've never seen it in an HTML page.
|
Don't worry about it, I know the situation. You don't seem to have an e-mail address associated with your GitHub account (besides |
911f3ee
to
11e6729
Compare
The different approaches each have their advantages and disadvantages:
|
Ideally, the output files should be self-contained, independent of any paths to other files. Anything else just causes more trouble, and the added effort of specifying behaviors (as per the first bullet point of your post) is not really worth it IMHO. [Edit] Therefore, my final goal is to:
As you can see, I'm trying to follow the KISS principle instead of providing too much configurability... I'd rather implement this straightforward (implementation-wise), but hopefully foolproof (from the user's perspective) method, and eventuall add more output options later. |
11e6729
to
a7e75a0
Compare
Embedding images in the output SVG works 🎉 It has been tested with PNG, JPEG and animated GIFs. |
@kvid, this PR is ready for review. |
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'm sorry this review took so long time. I only had time for a minor section each day, and some of the days, I had to give up due to extremely slow response from github servers.
@kvid, this PR is ready for review.
Feel free to mark my comments as resolved if you agree, and let me know if you don't.
I'm not allowed to mark your code comments as resolved, but I've tagged with 👍 where I agree.
I am open to discussing your ideas regarding finer user control over how to handle images (embed or not, copy to output directory, ...) as a separate PR, but I would first like to have embedded images as default since it leaves no open questions (see my comment above).
Thanks!
I agree those other ideas can be handled later. Probably will most users will be happy with this PR and might not give my other ideas a high priority.
src/wireviz/wireviz.py
Outdated
@@ -209,7 +210,7 @@ def parse_file(yaml_file: str, file_out: (str, Path) = None) -> None: | |||
file_out = fn | |||
file_out = os.path.abspath(file_out) | |||
|
|||
parse(yaml_input, file_out=file_out) | |||
parse(yaml_input, file_in=Path(yaml_file).resolve(), file_out=file_out) |
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 suggest moving Path( ).resolve()
inside the parse()
function.
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.
See 6a42a30 for the new implementation and let me know what you think!
src/wireviz/wireviz.py
Outdated
@@ -251,7 +252,7 @@ def main(): | |||
file_out = args.output_file | |||
file_out = os.path.abspath(file_out) | |||
|
|||
parse(yaml_input, file_out=file_out) | |||
parse(yaml_input, file_in=Path(args.input_file).resolve(), file_out=file_out) |
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 suggest moving Path( ).resolve()
inside the parse()
function.
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.
See 6a42a30 for the new implementation and let me know what you think!
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 have included a few more suggestions, including a fix for a bug that might lead to bad replacements if one URL is a substring of another, and the former is replaced before the latter. The error is that only the substring of the latter will be replaced. E.g. if "connector.png" and "shielded_connector.png" are two of the URLs in the same SVG, then the "connector.png" part of the latter URL might be replaced by the embedded contents of the former URL.
b1e3345
to
2d7770a
Compare
Thanks for your suggestions. Don't worry about not responding earlier.. there is no obligation here. |
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.
Thanks for your suggestions. Don't worry about not responding earlier.. there is no obligation here.
I've included most of your suggestions and commented on the ones that need discussion/clarification.
Thank you for accepting most of my suggestions. I've tried answering the issues with questions, and added some more suggestions as well.
I am working on a refactoring of the WireViz CLI in #244 which will finally close #60 and will stop outputting I am using |
a02f97a
to
c900e24
Compare
Rebased on top of |
86c32ce
to
e31ed72
Compare
c900e24
to
85abf9c
Compare
85abf9c
to
6f9bb67
Compare
[Update 2020-11-16]
This PR has evolved from simply fixing how relative image paths are resolved, to embedding any images in the SVG file by default, eliminating the original issue.
Previously, paths to images were resolved relatively to the specified output file instead of the input file.
This produces errors when calling WireViz with the
-o
flag, creating output files in a different location from the input.This PR [partially, see comment below] fixes the problem.
Additionally, it eliminates the need for passing a
gv_dir
variable to theImage
class, resolving paths beforehand and passing the absolute path to theImage
class.