set_direction()
Rewrite the direction of a flowchart, state, class, or git graph diagram.
Usage
set_direction(
code,
direction,
)Only the diagram type line (after any frontmatter and %% lines) and, for state and class diagrams, the top level direction statement are changed:
flowchart,flowchart-elk, andgraph: the header direction.stateDiagramandclassDiagram: adirectionstatement is replaced or added."TD"is written asTB.gitGraph: the header (gitGraph TB:)."TD"is written asTB;"RL"is not supported and leaves the code unchanged.
"asis" and every other diagram type return code unchanged.
Parameters
code: str-
Mermaid source.
direction: str-
A key of
DIRECTIONS:"asis","TD","BT","LR", or"RL".
Returns
str- The code with its direction rewritten.
Raises
ValueError-
If
directionis not a key ofDIRECTIONS.
Examples
>>> set_direction("flowchart TD", "LR")‘flowchart LR’
>>> set_direction("classDiagram", "RL")‘classDiagramdirection RL’