24.5 KB754 lines
Blame
1> **Warning**
2>
3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
4>
5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/block.md](../../packages/mermaid/src/docs/syntax/block.md).
6
7# Block Diagrams Documentation
8
9## Introduction to Block Diagrams
10
11```mermaid-example
12block
13columns 1
14 db(("DB"))
15 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
16 block:ID
17 A
18 B["A wide one in the middle"]
19 C
20 end
21 space
22 D
23 ID --> D
24 C --> D
25 style B fill:#969,stroke:#333,stroke-width:4px
26```
27
28```mermaid
29block
30columns 1
31 db(("DB"))
32 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
33 block:ID
34 A
35 B["A wide one in the middle"]
36 C
37 end
38 space
39 D
40 ID --> D
41 C --> D
42 style B fill:#969,stroke:#333,stroke-width:4px
43```
44
45### Definition and Purpose
46
47Block diagrams are an intuitive and efficient way to represent complex systems, processes, or architectures visually. They are composed of blocks and connectors, where blocks represent the fundamental components or functions, and connectors show the relationship or flow between these components. This method of diagramming is essential in various fields such as engineering, software development, and process management.
48
49The primary purpose of block diagrams is to provide a high-level view of a system, allowing for easy understanding and analysis without delving into the intricate details of each component. This makes them particularly useful for simplifying complex systems and for explaining the overall structure and interaction of components within a system.
50
51Many people use mermaid flowcharts for this purpose. A side-effect of this is that the automatic layout sometimes move shapes to positions that the diagram maker does not want. Block diagrams use a different approach. In this diagram we give the author full control over where the shapes are positioned.
52
53### General Use Cases
54
55Block diagrams have a wide range of applications across various industries and disciplines. Some of the key use cases include:
56
57- **Software Architecture**: In software development, block diagrams can be used to illustrate the architecture of a software application. This includes showing how different modules or services interact, data flow, and high-level component interaction.
58
59- **Network Diagrams**: Block diagrams are ideal for representing network architectures in IT and telecommunications. They can depict how different network devices and services are interconnected, including routers, switches, firewalls, and the flow of data across the network.
60
61- **Process Flowcharts**: In business and manufacturing, block diagrams can be employed to create process flowcharts. These flowcharts represent various stages of a business or manufacturing process, helping to visualize the sequence of steps, decision points, and the flow of control.
62
63- **Electrical Systems**: Engineers use block diagrams to represent electrical systems and circuitry. They can illustrate the high-level structure of an electrical system, the interaction between different electrical components, and the flow of electrical currents.
64
65- **Educational Purposes**: Block diagrams are also extensively used in educational materials to explain complex concepts and systems in a simplified manner. They help in breaking down and visualizing scientific theories, engineering principles, and technological systems.
66
67These examples demonstrate the versatility of block diagrams in providing clear and concise representations of complex systems. Their simplicity and clarity make them a valuable tool for professionals across various fields to communicate complex ideas effectively.
68
69In the following sections, we will delve into the specifics of creating and manipulating block diagrams using Mermaid, covering everything from basic syntax to advanced configurations and styling.
70
71Creating block diagrams with Mermaid is straightforward and accessible. This section introduces the basic syntax and structure needed to start building simple diagrams. Understanding these foundational concepts is key to efficiently utilizing Mermaid for more complex diagramming tasks.
72
73### Simple Block Diagrams
74
75#### Basic Structure
76
77At its core, a block diagram consists of blocks representing different entities or components. In Mermaid, these blocks are easily created using simple text labels. The most basic form of a block diagram can be a series of blocks without any connectors.
78
79**Example - Simple Block Diagram**:
80To create a simple block diagram with three blocks labeled 'a', 'b', and 'c', the syntax is as follows:
81
82```mermaid-example
83block
84 a b c
85```
86
87```mermaid
88block
89 a b c
90```
91
92This example will produce a horizontal sequence of three blocks. Each block is automatically spaced and aligned for optimal readability.
93
94### Defining the number of columns to use
95
96#### Column Usage
97
98While simple block diagrams are linear and straightforward, more complex systems may require a structured layout. Mermaid allows for the organization of blocks into multiple columns, facilitating the creation of more intricate and detailed diagrams.
99
100**Example - Multi-Column Diagram:**
101In scenarios where you need to distribute blocks across multiple columns, you can specify the number of columns and arrange the blocks accordingly. Here's how to create a block diagram with three columns and four blocks, where the fourth block appears in a second row:
102
103```mermaid-example
104block
105 columns 3
106 a b c d
107```
108
109```mermaid
110block
111 columns 3
112 a b c d
113```
114
115This syntax instructs Mermaid to arrange the blocks 'a', 'b', 'c', and 'd' across three columns, wrapping to the next row as needed. This feature is particularly useful for representing layered or multi-tiered systems, such as network layers or hierarchical structures.
116
117These basic building blocks of Mermaid's block diagrams provide a foundation for more complex diagramming. The simplicity of the syntax allows for quick creation and iteration of diagrams, making it an efficient tool for visualizing ideas and concepts. In the next section, we'll explore advanced block configuration options, including setting block widths and creating composite blocks.
118
119## 3. Advanced Block Configuration
120
121Building upon the basics, this section delves into more advanced features of block diagramming in Mermaid. These features allow for greater flexibility and complexity in diagram design, accommodating a wider range of use cases and scenarios.
122
123### Setting Block Width
124
125#### Spanning Multiple Columns
126
127In more complex diagrams, you may need blocks that span multiple columns to emphasize certain components or to represent larger entities. Mermaid allows for the adjustment of block widths to cover multiple columns, enhancing the diagram's readability and structure.
128
129**Example - Block Spanning Multiple Columns**:
130To create a block diagram where one block spans across two columns, you can specify the desired width for each block:
131
132```mermaid-example
133block
134 columns 3
135 a["A label"] b:2 c:2 d
136```
137
138```mermaid
139block
140 columns 3
141 a["A label"] b:2 c:2 d
142```
143
144In this example, the block labeled "A labels" spans one column, while blocks 'b', 'c' span 2 columns, and 'd' is again allocated its own column. This flexibility in block sizing is crucial for accurately representing systems with components of varying significance or size.
145
146### Creating Composite Blocks
147
148#### Nested Blocks
149
150Composite blocks, or blocks within blocks, are an advanced feature in Mermaid's block diagram syntax. They allow for the representation of nested or hierarchical systems, where one component encompasses several subcomponents.
151
152**Example - Composite Blocks:**
153Creating a composite block involves defining a parent block and then nesting other blocks within it. Here's how to define a composite block with nested elements:
154
155```mermaid-example
156block
157 block
158 D
159 end
160 A["A: I am a wide one"]
161```
162
163```mermaid
164block
165 block
166 D
167 end
168 A["A: I am a wide one"]
169```
170
171In this syntax, 'D' is a nested block within a larger parent block. This feature is particularly useful for depicting complex structures, such as a server with multiple services or a department within a larger organizational framework.
172
173### Column Width Dynamics
174
175#### Adjusting Widths
176
177Mermaid also allows for dynamic adjustment of column widths based on the content of the blocks. The width of the columns is determined by the widest block in the column, ensuring that the diagram remains balanced and readable.
178
179**Example - Dynamic Column Widths:**
180In diagrams with varying block sizes, Mermaid automatically adjusts the column widths to fit the largest block in each column. Here's an example:
181
182```mermaid-example
183block
184 columns 3
185 a:3
186 block:group1:2
187 columns 2
188 h i j k
189 end
190 g
191 block:group2:3
192 %% columns auto (default)
193 l m n o p q r
194 end
195```
196
197```mermaid
198block
199 columns 3
200 a:3
201 block:group1:2
202 columns 2
203 h i j k
204 end
205 g
206 block:group2:3
207 %% columns auto (default)
208 l m n o p q r
209 end
210```
211
212This 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.
213
214**Merging Blocks Horizontally:**
215In scenarios where you need to stack blocks horizontally, you can use column width to accomplish the task. Blocks can be arranged vertically by putting them in a single column. Here is how you can create a block diagram in which 4 blocks are stacked on top of each other:
216
217```mermaid-example
218block
219 block
220 columns 1
221 a["A label"] b c d
222 end
223```
224
225```mermaid
226block
227 block
228 columns 1
229 a["A label"] b c d
230 end
231```
232
233In this example, the width of the merged block dynamically adjusts to the width of the largest child block.
234
235With these advanced configuration options, Mermaid's block diagrams can be tailored to represent a wide array of complex systems and structures. The flexibility offered by these features enables users to create diagrams that are both informative and visually appealing. In the following sections, we will explore further capabilities, including different block shapes and linking options.
236
237## 4. Block Varieties and Shapes
238
239Mermaid's block diagrams are not limited to standard rectangular shapes. A variety of block shapes are available, allowing for a more nuanced and tailored representation of different types of information or entities. This section outlines the different block shapes you can use in Mermaid and their specific applications.
240
241### Standard and Special Block Shapes
242
243Mermaid supports a range of block shapes to suit different diagramming needs, from basic geometric shapes to more specialized forms.
244
245#### Example - Round Edged Block
246
247To create a block with round edges, which can be used to represent a softer or more flexible component:
248
249```mermaid-example
250block
251 id1("This is the text in the box")
252```
253
254```mermaid
255block
256 id1("This is the text in the box")
257```
258
259#### Example - Stadium-Shaped Block
260
261A stadium-shaped block, resembling an elongated circle, can be used for components that are process-oriented:
262
263```mermaid-example
264block
265 id1(["This is the text in the box"])
266```
267
268```mermaid
269block
270 id1(["This is the text in the box"])
271```
272
273#### Example - Subroutine Shape
274
275For representing subroutines or contained processes, a block with double vertical lines is useful:
276
277```mermaid-example
278block
279 id1[["This is the text in the box"]]
280```
281
282```mermaid
283block
284 id1[["This is the text in the box"]]
285```
286
287#### Example - Cylindrical Shape
288
289The cylindrical shape is ideal for representing databases or storage components:
290
291```mermaid-example
292block
293 id1[("Database")]
294```
295
296```mermaid
297block
298 id1[("Database")]
299```
300
301#### Example - Circle Shape
302
303A circle can be used for centralized or pivotal components:
304
305```mermaid-example
306block
307 id1(("This is the text in the circle"))
308```
309
310```mermaid
311block
312 id1(("This is the text in the circle"))
313```
314
315#### Example - Asymmetric, Rhombus, and Hexagon Shapes
316
317For decision points, use a rhombus, and for unique or specialized processes, asymmetric and hexagon shapes can be utilized:
318
319**Asymmetric**
320
321```mermaid-example
322block
323 id1>"This is the text in the box"]
324```
325
326```mermaid
327block
328 id1>"This is the text in the box"]
329```
330
331**Rhombus**
332
333```mermaid-example
334block
335 id1{"This is the text in the box"}
336```
337
338```mermaid
339block
340 id1{"This is the text in the box"}
341```
342
343**Hexagon**
344
345```mermaid-example
346block
347 id1{{"This is the text in the box"}}
348```
349
350```mermaid
351block
352 id1{{"This is the text in the box"}}
353```
354
355#### Example - Parallelogram and Trapezoid Shapes
356
357Parallelogram and trapezoid shapes are perfect for inputs/outputs and transitional processes:
358
359```mermaid-example
360block
361 id1[/"This is the text in the box"/]
362 id2[\"This is the text in the box"\]
363 A[/"Christmas"\]
364 B[\"Go shopping"/]
365```
366
367```mermaid
368block
369 id1[/"This is the text in the box"/]
370 id2[\"This is the text in the box"\]
371 A[/"Christmas"\]
372 B[\"Go shopping"/]
373```
374
375#### Example - Double Circle
376
377For highlighting critical or high-priority components, a double circle can be effective:
378
379```mermaid-example
380block
381 id1((("This is the text in the circle")))
382```
383
384```mermaid
385block
386 id1((("This is the text in the circle")))
387```
388
389### Block Arrows and Space Blocks
390
391Mermaid also offers unique shapes like block arrows and space blocks for directional flow and spacing.
392
393#### Example - Block Arrows
394
395Block arrows can visually indicate direction or flow within a process:
396
397```mermaid-example
398block
399 blockArrowId<["Label"]>(right)
400 blockArrowId2<["Label"]>(left)
401 blockArrowId3<["Label"]>(up)
402 blockArrowId4<["Label"]>(down)
403 blockArrowId5<["Label"]>(x)
404 blockArrowId6<["Label"]>(y)
405 blockArrowId7<["Label"]>(x, down)
406```
407
408```mermaid
409block
410 blockArrowId<["Label"]>(right)
411 blockArrowId2<["Label"]>(left)
412 blockArrowId3<["Label"]>(up)
413 blockArrowId4<["Label"]>(down)
414 blockArrowId5<["Label"]>(x)
415 blockArrowId6<["Label"]>(y)
416 blockArrowId7<["Label"]>(x, down)
417```
418
419#### Example - Space Blocks
420
421Space blocks can be used to create intentional empty spaces in the diagram, which is useful for layout and readability:
422
423```mermaid-example
424block
425 columns 3
426 a space b
427 c d e
428```
429
430```mermaid
431block
432 columns 3
433 a space b
434 c d e
435```
436
437or
438
439```mermaid-example
440block
441 ida space:3 idb idc
442```
443
444```mermaid
445block
446 ida space:3 idb idc
447```
448
449Note that you can set how many columns the space block occupied using the number notation `space:num` where num is a number indicating the num columns width. You can also use `space` which defaults to one column.
450
451The variety of shapes and special blocks in Mermaid enhances the expressive power of block diagrams, allowing for more accurate and context-specific representations. These options give users the flexibility to create diagrams that are both informative and visually appealing. In the next sections, we will explore the ways to connect these blocks and customize their appearance.
452
453### Standard and Special Block Shapes
454
455Discuss the various shapes available for blocks, including standard shapes and special forms like block arrows and space blocks.
456
457## 5. Connecting Blocks with Edges
458
459One of the key features of block diagrams in Mermaid is the ability to connect blocks using various types of edges or links. This section explores the different ways blocks can be interconnected to represent relationships and flows between components.
460
461### Basic Linking and Arrow Types
462
463The most fundamental aspect of connecting blocks is the use of arrows or links. These connectors depict the relationships or the flow of information between the blocks. Mermaid offers a range of arrow types to suit different diagramming needs.
464
465**Example - Basic Links**
466
467A simple link with an arrow can be created to show direction or flow from one block to another:
468
469```mermaid-example
470block
471 A space B
472 A-->B
473```
474
475```mermaid
476block
477 A space B
478 A-->B
479```
480
481This example illustrates a direct connection from block 'A' to block 'B', using a straightforward arrow.
482
483This syntax creates a line connecting 'A' and 'B', implying a relationship or connection without indicating a specific direction.
484
485### Text on Links
486
487In addition to connecting blocks, it's often necessary to describe or label the relationship. Mermaid allows for the inclusion of text on links, providing context to the connections.
488
489Example - Text with Links
490To add text to a link, the syntax includes the text within the link definition:
491
492```mermaid-example
493block
494 A space:2 B
495 A-- "X" -->B
496```
497
498```mermaid
499block
500 A space:2 B
501 A-- "X" -->B
502```
503
504This example show how to add descriptive text to the links, enhancing the information conveyed by the diagram.
505
506Example - Edges and Styles:
507
508```mermaid-example
509block
510columns 1
511 db(("DB"))
512 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
513 block:ID
514 A
515 B["A wide one in the middle"]
516 C
517 end
518 space
519 D
520 ID --> D
521 C --> D
522 style B fill:#939,stroke:#333,stroke-width:4px
523```
524
525```mermaid
526block
527columns 1
528 db(("DB"))
529 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
530 block:ID
531 A
532 B["A wide one in the middle"]
533 C
534 end
535 space
536 D
537 ID --> D
538 C --> D
539 style B fill:#939,stroke:#333,stroke-width:4px
540```
541
542## 6. Styling and Customization
543
544Beyond the structure and layout of block diagrams, Mermaid offers extensive styling options. These customization features allow for the creation of more visually distinctive and informative diagrams. This section covers how to apply individual styles to blocks and how to use classes for consistent styling across multiple elements.
545
546### Individual Block Styling
547
548Mermaid enables detailed styling of individual blocks, allowing you to apply various CSS properties such as color, stroke, and border thickness. This feature is especially useful for highlighting specific parts of a diagram or for adhering to certain visual themes.
549
550#### Example - Styling a Single Block
551
552To apply custom styles to a block, you can use the `style` keyword followed by the block identifier and the desired CSS properties:
553
554```mermaid-example
555block
556 id1 space id2
557 id1("Start")-->id2("Stop")
558 style id1 fill:#636,stroke:#333,stroke-width:4px
559 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
560```
561
562```mermaid
563block
564 id1 space id2
565 id1("Start")-->id2("Stop")
566 style id1 fill:#636,stroke:#333,stroke-width:4px
567 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
568```
569
570### Class Styling
571
572Mermaid enables applying styling to classes, which could make styling easier if you want to apply a certain set of styles to multiple elements, as you could just link those elements to a class.
573
574#### Example - Styling a Single Class
575
576```mermaid-example
577block
578 A space B
579 A-->B
580 classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px;
581 class A blue
582 style B fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
583```
584
585```mermaid
586block
587 A space B
588 A-->B
589 classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px;
590 class A blue
591 style B fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
592```
593
594In this example, a class named 'blue' is defined and applied to block 'A', while block 'B' receives individual styling. This demonstrates the flexibility of Mermaid in applying both shared and unique styles within the same diagram.
595
596The ability to style blocks individually or through classes provides a powerful tool for enhancing the visual impact and clarity of block diagrams. Whether emphasizing certain elements or maintaining a cohesive design across the diagram, these styling capabilities are central to effective diagramming. The next sections will present practical examples and use cases, followed by tips for troubleshooting common issues.
597
598### 7. Practical Examples and Use Cases
599
600The versatility of Mermaid's block diagrams becomes evident when applied to real-world scenarios. This section provides practical examples demonstrating the application of various features discussed in previous sections. These examples showcase how block diagrams can be used to represent complex systems and processes in an accessible and informative manner.
601
602### Detailed Examples Illustrating Various Features
603
604Combining the elements of structure, linking, and styling, we can create comprehensive diagrams that serve specific purposes in different contexts.
605
606#### Example - System Architecture
607
608Illustrating a simple software system architecture with interconnected components:
609
610```mermaid-example
611block
612 columns 3
613 Frontend blockArrowId6<[" "]>(right) Backend
614 space:2 down<[" "]>(down)
615 Disk left<[" "]>(left) Database[("Database")]
616
617 classDef front fill:#696,stroke:#333;
618 classDef back fill:#969,stroke:#333;
619 class Frontend front
620 class Backend,Database back
621```
622
623```mermaid
624block
625 columns 3
626 Frontend blockArrowId6<[" "]>(right) Backend
627 space:2 down<[" "]>(down)
628 Disk left<[" "]>(left) Database[("Database")]
629
630 classDef front fill:#696,stroke:#333;
631 classDef back fill:#969,stroke:#333;
632 class Frontend front
633 class Backend,Database back
634```
635
636This example shows a basic architecture with a frontend, backend, and database. The blocks are styled to differentiate between types of components.
637
638#### Example - Business Process Flow
639
640Representing a business process flow with decision points and multiple stages:
641
642```mermaid-example
643block
644 columns 3
645 Start(("Start")) space:2
646 down<[" "]>(down) space:2
647 Decision{{"Make Decision"}} right<["Yes"]>(right) Process1["Process A"]
648 downAgain<["No"]>(down) space r3<["Done"]>(down)
649 Process2["Process B"] r2<["Done"]>(right) End(("End"))
650
651 style Start fill:#969;
652 style End fill:#696;
653```
654
655```mermaid
656block
657 columns 3
658 Start(("Start")) space:2
659 down<[" "]>(down) space:2
660 Decision{{"Make Decision"}} right<["Yes"]>(right) Process1["Process A"]
661 downAgain<["No"]>(down) space r3<["Done"]>(down)
662 Process2["Process B"] r2<["Done"]>(right) End(("End"))
663
664 style Start fill:#969;
665 style End fill:#696;
666```
667
668These practical examples and scenarios underscore the utility of Mermaid block diagrams in simplifying and effectively communicating complex information across various domains.
669
670The 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.
671
672## 8. Troubleshooting and Common Issues
673
674Working with Mermaid block diagrams can sometimes present challenges, especially as the complexity of the diagrams increases. This section aims to provide guidance on resolving common issues and offers tips for managing more intricate diagram structures.
675
676### Common Syntax Errors
677
678Understanding and avoiding common syntax errors is key to a smooth experience with Mermaid diagrams.
679
680#### Example - Incorrect Linking
681
682A common mistake is incorrect linking syntax, which can lead to unexpected results or broken diagrams:
683
684```
685block
686 A - B
687```
688
689**Correction**:
690Ensure that links between blocks are correctly specified with arrows (--> or ---) to define the direction and type of connection. Also remember that one of the fundamentals for block diagram is to give the author full control of where the boxes are positioned so in the example you need to add a space between the boxes:
691
692```mermaid-example
693block
694 A space B
695 A --> B
696```
697
698```mermaid
699block
700 A space B
701 A --> B
702```
703
704#### Example - Misplaced Styling
705
706Applying styles in the wrong context or with incorrect syntax can lead to blocks not being styled as intended:
707
708```mermaid-example
709 block
710 A
711 style A fill#969;
712```
713
714```mermaid
715 block
716 A
717 style A fill#969;
718```
719
720**Correction:**
721Correct the syntax by ensuring proper separation of style properties with commas and using the correct CSS property format:
722
723```mermaid-example
724block
725 A
726 style A fill:#969,stroke:#333;
727
728```
729
730```mermaid
731block
732 A
733 style A fill:#969,stroke:#333;
734
735```
736
737### Tips for Complex Diagram Structures
738
739Managing complexity in Mermaid diagrams involves planning and employing best practices.
740
741#### Modular Design
742
743Break down complex diagrams into smaller, more manageable components. This approach not only makes the diagram easier to understand but also simplifies the creation and maintenance process.
744
745#### Consistent Styling
746
747Use classes to maintain consistent styling across similar elements. This not only saves time but also ensures a cohesive and professional appearance.
748
749#### Comments and Documentation
750
751Use 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.
752
753With 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.
754