summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/charts/charts-mkiv.tex
blob: 2081b872b1e3b57fdf6a85ca520e87d12ada8073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\usemodule[abr-02]

\usemodule[setups-basics] \loadsetups[i-chart.xml]

\setupexternalfigures
  [location={local,default}]

\setuplayout
  [topspace=15mm,
   header=15mm,
   headerdistance=0mm,
   footer=0cm,
   width=middle,
   height=middle]

\setuppagenumbering
  [alternative=doublesided]

\definetypeface [mainface] [rm] [serif] [pagella] [default]
\definetypeface [mainface] [ss] [sans]  [heros]   [default] % [rscale=1.1]
\definetypeface [mainface] [tt] [mono]  [modern]  [default] % [rscale=1.1]
\definetypeface [mainface] [mm] [math]  [pagella] [default]

\setupbodyfont[mainface,12pt]

% \definecolor[maincolor][r=.4,g=.2,b=.6]
\definecolor[maincolor][r=.2,g=.1,b=.3]

\setupwhitespace
  [big]

\setuptolerance
  [verytolerant,stretch]

\setuptype
  [color=maincolor]

\setuptyping
  [color=maincolor]

\setuphead
  [section]
  [style=\bfb,
   color=maincolor]

\setupinteraction
  [state=start,
   color=,
   contrastcolor=,
   style=]

\startsetups titlepage
    \startpagemakeup[doublesided=no,page=no]
        \useMPgraphic{titlepage}
    \stoppagemakeup
    \startstandardmakeup[doublesided=no,page=no]
        \vfill
        \startsubject[title=Contents]
            \startcolumns[distance=4em]
                \placelist[section][alternative=c,width=2em]
            \stopcolumns
        \stopsubject
    \stopstandardmakeup
\stopsetups

\startsetups colofon
    \blank[2*big]
    \testpage[3]
    \startpacked
        \documentvariable{author}\par
        \documentvariable{affiliation}\par
        \documentvariable{location}\par
    \stoppacked
\stopsetups

\setupdocument
  [title=No Title,
   before=\setups{titlepage},
   after=\setups{colofon}]

% specific for this document

\usemodule[chart]

\setupFLOWcharts
  [width=2.25cm,
   height=1.25cm,
   dx=.25cm,
   dy=.25cm]

\startuseMPgraphic{titlepage}
    numeric width, height, delta ;
    color a, b, c, d ;

    width    := PaperWidth ;
    height   := PaperHeight ;
    delta    := width/10 ;
    ahlength := 6delta ;

    a := white/2 ;
    b := white/3 ;
    c := resolvedcolor ("maincolor") ;
    d := c ;

    path p ; p := unitsquare xscaled width yscaled height ;

    fill p withcolor c ;

    drawarrow llcorner p -- urcorner p withpen pencircle scaled (3.0delta) withcolor a ;
    draw      llcorner p -- urcorner p withpen pencircle scaled (4.0delta) withcolor a ;
    drawarrow urcorner p -- llcorner p withpen pencircle scaled (2.5delta) withcolor b ;
    draw      llcorner p -- urcorner p withpen pencircle scaled (3.0delta) withcolor b ;
    drawarrow llcorner p -- urcorner p withpen pencircle scaled (2.0delta) withcolor d ;
    drawarrow urcorner p -- llcorner p withpen pencircle scaled (1.5delta) withcolor d ;

    draw anchored.lrt(
        textext("\ss\bf \documentvariable{title}") rotated 90 xsized (3delta/4),
        lrcorner p shifted (-delta,3delta/4)
    ) withcolor white ;

    resetarrows ;

    setbounds currentpicture to p ;
\stopuseMPgraphic

\startdocument
  [title=Flowcharts,
   author= Hans Hagen,
   affiliation=PRAGMA ADE,
   location=Hasselt NL]

\startsection[reference=introduction,title={Introduction}]

This is just another story of \TEX\ meeting \METAPOST. This time we will focus on
charts, especially flowcharts. In \CONTEXT\ flowchart support is not part of the
core functionality, but is provided as a module. Therefore, before you can
actually define a chart, this module must be loaded:

\starttyping
\usemodule[chart]
\stoptyping

Once loaded, you has access to the functionality described here. Before we go
into detail on the features, we will say some words on history.

When dealing with graphics, it makes sense to use a drawing program. In fact,
before we started using this module, we did use such programs, and they have
without doubt their advantages. As soon as \CONTEXT\ supported interactive
documents, there were means to make graphics interactive, and as long as only a
few graphics are involved, this mechanism works ok.

And then we suddenly had to make a document with thousands of pages and hundreds
of often rather complicated flowcharts. Because these charts were tightly
integrated in the main document, they not only had to be consistent in the use of
fonts, but also had to be interactive and were to be presented both as a whole
and in subchart parts. We wanted fonts, colors and the overall appearance as well
as names of people, places, steps, activities and more to be consistent,
especially because these charts are constantly updated.

I use the term flowchart here because I want to stress that this module typesets
charts which cells are connected by lines (often arrows). Our first application
of this module concerned diagrams that expressed actions and relations between
those actions, using some techniques originating years ago in programming
environments: lines were not to cross, one should read from top to bottom and
left to right, etc. However, the module presented here can be used to draw all
kind of charts, and all kind of connections. But there are limits.

{\em This manual is mostly the one written of end 1998 when the flowchart module
showed up in the distribution. In the meantime the code has been rewritten for
\MKIV\ and some functionality is adapted. But the interface hasn't changed much.}

\stopsection

\startsection[title={The grid}]

A flowchart consists of shapes, positioned on a grid, connected by lines. The
grid enables the user to anchor the shapes and enables the drawing routines to
determine connections. One can either explicitly specify the grid, or let it be
calculated automatically.

\startbuffer[grid]
\setupFLOWcharts
  [option=test,
   nx=4,
   ny=3,
   dx=\bodyfontsize,
   dy=\bodyfontsize,
   width=6\bodyfontsize,
   height=4\bodyfontsize,
   maxwidth=\textwidth]

\startFLOWchart [grid]
\stopFLOWchart
\stopbuffer

\placefigure
  [here][fig:grid]
  {The grid.}
  {\getbuffer[grid]\FLOWchart[grid]}

Normally the grid is not visible, unless one enters test mode. The grid in \in
{figure} [fig:grid] is the result of the definition:

\typebuffer[grid]

The most straightforward way of calling up this chart is by saying:

\starttyping
\FLOWchart[grid]
\stoptyping

In \in {figure} [fig:grid] we see a grid an dwithin each cell a shape. Normally
shapes are smaller than grid cells. This is necessary because connecting lines
need some room. The offset is important, because when a connection follows the
outer lines, a little extra space outside that line not only looks better, but
also prevents the line from being clipped. It makes sense to keep the offset as
well as the space between shapes constant across a document. The numbers are
typeset outside the bounding box of the figure.

Grid cells are numbered from top to bottom starting at the left side, so the left
topmost cell is $(1,1)$. Later we will see that because cells have names, these
numbers play a minor role.

\stopsection

\startsection[title={Shapes}]

A shape is something, typically a text, within a frame. The frame has certain
dimensions and can have some color and background. In this respect it looks like
the \CONTEXT\ command \type {\framed}. The most important shapes have been
assigned names as indicated in \in {figure} [fig:shapes]. There are more shapes,
but they are identified by a number only. The total number of shapes will quite
certainly increase. The shapes {\em up}, {\em down}, {\em left} and {\em right}
are not really shapes, but lines that can be used to force a direction.

\startFLOWchart [shapes]
\startFLOWcell \name{a} \location{1,1} \shape{node}           \text{node}           \stopFLOWcell
\startFLOWcell \name{b} \location{2,1} \shape{action}         \text{action}         \stopFLOWcell
\startFLOWcell \name{c} \location{3,1} \shape{procedure}      \text{procedure}      \stopFLOWcell
\startFLOWcell \name{d} \location{4,1} \shape{product}        \text{product}        \stopFLOWcell
\startFLOWcell \name{e} \location{1,2} \shape{decision}       \text{decision}       \stopFLOWcell
\startFLOWcell \name{f} \location{2,2} \shape{archive}        \text{archive}        \stopFLOWcell
\startFLOWcell \name{g} \location{3,2} \shape{loop}           \text{loop}           \stopFLOWcell
\startFLOWcell \name{h} \location{4,2} \shape{wait}           \text{wait}           \stopFLOWcell
\startFLOWcell \name{i} \location{1,3} \shape{subprocedure}   \text{sub procedure}   \stopFLOWcell
\startFLOWcell \name{j} \location{2,3} \shape{singledocument} \text{single document} \stopFLOWcell
\startFLOWcell \name{k} \location{3,3} \shape{multidocument}  \text{multi document}  \stopFLOWcell

\startFLOWcell \name{l} \location{1,4} \shape{right}          \text{right}          \stopFLOWcell
\startFLOWcell \name{m} \location{2,4} \shape{left}           \text{left}           \stopFLOWcell
\startFLOWcell \name{n} \location{3,4} \shape{up}             \text{up}             \stopFLOWcell
\startFLOWcell \name{o} \location{4,4} \shape{down}           \text{down}           \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:shapes]
  {The shapes.}
  {\tx\FLOWchart[shapes]}

When no shape is specified, the default shape is used. One can change this
default value with the \type {\setupFLOWshapes} command.

\startbuffer[cells]
\startFLOWchart [cells]
  \startFLOWcell
    \name     {first}
    \location {1,1}
    \shape    {singledocument}
    \text     {not realy a document}
  \stopFLOWcell
\stopFLOWchart
\stopbuffer

\typebuffer[cells]

\getbuffer[cells]

A flow chart consists of cells. Each cell has a name, is positioned somewhere on
the grid, has a certain shape, and normally this shape surrounds text. The shape
is drawn by \METAPOST, and the text is placed by \TEX. Later we will see that
there are some more fields to fill. Names are local to a chart.

\placefigure
  [][fig:cells]
  {}{\tx\FLOWchart[cells]}

\stopsection

\startsection[title={Connections}]

Shapes can be connected. As shown in \in {figure} [fig:points] each shape has
four connection points: top, bottom, left and right. When connecting shapes we
refer to their logical names and specify two of the four directions.

\startFLOWchart [points]
\startFLOWcell \name{a} \location{1,1} \shape{procedure}     \stopFLOWcell
\startFLOWcell \name{b} \location{2,1} \shape{product}       \stopFLOWcell
\startFLOWcell \name{c} \location{3,1} \shape{archive}       \stopFLOWcell
\startFLOWcell \name{d} \location{4,1} \shape{multidocument} \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:points]
  {The connection points.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[points]}

In \in {figure} [fig:connect] we see three connections. The lines have smooth
curves and run across the grid lines. By using smooth curves, an option that can
be turned off, the direction of touching curves is always clear. Here we use
arrows. Smoothing, arrows and dashed lines are some of the attributes of lines.

\startFLOWchart [connect]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {procedure}
    \text       {first}
    \connection [rl] {beta}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,1}
    \shape      {product}
    \text       {second}
    \connection [bl] {alpha}
    \connection [rl] {gamma}
  \stopFLOWcell
  \startFLOWcell
    \name     {gamma}
    \location {3,1}
    \shape    {action}
    \text     {third}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:connect]
  {A few connections.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[connect]}

\startFLOWchart [two]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {action}
    \text       {first}
    \connection [rl] {beta}
    \connection [rl] {alpha}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,1}
    \shape      {loop}
    \text       {second}
    \connection [tr] {beta}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  {A few more connections.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[two]}

There can be more than one connection per shape. When defining such a connection
we first specify the direction. In this example \type {[rl]} means connect the
right point to the left one, while \type {[tr]} results in a connection between
the top and the right point. The second argument specifies the shape to connect
to. As we can see, connections can point back to their origin shape.

\startFLOWchart [around]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {procedure}
    \text       {first}
    \connection [rl] {gamma}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,1}
    \shape      {product}
    \text       {second}
  \stopFLOWcell
  \startFLOWcell
    \name       {gamma}
    \location   {3,1}
    \shape      {action}
    \text       {third}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:around]
  {Going around shapes.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[around]}

\startFLOWchart [straight]
  \startFLOWcell
    \name       {alpha}
    \location   {2,1}
    \shape      {procedure}
    \text       {first}
    \connection [lt] {gamma}
    \connection [rt] {delta}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {3,1}
    \shape      {product}
    \text       {second}
    \connection [tl] {gamma}
  \stopFLOWcell
  \startFLOWcell
    \name       {gamma}
    \location   {1,2}
    \shape      {action}
    \text       {third}
    \connection [rr] {delta}
  \stopFLOWcell
  \startFLOWcell
    \name       {delta}
    \location   {3,2}
    \shape      {archive}
    \text       {fourth}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:straight]
  {Following grid lines.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[straight]}

The connection drawing routines have a rather strong urge to follow grid lines.
\in {Figure} [fig:straight] demonstrates this several times. From the first shape
to the third one, we see that the connection takes the shortest route possible
without crossing other shapes. I have to admit that the routines in themselves
are rather stupid, but for normal use they suffice.

\startFLOWchart [straightagain]
  \startFLOWcell
    \name       {alpha}
    \location   {2,1}
    \shape      {procedure}
    \text       {first}
    \connection [lt] {gamma}
    \connection [rt] {delta}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {3,1}
    \shape      {product}
    \text       {second}
    \connection [tl] {gamma}
    \connection [tt] {alpha}
    \connection [bt] {delta}
  \stopFLOWcell
  \startFLOWcell
    \name       {gamma}
    \location   {1,2}
    \shape      {action}
    \text       {third}
    \connection [rr] {delta}
  \stopFLOWcell
  \startFLOWcell
    \name       {delta}
    \location   {3,2}
    \shape      {archive}
    \text       {fourth}
    \connection [bb] {gamma}
  \stopFLOWcell
\stopFLOWchart

Generally speaking, when two lines end at the same point, it makes sense to
connect these. When on the other hand lines originate at the same point or cross
eachother, readers can get confused. Therefore such lines are drawn in such a way
that they don't touch. In this respect, \in {figure} [fig:white] demonstrates a
less than optimal chart.

\placefigure
  [here][fig:white]
  {Confusing (crossing) grid lines.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[straightagain]}

\stopsection

\startsection[title={Adding text}]

In \in {figure} [fig:comment] we have added some comment to a connection. Like
the dots at the connections, the point halfway the connection shows up in a
special debugging mode. The comment will be placed relative to this point. In \in
{figure} [fig:comment] this is to the left of the point.

\startFLOWchart [comment]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {action}
    \text       {here}
    \connection [bl] {beta}
    \comment    [l] {from here to there}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,2}
    \shape      {action}
    \text       {there}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:comment]
  {Comment to connections.}
  {\tx\setupFLOWcharts[dot=mid]\FLOWchart[comment]}

It will be no surprise that a comment is defined using \type {\comment}. Comments
can be anchored to eight locations, simply \type {l}, \type {r}, \type {t}, \type
{b}, or a combination like \type {tr}.

\starttyping
\startFLOWcell
  ...
  \comment [l] {from here to there}
  ...
\stopFLOWcell
\stoptyping

\startFLOWchart [labels]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {action}
    \text       {here}
    \connection [bl] {beta}
    \label      [b] {from here}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,2}
    \shape      {action}
    \text       {there}
    \label      [l] {to there}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:labels]
  {Labels to connection points.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[labels]}

We can also put labels at the connection points. Often this is preferred over
comment halfway along a connection. Like comments, labels have a dedicated
command. Here we specify the connection point \type {l}, \type {r}, \type {t} or
\type {b}.

\starttyping
\startFLOWcell
  ...
  \label [l] {to there}
  ...
\stopFLOWcell
\stoptyping

\startFLOWchart [text]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {action}
    \text       {here}
    \connection [bl] {beta}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,2}
    \shape      {action}
    \text       {there}
  \stopFLOWcell
  \startFLOWcell
    \shape      {none}
    \location   {2,1}
    \text       {Is there any reason to go
                 from here to there?}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:text]
  {Text without shapes.}
  {\tx\setupFLOWcharts[dot=con]\FLOWchart[text]}

In \in {figure} [fig:text] we see some text without any shapes around it. When
shape \type {none} is specified, the whole shape area is available for text.

\starttyping
\startFLOWcell
  \shape    {none}
  \location {2,1}
  \text     {Is there any reason to go
             from here to there?}
\stopFLOWcell
\stoptyping

One can force the alignment with the key characters \type {l}, \type {r}, \type
{c}, \type {t} and \type {b}. So, the next definition only places text.

\stopsection

\startsection[title={Inheritance}]

When explaining something by using a chart, we often show successive versions of
the chart, where each version adds a new feature. To prevent us from retyping the
same components again and again, it helps to partition the source code of the
complete chart into subcharts. Inclusion of a part is straightforward: the
subchart is called by name and positioned on the grid.

\startbuffer[include]
\startFLOWchart [include]

  \includeFLOWchart[labels][x=1,y=1]

  \startFLOWcell
    \shape    {none}
    \location {2,1}
    \text     {There is no reason to go
               from here to there!}
  \stopFLOWcell

\stopFLOWchart
\stopbuffer

\typebuffer[include]

The included sub chart has its own reference point, so one does not have to
bother about positions.

\getbuffer[include]

\placefigure
  [here][fig:include]
  {Sharing components.}
  {\tx\FLOWchart[include]}

\stopsection

\startsection[title={How it works}]

The charting module, loaded by \type {\usemodule[chart]} is only responsible for
the \TEX\ part of the job, which means positioning text and graphics generated by
\METAPOST. The grid, shape and connection drawing routines are grouped together
in a dedicated \METAPOST\ module.

Because of the mix of \TEX\ and \METAPOST, and because we want to be able to
scale charts, the buffer mechanism is used. The communication between \TEX\ and
\METAPOST\ uses the \METAPOST\ embedding macros that are native to \CONTEXT.
Additional communication from \METAPOST\ to \CONTEXT\ is handled in the module
itself. This rather fuzzy description is visualized in \in {figure}
[fig:process]. Depending on the general color settings, among the other processes
involved are: color conversion and|/|or reduction to grayscales, and conversion
to \PDF. When watching this module in action, don't feel disturbed by the many
steps involved.

\startFLOWchart [process]
  \startFLOWcell
    \name       {user file}
    \location   {1,2}
    \shape      {action}
    \text       {User File}
    \connection [rl] {context}
  \stopFLOWcell
  \startFLOWcell
    \name       {context}
    \location   {2,2}
    \shape      {action}
    \text       {\CONTEXT}
    \connection [nrnl] {buffer}
    \connection [prl] {metapost}
  \stopFLOWcell
  \startFLOWcell
    \name       {buffer}
    \location   {3,2}
    \shape      {action}
    \text       {scalable buffer}
    \connection [nlnr] {context}
  \stopFLOWcell
  \startFLOWcell
    \name       {metapost}
    \location   {4,2}
    \shape      {action}
    \text       {\METAPOST}
    \connection [rr] {graphic}
    \connection [rr] {datafile}
  \stopFLOWcell
  \startFLOWcell
    \name       {graphic}
    \location   {4,1}
    \shape      {action}
    \text       {\POSTSCRIPT}
    \connection [lt] {context}
  \stopFLOWcell
  \startFLOWcell
    \name       {datafile}
    \location   {4,3}
    \shape      {action}
    \text       {Data File}
    \connection [lb] {context}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:process]
  {The process.}
  {\tx\FLOWchart[process]}

\startbuffer[collection]
\startFLOWchart [collection]
  \dorecurse{10}
    {\dorecurse{8}
       {\scratchcounter=\numexpr\numexpr##1-1\relax*10+#1\relax
        \startFLOWcell
           \name     {#1-##1}
           \location {#1,##1}
           \shape    {\the\scratchcounter}
           \normalexpanded{\label[bc]{\hbox{\tt\the\scratchcounter}}}
        \stopFLOWcell}}
\stopFLOWchart

\setupFLOWcharts
  [width=.08\textwidth,
   height=.06\textwidth,
   dx=.01\textwidth,
   dy=.02\textwidth,
   linewidth=1pt,
   dot=yes]

\FLOWchart[collection]
\stopbuffer

A few pages back we introduced the named shapes. There are however some more
shapes. Each shape is identified by a number. In \in {figure} [fig:collection]
all currently available shapes are shown. The zero numbered shape is actually a
shape, but with zero dimensions. It can be used as a meeting point for lines. The
unused numbers can be used for new shapes. The maximum number of shapes is
limited to 4095, which is a \METAPOST\ limitation.

\placefigure
  [here][fig:collection]
  {All shapes by number. Shape 0 is valid and has zero dimensions.}
  {\tx\getbuffer[collection]}

\stopsection

\startsection[title={Bonus points}]

Sometimes charts can become rather large, due to the many shapes used or lines
drawn. At the same time charts can become unclear because more than one
connection starts or ends at a shape. \in {Figure} [fig:bonus 1] shows a way out
of this situation.

\startFLOWchart [bonus 1]
  \startFLOWcell
    \name       {tex}
    \location   {1,1}
    \shape      {action}
    \text       {\TEX}
    \connection [prpl] {pdf}
    \connection [nrnl] {dvi}
  \stopFLOWcell
  \startFLOWcell
    \name       {dvi}
    \location   {2,1}
    \shape      {action}
    \text       {\DVI}
    \connection [prpl] {ps}
    \connection [nrr]  {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {ps}
    \location   {3,1}
    \shape      {action}
    \text       {\POSTSCRIPT}
    \connection [rnl] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {pdf}
    \location   {4,1}
    \shape      {action}
    \text       {\PDF}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:bonus 1]
  {Even more points.}
  {\tx\setupFLOWcharts[dot=all]\FLOWchart[bonus 1]}

\startFLOWchart [bonus 2]
  \startFLOWcell
    \name       {tex}
    \location   {1,1}
    \shape      {action}
    \text       {\TEX}
    \connection [bt] {pdf}
    \connection [rl] {dvi}
  \stopFLOWcell
  \startFLOWcell
    \name       {dvi}
    \location   {2,1}
    \shape      {action}
    \text       {\DVI}
    \connection [rl] {ps}
    \connection [br] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {ps}
    \location   {3,1}
    \shape      {action}
    \text       {\POSTSCRIPT}
    \connection [br] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {pdf}
    \location   {1,2}
    \shape      {action}
    \text       {\PDF}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:bonus 2]
  {An alternative for \in {figure}[fig:bonus 1].}
  {\tx\FLOWchart[bonus 2]}

\startFLOWchart [bonus 3]
  \startFLOWcell
    \name       {tex}
    \location   {1,1}
    \shape      {action}
    \text       {\TEX}
    \connection [bb] {pdf}
    \connection [rl] {dvi}
  \stopFLOWcell
  \startFLOWcell
    \name       {dvi}
    \location   {2,1}
    \shape      {action}
    \text       {\DVI}
    \connection [rl] {ps}
    \connection [tt] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {ps}
    \location   {3,1}
    \shape      {action}
    \text       {\POSTSCRIPT}
    \connection [rl] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {pdf}
    \location   {4,1}
    \shape      {action}
    \text       {\PDF}
  \stopFLOWcell
\stopFLOWchart

\placefigure
  [here][fig:bonus 3]
  {Yet another alternative for \in {figure}[fig:bonus 1].}
  {\tx\FLOWchart[bonus 3]}

Defining such a chart is not so much harder than previous cases. Each left,
right, top and bottom point has two companion points: positive and negative. In
connections the left points are: \type {pl}, \type {l} and \type {nl}: positive
left, left and negative left, so the first cell in \in {figure} [fig:bonus 1] is
defined as:

\starttyping
\startFLOWcell
  \name       {tex}
  \location   {1,1}
  \shape      {action}
  \text       {\TEX}
  \connection [prpl] {pdf}
  \connection [nrnl] {dvi}
\stopFLOWcell
\stoptyping

Alternatively to \type {p} and \type {n} one may use \type {+} and \type {-}. As
soon as the positive and negative points are used, the connection drawing
routines will take into account the fact that they are off||center. This does not
free users from thinking about better ways to draw such a chart.

\stopsection

\startsection[title={Clip and focus}]

The flowcharter automatically calculates the size of the grid. When needed, one
can force the dimensions and/or clip pieces of a chart. \in {Figure}
[fig:clipped] shows such a clip. This example also shows why the offset, the
small area around the outer grid lines, is important. \in {Figure} [fig:clipped]
was produced while the next settings were in action.

\startbuffer[clip]
\setupFLOWcharts
  [x=1,y=1,nx=2,ny=1]
\stopbuffer

\typebuffer[clip]

\placefigure
  [here][fig:clipped]
  {Clipping a piece of a chart.}
  {\tx\getbuffer[clip]\FLOWchart[connect]}

Sometimes, for instance when explaining a chart, it makes sense to emphasize one
or more particular cells. Therefore this module offers the ability to focus on
cells. In \in {figure} [fig:focus] we see that the focus is on the cell with name
\type {dvi}. This is accomplished by saying:

\startbuffer
\setupFLOWfocus
  [framecolor=pragmacolor]
\setupFLOWcharts
  [focus=dvi]
\stopbuffer

\typebuffer

\placefigure
  [here][fig:focus]
  {Gaining some focus.}
  {\tx\getbuffer\FLOWchart[bonus 3]}

Clipping and focus bring us to the third way of zooming in: autofocus. \in
{Figure} [fig:autofocus] shows what happens when we say:

\startbuffer
\setupFLOWfocus
  [framecolor=pragmacolor]
\setupFLOWcharts
  [focus=dvi,autofocus=dvi,
   nx=1,ny=1]

\startFLOWchart [bonus 3]
  \startFLOWcell
    \name       {tex}
    \location   {1,1}
    \shape      {action}
    \text       {\TEX}
    \connection [rl] {pdf}
  \stopFLOWcell
  \startFLOWcell
    \name       {pdf}
    \location   {4,1}
    \shape      {action}
    \text       {\PDF}
  \stopFLOWcell
\stopFLOWchart
\stopbuffer

\typebuffer

\placefigure
  [here][fig:autofocus]
  {Applying autofocus.}
  {\tx\getbuffer\FLOWchart[bonus 3]}

In \in {figure}[fig:autofocus] we see both focus and auto focus in action.

\stopsection

\startsection[title={Line types}]

As is to be expected, we can set up some characteristics of a chart, the shapes,
the connecting lines, and the focus. When we want dashed lines and a different
shape color, we just say:

\startbuffer
\setupFLOWshapes
  [framecolor=pragmacolor]
\setupFLOWlines
  [framecolor=pragmacolor,
   dash=yes]
\stopbuffer

\typebuffer

\placefigure
  [here][fig:lines]
  {Dashed and colored lines.}
  {\tx\getbuffer\FLOWchart[bonus 3]}

We can change the characteristics at several levels: chart, line, shape and|/|or
focus. In the near future some more options will be added. Once the \METAPOST\
module is stable and documented, the graphic code will also be accessible. The
formal definition of the four setup commands is as follows (these diagrams
conform the \CONTEXT\ conventions):

\setup{setupFLOWcharts}

\setup{setupFLOWfocus}

\setup{setupFLOWlines}

\setup{setupFLOWshapes}

\stopsection

\startsection[title={Overlays}]

Why should we limit ourselves to text? In \CONTEXT\ most frames||related features
can have overlays. Because in this flowchart module shapes are drawn by
\METAPOST, we use a slightly different approach: there can be overlays but they
are sort of clipped by the shape. \in {Figure} [fig:overlay] illustrates this.

\startbuffer
\defineoverlay
  [coward]
  [{\externalfigure
      [cow]
      [width=\overlaywidth,
       height=\overlayheight]}]

\startFLOWchart [overlay]
  \startFLOWcell
    \name       {alpha}
    \location   {1,1}
    \shape      {procedure}
    \connection [rl] {beta}
    \figure     {cow}
    \text       [lt] {\darkred \bfb COW 1}
  \stopFLOWcell
  \startFLOWcell
    \name       {beta}
    \location   {2,1}
    \shape      {product}
    \connection [rl] {gamma}
    \overlay    {cow}
    \text       {\darkgreen \bfb COW 2}
  \stopFLOWcell
  \startFLOWcell
    \name       {gamma}
    \location   {3,1}
    \shape      {action}
    \connection [rl] {alpha}
    \overlay    {cow}
    \text       [rb] {\darkblue \bfb COW 3}
  \stopFLOWcell
\stopFLOWchart
\stopbuffer

\typebuffer \getbuffer

\placefigure
  [here][fig:overlay]
  {Overlays.}
  {\tx\FLOWchart[overlay]}

There are two commands related to overlays. In our example we used: which
automatically scales figure {\em cow} to the shape size. The normal rules for
overlays apply. The width and height of the overlay are available at the moment
the overlay is typeset.

The text is aligned differently in this example and driven by an optional
argument that can take one of the following values: \type {l}, \type {r}, \type
{m}, \type {c}, \type {t}, \type {b}, \type {lt}, \type {rt}, \type {mt}, \type
{ct}, \type {lb}, \type {rb}, \type {mb}, \type {cb}.

\stopsection

\startsection[title={Interaction}]

One of the reasons for writing this module was that we wanted interactive
flowcharts. The shape text can contain references. \footnote {Currently this only
works ok when the chart is not scaled.} The shape as a whole becomes a button as
soon as we add the \type {\destination} entry:

\starttyping
\startFLOWcell
  ...
  \destination {destination}
  ...
\stopFLOWcell
\stoptyping

\startbuffer[movie]
\defineoverlay
  [fun]
  [{\externalfigure
      [texwork.mov]
      [width=\framedwidth,
       height=\framedheight,
       preview=yes,
       repeat=yes]}]
\stopbuffer

\getbuffer[movie]

\starthelptext [alpha]
  \input knuth \blank D.E.~Knuth
\stophelptext

\starthelptext [beta]
  \input tufte \blank E.R.~Tufte
\stophelptext

\starthelptext [delta]
  \externalfigure[cow][width=\hsize]
\stophelptext

\startFLOWchart [interactive]

  \startFLOWcell
    \name        {alpha}
    \location    {1,1}
    \shape       {procedure}
    \connection  [rl] {beta}
    \text        {\goto{introduction}[introduction]}
  \stopFLOWcell

  \startFLOWcell
    \name       {beta}
    \location   {2,1}
    \shape      {product}
    \connection [rl] {gamma}
    \text       {Did you\\read me\\indeed?}
    \destination{introduction}
  \stopFLOWcell

  \setupFLOWlines[dash=yes]

  \startFLOWcell
    \name       {gamma}
    \location   {3,1}
    \shape      {action}
    \connection [rl] {alpha}
    \overlay    {fun}
  \stopFLOWcell

  \setupFLOWlines[dash=no]

  \startFLOWcell
    \name       {delta}
    \location   {4,1}
    \shape      {decision}
    \connection [tt] {alpha}
    \connection [tt] {beta}
    \connection [tt] {gamma}
    \figure     {cow}
  \stopFLOWcell

\stopFLOWchart

\placefigure
  [here][fig:interactive]
  {Interactive buttons.}
  {\tx\FLOWchart[interactive]}

When read as \PDF\ file, \in {figure} [fig:interactive] shows quite a few
interactive features. The first cell has a \type {\goto} included in the text,
like:

\starttyping
\startFLOWcell
  ...
  \text {\goto{introduction}[introduction]}
  ...
\stopFLOWcell
\stoptyping

The second shape is interactive as a whole. This is accomplished by saying:

\starttyping
\startFLOWcell
  ...
  \text        {Did you\\read me\\indeed?}
  \destination {introduction}
  ...
\stopFLOWcell
\stoptyping

The third cell is a movie, which is only visible in suitable viewers. The movie
is included as an overlay.

\typebuffer[movie]

The last cell is an illustration.

\stopsection

\startsection[title={Splitting charts}]

Sometimes a chart does not fit comfortably on the page. In such cases, it makes
sense to split up the chart. There is a dedicated setup command to serve
splitting:

\setup{setupFLOWsplit}

An example of splitting is:

\starttyping
\setupFLOWsplit
  [nx=5,ny=10,
   dx=1,dy=1,
   before=,after=\page]

\FLOWcharts[mybigflow]
\stoptyping

For easy alignment of the split pages, cut marks are added. This can be turned
off by setting \type {marking} to \type {off}. The \type {n} parameters determine
the number of cells per split off subject, and the \type {d} parameters specify
the overlap: a value of~1 means that each split off subject has one row and|/|or
columns in common with its neighbour.

The splitter can be used with the split float placement macro:

\starttyping
\splitfloat
  {\placefigure{What a big flowchart this is!}}
  {\FLOWcharts[mybigflow]}
\stoptyping

Here every flowchart gets an caption with a decent subnumber.

Related to splitting up charts is the option to define exit points as
demonstrated in the next chart.

\startbuffer
\startFLOWchart[metatex]
  \setupFLOWcharts
    [width=6\bodyfontsize,
     height=3\bodyfontsize,
     dx=\bodyfontsize,
     dy=\bodyfontsize]
   \startFLOWcell
    \name       {texexec 1}
    \location   {1,1}
    \shape      {action}
    \text       {\TEXEXEC}
    \connection [rl] {context 1}
  \stopFLOWcell
  \startFLOWcell
    \name       {context 1}
    \location   {2,1}
    \shape      {action}
    \text       {\CONTEXT}
    \connection [bt] {metapost 1}
    \connection [rl] {texexec  2}
    \exit       [r] {123}
  \stopFLOWcell
  \startFLOWcell
    \name       {metapost 1}
    \location   {2,2}
    \shape      {action}
    \text       {\METAPOST}
  \stopFLOWcell
  \startFLOWcell
    \name       {texexec 2}
    \location   {3,1}
    \shape      {action}
    \text       {\TEXEXEC}
    \connection [rl] {context  2}
    \connection [bt] {metapost 2}
    \exit       [l] {123}
  \stopFLOWcell
  \startFLOWcell
    \name       {context 2}
    \location   {4,1}
    \shape      {action}
    \text       {\CONTEXT}
  \stopFLOWcell
  \startFLOWcell
    \name       {metapost 2}
    \location   {3,2}
    \shape      {action}
    \text       {\METAPOST}
  \stopFLOWcell
\stopFLOWchart
\stopbuffer

\typebuffer \getbuffer

\startbuffer[a]
\FLOWchart [metatex] [x=1,nx=2,frame=on]
\stopbuffer

\startbuffer[b]
\FLOWchart [metatex] [x=3,nx=2,frame=on]
\stopbuffer

When we ask for subcharts, the exit points will show up. Because they don't
attribute to the dimensions of the chart, you can still align charts as expected.

\startlinecorrection[blank] \getbuffer[a] \stoplinecorrection
\typebuffer[a]

\startlinecorrection[blank] \getbuffer[b] \stoplinecorrection
\typebuffer[b]

\stopsection

\startsection[title={Other features}]

It is possible to predefine flow charts in a way similar to external figures.
Currently this mechanism is under construction, so describing it would be a bit
premature.

Crossing lines, which are often forbidden in charts, can be made less confusing
by adding a gap in the lines to be crossed. This is one of the features that are
already implemented but not yet accessible by the \CONTEXT\ user interface.

Another feature, used in this document, concerns automatic down||scaling. As soon
as we start scaling illustrations, we introduce inconsistent typography,
especially in the bodyfontsize. Therefore, the flow chart macros, when told to,
are able to automatically scale down in steps of 1~point.

{\em This manual was first published in GUST magazine and presented at the anual
meeting of the Polish user group in Bachotek 1999. Next it was published in the
MAPS volume 23. After that it became Up||To||Date number 1999-003, and now it's
part of the manual series. This version is for \MKIV.}

\stopsection

\stopdocument