Skip to content

韦恩图 (v11.12.3+) ​

🌐 Venn diagrams (v11.12.3+)

维恩图使用重叠的圆圈显示集合之间的关系。

🌐 Venn diagrams show relationships between sets using overlapping circles.

警告 这是 Mermaid 中的一种新图表类型。其语法可能会在未来版本中演变。

默认主题和外观(v12.0.0及以上) ​

🌐 Default theme and look (v12.0.0+)

韦恩图默认使用 redux-color 主题和 neo 风格。并不是每种图表类型都这么做——请参阅 每图表默认值 获取列表以及 Mermaid 决定顺序。

🌐 Venn diagrams use the redux-color theme and the neo look by default. Not every diagram type does — see Per-diagram defaults for the list and for the order in which Mermaid decides.

同一个图,画法两种:

🌐 The same diagram, drawn both ways:

使用默认设置 ​

🌐 With the defaults

代码:
mermaid
⌘ + 回车键|

之前的样子 ​

🌐 The previous appearance

两者只是默认设置,所以你自己设置的任何东西都会生效。在图表的前言中命名之前的主题和样式会像以前 Mermaid 那样显示出来:

🌐 Both are only defaults, so anything you set yourself wins. Naming the previous theme and look in a diagram's front matter draws it the way Mermaid did before:

代码:
mermaid
⌘ + 回车键|

将同样的两个键传给 mermaid.initialize(),页面上的每个图表都会使用它;而将它们限制在一种图表类型 — mermaid.initialize({ venn: { theme: 'default', look: 'classic' } }) — 则只会对那种类型起作用。

🌐 Passing the same two keys to mermaid.initialize() does it for every diagram on the page, and scoping them to one diagram type — mermaid.initialize({ venn: { theme: 'default', look: 'classic' } }) — does it for that type alone.

语法 ​

🌐 Syntax

  • 从 venn-beta 开始。
  • 对于单个集合名称,使用 set。
  • 对于两个或更多集合名称的重叠,使用 union。
  • union 中的标识符必须由之前的 set 行定义。
  • 集合标识符可以是裸词(A、Set_1)或带引号的字符串("Foo Bar")。
代码:
mermaid
⌘ + 回车键|

标签 ​

🌐 Labels

使用括号语法 ["..."] 来设置显示标签,同时保持标识符简短:

🌐 Use bracket syntax ["..."] to set a display label while keeping the identifier short:

代码:
mermaid
⌘ + 回车键|

高阶联合 ​

🌐 Higher-arity unions

union 接受三个或更多集合名称。图表会自动渲染隐含的两两重叠,因此在高阶联合上的标签有可视区域显示:

代码:
mermaid
⌘ + 回车键|

尺寸 ​

🌐 Sizes

使用 :N 后缀来设置集合或并集的大小:

🌐 Use :N suffix to set the size of a set or union:

代码:
mermaid
⌘ + 回车键|

文本节点 ​

🌐 Text nodes

  • 使用 text 将标签放置在集合或并集中。
  • 缩进的 text 行附加到最近的 set 或 union。
  • 使用括号语法 ["..."] 为文本节点设置显示标签。
代码:
mermaid
⌘ + 回车键|

样式 ​

🌐 Styling

使用 style 语句将视觉样式应用到集合、并集和文本节点:

🌐 Use style statements to apply visual styles to sets, unions, and text nodes:

  • fill:更改填充颜色
  • color:更改文本颜色
  • stroke:更改描边颜色
  • stroke-width:更改笔画宽度
  • fill-opacity:更改填充不透明度
代码:
mermaid
⌘ + 回车键|
Opens in mermaid.ai