mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.66k stars 6.62k forks source link

ZOOM!!! #1860

Open zjslqshqz opened 3 years ago

zjslqshqz commented 3 years ago

look!

QQ20210120-134214@2x

live-edito

look this live-edito

I want

When I made a more reproducible flowchart, I wanted a zoom function. Otherwise, I can only save it as a picture for zooming. .

maelstrom256 commented 3 years ago

The main problem of flowcharts is hardnailing width=100% attribute and style={max-width: …px} that render any diagram in completely useless unreadable unscrollable and unzoomable mess.

Internet full of broken recipes how to force mermaid to not forcing, but they are obsolete.

yringler commented 3 years ago

The markup puts a width="100%" - that ensures that if you have a massive flowchart, it will only be readable never be readable. It should be removed. It could be placed in a wrapper with width:100%, which would give you scrollbars.

<svg id="graph-div" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="2283.43505859375" style="max-width: 3595.38232421875px;" viewBox="0 0 3595.38232421875 2283.43505859375">
segunak commented 2 years ago

+1 on this. Have created some pretty massive diagrams only to be disappointed when it's so zoomed out nobody can really see it properly. I've played around with directives but haven't been able to find anything that affects the zoom level of a large diagram.

dgbittner-sb commented 2 years ago

Agreed. Please include zoomable results. I love this tool, but it only works with small diagrams. A medium to large database schema is completely unreadable.

oxijas commented 2 years ago

+1 also. Nice tool but not suitable for any serious flowcharts as you can not properly see the results if you have more than a few steps in your chart.

segunak commented 2 years ago

+1 also. Nice tool but not suitable for any serious flowcharts as you can not properly see the results if you have more than a few steps in your chart.

I've found the only real way around this is to make the chart vertical, and then within it have some sub graphs that you force left to right for things that must be shown horizontally. It results in some pretty gnarly diagrams code wise, but that's the only solution I've been able to employ.

0x7FFFFFFFFFFFFFFF commented 1 year ago

+1. Please considering it.

Jaciss commented 1 year ago

If you're desperate you can use d3.js to do this quickly, but it's a huge graphing/data document lib on its own so I wouldn't recommend it for regular use. Mentioned in https://github.com/mermaid-js/mermaid/issues/535#issuecomment-373736818 See this fiddle for a working demo: https://jsfiddle.net/zu_min_com/2agy5ehm/26/ Using only the zoom module (https://github.com/d3/d3-zoom) reduces size greatly but it's still not an ideal solution.

otaviosgoncalves commented 1 year ago

+1

corentinleberre commented 1 year ago

I've made a little plugin using d3 to zoom in mermaid diagram rendered in Docsify.

https://corentinleberre.github.io/docsify-mermaid-zoom/#/ https://github.com/corentinleberre/docsify-mermaid-zoom

Maybe you can reuse piece of code for your own need.

segunak commented 1 year ago

I've made a little plugin using d3 to zoom in mermaid diagram rendered in Docsify.

https://corentinleberre.github.io/docsify-mermaid-zoom/#/ https://github.com/corentinleberre/docsify-mermaid-zoom

Maybe you can reuse piece of code for your own need.

Dude, that's awesome. Good work!

guhuajun commented 1 year ago

GitHub provides the lovely zoom control (recently?)!

sequenceDiagram
  autonumber
  Alice->>John: Hello John, how are you?
  loop Healthcheck
      John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts!
  John-->>Alice: Great!
  John->>Bob: How about you?
  Bob-->>John: Jolly good!
maelstrom256 commented 1 year ago

Really. Gitlab is lacking that feature, but having a copy button at least

kraditya commented 1 year ago

You can use

  1. Obsidian app (markdown editor)
  2. Create a canvas file
  3. Add the markdown file (having the big flowchart) into the canvas file
  4. Then you can zoom into the flowchart (including zoom out, drag left, right, up, down etc) :)
DmitryGalyuk commented 1 year ago

This directive worked for me: %%{ init: { "flowchart":{ "useMaxWidth": 0 } } }%%

corbym commented 1 year ago

There's just no need for that 100%, just remove it..

philousoph commented 1 year ago

You can use

  1. Obsidian app (markdown editor)
  2. Create a canvas file
  3. Add the markdown file (having the big flowchart) into the canvas file
  4. Then you can zoom into the flowchart (including zoom out, drag left, right, up, down etc) :)

Great idea. And now you can even import a Mermaid Flowchart into Obsidian Excalidraw, which gives even a better experience. Just make sure your mermaid code is 100% correct as I spent one day searching around why it would fraw the flowchart in Notion and Typora just fine but not in Obsidian or Excalidraw. (Spoiler, it was the last empty comment-sign I had, so really in the last line.) Nearly killed me...

senese commented 11 months ago

I know this topic is kinda old, but how this was implemented yet? My guess it's that is not that hard given that Mermaid Editor already have that feature:

image

In fact, the Mermaid Editor and GitHub support for zoom were the reasons that I started to script my diagram only to find out that it doesn't have zoom in the final diagram.

Omnibus-ai commented 8 months ago

this is working as well:

<script type="module">
    
   const defaultConfig = {
   startOnLoad: true,
   securityLevel: 'loose',
   flowchart: {
   useMaxWidth: 0,
   },
   gantt: {
   useMaxWidth: 0,
   },
   }
   import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
   mermaid.initialize(defaultConfig);
    
   </script>

image

ppenguin commented 8 months ago

this is working as well:

<script type="module">
    
   const defaultConfig = {
   startOnLoad: true,
   securityLevel: 'loose',
   flowchart: {
   useMaxWidth: 0,
   },
   gantt: {
   useMaxWidth: 0,
   },
   }
   import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
   mermaid.initialize(defaultConfig);
    
   </script>

Am I correct in my understanding that this is essentially the same as what @DmitryGalyuk suggested here: https://github.com/mermaid-js/mermaid/issues/1860#issuecomment-1592879401

In other words, we can apparently use the %%{ ... }%%% syntax within the mermaid code to pass a config? (This appears to work well also in markdown preview (nvim) but not in Gitlab (actually in Gitlab the size is ok, but there are no scrollbars for the content, which makes only part of the diagram visible)) Is this documented somewhere and is there a documentation reference for the possible config attributes?

sanchezzzhak commented 4 months ago

https://github.com/sanchezzzhak/node-proxy-logger/wiki/Display-logs-mermaid.js

use mermaid to visualize how method invocation behaves under different parameters. Yes, the diagrams are not perfect, but at least something. Not the point

in this wiki, I described how to fix pan-zoom.