Skip to content
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

SVG arrows with text disappeared on Zoom #438

Closed
FaizanAhmad1122 opened this issue Aug 10, 2023 · 19 comments · Fixed by #456, #568 or #575
Closed

SVG arrows with text disappeared on Zoom #438

FaizanAhmad1122 opened this issue Aug 10, 2023 · 19 comments · Fixed by #456, #568 or #575
Assignees
Labels

Comments

@FaizanAhmad1122
Copy link

Issue Type

  • Bug report

Description

SVG Arrows that contain text seem to disappear on Zoom. I go to your official editor as well https://rpearce.github.io/react-medium-image-zoom/?path=/story/svg--animating-square and place my svg code instead of your svg through inspect element and got the same behavior. Below is the screen recording of your official site.

Screen.Recording.2023-08-10.at.11.04.01.AM.mov

Below is the SVG code that I am trying to Zoom

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 626.29296875 489.6796875" width="1252.5859375" height="979.359375">
  <!-- svg-source:excalidraw -->
  
  <defs>
    <style class="style-fonts">
      @font-face {
        font-family: "Virgil";
        src: url("https://unpkg.com/@excalidraw/excalidraw@0.15.2/dist/excalidraw-assets/Virgil.woff2");
      }
      @font-face {
        font-family: "Cascadia";
        src: url("https://unpkg.com/@excalidraw/excalidraw@0.15.2/dist/excalidraw-assets/Cascadia.woff2");
      }
    </style>
  </defs>
  <rect x="0" y="0" width="626.29296875" height="489.6796875" fill="#ffff"></rect><g stroke-linecap="round" transform="translate(20 20.55078125) rotate(0 56.818359375 46.0390625)"><path d="M76.44 1.84 C85.17 3.54, 93.63 10.5, 99.59 16.35 C105.54 22.19, 110.29 29.57, 112.17 36.9 C114.06 44.24, 113.8 52.94, 110.9 60.34 C107.99 67.74, 102.04 76, 94.77 81.3 C87.49 86.6, 76.65 90.75, 67.24 92.15 C57.82 93.54, 47.35 92.35, 38.28 89.64 C29.2 86.93, 18.87 81.58, 12.77 75.86 C6.68 70.14, 3.38 62.93, 1.69 55.33 C0 47.72, -0.46 37.43, 2.61 30.23 C5.68 23.02, 12.85 17.08, 20.1 12.11 C27.36 7.14, 35.75 1.58, 46.16 0.4 C56.56 -0.79, 75.29 3.46, 82.55 4.99 C89.82 6.52, 90.11 8.8, 89.75 9.59 M35.64 2.79 C43.74 -0.96, 54.48 -2, 63.94 -0.74 C73.41 0.52, 84.69 5.74, 92.42 10.36 C100.16 14.97, 107.02 20.2, 110.34 26.97 C113.67 33.75, 113.56 43.07, 112.35 51 C111.13 58.94, 108.74 68.38, 103.05 74.59 C97.35 80.8, 86.83 85.62, 78.16 88.27 C69.49 90.92, 60.26 91.36, 51.04 90.48 C41.81 89.6, 30.55 87.38, 22.82 82.99 C15.09 78.6, 8.53 71.2, 4.68 64.11 C0.82 57.02, -1.35 48.06, -0.32 40.45 C0.7 32.83, 5.17 24.66, 10.82 18.44 C16.47 12.23, 29.67 5.29, 33.59 3.16 C37.51 1.03, 33.75 4.79, 34.36 5.67" stroke="#000000" stroke-width="1" fill="none"></path></g><g stroke-linecap="round" transform="translate(392.59375 20) rotate(0 67.927734375 50.771484375)"><path d="M73.65 -0.19 C83.82 -0.22, 95.32 4.01, 104.01 8.36 C112.7 12.7, 120.45 19.29, 125.8 25.89 C131.16 32.49, 135.56 40.37, 136.12 47.97 C136.69 55.57, 133.69 64.14, 129.19 71.5 C124.69 78.87, 117.51 87.27, 109.13 92.17 C100.75 97.07, 89.51 99.76, 78.91 100.92 C68.31 102.09, 55.39 101.58, 45.52 99.18 C35.66 96.78, 26.88 92.24, 19.74 86.53 C12.59 80.81, 5.68 72.47, 2.64 64.87 C-0.39 57.28, -0.58 48.52, 1.51 40.96 C3.61 33.39, 8.57 25.47, 15.22 19.48 C21.87 13.5, 31.33 8.4, 41.44 5.05 C51.54 1.69, 69.9 0.1, 75.86 -0.63 C81.82 -1.35, 77.44 -0.22, 77.21 0.69 M45.05 3.73 C54.51 0.92, 68.17 0.28, 78.84 1.45 C89.51 2.62, 100.52 6.49, 109.08 10.73 C117.64 14.96, 125.67 19.96, 130.21 26.86 C134.75 33.76, 136.83 43.91, 136.32 52.15 C135.81 60.4, 132.24 69.74, 127.14 76.32 C122.05 82.91, 114.62 87.6, 105.74 91.66 C96.85 95.73, 84.29 99.63, 73.85 100.69 C63.41 101.75, 52.54 100.93, 43.1 98.01 C33.66 95.09, 23.96 89.11, 17.22 83.17 C10.48 77.22, 5.02 70.2, 2.66 62.37 C0.3 54.54, 0.37 44.03, 3.06 36.18 C5.75 28.34, 11.66 21.06, 18.79 15.32 C25.92 9.58, 41.46 3.48, 45.84 1.75 C50.23 0.02, 44.77 3.93, 45.08 4.92" stroke="#000000" stroke-width="1" fill="none"></path></g><g mask="url(#mask-ooJ4ibF08UocumcqOa1EM)" stroke-linecap="round"><g transform="translate(145.59428097835973 59.070939438578705) rotate(0 115.39682997613369 -0.4915348908477881)"><path d="M0.15 -0.24 C38.69 -0.34, 193.23 -0.72, 231.49 -0.81 M-1.23 -1.41 C37.2 -1.27, 192.03 0.48, 230.91 0.82" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(145.59428097835973 59.070939438578705) rotate(0 115.39682997613369 -0.4915348908477881)"><path d="M202.21 11.96 C211.96 5.78, 221.05 4.29, 230.39 -0.44 M202.16 11.32 C212.6 8.26, 221.12 3.41, 231.42 0.63" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(145.59428097835973 59.070939438578705) rotate(0 115.39682997613369 -0.4915348908477881)"><path d="M202.42 -8.56 C212.06 -8.19, 221.09 -3.13, 230.39 -0.44 M202.37 -9.2 C212.71 -5.25, 221.16 -3.08, 231.42 0.63" stroke="#000000" stroke-width="1" fill="none"></path></g></g><mask id="mask-ooJ4ibF08UocumcqOa1EM"><rect x="0" y="0" fill="#fff" width="476.3879409306271" height="160.05400922027428"></rect><rect x="236.2111350633802" y="46.07940454773092" fill="#000" width="49.55995178222656" height="25" opacity="1"></rect></mask><g transform="translate(236.2111350633802 46.07940454773092) rotate(0 24.512669051224293 12.696544553246326)"><text x="24.77997589111328" y="0" font-family="Virgil, Segoe UI Emoji" font-size="20px" fill="#000000" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">Text</text></g><g mask="url(#mask-SzkdVd0dyrggj1A8lYRnx)" stroke-linecap="round"><g transform="translate(101.609375 126.671875) rotate(0 37.703125 82.224609375)"><path d="M1.16 1.1 C13.46 28.52, 62.75 137.7, 74.96 164.96 M0.32 0.63 C12.31 27.65, 61.03 135.53, 73.78 163.11" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(101.609375 126.671875) rotate(0 37.703125 82.224609375)"><path d="M54.58 140.97 C62.05 148.39, 69.93 157.55, 74.43 161.75 M51.86 142.36 C59.42 148.76, 65.4 156.07, 73.14 163.54" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(101.609375 126.671875) rotate(0 37.703125 82.224609375)"><path d="M73.25 132.45 C73.31 143.45, 73.76 156, 74.43 161.75 M70.53 133.84 C72.19 142.85, 72.24 152.87, 73.14 163.54" stroke="#000000" stroke-width="1" fill="none"></path></g></g><mask id="mask-SzkdVd0dyrggj1A8lYRnx"><rect x="0" y="0" fill="#fff" width="277.015625" height="391.12109375"></rect><rect x="82.74254608154297" y="196.396484375" fill="#000" width="113.13990783691406" height="25" opacity="1"></rect></mask><g transform="translate(82.74254608154297 196.396484375) rotate(0 56.50484466232359 13.071097182855027)"><text x="56.56995391845703" y="0" font-family="Virgil, Segoe UI Emoji" font-size="20px" fill="#000000" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">Text Arrow</text></g><g stroke-linecap="round" transform="translate(174.39453125 244) rotate(0 94.26953125 68.515625)"><path d="M118.75 17.25 M118.75 17.25 C136.41 30.62, 149.3 43.12, 164.79 51.75 M118.75 17.25 C134.22 27.86, 149.75 41.11, 164.79 51.75 M164.79 51.75 C186.66 67.31, 189.85 67.4, 164.79 86.25 M164.79 51.75 C187.4 70.11, 188.16 67.21, 164.79 86.25 M164.79 86.25 C147.25 100.24, 129.87 110.32, 118.75 119.78 M164.79 86.25 C150.71 95.77, 136.22 107.08, 118.75 119.78 M118.75 119.78 C96.45 135.91, 95.43 136.4, 71.25 119.78 M118.75 119.78 C95.24 136.6, 94.84 137.75, 71.25 119.78 M71.25 119.78 C56.5 110.18, 39.52 99.98, 23.75 86.25 M71.25 119.78 C61.78 112.63, 51.46 106.26, 23.75 86.25 M23.75 86.25 C-1.23 68.64, 1.79 69.34, 23.75 51.75 M23.75 86.25 C1.18 69.81, -2.01 68.03, 23.75 51.75 M23.75 51.75 C33.82 43.77, 48.63 33.66, 71.25 17.25 M23.75 51.75 C37.67 41.71, 52.89 30.07, 71.25 17.25 M71.25 17.25 C96 -0.01, 93.11 -1.17, 118.75 17.25 M71.25 17.25 C93.47 0.15, 96.36 -1.46, 118.75 17.25" stroke="#000000" stroke-width="1" fill="none"></path></g><g mask="url(#mask-GrRrUWX5cd0_tTvab9KPU)" stroke-linecap="round"><g transform="translate(488.734375 135.21875) rotate(0 14.822265625 92.8828125)"><path d="M-0.96 -1.04 C4.08 29.88, 25.02 155.15, 30.2 186.25 M0.74 1.03 C5.67 31.52, 24.73 153.42, 29.54 184.37" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(488.734375 135.21875) rotate(0 14.822265625 92.8828125)"><path d="M13.32 159.02 C20.33 166.8, 23.47 174.35, 30.77 182.75 M15.65 158.92 C19.5 166.51, 24.96 174.51, 30.32 185.21" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(488.734375 135.21875) rotate(0 14.822265625 92.8828125)"><path d="M33.6 155.86 C34.59 164.42, 31.68 172.91, 30.77 182.75 M35.93 155.75 C33.27 164.25, 32.21 173.27, 30.32 185.21" stroke="#000000" stroke-width="1" fill="none"></path></g></g><mask id="mask-GrRrUWX5cd0_tTvab9KPU"><rect x="0" y="0" fill="#fff" width="618.37890625" height="420.984375"></rect><rect x="406.3067092895508" y="215.6015625" fill="#000" width="194.49986267089844" height="25" opacity="1"></rect></mask><g transform="translate(406.3067092895508 215.6015625) rotate(0 97.04689681343734 12.220587964728452)"><text x="97.24993133544922" y="0" font-family="Virgil, Segoe UI Emoji" font-size="20px" fill="#000000" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">Random Text Arrow</text></g><g stroke-linecap="round" transform="translate(458.45703125 325.26171875) rotate(0 73.91796875 72.208984375)"><path d="M32 0 M32 0 C59.59 -0.4, 88.53 0.12, 115.84 0 M32 0 C54.4 -1.14, 74.38 -0.62, 115.84 0 M115.84 0 C137.69 1.49, 145.9 11.96, 147.84 32 M115.84 0 C137.47 0.64, 146.34 10.98, 147.84 32 M147.84 32 C148.28 48.33, 145.78 65.81, 147.84 112.42 M147.84 32 C146.26 58.81, 147.92 86.35, 147.84 112.42 M147.84 112.42 C149.33 133.71, 138.22 145.63, 115.84 144.42 M147.84 112.42 C149.49 133.66, 138.02 144.09, 115.84 144.42 M115.84 144.42 C97.9 143.38, 76.73 142.11, 32 144.42 M115.84 144.42 C89 144.85, 62.01 145.17, 32 144.42 M32 144.42 C10.37 142.96, -0.67 135.22, 0 112.42 M32 144.42 C10.33 146.48, 1.7 132.31, 0 112.42 M0 112.42 C0.69 85.82, -2.2 56.5, 0 32 M0 112.42 C0.4 96.54, 0.21 79.98, 0 32 M0 32 C-1.83 9.28, 9.25 -1.34, 32 0 M0 32 C-2.19 8.75, 12.95 -0.69, 32 0" stroke="#000000" stroke-width="1" fill="none"></path></g><g stroke-linecap="round"><g transform="translate(337.21484375 348.984375) rotate(0 52.912109375 13.373046875)"><path d="M0.12 0.48 C17.85 4.98, 88.64 21.82, 106.2 26.39 M-1.27 -0.31 C16.34 4.42, 87.81 23.33, 105.45 27.74" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(337.21484375 348.984375) rotate(0 52.912109375 13.373046875)"><path d="M76.39 31.24 C83.64 29.16, 94.76 29.29, 106.39 26.92 M76.04 29.84 C83.93 29.99, 92.75 29.2, 104.74 27.03" stroke="#000000" stroke-width="1" fill="none"></path></g><g transform="translate(337.21484375 348.984375) rotate(0 52.912109375 13.373046875)"><path d="M81.53 11.37 C87.19 15.05, 96.82 20.92, 106.39 26.92 M81.18 9.98 C87.65 15.55, 95.07 20.17, 104.74 27.03" stroke="#000000" stroke-width="1" fill="none"></path></g></g><mask></mask></svg>
@rpearce
Copy link
Owner

rpearce commented Aug 10, 2023

@FaizanAhmad1122 That's an interesting bug! I'll use your example and try to figure it out. I'm on parental leave with a baby, but I'll try to get to this as quickly as possible.

@rpearce rpearce self-assigned this Sep 18, 2023
@rpearce rpearce added the bug label Nov 12, 2023
@FaizanAhmad1122
Copy link
Author

@rpearce Can you please provide any update on this?

@rpearce
Copy link
Owner

rpearce commented Dec 12, 2023

@FaizanAhmad1122 Honestly, I didn't prioritize this issue in my life, and it never got done. I'll start thinking about it later tonight and see if I can get you taken care of.

Expect a response here within maximum 3 days.

Additionally, if you want to run the project locally and try to figure it out, you're more than welcome to! Contributions are welcome.

@rpearce
Copy link
Owner

rpearce commented Dec 15, 2023

@FaizanAhmad1122 After digging in to this, I have what might be an incredibly easy fix for you. On your SVG, put style="visibility:visible;", or in React, style={{ visibility: 'visible' }}.

The reason for this is, I believe, because of the use of mask IDs: id="" must be unique per document, and when I clone the SVG so we can zoom it, the IDs are all still pointing to the original SVG, but that SVG's parent has visibility: hidden; on it so that the zooming styles and whatnot can work. If you put visibility: visible on the SVG, itself, it appears to be working...

edit: it does seem like this doesn't make the animation as smooth, for the original image is visible for a moment 🤔

edit 2: if the mask ID and the url() change in the modal, it all works fine. Maybe I can do something here...

edit 3: ok, it's a little hacky, but I have a fix I'll publish.

@rpearce
Copy link
Owner

rpearce commented Dec 15, 2023

@FaizanAhmad1122 This should be fixed in react-medium-image-zoom@5.1.9, and I've added you to the All Contributors list in the README for your bug report!

Thank you for your bug report and your patience.

@andreibarabas
Copy link

andreibarabas commented Dec 26, 2023

It seems this happens as well with clipPath or pattern defs. Here is a patch I made locally, but I'm sure it can be written much nicer. what do you think @rpearce ? Something like: take all defs, append the zoom to their id, then take all attributes that reference them and use the new id?

diff --git a/dist/index.js b/dist/index.js
index cee23b0e3388becea4959619a1f5458ced7a29ba..f3765253eaf67bb9d92f44ada8e9e540647a0a4f 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -581,6 +581,20 @@ class ControlledBase extends Component {
                     });
                     maskEl.id = newId;
                 });
+                tmp.querySelectorAll('clipPath[id]').forEach(maskEl => {
+                    const newId = maskEl.id + '-zoom';
+                    tmp.querySelectorAll(`[clip-path="url(#${maskEl.id})"]`).forEach(maskedEl => {
+                        maskedEl.setAttribute('clip-path', `url(#${newId})`);
+                    });
+                    maskEl.id = newId;
+                });
+                tmp.querySelectorAll('pattern[id]').forEach(maskEl => {
+                    const newId = maskEl.id + '-zoom';
+                    tmp.querySelectorAll(`[fill="url(#${maskEl.id})"]`).forEach(maskedEl => {
+                        maskedEl.setAttribute('fill', `url(#${newId})`);
+                    });
+                    maskEl.id = newId;
+                });
                 const svg = tmp.firstChild;
                 svg.style.width = `${styleModalImg.width || 0}px`;
                 svg.style.height = `${styleModalImg.height || 0}px`;

@rpearce
Copy link
Owner

rpearce commented Dec 26, 2023

@andreibarabas Do you have an example image you can share?

@andreibarabas
Copy link

sure @rpearce. see this one.
giveaway-story (1)

@zeitderforschung
Copy link

zeitderforschung commented Jan 8, 2024

Here is another one in mermaid diagrams:

<svg>
  <g>
    <marker id="mermaid-1234_flowchart-pointEnd"></marker>
    <g>
      <path marker-end="url(#mermaid-1234_flowchart-pointEnd)"></path>
    <g>
  </g>
</svg>

@rpearce
Copy link
Owner

rpearce commented Jan 9, 2024

Thanks, y'all. I haven't gotten back to this yet.

@rpearce rpearce reopened this Jan 19, 2024
@rpearce
Copy link
Owner

rpearce commented May 14, 2024

FYI, I'm looking at fixing this in the very near future. I have a test scenario all set up, and I'll try to get it fixed ASAP.

@rpearce
Copy link
Owner

rpearce commented May 14, 2024

Ok, I think I've got this fixed by targeting clip-path, fill, mask, marker-start, marker-mid, marker-end and updating those IDs for the zoomed element.

If there are other attributes that can receive url(#foo) values, let me know. Also, I couldn't find a cleaner way to do this.

https://github.com/rpearce/react-medium-image-zoom/pull/568/files#diff-bde66ada4e7457ce1c2b9b7bda38af542b14d242e7388ff4f9da7490ad82ae21R751-R766

@rpearce
Copy link
Owner

rpearce commented May 14, 2024

@andreibarabas @zeitderforschung This has been updated and released in react-medium-image-zoom@5.2.3, and you both have been added to the all contributors list in the README for your help here. Thanks for your patience 🙇

Let me know if anything needs adjusting to help with this issue further.

@andreibarabas
Copy link

Thanks @rpearce look forward to testing it

@zeitderforschung
Copy link

zeitderforschung commented May 14, 2024

@rpearce Thank you for working on it.

I just tested it and don't know if it is a problem with the update or in my code, but this...

image

...turns into this after zooming with version 5.2.3:

image

...and here after zooming with version 5.2.2:

image

If you need more information, let me know.

Update:

I am using mermaid charts. Below the svg element, there is a style tag and the ids inside need to be rewritten with the -zoom suffix, I guess.

<svg id="mermaid-7NK7QkPDxFdxavoHEmQvkB-zoom">
    <style>
        #mermaid-7NK7QkPDxFdxavoHEmQvkB {}
    </style>
    ...
</svg>

@rpearce
Copy link
Owner

rpearce commented May 14, 2024

😅 Goodness gracious there's a lot to this all because of IDs. I'll try to account for that, as well...

This is normally the point where I say "this is the wrong solution to the problem", so I'll try to rethink it, too.

@rpearce rpearce reopened this May 14, 2024
@rpearce
Copy link
Owner

rpearce commented May 14, 2024

@zeitderforschung Can you share the source SVG with me? I won't include it in the project, and I'll take that other one shared above out, too. Nevermind, I think I got it figured out...

@rpearce
Copy link
Owner

rpearce commented May 16, 2024

@zeitderforschung Can you give react-medium-image-zoom@5.2.4 a try? I'm now also updating all SVG <style> elements' CSS to update the IDs in there when zoomed.

@zeitderforschung
Copy link

@rpearce Update 5.2.4 works like a charm! 👍🏻 Very cool, thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment