Improve the flowchart of *consecutive If statements* converted from python code with the new feature of `v0.2.0`:
python
example-conds-align.py
if cond1:
op1
if cond2:
op2
if cond3:
op3
op_end
It works fine in `v0.1.4` with the default `simplify` feature:
sh
python3 -m pyflowchart example.py
flow
cond3=>operation: op1 if cond1
cond14=>operation: op2 if cond2
cond25=>operation: op3 if cond3
op35=>operation: op_end
cond3->cond14
cond14->cond25
cond25->op35
![result-simplify](https://tva1.sinaimg.cn/large/008i3skNgy1gzcuv9rm3wj30we0ns3yx.jpg)
But if we run it with ` --no-simplify`:
sh
python3 -m pyflowchart --no-simplify example-condsalign.py
flow
cond3=>condition: if cond1
op7=>operation: op1
cond13=>condition: if cond2
op17=>operation: op2
cond23=>condition: if cond3
op27=>operation: op3
op32=>operation: op_end
cond3(yes)->op7
op7->cond13
cond13(yes)->op17
op17->cond23
cond23(yes)->op27
op27->op32
cond23(no)->op32
cond13(no)->cond23
cond3(no)->cond13
![result-old](https://tva1.sinaimg.cn/large/008i3skNgy1gzcuvb2nzbj30u00vjaap.jpg)
Ugly, right? No more~! This version offers a new `--conds-align` flag to beautify these *consecutive If statements*.
sh
python3 -m pyflowchart --no-simplify --conds-align example.py
or in python:
python
import pyflowchart
with open('example.py') as f:
code = f.read()
fc = pyflowchart.Flowchart.from_code(code, simplify=False, conds_align=True)
print(fc.flowchart())
Outputs:
flow
cond3(align-next=no)=>condition: if cond1
op7=>operation: op1
cond13(align-next=no)=>condition: if cond2
op17=>operation: op2
cond23=>condition: if cond3
op27=>operation: op3
op32=>operation: op_end
cond3(yes, right)->op7
op7->cond13
cond13(yes, right)->op17
op17->cond23
cond23(yes, right)->op27
op27->op32
cond23(no)->op32
cond13(no)->cond23
cond3(no)->cond13
![result-conds-align](https://tva1.sinaimg.cn/large/008i3skNgy1gzcuv8rg7kj30p40nqdgk.jpg)