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.14k stars 6.41k forks source link

Elk renderer not wokring on empty subgraph #5402

Open Alexandre-SCHOEPP opened 6 months ago

Alexandre-SCHOEPP commented 6 months ago

Description

When using the elk renderer when a subgraph is empty, I get the following error : Cannot read properties of null (reading 're')

Steps to reproduce

  1. Using Meramid 10.8.0 locally or live editor
  2. select flowchart
  3. initialize with default renderer set to "elk" as documented
  4. create an empty subgraph
  5. weep

Screenshots

image

Code Sample

Here is my minimum reproducible example:

## Works

:::mermaid
%%{init: {"flowchart": {"defaultRenderer": "dagre"}} }%%
flowchart TD
subgraph A
end
:::
## Does not work
:::mermaid
%%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
flowchart TD
subgraph B
end
:::

Here is my minimum reproducible example:

Works

:::mermaid %%{init: {"flowchart": {"defaultRenderer": "dagre"}} }%% flowchart TD subgraph A end :::

## Does not work
:::mermaid
%%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
flowchart TD
subgraph B
end
:::

Setup

Suggested Solutions

variable re seems to be at the root of the issue.

Additional Context

No response

Yokozuna59 commented 6 months ago

Hi @Alexandre-SCHOEPP, thanks for reporting the issue.

But I wouldn’t really consider this an issue; subgraphs are just rectangles that wrap nodes according to their size; there is no point in creating empty rectangles with no nodes inside.

It’s kind of similar to the empty namespace in class diagram, see https://github.com/mermaid-js/mermaid/issues/4625#issuecomment-1629778506.

Unless you’re suggesting to make the behavior similar to the default renderer, degre, to consider it a regular node:

flowchart
subgraph a
end
Alexandre-SCHOEPP commented 6 months ago

Hi @Yokozuna59 !

there is no point in creating empty rectangles with no nodes inside.

I regularly use this functionality in mermaid with the default renderer as it allows for flowchart that evolve with development. For example, if I suspect that there will be subsystems in the future, I often leave an empty subgraph.

I also tend to make rather complex graphs, which, I understand, is a bit beyond the typical usecase for mermaid, but having empty subgraphs allows me to :

Unless you’re suggesting to make the behavior similar to the default renderer, degre, to consider it a regular node:

I think that this needs to either be properly documented (as I didn't find my answer in your documentation) with an error message saying that this is an intentional choice, or, as you've said, be brought to consistency with both renderer.

Thank you for the work you do on mermaid, I love that it does not have to be a static graph, and I think that this would help move the project in that direction.