Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new diagram type - Block Diagram #5221

Merged
merged 76 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
86e1bb3
#3358 First commit with basic grammar and 1st test
knsv Jul 5, 2023
791e676
Rename BlockDiagram to Block
nirname Jul 7, 2023
fee2b24
Small cleanup
nirname Jul 7, 2023
975f36c
Fixed block diagram parser import
nirname Jul 7, 2023
c10f765
Adding some more tests
knsv Jul 9, 2023
d165e8a
Started block diag db development
nirname Jul 10, 2023
e251baa
Started layout and rendering
nirname Jul 10, 2023
13114eb
Merge branch 'develop' into 3358-blocks-diagram
knsv Jul 25, 2023
b9531d5
Adding support for compound blocks
knsv Aug 8, 2023
5fc99f1
#3358 Adding db calls from node statements
knsv Aug 28, 2023
aa7f5a8
before refactoring
knsv Sep 1, 2023
8a55b21
Saving data from compound blocks
knsv Sep 1, 2023
e52de6c
Some cleanup
knsv Sep 1, 2023
5f1cfc7
Support for compound blocks with id, title and type
knsv Sep 1, 2023
1e864a5
Rendering, tmp commit before refactoring
knsv Sep 5, 2023
ccdb803
Rendering, interim
knsv Sep 5, 2023
836d3a8
WIP
knsv Sep 14, 2023
b4e3254
#3358 Recursive positioning
knsv Oct 3, 2023
f00871a
#3358 Recursive positioning
knsv Oct 3, 2023
c8d155c
#3358 Recursive positioning
knsv Oct 3, 2023
da79b37
#3358 Recursive positioning paddings
knsv Oct 4, 2023
a641fd5
#3358 Adding support for column statements
knsv Oct 15, 2023
74a9e86
#3358 Putting the elements back in
knsv Oct 15, 2023
5619f87
#3358 Adding support for space blocks and different shapes
knsv Oct 20, 2023
f3f25c7
#3358 Adding support for space blocks and different shapes
knsv Oct 20, 2023
7198fe5
Parsing of block arrows with directions, creating a dedicated new nod…
knsv Oct 26, 2023
03c59ad
Parsing of block arrows with directions, creating a dedicated new nod…
knsv Oct 26, 2023
df858dc
#3358 Adding arrows to syntax
knsv Nov 20, 2023
2ed4469
#3358 Adding arrows to rendering
knsv Jan 4, 2024
d0eca26
#3358 Multiple arrows
knsv Jan 4, 2024
72135c2
#3358 Edge labels
knsv Jan 4, 2024
275e01a
#3358 Adding support for classDef and class statements
knsv Jan 5, 2024
818cb2f
#3358 Adding support for style statements
knsv Jan 5, 2024
809c450
#3358 Support for adding tests and fixed issues for some shapes
knsv Jan 8, 2024
7043892
#3358 Fix for layout where a siebling has wider siize
knsv Jan 8, 2024
1d18757
#3358 Sieblinmg height alignment
knsv Jan 8, 2024
bbc7fe6
#3358 Fix for width of composite blocks
knsv Jan 18, 2024
a0d328d
#3358 Removed logging, fixed som tests
knsv Jan 18, 2024
1230da7
#3358 Some cleanup
knsv Jan 18, 2024
8e14720
#3358 Removed logging som type fixes
knsv Jan 18, 2024
173ba2e
Final console.log removed
knsv Jan 18, 2024
bf64509
Merge branch 'develop' into 3358-blocks-diagram
knsv Jan 18, 2024
5553cbb
Update docs
knsv Jan 18, 2024
d075766
#3358 Doc updates after viewing the page
knsv Jan 18, 2024
b4dece8
Merge branch '3358-blocks-diagram' of github.com:mermaid-js/mermaid i…
knsv Jan 18, 2024
d96425d
#3358 Reviving arrow heads after merging develop
knsv Jan 19, 2024
fe89b95
#3358 Adjusting docs and a bug fix for nested blocks
knsv Jan 22, 2024
c85b248
Merge branch 'develop' into 3358-blocks-diagram
knsv Jan 22, 2024
1629a91
Updated lockfile
knsv Jan 22, 2024
1965f69
Update packages/mermaid/src/schemas/config.schema.yaml
knsv Jan 29, 2024
37d7c7e
#3358 Second set of changes after review
knsv Jan 29, 2024
5aab2ba
Merge branch '3358-blocks-diagram' of github.com:mermaid-js/mermaid i…
knsv Jan 29, 2024
bfa8111
#3358 Third set of changes after review
knsv Jan 29, 2024
dae8a13
Update packages/mermaid/src/defaultConfig.ts
knsv Jan 30, 2024
4823cf5
Update packages/mermaid/src/diagrams/block/blockDB.ts
knsv Jan 30, 2024
1023797
Merge branch 'develop' into 3358-blocks-diagram
knsv Jan 30, 2024
4a14d99
Update packages/mermaid/src/diagrams/block/blockRenderer.ts
knsv Jan 30, 2024
2f8f9dd
Update packages/mermaid/src/diagrams/block/blockDB.ts
knsv Jan 30, 2024
452cb83
#3358 Review changes
knsv Jan 30, 2024
8f8ce2f
Merge branch '3358-blocks-diagram' of github.com:mermaid-js/mermaid i…
knsv Jan 30, 2024
010fc70
Update packages/mermaid/src/diagrams/block/blockTypes.ts
knsv Jan 30, 2024
4a04ce6
Update cypress/integration/rendering/block.spec.ts
knsv Jan 30, 2024
df9b801
#3358 Some fixes
knsv Jan 30, 2024
907006f
#3358 Some fixes
knsv Jan 30, 2024
b99b1bf
#3358 Another set of review changes
knsv Jan 30, 2024
dbcb800
Update docs
knsv Jan 30, 2024
8fdf512
Merge branch 'develop' into 3358-blocks-diagram
knsv Jan 30, 2024
7bcdea9
#3358n Updated lockfile
knsv Jan 30, 2024
6fce617
3358 Adding types for blockArrowHelper
knsv Jan 30, 2024
2bfd5a9
Merge branch 'develop' into 3358-blocks-diagram
sidharthv96 Jan 31, 2024
4786cfb
#3358 Renaming of IOperation to ActionFun
knsv Jan 31, 2024
cd7003e
Merge branch '3358-blocks-diagram' of github.com:mermaid-js/mermaid i…
knsv Jan 31, 2024
13d0b61
Merge branch 'develop' into 3358-blocks-diagram
ashishjain0512 Jan 31, 2024
16149ab
#3358 Fix after review
knsv Feb 1, 2024
d3c5b02
Merge branch '3358-blocks-diagram' of github.com:mermaid-js/mermaid i…
knsv Feb 1, 2024
a7afc11
#3358 Removing redundant file
knsv Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions cypress/integration/rendering/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('Block diagram', () => {
id1
end
id["Next row"]
`,
{}
`
);
});

Expand Down Expand Up @@ -305,7 +304,7 @@ describe('Block diagram', () => {
it('BL22: sizing - it should be possible to make a block wider', () => {
imgSnapshotTest(
`block-beta
A("rounded):2
A("rounded"):2
B:2
C
`,
Expand Down
25 changes: 13 additions & 12 deletions cypress/platform/knsv2.html
knsv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
</head>
<body>
<pre id="diagram" class="mermaid">
block-beta
columns 3
a:3
block:e:3
f
end
g

block-beta
blockArrowId<["Label"]>(right)
blockArrowId2<["Label"]>(left)
blockArrowId3<["Label"]>(up)
blockArrowId4<["Label"]>(down)
blockArrowId5<["Label"]>(x)
blockArrowId6<["Label"]>(y)
blockArrowId6<["Label"]>(x, down)
</pre>
<pre id="diagram" class="mermaid">
block-beta
Expand Down Expand Up @@ -157,14 +157,14 @@
end
g h i
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta
columns 3
a b c
e:3
f g h
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta
columns 1
db(("DB"))
Expand All @@ -180,12 +180,13 @@
C --> D
style B fill:#f9F,stroke:#333,stroke-width:4px
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta

columns 5
A1:3
A2:1
A3
B1 B2 B3:3
</pre>
<pre id="diagram" class="mermaid2">
block-beta
Expand Down
126 changes: 114 additions & 12 deletions demos/block.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,125 @@
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>States Mermaid Quick Test Page</title>
<title>Mermaid Block diagram demo page</title>
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=" />
<style>
div.mermaid {
font-family: 'Courier New', Courier, monospace !important;
}
</style>
</head>

<body>
<h1>Block diagram demos</h1>
<h2>TCI IP</h2>
<pre class="mermaid">
block-beta
A>"rect_left_inv_arrow"]
B{"diamond"}
C{{"hexagon"}}
<pre id="diagram" class="mermaid">
block-beta
columns 1
db(("DB"))
blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
block:ID
A
B["A wide one in the middle"]
C
end
space
D
ID --> D
C --> D
style B fill:#f9F,stroke:#333,stroke-width:4px
</pre>
<pre id="diagram" class="mermaid">
block-beta
A1["square"]
B1("rounded")
C1(("circle"))
A2>"rect_left_inv_arrow"]
B2{"diamond"}
C2{{"hexagon"}}
</pre>

<pre id="diagram" class="mermaid">
block-beta
A1(["stadium"])
A2[["subroutine"]]
B1[("cylinder")]
C1>"surprise"]
A3[/"lean right"/]
B2[\"lean left"\]
C2[/"trapezoid"\]
D2[\"trapezoid"/]
</pre>

<pre id="diagram" class="mermaid">
block-beta
block:e:4
columns 2
f
g
end

</pre>
<pre id="diagram" class="mermaid">
block-beta
block:e:4
columns 2
f
g
h
end

</pre>
<pre id="diagram" class="mermaid">
block-beta
columns 3
a:3
block:e:3
f
g
end
h
i
j

</pre>
<pre id="diagram" class="mermaid">
block-beta
columns 4
a b c d
block:e:4
columns 2
f
g
h
end
i:4

</pre>
<pre id="diagram" class="mermaid">
flowchart LR
X-- "a label" -->z
</pre>
<pre id="diagram" class="mermaid">
block-beta
columns 5
A space B
A --x B
</pre>
<pre id="diagram" class="mermaid">
block-beta
columns 3
a["A wide one"] b:2 c:2 d
</pre>

<pre id="diagram" class="mermaid">
block-beta
columns 3
a b c
e:3
f g h
</pre>

<pre id="diagram" class="mermaid">
block-beta

A1:3
A2:1
A3
</pre>

<script type="module">
Expand Down
2 changes: 1 addition & 1 deletion docs/config/setup/modules/defaultConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#### Defined in

[defaultConfig.ts:278](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L278)
[defaultConfig.ts:272](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L272)

---

Expand Down
44 changes: 20 additions & 24 deletions docs/syntax/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ block-beta

This example will produce a horizontal sequence of three blocks. Each block is automatically spaced and aligned for optimal readability.

### Diagrams with Multiple Columns
### Defining the number of columns to use

#### Column Usage

Expand Down Expand Up @@ -132,13 +132,13 @@ To create a block diagram where one block spans across two columns, you can spec
```mermaid-example
block-beta
columns 3
a["A wide one"] b:2 c:2 d
a["A label"] b:2 c:2 d
```

```mermaid
block-beta
columns 3
a["A wide one"] b:2 c:2 d
a["A label"] b:2 c:2 d
```

In this example, the block labeled "A wide one" spans two columns, while blocks 'b', 'c', and 'd' are allocated their own columns. This flexibility in block sizing is crucial for accurately representing systems with components of varying significance or size.
Expand Down Expand Up @@ -183,20 +183,30 @@ In diagrams with varying block sizes, Mermaid automatically adjusts the column w
block-beta
columns 3
a:3
block:e:3
f
block:group1:2
columns 2
h i j k
end
g
block:group2:3
%% columns auto (default)
l m n o p q r
end
```

```mermaid
block-beta
columns 3
a:3
block:e:3
f
block:group1:2
columns 2
h i j k
end
g
block:group2:3
%% columns auto (default)
l m n o p q r
end
```

This example demonstrates how Mermaid dynamically adjusts the width of the columns to accommodate the widest block, in this case, 'a' and the composite block 'e'. This dynamic adjustment is essential for creating visually balanced and easy-to-understand diagrams.
Expand Down Expand Up @@ -407,14 +417,12 @@ or

```mermaid-example
block-beta
space:3
ida idb idc
ida space:3 idb idc
```

```mermaid
block-beta
space:3
ida idb idc
ida space:3 idb idc
```

Note that you can set how many columns the spece block occupied using the number notaion `space:num` where num is a number indicating the num columns width. You can alsio use `space` which defaults to one column.
Expand Down Expand Up @@ -597,7 +605,6 @@ block-beta

style Start fill:#969;
style End fill:#696;

```

```mermaid
Expand All @@ -611,19 +618,8 @@ block-beta

style Start fill:#969;
style End fill:#696;

```

This diagram depicts a simple decision-making process with two possible paths leading to an endpoint, demonstrating the use of different shapes and directional arrows.

### Real world Scenarios

Block diagrams can be employed in a variety of real-world scenarios. Here are a few examples:

- **IT Network Layouts**: Visualize the structure of IT networks, showing how different devices and services are connected.
- **Educational Diagrams**: Explain complex scientific concepts, engineering systems, or historical timelines.
- **Organizational Charts**: Represent the hierarchy and relationships within an organization or department.

These practical examples and scenarios underscore the utility of Mermaid block diagrams in simplifying and effectively communicating complex information across various domains.

The next section, 'Troubleshooting and Common Issues', will provide insights into resolving common challenges encountered when working with Mermaid block diagrams, ensuring a smooth diagramming experience.
Expand Down Expand Up @@ -705,6 +701,6 @@ Use classes to maintain consistent styling across similar elements. This not onl

#### Comments and Documentation

Use comments within the Mermaid syntax to document the purpose of various parts of the diagram. This practice is invaluable for maintaining clarity, especially when working in teams or returning to a diagram after some time.
Use comments with `%%` within the Mermaid syntax to document the purpose of various parts of the diagram. This practice is invaluable for maintaining clarity, especially when working in teams or returning to a diagram after some time.

With these troubleshooting tips and best practices, you can effectively manage and resolve common issues in Mermaid block diagrams. The final section, 'Conclusion', will summarize the key points covered in this documentation and invite user feedback for continuous improvement.
1 change: 0 additions & 1 deletion packages/mermaid/src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export interface MermaidConfig {
* via the `definition` "BlockDiagramConfig".
*/
export interface BlockDiagramConfig extends BaseDiagramConfig {
useMaxWidth?: boolean;
padding?: number;
}
/**
Expand Down