summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2011-10-12 19:30:00 +0200
committerHans Hagen <pragma@wxs.nl>2011-10-12 19:30:00 +0200
commit4a773c08afc8f14ff421110d2baa060b84952b08 (patch)
tree6d80185e57a807c49f50c3de1af0fe9159560076 /metapost
parent072cb8119b98a781ae7af278a3fa36026a3d19a8 (diff)
downloadcontext-4a773c08afc8f14ff421110d2baa060b84952b08.tar.gz
beta 2011.10.12 19:30
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/metafun.mpii4
-rw-r--r--metapost/context/base/metafun.mpiv4
-rw-r--r--metapost/context/base/mp-char.mp1019
-rw-r--r--metapost/context/base/mp-flow.mpiv1020
-rw-r--r--metapost/context/base/mp-step.mpii (renamed from metapost/context/base/mp-step.mp)0
-rw-r--r--metapost/context/base/mp-step.mpiv375
6 files changed, 379 insertions, 2043 deletions
diff --git a/metapost/context/base/metafun.mpii b/metapost/context/base/metafun.mpii
index 705900a18..65d7b87f8 100644
--- a/metapost/context/base/metafun.mpii
+++ b/metapost/context/base/metafun.mpii
@@ -37,8 +37,8 @@ input mp-text.mp ;
input mp-txts.mp ;
input mp-shap.mp ;
input mp-butt.mp ;
-input mp-char.mp ;
-input mp-step.mp ;
+input mp-char.mpii ;
+input mp-step.mpii ;
input mp-grph.mp ;
input mp-figs.mp ;
input mp-grid.mp ;
diff --git a/metapost/context/base/metafun.mpiv b/metapost/context/base/metafun.mpiv
index 80cfcd423..b32e301a7 100644
--- a/metapost/context/base/metafun.mpiv
+++ b/metapost/context/base/metafun.mpiv
@@ -24,8 +24,8 @@ input mp-text.mp ;
input mp-txts.mp ;
input mp-butt.mp ;
input mp-shap.mp ;
-% mp-char.mp ; % there no need to always load this
-% mp-step.mp ; % there no need to always load this
+% mp-char.mpiv ; % there no need to always load this
+% mp-step.mpiv ; % there no need to always load this
input mp-grph.mp ;
input mp-figs.mp ;
input mp-mlib.mpiv ;
diff --git a/metapost/context/base/mp-char.mp b/metapost/context/base/mp-char.mp
deleted file mode 100644
index 3a7a1d939..000000000
--- a/metapost/context/base/mp-char.mp
+++ /dev/null
@@ -1,1019 +0,0 @@
-% to be cleaned up, namespace needed ! ! ! ! !
-
-%D \module
-%D [ file=mp-char.mp,
-%D version=1998.10.10,
-%D title=\CONTEXT\ \METAPOST\ graphics,
-%D subtitle=charts,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
-%C details.
-
-if unknown context_tool : input mp-tool ; fi ;
-if unknown context_shap : input mp-shap ; fi ;
-if known context_char : endinput ; fi ;
-
-boolean context_char ; context_char := true ;
-
-% kan naar elders
-
-current_position := 0 ;
-
-def save_text_position (expr p) = % beware: clip shift needed
- current_position := current_position + 1 ;
- savedata
- "\MPposition{" & decimal current_position & "}{"
- & decimal xpart p & "}{"
- & decimal ypart p & "}%" ;
-enddef ;
-
-%D settings
-
-grid_width := 60pt ; grid_height := 40pt ;
-shape_width := 45pt ; shape_height := 30pt ;
-
-chart_offset := 2pt ;
-color chart_background_color ; chart_background_color := white ;
-
-%D test mode
-
-boolean show_mid_points ; show_mid_points := false ;
-boolean show_con_points ; show_con_points := false ;
-boolean show_all_points ; show_all_points := false ;
-
-%D shapes
-
-color shape_line_color, shape_fill_color ;
-
-shape_line_width := 2pt ;
-shape_line_color := .5white ;
-shape_fill_color := .9white ;
-
-shape_node := 0 ;
-shape_action := 24 ;
-shape_procedure := 5 ;
-shape_product := 12 ;
-shape_decision := 14 ;
-shape_archive := 19 ;
-shape_loop := 35 ;
-shape_wait := 6 ;
-shape_subprocedure := 20 ; shape_sub_procedure := 20 ;
-shape_singledocument := 32 ; shape_single_document := 32 ;
-shape_multidocument := 33 ; shape_multi_document := 33 ;
-shape_right := 66 ;
-shape_left := 67 ;
-shape_up := 68 ;
-shape_down := 69 ;
-
-% vardef some_shape_path (expr type) == imported from mp-shap
-
-def show_shapes (expr n) =
-
- begin_chart(n,8,10) ;
- show_con_points := true ;
- for i=0 upto 7 :
- for j=0 upto 9 :
- new_shape(i+1,j+1,i*10+j);
- endfor ;
- endfor ;
- end_chart ;
-
-enddef ;
-
-%D connections
-
-def new_chart =
-
- color connection_line_color ;
-
- connection_line_width := shape_line_width ;
- connection_line_color := .8white ;
- connection_smooth_size := 5pt ;
- connection_arrow_size := 4pt ;
- connection_dash_size := 3pt ;
-
- max_x := 6 ;
- max_y := 4 ;
-
- numeric xypoint ; xypoint := 0 ;
-
- pair xypoints [] ;
-
- boolean xyfree [][] ;
- path xypath [][] ;
- numeric xysx [][] ;
- numeric xysy [][] ;
- color xyfill [][] ;
- color xydraw [][] ;
- numeric xyline [][] ;
- boolean xypeep [][] ;
- picture xypicture[][] ;
-
- numeric cpath ; cpath := 0 ;
- path cpaths [] ;
- numeric cline [] ;
- color ccolor [] ;
- boolean carrow [] ;
- boolean cdash [] ;
- boolean ccross [] ;
-
- boolean smooth ; smooth := true ;
- boolean peepshape ; peepshape := false ;
- boolean arrowtip ; arrowtip := true ;
- boolean dashline ; dashline := false ;
- boolean forcevalid ; forcevalid := false ;
- boolean touchshape ; touchshape := false ;
- boolean showcrossing ; showcrossing := false ;
-
- picture dash_pattern ;
-
- boolean reverse_y ; reverse_y := true ;
-
-enddef ;
-
-new_chart ;
-
-def y_pos (expr y) =
- if reverse_y : max_y + 1 - y else : y fi
-enddef ;
-
-def initialize_grid (expr maxx, maxy) =
- begingroup ;
- save i, j ;
- max_x := maxx ;
- max_y := maxy ;
- dsp_x := 0 ;
- dsp_y := 0 ;
- for x=1 upto max_x :
- for y=1 upto max_y :
- xyfree [x][y] := true ;
- xyfill [x][y] := shape_fill_color ;
- xydraw [x][y] := shape_line_color ;
- xyline [x][y] := shape_line_width ;
- endfor ;
- endfor ;
- endgroup ;
-enddef ;
-
-def scaled_to_grid =
- xscaled grid_width yscaled grid_height
-enddef ;
-
-def xy_offset (expr x, y) =
- (x+.5,y+.5)
-enddef ;
-
-def draw_shape (expr x, yy, p, sx, sy) =
- begingroup ;
- save y ;
- y := y_pos(yy) ;
- xypath [x][y] := (p xscaled sx yscaled sy) shifted xy_offset(x,y) ;
- xyfree [x][y] := false ;
- xysx [x][y] := sx ;
- xysy [x][y] := sy ;
- xyfill [x][y] := shape_fill_color ;
- xydraw [x][y] := shape_line_color ;
- xyline [x][y] := shape_line_width ;
- xypeep [x][y] := peepshape ;
- endgroup ;
-enddef ;
-
-vardef i_point (expr x, y, p, t) =
- begingroup ;
- save q, ok ;
- pair q ;
- boolean ok ;
- q := xypath[x][y] intersection_point ((p) shifted xy_offset(x,y)) ;
- ok := true ;
-% if xpart q < -.5 : ok := false ; q := (-.45,ypart q) fi ;
-% if xpart q > .5 : ok := false ; q := ( .45,ypart q) fi ;
-% if ypart q < -.5 : ok := false ; q := (xpart q,-.45) fi ;
-% if ypart q > .5 : ok := false ; q := (xpart q, .45) fi ;
- if not ok :
- message (t & " of shape (" & decimal x & "," & decimal y & ") limited") ;
- fi ;
- q
- endgroup
-enddef ;
-
-vardef trimmed (expr x, y, z, t) =
- if touchshape and t : xyline[x][y]/z else : epsilon fi
-enddef ;
-
-zfactor := 1/3 ;
-
-vardef xy_bottom (expr x, y, z, t) =
- i_point (x, y, ((0,0)--(0,-2)) shifted (zfactor*z*xysx[x][y],0), "bottom")
- shifted(0,-trimmed(x,y,grid_height,t))
-enddef ;
-
-vardef xy_top (expr x, y, z, t) =
- i_point (x, y, ((0,0)--(0,2)) shifted (zfactor*z*xysx[x][y],0), "top")
- shifted(0,trimmed(x,y,grid_height,t))
-enddef ;
-
-vardef xy_left (expr x, y, z, t) =
- i_point (x, y, ((0,0)--(-2,0)) shifted (0,zfactor*z*xysy[x][y]), "left")
- shifted(-trimmed(x,y,grid_width,t),0)
-enddef ;
-
-vardef xy_right (expr x, y, z, t) =
- i_point (x, y, ((0,0)--(2,0)) shifted (0,zfactor*z*xysy[x][y]), "right")
- shifted(trimmed(x,y,grid_width,t),0)
-enddef ;
-
-def flush_shapes =
- for x=1 upto max_x :
- for y=1 upto max_y :
- flush_shape (x, y) ;
- endfor ;
- endfor ;
-enddef ;
-
-def flush_pictures =
- for x=1 upto max_x :
- for y=1 upto max_y :
- flush_picture (x, y) ;
- endfor ;
- endfor ;
-enddef ;
-
-
-def draw_connection_point (expr x, y, z) =
- pickup pencircle scaled if (z=0): 2 fi xyline[x][y] ;
- drawdot xy_bottom(x,y,z,false) scaled_to_grid withcolor (1,0,0) ;
- drawdot xy_top (x,y,z,false) scaled_to_grid withcolor (0,1,0) ;
- drawdot xy_left (x,y,z,false) scaled_to_grid withcolor (0,0,1) ;
- drawdot xy_right (x,y,z,false) scaled_to_grid withcolor (1,1,0) ;
-enddef ;
-
-def flush_shape (expr x, yy) =
- begingroup ;
- save y ;
- y := y_pos(yy) ;
- if not xyfree[x][y] :
- pickup pencircle scaled xyline[x][y] ;
- if xypeep[x][y] :
- fill (xypath[x][y] peepholed (unitsquare shifted (x,y)))
- scaled_to_grid withpen pencircle scaled 0
- withcolor chart_background_color ;
- else :
- fill xypath[x][y] scaled_to_grid withcolor xyfill[x][y] ;
- fi ;
- draw xypath[x][y] scaled_to_grid withcolor xydraw[x][y] ;
- if show_con_points or show_all_points :
- draw_connection_point (x, y, 0) ;
- fi ;
- if show_all_points :
- for i=-1 upto 1 :
- draw_connection_point (x, y, i) ;
- endfor ;
- fi ;
- fi ;
- endgroup ;
-enddef ;
-
-vardef points_initialized (expr xfrom, yfrom, xto, yto, n) =
- if not xyfree[xfrom][yfrom] and not xyfree[xto][yto] :
- xypoint := n ; true
- else :
- xypoint := 0 ; false
- fi
-enddef ;
-
-def collapse_points = % this is now an mp-tool macro
- % remove redundant points
- n := 1 ;
- for i=2 upto xypoint:
- if not (xypoints[i]=xypoints[n]) :
- n := n + 1 ;
- xypoints[n] := xypoints[i]
- fi ;
- endfor ;
- xypoint := n ;
- % make straight lines
- if xypoints[2]=xypoints[xypoint-1] :
- xypoints[3] := xypoints[xypoint] ;
- xypoint := 3 ;
- fi ;
-enddef ;
-
-vardef smooth_connection (expr a,b) =
- sx := connection_smooth_size/grid_width ;
- sy := connection_smooth_size/grid_height ;
- if ypart a = ypart b :
- a shifted (if xpart a >= xpart b : - fi sx,0)
-% a shifted (sx*xpart unitvector(b-a),0)
- else :
- a shifted (0,if ypart a >= ypart b : - fi sy)
-% a shifted (0,sy*ypart unitvector(b-a))
- fi
-enddef ;
-
-vardef trim_points =
- begingroup
- save p, a, b, d, i ; path p ; pair d ;
- p := for i=1 upto xypoint-1 : xypoints[i]-- endfor xypoints[xypoint] ;
- if touchshape :
- a := shape_line_width/grid_width ;
- b := shape_line_width/grid_height ;
- else :
- a := epsilon ;
- b := epsilon ;
- fi ;
- d := direction infinity of p ;
- xypoints[xypoint] := xypoints[xypoint] shifted
- if xpart d < 0 : (+a,0) ;
- elseif xpart d > 0 : (-a,0) ;
- elseif ypart d < 0 : (0,+b) ;
- elseif ypart d > 0 : (0,-b) ;
- else : origin ;
- fi ;
- d := direction 0 of p ;
- xypoints[1] := xypoints[1] shifted
- if xpart d < 0 : (-a,0) ;
- elseif xpart d > 0 : (+a,0) ;
- elseif ypart d < 0 : (0,-b) ;
- elseif ypart d > 0 : (0,+b) ;
- else : origin ;
- fi ;
- endgroup
-enddef ;
-
-vardef trim_points = enddef ;
-
-vardef connection_path =
- if reverse_connection : reverse fi (xypoints[1]--
- for i=2 upto xypoint-1 :
- if smooth :
- smooth_connection(xypoints[i],xypoints[i-1]) ..
- controls xypoints[i] and xypoints[i] ..
- smooth_connection(xypoints[i],xypoints[i+1]) --
- else :
- xypoints[i]--
- fi
- endfor
- xypoints[xypoint])
-enddef ;
-
-% vardef connection_path =
-% sx := connection_smooth_size/grid_width ;
-% sy := connection_smooth_size/grid_height ;
-% if reverse_connection : reverse fi
-% (for i=1 upto xypoint-1 : xypoints[i] -- endfor xypoints[xypoint])
-% if smooth : cornered max(sx,sy) fi
-% enddef ;
-%
-% primarydef p cornered c =
-% if cycle p :
-% ((point 0 of p) shifted (c*(unitvector(point 1 of p - point 0 of p))) --
-% for i=1 upto length(p) :
-% (point i-1 of p) shifted (c*(unitvector(point i of p - point i-1 of p))) --
-% (point i of p) shifted (c*(unitvector(point i-1 of p - point i of p))) ..
-% controls point i of p ..
-% endfor cycle)
-% else :
-% ((point 0 of p) --
-% for i=1 upto length(p)-1 :
-% (point i-1 of p) shifted (c*(unitvector(point i of p - point i-1 of p))) --
-% (point i of p) shifted (c*(unitvector(point i-1 of p - point i of p))) ..
-% controls point i of p ..
-% endfor
-% (point length(p) of p))
-% fi
-% enddef ;
-
-def draw_connection =
- if xypoint>0 :
- collapse_points ;
- trim_points ;
- cpath := cpath + 1 ;
- cpaths[cpath] := connection_path scaled_to_grid ;
- cline[cpath] := connection_line_width ;
- ccolor[cpath] := connection_line_color ;
- carrow[cpath] := arrowtip ;
- cdash[cpath] := dashline ;
- ccross[cpath] := showcrossing ;
- else :
- message("no connection defined") ;
- fi ;
- reverse_connection := false ;
-enddef ;
-
-def flush_connections =
- pair ip ;
- boolean crossing ;
- ahlength := connection_arrow_size ;
- dash_pattern := dashpattern(on connection_dash_size off connection_dash_size ) ;
- for i=1 upto cpath :
- if ccross[i] :
- crossing := false ;
- for j=1 upto i :
- %if not ((point infinity of cpaths[i] = point infinity of cpaths[j]) or
- % (point 0 of cpaths[i] = point 0 of cpaths[j])) :
- if not (point infinity of cpaths[i] = point infinity of cpaths[j]) :
- ip := cpaths[i] intersection_point cpaths[j] ;
- if intersection_found : crossing := true fi ;
- fi ;
- endfor ;
- if crossing :
- pickup pencircle scaled 2cline[i] ;
- %draw cpaths[i] withcolor chart_background_color ;
- path cp ; cp := cpaths[i] ;
- cp := cp cutbefore point .05 length cp of cp ;
- cp := cp cutafter point .95 length cp of cp ;
- draw cp withcolor chart_background_color ;
- fi ;
- fi ;
- pickup pencircle scaled cline[i] ;
- if carrow[i] :
- if cdash[i] :
- drawarrow cpaths[i] withcolor ccolor[i] dashed dash_pattern ;
- else :
- drawarrow cpaths[i] withcolor ccolor[i] ;
- fi ;
- else :
- if cdash[i] :
- draw cpaths[i] withcolor ccolor[i] dashed dash_pattern ;
- else :
- draw cpaths[i] withcolor ccolor[i] ;
- fi ;
- fi ;
- draw_midpoint (i) ;
- endfor ;
-enddef ;
-
-def draw_midpoint (expr n) =
- begingroup
- save p ;
- pair p ;
- p := point .5*length(cpaths[n]) of cpaths[n];
- pickup pencircle scaled 2cline[n] ;
- save_text_position (p) ;
- if show_mid_points :
- drawdot p withcolor .7white ;
- fi ;
- endgroup ;
-enddef ;
-
-def flush_picture(expr x, y) =
- if known xypicture[x][y]:
- draw xypicture[x][y] shifted xy_offset((x+0.5)*grid_width,(max_y-y+1.5)*grid_height) ;
- fi ;
-enddef ;
-
-def chart_draw_picture(expr x, y, p) =
- xypicture[x][y] := p ;
-enddef ;
-
-boolean reverse_connection ; reverse_connection := false ;
-
-vardef up_on_grid (expr n) =
- (xpart xypoints[n],(ypart xypoints[n]+1) div 1)
-enddef ;
-
-vardef down_on_grid (expr n) =
- (xpart xypoints[n],(ypart xypoints[n]) div 1)
-enddef ;
-
-vardef left_on_grid (expr n) =
- ((xpart xypoints[n]) div 1, ypart xypoints[n])
-enddef ;
-
-vardef right_on_grid (expr n) =
- ((xpart xypoints[n]+1) div 1, ypart xypoints[n])
-enddef ;
-
-vardef x_on_grid (expr n, xfrom, xto, zfrom) =
- if (xfrom=xto) and not (zfrom=0) :
- if (zfrom=1) : right_on_grid(2) else : left_on_grid(2) fi
- elseif xpart xypoints[1] < xpart xypoints[6] :
- right_on_grid(n)
- else :
- left_on_grid(n)
- fi
-enddef ;
-
-vardef y_on_grid (expr n, yfrom, yto, zfrom) =
- if (yfrom=yto) and not (zfrom=0) :
- if (zfrom=1) : up_on_grid(2) else : down_on_grid(2) fi
- elseif ypart xypoints[1] < ypart xypoints[6] :
- up_on_grid(n)
- else :
- down_on_grid(n)
- fi
-enddef ;
-
-vardef xy_on_grid (expr n, m) =
- (xpart xypoints[n], ypart xypoints[m])
-enddef ;
-
-vardef down_to_grid (expr a,b) =
- (xpart xypoints[a],
- ypart xypoints[if ypart xypoints[a]<ypart xypoints[b]:a else:b fi])
-enddef ;
-
-vardef up_to_grid (expr a,b) =
- (xpart xypoints[a],
- ypart xypoints[if ypart xypoints[a]>ypart xypoints[b]:a else:b fi])
-enddef ;
-
-vardef left_to_grid (expr a,b) =
- (xpart xypoints[if xpart xypoints[a]<xpart xypoints[b]:a else:b fi],
- ypart xypoints[a])
-enddef ;
-
-vardef right_to_grid (expr a,b) =
- (xpart xypoints[if xpart xypoints[a]>xpart xypoints[b]:a else:b fi],
- ypart xypoints[a])
-enddef ;
-
-% vardef boundingboxfraction(expr p, f) =
-% ((boundingbox p) enlarged (-f*bbwidth(p),-f*bbheight(p)))
-% enddef ;
-
-vardef valid_connection (expr xfrom, yfrom, xto, yto) =
- begingroup ;
- save ok, vc, pp ;
- boolean ok ;
- % check for slanted lines
- ok := true ;
- for i=1 upto xypoint-1 :
- if not ((xpart xypoints[i]=xpart xypoints[i+1]) or
- (ypart xypoints[i]=ypart xypoints[i+1])) : ok := false ;
- fi ;
- endfor ;
- if not ok :
- %message("slanted");
- false
- elseif forcevalid :
- %message("force");
- true
- elseif (xfrom=xto) and (yfrom=yto) :
- %message("self");
- false
- else :
- % check for crossing shapes
- pair vc ;
- path pp ;
-
- pair xyfirst, xylast ;
- xyfirst := xypoints[1] ;
- xylast := xypoints[xypoint] ;
- trim_points ;
- pp := for i=1 upto xypoint-1 : xypoints[i]-- endfor xypoints[xypoint] ;
- xypoints[1] := xyfirst ;
- xypoints[xypoint] := xylast ;
-
- for i=1 upto max_x :
- for j=1 upto max_y : % was bug: xfrom,yto
- if not ( ( (i,j)=(xfrom,yfrom) ) or ( (i,j)=(xto,yto) ) ) :
- if not xyfree[i][j] :
- vc := pp intersection_point xypath[i][j] ;
- if intersection_found : ok := false fi ;
- fi ;
- fi ;
- endfor ;
- endfor ;
- %if not ok: message("crossing") ; fi ;
- ok
- fi
- endgroup
-enddef ;
-
-def connect_top_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_top(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_bottom(xto,yto,zto,true) ;
- xypoints[2] := up_on_grid(1) ;
- xypoints[5] := down_on_grid(6) ;
- xypoints[3] := up_to_grid(2,5) ;
- xypoints[4] := up_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ;
- xypoints[4] := xy_on_grid(3,5) ;
- fi ;
- %%%% begin experiment
- xypoints[3] := xypoints[3] shifted (dsp_x,0) ;
- xypoints[4] := xypoints[4] shifted (dsp_x,0) ;
- if dsp_y>0 :
- xypoints[2] := xypoints[2] shifted (0,dsp_y) ;
- xypoints[3] := xypoints[3] shifted (0,dsp_y) ;
- elseif dsp_y<0 :
- xypoints[4] := xypoints[4] shifted (0,dsp_y) ;
- xypoints[5] := xypoints[5] shifted (0,dsp_y) ;
- fi
- %%%% end experiment
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_left_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_right(xto,yto,zto,true) ;
- xypoints[2] := left_on_grid(1) ;
- xypoints[5] := right_on_grid(6) ;
- xypoints[3] := left_to_grid(2,5) ;
- xypoints[4] := left_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ;
- xypoints[4] := xy_on_grid(5,3) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_left_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,5) :
- xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ;
- xypoints[5] := xy_top(xto,yto,zto,true) ;
- xypoints[2] := left_on_grid(1) ;
- xypoints[4] := up_on_grid(5) ;
- xypoints[3] := left_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := xy_on_grid(2,4) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_left_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,5) :
- xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ;
- xypoints[5] := xy_bottom(xto,yto,zto,true) ;
- xypoints[2] := left_on_grid(1) ;
- xypoints[4] := down_on_grid(5) ;
- xypoints[3] := left_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := xy_on_grid(2,4) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_right_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,5) :
- xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ;
- xypoints[5] := xy_top(xto,yto,zto,true) ;
- xypoints[2] := right_on_grid(1) ;
- xypoints[4] := up_on_grid(5) ;
- xypoints[3] := right_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := xy_on_grid(2,4) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_right_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,5) :
- xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ;
- xypoints[5] := xy_bottom(xto,yto,zto,true) ;
- xypoints[2] := right_on_grid(1) ;
- xypoints[4] := down_on_grid(5) ;
- xypoints[3] := right_to_grid(2,5) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := xy_on_grid(2,4) ;
- fi ;
- %%%% begin experiment
- xypoints[2] := xypoints[2] shifted (dsp_x,0) ;
- xypoints[3] := xypoints[3] shifted (dsp_x,0) ;
- if dsp_y>0 :
- xypoints[3] := xypoints[3] shifted (0,-dsp_y) ;
- xypoints[4] := xypoints[4] shifted (0,-dsp_y) ;
- elseif dsp_y<0 :
- xypoints[3] := xypoints[3] shifted (0,dsp_y) ;
- xypoints[4] := xypoints[4] shifted (0,dsp_y) ;
- fi
- %%%% end experiment
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_left_left (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_left(xto,yto,zto,true) ;
- xypoints[2] := left_on_grid(1) ;
- xypoints[5] := left_on_grid(6) ;
- xypoints[3] := left_to_grid(2,5) ;
- xypoints[4] := left_to_grid(5,2) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ;
- xypoints[4] := xy_on_grid(5,3) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_right_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_right(xto,yto,zto,true) ;
- xypoints[2] := right_on_grid(1) ;
- xypoints[5] := right_on_grid(6) ;
- xypoints[3] := right_to_grid(2,5) ;
- xypoints[4] := right_to_grid(5,2) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ;
- xypoints[4] := xy_on_grid(5,3) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_top_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_top(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_top(xto,yto,zto,true) ;
- xypoints[2] := up_on_grid(1) ;
- xypoints[5] := up_on_grid(6) ;
- xypoints[3] := up_to_grid(2,5) ;
- xypoints[4] := up_to_grid(5,2) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ;
- xypoints[4] := xy_on_grid(3,5) ;
- fi ;
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_bottom_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ;
- if points_initialized(xfrom,yfrom,xto,yto,6) :
- xypoints[1] := xy_bottom(xfrom,yfrom,zfrom,true) ;
- xypoints[6] := xy_bottom(xto,yto,zto,true) ;
- xypoints[2] := down_on_grid(1) ;
- xypoints[5] := down_on_grid(6) ;
- xypoints[3] := down_to_grid(2,5) ;
- xypoints[4] := down_to_grid(5,2) ;
- if not valid_connection(xfrom,yfrom,xto,yto) :
- xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ;
- xypoints[4] := xy_on_grid(3,5) ;
- fi ;
- %%%% begin experiment
- xypoints[3] := xypoints[3] shifted (dsp_x,0) ;
- xypoints[4] := xypoints[4] shifted (dsp_x,0) ;
- if dsp_y<0 :
- xypoints[2] := xypoints[2] shifted (0,-dsp_y) ;
- xypoints[3] := xypoints[3] shifted (0,-dsp_y) ;
- elseif dsp_y>0 :
- xypoints[4] := xypoints[4] shifted (0,dsp_y) ;
- xypoints[5] := xypoints[5] shifted (0,dsp_y) ;
- fi
- %%%% end experiment
- draw_connection ;
- fi ;
-enddef ;
-
-def connect_bottom_top (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_top_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def connect_right_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_left_right (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def connect_top_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_left_top (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def connect_bottom_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_left_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def connect_top_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_right_top (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def connect_bottom_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- reverse_connection := true ;
- connect_right_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def draw_test_shape (expr x, y) =
- draw_shape(x,y,fullcircle, .7, .7) ;
-enddef ;
-
-def draw_test_shapes =
- for i=1 upto max_x :
- for j=1 upto max_y :
- draw_test_shape(i,j) ;
- endfor ;
- endfor ;
-enddef;
-
-def draw_test_area =
- pickup pencircle scaled .5shape_line_width ;
- draw (unitsquare xscaled max_x yscaled max_y shifted (1,1))
- scaled_to_grid withcolor blue ;
-enddef ;
-
-def show_connection (expr n, m) =
-
- begin_chart(100+n,6,6) ;
-
- draw_test_area ;
-
- smooth := true ;
- arrowtip := true ;
- dashline := true ;
-
- draw_test_shape(2,2) ; draw_test_shape(4,5) ;
- draw_test_shape(3,3) ; draw_test_shape(5,1) ;
- draw_test_shape(2,5) ; draw_test_shape(1,3) ;
- draw_test_shape(6,2) ; draw_test_shape(4,6) ;
-
- if (m=1) :
- connect_top_bottom (2,2,0) (4,5,0) ;
- connect_top_bottom (3,3,0) (5,1,0) ;
- connect_top_bottom (2,5,0) (1,3,0) ;
- connect_top_bottom (6,2,0) (4,6,0) ;
- elseif (m=2) :
- connect_top_top (2,2,0) (4,5,0) ;
- connect_top_top (3,3,0) (5,1,0) ;
- connect_top_top (2,5,0) (1,3,0) ;
- connect_top_top (6,2,0) (4,6,0) ;
- elseif (m=3) :
- connect_bottom_bottom (2,2,0) (4,5,0) ;
- connect_bottom_bottom (3,3,0) (5,1,0) ;
- connect_bottom_bottom (2,5,0) (1,3,0) ;
- connect_bottom_bottom (6,2,0) (4,6,0) ;
- elseif (m=4) :
- connect_left_right (2,2,0) (4,5,0) ;
- connect_left_right (3,3,0) (5,1,0) ;
- connect_left_right (2,5,0) (1,3,0) ;
- connect_left_right (6,2,0) (4,6,0) ;
- elseif (m=5) :
- connect_left_left (2,2,0) (4,5,0) ;
- connect_left_left (3,3,0) (5,1,0) ;
- connect_left_left (2,5,0) (1,3,0) ;
- connect_left_left (6,2,0) (4,6,0) ;
- elseif (m=6) :
- connect_right_right (2,2,0) (4,5,0) ;
- connect_right_right (3,3,0) (5,1,0) ;
- connect_right_right (2,5,0) (1,3,0) ;
- connect_right_right (6,2,0) (4,6,0) ;
- elseif (m=7) :
- connect_left_top (2,2,0) (4,5,0) ;
- connect_left_top (3,3,0) (5,1,0) ;
- connect_left_top (2,5,0) (1,3,0) ;
- connect_left_top (6,2,0) (4,6,0) ;
- elseif (m=8) :
- connect_left_bottom (2,2,0) (4,5,0) ;
- connect_left_bottom (3,3,0) (5,1,0) ;
- connect_left_bottom (2,5,0) (1,3,0) ;
- connect_left_bottom (6,2,0) (4,6,0) ;
- elseif (m=9) :
- connect_right_top (2,2,0) (4,5,0) ;
- connect_right_top (3,3,0) (5,1,0) ;
- connect_right_top (2,5,0) (1,3,0) ;
- connect_right_top (6,2,0) (4,6,0) ;
- else :
- connect_right_bottom (2,2,0) (4,5,0) ;
- connect_right_bottom (3,3,0) (5,1,0) ;
- connect_right_bottom (2,5,0) (1,3,0) ;
- connect_right_bottom (6,2,0) (4,6,0) ;
- fi ;
-
- end_chart ;
-
-enddef ;
-
-def show_connections =
- for f=1 upto 10 :
- show_connection(f,f) ;
- endfor ;
-enddef ;
-
-%D charts
-
-def clip_chart (expr minx, miny, maxx, maxy) =
- cmin_x := minx ;
- cmax_x := maxx ;
- cmin_y := miny ;
- cmax_y := maxy ;
-enddef ;
-
-def begin_chart (expr n, maxx, maxy) =
- new_chart ;
- chart_figure := n ;
- chart_scale := 1 ;
- if chart_figure>0: beginfig(chart_figure) ; fi ;
- startsavingdata ;
- initialize_grid (maxx, maxy) ;
- bboxmargin := 0 ;
- cmin_x := 1 ;
- cmax_x := maxx ;
- cmin_y := 1 ;
- cmax_y := maxy ;
-enddef ;
-
-def end_chart =
- flush_shapes ;
- flush_connections ;
- flush_pictures ;
- cmin_x := cmin_x ;
- cmax_x := cmin_x+cmax_x ;
- cmin_y := cmin_y-1 ;
- cmax_y := cmin_y+cmax_y ;
- if reverse_y :
- cmin_y := y_pos(cmin_y) ;
- cmax_y := y_pos(cmax_y) ;
- fi ;
- path p ;
- p := (((cmin_x,cmin_y)--(cmax_x,cmin_y)--
- (cmax_x,cmax_y)--(cmin_x,cmax_y)--cycle))
- scaled_to_grid ;
- %draw p withcolor red ;
- p := p enlarged chart_offset ;
- clip currentpicture to p ;
- setbounds currentpicture to p ;
- savedata
- "\MPclippath{" &
- decimal xpart llcorner p & "}{" &
- decimal ypart llcorner p & "}{" &
- decimal xpart urcorner p & "}{" &
- decimal ypart urcorner p & "}%" ;
- savedata
- "\MPareapath{" &
- decimal (xpart llcorner p + 2chart_offset) & "}{" &
- decimal (ypart llcorner p + 2chart_offset) & "}{" &
- decimal (xpart urcorner p - 2chart_offset) & "}{" &
- decimal (ypart urcorner p - 2chart_offset) & "}%" ;
- currentpicture := currentpicture scaled chart_scale ;
- stopsavingdata ;
- if chart_figure>0: endfig ; fi ;
-enddef ;
-
-def new_shape (expr x, y, n) =
- if known n :
- if (x>0) and (x<=max_x) and (y>0) and (y<=max_y) :
- sx := shape_width/grid_width ;
- sy := shape_height/grid_height ;
- draw_shape(x,y,some_shape_path(n), sx, sy) ;
- else :
- message ("shape outside grid ignored") ;
- fi ;
- else
- message ("shape not known" ) ;
- fi ;
-enddef ;
-
-def begin_sub_chart =
- begingroup ;
- save shape_line_width , connection_line_width ;
- save shape_line_color, shape_fill_color, connection_line_color ;
- color shape_line_color, shape_fill_color, connection_line_color ;
- save smooth, arrowtip, dashline, peepshape ;
- boolean smooth, arrowtip, dashline, peepshape ;
-enddef ;
-
-def end_sub_chart =
- endgroup ;
-enddef ;
-
-%D done
-
-endinput ;
-
-%D testing
-
-show_shapes(100) ;
-
-end
-
-%D more testing
-
-show_connections ;
-
-begin_chart (1,4,5) ;
- %clip_chart(1,1,1,2) ;
- new_shape (1,1,31) ;
- new_shape (1,2,3) ;
- new_shape (4,4,5) ;
- connect_top_left (1,1,0) (4,4,0) ;
- connect_bottom_top (1,2,0) (4,4,0) ;
- connect_left_right (1,2,0) (1,1,0) ;
-end_chart ;
-
-end
diff --git a/metapost/context/base/mp-flow.mpiv b/metapost/context/base/mp-flow.mpiv
deleted file mode 100644
index 4cf4af0f9..000000000
--- a/metapost/context/base/mp-flow.mpiv
+++ /dev/null
@@ -1,1020 +0,0 @@
-%D \module
-%D [ file=mp-char.mp,
-%D version=2011.10.1, % 1998.10.10,
-%D title=\CONTEXT\ \METAPOST\ graphics,
-%D subtitle=charts,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
-%C details.
-
-%D This is ancient code .. but I see no need to rewrite it.
-
-if unknown context_tool : input mp-tool ; fi ;
-if unknown context_shap : input mp-shap ; fi ;
-if known context_flow : endinput ; fi ;
-
-boolean context_flow ; context_flow := true ;
-
-%D settings
-
-numeric flow_grid_width ; flow_grid_width := 60pt ;
-numeric flow_shape_width ; flow_shape_width := 45pt ;
-numeric flow_grid_height ; flow_grid_height := 40pt ;
-numeric flow_shape_height ; flow_shape_height := 30pt ;
-numeric flow_chart_offset ; flow_chart_offset := 2pt ;
-color flow_chart_background_color ; flow_chart_background_color := white ;
-boolean flow_show_mid_points ; flow_show_mid_points := false ;
-boolean flow_show_con_points ; flow_show_con_points := false ;
-boolean flow_show_all_points ; flow_show_all_points := false ;
-numeric flow_shape_line_width ; flow_shape_line_width := 2pt ;
-color flow_shape_line_color ; flow_shape_line_color := .5white ;
-color flow_shape_fill_color ; flow_shape_fill_color := .9white ;
-color flow_connection_line_color ; flow_connection_line_color := .2white ;
-
-numeric flow_connection_line_width ; flow_connection_line_width := flow_shape_line_width ;
-
-numeric flow_connection_smooth_size ; flow_connection_smooth_size := 5pt ;
-numeric flow_connection_arrow_size ; flow_connection_arrow_size := 4pt ;
-numeric flow_connection_dash_size ; flow_connection_dash_size := 3pt ;
-
-numeric flow_max_x ; flow_max_x := 6 ;
-numeric flow_max_y ; flow_max_y := 4 ;
-
-boolean flow_smooth ; flow_smooth := true ;
-boolean flow_peepshape ; flow_peepshape := false ;
-boolean flow_arrowtip ; flow_arrowtip := true ;
-boolean flow_dashline ; flow_dashline := false ;
-boolean flow_forcevalid ; flow_forcevalid := false ;
-boolean flow_touchshape ; flow_touchshape := false ;
-boolean flow_showcrossing ; flow_showcrossing := false ;
-boolean flow_reverse_y ; flow_reverse_y := true ;
-
-picture flow_dash_pattern ; flow_dash_pattern := nullpicture ;
-
-numeric flow_shape_node ; flow_shape_node := 0 ;
-numeric flow_shape_action ; flow_shape_action := 24 ;
-numeric flow_shape_procedure ; flow_shape_procedure := 5 ;
-numeric flow_shape_product ; flow_shape_product := 12 ;
-numeric flow_shape_decision ; flow_shape_decision := 14 ;
-numeric flow_shape_archive ; flow_shape_archive := 19 ;
-numeric flow_shape_loop ; flow_shape_loop := 35 ;
-numeric flow_shape_wait ; flow_shape_wait := 6 ;
-numeric flow_shape_subprocedure ; flow_shape_subprocedure := 20 ;
-numeric flow_shape_singledocument ; flow_shape_singledocument := 32 ;
-numeric flow_shape_multidocument ; flow_shape_multidocument := 33 ;
-numeric flow_shape_right ; flow_shape_right := 66 ;
-numeric flow_shape_left ; flow_shape_left := 67 ;
-numeric flow_shape_up ; flow_shape_up := 68 ;
-numeric flow_shape_down ; flow_shape_down := 69 ;
-
-% vardef some_shape_path (expr type) == imported from mp-shap
-
-def flow_show_shapes(expr n) =
- flow_begin_chart(n,8,10) ;
- flow_show_con_points := true ;
- for i=0 upto 7 :
- for j=0 upto 9 :
- flow_new_shape(i+1,j+1,i*10+j);
- endfor ;
- endfor ;
- flow_end_chart ;
-enddef ;
-
-%D connections
-
-def flow_new_chart =
-
- flow_grid_width := 60pt ;
- flow_shape_width := 45pt ;
- flow_grid_height := 40pt ;
- flow_shape_height := 30pt ;
- flow_chart_offset := 2pt ;
- flow_chart_background_color := white ;
- flow_show_mid_points := false ;
- flow_show_con_points := false ;
- flow_show_all_points := false ;
- flow_shape_line_width := 2pt ;
- flow_shape_line_color := .5white ;
- flow_shape_fill_color := .9white ;
- flow_connection_line_color := .2white ;
- flow_connection_line_width := flow_shape_line_width ;
- flow_connection_smooth_size := 5pt ;
- flow_connection_arrow_size := 4pt ;
- flow_connection_dash_size := 3pt ;
-
- flow_max_x := 6 ;
- flow_max_y := 4 ;
-
- flow_smooth := true ;
- flow_peepshape := false ;
- flow_arrowtip := true ;
- flow_dashline := false ;
- flow_forcevalid := false ;
- flow_touchshape := false ;
- flow_showcrossing := false ;
- flow_reverse_y := true ;
-
- flow_dash_pattern := nullpicture ;
-
- numeric flow_xypoint ; flow_xypoint := 0 ;
- numeric flow_cpath ; flow_cpath := 0 ;
-
- pair flow_xypoints [] ;
- boolean flow_xyfree [][] ;
- path flow_xypath [][] ;
- numeric flow_xysx [][] ;
- numeric flow_xysy [][] ;
- color flow_xyfill [][] ;
- color flow_xydraw [][] ;
- numeric flow_xyline [][] ;
- boolean flow_xypeep [][] ;
- picture flow_xytext [][] ;
- picture flow_xylabel_l[][] ;
- picture flow_xylabel_r[][] ;
- picture flow_xylabel_t[][] ;
- picture flow_xylabel_b[][] ;
- picture flow_xyexit_l [][] ;
- picture flow_xyexit_r [][] ;
- picture flow_xyexit_t [][] ;
- picture flow_xyexit_b [][] ;
- path flow_cpaths [] ;
- numeric flow_cline [] ;
- color flow_ccolor [] ;
- boolean flow_carrow [] ;
- boolean flow_cdash [] ;
- boolean flow_ccross [] ;
-
- picture flow_tpicture[][] ;
- picture flow_bpicture[][] ;
- picture flow_lpicture[][] ;
- picture flow_rpicture[][] ;
-
- predefined_shapes[61] := (fullcircle scaled (1.5*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ;
- predefined_shapes[62] := (fullcircle scaled (2.0*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ;
-
-enddef ;
-
-flow_new_chart ;
-
-def flow_y_pos(expr y) =
- if flow_reverse_y :
- flow_max_y + 1 - y
- else :
- y
- fi
-enddef ;
-
-def flow_initialize_grid(expr maxx, maxy) =
- flow_max_x := maxx ;
- flow_max_y := maxy ;
- flow_dsp_x := 0 ;
- flow_dsp_y := 0 ;
- for x=1 upto flow_max_x :
- for y=1 upto flow_max_y :
- flow_xyfree[x][y] := true ;
- flow_xyfill[x][y] := flow_shape_fill_color ;
- flow_xydraw[x][y] := flow_shape_line_color ;
- flow_xyline[x][y] := flow_shape_line_width ;
- endfor ;
- endfor ;
-enddef ;
-
-def flow_scaled_to_grid =
- xscaled flow_grid_width yscaled flow_grid_height
-enddef ;
-
-def flow_xy_offset(expr x, y) =
- (x+.5,y+.5)
-enddef ;
-
-def flow_draw_shape(expr x, yy, p, sx, sy) =
- begingroup ;
- save y ; numeric y ;
- y := flow_y_pos(yy) ;
- flow_xypath [x][y] := (p xscaled sx yscaled sy) shifted flow_xy_offset(x,y) ;
- flow_xyfree [x][y] := false ;
- flow_xysx [x][y] := sx ;
- flow_xysy [x][y] := sy ;
- flow_xyfill [x][y] := flow_shape_fill_color ;
- flow_xydraw [x][y] := flow_shape_line_color ;
- flow_xyline [x][y] := flow_shape_line_width ;
- flow_xypeep [x][y] := flow_peepshape ;
- endgroup ;
-enddef ;
-
-vardef flow_i_point (expr x, y, p, t) =
- begingroup ;
- save q, ok ; pair q ; boolean ok ;
- q := flow_xypath[x][y] intersection_point ((p) shifted flow_xy_offset(x,y)) ;
- ok := true ;
- if not ok :
- message (t & " of shape (" & decimal x & "," & decimal y & ") limited") ;
- fi ;
- q
- endgroup
-enddef ;
-
-vardef flow_trimmed (expr x, y, z, t) =
- if flow_touchshape and t :
- flow_xyline[x][y]/z
- else :
- epsilon
- fi
-enddef ;
-
-numeric flow_zfactor ; flow_zfactor := 1/3 ;
-
-vardef flow_xy_bottom (expr x, y, z, t) =
- flow_i_point(x, y, ((0,0)--(0,-2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "bottom")
- shifted(0,-flow_trimmed(x,y,flow_grid_height,t))
-enddef ;
-
-vardef flow_xy_top (expr x, y, z, t) =
- flow_i_point (x, y, ((0,0)--(0,2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "top")
- shifted(0,flow_trimmed(x,y,flow_grid_height,t))
-enddef ;
-
-vardef flow_xy_left (expr x, y, z, t) =
- flow_i_point (x, y, ((0,0)--(-2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "left")
- shifted(-flow_trimmed(x,y,flow_grid_width,t),0)
-enddef ;
-
-vardef flow_xy_right (expr x, y, z, t) =
- flow_i_point (x, y, ((0,0)--(2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "right")
- shifted(flow_trimmed(x,y,flow_grid_width,t),0)
-enddef ;
-
-def flow_flush_shapes =
- for x=1 upto flow_max_x :
- for y=1 upto flow_max_y :
- flow_flush_shape(x, y) ;
- endfor ;
- endfor ;
-enddef ;
-
-def flow_flush_pictures =
- for x=1 upto flow_max_x :
- for y=1 upto flow_max_y :
- flow_flush_picture(x, y) ;
- endfor ;
- endfor ;
-enddef ;
-
-def flow_draw_connection_point(expr x, y, z) =
- pickup pencircle scaled if (z=0): 2 fi flow_xyline[x][y] ;
- drawdot flow_xy_bottom(x,y,z,false) flow_scaled_to_grid withcolor (1,0,0) ;
- drawdot flow_xy_top (x,y,z,false) flow_scaled_to_grid withcolor (0,1,0) ;
- drawdot flow_xy_left (x,y,z,false) flow_scaled_to_grid withcolor (0,0,1) ;
- drawdot flow_xy_right (x,y,z,false) flow_scaled_to_grid withcolor (1,1,0) ;
-enddef ;
-
-def flow_flush_shape(expr x, yy) =
- begingroup ;
- save y ; numeric y ;
- y := flow_y_pos(yy) ;
- if not flow_xyfree[x][y] :
- pickup pencircle scaled flow_xyline[x][y] ;
- if flow_xypeep[x][y] :
- fill (flow_xypath[x][y] peepholed (unitsquare shifted (x,y)))
- flow_scaled_to_grid withpen pencircle scaled 0
- withcolor flow_chart_background_color ;
- else :
- fill flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xyfill[x][y] ;
- fi ;
- draw flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xydraw[x][y] ;
- if flow_show_con_points or flow_show_all_points :
- flow_draw_connection_point(x, y, 0) ;
- fi ;
- if flow_show_all_points :
- for i=-1 upto 1 :
- flow_draw_connection_point(x, y, i) ;
- endfor ;
- fi ;
- fi ;
- endgroup ;
-enddef ;
-
-vardef flow_points_initialized(expr xfrom, yfrom, xto, yto, n) =
- if not flow_xyfree[xfrom][yfrom] and not flow_xyfree[xto][yto] :
- flow_xypoint := n ; true
- else :
- flow_xypoint := 0 ; false
- fi
-enddef ;
-
-def flow_collapse_points = % this is now an mp-tool macro
- begingroup ;
- % remove redundant points
- save n ; numeric n ;
- n := 1 ;
- for i=2 upto flow_xypoint :
- if not (flow_xypoints[i] = flow_xypoints[n]) :
- n := n + 1 ;
- flow_xypoints[n] := flow_xypoints[i]
- fi ;
- endfor ;
- flow_xypoint := n ;
- % make straight lines
- if flow_xypoints[2] = flow_xypoints[flow_xypoint-1] :
- flow_xypoints[3] := flow_xypoints[flow_xypoint] ;
- flow_xypoint := 3 ;
- fi ;
- endgroup ;
-enddef ;
-
-vardef flow_smooth_connection(expr a,b) =
- if ypart a = ypart b :
- a shifted ( if xpart a >= xpart b : - fi (flow_connection_smooth_size/flow_grid_width ),0)
- else :
- a shifted (0,if ypart a >= ypart b : - fi (flow_connection_smooth_size/flow_grid_height) )
- fi
-enddef ;
-
-vardef flow_trim_points =
- begingroup
- save p, a, b, d, i ; numeric a, b ; path p ; pair d ;
- p := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ;
- if flow_touchshape :
- a := flow_shape_line_width/flow_grid_width ;
- b := flow_shape_line_width/flow_grid_height ;
- else :
- a := epsilon ;
- b := epsilon ;
- fi ;
- d := direction infinity of p ;
- flow_xypoints[flow_xypoint] := flow_xypoints[flow_xypoint] shifted
- if xpart d < 0 : (+a,0) ;
- elseif xpart d > 0 : (-a,0) ;
- elseif ypart d < 0 : (0,+b) ;
- elseif ypart d > 0 : (0,-b) ;
- else : origin ;
- fi ;
- d := direction 0 of p ;
- flow_xypoints[1] := flow_xypoints[1] shifted
- if xpart d < 0 : (-a,0) ;
- elseif xpart d > 0 : (+a,0) ;
- elseif ypart d < 0 : (0,-b) ;
- elseif ypart d > 0 : (0,+b) ;
- else : origin ;
- fi ;
- endgroup
-enddef ;
-
-vardef flow_trim_points = enddef ;
-
-vardef flow_connection_path =
- if flow_reverse_connection : reverse fi (flow_xypoints[1] --
- for i=2 upto flow_xypoint-1 :
- if flow_smooth :
- flow_smooth_connection(flow_xypoints[i],flow_xypoints[i-1]) ..
- controls flow_xypoints[i] and flow_xypoints[i] ..
- flow_smooth_connection(flow_xypoints[i],flow_xypoints[i+1]) --
- else :
- flow_xypoints[i] --
- fi
- endfor
- flow_xypoints[flow_xypoint])
-enddef ;
-
-def flow_draw_connection =
- if flow_xypoint > 0 :
- flow_collapse_points ;
- flow_trim_points ;
- flow_cpath := flow_cpath + 1 ;
- flow_cpaths[flow_cpath] := flow_connection_path flow_scaled_to_grid ;
- flow_cline[flow_cpath] := flow_connection_line_width ;
- flow_ccolor[flow_cpath] := flow_connection_line_color ;
- flow_carrow[flow_cpath] := flow_arrowtip ;
- flow_cdash[flow_cpath] := flow_dashline ;
- flow_ccross[flow_cpath] := flow_showcrossing ;
- else :
- message("no connection defined") ;
- fi ;
- flow_reverse_connection := false ;
-enddef ;
-
-def flow_flush_connections = % protect locals
- begingroup ;
- save ip, crossing, cp ; numeric ip ; boolean crossing ; path cp ;
- ahlength := flow_connection_arrow_size ;
- flow_dash_pattern := dashpattern(on flow_connection_dash_size off flow_connection_dash_size) ;
- for i=1 upto flow_cpath :
- if flow_ccross[i] :
- crossing := false ;
- for j=1 upto i :
- if not (point infinity of flow_cpaths[i] = point infinity of flow_cpaths[j]) :
- ip := flow_cpaths[i] intersection_point flow_cpaths[j] ;
- if intersection_found : crossing := true fi ;
- fi ;
- endfor ;
- if crossing :
- pickup pencircle scaled 2flow_cline[i] ;
- cp := flow_cpaths[i] ;
- cp := cp cutbefore point .05 length cp of cp ;
- cp := cp cutafter point .95 length cp of cp ;
- draw cp withcolor flow_chart_background_color ;
- fi ;
- fi ;
- pickup pencircle scaled flow_cline[i] ;
- if flow_carrow[i] :
- if flow_cdash[i] :
- drawarrow flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ;
- else :
- drawarrow flow_cpaths[i] withcolor flow_ccolor[i] ;
- fi ;
- else :
- if flow_cdash[i] :
- draw flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ;
- else :
- draw flow_cpaths[i] withcolor flow_ccolor[i] ;
- fi ;
- fi ;
- flow_draw_midpoint(i) ;
- endfor ;
- endgroup ;
-enddef ;
-
-def flow_draw_midpoint (expr n) =
- begingroup
- save p ; pair p ;
- p := point .5*length(flow_cpaths[n]) of flow_cpaths[n];
- pickup pencircle scaled 2flow_cline[n] ;
- if flow_show_mid_points :
- drawdot p withcolor .7white ;
- fi ;
- endgroup ;
-enddef ;
-
-def flow_flush_picture(expr x, yy) =
- begingroup ; save y ; numeric y ;
- y := flow_y_pos(yy) ;
- if known flow_xytext[x][y] :
- begingroup ;
- % flow_xypath[x][y]
- save p, offset ; path p ; pair offset ;
- offset := flow_xy_offset((x+0.5)*flow_grid_width,(flow_max_y-y+1.5)*flow_grid_height) ;
- offset := offset shifted (-flow_xyline[x][y]/4,-flow_xyline[x][y]/4) ; % terrible hack (some compensation)
- p := fullsquare
- xscaled flow_grid_width
- yscaled flow_grid_height
- shifted offset ;
- if known flow_xytext[x][y]:
- draw flow_xytext[x][y] shifted offset ;
- fi ;
- if known flow_xylabel_t[x][y] :
- label.urt(flow_xylabel_t[x][y],0.5[ulcorner p,urcorner p]) ;
- fi ;
- if known flow_xylabel_b[x][y] :
- label.lrt(flow_xylabel_b[x][y],0.5[llcorner p,lrcorner p]) ;
- fi ;
- if known flow_xylabel_l[x][y] :
- label.ulft(flow_xylabel_l[x][y],0.5[ulcorner p,llcorner p]) ;
- fi ;
- if known flow_xylabel_r[x][y] :
- label.urt (flow_xylabel_r[x][y],0.5[urcorner p,lrcorner p]) ;
- fi ;
- if known flow_xyexit_t[x][y] :
- label.top(flow_xyexit_t[x][y],0.5[ulcorner p,urcorner p] shifted (0, flow_grid_height/2)) ;
- fi ;
- if known flow_xyexit_b[x][y] :
- label.bot(flow_xyexit_b[x][y],0.5[llcorner p,lrcorner p] shifted (0,-flow_grid_height/2)) ;
- fi ;
- if known flow_xyexit_l[x][y] :
- label.lft(flow_xyexit_l[x][y],0.5[ulcorner p,llcorner p] shifted (-flow_grid_width/2,0)) ;
- fi ;
- if known flow_xyexit_r[x][y] :
- label.rt (flow_xyexit_r[x][y],0.5[urcorner p,lrcorner p] shifted ( flow_grid_width/2,0)) ;
- fi ;
- endgroup ;
- fi ;
- endgroup ;
-enddef ;
-
-def flow_chart_draw_text(expr x, y, p) =
- flow_xytext[x][y] := p ;
-enddef ;
-
-def flow_chart_draw_label_t(expr x, y, p) = flow_xylabel_t[x][y] := p ; enddef ;
-def flow_chart_draw_label_b(expr x, y, p) = flow_xylabel_b[x][y] := p ; enddef ;
-def flow_chart_draw_label_l(expr x, y, p) = flow_xylabel_l[x][y] := p ; enddef ;
-def flow_chart_draw_label_r(expr x, y, p) = flow_xylabel_r[x][y] := p ; enddef ;
-
-def flow_chart_draw_exit_t (expr x, y, p) = flow_xyexit_t [x][y] := p ; enddef ;
-def flow_chart_draw_exit_b (expr x, y, p) = flow_xyexit_b [x][y] := p ; enddef ;
-def flow_chart_draw_exit_l (expr x, y, p) = flow_xyexit_l [x][y] := p ; enddef ;
-def flow_chart_draw_exit_r (expr x, y, p) = flow_xyexit_r [x][y] := p ; enddef ;
-
-boolean flow_reverse_connection ; flow_reverse_connection := false ;
-
-vardef flow_up_on_grid (expr n) =
- (xpart flow_xypoints[n],(ypart flow_xypoints[n]+1) div 1)
-enddef ;
-
-vardef flow_down_on_grid (expr n) =
- (xpart flow_xypoints[n],(ypart flow_xypoints[n]) div 1)
-enddef ;
-
-vardef flow_left_on_grid (expr n) =
- ((xpart flow_xypoints[n]) div 1, ypart flow_xypoints[n])
-enddef ;
-
-vardef flow_right_on_grid (expr n) =
- ((xpart flow_xypoints[n]+1) div 1, ypart flow_xypoints[n])
-enddef ;
-
-vardef flow_x_on_grid (expr n, xfrom, xto, zfrom) =
- if (xfrom = xto) and not (zfrom = 0) :
- if (zfrom=1) : flow_right_on_grid(2) else : flow_left_on_grid(2) fi
- elseif xpart flow_xypoints[1] < xpart flow_xypoints[6] :
- flow_right_on_grid(n)
- else :
- flow_left_on_grid(n)
- fi
-enddef ;
-
-vardef flow_y_on_grid (expr n, yfrom, yto, zfrom) =
- if (yfrom = yto) and not (zfrom = 0) :
- if (zfrom = 1) : flow_up_on_grid(2) else : flow_down_on_grid(2) fi
- elseif ypart flow_xypoints[1] < ypart flow_xypoints[6] :
- flow_up_on_grid(n)
- else :
- flow_down_on_grid(n)
- fi
-enddef ;
-
-vardef flow_xy_on_grid (expr n, m) =
- (xpart flow_xypoints[n], ypart flow_xypoints[m])
-enddef ;
-
-vardef flow_down_to_grid (expr a,b) =
- (xpart flow_xypoints[a], ypart flow_xypoints[if ypart flow_xypoints[a]<ypart flow_xypoints[b] : a else : b fi])
-enddef ;
-
-vardef flow_up_to_grid (expr a,b) =
- (xpart flow_xypoints[a], ypart flow_xypoints[if ypart flow_xypoints[a]>ypart flow_xypoints[b] : a else : b fi])
-enddef ;
-
-vardef flow_left_to_grid (expr a,b) =
- (xpart flow_xypoints[if xpart flow_xypoints[a]<xpart flow_xypoints[b] : a else : b fi], ypart flow_xypoints[a])
-enddef ;
-
-vardef flow_right_to_grid (expr a,b) =
- (xpart flow_xypoints[if xpart flow_xypoints[a]>xpart flow_xypoints[b] : a else : b fi], ypart flow_xypoints[a])
-enddef ;
-
-vardef flow_valid_connection (expr xfrom, yfrom, xto, yto) =
- begingroup ;
- save ok, vc, pp ; boolean ok ; pair vc ; path pp ;
- save flow_xyfirst, flow_xylast ; pair flow_xyfirst, flow_xylast ;
- % check for slanted lines
- ok := true ;
- for i=1 upto flow_xypoint-1 :
- if not ((xpart flow_xypoints[i]=xpart flow_xypoints[i+1]) or (ypart flow_xypoints[i]=ypart flow_xypoints[i+1])) :
- ok := false ;
- fi ;
- endfor ;
- if not ok :
- % message("slanted");
- false
- elseif flow_forcevalid :
- % message("force");
- true
- elseif (xfrom=xto) and (yfrom=yto) :
- % message("self");
- false
- else :
- % check for crossing shapes
- flow_xyfirst := flow_xypoints[1] ;
- flow_xylast := flow_xypoints[flow_xypoint] ;
- flow_trim_points ;
- pp := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ;
- flow_xypoints[1] := flow_xyfirst ;
- flow_xypoints[flow_xypoint] := flow_xylast ;
- for i=1 upto flow_max_x :
- for j=1 upto flow_max_y : % was bug: xfrom,yto
- if not ( ( (i,j)=(xfrom,yfrom) ) or ( (i,j)=(xto,yto) ) ) :
- if not flow_xyfree[i][j] :
- vc := pp intersection_point flow_xypath[i][j] ;
- if intersection_found :
- ok := false
- fi ;
- fi ;
- fi ;
- endfor ;
- endfor ;
- % if not ok: message("crossing") ; fi ;
- ok
- fi
- endgroup
-enddef ;
-
-def flow_connect_top_bottom (expr xfrom, yyfrom, zfrom) (expr xto, yyto, zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_up_on_grid(1) ;
- flow_xypoints[5] := flow_down_on_grid(6) ;
- flow_xypoints[3] := flow_up_to_grid(2,5) ;
- flow_xypoints[4] := flow_up_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(3,5) ;
- fi ;
- %%%% begin experiment
- flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
- flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ;
- if flow_dsp_y>0 :
- flow_xypoints[2] := flow_xypoints[2] shifted (0,flow_dsp_y) ;
- flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ;
- elseif flow_dsp_y<0 :
- flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
- flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ;
- fi
- %%%% end experiment
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_left_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_left_on_grid(1) ;
- flow_xypoints[5] := flow_right_on_grid(6) ;
- flow_xypoints[3] := flow_left_to_grid(2,5) ;
- flow_xypoints[4] := flow_left_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(5,3) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_left_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
- flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_left_on_grid(1) ;
- flow_xypoints[4] := flow_up_on_grid(5) ;
- flow_xypoints[3] := flow_left_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_xy_on_grid(2,4) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_left_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
- flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_left_on_grid(1) ;
- flow_xypoints[4] := flow_down_on_grid(5) ;
- flow_xypoints[3] := flow_left_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_xy_on_grid(2,4) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_right_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
- flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_right_on_grid(1) ;
- flow_xypoints[4] := flow_up_on_grid(5) ;
- flow_xypoints[3] := flow_right_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_xy_on_grid(2,4) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_right_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
- flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_right_on_grid(1) ;
- flow_xypoints[4] := flow_down_on_grid(5) ;
- flow_xypoints[3] := flow_right_to_grid(2,5) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_xy_on_grid(2,4) ;
- fi ;
- %%%% begin experiment
- flow_xypoints[2] := flow_xypoints[2] shifted (flow_dsp_x,0) ;
- flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
- if flow_dsp_y>0 :
- flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ;
- flow_xypoints[4] := flow_xypoints[4] shifted (0,-flow_dsp_y) ;
- elseif flow_dsp_y<0 :
- flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ;
- flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
- fi
- %%%% end experiment
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_left_left (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_left(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_left_on_grid(1) ;
- flow_xypoints[5] := flow_left_on_grid(6) ;
- flow_xypoints[3] := flow_left_to_grid(2,5) ;
- flow_xypoints[4] := flow_left_to_grid(5,2) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(5,3) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_right_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_right_on_grid(1) ;
- flow_xypoints[5] := flow_right_on_grid(6) ;
- flow_xypoints[3] := flow_right_to_grid(2,5) ;
- flow_xypoints[4] := flow_right_to_grid(5,2) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(5,3) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_top_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_top(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_up_on_grid(1) ;
- flow_xypoints[5] := flow_up_on_grid(6) ;
- flow_xypoints[3] := flow_up_to_grid(2,5) ;
- flow_xypoints[4] := flow_up_to_grid(5,2) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(3,5) ;
- fi ;
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_bottom_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
- yfrom := flow_y_pos(yyfrom) ;
- yto := flow_y_pos(yyto) ;
- if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
- flow_xypoints[1] := flow_xy_bottom(xfrom,yfrom,zfrom,true) ;
- flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ;
- flow_xypoints[2] := flow_down_on_grid(1) ;
- flow_xypoints[5] := flow_down_on_grid(6) ;
- flow_xypoints[3] := flow_down_to_grid(2,5) ;
- flow_xypoints[4] := flow_down_to_grid(5,2) ;
- if not flow_valid_connection(xfrom,yfrom,xto,yto) :
- flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
- flow_xypoints[4] := flow_xy_on_grid(3,5) ;
- fi ;
- %%%% begin experiment
- flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
- flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ;
- if flow_dsp_y<0 :
- flow_xypoints[2] := flow_xypoints[2] shifted (0,-flow_dsp_y) ;
- flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ;
- elseif flow_dsp_y>0 :
- flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
- flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ;
- fi
- %%%% end experiment
- flow_draw_connection ;
- fi ;
-enddef ;
-
-def flow_connect_bottom_top (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_top_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_connect_right_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_left_right (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_connect_top_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_left_top(xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_connect_bottom_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_left_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_connect_top_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_right_top (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_connect_bottom_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
- flow_reverse_connection := true ;
- flow_connect_right_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
-enddef ;
-
-def flow_draw_test_shape(expr x, y) =
- flow_draw_shape(x,y,fullcircle, .7, .7) ;
-enddef ;
-
-def flow_draw_test_shapes =
- for i=1 upto flow_max_x :
- for j=1 upto flow_max_y :
- flow_draw_test_shape(i,j) ;
- endfor ;
- endfor ;
-enddef;
-
-def flow_draw_test_area =
- pickup pencircle scaled .5flow_shape_line_width ;
- draw (unitsquare xscaled flow_max_x yscaled flow_max_y shifted (1,1)) flow_scaled_to_grid withcolor blue ;
-enddef ;
-
-def flow_show_connection(expr n, m) =
-
- flow_begin_chart(100+n,6,6) ;
-
- flow_draw_test_area ;
-
- flow_smooth := true ;
- flow_arrowtip := true ;
- flow_dashline := true ;
-
- flow_draw_test_shape(2,2) ; flow_draw_test_shape(4,5) ;
- flow_draw_test_shape(3,3) ; flow_draw_test_shape(5,1) ;
- flow_draw_test_shape(2,5) ; flow_draw_test_shape(1,3) ;
- flow_draw_test_shape(6,2) ; flow_draw_test_shape(4,6) ;
-
- if (m=1) :
- flow_connect_top_bottom (2,2,0) (4,5,0) ;
- flow_connect_top_bottom (3,3,0) (5,1,0) ;
- flow_connect_top_bottom (2,5,0) (1,3,0) ;
- flow_connect_top_bottom (6,2,0) (4,6,0) ;
- elseif (m=2) :
- flow_connect_top_top (2,2,0) (4,5,0) ;
- flow_connect_top_top (3,3,0) (5,1,0) ;
- flow_connect_top_top (2,5,0) (1,3,0) ;
- flow_connect_top_top (6,2,0) (4,6,0) ;
- elseif (m=3) :
- flow_connect_bottom_bottom (2,2,0) (4,5,0) ;
- flow_connect_bottom_bottom (3,3,0) (5,1,0) ;
- flow_connect_bottom_bottom (2,5,0) (1,3,0) ;
- flow_connect_bottom_bottom (6,2,0) (4,6,0) ;
- elseif (m=4) :
- flow_connect_left_right (2,2,0) (4,5,0) ;
- flow_connect_left_right (3,3,0) (5,1,0) ;
- flow_connect_left_right (2,5,0) (1,3,0) ;
- flow_connect_left_right (6,2,0) (4,6,0) ;
- elseif (m=5) :
- flow_connect_left_left (2,2,0) (4,5,0) ;
- flow_connect_left_left (3,3,0) (5,1,0) ;
- flow_connect_left_left (2,5,0) (1,3,0) ;
- flow_connect_left_left (6,2,0) (4,6,0) ;
- elseif (m=6) :
- flow_connect_right_right (2,2,0) (4,5,0) ;
- flow_connect_right_right (3,3,0) (5,1,0) ;
- flow_connect_right_right (2,5,0) (1,3,0) ;
- flow_connect_right_right (6,2,0) (4,6,0) ;
- elseif (m=7) :
- flow_connect_left_top (2,2,0) (4,5,0) ;
- flow_connect_left_top (3,3,0) (5,1,0) ;
- flow_connect_left_top (2,5,0) (1,3,0) ;
- flow_connect_left_top (6,2,0) (4,6,0) ;
- elseif (m=8) :
- flow_connect_left_bottom (2,2,0) (4,5,0) ;
- flow_connect_left_bottom (3,3,0) (5,1,0) ;
- flow_connect_left_bottom (2,5,0) (1,3,0) ;
- flow_connect_left_bottom (6,2,0) (4,6,0) ;
- elseif (m=9) :
- flow_connect_right_top (2,2,0) (4,5,0) ;
- flow_connect_right_top (3,3,0) (5,1,0) ;
- flow_connect_right_top (2,5,0) (1,3,0) ;
- flow_connect_right_top (6,2,0) (4,6,0) ;
- else :
- flow_connect_right_bottom (2,2,0) (4,5,0) ;
- flow_connect_right_bottom (3,3,0) (5,1,0) ;
- flow_connect_right_bottom (2,5,0) (1,3,0) ;
- flow_connect_right_bottom (6,2,0) (4,6,0) ;
- fi ;
-
- flow_end_chart ;
-
-enddef ;
-
-def flow_show_connections =
- for f=1 upto 10 :
- flow_show_connection(f,f) ;
- endfor ;
-enddef ;
-
-%D charts
-
-def flow_clip_chart(expr minx, miny, maxx, maxy) =
- flow_cmin_x := minx ;
- flow_cmax_x := maxx ;
- flow_cmin_y := miny ;
- flow_cmax_y := maxy ;
-enddef ;
-
-def flow_begin_chart(expr n, maxx, maxy) =
- flow_new_chart ;
- flow_chart_figure := n ;
- flow_chart_scale := 1 ;
- if flow_chart_figure>0:
- beginfig(flow_chart_figure) ;
- fi ;
- flow_initialize_grid (maxx, maxy) ;
- bboxmargin := 0 ;
- flow_cmin_x := 1 ;
- flow_cmax_x := maxx ;
- flow_cmin_y := 1 ;
- flow_cmax_y := maxy ;
-enddef ;
-
-def flow_end_chart =
- begingroup ;
- save p ; path p ;
- flow_flush_shapes ;
- flow_flush_connections ;
- flow_flush_pictures ;
- flow_cmin_x := flow_cmin_x ;
- flow_cmax_x := flow_cmin_x+flow_cmax_x ;
- flow_cmin_y := flow_cmin_y-1 ;
- flow_cmax_y := flow_cmin_y+flow_cmax_y ;
- if flow_reverse_y :
- flow_cmin_y := flow_y_pos(flow_cmin_y) ;
- flow_cmax_y := flow_y_pos(flow_cmax_y) ;
- fi ;
- p := (((flow_cmin_x,flow_cmin_y)--(flow_cmax_x,flow_cmin_y)--
- (flow_cmax_x,flow_cmax_y)--(flow_cmin_x,flow_cmax_y)--cycle))
- flow_scaled_to_grid ;
- %draw p withcolor red ;
- p := p enlarged flow_chart_offset ;
- clip currentpicture to p ;
- setbounds currentpicture to p ;
- endgroup ;
- currentpicture := currentpicture scaled flow_chart_scale ;
- if flow_chart_figure>0:
- endfig ;
- fi ;
-enddef ;
-
-def flow_new_shape(expr x, y, n) =
- if known n :
- if (x>0) and (x<=flow_max_x) and (y>0) and (y<=flow_max_y) :
- flow_draw_shape(x,y,some_shape_path(n), flow_shape_width/flow_grid_width, flow_shape_height/flow_grid_height) ;
- else :
- message ("shape outside grid ignored") ;
- fi ;
- else :
- message ("shape not known" ) ;
- fi ;
-enddef ;
-
-def flow_begin_sub_chart =
- begingroup ;
- save flow_shape_line_width, flow_connection_line_width ;
- save flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ;
- color flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ;
- save flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ;
- boolean flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ;
-enddef ;
-
-def flow_end_sub_chart =
- endgroup ;
-enddef ;
-
diff --git a/metapost/context/base/mp-step.mp b/metapost/context/base/mp-step.mpii
index d602f7014..d602f7014 100644
--- a/metapost/context/base/mp-step.mp
+++ b/metapost/context/base/mp-step.mpii
diff --git a/metapost/context/base/mp-step.mpiv b/metapost/context/base/mp-step.mpiv
new file mode 100644
index 000000000..dbbc38231
--- /dev/null
+++ b/metapost/context/base/mp-step.mpiv
@@ -0,0 +1,375 @@
+%D \module
+%D [ file=mp-cell.mpiv, % mp-step.mp,
+%D version=2010.10.07, % 2001.05.22,
+%D title=\CONTEXT\ \METAPOST\ graphics,
+%D subtitle=steps,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C details.
+
+if unknown context_tool : input mp-tool ; fi ;
+if known context_cell : endinput ; fi ;
+
+boolean context_cell ; context_cell := true ;
+
+def initialize_step_variables =
+ save
+ text_fill_color, text_line_color, text_line_width, text_offset,
+ cell_fill_color, cell_line_color, cell_line_width, cell_offset,
+ line_line_color, line_line_width, line_alternative,
+ line_distance, cell_distance_y, cell_distance_x,
+ nofcells, chart_vertical ;
+
+ color text_line_color ; text_line_color := red ;
+ color cell_line_color ; cell_line_color := blue ;
+ color line_line_color ; line_line_color := green ;
+
+ color text_fill_color ; text_fill_color := white ;
+ color cell_fill_color ; cell_fill_color := white ;
+
+ numeric text_line_width ; text_line_width := 2pt ;
+ numeric cell_line_width ; cell_line_width := 2pt ;
+ numeric line_line_width ; line_line_width := 2pt ;
+
+ numeric text_offset ; text_offset := 4pt ;
+ numeric cell_offset ; cell_offset := 4pt ;
+
+ numeric line_distance ; line_distance := 10pt ; % between line and text
+ numeric line_offset ; line_offset := 4pt ; % between center and start of line
+ numeric line_height ; line_height := 20pt ;
+
+ numeric cell_distance_y ; cell_distance_y := 20pt ;
+ numeric cell_distance_x ; cell_distance_x := 20pt ;
+
+ numeric text_distance_set ; text_distance_set := 4pt ;
+
+ boolean chart_vertical ; chart_vertical := false ;
+
+ numeric nofcells ; nofcells := 0 ;
+
+enddef ;
+
+def step_cells (expr t, b) =
+ nofcells := nofcells + 1 ;
+ cells_t[nofcells] := textext.d(t) ;
+ cells_b[nofcells] := textext.d(b) ;
+ texts_t[nofcells] := nullpicture ;
+ texts_m[nofcells] := nullpicture ;
+ texts_b[nofcells] := nullpicture ;
+enddef ;
+
+def step_texts (expr t, b) =
+ texts_t[nofcells] := textext.d(t) ;
+ texts_m[nofcells] := textext.d(m) ;
+ texts_b[nofcells] := textext.d(b) ;
+enddef ;
+
+def step_begin_cell =
+ nofcells := nofcells + 1 ;
+ cells_t[nofcells] := nullpicture ;
+ cells_b[nofcells] := nullpicture ;
+ texts_t[nofcells] := nullpicture ;
+ texts_m[nofcells] := nullpicture ;
+ texts_b[nofcells] := nullpicture ;
+enddef ;
+
+def step_end_cell =
+enddef ;
+
+def step_cell_top (expr t) = cells_t[nofcells] := textext.d(t) ; enddef ;
+def step_cell_bot (expr b) = cells_b[nofcells] := textext.d(b) ; enddef ;
+def step_text_top (expr t) = texts_t[nofcells] := textext.d(t) ; enddef ;
+def step_text_mid (expr m) = texts_m[nofcells] := textext.d(m) ; enddef ;
+def step_text_bot (expr b) = texts_b[nofcells] := textext.d(b) ; enddef ;
+
+def step_begin_chart =
+ begingroup ;
+ initialize_step_variables ;
+ save nofcells ; numeric nofcells ; nofcells := 0 ;
+ save cells_t, cells_m, cells_b ; picture cells_t[], cells_m[], cells_b[] ;
+ save texts_t, texts_m, texts_b ; picture texts_t[], texts_m[], texts_b[] ;
+enddef ;
+
+def step_end_chart =
+ % we could combine some loops but this is cleaner
+ save dx, delta ; numeric dx, delta ;
+ save p ; path p ;
+ save one_row_only ; boolean one_row_only ;
+ save cell_t, next_t, text_t ; picture cell_t, next_t, text_t ;
+ save cell_m, next_m, text_m ; picture cell_m, next_m, text_m ;
+ save cell_b, next_b, text_b ; picture cell_b, next_b, text_b ;
+ save height_t, width_t, max_height_t, max_width_t ; numeric height_t, width_t, max_height_t, max_width_t ;
+ save height_m, width_m, max_height_m, max_width_m ; numeric height_m, width_m, max_height_m, max_width_m ;
+ save height_b, width_b, max_height_b, max_width_b ; numeric height_b, width_b, max_height_b, max_width_b ;
+ % check rows
+ one_row_only := true ;
+ for i=1 upto nofcells :
+ if bbwidth(cells_b[i]) > 0 :
+ one_row_only := false ;
+ fi ;
+ endfor ;
+ % swap and rotate
+ if chart_vertical :
+ if one_row_only :
+ % deal with mid_texts
+ max_width_t := max_width_m := max_width_b := 0 ;
+ for i=1 upto nofcells :
+ width_t := bbwidth(texts_t[i]) ;
+ width_m := bbwidth(texts_m[i]) ;
+ width_b := bbwidth(texts_b[i]) ;
+ if width_t > max_width_t : max_width_t := width_t fi ;
+ if width_m > max_width_m : max_width_m := width_m fi ;
+ if width_b > max_width_b : max_width_b := width_b fi ;
+ endfor ;
+ if max_width_m > 0 :
+ for i=1 upto nofcells :
+ text_t := texts_t[i] ; width_t := bbwidth(text_t) ;
+ text_m := texts_m[i] ; width_m := bbwidth(text_m) ;
+ text_b := texts_b[i] ; width_b := bbwidth(text_b) ;
+ if width_t < max_width_t :
+ setbounds text_t to boundingbox text_t leftenlarged (max_width_t - width_t) ;
+ fi ;
+ if width_m < max_width_m :
+ setbounds text_m to boundingbox text_m leftenlarged ((max_width_m - width_m)/2) ;
+ setbounds text_m to boundingbox text_m rightenlarged ((max_width_m - width_m)/2) ;
+ fi ;
+ if width_b < max_width_b :
+ setbounds text_b to boundingbox text_b rightenlarged (max_width_b - width_b) ;
+ fi ;
+ text_t := text_t shifted (- xpart llcorner text_t, 0) ;
+ text_m := text_m shifted (- xpart llcorner text_m, 0) ;
+ text_b := text_b shifted (- xpart llcorner text_b, 0) ;
+ texts_t[i] := image (
+ draw text_t ;
+ draw text_m shifted (max_width_t + text_distance_set,0) ;
+ draw text_b shifted (max_width_t + max_width_m + 2*text_distance_set,0) ;
+ ) rotated 90 ;
+ texts_m[i] := texts_b[i] := nullpicture ;
+ cells_t[i] := cells_t[i] rotated 90 ;
+ endfor ;
+ else :
+ for i=1 upto nofcells :
+ cells_t[i] := cells_t[i] rotated 90 ;
+ texts_t[i] := texts_t[i] rotated 90 ;
+ texts_b[i] := texts_b[i] rotated 90 ;
+ endfor ;
+ fi ;
+ else :
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ cells_t[i] := cell_b rotated 90 ;
+ cells_b[i] := cell_t rotated 90 ;
+ text_t := texts_t[i] ;
+ text_b := texts_b[i] ;
+ texts_t[i] := text_b rotated 90 ;
+ texts_b[i] := text_t rotated 90 ;
+ endfor ;
+ fi ;
+ fi ;
+ % align horizontal
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ width_t := bbwidth(cell_t) ;
+ width_b := bbwidth(cell_b) ;
+ if (width_t = 0) and (width_b = 0) :
+ % skip
+ elseif (width_t > 0) and (width_t < width_b) :
+ delta := (width_b-width_t)/2 ;
+ setbounds cell_t to boundingbox cell_t leftenlarged delta rightenlarged delta ;
+ cells_t[i] := cell_t ;
+ elseif (width_b > 0) and (width_t > width_b) :
+ delta := (width_t-width_b)/2 ;
+ setbounds cell_b to boundingbox cell_b leftenlarged delta rightenlarged delta ;
+ cells_b[i] := cell_b ;
+ fi ;
+ endfor ;
+ % analyze vertical
+ max_height_t := 0 ;
+ max_height_b := 0 ;
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ height_t := bbheight(cell_t) ;
+ height_b := bbheight(cell_b) ;
+ if height_t > 0 :
+ setbounds cell_t to boundingbox cell_t enlarged cell_offset ;
+ height_t := height_t + 2 * cell_offset ;
+ cells_t[i] := cell_t ;
+ fi ;
+ if height_b > 0 :
+ setbounds cell_b to boundingbox cell_b enlarged cell_offset ;
+ height_b := height_b + 2 * cell_offset ;
+ cells_b[i] := cell_b ;
+ fi ;
+ if height_t > max_height_t :
+ max_height_t := height_t ;
+ fi
+ if height_b > max_height_b :
+ max_height_b := height_b ;
+ fi ;
+ endfor ;
+ % align vertical
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ height_t := bbheight(cell_t) ;
+ height_b := bbheight(cell_b) ;
+ if height_t > 0 :
+ delta := (max_height_t-height_t)/2 ;
+ setbounds cell_t to boundingbox cell_t topenlarged delta bottomenlarged delta ;
+ fi ;
+ if height_b > 0 :
+ delta := (max_height_b-height_b)/2 ;
+ setbounds cell_b to boundingbox cell_b topenlarged delta bottomenlarged delta ;
+ fi ;
+ cells_t[i] := cell_t ;
+ cells_b[i] := cell_b ;
+ endfor ;
+ % position
+ dx := 0 ;
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ cell_t := cell_t shifted -llcorner cell_t ;
+ cell_b := cell_b shifted -llcorner cell_b ;
+ cell_t := cell_t shifted (dx, 0) ;
+ cell_b := cell_b shifted (dx,-cell_distance_y-max_height_b) ;
+ cells_t[i] := cell_t ;
+ cells_b[i] := cell_b ;
+ width_t := bbwidth(cell_t) ;
+ width_b := bbwidth(cell_b) ;
+ if width_t > 0 :
+ dx := dx + cell_distance_x + width_t ;
+ elseif width_b > 0 :
+ dx := dx + cell_distance_x + width_b ;
+ fi ;
+ endfor ;
+ % flush
+ for i=1 upto nofcells :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ width_t := bbwidth(cell_t) ;
+ width_b := bbwidth(cell_b) ;
+ if width_t > 0 :
+ fill boundingbox cell_t withcolor cell_fill_color ;
+ draw boundingbox cell_t withpen pencircle scaled cell_line_width withcolor cell_line_color ;
+ draw cell_t ;
+ fi ;
+ if width_b > 0 :
+ fill boundingbox cell_b withcolor cell_fill_color ;
+ draw boundingbox cell_b withpen pencircle scaled cell_line_width withcolor cell_line_color ;
+ draw cell_b ;
+ fi ;
+ endfor ;
+ %
+ def midtopboundary expr p = 0.5[ulcorner boundingbox p, urcorner boundingbox p] enddef ;
+ def midbottomboundary expr p = 0.5[llcorner boundingbox p, lrcorner boundingbox p] enddef ;
+ % draw top and bottom text boxes
+ for i=1 upto nofcells-1 :
+ text_t := texts_t[i] ;
+ text_b := texts_b[i] ;
+ if bbwidth(text_t) > 0 :
+ setbounds text_t to boundingbox text_t enlarged text_offset ;
+ texts_t[i] := text_t ;
+ fi ;
+ if bbwidth(text_b) > 0 :
+ setbounds text_b to boundingbox text_b enlarged text_offset ;
+ texts_b[i] := text_b ;
+ fi ;
+ endfor ;
+ % arrows
+ for i=1 upto nofcells-1 :
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ next_t := cells_t[i+1] ;
+ next_b := cells_b[i+1] ;
+ pair t_a, t_b, t_c, b_a, b_b, b_c ;
+ t_a := midtopboundary cell_t ;
+ t_b := midtopboundary next_t ;
+ t_c := (xpart 0.5[t_a,t_b], ypart t_a+line_height+line_distance) ;
+ if one_row_only :
+ b_a := midbottomboundary cell_t ;
+ b_b := midbottomboundary next_t ;
+ else :
+ b_a := midbottomboundary cell_b ;
+ b_b := midbottomboundary next_b ;
+ fi ;
+ b_c := (xpart 0.5[b_a,b_b], ypart b_a-line_height-line_distance) ;
+ texts_t[i] := thelabel.top(texts_t[i],t_c) ;
+ texts_b[i] := thelabel.bot(texts_b[i],b_c) ;
+ endfor ;
+ %
+ for i=1 upto nofcells-1 : % todo arrows when empty text
+ cell_t := cells_t[i] ;
+ cell_b := cells_b[i] ;
+ next_t := cells_t[i+1] ;
+ next_b := cells_b[i+1] ;
+ text_t := texts_t[i] ;
+ text_b := texts_b[i] ;
+ if bbwidth(text_t) > 0 :
+ if bbwidth(cell_t) > 0 :
+ drawarrow midtopboundary cell_t
+ shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {up} ..
+ midbottomboundary text_t shifted (0,-line_distance) ..
+ {down} midtopboundary next_t shifted(if i < nofcells - 1 : -line_offset else : 0 fi,cell_line_width)
+ withpen pencircle scaled line_line_width
+ withcolor line_line_color ;
+ else :
+ fi ;
+ fi ;
+ if bbwidth(text_b) > 0 :
+ if one_row_only :
+ cell_b := cell_t ;
+ next_b := next_t ;
+ fi ;
+ if bbwidth(cell_b) > 0 :
+ drawarrow midbottomboundary cell_b
+ shifted (if i > 1 : line_offset else : 0 fi, -cell_line_width) {down} ..
+ midtopboundary text_b shifted (0, line_distance) ..
+ {up} midbottomboundary next_b shifted (if i < nofcells - 1 : -line_offset else : 0 fi,-cell_line_width)
+ withpen pencircle scaled line_line_width
+ withcolor line_line_color ;
+ else :
+ fi ;
+ fi ;
+ endfor ;
+ % draw top and bottom text boxes
+ for i=1 upto nofcells-1 :
+ text_t := texts_t[i] ;
+ text_b := texts_b[i] ;
+ if bbwidth(text_t) > 0 :
+ fill boundingbox text_t withcolor text_fill_color ;
+ draw boundingbox text_t withpen pencircle scaled text_line_width withcolor text_line_color ;
+ draw text_t ;
+ fi ;
+ if bbwidth(text_b) > 0 :
+ fill boundingbox text_b withcolor text_fill_color ;
+ draw boundingbox text_b withpen pencircle scaled text_line_width withcolor text_line_color ;
+ draw text_b ;
+ fi ;
+ endfor ;
+ if chart_vertical :
+ % rotate back
+ currentpicture := currentpicture rotated -90 ;
+ fi ;
+ endgroup ;
+enddef ;
+
+% start_begin_step ;
+% step_cells ("\strut test 0", "\strut test 0") ;
+% step_cells ("\strut test 1", "\vbox{\hsize3cm \strut oeps 1\crlf oeps 1}") ;
+% step_texts ("\strut 1", "\strut 1") ;
+% step_cells ("\strut test 2", "\strut oeps 2 oeps 2") ;
+% step_cells ("\strut test X", "\strut test X") ;
+% step_texts ("\strut 2", "\strut 2") ;
+% step_cells ("\strut test 3", "\strut oeps 3 oeps 3") ;
+% step_texts ("\strut 3", "\strut 3") ;
+% step_cells ("\strut test 4", "\strut oeps 4 oeps 4") ;
+% step_texts ("\strut 4", "\strut 4") ;
+% stop_end_chart ;