Flowcharts: linkStyle interpolation

Flowcharts: linkStyle interpolation

puml.online

简介 / Introduction

The connectors in a flowchart are the most overlooked and most semantically loaded part of the drawing: when the happy path, the error path and the audit path all look the same, readers have to parse labels to figure out which is which. Mermaid styles an individual edge with the linkStyle statement, addressed by index; PlantUML instead inlines the color and line style directly on the arrow. There is a subtler difference too — whether an edge is drawn straight, as a polyline, or as a smooth curve is decided by the interpolation mode, and in Mermaid that switch lives in the %%{init:...}%% directive, entirely separate from linkStyle. This post walks through both approaches with the same request-validation flow.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@startuml
skinparam ArrowColor #666666
skinparam ArrowThickness 1

start
:接收请求;
if (参数合法?) then (是)
:写入缓存;
:返回结果;
else (否)
:返回错误;
endif
stop

:失败分支;
-[#d33,bold]->
:重试;

:审计日志;
-[#999,dashed]->
:落盘;
@enduml

Key syntax notes:

  • skinparam ArrowColor / skinparam ArrowThickness — set the baseline color and width for every arrow; the scope is global
  • -[#d33,bold]-> — inline styling on the arrow itself. #d33 is a hex color, and bold thickens the line (the rendered output shows stroke-width:2)
  • -[#999,dashed]-> — a dashed line. PlantUML supports dashed (renders as stroke-dasharray:7,7) and dotted (stroke-dasharray:1,3)
  • Important: PlantUML does not accept thickness=2. Using it returns an HTTP 400 syntax error; bold is the only thickness knob available
  • The color in the bracket is a completely separate mechanism from the node color suffix <<#RRGGBB>> — the two never interact

PlantUML’s model is “style travels with the edge”: each style sits right next to the arrow it applies to. There is no index, and therefore no risk of an off-by-one.

Mermaid 版

1
2
3
4
5
6
7
8
9
%%{init: {"flowchart": {"curve": "linear"}}}%%
flowchart TD
A[接收请求] --> B{参数合法?}
B -->|是| C[写入缓存]
B -->|否| D[返回错误]
C --> E[返回结果]
D -.-> F[记录日志]
linkStyle 2 stroke:#d33,stroke-width:2px
linkStyle 4 stroke:#999,stroke-width:1px

Key syntax notes:

  • linkStyle <index> <properties> — styles one edge by its declaration order, counted from 0. There are five edges here: A→B(0), B→C(1), B→D(2), C→E(3), D→F(4)
  • Supported properties: stroke (color), stroke-width (thickness), stroke-dasharray (dash spacing, e.g. 5 5)
  • linkStyle can only target an edge that already exists. An out-of-range index fails hard: The index 4 for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and 3.
  • %%{init: {"flowchart": {"curve": "linear"}}}%% — this is the global curve interpolation switch and has nothing to do with linkStyle. curve accepts basis (the default, smooth spline), linear (polyline), monotoneX and others
  • The same setting can be written as YAML front matter: ---\nconfig:\n flowchart:\n curve: linear\n---

One trap worth remembering: interpolate is not a valid linkStyle property. Writing linkStyle 3 stroke:#999,interpolate:linear fails with Expecting 'SPACE', 'COLON', ... got 'INTERPOLATE'. Curve interpolation can only be set globally, via the init directive or the front matter — never per edge.

对比 / Side-by-side

Meaning PlantUML Mermaid
Color one edge -[#d33]-> inline on the arrow linkStyle 2 stroke:#d33
How an edge is addressed Inline syntax, no index needed Zero-based index in declaration order
Dashed line -[#999,dashed]-> linkStyle 2 stroke-dasharray:5 5
Thicker line -[#d33,bold]-> (one fixed step) stroke-width:2px (any value)
Global arrow baseline skinparam ArrowColor / ArrowThickness No dedicated statement; use classDef or themeVariables
Curve interpolation No equivalent — polylines only %%{init: {"flowchart": {"curve": "linear"}}}%%, diagram-wide
What a mistake costs Syntax error, HTTP 400 Out-of-range index or unknown property — rendering fails outright

小结 / Wrap-up

The division of labor is actually clean. PlantUML attaches styling to the edge itself, so a style can never drift onto the wrong arrow; Mermaid keeps styling in a separate global linkStyle list, which is easier to maintain centrally but leaves you responsible for counting edges. When working on Mermaid connectors, treat the linkStyle index and the curve interpolation setting as two unrelated concepts — the first controls color and thickness, the second controls geometry. Blurring them together is exactly how you end up with interpolate being rejected as an invalid property.

  • Title: Flowcharts: linkStyle interpolation
  • Author: puml.online
  • Created at : 2026-11-11 09:00:00
  • Updated at : 2026-11-26 01:07:01
  • Link: https://puml.online/blog/flowchart-link-style-interpolate-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.