Pikchr

Flow Chart Alignment with Shape Macros
Login

Flow Chart Alignment with Shape Macros

(1.1) Originally by anonymous with edits by drh on 2024-03-16 21:02:49 from 1.0 [link] [source]

Hello. My goal in this flow chart is to have the triangle and the parallelogram macros aligned with the rest of the flow chart, as well as the display text to be centered in the parallelogram macro.

Start/End Execute Condition ??? Yes ???
      define diamondx { \
        box wid 80% invis
        line from last.w to last.n to last.e to last.s close rad 0 $1
      }
   define parallelogram { \
	      line up 1cm right 0.5cm
	      line right 2.5cm
	      line down 1cm left 0.5cm
              line left 2.5cm
	  }
   define par { \
		box wid 100% invis
		line from last.sw to last.se 
		line up 1cm right 0.5cm from last.se to last.ne
		line from last.ne left 2cm
		line down 1cm left 0.4cm
	  }
   define triangle { \
	    box wid 0% invis
		line go 1.5cm heading 150 then 1.5cm west close rad 0 $1
	  }

oval "Start/End" width 100% height 50%
right
arrow 50%
box "Execute" fit width 75%
right
arrow 50%
DIAM: diamondx("Condition")
right
arrow 50% "???" above
triangle("Yes") 
right
arrow 50% "???" above
parallelogram("No")

(2.1) By Warren Young (wyoung) on 2024-03-16 21:50:48 edited from 2.0 in reply to 1.1 [source]

A solution for your triangle does not spring immediately to mind, but I do have a solution for your parallelogram:

Start/End Execute Condition !!! No
po = 0.3cm

define par { \
  box wid 100% invis $1
  line \
    from po left of last.sw \
      to po left of last.se \
      to po right of last.ne \
      to po right of last.nw \
      close
}

oval "Start/End" width 100% height 50%
arrow 50%
box "Execute" fit width 75%
arrow 50%
diamond "Condition" fit
arrow 50% "!!!" above
par("No")

I've also switched the code to use Pikchr's new native diamond object, superior in several ways to the old manual cardinal point hack, as detailed in that link.

Alas, my parallelogram hack suffers from essentially the same set of flaws, for the same reason. Until someone gets around to giving us native parallelograms, though, it should suffice.

(EDIT: Note that you don't need all those "right" calls. The direction defaults to that to begin with. It's the "arrow" calls that move the diagram one more step to the right.)

(3.1) Originally by anonymous with edits by drh on 2024-03-16 22:44:34 from 3.0 in reply to 2.1 [link] [source]

Ah thanks, I suppose this is also why the arrow is aligned to the height of the top right corner of the parallelogram instead of the middle of the right side. I suppose this is an Adamantine Pick issue, since it also fails to render the native diamond object.

Start/End Execute Input/Output Condition
po = 0.2cm

define par { \
  box wid 100% height 50% invis $1
  line \
    from po left of last.sw \
      to po left of last.se \
      to po right of last.ne \
      to po right of last.nw \
      close
}

oval "Start/End" width 100% height 50%
arrow 50%
box "Execute" fit width 75%
arrow 50%
par("Input/Output")
arrow 50%
diamond "Condition"

(4) By Warren Young (wyoung) on 2024-03-16 23:25:28 in reply to 3.1 [link] [source]

If you know the parallelogram will always have something to the right, you can define par() thus:

Start/End Execute Input/Output Condition
skew = 0.2cm

define par { \
  B: box invis $1 fit
  line \
    from skew  left of B.se \
      to skew  left of B.sw \
      to skew right of B.nw \
      to skew right of B.ne \
      close
  line from B.e to skew/2 right of B.e
}

oval "Start/End" width 100% height 50%
arrow 50%
box "Execute" fit
arrow 50%
par("Input/Output")
arrow 50%
diamond "Condition" fit

This scheme means you might need two or more versions of par(), since as far as I can tell, there are no conditionals in Pikchr, nor a way to pull off numeric tricks like "int($2) * skew/2" to give 0 when you don't give a second parameter.

Note the renaming of "po" (parallelogram offset) to "skew", a more geometrically-accurate term for what it does.

(5) By Warren Young (wyoung) on 2024-03-18 04:47:12 in reply to 2.1 [link] [source]

A solution for your triangle does not spring immediately to mind

I've got the triangle aspect solved now, too, with essentially the same idea as in my parallelogram solution:

Start Execute Input/Output Condition Yes End
skew = 0.2cm

define par { \
  B: box invis $1 fit
  line \
    from skew  left of B.se \
      to skew  left of B.sw \
      to skew right of B.nw \
      to skew right of B.ne \
      close
  line from B.e to skew/2 right of B.e
}

define tri { [ \
  B: box $1 invis
  line from B.sw to B.n to B.se close
  arrow from B.w to 1/2 way between B.w and B.c
  line 25% from 1/2 way between B.e and B.c to B.e
] }

oval "Start" fit
arrow 50%
box "Execute" fit
arrow 50%
par("Input/Output")
arrow 50%
diamond "Condition" fit
line 25%
tri("Yes")
arrow 10%
oval "End" fit

The fitting is fiddly and will require local tweaking if you make the text much longer than in this example.