1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17if known context_step : endinput ; fi ;
18
19boolean context_step ; context_step := true ;
20
21def initialize_step_variables =
22 save
23 text_fill_color, text_line_color, text_line_width, text_offset,
24 cell_fill_color, cell_line_color, cell_line_width, cell_offset,
25 line_line_color, line_line_width, line_alternative,
26 line_distance, cell_distance_y, cell_distance_x,
27 nofcells, chart_vertical, chart_align, chart_category ;
28
29 string chart_category ; chart_category := "" ;
30
31 string text_line_color ; text_line_color := "red" ;
32 string cell_line_color ; cell_line_color := "blue" ;
33 string line_line_color ; line_line_color := "green" ;
34
35 string text_fill_color ; text_fill_color := "white" ;
36 string cell_fill_color ; cell_fill_color := "white" ;
37
38 numeric text_line_width ; text_line_width := 2pt ;
39 numeric cell_line_width ; cell_line_width := 2pt ;
40 numeric line_line_width ; line_line_width := 2pt ;
41
42 numeric text_offset ; text_offset := 4pt ;
43 numeric cell_offset ; cell_offset := 4pt ;
44
45 numeric line_distance ; line_distance := 10pt ;
46 numeric line_offset ; line_offset := 4pt ;
47 numeric line_height ; line_height := 20pt ;
48
49 numeric cell_distance_y ; cell_distance_y := 20pt ;
50 numeric cell_distance_x ; cell_distance_x := 20pt ;
51
52 numeric text_distance_set ; text_distance_set := 4pt ;
53
54 boolean chart_vertical ; chart_vertical := false ;
55 boolean chart_align ; chart_align := false ;
56
57 numeric nofcells ; nofcells := 0 ;
58
59enddef ;
60
61def step_cells (expr t, b) =
62 nofcells := nofcells 1 ;
63 cells_t[nofcells] := texbox.d(chart_category,t) ;
64 cells_b[nofcells] := texbox.d(chart_category,b) ;
65 texts_t[nofcells] := nullpicture ;
66 texts_m[nofcells] := nullpicture ;
67 texts_b[nofcells] := nullpicture ;
68enddef ;
69
70def step_texts (expr t, m, b) =
71 texts_t[nofcells] := texbox.d(chart_category,t) ;
72 texts_m[nofcells] := texbox.d(chart_category,m) ;
73 texts_b[nofcells] := texbox.d(chart_category,b) ;
74enddef ;
75
76def step_begin_cell =
77 nofcells := nofcells 1 ;
78 cells_t[nofcells] := nullpicture ;
79 cells_b[nofcells] := nullpicture ;
80 texts_t[nofcells] := nullpicture ;
81 texts_m[nofcells] := nullpicture ;
82 texts_b[nofcells] := nullpicture ;
83enddef ;
84
85def step_end_cell =
86enddef ;
87
88
89
90def step_cell_top (expr t, c, f, l, s) =
91 cells_t[nofcells] := texbox.d(chart_category,t) ;
92 cell_top_colors[nofcells] := c ;
93 cell_top_fills [nofcells] := f ;
94 cell_top_lines [nofcells] := l ;
95 cell_top_shapes[nofcells] := s ;
96enddef ;
97
98def step_cell_bot (expr b, c, f, l, s) =
99 cells_b[nofcells] := texbox.d(chart_category,b) ;
100 cell_bot_colors[nofcells] := c ;
101 cell_bot_fills [nofcells] := f ;
102 cell_bot_lines [nofcells] := l ;
103 cell_bot_shapes[nofcells] := s ;
104enddef ;
105
106def step_cell_ali (expr ca, cb, cc, c, f, l, s) =
107 cells_a[nofcells][1] := texbox.d(chart_category,ca) ;
108 cells_a[nofcells][2] := texbox.d(chart_category,cb) ;
109 cells_a[nofcells][3] := texbox.d(chart_category,cc) ;
110 cell_top_colors[nofcells] := c ;
111 cell_top_fills [nofcells] := f ;
112 cell_top_lines [nofcells] := l ;
113 cell_top_shapes[nofcells] := s ;
114enddef ;
115
116def step_text_top (expr t, tc, tf, tl, ts, lc, ll, ls) =
117 texts_t[nofcells] := texbox.d(chart_category,t) ;
118 text_top_colors[nofcells] := tc ;
119 text_top_fills [nofcells] := tf ;
120 text_top_lines [nofcells] := tl ;
121 text_top_shapes[nofcells] := ts ;
122 line_top_colors[nofcells] := lc ;
123 line_top_lines [nofcells] := ll ;
124 line_top_shapes[nofcells] := ls ;
125enddef ;
126
127def step_text_mid (expr m, tc, tf, tl, ts, lc, ll, ls) =
128 texts_m[nofcells] := texbox.d(chart_category,m) ;
129 text_mid_colors[nofcells] := tc ;
130 text_mid_fills [nofcells] := tf ;
131 text_mid_lines [nofcells] := tl ;
132 text_mid_shapes[nofcells] := ts ;
133 line_mid_colors[nofcells] := lc ;
134 line_mid_lines [nofcells] := ll ;
135 line_mid_shapes[nofcells] := ls ;
136enddef ;
137
138def step_text_bot (expr b, tc, tf, tl, ts, lc, ll, ls) =
139 texts_b[nofcells] := texbox.d(chart_category,b) ;
140 text_bot_colors[nofcells] := tc ;
141 text_bot_fills [nofcells] := tf ;
142 text_bot_lines [nofcells] := tl ;
143 text_bot_shapes[nofcells] := ts ;
144 line_bot_colors[nofcells] := lc ;
145 line_bot_lines [nofcells] := ll ;
146 line_bot_shapes[nofcells] := ls ;
147enddef ;
148
149def step_begin_chart =
150 begingroup ;
151 initialize_step_variables ;
152 save nofcells ; numeric nofcells ; nofcells := 0 ;
153 save cells_t, cells_m, cells_b ; picture cells_t[], cells_m[], cells_b[] ;
154 save texts_t, texts_m, texts_b ; picture texts_t[], texts_m[], texts_b[] ;
155 save start_t, start_m, start_b ; numeric start_t[], start_m[], start_b[] ;
156 save cells_a ; picture cells_a[][] ;
157
158 save cell_top_colors ; string cell_top_colors[] ;
159 save cell_bot_colors ; string cell_bot_colors[] ;
160 save text_top_colors ; string text_top_colors[] ;
161 save text_mid_colors ; string text_mid_colors[] ;
162 save text_bot_colors ; string text_bot_colors[] ;
163
164 save cell_top_fills ; string cell_top_fills[] ;
165 save cell_bot_fills ; string cell_bot_fills[] ;
166 save text_top_fills ; string text_top_fills[] ;
167 save text_mid_fills ; string text_mid_fills[] ;
168 save text_bot_fills ; string text_bot_fills[] ;
169
170 save cell_top_lines ; numeric cell_top_lines[] ;
171 save cell_bot_lines ; numeric cell_bot_lines[] ;
172 save text_top_lines ; numeric text_top_lines[] ;
173 save text_mid_lines ; numeric text_mid_lines[] ;
174 save text_bot_lines ; numeric text_bot_lines[] ;
175
176 save cell_top_shapes ; numeric cell_top_shapes[] ;
177 save cell_bot_shapes ; numeric cell_bot_shapes[] ;
178 save text_top_shapes ; numeric text_top_shapes[] ;
179 save text_mid_shapes ; numeric text_mid_shapes[] ;
180 save text_bot_shapes ; numeric text_bot_shapes[] ;
181
182 save line_top_lines ; numeric line_top_lines[] ;
183 save line_mid_lines ; numeric line_mid_lines[] ;
184 save line_bot_lines ; numeric line_bot_lines[] ;
185
186 save line_top_colors ; string line_top_colors[] ;
187 save line_mid_colors ; string line_mid_colors[] ;
188 save line_bot_colors ; string line_bot_colors[] ;
189
190 save line_top_shapes ; numeric line_top_shapes[] ;
191 save line_mid_shapes ; numeric line_mid_shapes[] ;
192 save line_bot_shapes ; numeric line_bot_shapes[] ;
193enddef ;
194
195def step_end_chart =
196
197 save dx, delta ; numeric dx, delta ;
198 save p ; path p ;
199 save one_row_only ; boolean one_row_only ;
200 save cell_t, next_t, text_t ; picture cell_t, next_t, text_t ;
201 save cell_m, next_m, text_m ; picture cell_m, next_m, text_m ;
202 save cell_b, next_b, text_b ; picture cell_b, next_b, text_b ;
203 save height_t, width_t, max_height_t, max_width_t ; numeric height_t, width_t, max_height_t, max_width_t ;
204 save height_m, width_m, max_height_m, max_width_m ; numeric height_m, width_m, max_height_m, max_width_m ;
205 save height_b, width_b, max_height_b, max_width_b ; numeric height_b, width_b, max_height_b, max_width_b ;
206 save alternative ; numeric alternative ;
207
208 one_row_only := true ;
209 for i=1 upto nofcells :
210 if bbwidth(cells_b[i]) > 0 :
211 one_row_only := false ;
212 fi ;
213 endfor ;
214
215 if chart_align :
216 save size, delta, width ; numeric size[], delta[], width[] ;
217 for i=1 upto 3:
218 size[i] = 0 ;
219 for c=1 upto nofcells :
220 size[i] := max(size[i],bbwidth(cells_a[c][i])) ;
221 endfor ;
222 endfor ;
223 for c=1 upto nofcells :
224 cells_t[c] := image (
225 for i=1 upto 3:
226 width[i] := bbwidth(cells_a[c][i]);
227 delta[i] := size[i] width[i] ;
228 endfor;
229 setbounds cells_a[c][1] to boundingbox(cells_a[c][1]) leftenlarged (delta[1]) ;
230 setbounds cells_a[c][2] to boundingbox(cells_a[c][2]) leftenlarged (delta[2]2)
231 rightenlarged(delta[2]2) ;
232 setbounds cells_a[c][3] to boundingbox(cells_a[c][3]) rightenlarged(delta[3]) ;
233 cells_a[c][1] := cells_a[c][1] shifted ( width[1]2 size[2]2 text_distance_set,0) ;
234 cells_a[c][3] := cells_a[c][3] shifted ( width[3]2 size[2]2 text_distance_set,0) ;
235 for i=1 upto 3:
236 draw cells_a[c][i] ;
237
238 endfor ;
239 ) ;
240 endfor ;
241 fi ;
242
243 if chart_vertical :
244 if one_row_only :
245
246 max_width_t := max_width_m := max_width_b := 0 ;
247 for i=1 upto nofcells :
248 max_width_t := max(max_width_t,bbwidth(texts_t[i]));
249 max_width_m := max(max_width_m,bbwidth(texts_m[i]));
250 max_width_b := max(max_width_b,bbwidth(texts_b[i]));
251 endfor ;
252 if max_width_m > 0 :
253 for i=1 upto nofcells :
254 text_t := texts_t[i] ; width_t := bbwidth(text_t) ;
255 text_m := texts_m[i] ; width_m := bbwidth(text_m) ;
256 text_b := texts_b[i] ; width_b := bbwidth(text_b) ;
257 if width_t < max_width_t :
258 setbounds text_t to boundingbox text_t
259 leftenlarged (max_width_t width_t) ;
260 fi ;
261 if width_m < max_width_m :
262 setbounds text_m to boundingbox text_m
263 leftenlarged ((max_width_m width_m)2)
264 rightenlarged ((max_width_m width_m)2) ;
265 fi ;
266 if width_b < max_width_b :
267 setbounds text_b to boundingbox text_b
268 rightenlarged (max_width_b width_b) ;
269 fi ;
270 text_t := text_t shifted ( xpart llcorner text_t, 0) ;
271 text_m := text_m shifted ( xpart llcorner text_m, 0) ;
272 text_b := text_b shifted ( xpart llcorner text_b, 0) ;
273 texts_t[i] := image (
274 draw text_t ;
275 draw text_m shifted (max_width_t text_distance_set,0) ;
276 draw text_b shifted (max_width_t max_width_m 2text_distance_set,0) ;
277 ) rotated 90 ;
278 texts_m[i] := texts_b[i] := nullpicture ;
279 cells_t[i] := cells_t[i] rotated 90 ;
280 endfor ;
281 else :
282 for i=1 upto nofcells :
283 cells_t[i] := cells_t[i] rotated 90 ;
284 texts_t[i] := texts_t[i] rotated 90 ;
285 texts_b[i] := texts_b[i] rotated 90 ;
286 endfor ;
287 fi ;
288 else :
289 for i=1 upto nofcells :
290
291 cell_t := cells_t[i] ;
292 cell_b := cells_b[i] ;
293 cells_t[i] := cell_b rotated 90 ;
294 cells_b[i] := cell_t rotated 90 ;
295 text_t := texts_t[i] ;
296 text_b := texts_b[i] ;
297 texts_t[i] := text_b rotated 90 ;
298 texts_b[i] := text_t rotated 90 ;
299 endfor ;
300 fi ;
301 fi ;
302
303 for i=1 upto nofcells :
304 width_t := bbwidth(cells_t[i]) ;
305 width_b := bbwidth(cells_b[i]) ;
306 if (width_t = 0) and (width_b = 0) :
307
308 elseif (width_t > 0) and (width_t < width_b) :
309 delta := (width_bwidth_t)2 ;
310 setbounds cells_t[i] to boundingbox cells_t[i] leftenlarged delta rightenlarged delta ;
311 elseif (width_b > 0) and (width_t > width_b) :
312 delta := (width_twidth_b)2 ;
313 setbounds cells_b[i] to boundingbox cells_b[i] leftenlarged delta rightenlarged delta ;
314 fi ;
315 endfor ;
316
317 max_height_t := 0 ;
318 max_height_b := 0 ;
319 for i=1 upto nofcells :
320 height_t := bbheight(cells_t[i]) ;
321 height_b := bbheight(cells_b[i]) ;
322 if height_t > 0 :
323 setbounds cells_t[i] to boundingbox cells_t[i] enlarged cell_offset ;
324 height_t := height_t 2 cell_offset ;
325 fi ;
326 if height_b > 0 :
327 setbounds cells_b[i] to boundingbox cells_b[i] enlarged cell_offset ;
328 height_b := height_b 2 cell_offset ;
329 fi ;
330 if height_t > max_height_t :
331 max_height_t := height_t ;
332 fi
333 if height_b > max_height_b :
334 max_height_b := height_b ;
335 fi ;
336 endfor ;
337
338 for i=1 upto nofcells :
339 height_t := bbheight(cells_t[i]) ;
340 height_b := bbheight(cells_b[i]) ;
341 if height_t > 0 :
342 delta := (max_height_theight_t)2 ;
343 setbounds cells_t[i] to boundingbox cells_t[i] topenlarged delta bottomenlarged delta ;
344 fi ;
345 if height_b > 0 :
346 delta := (max_height_bheight_b)2 ;
347 setbounds cells_b[i] to boundingbox cells_b[i] topenlarged delta bottomenlarged delta ;
348 fi ;
349 endfor ;
350
351 dx := 0 ;
352 for i=1 upto nofcells :
353 cells_t[i] := cells_t[i] shifted llcorner cells_t[i] shifted (dx, 0) ;
354 cells_b[i] := cells_b[i] shifted llcorner cells_b[i] shifted (dx,cell_distance_ymax_height_b) ;
355 width_t := bbwidth(cells_t[i]) ;
356 width_b := bbwidth(cells_b[i]) ;
357 if width_t > 0 :
358 dx := dx cell_distance_x width_t ;
359 elseif width_b > 0 :
360 dx := dx cell_distance_x width_b ;
361 fi ;
362 endfor ;
363
364 for i=1 upto nofcells :
365 width_t := bbwidth(cells_t[i]) ;
366 width_b := bbwidth(cells_b[i]) ;
367 if width_t > 0 :
368 drawpredefinedshape (
369 if known cell_top_shapes[i] : cell_top_shapes[i] else : 24 fi,
370 cells_t[i],
371 if known cell_top_lines [i] : cell_top_lines [i] else : cell_line_width fi,
372 if known cell_top_colors[i] : cell_top_colors[i] else : cell_line_color fi,
373 if known cell_top_fills [i] : cell_top_fills [i] else : cell_fill_color fi
374 ) ;
375 draw cells_t[i] ;
376 fi ;
377 if width_b > 0 :
378 drawpredefinedshape (
379 if known cell_bot_shapes[i] : cell_bot_shapes[i] else : 24 fi,
380 cells_b[i],
381 if known cell_bot_lines [i] : cell_bot_lines [i] else : cell_line_width fi,
382 if known cell_bot_colors[i] : cell_bot_colors[i] else : cell_line_color fi,
383 if known cell_bot_fills [i] : cell_bot_fills [i] else : cell_fill_color fi
384 ) ;
385 draw cells_b[i] ;
386 fi ;
387 endfor ;
388
389 def midtopboundary expr p = 0.5[ulcorner boundingbox p, urcorner boundingbox p] enddef ;
390 def midbottomboundary expr p = 0.5[llcorner boundingbox p, lrcorner boundingbox p] enddef ;
391
392 for i=1 upto nofcells-1 :
393 if bbwidth(texts_t[i]) > 0 :
394 setbounds texts_t[i] to boundingbox texts_t[i] enlarged text_offset ;
395 fi ;
396 if bbwidth(texts_b[i]) > 0 :
397 setbounds texts_b[i] to boundingbox texts_b[i] enlarged text_offset ;
398 fi ;
399 endfor ;
400
401 for i=1 upto nofcells-1 :
402 pair t_a, t_b, t_c, b_a, b_b, b_c ;
403 t_a := midtopboundary cells_t[i] ;
404 t_b := midtopboundary cells_t[i+1] ;
405 if one_row_only :
406 b_a := midbottomboundary cells_t[i] ;
407 b_b := midbottomboundary cells_t[i+1] ;
408 else :
409 b_a := midbottomboundary cells_b[i] ;
410 b_b := midbottomboundary cells_b[i+1] ;
411 fi ;
412 t_c := (xpart 0.5[t_a,t_b], ypart t_aline_heightline_distance) ;
413 b_c := (xpart 0.5[b_a,b_b], ypart b_aline_heightline_distance) ;
414 texts_t[i] := thelabel.top(texts_t[i],t_c) ;
415 texts_b[i] := thelabel.bot(texts_b[i],b_c) ;
416 endfor ;
417
418 for i=1 upto nofcells-1 :
419 text_t := texts_t[i] ;
420 text_b := texts_b[i] ;
421 cell_t := cells_t[start_t[i]] ;
422 cell_b := cells_b[start_b[i]] ;
423 next_t := cells_t[i+1] ;
424 next_b := cells_b[i+1] ;
425 if bbwidth(text_t) > 0 :
426 if bbwidth(cell_t) > 0 :
427 alternative := if known line_top_shapes[i] : line_top_shapes[i] else : 1 fi ;
428 if alternative <> 0 :
429 if (alternative = 1) or (alternative = 2) or (alternative = 5) or (alternative = 6) :
430 drawarrow
431 elseif (alternative = 3) or (alternative = 7):
432 drawdblarrow
433 else :
434 draw
435 fi
436 if (alternative = 2) or (alternative = 6) :
437 reverse
438 fi
439 (
440 midtopboundary cell_t
441 shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {up} ..
442 midbottomboundary text_t
443 shifted (0,line_distance) ..
444 {down} midtopboundary next_t
445 shifted (if i < nofcells 1 : line_offset else : 0 fi,cell_line_width)
446 )
447 withpen pencircle scaled
448 if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi
449 withcolor
450 if known line_top_colors[i] : line_top_colors[i] else : line_line_color fi
451 if (alternative >= 5) and (alternative <= 8) :
452 dashed evenly scaled (
453 if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi
454 )
455 fi
456 ;
457 fi ;
458 fi ;
459 fi ;
460 if bbwidth(text_b) > 0 :
461 if one_row_only :
462 cell_b := cell_t ;
463 next_b := next_t ;
464 fi ;
465 if bbwidth(cell_b) > 0 :
466 alternative := if known line_bot_shapes[i] : line_bot_shapes[i] else : 1 fi ;
467 if alternative <> 0 :
468 if (alternative = 1) or (alternative = 2) or (alternative = 5) or (alternative = 6) :
469 drawarrow
470 elseif (alternative = 3) or (alternative = 7):
471 drawdblarrow
472 else :
473 draw
474 fi
475 if (alternative = 2) or (alternative = 6) :
476 reverse
477 fi
478 (
479 midbottomboundary cell_b
480 shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {down} ..
481 midtopboundary text_b
482 shifted (0, line_distance) ..
483 {up} midbottomboundary next_b
484 shifted (if i < nofcells 1 : line_offset else : 0 fi,cell_line_width)
485 )
486 withpen pencircle scaled
487 if known line_bot_lines [i] : line_bot_lines [i] else : line_line_width fi
488 withcolor
489 if known line_bot_colors[i] : line_bot_colors[i] else : line_line_color fi
490 if (alternative >= 5) and (alternative <= 8) :
491 dashed evenly scaled (
492 if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi
493 )
494 fi
495 ;
496 fi ;
497 fi ;
498 fi ;
499 endfor ;
500
501 for i=1 upto nofcells-1 :
502 if bbwidth(texts_t[i]) > 0 :
503 drawpredefinedshape (
504 if known text_top_shapes[i] : text_top_shapes[i] else : 24 fi,
505 texts_t[i],
506 if known text_top_lines [i] : text_top_lines [i] else : text_line_width fi,
507 if known text_top_colors[i] : text_top_colors[i] else : text_line_color fi,
508 if known text_top_fills [i] : text_top_fills [i] else : text_fill_color fi
509 ) ;
510 draw texts_t[i] ;
511 fi ;
512 if bbwidth(texts_b[i]) > 0 :
513 drawpredefinedshape (
514 if known text_bot_shapes[i] : text_bot_shapes[i] else : 24 fi,
515 texts_b[i],
516 if known text_bot_lines [i] : text_bot_lines [i] else : text_line_width fi,
517 if known text_bot_colors[i] : text_bot_colors[i] else : text_line_color fi,
518 if known text_bot_fills [i] : text_bot_fills [i] else : text_fill_color fi
519 ) ;
520 draw texts_b[i] ;
521 fi ;
522 endfor ;
523 if chart_vertical :
524
525 currentpicture := currentpicture rotated -90 ;
526 fi ;
527 endgroup ;
528enddef ;
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 |