Mermaid: Create diagrams and visualizations using text and code
mermaid-js.github.io
mermaid-js.github.io
That said, I also found the default styling and layout of the generated graphs to be far more attractive than Graphviz/dot, though I'm not sure if that's attributable to Mermaid or GitHub.
Which is to say, altogether probably a step forward, but still lots of room for improvement. Please, start with the error messages!
(You are supposed to be able to bootstrap all of UML from the very simple EMOF vocabulary but I think there are a few small missing pieces that make it non-trivial)
That's mostly an artifact of trying to create a DSL for wildly different types of graphs. A unified syntax that covers sequence diagrams, pie charts, class diagrams, and more probably wouldn't be that pleasant, so why even try. You'll see the same thing in PlantUML.
For those using VS Code, this GitHub Markdown extension also renders mermaid: https://marketplace.visualstudio.com/items?itemName=bierner....
Instead I just use GitLab where it works great. This is just an example of GitHub being a bit behind but am hopeful that they’ll eventually come up to speed. Especially since they have it in their markdown preview.
That being said, Markdown has always included the ability to insert custom HTML, because Gruber wrote it to scratch his own itch. He didn't make Markdown to hide HTML from himself, he made it to do away with all the ceremony of angle brackets, which are a PITA to type and definitely make the result harder to read from source.
From a readability standpoint, I'd prefer:
```mermaid
stateDiagram
[*] --> start
start --> zero : 0
start --> one : 1
one --> one : 0, 1
zero --> [*]
one --> [*]
```
to: <div class="mermaid">
stateDiagram
[*] --> start
start --> zero : 0
start --> one : 1
one --> one : 0, 1
zero --> [*]
one --> [*]
</div>
But I can deal with that. What discomforts me personally is the worry that something about the mermaid.js implementation will break in a future browser version.Were I compiling to SVG or PNG as part of my build tooling, I would have a lot more trust that I could maintain a working toolchain in the future.
JM2C, YMMV, &c.
For example, Latex-style formulae are usually written (for markdown renderers that support it, not GitHub) $inline$ or in $$-delimited blocks. But if you want to explain how to do that then you write `$inline$` or
```latex
$$
\foobar
$$
```
And that formats it, it doesn't execute the 'latex' (or whatever) interpreter with the contents and render its output.That has dramatically better support.
What might be cool is a graphical editor that uses Mermaid as a file format.
I wrote a tutorial for mermaid.js that you all might like :)
It includes: * the most common use cases * syntax gotchas and mnemonics for remembering them * how to style the diagrams (similar to css) * options for editors (including online ones! https://mermaid.live rocks)
Casey's Mermaid.js tutorial: https://www.happyandeffective.com/blog/realtime-collaborativ...
---
I also wrote a tutorial for graphviz (which does not have GitHub or Notion support last I checked). I'm so proud of it -- it's the most starred graphviz tutorial on GitHub
Casey's Graphviz tutorial: https://github.com/caseywatts/graphviz-tutorial
However they don't have the simplest one (a tar.gz archive where you run ./app.sh from bin folder). But at least they have AppImage.
Edit: they actually have the tar.gz option but only for arm64
[0]: https://flowchart.fun/ [1]: https://sourcetarget.email/editions/43/
I was looking at Mermaid last weekend, since a coworker has praised it a few times and I was wanting to play with it.
I think my expectation of how to use it was wrong? I typically expect to share my diagrams as .png files. The main documentation didn't seem to give much guidance in this usecase.
I ended up going to https://github.com/mermaid-js/mermaid-cli ... there didn't seem to be a simple install-and-use pathway similar to `apt` or `pip`, so I ended up trying the docker image for it. I got it working to create pngs, but I thought having to mess with docker volume mounts and defining my own aliases (`alias mermaid='docker run -u $UID -it --rm -v ~/mermaid:/data minlag/mermaid-cli -i'` so I can do `mermaid blah.mmd` in my ~/mermaid folder) was a bit cumbersome...
Just sharing to see if there's hot takes on where I went wrong, I guess. (for example, I certainly didn't extensively read the docs to understand the usage paradigm it's intended for)
By using the built-in codeblocks functionality of Markdown, Mermaid allows you to source-control the same exact graphs that you would have normally put in as images.
For me, I'm often either (1) sharing diagrams outside of github (e.g. email), as well as (2) generating a bunch of diagrams based on code or whatever, rather than defining a diagram in a markdown file. There may be better tools for those usecases. Those were what I was trying to do last weekend, too.
But I've definitely passed on adding diagrams to my .md files, or sighed at needing to add yet another imgs/ dir and files to a repo folder. My toolbelt now has another thing hanging off it!
So the desire "Turn this generated graph into a diagram for inclusion in this PDF report" would be deemed a category error: my desire is wrong.
It clearly makes some folks happy, but to me it's the antithesis of a "tool"; it's more a "website feature". Different strokes.
This way, there's no need to separately generate an image output to include into the document later on.
Different "tools".
That said, I'd love a dedicated application for diagraming, with exports to various formats for other use-cases.
npm i mermaid.cli
npm i mermaid
npm i puppeteer@latest
./node_modules/.bin/mmdc -i my_diagram.md -o my_image_name.png
Only problem was the text overhangs the bubbles in sequence diagram notes.I was excited when GitHub enabled mermaid in their markdown preview. But weird that they still don’t support it in GitHub pages. I wish they would do this as being able to use mermaid in the default pages sites will be really nice. I’m currently not able to convince scientists I work with to set up their own static site generation instead of pages, just to get mermaid working.
When I try to create large diagrams with lots of linkages and text, my laptop fans kick in, and the battery starts draining. I use a reasonably beefy macbook pro as my daily driver.
Also, VisualStudio.com supports Mermaid as well.
In the end draw.io/diagrams.net wins out as embeds the diagram in the header of a PNG, so it can be rendered by everything and edited in many ways, including the web, the desktop app or the VS Code plug in.
Then a guy on twitter and his son remixed it graphically into something truly artistic. [2]
I thank Mermaid for the overall experience b/c it let somewhat complex concepts be shown so clearly that they could be immediately understood.
And even if you don't have direct tooling support for Mermaid, you can render it in the browser using JavaScript. For example:
https://raganwald.com/2019/09/21/regular-expressions.html#fi...
The markdown is:
# Finite-State Recognizers
If we're going to compile regular expressions to finite-state
recognizers, we need a representation for finite-state recognizers.
There are many ways to notate finite-state automata. For example, state
diagrams are particularly easy to read for smallish examples:
<div class="mermaid">
stateDiagram
[*] --> start
start --> zero : 0
start --> one : 1
one --> one : 0, 1
zero --> [*]
one --> [*]
</div>
Of course, diagrams are not particularly easy to work with in
JavaScript. If we want to write JavaScript algorithms that operate on
finite-state recognizers, we need a language for describing finite-state
recognizers that JavaScript is comfortable manipulating.
IMO, the best way to use it is within a format you're already checking into git, and if you can, use a tool that compiles your diagrams into an embedded SVG at rendering time.But even if your toolchain doesn't make this easy, it's still flexible enough to get the job done.
There is a command line tool, but it downloads a browser renderer.
Hopefully someone will let me know if this has changed since I looked :)
One day, I should sit down and manually render them all to .png and update the markdown to use the .pngs instead. But today is not that day. Tomorrow isn't looking too good, either.
I'm currently evaluating whether to decouple Mermaid from the browser by using a minimal fake DOM, or just rewriting it in pure Swift. It would be nice if DocC could support Mermaid in Swift doc comments.
Like some of the other comments say (and after working with it quite a bit) it definitely has its warts. It's not super well documented, it's not as feature rich as I'd like, and the syntax can be a little wonky. All that said, it "just works" for creating simple visualizations and fit my use case near perfectly.
[0]: https://github.com/floverfelt/pom-visualizer-maven-plugin
It’s choices on where to position things are often infuriating but every visual flowchart builder has been a huge pain IMO so a text based one is super preferable even with the limitations.
What I use myself and suggest to others these days is first and foremost blockdiag and its variants (nwdiag, seqdiag, rackdiag, etc), and the very descriptive python "diagrams".
Am I wrong for wanting this?
Generalized to "Unicode art" input, with smoothed output in SVG format:
I was thinking something like this:
println 'hello world';
/* #mermaid graph TD; A-->B; A-->C; B-->D; C-->D; */
When the file is viewed in the IDE or git web host the image is rendered in the text viewer.
> The @github Markdown Preview extension for VS Code now includes Mermaid support!
and since Nim also made front page today I will share how I added mermaid.js support in my very own nimib project some time ago [1].
[0]: https://twitter.com/mattbierner/status/1522003140777701376 [1]: https://pietroppeter.github.io/nblog/drafts/mermaid_diagram....
Looking forward to this being available in more places, I'll probably start using it in my documentation.
According to a top-level comment, GitHub also supports it, too, now: https://docs.github.com/en/get-started/writing-on-github/wor...
However, if I'm putting the graph into a project in GitHub/GitLab then I'll use Mermaid as it lets me keep it inline in the markdown file itself. It's also makes it easier for other team members to maintain that graph in the documentation as it doesn't require them to run additional tooling.
Also: graphviz is good at graphs, but not every visual representation is a graph (e.g. sequence diagrams, railroad diagrams, gantt charts).
https://diagrams.mingrammer.com/ https://github.com/blushft/go-diagrams