## set_direction()


Rewrite the direction of a flowchart, state, class, or git graph diagram.


Usage


``` python
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`, and `graph`: the header direction.
- `stateDiagram` and `classDiagram`: a `direction` statement is replaced or added. `"TD"` is written as `TB`.
- `gitGraph`: the header (`gitGraph TB:`). `"TD"` is written as `TB`; `"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 `direction` is not a key of `DIRECTIONS`.


## Examples

``` python
>>> set_direction("flowchart TD", "LR")
```

'flowchart LR'

``` python
>>> set_direction("classDiagram", "RL")
```

'classDiagramdirection RL'
