Skip to content

Implement FlowchartGenerator for Python-to-flowchart conversion#18

Draft
tmaier-kettering with Copilot wants to merge 5 commits into
flowchart-by-block2from
copilot/create-flowchart-generator-scripts
Draft

Implement FlowchartGenerator for Python-to-flowchart conversion#18
tmaier-kettering with Copilot wants to merge 5 commits into
flowchart-by-block2from
copilot/create-flowchart-generator-scripts

Conversation

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown

Implements the missing FlowchartGenerator class to convert Python code from the code editor into flowchart blocks and connections for the visualization panel, following placement rules in FlowSight_Rules.md.

Implementation

  • src/flowsight/engine/flowchart.py (342 lines)
    • Parses Python code, filters executable lines (strips comments, imports, blank lines)
    • Places blocks in depth-first, lexical order per specification
    • Generates connections with proper port assignments (N/S/E/W)
    • Converts grid coordinates to pixel coordinates with configurable layout parameters

Placement Algorithm

Strict rule compliance:

  • Each executable line → exactly one block
  • Start at grid (0,0), first code at (1,0), End positioned below all code
  • Sequential blocks: +1 row, same column
  • If/elif/else chains: True body directly below, False branches +1 column right
  • For/while loops: body at (+1 row, +1 col), back edge from last body to header south port

Port usage matches specification:

  • Process blocks: N (in), S (out), W (back-out)
  • If/elif headers: N (in), S (True), E (False)
  • Loop headers: N (in), E (True), S (back-in), W (False/exit)

Example Usage

gen = FlowchartGenerator(margin_left=50, margin_top=50, col_width=150, row_height=80)
blocks, connections = gen.generate(code)
# Returns block dicts with {line_num, text, type, row, col, x, y, width, height}
# and connection dicts with {from, to, from_port, to_port, label}

Testing & Documentation

  • test_flowchart.py: 8 test cases covering sequential, conditionals, loops, nested structures, edge cases
  • docs/FlowchartGenerator_Implementation.md: Technical details, algorithms, data structures
  • docs/FlowchartGenerator_QuickStart.md: Usage reference and examples

All example files (fibonacci, conditionals, loops) generate correct flowcharts. Integration with ExecutionEngine already in place via existing import.

Original prompt

Using the FlowSight_Rules.md and associated files in the Rules for Reference folder, create the FlowchartGenerator and associated scripts that the software needs to convert the code from the code_editor to the visualization panel.

Take extra note of these absolute rules:

  • Each line of code is always converted to exactly one block on the diagram (omitting comments, blank lines, and imports and stripping in-line comments)
  • Blocks are placed one at a time in the order they appear in the code editor
  • Block placement is completely determined by direct target. A block may place only blocks it is directly connected to.
  • Because blocks are placed in the order they appear in the code editor, naturally, a header block will first place its child, wait until that child has placed its child, and so on, before then finally afterwards, placing its sequential successor

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 4, 2025 18:03
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Copilot AI changed the title [WIP] Add FlowchartGenerator for code visualization Implement FlowchartGenerator for Python-to-flowchart conversion Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants