Giter Club home page Giter Club logo

pyflowchart's Issues

ConditionNode alignment support

Thank you a lot for the package. It is really useful for one of my use cases in work :D

As raised in this issue, adrai/flowchart.js#221, it would be great to allow the align-text option set for the condition node. It should be something easy to do to set a positional argument in the constructor for the ConditionNode(name, isAlign=True).

Can this be added quickly? If not, we can maybe do a PR if you point out the caveats :D

Thought it we need to modify these two definitions?

class ConditionNode(Node):
def fc_definition(self) -> str:

Nodes: white spaces and shpes

Hi all,
I am using version 0.3.1 of pyflowchart and got two problems when creating my own flow chart.

First, I would like to change the shapes of the node. I searched around the source files and could spot the codes for changing the fill colours, font size etc and not the shapes of node. May I know where is this line?

Second, when creating my flowcharts, the white spaces in the text of each node become new lines. For example, when I have some node like :
st3=>start: start my function
The text in the output svg or png image will becomes:

start
my
function

I tried to search for some encoding issue when in the block of creating svg image, but failed. May I know how to solve it ?

I would be grateful if any expert could offer me with some advice. Thanks

Kenny

CLI running `python3 -m pyflowchart simple.py` got no outputs

People complain to me about pyflowchart outputting nothing! Here is an example:

test51f7b490-9c2a-4267-84a4-3006e144e08e jpg

Where simple.py is defined as:

from pkgutil import get_data

def foo(a, b):
    if a:
        print("a")
    else:
        for i in range(3):
            print("b")
    return a + b

Awfully strange it is that pyflowchart works well on my mac for the instance above:

testda96b50f-a211-43cf-9a33-e2fe718ef31e jpg

Whatever I know at the moment is that the described wrong behavior may be another bug related to the Windows :(

To handle this, I need more feedback.

Parallel node support

At the moment we can only support one flow out. Is there any plans to include parallel node type or even limited support? I am trying to draw something very simple but found it hard without the parallel node:

mtdzyl

At the moment, I can only do something like the below which is not ideal : (
Screenshot 2022-02-15 at 01 58 22

AttributeError: 'Unparser' object has no attribute '_str'. Did you mean: '_Str'? pyflowchart 0.3.1 with python 3.11 and astunparse 1.6.3

As pyflowchart 0.3.1 used with python 3.11 and astunparse 1.6.3 throws an exception:

Traceback (most recent call last):
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\flowchart.py", line 12, in <module>
    fc = pfc.parse(code)
         ^^^^^^^^^^^^^^^
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\pyflowchart\ast_node.py", line 659, in parse
    node = ast_node_class(ast_object, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\pyflowchart\ast_node.py", line 463, in __init__
    OperationNode.__init__(self, operation=self.ast_to_source())
                                           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\pyflowchart\ast_node.py", line 33, in ast_to_source
    return astunparse.unparse(self.ast_object).strip()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\astunparse\__init__.py", line 13, in unparse
    Unparser(tree, file=v)
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\astunparse\unparser.py", line 38, in __init__
    self.dispatch(tree)
  File "C:\Downloads\sc-navigator-model-generation-cp\APO Input Workflow\src\new_env\Lib\site-packages\astunparse\unparser.py", line 65, in dispatch
    meth = getattr(self, "_"+tree.__class__.__name__)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Unparser' object has no attribute '_str'. Did you mean: '_Str'?

How do I resolve this issue?

Originally posted by @kaasima10 in #28 (comment)

windows: UnicodeDecodeError: 'gbk' codec can't decode

Env

  • windwos 10 amd64
  • py 3.9.0
  • pyflowchart 0.1.0

Err

code

# This is statement is required by the build system to query build info
if __name__ == '__build__':
    raise Exception

# cube.py
# Converted to Python by Jason Petrone 6/00

import sys

try:
    from OpenGL.GLUT import *
    from OpenGL.GL import *
    from OpenGL.GLU import *
except:
    print("ERROR: PyOpenGL not installed properly")


def init():
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glShadeModel(GL_FLAT)


def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    glLoadIdentity()  # clear the matrix
    # viewing transformation
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
    glScalef(1.0, 2.0, 1.0)  # modeling transformation
    glutWireCube(1.0)
    glFlush()


def reshape(w, h):
    glViewport(0, 0, w, h)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
    glMatrixMode(GL_MODELVIEW)


glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowSize(500, 500)
glutInitWindowPosition(100, 100)
glutCreateWindow('cube')
init()
glutDisplayFunc(display)
glutReshapeFunc(reshape)

glutMainLoop()

Exceptioin

$ python -m pyflowchart cube.py
Traceback (most recent call last):
  File "D:\Program Files\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Program Files\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Program Files\Python\Python39\lib\site-packages\pyflowchart\__main__.py", line 33, in <module>
    main(args.code_file, args.field, args.inner)
  File "D:\Program Files\Python\Python39\lib\site-packages\pyflowchart\__main__.py", line 16, in main
    code = code_file.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 355: illegal multibyte sequence

另一个代码证明了不是code问题,也爆出了同样的错误,因此错误是由于该模块本身的问题...但是我目前的知识还不足以维护这个模块...

code2

import math
#  计算磁环的横截面积F  cm^2
def calMagnetRingCrossArea(D, d, h):
    return (0.5 * h * (D + d))

#  计算磁环平均长度l  cm
def calMagnetRingLength(D, d):
    return (0.5 * (D + d) * math.pi)

#  计算磁环绕线电感的电感L  mH
def calInductance(u, N, F, l):
    return 0

#  计算线圈匝数N
def calRingNumber(u, L, F, l):
    return math.sqrt((L * l * math.pow(10,5))/(0.4 * math.pi * u * F))
    
u = 75    
D = 3.3
d = 1.99
h = 1.07
L = 50.0
F = calMagnetRingCrossArea(D,d,h)
l = calMagnetRingLength(D,d)
N = calRingNumber(u,L,F,l)
print(N)

aa

st3=>start: start foo
io5=>inputoutput: input: a, b
cond9=>condition: if a
sub13=>subroutine: print('a')
io34=>inputoutput: output: (a + b)
e32=>end: end function return
cond18=>operation: print('b') while i in range(3)

st3->io5
io5->cond9
cond9(yes)->sub13
sub13->io34
io34->e32
cond9(no)->cond18
cond18->io34

TODO Items

It would be very handy indeed if there was a simple CLI for code->svg.

Flowchart.js is javascript (obviously), so how would you feel if I made a pull request that installed npm, and the npm 'diagrams' package? From there, it's really just a simple CLI interface once those 2 things are installed.

for loop rendered as an operation not a loop

One of the things I noticed in your demo is that a for loop is rendered as a while in an operation block whereas a while is rendered (more usefully) in looped decision. Is there any way of rendering the for loop as a looped decision without manually converting the code to explicitly use a while?

Support for match-case statement: AttributeError: 'Unparser' object has no attribute '_Match'

As pyflowchart 0.3.1 used with python 3.11 and astunparse 1.6.3 throws an exception:
Traceback (most recent call last): File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/__main__.py", line 115, in <module> main(args.code_file, args.field, args.inner, args.output, args.no_simplify, args.conds_align) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/__main__.py", line 85, in main flowchart = Flowchart.from_code(code, File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/flowchart.py", line 102, in from_code p = parse(f, simplify=simplify, conds_align=conds_align) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 659, in parse node = ast_node_class(ast_object, **kwargs) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 137, in __init__ self.body_head, self.body_tails = self.parse_func_body(**kwargs) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 158, in parse_func_body p = parse(self.ast_object.body, **kwargs) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 659, in parse node = ast_node_class(ast_object, **kwargs) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 463, in __init__ OperationNode.__init__(self, operation=self.ast_to_source()) File "/home/bjorn/.local/lib/python3.10/site-packages/pyflowchart/ast_node.py", line 33, in ast_to_source return astunparse.unparse(self.ast_object).strip() File "/home/bjorn/.local/lib/python3.10/site-packages/astunparse/__init__.py", line 13, in unparse Unparser(tree, file=v) File "/home/bjorn/.local/lib/python3.10/site-packages/astunparse/unparser.py", line 38, in __init__ self.dispatch(tree) File "/home/bjorn/.local/lib/python3.10/site-packages/astunparse/unparser.py", line 65, in dispatch meth = getattr(self, "_"+tree.__class__.__name__) AttributeError: 'Unparser' object has no attribute '_Match'

I looked into a solution. It now seems that replacing astunparse with the inbuild package ast package (see e.g. simonpercivall/astunparse#56 (comment)) doesnt throw this and works atm.

Please add `scroll to zoom` functionality if possible.

for smaller code it is OK to view the flowchart in a small image but for large python file we need to have some library like bokeh to plot the graph so that the content is scroll to zoom and all the nodes are dragable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.