return to table of content

Mermaid Gantt diagrams for displaying distributed traces in Markdown (2023)

random_i
13 replies
3h10m

I was a big Mermaid fan, but no longer.

It is very difficult to save the images as bitmap (.jpeg, .mpng) or vector (.svg).

You basically have to use a headless browser rendering toolkit, and guess what? The images aren't consistent (different rendering styles).

I'm switching to Graphviz (DOT-based) which can look just as nice and has tons of file save features.

sidharthv
3 replies
2h28m

We are doing some fundamental changes to how diagrams are rendered, which would enable us to support more renderers. This will enable us to do server side rendering without a browser.

The main reason why we need a browser currently is size calculations of the SVG boxes, which libraries like jsdom does not support.

doublesocket
1 replies
1h56m

FWIW I gave up trying to render SVG for our project and switched to using fabric.js (and node-canvas for server side rendering). For us it was mostly because it had far better text support.

sidharthv
0 replies
59m

fabric.js looks interesting. We should theoretically be able to add a fabric.js based renderer for mermaid once the refactoring work is done.

teruakohatu
0 replies
1h59m

Please don't take the, in my opinion, excessive criticism to heart. Mermaid is fantastic. It would be even better if it supported more renderers but as it stands to day its an invaluable tool.

strken
1 replies
3h0m

I was going to point to https://github.com/mermaid-js/mermaid-cli, but it uses puppeteer and chromium under the hood. That seems...excessive, to render an SVG.

mananaysiempre
0 replies
1h50m

SVG is in a bit of an awkward place. It’s mostly used as a graphics file format. It actually is (when opened by a web browser) a full application environment, the nonreflowable counterpart to the reflowable HTML, or the open version of Flash with worse authoring tools: there’s support for full JavaScript, MathML, CSS, animations without CSS... You can probably stick RDFa somewhere in there too. And while XML is outwardly simple, I’ve heard an XML parser author say Adobe tools exporting SVGs like to define parsed entities in the internal DTD subset (did you know XML inherited a full textual macro system from SGML?).

There’s a reason why there’s SVG then there’s SVG Tiny then (recently, not approved by any standards process) there’s SVG Tiny PS. But as far as I can tell, there still isn’t any broad agreement on what subset of SVG is sane for dumb graphics consumed by (relatively) dumb rasterizers.

thangalin
0 replies
2h7m

https://github.com/mermaid-js/mermaid/issues/2485

Mermaid diagrams do not render correctly using the following programs and libraries:

    Adobe FrameMaker 2020
    Apache Batik
    EchoSVG
    svgSalamander
    resvg
    rsvg-convert
    svglib
    prawn-svg
    CairoSVG
    ConTeXt
    QtSVG
    MS Word
    PlutoSVG

steve1977
0 replies
3h4m

I don’t disagree, but aren’t we actually using kind of a headless browser rendering toolkit for SVG anyway?

mahdi7d1
0 replies
1h40m

Graphviz is hard. I only need a graph making tool three or four times a year and when I go back to mermaid, only 5 minutes of going through the documentation get's me up to speed. But graphviz is much more complex in a way I often don't need. It's also pretty verbose; You first need to define nodes then the connections while in mermaid both are done in a single line.

However mermaid's experience and output is definitely subpar. Under the saved graphs section you find randomly saved graphs and there is no way to organize multiple graphs in the web editor.

I've even thought of writing a simple script to translate mermaid charts into dot language.

coldtea
0 replies
2h30m

It is very difficult to save the images as bitmap (.jpeg, .mpng) or vector (.svg)

Huh? It's quite trivial, and even some tools for VS Code and other environments support it.

You basically have to use a headless browser rendering toolkit, and guess what? The images aren't consistent (different rendering styles)

Is your problem saving Mermaid as images or lamenting cross browser rendering consistency?

If it's the former, why is the latter a problem? Use a single headless browser rendering toolkit and stick with it. Who said you need to use multiple and compare?

And there are other ways to do it, like exporting from an actual in-browser render, or even a VS Code extension - it can also be found in other tools based on Electron.

breck
0 replies
2h32m

I work on Scroll (https://scroll.pub), which currently compiles to HTML/TXT et cetera.

Compiling to JPG, SVG, PDF, MKV, MP4, et cetera, are high on my todo list, but I really haven't seen a standout way to do that, beyond that would run through Chromium.

I wonder if Ladybird (https://ladybird.org/) might be appropriate for that use case? Not sure if it's a new rendering engine or what.

arminiusreturns
0 replies
1h28m

May I suggest my favorite: blockdiag (including seqdiag, nwdiag, and actdiag, and rackdiag (rackdiag super slept on!))

I've evaluated every diagrams-as-code tool in existence just about, and revisit them every year or two, and I keep coming back to blockdiag. Mermaid looked nice but had many issues I ran into.

blockdiag doesn't look as pretty out of the box, but when done right it looks really good, especially as an SVG

kibwen
9 replies
3h6m

I've used mermaid from within markdown before, but the whole premise still leaves me conflicted. The original selling point of markdown is that it wasn't a markup language; it was readable text that could optionally be rendered with some extra niceties if you were reading it in something more sophisticated than a simple text field. While mermaid is undoubtedly useful as a textual language for describing graphs, the spirit of markdown would favor something that actually looked like a graph without needing to run it through a renderer, something more akin to ascii art, but with well-defined semantics such that it would produce something reasonable if you did have a renderer at hand.

fastball
7 replies
2h46m

While I agree in principle, in practice the result would probably be terrible.

Just look at tables in GFM, which mostly were designed as you propose. They look like tables even before rendering, however the experience of actually creating and editing the tables is not fun at all.

I have a horse in this race (co-founder of a markdown-based note-taking app) and to me, the benefit of markdown is easy + explicit editing, not that it looks the same in plain text vs rendered.

MajimasEyepatch
4 replies
2h16m

I agree with you on Markdown tables. They're pretty horrendous to write by hand. I wonder if there's an alternative that would be easier? Maybe something that's essentially a CSV embedded in a Markdown file? I'm sure CSV has some edge cases that could be a problem, but it's probably a decent 80/20 (or better) solution if you just want to make a quick table by hand.

macintux
2 replies
2h0m

Worth noting that Emacs makes Markdown tables pretty easy to create and format cleanly for plain text viewing, and other editors may/could/should do the same.

thechao
1 replies
1h47m

I use Sublime almost 100% now-a-days; and, it for sure isn't as nice as Emacs for editing MD tables, but multi-cursor editing does about 80% of the heavy-lifting for MD tables. I guess I could conjecture someone objecting about "really big" tables and editing them ... but, is MD really the right choice in that case?

pronoiac
0 replies
28m

Are you talking about lining up the pipeline symbols for columns? If it is, have you tried the AlignTab package?

fastball
0 replies
1h59m

I think the solution[1] used by MarkDoc is an improvement, but it does indeed start to veer towards re-inventing markup (with tag directives).

[1] https://markdoc.dev/docs/tags#table

zokier
0 replies
2h22m

I personally think the bottom line here is that markdown simply isn't intended nor well suited for anything complex such as tables or diagrams or any such things that have been bolted on afterwards.

spudlyo
0 replies
2h10m

This is one area where Emacs' Org mode really shines. The tables look good even in the terminal, and the editing experience is excellent.

jmholla
0 replies
2h9m

Yea, I have to agree. I don't agree with the title. It may be convenient to put Mermaid Gantt diagram SPECIFICATIONS in a Markdown document, but they are not great for displaying the Gantt charts in Markdown.

To me a more accurate title and summary of the article is "TIL: Mermaid Gantt diagram specifications can be embedded and processed in Markdown documents".

onehp
8 replies
4h40m

I wonder how much effort it would be to put together something expanding on this that's really friendly to new developers exploring a system. The goal would be to have something that looks more like a traditional swimlane diagram, but with human readable labelling of the connections. The open telemetry data should provide a nice skeleton and then maybe use some LLM summarisation (with access to the source code) to label what's going on.

anytime5704
1 replies
2h39m

This looks super neat.

I didn’t see anything on the page about running the tool locally (remote code analysis is a deal breaker).

Anyone know if that’s an option?

notpushkin
0 replies
1h43m

Given it's a paid service – probably not.

There are local code <-> LLM interfaces though (CLI tools, editor extensions), and if you can figure out a suitable prompt you can get pretty similar experience. (Of course, you'll also want to run an LLM locally as well)

tamiral
0 replies
2h46m

diagrams + poems sounds like a wonderful time in code reviews!

jddj
0 replies
3h46m

And a ...poem?

geysersam
0 replies
3h19m

That looks positively futuristic.

codewithcheese
0 replies
4h15m

Yes, looks like they could be adapted to create Story Maps

DavidPeiffer
0 replies
3h2m

I love diagrams to represent how systems are setup and run. At one employer, they had hundreds of spreadsheets around the network drive which often linked together via formula or VBA code, along with queries out to databases.

I built a file parser (in VBA, because that is what was available) to log every file reference to a big table, the generate graphviz code to visualize it.

It's easy to say "tons of stuff uses $datasource", but it's way better if you can show exactly how much and the impact of changes.

It was incredibly useful when we changed our domain and all network drive mappings broke.

einpoklum
5 replies
4h6m

A simple syntax for gantt charts is a nice enough idea. But I don't understand:

1. What that has to do with markdown? I mean, that syntax isn't markdown nor does it require anything markdown-related to render AFAICT.

2. What mermaid is; the link itself doesn't explain it. I think this does, sort of:

    https://mermaid.js.org/intro/
but then - how does this relate to graphviz, or gnuplot? I'm missing that information.

3. Can I get something nice-and-compilable, not JS, for rendering these gantt charts into SVGs or what-not?

refulgentis
1 replies
3h59m

#1. mermaid is a syntax for diagrams that is markdown native, in that it is designed to be fit well in MD, and shares goals like ex. a progressive upgrade from text to render that is readable in either format

#2. Graphviz and gnuplot also render diagrams

#3. Sort of like asking if you can get a Markdown renderer in not JS: most direct answer is yes. If the Q is more "can Mermaid be rendered as SVG?", yes, the render format is SVG

einpoklum
0 replies
51m

I should have probably written: Something portable and compilable to a small(ish) Unix/Windows dynamic library with an associated C header, which takes the Mermaid input and produces some kind of vector graphic output like SVG. So it can be used basically everywhere and with everything.

turnsout
0 replies
4h1m

Not a complete answer to your question, but Mermaid is a plain-text diagram format which, while far from perfect, is supported by Github. So if you're looking to include a simple chart in your Readme or Markdown docs, it's a good choice.

rhdunn
0 replies
55m

1. In markdown you can specify a language to perform syntax highlighting within code blocks -- e.g. ```java ... ```. If you use "mermaid" there you can get the mermaid plugin to render that block. This is useful when providing a system overview, etc. in a project readme file.

2. Mermaid is a diagram rendering tool similar to graphviz and D3.js. It uses a different syntax for each chart type with the intention of making it easy to write and to read when looking at markdown source.

3. You would need to use a separate program like graphviz to do the layout and generate an SVG, PNG or other file that you can reference in your markdown or other document files. If/when mermaid provides a similar capability you'll be able to use that instead.

Beijinger
0 replies
3h58m

https://nomnoml.com/ does allow export to SVG if I remember right. But does not do GNATT Diagrams AFAIK.

I just tried the LIVE Editor: https://mermaid.live/

Yes, it does allow SVG export. Nice!

jmull
4 replies
3h41m

I didn't know about Mermaid. It looks nice.

This post is a little confusing, though, because this isn't markdown. It's mermaid's own markdown-like syntax for graphs/charts.

I wasn't expecting it to run client-side.

jayd16
3 replies
3h26m

Popular (or at least relevant) markdown implementations support mermaid charts. GitHub and gitlab do, for example.

beeforpork
2 replies
4h10m

Why is the Gantt chart rendered in JavaScript on the client instead of right away by the .md > .html converter?

karolist
0 replies
3h14m

Ha, I was pondering the exact same question after reading this, for this use-case and in more widespread sense. I've came to the conclusion that it's a form of outsourcing your costs. The clients want to view your charts? They pay for it with their electricity, instead of your server doing handouts for everyone.

chad1n
0 replies
4h1m

I think that the point is to be easy to be changed, since Mermaid's first use case is to be used in building diagrams/graphs with data fetched at runtime like telemetry or finances data. I guess you can probably use Mermaid and take the resulting html and add it to the resulting document if you really want.

Beijinger
2 replies
4h7m

Nice. But the first page ot the Live Editor shows an UML diagram.

I used this in the past, found it via HN: https://nomnoml.com/

remram
0 replies
2h30m

With SVG and PNG export! And MIT licensed! Looks great, thanks.

teamx
1 replies
3h23m

We use the mermaid gantt chart to track our releases, as well as team individuals that are out of office.

Looks like this: Out of office: [John Doe] [Stacy] Release: [code freeze] [Staging date] [Release!]

pronoiac
0 replies
24m

You need at least two leading spaces to get that to render as code and preserve the layout, like:

     Out of office: 
            [John Doe]
                         [Stacy]
     Release:
            [code freeze]
                           [Staging date]
                                            [Release!]

smusamashah
1 replies
3h13m

See also https://app.markwhen.com/

Its a dedicated text-to-timeline generator. Don't know if it can be embedded or available as a library too.

mrits
1 replies
3h25m

I used mermaid for years but recently converted to Eraser.io.

BiteCode_dev
0 replies
3h19m

If mermaid came with a similar integration in IDE and collaborative tooling, would you switched back?

juujian
1 replies
4h29m

Yes, I'm not a pragmatic person. But the lives going right through the text, that would bother me so much if I was to regularly use this.

genezeta
0 replies
2h11m

It bothered me too. Apparently a single CSS addition makes it more reasonable:

    .grid .tick line { opacity: 0.3; }

xnorswap
0 replies
2h42m

I've tried this exact scenario and they're really not great.

They fall down when you want to partially collapse the trace.

Mermaid supports either fully-collapsed, which will re-order your items, or not collapsed at all.

neonsunset
0 replies
3h32m

Wow, TIL you can use Mermaid for this. This is incredibly useful, thank you!

ks2048
0 replies
58m

This blog post doesn't mention it, but the tweet that it links to contains the more interesting point: GitHub markdown supports automatically rendering these mermaid diagrams.

jdcampolargo
0 replies
3h11m

used claude to generate some diagrams, and it was insanely good!

aronhegedus
0 replies
2h57m

As an aside, Chat GPT is very good at giving you a baseline for mermaid diagrams given a technical spec/ hand drawn image