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

Ability to zoom HTML diagram #2162

Open
DrGriff opened this issue Jun 30, 2021 · 7 comments
Open

Ability to zoom HTML diagram #2162

DrGriff opened this issue Jun 30, 2021 · 7 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@DrGriff
Copy link

DrGriff commented Jun 30, 2021

Is your feature request related to a problem? Please describe.
I've created quite a large complicated flowchart with multiple subgraphs. I embed the diagram in the HTML (as described in the documentation) and am able to pass that to my colleagues. However....the webpage always fit the diagram to the page. As it's become more complex, it requires more space but the page keeps shrinking it to fit, making it harder to see, particularly on a small screen. The Zoom feature in the browser doesn't make the diagram larger.

Describe the solution you'd like
Zooming the webpage should allow me to zoom in on the diagram (with horizontal and vertical scroll bars to allow navigation around the diagram).

Describe alternatives you've considered
A larger monitor, and updating to glasses 1.1....?

Additional context

@DrGriff DrGriff added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Jun 30, 2021
@go2null
Copy link

go2null commented Oct 28, 2021

This has caused me to break up diagrams

@kokizzu
Copy link

kokizzu commented Feb 15, 2022

indeed, zoom in, zoom out, and panning is really important especially when diagram too large or screen resolution too small

@imkarrer
Copy link

imkarrer commented Apr 6, 2022

++ after all the work to do the documentation of our complicated system to demonstrate where our tech debt is, I cannot effectively leverage the created diagrams without taking a screenshot, and using an image viewer to zoom in 😭

I use the github integration which is a dream otherwise.

@artfulrobot
Copy link

This already seems to be a feature on the live editor but I can't find out how to enable it! https://mermaid-js.github.io/mermaid-live-editor/

@kkkkkxiaofei
Copy link

The similar issue has been posted since 2019, I'm hesitating to reinvent the wheel to pan my large graph or give mermaid up. 😢

@ThomasG77
Copy link

Dirty code sample to do it. Borrowed code from svg-pan-zoom used in the Live Editor (e.g https://github.com/mermaid-js/mermaid-live-editor/blob/master/src/lib/components/View.svelte#L4 and https://github.com/mermaid-js/mermaid-live-editor/blob/master/package.json#L80)

<html>
  <head>
    <style type="text/css">
      #mySvgId {
        height: 90%;
        width: 90%;
      }
    </style>
  </head>
  <body>
    <div id="graphDiv"></div>
    <script src="https://bumbu.me/svg-pan-zoom/dist/svg-pan-zoom.js"></script>
    <script type="module">
      import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
      mermaid.initialize({ startOnLoad: false });
      // Example of using the render function
      const drawDiagram = async function () {
        const element = document.querySelector('#graphDiv');
        const graphDefinition = `
          flowchart TD
          A[Christmas] -->|Get money| B(Go shopping)
          B --> C{Let me think}
          C -->|One| D[Laptop]
          C -->|Two| E[iPhone]
          C -->|Three| F[fa:fa-car Car]
        `;
        const { svg } = await mermaid.render('mySvgId', graphDefinition);
        element.innerHTML = svg.replace(/[ ]*max-width:[ 0-9\.]*px;/i , '');
        var panZoomTiger = svgPanZoom('#mySvgId', {
          zoomEnabled: true,
          controlIconsEnabled: true,
          fit: true,
          center: true
        })
      };
      await drawDiagram();
    </script>
  </body>
</html>

@samsmithnz
Copy link

This worked for me, but I had to add some code to make the SVG bigger - it kept defaulting to 150px high:

            document.getElementById('mySvgId').setAttribute("height", "1000px");
            document.getElementById('mySvgId').setAttribute("width", "2000px");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants