v0.2.3
https://pypi.org/project/pyflowchart/0.2.3/
What's Changed
Thanks @angerhang for digging out this feature.
Full Changelog: v0.1.4...v0.2.3r
v0.2.0 issue-14-align-conds
Support Node.set_param(key, value)
to generate flowchart like this:
element(param1=value1,param2=value2)=>start: Start
And as a grammar sugar, support ConditionNode.no_align_next()
to set a param align-next=no
.
cond2(align-next=no)=>condition: Yes or No?
For convenience, you can also specify this operation when constructing a ConditionNode by:
ConditionNode("a cond node", align_next=False)
(Version 0.2.0 and 0.2.1 do not involve anything function of python code to flowchart, but are features regarding writing flowcharts in python.)
v0.2.1 connect_direction setting for human!
I find it's hard to make something like cond2(yes,right)->io5
when testing the v0.2.0
. So I modified some interfaces to make it better.
To set a connection direction, Instead of calling the Node.set_connect_direction()
, since v0.2.1 you can just pass a second parameter to connect()
, which seems more human:
st = StartNode('a_pyflow_test')
op = OperationNode('do something')
cond1 = ConditionNode('Yes or No?', align_next=False)
cond2 = ConditionNode('True or False?', align_next=False)
cond3 = ConditionNode('1 or 0?', align_next=False)
io1 = InputOutputNode(InputOutputNode.OUTPUT, 'something...')
io2 = InputOutputNode(InputOutputNode.OUTPUT, 'anything...')
io3 = InputOutputNode(InputOutputNode.OUTPUT, 'nothing...')
sub = SubroutineNode('A Subroutine')
e = EndNode('a_pyflow_test')
st.connect(op, 'right')
op.connect(cond1)
cond1.connect_yes(io1, 'right')
cond2.connect_yes(io2, 'right')
cond3.connect_yes(io3, 'right')
cond1.connect_no(cond2)
cond2.connect_no(cond3)
io1.connect(sub, 'right')
io2.connect(sub, 'right')
io3.connect(sub, 'right')
sub.connect(e)
fc = Flowchart(st)
print(fc.flowchart())
Outputs:
st0=>start: start a_pyflow_test
op1=>operation: do something
cond2(align-next=no)=>condition: Yes or No?
io5=>inputoutput: output: something...
sub8=>subroutine: A Subroutine
e9=>end: end a_pyflow_test
cond3(align-next=no)=>condition: True or False?
io6=>inputoutput: output: anything...
cond4(align-next=no)=>condition: 1 or 0?
io7=>inputoutput: output: nothing...
st0(right)->op1
op1->cond2
cond2->
cond2->
cond2(yes, right)->io5
io5(right)->sub8
sub8->e9
cond2(no)->cond3
cond3->
cond3->
cond3(yes, right)->io6
io6(right)->sub8
cond3(no)->cond4
cond4->
cond4(yes, right)->io7
io7(right)->sub8
v0.2.2 conds-align for py2flowchart
Improve the flowchart of consecutive If statements converted from python code with the new feature of v0.2.0
:
# 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:
python3 -m pyflowchart example.py
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
But if we run it with --no-simplify
:
python3 -m pyflowchart --no-simplify example-condsalign.py
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
Ugly, right? No more~! This version offers a new --conds-align
flag to beautify these consecutive If statements.
python3 -m pyflowchart --no-simplify --conds-align example.py
or in 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:
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
v0.2.3 fix a bug
v0.2.1
(ddc4486) does something wrong causing the old way Node.set_connect_direction()
invalid. This version fixed it. So you can use both
sub.set_connect_direction("right")
sub.connect(op)
and
sub.connect(op, "right")
On a top level.
docs updates
Updates README, docs new features above.