/tefcha

Text to Flowchart

Primary LanguageTypeScriptMIT LicenseMIT

Tefcha

Text to Flowchart.

./img/sample.gif

Demo

Rich Editor

Simple Editor

Feature

  • Convert pseudo code to flowchart image.

Installation

CDN

<script src="https://unpkg.com/tefcha/umd/tefcha.js"></script>

npm

npm install tefcha

CLI Tool

You can use command line interface also. https://github.com/hrhr49/tefcha-cli

npm install tefcha-cli

Supported

Only these features are supported for now

  • if, elif, else statements
  • switch-case statement
  • while, do-while statements
  • break, continue statement
  • try-except statement

Not Supported (for now)

  • for statement
  • return statement

Reserved Word

  • if, elif, else, while, do, for, continue, break, switch, case, pass, try, except

Usage

  1. Add <div class="tefca"> tag in HTML file.
  2. Write psedo code in <div class="tefca"> tag.
  3. Load umd/tefcha.js by script tag.
  4. Call tefcha.initialize(), then, svg element will be generated.

Simple Example.

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
</head>

<body>
  <div class="tefcha">
# This is a example.
# NOTE:
#   The line starts with "#" is comment.
#   "\n" is newline.
#   All indent must be "  " (2 white spaces).

Start\nFizzBuzz!
i = 1

while i <= 100
  if i % 15 == 0
    print("FizzBuzz")
  elif i % 3 == 0
    print("Fizz")
  elif i % 5 == 0
    print("Buzz")
  else
    print(i)
  i = i + 1
End
  </div>
  <script src="https://unpkg.com/tefcha/umd/tefcha.js"></script>
  <script>
    tefcha.initialize();
  </script>
</body>

</html>

Simple Example Result

simple-example

Configuration

You can pass a custom configuration to tefcha.initialize().

See

Configuration Example

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
</head>

<body>
  <div class="tefcha">
# This is a example.
# NOTE:
#   The line starts with "#" is comment.
#   "\n" is newline.
#   All indent must be "  " (2 white spaces).

Start\nFizzBuzz!
i = 1

while i <= 100
  if i % 15 == 0
    print("FizzBuzz")
  elif i % 3 == 0
    print("Fizz")
  elif i % 5 == 0
    print("Buzz")
  else
    print(i)
  i = i + 1
End
  </div>
  <script src="https://unpkg.com/tefcha/umd/tefcha.js"></script>
  <script>
    var blueConfig = {
      text: {
        attrs: {
          'font-size': '14px',
          'stroke': 'white',
          'fill': 'white',
          'fill-opacity': '100%',
          'stroke-width': '0px',
        },
      },
      label: {
        attrs: {
          'font-size': '10px',
          'stroke': 'royalblue',
          'fill': 'royalblue',
          'fill-opacity': '100%',
        },
      },
      path: {
        attrs: {
          'stroke': 'dimgray',
          'stroke-width': '2px',
          'fill-opacity': '0%',
        },
      },
      rect: {
        attrs: {
          'stroke': 'steelblue',
          'stroke-width': '2px',
          'fill': 'steelblue',
          'fill-opacity': '100%',
          'rx': '3px',
          'ry': '3px',
        },
      },
      diamond: {
        attrs: {
          'stroke': 'royalblue',
          'stroke-width': '2px',
          'fill': 'royalblue',
          'fill-opacity': '100%',
        },
      },
      arrowHead: {
        attrs: {
          'stroke': 'dimgray',
          'stroke-width': '2px',
          'fill': 'dimgray',
          'fill-opacity': '100%',
        },
      },
    };
    tefcha.initialize(blueConfig);
  </script>
</body>

</html>

Configuration Example Result

blue-theme.png

Syntax

Statement

If text is not started with reserved word, it means simple statement. It is rendered as a box with the text.

hello

simple.png

Newline

You can use \n for newline.

hello\nworld

newline.png

If Statement

  • text starts with if means if statement.
  • indented line means block.
if score > 80
  good!

end

if.png

If-elif Statement

You can use elif and else also.

if score > 80
  good!
elif score > 30
  soso
else
  bad!

end

if-elif-else.png

Switch-Case Statement

You can use switch-case statement by switch block and case block.

NOTE: Unlike switch-case in C language, you cannot use "break" at the end of case block.

switch fruit
  case apple
    red
  case banana
    yellow
  case grape
    purple
end

switch-case.png

While Statement

  • text starts with while means while statement.
while score < 30
  study again

end

while.png

Do While Statement

  • text starts with do means do-while statement.
  • after do block, line starts with while is needed.
do
  get input from user
while input is invalid

end

do-while.png

Break

You can break loop by break keyword.

i = 0

while i < n
  if fruits[i] == 'apple'
    break
  i = i + 1
end

break.png

Continue

You can use continue keyword also.

i = 0

while i < n
  if user[i] is null
    continue
  register user[i]
  i = i + 1

end

continue.png

Try-Except

You can use try, except keyword also. It's syntax is similar to Python (a kind of programming language).

try
  calculate()
except ValueError
  invalid value
except ZeroDivisionError
  value must be != 0
end

try-except.png

Author

hrhr49

hiro49410@gmail.com

License

MIT

Links