Closed aloisklink closed 1 year ago
Hi,
I'm the one who wrote PR https://github.com/mermaid-js/mermaid/pull/4268. Sorry about this issue.
The way the code is supposed to work is to scale the images to the width of the text in the same node by setting width=100%
in the node style. This works with most images, however for this svg it seems that it crops it instead of scaling it. I'm not an svg expert but it seems like it is because it doesn't have a viewBox
attribute. If you use this slightly modified svg with a viewBox:
<img height='100' width='100' src='data:image/svg+xml,%3Csvg viewBox=%220 0 100 100%22 xmlns=%22http://www.w3.org/2000/svg%22%3E%3Ccircle cx=%2250%22 cy=%2250%22 r=%2240%22 stroke=%22black%22 stroke-width=%223%22 fill=%22red%22 /%3E%3C/svg%3E'/>
the image is not cropped anymore. So
graph TD
B["fa:fa-car for peace"]
B-->C[fa:fa-ban forbidden]
B-->D(fa:fa-spinner);
B-->E(A fa:fa-camera-retro perhaps?);
%% Test whether embed <img> work correctly
D-->F("<img height='100' width='100' src='data:image/svg+xml,%3Csvg viewBox=%220 0 100 100%22 xmlns=%22http://www.w3.org/2000/svg%22%3E%3Ccircle cx=%2250%22 cy=%2250%22 r=%2240%22 stroke=%22black%22 stroke-width=%223%22 fill=%22red%22 /%3E%3C/svg%3E'/> <br/> Red Circle")
renders a
I am not sure how big of an issue that is?
I'm the one who wrote PR https://github.com/mermaid-js/mermaid/pull/4268. Sorry about this issue.
No worries! The image rendering improvements in PR #4268 seem really useful. To be honest, this might be my fault, I'm not an expert on SVGs, but from some quick googling, it sounds like SVGs without a viewBox
have weird behaviors, and some browsers treat them differently.
In fact, adding a viewBox
also makes the mermaid diagram work correctly on https://mermaid.live too!
I'm going to close this issue, since it sounds like missing a viewBox
in SVGs have strange behaviors in most browsers, but I'm an SVG novice, so I'm happy to re-open this if somebody more knowledgeable about SVGs/browsers chimes in.
If you use this slightly modified svg with a viewBox:
@Valentine14th, do you mind if I submit the change you've recommended to the mermaid-cli project and credit you as a Co-author? I've tested the change, and adding a viewBox
works great!
@Valentine14th, do you mind if I submit the change you've recommended to the mermaid-cli project and credit you as a Co-author? I've tested the change, and adding a
viewBox
works great!
@aloisklink Of course go ahead! Thank you!
Description
Images in flowcharts used to work fine in Mermaid v10.1.0 or before, but in Mermaid v10.2.0, the boxes are now smaller, and longer automatically expand to fit the entire image.
This was caught by
mermaid-cli
's automated visual regression tests, see https://github.com/mermaid-js/mermaid-cli/pull/541#pullrequestreview-1449884035Steps to reproduce
Copy in the code sample below in Mermaid v10.1.0 and v10.2.0 (or commit d132d26246dc480b57e74c7ed94dc984207c4895 and 9bb0cef82bba4f31878852c9bf8075964652b93f).
However, they both do not work with the mermaid.live editor. So you may find it easier to add the following patch to the
demos/flowchart.html
file:Screenshots
Working in Mermaid v10.1.0
SVG (may miss fontawesome fonts when rendered on GitHub)
PNG
Broken in Mermaid v10.2.0
SVG (may miss fontawesome fonts when rendered on GitHub)
PNG
Code Sample
Setup
Additional Context
I've done a diff on the output SVGs, after passing the SVGs through an XML prettier to make it a bit prettier:
It looks like the change was in PR https://github.com/mermaid-js/mermaid/pull/4268, or commit 9bb0cef82bba4f31878852c9bf8075964652b93f.
Edit: I've done some testing and confirmed that commit 9bb0cef82bba4f31878852c9bf8075964652b93f is the one that changed this behavior.