collab/mermaid/docs/syntax/block.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/block.md](../../packages/mermaid/src/docs/syntax/block.md).
6dd74de6
6dd74de7# Block Diagrams Documentation
6dd74de8
6dd74de9## Introduction to Block Diagrams
6dd74de10
6dd74de11```mermaid-example
6dd74de12block
6dd74de13columns 1
6dd74de14 db(("DB"))
6dd74de15 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
6dd74de16 block:ID
6dd74de17 A
6dd74de18 B["A wide one in the middle"]
6dd74de19 C
6dd74de20 end
6dd74de21 space
6dd74de22 D
6dd74de23 ID --> D
6dd74de24 C --> D
6dd74de25 style B fill:#969,stroke:#333,stroke-width:4px
6dd74de26```
6dd74de27
6dd74de28```mermaid
6dd74de29block
6dd74de30columns 1
6dd74de31 db(("DB"))
6dd74de32 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
6dd74de33 block:ID
6dd74de34 A
6dd74de35 B["A wide one in the middle"]
6dd74de36 C
6dd74de37 end
6dd74de38 space
6dd74de39 D
6dd74de40 ID --> D
6dd74de41 C --> D
6dd74de42 style B fill:#969,stroke:#333,stroke-width:4px
6dd74de43```
6dd74de44
6dd74de45### Definition and Purpose
6dd74de46
6dd74de47Block 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.
6dd74de48
6dd74de49The 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.
6dd74de50
6dd74de51Many 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.
6dd74de52
6dd74de53### General Use Cases
6dd74de54
6dd74de55Block diagrams have a wide range of applications across various industries and disciplines. Some of the key use cases include:
6dd74de56
6dd74de57- **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.
6dd74de58
6dd74de59- **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.
6dd74de60
6dd74de61- **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.
6dd74de62
6dd74de63- **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.
6dd74de64
6dd74de65- **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.
6dd74de66
6dd74de67These 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.
6dd74de68
6dd74de69In 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.
6dd74de70
6dd74de71Creating 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.
6dd74de72
6dd74de73### Simple Block Diagrams
6dd74de74
6dd74de75#### Basic Structure
6dd74de76
6dd74de77At 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.
6dd74de78
6dd74de79**Example - Simple Block Diagram**:
6dd74de80To create a simple block diagram with three blocks labeled 'a', 'b', and 'c', the syntax is as follows:
6dd74de81
6dd74de82```mermaid-example
6dd74de83block
6dd74de84 a b c
6dd74de85```
6dd74de86
6dd74de87```mermaid
6dd74de88block
6dd74de89 a b c
6dd74de90```
6dd74de91
6dd74de92This example will produce a horizontal sequence of three blocks. Each block is automatically spaced and aligned for optimal readability.
6dd74de93
6dd74de94### Defining the number of columns to use
6dd74de95
6dd74de96#### Column Usage
6dd74de97
6dd74de98While 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.
6dd74de99
6dd74de100**Example - Multi-Column Diagram:**
6dd74de101In 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:
6dd74de102
6dd74de103```mermaid-example
6dd74de104block
6dd74de105 columns 3
6dd74de106 a b c d
6dd74de107```
6dd74de108
6dd74de109```mermaid
6dd74de110block
6dd74de111 columns 3
6dd74de112 a b c d
6dd74de113```
6dd74de114
6dd74de115This 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.
6dd74de116
6dd74de117These 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.
6dd74de118
6dd74de119## 3. Advanced Block Configuration
6dd74de120
6dd74de121Building 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.
6dd74de122
6dd74de123### Setting Block Width
6dd74de124
6dd74de125#### Spanning Multiple Columns
6dd74de126
6dd74de127In 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.
6dd74de128
6dd74de129**Example - Block Spanning Multiple Columns**:
6dd74de130To create a block diagram where one block spans across two columns, you can specify the desired width for each block:
6dd74de131
6dd74de132```mermaid-example
6dd74de133block
6dd74de134 columns 3
6dd74de135 a["A label"] b:2 c:2 d
6dd74de136```
6dd74de137
6dd74de138```mermaid
6dd74de139block
6dd74de140 columns 3
6dd74de141 a["A label"] b:2 c:2 d
6dd74de142```
6dd74de143
6dd74de144In 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.
6dd74de145
6dd74de146### Creating Composite Blocks
6dd74de147
6dd74de148#### Nested Blocks
6dd74de149
6dd74de150Composite 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.
6dd74de151
6dd74de152**Example - Composite Blocks:**
6dd74de153Creating 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:
6dd74de154
6dd74de155```mermaid-example
6dd74de156block
6dd74de157 block
6dd74de158 D
6dd74de159 end
6dd74de160 A["A: I am a wide one"]
6dd74de161```
6dd74de162
6dd74de163```mermaid
6dd74de164block
6dd74de165 block
6dd74de166 D
6dd74de167 end
6dd74de168 A["A: I am a wide one"]
6dd74de169```
6dd74de170
6dd74de171In 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.
6dd74de172
6dd74de173### Column Width Dynamics
6dd74de174
6dd74de175#### Adjusting Widths
6dd74de176
6dd74de177Mermaid 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.
6dd74de178
6dd74de179**Example - Dynamic Column Widths:**
6dd74de180In diagrams with varying block sizes, Mermaid automatically adjusts the column widths to fit the largest block in each column. Here's an example:
6dd74de181
6dd74de182```mermaid-example
6dd74de183block
6dd74de184 columns 3
6dd74de185 a:3
6dd74de186 block:group1:2
6dd74de187 columns 2
6dd74de188 h i j k
6dd74de189 end
6dd74de190 g
6dd74de191 block:group2:3
6dd74de192 %% columns auto (default)
6dd74de193 l m n o p q r
6dd74de194 end
6dd74de195```
6dd74de196
6dd74de197```mermaid
6dd74de198block
6dd74de199 columns 3
6dd74de200 a:3
6dd74de201 block:group1:2
6dd74de202 columns 2
6dd74de203 h i j k
6dd74de204 end
6dd74de205 g
6dd74de206 block:group2:3
6dd74de207 %% columns auto (default)
6dd74de208 l m n o p q r
6dd74de209 end
6dd74de210```
6dd74de211
6dd74de212This 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.
6dd74de213
6dd74de214**Merging Blocks Horizontally:**
6dd74de215In 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:
6dd74de216
6dd74de217```mermaid-example
6dd74de218block
6dd74de219 block
6dd74de220 columns 1
6dd74de221 a["A label"] b c d
6dd74de222 end
6dd74de223```
6dd74de224
6dd74de225```mermaid
6dd74de226block
6dd74de227 block
6dd74de228 columns 1
6dd74de229 a["A label"] b c d
6dd74de230 end
6dd74de231```
6dd74de232
6dd74de233In this example, the width of the merged block dynamically adjusts to the width of the largest child block.
6dd74de234
6dd74de235With 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.
6dd74de236
6dd74de237## 4. Block Varieties and Shapes
6dd74de238
6dd74de239Mermaid'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.
6dd74de240
6dd74de241### Standard and Special Block Shapes
6dd74de242
6dd74de243Mermaid supports a range of block shapes to suit different diagramming needs, from basic geometric shapes to more specialized forms.
6dd74de244
6dd74de245#### Example - Round Edged Block
6dd74de246
6dd74de247To create a block with round edges, which can be used to represent a softer or more flexible component:
6dd74de248
6dd74de249```mermaid-example
6dd74de250block
6dd74de251 id1("This is the text in the box")
6dd74de252```
6dd74de253
6dd74de254```mermaid
6dd74de255block
6dd74de256 id1("This is the text in the box")
6dd74de257```
6dd74de258
6dd74de259#### Example - Stadium-Shaped Block
6dd74de260
6dd74de261A stadium-shaped block, resembling an elongated circle, can be used for components that are process-oriented:
6dd74de262
6dd74de263```mermaid-example
6dd74de264block
6dd74de265 id1(["This is the text in the box"])
6dd74de266```
6dd74de267
6dd74de268```mermaid
6dd74de269block
6dd74de270 id1(["This is the text in the box"])
6dd74de271```
6dd74de272
6dd74de273#### Example - Subroutine Shape
6dd74de274
6dd74de275For representing subroutines or contained processes, a block with double vertical lines is useful:
6dd74de276
6dd74de277```mermaid-example
6dd74de278block
6dd74de279 id1[["This is the text in the box"]]
6dd74de280```
6dd74de281
6dd74de282```mermaid
6dd74de283block
6dd74de284 id1[["This is the text in the box"]]
6dd74de285```
6dd74de286
6dd74de287#### Example - Cylindrical Shape
6dd74de288
6dd74de289The cylindrical shape is ideal for representing databases or storage components:
6dd74de290
6dd74de291```mermaid-example
6dd74de292block
6dd74de293 id1[("Database")]
6dd74de294```
6dd74de295
6dd74de296```mermaid
6dd74de297block
6dd74de298 id1[("Database")]
6dd74de299```
6dd74de300
6dd74de301#### Example - Circle Shape
6dd74de302
6dd74de303A circle can be used for centralized or pivotal components:
6dd74de304
6dd74de305```mermaid-example
6dd74de306block
6dd74de307 id1(("This is the text in the circle"))
6dd74de308```
6dd74de309
6dd74de310```mermaid
6dd74de311block
6dd74de312 id1(("This is the text in the circle"))
6dd74de313```
6dd74de314
6dd74de315#### Example - Asymmetric, Rhombus, and Hexagon Shapes
6dd74de316
6dd74de317For decision points, use a rhombus, and for unique or specialized processes, asymmetric and hexagon shapes can be utilized:
6dd74de318
6dd74de319**Asymmetric**
6dd74de320
6dd74de321```mermaid-example
6dd74de322block
6dd74de323 id1>"This is the text in the box"]
6dd74de324```
6dd74de325
6dd74de326```mermaid
6dd74de327block
6dd74de328 id1>"This is the text in the box"]
6dd74de329```
6dd74de330
6dd74de331**Rhombus**
6dd74de332
6dd74de333```mermaid-example
6dd74de334block
6dd74de335 id1{"This is the text in the box"}
6dd74de336```
6dd74de337
6dd74de338```mermaid
6dd74de339block
6dd74de340 id1{"This is the text in the box"}
6dd74de341```
6dd74de342
6dd74de343**Hexagon**
6dd74de344
6dd74de345```mermaid-example
6dd74de346block
6dd74de347 id1{{"This is the text in the box"}}
6dd74de348```
6dd74de349
6dd74de350```mermaid
6dd74de351block
6dd74de352 id1{{"This is the text in the box"}}
6dd74de353```
6dd74de354
6dd74de355#### Example - Parallelogram and Trapezoid Shapes
6dd74de356
6dd74de357Parallelogram and trapezoid shapes are perfect for inputs/outputs and transitional processes:
6dd74de358
6dd74de359```mermaid-example
6dd74de360block
6dd74de361 id1[/"This is the text in the box"/]
6dd74de362 id2[\"This is the text in the box"\]
6dd74de363 A[/"Christmas"\]
6dd74de364 B[\"Go shopping"/]
6dd74de365```
6dd74de366
6dd74de367```mermaid
6dd74de368block
6dd74de369 id1[/"This is the text in the box"/]
6dd74de370 id2[\"This is the text in the box"\]
6dd74de371 A[/"Christmas"\]
6dd74de372 B[\"Go shopping"/]
6dd74de373```
6dd74de374
6dd74de375#### Example - Double Circle
6dd74de376
6dd74de377For highlighting critical or high-priority components, a double circle can be effective:
6dd74de378
6dd74de379```mermaid-example
6dd74de380block
6dd74de381 id1((("This is the text in the circle")))
6dd74de382```
6dd74de383
6dd74de384```mermaid
6dd74de385block
6dd74de386 id1((("This is the text in the circle")))
6dd74de387```
6dd74de388
6dd74de389### Block Arrows and Space Blocks
6dd74de390
6dd74de391Mermaid also offers unique shapes like block arrows and space blocks for directional flow and spacing.
6dd74de392
6dd74de393#### Example - Block Arrows
6dd74de394
6dd74de395Block arrows can visually indicate direction or flow within a process:
6dd74de396
6dd74de397```mermaid-example
6dd74de398block
6dd74de399 blockArrowId<["Label"]>(right)
6dd74de400 blockArrowId2<["Label"]>(left)
6dd74de401 blockArrowId3<["Label"]>(up)
6dd74de402 blockArrowId4<["Label"]>(down)
6dd74de403 blockArrowId5<["Label"]>(x)
6dd74de404 blockArrowId6<["Label"]>(y)
6dd74de405 blockArrowId7<["Label"]>(x, down)
6dd74de406```
6dd74de407
6dd74de408```mermaid
6dd74de409block
6dd74de410 blockArrowId<["Label"]>(right)
6dd74de411 blockArrowId2<["Label"]>(left)
6dd74de412 blockArrowId3<["Label"]>(up)
6dd74de413 blockArrowId4<["Label"]>(down)
6dd74de414 blockArrowId5<["Label"]>(x)
6dd74de415 blockArrowId6<["Label"]>(y)
6dd74de416 blockArrowId7<["Label"]>(x, down)
6dd74de417```
6dd74de418
6dd74de419#### Example - Space Blocks
6dd74de420
6dd74de421Space blocks can be used to create intentional empty spaces in the diagram, which is useful for layout and readability:
6dd74de422
6dd74de423```mermaid-example
6dd74de424block
6dd74de425 columns 3
6dd74de426 a space b
6dd74de427 c d e
6dd74de428```
6dd74de429
6dd74de430```mermaid
6dd74de431block
6dd74de432 columns 3
6dd74de433 a space b
6dd74de434 c d e
6dd74de435```
6dd74de436
6dd74de437or
6dd74de438
6dd74de439```mermaid-example
6dd74de440block
6dd74de441 ida space:3 idb idc
6dd74de442```
6dd74de443
6dd74de444```mermaid
6dd74de445block
6dd74de446 ida space:3 idb idc
6dd74de447```
6dd74de448
6dd74de449Note 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.
6dd74de450
6dd74de451The 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.
6dd74de452
6dd74de453### Standard and Special Block Shapes
6dd74de454
6dd74de455Discuss the various shapes available for blocks, including standard shapes and special forms like block arrows and space blocks.
6dd74de456
6dd74de457## 5. Connecting Blocks with Edges
6dd74de458
6dd74de459One 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.
6dd74de460
6dd74de461### Basic Linking and Arrow Types
6dd74de462
6dd74de463The 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.
6dd74de464
6dd74de465**Example - Basic Links**
6dd74de466
6dd74de467A simple link with an arrow can be created to show direction or flow from one block to another:
6dd74de468
6dd74de469```mermaid-example
6dd74de470block
6dd74de471 A space B
6dd74de472 A-->B
6dd74de473```
6dd74de474
6dd74de475```mermaid
6dd74de476block
6dd74de477 A space B
6dd74de478 A-->B
6dd74de479```
6dd74de480
6dd74de481This example illustrates a direct connection from block 'A' to block 'B', using a straightforward arrow.
6dd74de482
6dd74de483This syntax creates a line connecting 'A' and 'B', implying a relationship or connection without indicating a specific direction.
6dd74de484
6dd74de485### Text on Links
6dd74de486
6dd74de487In 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.
6dd74de488
6dd74de489Example - Text with Links
6dd74de490To add text to a link, the syntax includes the text within the link definition:
6dd74de491
6dd74de492```mermaid-example
6dd74de493block
6dd74de494 A space:2 B
6dd74de495 A-- "X" -->B
6dd74de496```
6dd74de497
6dd74de498```mermaid
6dd74de499block
6dd74de500 A space:2 B
6dd74de501 A-- "X" -->B
6dd74de502```
6dd74de503
6dd74de504This example show how to add descriptive text to the links, enhancing the information conveyed by the diagram.
6dd74de505
6dd74de506Example - Edges and Styles:
6dd74de507
6dd74de508```mermaid-example
6dd74de509block
6dd74de510columns 1
6dd74de511 db(("DB"))
6dd74de512 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
6dd74de513 block:ID
6dd74de514 A
6dd74de515 B["A wide one in the middle"]
6dd74de516 C
6dd74de517 end
6dd74de518 space
6dd74de519 D
6dd74de520 ID --> D
6dd74de521 C --> D
6dd74de522 style B fill:#939,stroke:#333,stroke-width:4px
6dd74de523```
6dd74de524
6dd74de525```mermaid
6dd74de526block
6dd74de527columns 1
6dd74de528 db(("DB"))
6dd74de529 blockArrowId6<["&nbsp;&nbsp;&nbsp;"]>(down)
6dd74de530 block:ID
6dd74de531 A
6dd74de532 B["A wide one in the middle"]
6dd74de533 C
6dd74de534 end
6dd74de535 space
6dd74de536 D
6dd74de537 ID --> D
6dd74de538 C --> D
6dd74de539 style B fill:#939,stroke:#333,stroke-width:4px
6dd74de540```
6dd74de541
6dd74de542## 6. Styling and Customization
6dd74de543
6dd74de544Beyond 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.
6dd74de545
6dd74de546### Individual Block Styling
6dd74de547
6dd74de548Mermaid 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.
6dd74de549
6dd74de550#### Example - Styling a Single Block
6dd74de551
6dd74de552To apply custom styles to a block, you can use the `style` keyword followed by the block identifier and the desired CSS properties:
6dd74de553
6dd74de554```mermaid-example
6dd74de555block
6dd74de556 id1 space id2
6dd74de557 id1("Start")-->id2("Stop")
6dd74de558 style id1 fill:#636,stroke:#333,stroke-width:4px
6dd74de559 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de560```
6dd74de561
6dd74de562```mermaid
6dd74de563block
6dd74de564 id1 space id2
6dd74de565 id1("Start")-->id2("Stop")
6dd74de566 style id1 fill:#636,stroke:#333,stroke-width:4px
6dd74de567 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de568```
6dd74de569
6dd74de570### Class Styling
6dd74de571
6dd74de572Mermaid 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.
6dd74de573
6dd74de574#### Example - Styling a Single Class
6dd74de575
6dd74de576```mermaid-example
6dd74de577block
6dd74de578 A space B
6dd74de579 A-->B
6dd74de580 classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px;
6dd74de581 class A blue
6dd74de582 style B fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de583```
6dd74de584
6dd74de585```mermaid
6dd74de586block
6dd74de587 A space B
6dd74de588 A-->B
6dd74de589 classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px;
6dd74de590 class A blue
6dd74de591 style B fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de592```
6dd74de593
6dd74de594In 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.
6dd74de595
6dd74de596The 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.
6dd74de597
6dd74de598### 7. Practical Examples and Use Cases
6dd74de599
6dd74de600The 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.
6dd74de601
6dd74de602### Detailed Examples Illustrating Various Features
6dd74de603
6dd74de604Combining the elements of structure, linking, and styling, we can create comprehensive diagrams that serve specific purposes in different contexts.
6dd74de605
6dd74de606#### Example - System Architecture
6dd74de607
6dd74de608Illustrating a simple software system architecture with interconnected components:
6dd74de609
6dd74de610```mermaid-example
6dd74de611block
6dd74de612 columns 3
6dd74de613 Frontend blockArrowId6<[" "]>(right) Backend
6dd74de614 space:2 down<[" "]>(down)
6dd74de615 Disk left<[" "]>(left) Database[("Database")]
6dd74de616
6dd74de617 classDef front fill:#696,stroke:#333;
6dd74de618 classDef back fill:#969,stroke:#333;
6dd74de619 class Frontend front
6dd74de620 class Backend,Database back
6dd74de621```
6dd74de622
6dd74de623```mermaid
6dd74de624block
6dd74de625 columns 3
6dd74de626 Frontend blockArrowId6<[" "]>(right) Backend
6dd74de627 space:2 down<[" "]>(down)
6dd74de628 Disk left<[" "]>(left) Database[("Database")]
6dd74de629
6dd74de630 classDef front fill:#696,stroke:#333;
6dd74de631 classDef back fill:#969,stroke:#333;
6dd74de632 class Frontend front
6dd74de633 class Backend,Database back
6dd74de634```
6dd74de635
6dd74de636This example shows a basic architecture with a frontend, backend, and database. The blocks are styled to differentiate between types of components.
6dd74de637
6dd74de638#### Example - Business Process Flow
6dd74de639
6dd74de640Representing a business process flow with decision points and multiple stages:
6dd74de641
6dd74de642```mermaid-example
6dd74de643block
6dd74de644 columns 3
6dd74de645 Start(("Start")) space:2
6dd74de646 down<[" "]>(down) space:2
6dd74de647 Decision{{"Make Decision"}} right<["Yes"]>(right) Process1["Process A"]
6dd74de648 downAgain<["No"]>(down) space r3<["Done"]>(down)
6dd74de649 Process2["Process B"] r2<["Done"]>(right) End(("End"))
6dd74de650
6dd74de651 style Start fill:#969;
6dd74de652 style End fill:#696;
6dd74de653```
6dd74de654
6dd74de655```mermaid
6dd74de656block
6dd74de657 columns 3
6dd74de658 Start(("Start")) space:2
6dd74de659 down<[" "]>(down) space:2
6dd74de660 Decision{{"Make Decision"}} right<["Yes"]>(right) Process1["Process A"]
6dd74de661 downAgain<["No"]>(down) space r3<["Done"]>(down)
6dd74de662 Process2["Process B"] r2<["Done"]>(right) End(("End"))
6dd74de663
6dd74de664 style Start fill:#969;
6dd74de665 style End fill:#696;
6dd74de666```
6dd74de667
6dd74de668These practical examples and scenarios underscore the utility of Mermaid block diagrams in simplifying and effectively communicating complex information across various domains.
6dd74de669
6dd74de670The 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.
6dd74de671
6dd74de672## 8. Troubleshooting and Common Issues
6dd74de673
6dd74de674Working 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.
6dd74de675
6dd74de676### Common Syntax Errors
6dd74de677
6dd74de678Understanding and avoiding common syntax errors is key to a smooth experience with Mermaid diagrams.
6dd74de679
6dd74de680#### Example - Incorrect Linking
6dd74de681
6dd74de682A common mistake is incorrect linking syntax, which can lead to unexpected results or broken diagrams:
6dd74de683
6dd74de684```
6dd74de685block
6dd74de686 A - B
6dd74de687```
6dd74de688
6dd74de689**Correction**:
6dd74de690Ensure 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:
6dd74de691
6dd74de692```mermaid-example
6dd74de693block
6dd74de694 A space B
6dd74de695 A --> B
6dd74de696```
6dd74de697
6dd74de698```mermaid
6dd74de699block
6dd74de700 A space B
6dd74de701 A --> B
6dd74de702```
6dd74de703
6dd74de704#### Example - Misplaced Styling
6dd74de705
6dd74de706Applying styles in the wrong context or with incorrect syntax can lead to blocks not being styled as intended:
6dd74de707
6dd74de708```mermaid-example
6dd74de709 block
6dd74de710 A
6dd74de711 style A fill#969;
6dd74de712```
6dd74de713
6dd74de714```mermaid
6dd74de715 block
6dd74de716 A
6dd74de717 style A fill#969;
6dd74de718```
6dd74de719
6dd74de720**Correction:**
6dd74de721Correct the syntax by ensuring proper separation of style properties with commas and using the correct CSS property format:
6dd74de722
6dd74de723```mermaid-example
6dd74de724block
6dd74de725 A
6dd74de726 style A fill:#969,stroke:#333;
6dd74de727
6dd74de728```
6dd74de729
6dd74de730```mermaid
6dd74de731block
6dd74de732 A
6dd74de733 style A fill:#969,stroke:#333;
6dd74de734
6dd74de735```
6dd74de736
6dd74de737### Tips for Complex Diagram Structures
6dd74de738
6dd74de739Managing complexity in Mermaid diagrams involves planning and employing best practices.
6dd74de740
6dd74de741#### Modular Design
6dd74de742
6dd74de743Break 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.
6dd74de744
6dd74de745#### Consistent Styling
6dd74de746
6dd74de747Use classes to maintain consistent styling across similar elements. This not only saves time but also ensures a cohesive and professional appearance.
6dd74de748
6dd74de749#### Comments and Documentation
6dd74de750
6dd74de751Use 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.
6dd74de752
6dd74de753With 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.