GithubHelp home page GithubHelp logo

Comments (13)

agusmba avatar agusmba commented on June 14, 2024 5

@Lucas-C The new version should allow you to use a custom css file where you could set your max-width workaround.

from mermaid.cli.

IAXES avatar IAXES commented on June 14, 2024 4

I just had to create the cssFile @matthew-piziak mentions above, then I could create my scaled output via the latest docker image (npm seems to be pulling an outdated version for some reason), via:

docker run -v $(pwd):/work \
    minlag/mermaid-cli:latest \
    -i "/work/mermaid.mmd" \
    --scale 4 \
    -o "/work/out.png" \
    -b transparent \
    --cssFile "/work/cssfile"

The only downside is that this seems to create a lot of excess horizontal border area around the image, so I just copy-paste it into something like GIMP and "crop to content". Not sure if there's a trivial way to automate this via imagemagick or some other CLI tool. Could likely (not 100% sure) achieve this via convert input.png -flatten -fuzz 1% -trim +repage output.png.

from mermaid.cli.

matthew-piziak avatar matthew-piziak commented on June 14, 2024 3

Okay, I figured it out.

Pass this to --cssFile:

#container > svg {
    max-width: 100% !important;
}

…and this to --configFile

{
  "flowchart": {
      "useMaxWidth": true
  }
}

…and finally --scale to your desired scale.

from mermaid.cli.

matthew-piziak avatar matthew-piziak commented on June 14, 2024 2

This does not work on version 0.5.1. Passing a mermaid.json to -c with {"flowchart": { "useMaxWidth": true}} still produces an image of width 130 despite passing -w 800.

Custom CSS does not work for SVGs, so one can't even render to SVG and then scale up with a different program without giving up the ability to specify, e.g. custom fonts.

from mermaid.cli.

ilyakooo0 avatar ilyakooo0 commented on June 14, 2024 1

@matthew-piziak Could you elaborate what you meant by --scale? mmdc doesn't seem to have a --scale option.

EDIT: I was using an older version of mmdc.

from mermaid.cli.

tylerlong avatar tylerlong commented on June 14, 2024

widget and height are actually web page size instead of the generated image size. For example: -w 800 -H 600 means: generate the image in a 800*600 browser window.

The cli is just a thin wrapper around the mermaid library. I guess in a real browser, you cannot change the image size either.

You can look at the code of the CLI, fewer than 100 LoC. Please share your opinions and suggestions.

from mermaid.cli.

Lucas-C avatar Lucas-C commented on June 14, 2024

I sent a PR that fixes the scaling
I still have a strange rendering bug, I'm going to open another issue for it

from mermaid.cli.

tylerlong avatar tylerlong commented on June 14, 2024

Please read the comments here: #4 (comment)

Overall this should be a mermaid issue. Mermaid doesn't allow user to manually set a width for the charts. It figures out the width according to page width and it also doesn't always take 100% of the page width.

Feel free to create an issue for the mermaid project.

from mermaid.cli.

Lucas-C avatar Lucas-C commented on June 14, 2024

Thanks for your investigations !

Have you considered the flowchart.useMaxWidth configuration entry ? cf. https://mermaidjs.github.io/mermaidAPI.html

This may be a solution, configurable from the CLI as a flag

from mermaid.cli.

agusmba avatar agusmba commented on June 14, 2024

Hi @tylerlong

It would be nice to have a way of increasing the resolution of pngs.
A working width/height options could do the trick.
Right now mermaid pngs cannot be used in documents due to their low resolution.

@Lucas-C 's fix seems to allow for better resolution sequence and flowchart graphs, but the default gantt diagram doesn't look right either at 1000 nor 2000 width.

Thank you both!

from mermaid.cli.

agusmba avatar agusmba commented on June 14, 2024

@Lucas-C I will make a PR shortly allowing mermaid configuration, so you could try flowchart.useMaxWidth

Unfortunately this is not available for sequence diagrams. In the meantime I was thinking about solving on the cli by inserting @Lucas-C fix only in the case of png, or looking at a different rendering option like using https://github.com/exupero/saveSvgAsPng

from mermaid.cli.

matthew-piziak avatar matthew-piziak commented on June 14, 2024

Reconfirmed the above on mmdc version 8.4.8.

from mermaid.cli.

connorjs avatar connorjs commented on June 14, 2024

Note: Simply using -trim worked for me. (Thanks for the tip!)

convert input.png -trim output.png

from mermaid.cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.