m-chart.mkvi /size: 19 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=m-chart,
3%D        version=2011.10.1, % 1998.10.10,
4%D          title=\CONTEXT\ Modules,
5%D       subtitle=Flow Charts,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% todo (if used):
15%    flowsets
16%    autoscaling (bodyfontsteps)
17%    comment
18%
19% todo:
20%    \useFLOWchart[name][parent][setting,setting][additional settings]
21%    \useFLOWchart[name][parent][additional settings]
22%    setups
23%    mp instance with less files
24
25\registerctxluafile{m-chart}{}
26
27\unprotect
28
29% todo: figure out a nice way to define the lot: share current and
30% support current as name (nb: we need to set parent then)
31
32\installcorenamespace {flowchart} % chart
33\installcorenamespace {flowline}  % line
34\installcorenamespace {flowshape} % shape
35\installcorenamespace {flowfocus} % focus
36\installcorenamespace {flowsets}  % sets
37\installcorenamespace {flowsplit} % split
38
39\installsimplecommandhandler \??flowchart {FLOWchart} \??flowchart % maybe just a setuphandler
40\installsimplecommandhandler \??flowline  {FLOWline}  \??flowline  % maybe just a setuphandler
41\installsimplecommandhandler \??flowshape {FLOWshape} \??flowshape % maybe just a setuphandler
42\installsimplecommandhandler \??flowfocus {FLOWfocus} \??flowfocus % maybe just a setuphandler
43\installsimplecommandhandler \??flowsets  {FLOWsets}  \??flowsets  % maybe just a setuphandler
44\installsimplecommandhandler \??flowsplit {FLOWsplit} \??flowsplit % maybe just a setuphandler
45
46\let\setupFLOWcharts\setupFLOWchart
47\let\setupFLOWlines \setupFLOWline
48\let\setupFLOWshapes\setupFLOWshape
49%let\setupFLOWset  \setupFLOWsets
50
51\setupFLOWcharts
52  [\c!width=12\bodyfontsize,
53   \c!height=7\bodyfontsize,
54   \c!offset=\FLOWlineparameter\c!rulethickness,
55   \c!clipoffset=\bodyfontsize,
56   \c!dx=2\bodyfontsize,
57   \c!dy=2\bodyfontsize,
58   \c!nx=0,
59   \c!ny=0,
60   \c!x=1,
61   \c!y=1,
62   \c!labeloffset=.5\bodyfontsize,
63   \c!commentoffset=.5\bodyfontsize,
64   \c!exitoffset=\zeropoint,
65 % \c!split=\v!no,
66 % \c!option=,
67 % \c!bodyfont=,
68 % \c!dot=, % private option
69 % \c!autofocus=,
70 % \c!focus=,
71 % \c!background=,
72 % \c!framecolor=
73 % \c!backgroundcolor=, % \s!white
74   \c!rulethickness=.15\bodyfontsize, %\linewidth,
75   \c!frame=\v!off]
76
77\setupFLOWlines
78  [\c!corner=\v!round,
79   \c!arrow=\v!yes,
80   \c!dash=\v!no,
81   \c!radius=.375\bodyfontsize,
82   \c!color=FLOWlinecolor,
83   \c!rulethickness=.15\bodyfontsize,
84   \c!offset=\zeropoint]
85
86\setupFLOWshapes
87  [\c!default=action,
88   \c!framecolor=FLOWframecolor,
89   \c!background=\v!color,
90   \c!backgroundcolor=FLOWbackgroundcolor,
91   \c!rulethickness=.15\bodyfontsize,
92   \c!offset=.5\bodyfontsize]
93
94\setupFLOWfocus
95  [\c!framecolor=FLOWfocuscolor,
96   \c!background=\FLOWshapeparameter\c!background,
97   \c!backgroundcolor=\FLOWshapeparameter\c!backgroundcolor,
98   \c!rulethickness=\FLOWshapeparameter\c!rulethickness,
99   \c!offset=\FLOWshapeparameter\c!offset]
100
101\setupFLOWsplit
102  [\c!dx=0,
103   \c!dy=0,
104 % \c!command=,
105 % \c!before=,
106 % \c!after=,
107   \c!nx=3,
108   \c!ny=4]
109
110\unexpanded\def\beforeFLOWsplit{\FLOWsplitparameter\c!before}
111\unexpanded\def\afterFLOWsplit {\FLOWsplitparameter\c!after}
112\unexpanded\def\handleFLOWsplit{\FLOWsplitparameter\c!command}
113
114\definecolor [FLOWfocuscolor]      [s=.2]
115\definecolor [FLOWlinecolor]       [s=.5]
116\definecolor [FLOWframecolor]      [s=.7]
117\definecolor [FLOWbackgroundcolor] [s=.9]
118
119\newtoks\everyFLOWchart
120
121\unexpanded\def\module_charts_process[#name]%
122  {\clf_flow_start_chart{#name}}
123
124\unexpanded\def\startFLOWchart
125  {\startnointerference
126   \the\everyFLOWchart
127   \dosingleempty\module_charts_start_chart}
128
129\unexpanded\def\module_charts_start_chart[#name]%
130  {\clf_flow_start_chart{#name}}
131
132\unexpanded\def\stopFLOWchart
133  {\clf_flow_stop_chart
134   \stopnointerference}
135
136\unexpanded\def\defineFLOWchart % for old times sake
137  {\dodoubleempty\module_charts_FLOW_define}
138
139\unexpanded\def\module_charts_FLOW_define[#name][#settings]#cells% todo: save settings
140  {\startnointerference
141   \the\everyFLOWchart
142   \clf_flow_start_chart{#name}%
143   #cells%
144   \clf_flow_stop_chart
145   \stopnointerference}
146
147\unexpanded\def\startFLOWcell
148  {\dodoubleempty\module_charts_start_cell}
149
150\unexpanded\def\module_charts_start_cell[#1][#2]%
151  {\begingroup
152   \iffirstargument
153     \setupFLOWshape[#1]%
154   \fi
155   \ifsecondargument
156     \setupFLOWline[#2]%
157   \fi
158   \clf_flow_start_cell
159        shape {
160            rulethickness   \dimexpr\FLOWshapeparameter\c!rulethickness\relax
161            default         {\FLOWshapeparameter\c!default}
162            framecolor      {\FLOWshapeparameter\c!framecolor}
163            backgroundcolor {\FLOWshapeparameter\c!backgroundcolor}
164        }
165        focus {
166            rulethickness   \dimexpr\FLOWfocusparameter\c!rulethickness\relax
167            framecolor      {\FLOWfocusparameter\c!framecolor}
168            backgroundcolor {\FLOWfocusparameter\c!backgroundcolor}
169        }
170        line {
171            rulethickness   \dimexpr\FLOWlineparameter\c!rulethickness\relax
172            radius          \dimexpr\FLOWlineparameter\c!radius\relax
173            color           {\FLOWlineparameter\c!color}
174            corner          {\FLOWlineparameter\c!corner}
175            dash            {\FLOWlineparameter\c!dash}
176            arrow           {\FLOWlineparameter\c!arrow}
177            offset          \dimexpr\FLOWlineparameter\c!offset\relax
178        }
179  \relax
180  \endgroup}
181
182\unexpanded\def\stopFLOWcell
183  {\clf_flow_stop_cell}
184
185\unexpanded\def\FLOWchart
186  {\dodoubleempty\module_charts_process}
187
188\def\module_charts_process[#name][#settings]%
189%   {\hpack\bgroup % \vbox removed, \hpack prevents issues with tex.runtoks
190  {\bgroup % \vbox removed, \hpack prevents issues with tex.runtoks
191     \insidefloattrue
192     \dontcomplain
193     \setupFLOWchart[#settings]%
194     \usebodyfontparameter\FLOWchartparameter
195% \meta_process_graphic_start
196% \meta_start_current_graphic
197     \clf_flow_make_chart
198        chart {
199            name            {#name}
200            option          {\FLOWchartparameter\c!option}
201            backgroundcolor {\FLOWchartparameter\c!backgroundcolor}
202            width           \dimexpr\FLOWchartparameter\c!width\relax
203            height          \dimexpr\FLOWchartparameter\c!height\relax
204            dx              \dimexpr\FLOWchartparameter\c!dx\relax
205            dy              \dimexpr\FLOWchartparameter\c!dy\relax
206            offset          \dimexpr\FLOWchartparameter\c!offset\relax
207            clipoffset      \dimexpr\FLOWchartparameter\c!clipoffset\relax
208          % bodyfont        {\FLOWchartparameter\c!bodyfont}
209            dot             {\FLOWchartparameter\c!dot}      % private option
210            hcompact        {\FLOWchartparameter\c!hcompact} % undocumented option
211            vcompact        {\FLOWchartparameter\c!vcompact} % undocumented option
212            focus           {\FLOWchartparameter\c!focus}
213            autofocus       {\FLOWchartparameter\c!autofocus}
214            nx              \numexpr\FLOWchartparameter\c!nx\relax
215            ny              \numexpr\FLOWchartparameter\c!ny\relax
216            x               \numexpr\FLOWchartparameter\c!x\relax
217            y               \numexpr\FLOWchartparameter\c!y\relax
218            labeloffset     \dimexpr\FLOWchartparameter\c!labeloffset\relax
219            commentoffset   \dimexpr\FLOWchartparameter\c!commentoffset\relax
220            exitoffset      \dimexpr\FLOWchartparameter\c!exitoffset\relax
221            split           {\FLOWchartparameter\c!split}
222        }
223        shape {
224            rulethickness   \dimexpr\FLOWshapeparameter\c!rulethickness\relax
225            default         {\FLOWshapeparameter\c!default}
226            framecolor      {\FLOWshapeparameter\c!framecolor}
227            backgroundcolor {\FLOWshapeparameter\c!backgroundcolor}
228        }
229        focus {
230            rulethickness   \dimexpr\FLOWfocusparameter\c!rulethickness\relax
231            framecolor      {\FLOWfocusparameter\c!framecolor}
232            backgroundcolor {\FLOWfocusparameter\c!backgroundcolor}
233        }
234        line {
235            rulethickness   \dimexpr\FLOWlineparameter\c!rulethickness\relax
236            radius          \dimexpr\FLOWlineparameter\c!radius\relax
237            color           {\FLOWlineparameter\c!color}
238            corner          {\FLOWlineparameter\c!corner}
239            dash            {\FLOWlineparameter\c!dash}
240            arrow           {\FLOWlineparameter\c!arrow}
241            offset          {\FLOWlineparameter\c!offset}
242        }
243      % set {
244      % }
245        split {
246            nx              \numexpr\FLOWsplitparameter\c!nx\relax
247            ny              \numexpr\FLOWsplitparameter\c!ny\relax
248            dx              \numexpr\FLOWsplitparameter\c!dx\relax
249            dy              \numexpr\FLOWsplitparameter\c!dy\relax
250            command         {}
251            marking         {\FLOWsplitparameter\c!marking}
252            before          {}
253            after           {}
254        }
255     \relax
256% \meta_stop_current_graphic
257% \meta_process_graphic_stop
258  \egroup}
259
260\unexpanded\def\FLOWcharts
261  {\dodoubleempty\FLOW_charts}
262
263\def\FLOW_charts[#name][#settings]%
264  {\begingroup
265   \setupFLOWchart[\c!split=\v!yes]%
266   \setupFLOWsplit[#settings]%
267   \FLOWchart[#name]%
268   \endgroup}
269
270\appendtoks
271   \let\name       \FLOW_name
272   \let\shape      \FLOW_shape
273   \let\destination\FLOW_destination
274   \let\focus      \FLOW_focus
275   \let\overlay    \FLOW_overlay
276   \let\location   \FLOW_location
277   \let\text       \FLOW_text
278   \let\label      \FLOW_label
279   \overloaded\let\comment    \FLOW_comment
280   \let\exit       \FLOW_exit
281   \let\connection \FLOW_connection
282   \let\include    \FLOW_include
283   \let\figure     \FLOW_figure
284   %
285   \let\connect    \FLOW_connection
286   \let\locate     \FLOW_location
287   %
288   \overloaded\let\includeFLOWchart\include
289\to \everyFLOWchart
290
291\unexpanded\def\FLOW_name              #name{\clf_flow_set_name{#name}\ignorespaces}
292\unexpanded\def\FLOW_shape            #shape{\clf_flow_set_shape{#shape}\ignorespaces}
293\unexpanded\def\FLOW_destination#destination{\clf_flow_set_destination{#destination}\ignorespaces}
294\unexpanded\def\FLOW_focus            #focus{\clf_flow_set_focus{#focus}\ignorespaces}
295\unexpanded\def\FLOW_overlay        #overlay{\clf_flow_set_overlay{#overlay}\ignorespaces}
296\unexpanded\def\FLOW_location      #location{\clf_flow_set_location{#location}\ignorespaces}
297\unexpanded\def\FLOW_figure          #figure{\clf_flow_set_figure{#figure}\ignorespaces}
298
299\unexpanded\def\FLOW_text      {\dosingleempty\module_charts_FLOW_text}
300\unexpanded\def\FLOW_label     {\dosingleempty\module_charts_FLOW_label}
301\unexpanded\def\FLOW_comment   {\dosingleempty\module_charts_FLOW_comment}
302\unexpanded\def\FLOW_exit      {\dosingleempty\module_charts_FLOW_exit}
303\unexpanded\def\FLOW_connection{\dodoubleempty\module_charts_FLOW_connection}
304\unexpanded\def\FLOW_include   {\dodoubleempty\module_charts_FLOW_include}
305
306\unexpanded\def\module_charts_FLOW_text                  [#align]#text{\clf_flow_set_text{#align}{\detokenize{#text}}\ignorespaces}
307\unexpanded\def\module_charts_FLOW_label              [#location]#text{\clf_flow_set_label{#location}{\detokenize{#text}}\ignorespaces}
308\unexpanded\def\module_charts_FLOW_comment            [#location]#text{\clf_flow_set_comment{#location}{\detokenize{#text}}\ignorespaces}
309\unexpanded\def\module_charts_FLOW_exit               [#location]#text{\clf_flow_set_exit{#location}{\detokenize{#text}}\ignorespaces}
310\unexpanded\def\module_charts_FLOW_connection[#location][#offset]#name{\clf_flow_set_connection{#location}{#offset}{#name}\ignorespaces}
311
312\unexpanded\def\module_charts_FLOW_include          [#name][#settings]{%
313    \begingroup
314        \getdummyparameters[\c!x=1,\c!y=1,#settings]%
315        \clf_flow_set_include{#name}\numexpr\dummyparameter\c!x\relax\numexpr\dummyparameter\c!y\relax{\detokenize{#settings}}%
316    \endgroup
317    \ignorespaces
318}
319
320\setvariables
321  [flowcell:text]
322  [n=0,
323   x=1,
324   y=1,
325   realx=1,
326   realy=1,
327   text=,
328   align=,
329   set=\setups{flowcell:text:place}]
330
331\def\FLOWx    {\getvariable{flowcell:text}{x}}     % compatibility (for Willi)
332\def\FLOWy    {\getvariable{flowcell:text}{y}}     % compatibility (for Willi)
333\def\FLOWrealx{\getvariable{flowcell:text}{realx}} % compatibility (for Willi)
334\def\FLOWrealy{\getvariable{flowcell:text}{realy}} % compatibility (for Willi)
335
336\defineoverlay
337  [flowcell:figure]
338  [\overlayfigure{\getvariable{flowcell:text}{figure}}]
339
340\startsetups flowcell:text:place
341    \begingroup
342        \iftrialtypesetting
343            \directsetup{flowcell:text:place:indeed}
344        \else \iflocation
345            \edef\flowcelldestination{\getvariable{flowcell:text}{destination}}%
346            \ifx\flowcelldestination\empty
347                \directsetup{flowcell:text:place:indeed}
348            \else
349                % tricky: scaling and moving around is not taken into account
350                \letinteractionparameter\c!color\empty
351                \letinteractionparameter\c!contrastcolor\empty
352                \gotobox{\directsetup{flowcell:text:place:indeed}}[\flowcelldestination]
353            \fi
354        \else
355            \directsetup{flowcell:text:place:indeed}
356        \fi \fi
357    \endgroup
358\stopsetups
359
360\startsetups flowcell:text:place:indeed
361    \begingroup
362        \directsetup{flowcell:text:user}
363        \edef\flowcellfigure {\getvariable{flowcell:text}{figure}}%
364        \edef\flowcelloverlay{\getvariable{flowcell:text}{overlay}}%
365        \edef\flowcellalign  {\getvariable{flowcell:text}{align}}%
366        \edef\flowcellindex  {\getvariable{flowcell:text}{n}}%
367        \ifx\flowcellfigure\empty
368            \ifx\flowcelloverlay\empty
369                \expandcheckedcsname{flowcell:}\flowcellalign\empty
370                    % {\getvariable{flowcell:text}{text}}
371                      {\getFLOWtext\flowcellindex}
372            \else
373                \expandcheckedcsname{flowcell:}\flowcellalign\empty
374                    [\c!background={\flowcelloverlay}]
375                  % {\getvariable{flowcell:text}{text}}
376                    {\getFLOWtext\flowcellindex}
377            \fi
378        \else
379            \expandcheckedcsname{flowcell:}\flowcellalign\empty
380                [\c!background=flowcell:figure]
381              % {\getvariable{flowcell:text}{text}}
382                {\getFLOWtext\flowcellindex}
383        \fi
384    \endgroup
385\stopsetups
386
387\unexpanded\def\doFLOWlabel#1#2#3#4#5%
388  {\begingroup
389   \def\FLOWx{#1}%
390   \def\FLOWy{#2}%
391   \def\FLOWrealx{#4}%
392   \def\FLOWrealy{#5}%
393   \strut
394   \getFLOWtext{#3}%
395   \endgroup}
396
397\unexpanded\def\getFLOWtext#1%
398  {\ifcase#1\else\clf_flow_get_text\numexpr#1\relax\fi}
399
400\defineframed % to be discussed: shape or global
401  [flowcell:base]
402  [\c!offset=\v!overlay, % no strut ?
403   \c!frame=\FLOWchartparameter\c!frame,
404   \c!background=\FLOWchartparameter\c!background,
405   \c!backgroundcolor=\FLOWchartparameter\c!backgroundcolor,
406  %\c!foregroundcolor=\FLOWshapeparameter\c!foregroundcolor,
407   \c!align=\v!middle,
408   \c!bottom=\vfill,
409   \c!top=\vfill,
410   \c!width=\FLOWchartparameter\c!width,
411   \c!height=\FLOWchartparameter\c!height,
412 % \c!rulethickness=\FLOWchartparameter\c!rulethickness,
413   \c!rulethickness=\zeropoint, % comment for tracing
414   \c!framecolor=\FLOWchartparameter\c!framecolor]
415
416\defineframed[flowcell:]  [flowcell:base]
417\defineframed[flowcell:l] [flowcell:base][\c!align=\v!flushleft]
418\defineframed[flowcell:r] [flowcell:base][\c!align=\v!flushright]
419\defineframed[flowcell:m] [flowcell:base][\c!align=\v!middle]
420\defineframed[flowcell:c] [flowcell:base][\c!align=\v!middle]
421
422\defineframed[flowcell:t] [flowcell:base][\c!top=]
423\defineframed[flowcell:b] [flowcell:base][\c!bottom=]
424
425\defineframed[flowcell:lt][flowcell:base][\c!top=,\c!align=\v!flushleft]
426\defineframed[flowcell:rt][flowcell:base][\c!top=,\c!align=\v!flushright]
427\defineframed[flowcell:mt][flowcell:base][\c!top=,\c!align=\v!middle]
428\defineframed[flowcell:ct][flowcell:base][\c!top=,\c!align=\v!middle]
429
430\defineframed[flowcell:lb][flowcell:base][\c!bottom=,\c!align=\v!flushleft]
431\defineframed[flowcell:rb][flowcell:base][\c!bottom=,\c!align=\v!flushright]
432\defineframed[flowcell:mb][flowcell:base][\c!bottom=,\c!align=\v!middle]
433\defineframed[flowcell:cb][flowcell:base][\c!bottom=,\c!align=\v!middle]
434
435% \startsetups flowcell:text:user
436%     \setupframed
437%       [flowcell:base]
438%       [background=flowcell]
439%     \definelayer
440%       [flowcell]
441%       [width=\namedframedparameter{flowcell:base}{width},
442%        height=\namedframedparameter{flowcell:base}{height}]
443%     \setlayerframed
444%       [flowcell]
445%       [preset=rightbottom,offset=-2.75ex]
446%       [frame=off]
447%       {\tx\FLOWx.\FLOWy}
448% \stopsetups
449%
450% % or:
451%
452% \setupframed
453%   [flowcell:base]
454%   [background={flowcell-1,flowcell-2}]
455%
456% \defineoverlay
457%   [flowcell-1]
458%   [\directsetup{flowcell-1}]
459%
460% \definelayer
461%   [flowcell-2]
462%   [width=\overlaywidth,
463%    height=\overlayheight]
464%
465% \startsetups flowcell-1
466%     \setlayerframed
467%       [flowcell-2]
468%       [preset=rightbottom,offset=-2.75ex]
469%       [frame=off]
470%       {\tx\FLOWx.\FLOWy}
471% \stopsetups
472
473% %D \starttyping
474% %D \setupFLOWsplit
475% %D   [nx=5,ny=10,
476% %D    dx=0,dy=0,
477% %D    before=,
478% %D    after=\page]
479% %D
480% %D \FLOWcharts[mybigflow]
481% %D \stoptyping
482% %D
483% %D \starttyping
484% %D \splitfloat
485% %D   {\placefigure{What a big flowchart this is!}}
486% %D   {\FLOWcharts[mybigflow]}
487% %D \stoptyping
488
489% \setupFLOWsplit
490%    [nx=5,
491%     ny=8,
492%     dx=1,
493%     dy=1,
494%     command=\framed,
495%     before=\page,
496%     after=\page]
497%
498% \FLOWchart[demo]                     \page
499% \FLOWchart[demo][split=yes]          \page
500% \FLOWchart[demo][x=1,y=1,nx=5,ny=8]  \page
501% \FLOWchart[demo][x=1,y=9,nx=5,ny=10] \page
502
503\protect
504
505\continueifinputfile{m-chart.mkvi}
506
507\input chrt-xml.tex
508
509\usemodule[abr-01]
510
511\setupFLOWcharts[option=test]
512\setupFLOWcharts[frame=on]
513\setupinteraction[state=start]
514
515% \setupFLOWcharts[dx=30pt,dy=30pt]
516
517\startMPinclusions
518    predefined_shapes[101] := fullcircle ;
519\stopMPinclusions
520
521\startFLOWchart[demo]
522  \startFLOWcell[framecolor=darkgray]
523    \name       {start}
524    \location   {1,1}
525    \shape      {action}
526    \text       {start}
527    \connection [bl] {one}
528  \stopFLOWcell
529  \startFLOWcell[framecolor=darkred]
530    \name       {one}
531%     \destination{CloseDocument}
532    \location   {2,2}
533%     \shape      {action}
534    \shape      {101}
535    \text       {first}
536%     \label      [b] {\bfx bottom}
537    \connection [rt] {two}
538%     \exit       [l] {exit l}
539%     \exit       [r] {exit r}
540%     \exit       [t] {exit t}
541%     \exit       [b] {exit b}
542  \stopFLOWcell
543  \setupFLOWshapes[framecolor=darkgray]
544  \startFLOWcell % [foregroundcolor=white]
545    \name       {two}
546%     \destination{CloseDocument}
547    \location   {3,3}
548    \shape      {action}
549    \text       {second}
550    \figure     {cow.pdf}
551%     \label      [l] {\bfx left}
552%     \exit       [l] {exit l}
553%     \exit       [r] {exit r}
554%     \exit       [t] {exit t}
555%     \exit       [b] {exit b}
556  \stopFLOWcell
557\stopFLOWchart
558
559\starttext
560
561\startTEXpage
562%     \FLOWchart[convert-en]
563%     \FLOWchart[conversion 1]
564%     \FLOWchart[conversion 7]
565%     \FLOWchart[conversion 9]
566%     \FLOWchart[conversion 10]
567    \FLOWchart[demo]
568
569\stopTEXpage
570
571\startTEXpage
572    \FLOWchart[conversion 10]
573\stopTEXpage
574
575\stoptext
576