Mermaid: Flowchart - add a default root element to prevent "lone trees"

Created on 2 Dec 2019  路  12Comments  路  Source: mermaid-js/mermaid

Hi and sorry if this request has already been sent.
Could you add a feature to flowchart (at least) that would allow a node to become the "default root element" of every trees in the flowchart.

For example, this flowchart could become this beautiful by defining the "A" node as the default root of every trees in the flowchart.

Thanks for your great work with mermaid!

Flow Pending Enhancement

Most helpful comment

I think this is solved by post processing of the graph before being fed into Mermaid. I believe that Mermaid should not know or care about what trees are unbound from each other.

All 12 comments

I don't quite see the benefit over just actually writing the connections to the "root element" if that's what you wish your flowchart to represent.

Thanks for your answer.
In fact, I'm generating quite complex trees and I can't determine in advance if a node is isolated or part of the "big tree".
To do so, I would need to parse my own data as a tree, which I have delegated to mermaid ;)
I hope this clarifies why I'm requesting this feature...

Would be nice, once the root element defined, to be also able to define the link style to use to connect the isolated nodes to the root element.
View this commented example.

Something like:
rootNode A -.-

I might be wrong about what is needed here, or maybe I just don't get it :)

But, given that a node only knows its connections to other nodes AFAIK, I guess it would be difficult to determine which node is the root of a "lone tree". If my assumptions are true, what about STEP 3, 22 and 23 then? These are obviously not "lone trees", but how can the model get to know that?

Basically, given a node X, if you find no other node in the graph connecting to node X you could assume they are lone and need a connection from the root node, if there's any...

To be fair, I don' think this actually fits what a flowchart is for. It would basically connect flowcharts that should be separate to the same "root node". Is this a supported feature in any other flowchart solution?

We'll see if it gathers popularity with time (if other people have the same requirement) and what other contributors think. Withholding the Status: Approved and Help wanted labels for now.

Thanks for your answers and sorry for my not-good-enough-english to explain you this better.
I don't know if other flowchart solution have this feature.

This is how I see things:
1- Given this model. You can see 3 distinct graphs.

2- We tell mermaid that the A (START OF THE FLOW) node is the default root element.

3- Mermaid then searches every top nodes of all trees (except A, now, defined as the root element). We have "TREE1", "TREE2" and "STEP23".

4- Seing the node "TREE1", mermaid determines that it is not connected to the root element yet, so it links it. We now got this model.

5- Next top node: "TREE2". As in the 4th step above, mermaid links it to the root element leading to this model.

6- Last top node: "STEP23". Mermaid sees that this node is already linked to the root element via the "STEP23 -> STEP21 -> TREE2 -> root" path. So it does nothing more :)

I understand this might be a complex request and, as said, I could do this on my side parsing my data and adding the connections manually.

@etimau Your English is more than fine! Don't worry! We understand the request and, implementation complexity aside, we'll see if other people have the same requirement as you and what other contributors think about it.

I think I understand what you want to achieve but not really why you want to do this. What data are you parsing and how? Just curious.

I think this is solved by post processing of the graph before being fed into Mermaid. I believe that Mermaid should not know or care about what trees are unbound from each other.

I think this is solved by post processing of the graph before being fed into Mermaid. I believe that Mermaid should not know or care about what trees are unbound from each other.

Totally agree on that. Regarding the introduction statement in the README:

Generate diagrams, charts, graphs or flows from markdown-like text via javascript.

This is the scope of the library. mermaid expects to become valid input data and should not be responsible for doing any unstated behaviour like connecting/unbounding trees or anything like that. As a user I would consider this as unintended behaviour if mermaid does any magic in the background about your definition.

I think I understand what you want to achieve but not really why you want to do this. What data are you parsing and how? Just curious.

I'm parsing execution plans of a MVS: executing a JCL generates a JOR and I use this JOR to draw the execution graph.
My parser just interprets the JCL instructions that have been executed (a STEP is then present in the JOR). I make some simple pre processing before writing the markdown-like definition for Mermaid.
I don't have a tree representation of my data (and I'd like to avoid it). This is where Mermaid is so convenient: you can give it data gradually without bothering with the big picture of your flow.

Here are two distinct examples illustrating my request.
The first one shows a "lone tree" (starting at .file53).
After the "root connexion", it could look like this.

The second one shows that my "simple pre processing" is not very good at defining the real start of a tree, as the first node I encounter is not always the top of the final tree.
It should be like this.

parsing execution plans of a MVS: executing a JCL generates a JOR

Wow, that will be a 'killer app' when its finished

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lumenwrites picture lumenwrites  路  5Comments

The-Alchemist picture The-Alchemist  路  4Comments

vikram-rawat picture vikram-rawat  路  5Comments

michaeltlombardi picture michaeltlombardi  路  3Comments

yk-liu picture yk-liu  路  4Comments