flowchart


title: Flowcharts Syntax

关于mermaid
本文GitHub项目地址
在线编辑:Mermaid Live Editor
在线编辑教程

Flowcharts - Basic Syntax

Flowcharts are composed of nodes (geometric shapes) and edges (arrows or lines). The Mermaid code defines how nodes and edges are made and accommodates different arrow types, multi-directional arrows, and any linking to and from subgraphs.

If you are using the word "end" in a Flowchart node, capitalize the entire word or any of the letters (e.g., "End" or "END"), or apply this [workaround](https://github.com/mermaid-js/mermaid/issues/1444#issuecomment-639528897). Typing "end" in all lowercase letters will break the Flowchart.
If you are using the letter "o" or "x" as the first letter in a connecting Flowchart node, add a space before the letter or capitalize the letter (e.g., "dev--- ops", "dev---Ops").

Typing "A---oB" will create a [circle edge](#circle-edge-example).

Typing "A---xB" will create a [cross edge](#cross-edge-example).

A node (default)

---
title: Node
---
flowchart LR
    id

在这里插入图片描述

The id is what is displayed in the box.

Instead of `flowchart` one can also use `graph`.

A node with text

It is also possible to set text in the box that differs from the id. If this is done several times, it is the last text
found for the node that will be used. Also if you define edges for the node later on, you can omit text definitions. The
one previously defined will be used when rendering the box.

---
title: Node with text
---
flowchart LR
    id1[This is the text in the box]

在这里插入图片描述

Unicode text

Use " to enclose the unicode text.

flowchart LR
    id["This ❤ Unicode"]
This ❤ Unicode
Markdown formatting

Use double quotes and backticks “` text `” to enclose the markdown text.

%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
    markdown["`This **is** _Markdown_`"]
    newLines["`Line1
    Line 2
    Line 3`"]
    markdown --> newLines
`This **is** _Markdown_` `Line1 Line 2 Line 3`

Direction

This statement declares the direction of the Flowchart.

This declares the flowchart is oriented from top to bottom (TD or TB).

flowchart TD
    Start --> Stop
Start
Stop

This declares the flowchart is oriented from left to right (LR).

flowchart LR
    Start --> Stop
Start
Stop

Possible FlowChart orientations are:

  • TB - Top to bottom
  • TD - Top-down/ same as top to bottom
  • BT - Bottom to top
  • RL - Right to left
  • LR - Left to right

Node shapes

A node with round edges

flowchart LR
    id1(This is the text in the box)
This is the text in the box

A stadium-shaped node

flowchart LR
    id1([This is the text in the box])
This is the text in the box

A node in a subroutine shape

flowchart LR
    id1[[This is the text in the box]]
This is the text in the box

A node in a cylindrical shape

flowchart LR
    id1[(Database)]
Database

A node in the form of a circle

flowchart LR
    id1((This is the text in the circle))
This is the text in the circle

A node in an asymmetric shape

flowchart LR
    id1>This is the text in the box]
This is the text in the box

Currently only the shape above is possible and not its mirror. This might change with future releases.

A node (rhombus)

flowchart LR
    id1{This is the text in the box}
This is the text in the box

A hexagon node

flowchart LR
    id1{{This is the text in the box}}
This is the text in the box

Parallelogram

flowchart TD
    id1[/This is the text in the box/]
This is the text in the box

Parallelogram alt

flowchart TD
    id1[\This is the text in the box\]
This is the text in the box

Trapezoid

flowchart TD
    A[/Christmas\]
Christmas

Trapezoid alt

flowchart TD
    B[\Go shopping/]
Go shopping

Double circle

flowchart TD
    id1(((This is the text in the circle)))

Links between nodes

Nodes can be connected with links/edges. It is possible to have different types of links or attach a text string to a link.

A link with arrow head

flowchart LR
    A-->B
A
B

An open link

flowchart LR
    A --- B
A
B

Text on links

flowchart LR
    A-- This is the text! ---B
This is the text!
A
B

or

flowchart LR
    A---|This is the text|B
This is the text
A
B

A link with arrow head and text

flowchart LR
    A-->|text|B
text
A
B

or

flowchart LR
    A-- text -->B
text
A
B

Dotted link

flowchart LR
   A-.->B;
A
B

Dotted link with text

flowchart LR
   A-. text .-> B
text
A
B

Thick link

flowchart LR
   A ==> B
A
B

Thick link with text

flowchart LR
   A == text ==> B
text
A
B

An invisible link

This can be a useful tool in some instances where you want to alter the default positioning of a node.

flowchart LR
    A ~~~ B

在这里插入图片描述

Chaining of links

It is possible declare many links in the same line as per below:

flowchart LR
   A -- text --> B -- text2 --> C
text
text2
A
B
C

It is also possible to declare multiple nodes links in the same line as per below:

flowchart LR
   a --> b & c--> d
a
b
c
d

You can then describe dependencies in a very expressive way. Like the one-liner below:

flowchart TB
    A & B--> C & D
A
B
C
D

If you describe the same diagram using the basic syntax, it will take four lines. A
word of warning, one could go overboard with this making the flowchart harder to read in
markdown form. The Swedish word lagom comes to mind. It means, not too much and not too little.
This goes for expressive syntaxes as well.

flowchart TB
    A --> C
    A --> D
    B --> C
    B --> D
A
C
D
B

New arrow types

There are new types of arrows supported:

  • circle edge
  • cross edge

Circle edge example

flowchart LR
    A --o B
A
B

Cross edge example

flowchart LR
    A --x B
A
B

Multi directional arrows

There is the possibility to use multidirectional arrows.

flowchart LR
    A o--o B
    B <--> C
    C x--x D
A
B
C
D

Minimum length of a link

Each node in the flowchart is ultimately assigned to a rank in the rendered
graph, i.e. to a vertical or horizontal level (depending on the flowchart
orientation), based on the nodes to which it is linked. By default, links
can span any number of ranks, but you can ask for any link to be longer
than the others by adding extra dashes in the link definition.

In the following example, two extra dashes are added in the link from node B
to node E, so that it spans two more ranks than regular links:

flowchart TD
    A[Start] --> B{Is it?}
    B -->|Yes| C[OK]
    C --> D[Rethink]
    D --> B
    B ---->|No| E[End]
Yes
No
Start
Is it?
OK
Rethink
End

Note Links may still be made longer than the requested number of ranks
by the rendering engine to accommodate other requests.

When the link label is written in the middle of the link, the extra dashes must
be added on the right side of the link. The following example is equivalent to
the previous one:

flowchart TD
    A[Start] --> B{Is it?}
    B -- Yes --> C[OK]
    C --> D[Rethink]
    D --> B
    B -- No ----> E[End]
Yes
No
Start
Is it?
OK
Rethink
End

For dotted or thick links, the characters to add are equals signs or dots,
as summed up in the following table:

Length123
Normal------------
Normal with arrow-->--->---->
Thick============
Thick with arrow==>===>====>
Dotted-.--..--...-
Dotted with arrow-.->-..->-...->

Special characters that break syntax

It is possible to put text within quotes in order to render more troublesome characters. As in the example below:

flowchart LR
    id1["This is the (text) in the box"]
This is the (text) in the box

Entity codes to escape characters

It is possible to escape characters using the syntax exemplified here.

    flowchart LR
        A["A double quote:#quot;"] --> B["A dec char:#9829;"]
A double quote:"
A dec char:♥

Numbers given are base 10, so # can be encoded as #35;. It is also supported to use HTML character names.

Subgraphs

subgraph title
    graph definition
end

An example below:

flowchart TB
    c1-->a2
    subgraph one
    a1-->a2
    end
    subgraph two
    b1-->b2
    end
    subgraph three
    c1-->c2
    end
three
one
c2
c1
two
b2
b1
a2
a1

You can also set an explicit id for the subgraph.

flowchart TB
    c1-->a2
    subgraph ide1 [one]
    a1-->a2
    end
one
a2
a1
c1

flowcharts

With the graphtype flowchart it is also possible to set edges to and from subgraphs as in the flowchart below.

flowchart TB
    c1-->a2
    subgraph one
    a1-->a2
    end
    subgraph two
    b1-->b2
    end
    subgraph three
    c1-->c2
    end
    one --> two
    three --> two
    two --> c2
three
one
c2
c1
two
b2
b1
a2
a1

Direction in subgraphs

With the graphtype flowcharts you can use the direction statement to set the direction which the subgraph will render like in this example.

flowchart LR
  subgraph TOP
    direction TB
    subgraph B1
        direction RL
        i1 -->f1
    end
    subgraph B2
        direction BT
        i2 -->f2
    end
  end
  A --> TOP --> B
  B1 --> B2
TOP
B1
f1
i1
B2
f2
i2
A
B
Limitation

If any of a subgraph’s nodes are linked to the outside, subgraph direction will be ignored. Instead the subgraph will inherit the direction of the parent graph:

flowchart LR
    subgraph subgraph1
        direction TB
        top1[top] --> bottom1[bottom]
    end
    subgraph subgraph2
        direction TB
        top2[top] --> bottom2[bottom]
    end
    %% ^ These subgraphs are identical, except for the links to them:

    %% Link *to* subgraph1: subgraph1 direction is maintained
    outside --> subgraph1
    %% Link *within* subgraph2:
    %% subgraph2 inherits the direction of the top-level graph (LR)
    outside ---> top2
subgraph2
bottom
top
subgraph1
bottom
top
outside

Markdown Strings

The “Markdown Strings” feature enhances flowcharts and mind maps by offering a more versatile string type, which supports text formatting options such as bold and italics, and automatically wraps text within labels.

%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
subgraph "One"
  a("`The **cat**
  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
end
subgraph "`**Two**`"
  c("`The **cat**
  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
end
`**Two**` `Bold **edge label**` The dog in the hog `The **cat** in the hat` One edge label `The **dog** in the hog` `The **cat** in the hat`

Formatting:

  • For bold text, use double asterisks (**) before and after the text.
  • For italics, use single asterisks (*) before and after the text.
  • With traditional strings, you needed to add <br> tags for text to wrap in nodes. However, markdown strings automatically wrap text when it becomes too long and allows you to start a new line by simply using a newline character instead of a <br> tag.

This feature is applicable to node labels, edge labels, and subgraph labels.

The auto wrapping can be disabled by using

---
config:
  markdownAutoWrap: false
---
graph LR

Interaction

It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab.

This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`.
click nodeId callback
click nodeId call callback()
  • nodeId is the id of the node
  • callback is the name of a javascript function defined on the page displaying the graph, the function will be called with the nodeId as parameter.

Examples of tooltip usage below:

<script>
  window.callback = function () {
    alert('A callback was triggered');
  };
</script>

The tooltip text is surrounded in double quotes. The styles of the tooltip are set by the class .mermaidTooltip.

flowchart LR
    A-->B
    B-->C
    C-->D
    click A callback "Tooltip for a callback"
    click B "https://www.github.com" "This is a tooltip for a link"
    click C call callback() "Tooltip for a callback"
    click D href "https://www.github.com" "This is a tooltip for a link"
A
B
C
D

Success The tooltip functionality and the ability to link to urls are available from version 0.5.2.

Due to limitations with how Docsify handles JavaScript callback functions, an alternate working demo for the above code can be viewed at this jsfiddle.

Links are opened in the same browser tab/window by default. It is possible to change this by adding a link target to the click definition (_self, _blank, _parent and _top are supported):

flowchart LR
    A-->B
    B-->C
    C-->D
    D-->E
    click A "https://www.github.com" _blank
    click B "https://www.github.com" "Open this in a new tab" _blank
    click C href "https://www.github.com" _blank
    click D href "https://www.github.com" "Open this in a new tab" _blank
A
B
C
D
E

Beginner’s tip—a full example using interactive links in a html context:

<body>
  <pre class="mermaid">
    flowchart LR
        A-->B
        B-->C
        C-->D
        click A callback "Tooltip"
        click B "https://www.github.com" "This is a link"
        click C call callback() "Tooltip"
        click D href "https://www.github.com" "This is a link"
  </pre>

  <script>
    window.callback = function () {
      alert('A callback was triggered');
    };
    const config = {
      startOnLoad: true,
      flowchart: { useMaxWidth: true, htmlLabels: true, curve: 'cardinal' },
      securityLevel: 'loose',
    };
    mermaid.initialize(config);
  </script>
</body>

Comments

Comments can be entered within a flow diagram, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with %% (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any flow syntax

flowchart LR
%% this is a comment A -- text --> B{node}
   A -- text --> B -- text2 --> C
text
text2
A
B
C

Styling and classes

Styling links

It is possible to style links. For instance, you might want to style a link that is going backwards in the flow. As links
have no ids in the same way as nodes, some other way of deciding what style the links should be attached to is required.
Instead of ids, the order number of when the link was defined in the graph is used, or use default to apply to all links.
In the example below the style defined in the linkStyle statement will belong to the fourth link in the graph:

linkStyle 3 stroke:#ff3,stroke-width:4px,color:red;

It is also possible to add style to multiple links in a single statement, by separating link numbers with commas:

linkStyle 1,2,7 color:blue;

Styling line curves

It is possible to style the type of curve used for lines between items, if the default method does not meet your needs.
Available curve styles include basis, bumpX, bumpY, cardinal, catmullRom, linear, monotoneX, monotoneY,
natural, step, stepAfter, and stepBefore.

In this example, a left-to-right graph uses the stepBefore curve style:

%%{ init: { 'flowchart': { 'curve': 'stepBefore' } } }%%
graph LR

For a full list of available curves, including an explanation of custom curves, refer to
the Shapes documentation in the
d3-shape project.

Styling a node

It is possible to apply specific styles such as a thicker border or a different background color to a node.

flowchart LR
    id1(Start)-->id2(Stop)
    style id1 fill:#f9f,stroke:#333,stroke-width:4px
    style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
Start
Stop
Classes

More convenient than defining the style every time is to define a class of styles and attach this class to the nodes that
should have a different look.

A class definition looks like the example below:

    classDef className fill:#f9f,stroke:#333,stroke-width:4px;

Also, it is possible to define style to multiple classes in one statement:

    classDef firstClassName,secondClassName font-size:12pt;

Attachment of a class to a node is done as per below:

    class nodeId1 className;

It is also possible to attach a class to a list of nodes in one statement:

    class nodeId1,nodeId2 className;

A shorter form of adding a class is to attach the classname to the node using the :::operator as per below:

flowchart LR
    A:::someclass --> B
    classDef someclass fill:#f96
A
B

This form can be used when declaring multiple links between nodes:

flowchart LR
    A:::foo & B:::bar --> C:::foobar
    classDef foo stroke:#f00
    classDef bar stroke:#0f0
    classDef foobar stroke:#00f

在这里插入图片描述

CSS classes

It is also possible to predefine classes in CSS styles that can be applied from the graph definition as in the example
below:

Example style

<style>
  .cssClass > rect {
    fill: #ff0000;
    stroke: #ffff00;
    stroke-width: 4px;
  }
</style>

Example definition

flowchart LR
    A-->B[AAA<span>BBB</span>]
    B-->D
    class A cssClass
A
AAABBB
D

Default class

If a class is named default it will be assigned to all classes without specific class definitions.

    classDef default fill:#f9f,stroke:#333,stroke-width:4px;

Basic support for fontawesome

It is possible to add icons from fontawesome.

The icons are accessed via the syntax fa:#icon class name#.

flowchart TD
    B["fa:fa-twitter for peace"]
    B-->C[fa:fa-ban forbidden]
    B-->D(fa:fa-spinner)
    B-->E(A fa:fa-camera-retro perhaps?)
for peace
forbidden
A perhaps?

Mermaid supports Font Awesome if the CSS is included on the website.
Mermaid does not have any restriction on the version of Font Awesome that can be used.

Please refer the Official Font Awesome Documentation on how to include it in your website.

Adding this snippet in the <head> would add support for Font Awesome v6.5.1

<link
  href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
  rel="stylesheet"
/>

Custom icons

It is possible to use custom icons served from Font Awesome as long as the website imports the corresponding kit.

Note that this is currently a paid feature from Font Awesome.

For custom icons, you need to use the fak prefix.

Example

flowchart TD
    B[fa:fa-twitter] %% standard icon
    B-->E(fak:fa-custom-icon-name) %% custom icon
fak:fa-custom-icon-name

And trying to render it

flowchart TD
    B["fa:fa-twitter for peace"]
    B-->C["fab:fa-truck-bold a custom icon"]
for peace
a custom icon

Graph declarations with spaces between vertices and link and without semicolon

  • In graph declarations, the statements also can now end without a semicolon. After release 0.2.16, ending a graph statement with semicolon is just optional. So the below graph declaration is also valid along with the old declarations of the graph.

  • A single space is allowed between vertices and the link. However there should not be any space between a vertex and its text and a link and its text. The old syntax of graph declaration will also work and hence this new feature is optional and is introduced to improve readability.

Below is the new declaration of the graph edges which is also valid along with the old declaration of the graph edges.

flowchart LR
    A[Hard edge] -->|Link text| B(Round edge)
    B --> C{Decision}
    C -->|One| D[Result one]
    C -->|Two| E[Result two]
Link text
One
Two
Hard edge
Round edge
Decision
Result one
Result two

Configuration

Renderer

The layout of the diagram is done with the renderer. The default renderer is dagre.

Starting with Mermaid version 9.4, you can use an alternate renderer named elk. The elk renderer is better for larger and/or more complex diagrams.

The elk renderer is an experimental feature.
You can change the renderer to elk by adding this directive:

%%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
Note that the site needs to use mermaid version 9.4+ for this to work and have this featured enabled in the lazy-loading configuration.

Width

It is possible to adjust the width of the rendered flowchart.

This is done by defining mermaid.flowchartConfig or by the CLI to use a JSON file with the configuration. How to use the CLI is described in the mermaidCLI page.
mermaid.flowchartConfig can be set to a JSON string with config parameters or the corresponding object.

mermaid.flowchartConfig = {
    width: 100%
}
  • 35
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
数字乡村和智慧农业的数字化转型是当前农业发展的新趋势,旨在通过应用数字技术,实现农业全流程的再造和全生命周期的管理服务。中国政府高度重视这一领域的发展,提出“数字中国”和“乡村振兴”战略,以提升国家治理能力,推动城乡融合发展。 数字乡村的建设面临乡村治理、基础设施、产业链条和公共服务等方面的问题,需要分阶段实施《数字乡村发展战略纲要》来解决。农业数字化转型的需求包括满足市民对优质农产品的需求、解决产销对接问题、形成优质优价机制、提高农业劳动力素质、打破信息孤岛、提高农业政策服务的精准度和有效性,以及解决农业融资难的问题。 数字乡村建设的关键在于构建“1+3+4+1”工程,即以新技术、新要素、新商业、新农民、新文化、新农村为核心,推进数据融合,强化农业大数据的汇集功能。数字农业大数据解决方案以农业数字底图和数据资源为基础,通过可视化监管,实现区域农业的全面数字化管理。 数字农业大数据架构基于大数据、区块链、GIS和物联网技术,构建农业大数据中心、农业物联网平台和农村综合服务指挥决策平台三大基础平台。农业大数据中心汇聚各类涉农信息资源和业务数据,支持大数据应用。信息采集系统覆盖市、县、乡、村多级,形成高效的农业大数据信息采集体系。 农业物联网平台包括环境监测系统、视频监控系统、预警预报系统和智能控制系统,通过收集和监测数据,实现对农业环境和生产过程的智能化管理。综合服务指挥决策平台利用数据分析和GIS技术,为农业决策提供支持。 数字乡村建设包括三大服务平台:治理服务平台、民生服务平台和产业服务平台。治理服务平台通过大数据和AI技术,实现乡村治理的数字化;民生服务平台利用互联网技术,提供各类民生服务;产业服务平台融合政企关系,支持农业产业发展。 数字乡村的应用场景广泛,包括农业生产过程、农产品流通、农业管理和农村社会服务。农业生产管理系统利用AIoT技术,实现农业生产的标准化和智能化。农产品智慧流通管理系统和溯源管理系统提高流通效率和产品追溯能力。智慧农业管理通过互联网+农业,提升农业管理的科学性和效率。农村社会服务则通过数字化手段,提高农村地区的公共服务水平。 总体而言,数字乡村和智慧农业的建设,不仅能够提升农业生产效率和管理水平,还能够促进农村地区的社会经济发展,实现城乡融合发展,是推动中国农业现代化的重要途径。
要安装Flowchart库,你可以按照以下步骤进行操作: 1. 首先,你需要从官方资源来源下载`pyppl_flowchart-0.1.3.tar.gz`文件。 2. 然后,你可以使用命令行或终端窗口进入到下载的文件所在的目录。 3. 接下来,你可以使用以下命令来安装Flowchart库: ```python pip install pyppl_flowchart-0.1.3.tar.gz ``` 4. 安装完成后,你可以在你的Python代码中导入Flowchart库并使用它来生成流程图。根据引用中提供的示例代码,你可以尝试以下操作: ```python from pyflowchart import Flowchart with open('month.py', encoding='utf-8', errors='ignore') as f: code = f.read() fc = Flowchart.from_code(code) print(fc.flowchart()) ``` 请注意,如果你在代码中使用了`%matplotlib inline`命令,你可能会遇到报错。根据引用中的解决方案,你可以将该行代码注释掉以解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [将python代码转换为flowchart代码](https://blog.csdn.net/qq_45423811/article/details/124789867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python库 | pyppl_flowchart-0.1.3.tar.gz](https://download.csdn.net/download/qq_38161040/85126325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JansonYG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值