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
71.01k stars 6.38k forks source link

Export image/svg sometime have big blank space on top and bottom #2649

Open nhymxu opened 2 years ago

nhymxu commented 2 years ago

Describe the bug Sometime, when I write very long sequence diagram, export image or svg always have big blank space on top/bottom image/svg.

I don't want this.

To Reproduce Steps to reproduce the behavior:

  1. Go to Bug link
  2. Click on Actions at Left-side panel
  3. Keep PNG size: auto (default)
  4. Click download PNG button
  5. Open image and see error

Expected behavior Not have blank space on top/bottom of image/svg

Screenshots

Screen Shot 2022-01-06 at 16 30 50

Desktop (please complete the following information):

Suggest solution When using inspector I found that image

SVG element on DOM have large height: 3637

So when export, export function using this height https://github.com/mermaid-js/mermaid-live-editor/blob/18a83a807a6ace0cda4d6d3f6008b7c9d87ea3d0/src/lib/components/actions.svelte#L26-L29

If svg element not have this attribute => export function will re-calculate and using fitable height. image

See, so new code maybe:

        const svg: HTMLElement = document.querySelector('#container svg');
        svg.removeAttribute('height');
        const box: DOMRect = svg.getBoundingClientRect();
        canvas.width = box.width;
        canvas.height = box.height;
sidharthv96 commented 2 years ago

Had some discussions in https://github.com/mermaid-js/mermaid-live-editor/pull/567