Debian Codegraph @

texmf-dist/tex/latex/bardiag/bardiag.sty

raw
1 %% =============================================
2 %% IMPORTANT NOTICE:
3 %%
4 %% This program can be redistributed and/or modified under the terms
5 %% of the LaTeX Project Public License Distributed from CTAN
6 %% archives in directory macros/latex/base/lppl.txt; either
7 %% version 1 of the License, or any later version.
8 %%
9 %% Only a few abbreviated comments remain here to describe the usage.
10 %% Documentation can be found in bardiag.ps or/and bardiag.tex files
11 %% =============================================
12 %% Copyright 2003 Roman Stepanyan
13 %% E-mail: [email protected]
14
15
16 %TODO
17 % Error ``whiskers'': do NOT work with \subtopbaritem !!!!
18
19 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
20 %
21 \ProvidesPackage{bardiag}[2003/12/10 version 0.5]
22 \def\bardiag{BagDiag}
23 % This package allows to draw bar diagrams.
24 % It is inspired by and build on top of PSTricks
25 %
26 %
27 % Changelog
28 % 2003/12/10 version 0.5 (compatible with 0.4, but "shapes"-macroses
29 % (bars) have to accept an optional argument!)
30 % "fillstyle" can be supplied to \baritem and friends
31 % as an optional argument: \baritem[fillstyle=vlines*,linecolor=red]{}...
32 % bardiag DOES NOT load pst-all anymore, only the necessary stuff
33 % use \barspergroup{N} to make life easier (thanks to Kris Dumont)
34 %
35 %
36 % 2003/06/29 version 0.4 (compatible with 0.3)
37 % Error ``whiskers'' are added
38 %
39 % 2003/06/20 version 0.3 (compatible with 0.2)
40 % ``Horizontal bars'' mode is added.
41 %
42 % 2003/05/23 version 0.2 (not compatible with 0.1)
43 % Code is completely rewritten.
44 % All parameters can be real numbers (not integers) thanks to fp.sty
45 % A lot of changes in the interface.
46 %
47 % 2003/05/10 version 0.1
48 % 0.first version :)
49
50
51 \RequirePackage{calc}
52 \RequirePackage{pstfp}
53 \RequirePackage{fp-snap}
54
55
56 \RequirePackage{pstricks}
57 \RequirePackage{pstcol}
58 \RequirePackage{pst-grad}
59 \RequirePackage{multido}
60
61 \RequirePackage{ifthen}
62
63 % * what should be changed through \renewcommand or \setlength
64 % @ arguments of functions
65 % + internal variables
66
67
68 %----------------------------------------
69 % Horizontal or vertical bars
70 \newcommand{\bdvert}{0}
71 \newcommand{\bdhor}{1}
72 \newcommand{\bdorientation}{\bdvert}
73
74 % Each group is assumed to consist of this number of bars
75 % (subtopbars not included)
76 % use \barspergroup{N} to change
77 \newcommand{\nbarsingroup}{1}
78 \newcommand{\barspergroup}[1]{\renewcommand{\nbarsingroup}{#1}}
79 % Sizes of the diag
80 %
81 \newcommand{\diagheight}{10} % units @
82 \newcommand{\diagwidth}{10} % units @
83 \newlength{\bottomheight} % cm @
84 % units of length
85 \newlength{\xunitlength} % cm @
86 \newlength{\yunitlength} % cm @
87 % of the bar
88 \newcommand{\dbar}{1} % units @
89 \newcommand{\dx}{2} % units @
90 %-----------------------------------------
91 % Sizes related to ticks and levellines
92 %
93 \newcommand{\betweenticks}{1} % units *
94 \newcommand{\numberofticks}{1}% +
95 \newcommand{\MAXnumberofticks}{20}% *
96 %
97 % frame and stuff
98 \newlength{\ticklength} %
99 \setlength{\ticklength}{2mm} % cm *
100 \newlength{\leftshift}
101 \setlength{\leftshift}{\ticklength+2mm}
102 % cm *
103 \newlength{\frameXleft}
104 \setlength{\frameXleft}{\leftshift}
105 \newlength{\frameYbottom}
106 \setlength{\frameYbottom}{0pt}
107 \newlength{\tickrightedge} % cm +
108 % text
109 \newlength{\textoffset} %
110 \setlength{\textoffset}{-0.2cm}%cm *
111 %caption
112 \newlength{\captionoffset}
113 \setlength{\captionoffset}{1.5cm}
114 %-----------------------------------------
115 % ``Counter''-like variables for bars
116 \newcommand{\xval}{1} % units +
117 \newcommand{\xxval}{1} % units +
118 \newcommand{\xhalf}{1} % units +
119 %
120 % and subbars
121 \newcounter{subbar}
122 %
123 % Number on bars
124 % numbers (0,1)
125 \newcommand\shownumbers{1} % *
126 % otherwise no numbers will appear
127 \newcommand\numbercolor{\black\bf} % *
128 \newcommand{\belowtop}{0} % constant
129 \newcommand{\overtop}{1} % constant
130 \newcommand{\bottom}{2} % constant
131 \newcommand\placenumber{\belowtop} % *
132 % can be: \belowtop, \overtop, \bottom
133 \newlength{\numberoffset}
134 \setlength{\numberoffset}{2\textoffset} % cm *
135 \newlength{\lefttextoffset}
136 \setlength{\lefttextoffset}{\leftshift+2mm} % cm *
137 % Angle of the text written below (if vertical bars)
138 % or to the left (if horizontal) of the item-bars
139 \newcommand{\barlabelangle}{90} % *
140 % The same, but for label next to the level line
141 \newcommand{\ticklabelangle}{0} % *
142 %----------------------------------------
143 % Legend-related vars
144 \newcommand{\legendShadow}{0} % *
145 % shadow color
146 \definecolor{legShCol}{gray}{.5}
147 \newcommand{\legendShadowColor}{legShCol} % *
148 %----------------------------------------
149 % 3D related stuff
150 \newcommand{\frameTD}{0} % 3D or not frame % *
151 \newcommand{\tdx}{0.4} % depth of 3d % *
152 \newcommand{\tdy}{1.0} % *
153 \newcommand{\tdhor}{\tdx} % +
154 \newcommand{\tdver}{\tdy} % +
155 %-----------------------------------------
156 % Error ``whiskers''
157 \newcommand{\barerrorterm}{*-|} % *
158 \newpsstyle{barerrorstyle}{linewidth=2pt,linecolor=black}
159 %-----------------------------------------
160 % Styles
161 \definecolor{frameBGgray}{gray}{0.9}
162 \newpsstyle{diagframestyle}{linewidth=1pt,linecolor=black,fillstyle=none}
163 \newpsstyle{tickstyle}{linewidth=1pt,linecolor=black}
164 \newpsstyle{levellinestyle}{linewidth=0.2pt,linecolor=blue}
165 \newpsstyle{diagTDframestyle}{linewidth=1pt,linecolor=black,fillstyle=none}
166 \newpsstyle{diagbgframestyle}{linewidth=1pt,linecolor=black,fillcolor=frameBGgray}
167 %-----------------------------------------
168 \newcommand{\tmpvar}{1}
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 % Commands to begin a bar diagram
172 % \bardiagbegin -> flat frame
173 % \bardiagTDbegin -> 3D frame
174 \newlength{\bgx} % +
175 \newlength{\bgy} % +
176 \newlength{\bgxa} % +
177 \newlength{\bgya} % +
178 %
179 \newcommand{\bardiagrambegin}[7]
180 { % 1 2 3 4 5 6 7
181 % width, height,bottom(cm), dbar, dx, xunit, yunit
182 % height(#1) and width(#2) can be any real numbers,
183 % they are in units of (#6) & (#7)
184
185 \renewcommand{\nbarsingroup}{1}
186
187 % Default \tdy is 5% from the height of the diag
188 \FPdiv{\tmpvar}{#2}{\dbar}%
189 \FPmul{\tdy}{0.05}{\tmpvar}%
190 %
191 \ifthenelse{\bdorientation = \bdvert}%
192 { \renewcommand{\diagheight}{#2}%
193 \renewcommand{\diagwidth}{#1}%
194 \setlength{\bottomheight}{#3}%
195 \renewcommand{\dbar}{#4}%
196 \renewcommand{\dx}{#5}%
197 \setlength{\xunitlength}{#6}%
198 \setlength{\yunitlength}{#7}%
199 %
200 \renewcommand{\tdhor}{\tdx}%
201 \renewcommand{\tdver}{\tdy}%
202 %
203 \setlength{\frameXleft}{\leftshift}
204 \setlength{\frameYbottom}{0pt}
205 %
206 \renewcommand{\barlabelangle}{90}
207 %\renewcommand{\ticklabelangle}{0}
208 }%
209 { \renewcommand{\diagheight}{#1}%
210 \renewcommand{\diagwidth}{#2}%
211 \setlength{\bottomheight}{#3}%
212 \renewcommand{\dbar}{#4}%
213 \renewcommand{\dx}{#5}%
214 \setlength{\xunitlength}{#7}%
215 \setlength{\yunitlength}{#6}%
216 %
217 \renewcommand{\tdhor}{\tdy}%
218 \renewcommand{\tdver}{\tdx}%
219 %
220 \setlength{\frameXleft}{0pt}
221 \setlength{\frameYbottom}{\leftshift}
222 %
223 \renewcommand{\barlabelangle}{0}
224 %\renewcommand{\ticklabelangle}{0}
225 }%
226 %
227 %- - - - - - - - - - - - - - - - - - - -
228 % Take care of ticks (not to draw)
229 \ifthenelse{\bdorientation = \bdvert}%
230 { \FPdiv{\tmpvar}{\diagheight}{\betweenticks}}%
231 { \FPdiv{\tmpvar}{\diagwidth}{\betweenticks}}%
232 \FPtrunc{\numberofticks}{\tmpvar}{0}%
233 \ifthenelse{\numberofticks > \MAXnumberofticks}%
234 { \typeout{----- \bardiag WARNING: }%
235 \typeout{Too LARGE number of ticks: \numberofticks. Falling back to \MAXnumberofticks.}%
236 \typeout{TIP: try to change the betweenticks parameter.}%
237 \typeout{If you DO want such a large number of ticks,}%
238 \typeout{change the MAXnumberofticks parameter.}%
239 \typeout{Ignore this warning if you do not use ticks.}%
240 \typeout{-----}%
241 \renewcommand{\numberofticks}{\MAXnumberofticks}%
242 \FPdiv{\betweenticks}{\diagheight}{\numberofticks}%
243 }%
244 {}%
245 %- - - - - - - - - - - - - - - - - - - -
246 % Compute center of the diagram
247 \FPdiv{\hordiagcenter}{\diagwidth}{2}%
248 \FPdiv{\vertdiagcenter}{\diagheight}{2}%
249 %
250 %- - - - - - - - - - - - - - - - - - - -
251 %
252 \psset{xunit=\xunitlength,yunit=\yunitlength}%
253 \ifthenelse{\frameTD = 0}
254 {\begin{pspicture}(-\captionoffset,-\bottomheight)(\diagwidth,\diagheight)}
255 {\setlength{\bgya}{\yunitlength*\real{\diagheight}+\yunitlength*\real{\dbar}*\real{\tdver}}
256 \begin{pspicture}(-\captionoffset,-\bottomheight)(\diagwidth,\bgya)
257 }
258 %\showgrid %#For debug purposes
259 \psset{fillstyle=solid}%
260 \renewcommand{\xval}{0}%
261 \setlength{\tickrightedge}{-\leftshift+\ticklength}%
262 \ifthenelse{\frameTD = 0}%
263 {\renewcommand{\legendShadow}{0}%
264 % let's draw a frame
265 \psframe[style=diagframestyle](-\frameXleft,-\frameYbottom)(\diagwidth,\diagheight)%
266 }%
267 {\renewcommand{\legendShadow}{1}%
268 % background frame
269 \setlength{\bgx}{-\frameXleft+\xunitlength*\real{\dbar}*\real{\tdhor}}%
270 \setlength{\bgxa}{\frameXleft+\bgx+\xunitlength*\real{\diagwidth}}%
271 \setlength{\bgy}{\yunitlength*\real{\dbar}*\real{\tdver}-\frameYbottom}%
272 \setlength{\bgya}{\bgy+\yunitlength*\real{\diagheight}+\frameYbottom}
273 % let's draw it
274 \psframe[style=diagbgframestyle](\bgx,\bgy)(\bgxa,\bgya)%
275 \psline(-\frameXleft,\diagheight)(\bgx,\bgya)%
276 \psline(-\frameXleft,-\frameYbottom)(\bgx,\bgy)%
277 \psline(\diagwidth,-\frameYbottom)(\bgxa,\bgy)%
278 \psline(\diagwidth,\diagheight)(\bgxa,\bgya)%
279 % let's draw the foreground frame
280 \psframe[style=diagTDframestyle](-\frameXleft,-\frameYbottom)(\diagwidth,\diagheight)%
281 }%
282 }%
283 % - - - - - - - - - - - - - - - - - -
284 \newcommand{\bardiagramend}[2]
285 { \ifthenelse{\frameTD = 1}
286 { % let's draw the frame ones again
287 \psframe[style=diagTDframestyle](-\frameXleft,-\frameYbottom)(\diagwidth,\diagheight)
288 }{}
289 \ifthenelse{\bdorientation = \bdvert}
290 { \rput[c](\hordiagcenter,-0.9\bottomheight){{#1}}
291 \rput[c]{90}(-\captionoffset,\vertdiagcenter){{#2}} % ???? -2cm ?
292 }
293 { \rput[c](\hordiagcenter,-0.9\bottomheight){{#2}}
294 \rput[c]{90}(-\captionoffset,\vertdiagcenter){{#1}} % ???? -2cm ?
295 }
296 \end{pspicture}
297 }
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 % BARITEMS:
300 \newcommand{\ActiveBarPrimitive}{\barRect}
301
302 \newcommand{\subtopx}{0}
303 \newcommand{\subtopy}{0}
304
305 \newcommand{\baritem}[4][fillstyle=solid]{%
306 % the first (optional) argument is "psstyle options": default=solid
307 % [style], name, value, color
308 %
309 % \xval and \xxval are left and right edges of a bar
310 % \xhalf is its center
311 %
312 \FPfadd{\xxval}{\xval}{\dbar}
313 \FPfadd{\tmpvar}{\xval}{\xxval}
314 \FPdiv{\xhalf}{\tmpvar}{2}% ?????????? Get rid of it?
315
316
317 %
318 % Now we call smth, which draws a ``bar''
319 % it can be rectangular, cylindrical, 2 or 3d - we do not know
320 % I plan \barRect; \barTDRect; \barCylinder; more???
321 % It takes 5 arguments:
322 % \something{\xval}{\yval}{\xxval}{\yyval}{color}
323 %
324 %
325 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
326 {\ActiveBarPrimitive[#1]{\xval}{0}{\xxval}{#3}{#4}}%
327 {\ActiveBarPrimitive[#1]{0}{\xval}{#3}{\xxval}{#4}}%
328 %
329 %
330 \printnumber{\xhalf}{#3}{0}{#3}
331 %
332 \FPset{\subtopx}{\xval}
333 \FPset{\subtopy}{#3}
334 %
335 \FPfadd{\tmpvar}{\xval}{\dx}
336 \FPset{\xval}{\tmpvar}
337 %
338 % \xhalf := \xhalf + \dbar * (\nbarsingroup - 1)/2
339
340 \FPfsub{\tmpvar}{\nbarsingroup}{1}
341 \FPdiv{\tmpvar}{\tmpvar}{2}
342 \FPmul{\tmpvar}{\tmpvar}{\dbar}
343 \FPfadd{\xhalf}{\xhalf}{\tmpvar}
344
345 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
346 {\printbarlabel{\xhalf}{\textoffset}{\barlabelangle}{#2}}%
347 {\printbarlabel{\textoffset}{\xhalf}{\barlabelangle}{#2}}%
348 \setcounter{subbar}{1}
349 }
350
351 \newcommand{\barmidx}{0}
352 \newcommand{\barerrormargins}[2] % To make asymmetric margins
353 % 1st = upper Dy; 2nd = bottom Dy
354 {%
355 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
356 { \FPdiv{\tmpvar}{\dbar}{2}
357 \FPfadd{\barmidx}{\subtopx}{\tmpvar}
358 \FPfadd{\tmpvar}{\subtopy}{#1}
359 \psline[style=barerrorstyle]{\barerrorterm}(\barmidx,\subtopy)(\barmidx,\tmpvar)
360 %
361 \FPdiv{\tmpvar}{\dbar}{2}
362 \FPfadd{\barmidx}{\subtopx}{\tmpvar}
363 \FPfsub{\tmpvar}{\subtopy}{#2}
364 \psline[style=barerrorstyle]{\barerrorterm}(\barmidx,\subtopy)(\barmidx,\tmpvar)
365 }
366 { \FPdiv{\tmpvar}{\dbar}{2}
367 \FPfadd{\barmidx}{\subtopx}{\tmpvar}
368 \FPfadd{\tmpvar}{\subtopy}{#1}
369 \psline[style=barerrorstyle]{\barerrorterm}(\subtopy,\barmidx)(\tmpvar,\barmidx)
370 %
371 \FPdiv{\tmpvar}{\dbar}{2}
372 \FPfadd{\barmidx}{\subtopx}{\tmpvar}
373 \FPfsub{\tmpvar}{\subtopy}{#2}
374 \psline[style=barerrorstyle]{\barerrorterm}(\subtopy,\barmidx)(\tmpvar,\barmidx)
375 }
376 }
377 %%%%%%%%%%%%%
378 \newcommand{\barerror}[1] % To make symmetric margins
379 {
380 \barerrormargins{#1}{#1}
381 }
382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 % SUBITEMS
384 \newcommand{\subxval}{0}
385 \newcommand{\subxxval}{0}
386
387
388 \newcommand{\subbaritem}[4][fillstyle=solid]{
389 % [style], name, value, color
390 %
391 % \subxval and \subxxval are left and right edges of a bar
392 % \subxhalf is its center
393 %
394 \FPfsub{\subxxval}{\xval}{\dx}
395 \FPmul{\tmpvar}{\dbar}{\thesubbar}
396 \FPfadd{\subxval}{\subxxval}{\tmpvar}
397
398 \FPfadd{\subxxval}{\subxval}{\dbar}
399
400 \FPfadd{\tmpvar}{\subxval}{\subxxval}
401 \FPdiv{\subxhalf}{\tmpvar}{2}% ?????????? Get rid of it?
402 %
403 % Now we call smth, which draws a ``bar''
404 % it can be rectangular, cylindrical, 2 or 3d - we do not know
405 % I plan \barRect; \barTDRect; \barCylinder; ???
406 % It takes 5 arguments:
407 % \something{\xval}{\yval}{\xxval}{\yyval}{color}
408 %
409 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
410 {\ActiveBarPrimitive[#1]{\subxval}{0}{\subxxval}{#3}{#4}}%
411 {\ActiveBarPrimitive[#1]{0}{\subxval}{#3}{\subxxval}{#4}}%
412 %
413 %
414 \printnumber{\subxhalf}{#3}{0}{#3}
415
416 \FPset{\subtopx}{\subxval}
417 \FPset{\subtopy}{#3}
418
419 %\rput[r]{90}(\subxhalf,\textoffset){#2}
420 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
421 {\printbarlabel{\subxhalf}{\textoffset}{\barlabelangle}{#2}}%
422 {\printbarlabel{\textoffset}{\subxhalf}{\barlabelangle}{#2}}%
423 \addtocounter{subbar}{1}
424 }
425
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % TOP SUBITEMS
428
429 \newcommand{\subtopxx}{0} % +
430 \newcommand{\subtopyy}{0} % +
431 \newcommand{\subtopxhalf}{0}% +
432
433 \newcommand{\subtopbaritem}[4][fillstyle=solid]{
434 % [style], name, value, color
435 %
436 %
437 % \subtopxhalf is the center
438 %
439 \FPfadd{\subtopxx}{\subtopx}{\dbar}
440
441 \FPfadd{\subtopyy}{\subtopy}{#3}
442
443 \FPfadd{\tmpvar}{\subtopx}{\subtopxx}
444 \FPdiv{\subtopxhalf}{\tmpvar}{2}%
445 %
446 \ifthenelse{\bdorientation = \bdvert}%is it vertical or horizontal?
447 {\ActiveBarPrimitive[#1]{\subtopx}{\subtopy}{\subtopxx}{\subtopyy}{#4}}%
448 {\ActiveBarPrimitive[#1]{\subtopy}{\subtopx}{\subtopyy}{\subtopxx}{#4}}%
449 %
450 %
451 \printnumber{\subtopxhalf}{#3}{\subtopy}{\subtopyy}
452 %
453 % it is not supposed to print any label, so,
454 % we do not need to tae care of it.
455 %\rput[r]{90}(\subxhalf,\textoffset){#1}
456 %\addtocounter{subbar}{1}
457 %
458 \FPset{\subtopy}{\subtopyy}
459 }
460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461 % Bar primitives
462 \input{bardiag.bar}
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464 % Legend
465 \newlength{\legendXo} % this one is an argument of diagLegendbegin
466 \newlength{\legendYo} % the same
467 \newlength{\legendWidth} % the same
468 \newlength{\legendHeight} % this will be computed
469 %
470 \newlength{\legenditemheight}\setlength{\legenditemheight}{7mm}
471 \newlength{\legendspacer}\setlength{\legendspacer}{3mm}
472 \newlength{\legendRectWidth}\setlength{\legendRectWidth}{6mm}
473 \newlength{\legendRectHeight}\setlength{\legendRectHeight}{4mm}
474 %
475 \newcommand{\diagLegendoptions}[3]
476 { % 1 2 3
477 % bgcolor framecolor framelinewidth
478 \newpsstyle{diagLegenditemstyle}{fillstyle=solid,fillcolor=#1,linecolor=#1}
479 \newpsstyle{diagLegendframetyle}{fillstyle=none,linecolor=#2,linewidth=#3}
480 }
481 %First we call \diagLegendoptions
482 \diagLegendoptions{white}{black}{0.5pt}
483 %
484 \newlength{\lixcoor}
485 \newlength{\liycoor}
486 \newlength{\lixxcoor}
487 \newlength{\liyycoor}
488 %
489 \newlength{\liix} % where to put the rectangle with color
490 \newlength{\liiix} % where to put the text
491 %
492 \newcommand{\diagLegendbegin}[3]
493 {% 1 2 3
494 % Xo(units) Yo(un) Width(un)
495 % (Xo,Yo) are coordinates of the left-up corner
496 \ifthenelse{\bdorientation = \bdvert}%
497 {
498 \setlength{\legendXo}{\xunitlength*\real{#1}}
499 \setlength{\legendYo}{\yunitlength*\real{#2}}
500 \setlength{\legendWidth}{\xunitlength*\real{#3}}
501 \setlength{\legendHeight}{0cm}
502 %
503 \setlength{\lixcoor}{\legendXo}
504 \setlength{\lixxcoor}{\legendXo+\legendWidth}
505 \setlength{\liycoor}{\legendYo}
506 %
507 \setlength{\liix}{\lixcoor+\legendspacer}
508 \setlength{\liiix}{\liix+\legendRectWidth+\legendspacer}
509 }
510 {
511 \setlength{\legendXo}{\xunitlength*\real{#2}}
512 \setlength{\legendYo}{\yunitlength*\real{#1}}
513 \setlength{\legendWidth}{\yunitlength*\real{#3}}
514 \setlength{\legendHeight}{0cm}
515 %
516 \setlength{\lixcoor}{\legendXo}
517 \setlength{\lixxcoor}{\legendXo+\legendWidth}
518 \setlength{\liycoor}{\legendYo}
519 %
520 \setlength{\liix}{\lixcoor+\legendspacer}
521 \setlength{\liiix}{\liix+\legendRectWidth+\legendspacer}
522 }
523 }
524
525 \newlength{\lShX}
526 \newlength{\lShXxx}
527 \newlength{\lShY}
528 \newlength{\lShYyy}
529
530 \newcommand{\diagLegendend}
531 { \ifthenelse{\legendShadow = 1}
532 {\setlength{\lShX}{\legendXo+\xunitlength*\dbar*\real{\tdhor}}
533 \setlength{\lShXxx}{\lixxcoor+\xunitlength*\dbar*\real{\tdhor}}
534 \setlength{\lShY}{\liycoor+\yunitlength*\dbar*\real{\tdver}}
535 \setlength{\lShYyy}{\legendYo+\yunitlength*\dbar*\real{\tdver}}
536 \psframe[fillstyle=solid,linecolor=\legendShadowColor,fillcolor=\legendShadowColor](\lShX,\legendYo)(\lShXxx,\lShYyy)
537 \psframe[fillstyle=solid,linecolor=\legendShadowColor,fillcolor=\legendShadowColor](\lixxcoor,\lShY)(\lShXxx,\lShYyy)
538 }
539 {}
540 \psframe[style=diagLegendframetyle](\legendXo,\liycoor)(\lixxcoor,\legendYo)
541 }
542
543
544 \newlength{\legendRectXo}
545 \newlength{\legendRectX}
546 \newlength{\legendRectYo}
547 \newlength{\legendRectY}
548 %
549 \newcommand{\legendPutRect}[2][fillstyle=solid]
550 {
551 \setlength{\legendRectXo}{\liix}
552 \setlength{\legendRectYo}{(\liyycoor+\liycoor-\legendRectHeight)/2}
553 %\setlength{\legendRectYo}{(\liyycoor+\liycoor)/2-\legendRectHeight}
554 \setlength{\legendRectX}{\legendRectXo+\legendRectWidth}
555 \setlength{\legendRectY}{\legendRectYo+\legendRectHeight}
556 \psframe[fillcolor=#2,#1](\legendRectXo,\legendRectYo)(\legendRectX,\legendRectY)
557 }
558
559
560 \newlength{\legendiyc}
561 \newcommand{\diagLegenditem}[3][fillstyle=solid]
562 {% [1] 2 3
563 % style item_text color
564 \addtolength{\legendHeight}{\legenditemheight}
565 \setlength{\liyycoor}{\liycoor}
566 \addtolength{\liycoor}{-\legenditemheight}
567 \psframe[style=diagLegenditemstyle](\lixcoor,\liycoor)(\lixxcoor,\liyycoor)
568 \legendPutRect[#1]{#3}
569 \setlength{\legendiyc}{(\liycoor+\liyycoor)/2}
570 \rput[l](\liiix,\legendiyc){#2}
571 }
572
573
574
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 % Util
577 \newcommand{\outputparameters}
578 {\rput[lt](0,-2\bottomheight){\parbox{10cm}{
579 \begin{tabular}{p{5cm}p{5cm}}
580 Width: & \diagwidth \\\hline
581 Height: &\diagheight \\\hline
582 Width of a bar:& \dx \\\hline
583 Distance between bars:& \dbar\\\hline\hline
584 %X unit length: & \ratio{\xunitlength}{1cm}\\\hline
585 %Y unit length: & \ratio{\yunitlength}{1cm}\\\hline
586 TICKS:\\
587 Between ticks: & \betweenticks\\
588 Number of ticks:&\numberofticks (computed)\\ \hline\hline
589 LAST VALS:\\
590 xval: & \xval\\
591 dbar: & \dbar\\
592 xxval:& \xxval\\
593 xhalf:& \xhalf\\
594 tmpvar:&\tmpvar\\
595 \end{tabular}}}
596 }
597 %--------------------------------------------------------------------
598
599 \newlength{\ycoordnum}
600 %
601 \newcommand\printnumber[4]
602 { % 1 2 3 4
603 % center of the bar, text(number) (will be centered), bottom y, top y
604 %
605 % we compute the y-position of the text depending on
606 % the value of the \placenumber parameter
607 % it can be: \belowtop, \overtop, \bottom
608 \ifthenelse{\bdorientation = \bdvert}
609 {
610 \ifthenelse{\placenumber = \overtop}
611 {\setlength{\ycoordnum}{\yunitlength*\real{#4}-\numberoffset}
612 \ifthenelse{\shownumbers = 1}
613 {\rput[bc](#1,\ycoordnum){\numbercolor #2}}{}
614 }
615 {%else
616 \ifthenelse{\placenumber = \bottom}
617 {\setlength{\ycoordnum}{\yunitlength*\real{#3}-\numberoffset}
618 \ifthenelse{\shownumbers = 1}
619 {\rput[bc](#1,\ycoordnum){\numbercolor #2}}
620 {}
621 }
622 % default->\belowtop
623 {\setlength{\ycoordnum}{{\yunitlength*\real{#4}}+\numberoffset}
624 \ifthenelse{\shownumbers = 1 \AND \lengthtest{\ycoordnum > -\numberoffset}}
625 {\rput[tc](#1,\ycoordnum){\numbercolor #2}}{}
626 }
627 }
628 }
629 {%else, i.e. if it is horisontal
630 %if fact, ``y-coordinate'' \ycoordnum is now along the horizontal axis
631 \ifthenelse{\placenumber = \overtop}
632 {
633 \setlength{\ycoordnum}{\xunitlength*\real{#4}-\numberoffset}
634 \ifthenelse{\shownumbers = 1}
635 {\rput[l](\ycoordnum,#1){\numbercolor #2}}{}
636 }
637 {%else
638 \ifthenelse{\placenumber = \bottom}
639 {\setlength{\ycoordnum}{\xunitlength*\real{#3}-\numberoffset}
640 \ifthenelse{\shownumbers = 1}
641 {\rput[l](\ycoordnum,#1){\numbercolor #2}}
642 {}
643 }
644 % default->\belowtop
645 {\setlength{\ycoordnum}{{\xunitlength*\real{#4}}+\numberoffset}
646 \ifthenelse{\shownumbers = 1 \AND \lengthtest{\ycoordnum > -\numberoffset}}
647 {\rput[r](\ycoordnum,#1){\numbercolor #2}}{}
648 } %\rput[tc](\ycoordnum,#1){\numbercolor #2}
649 }
650 }
651 }
652 %--------------------------------------------------------------------
653
654 \newlength{\ytick}
655 \newcommand{\whattoprint}{0}
656 %
657 \newcommand{\drawlevellines}
658 {\ifthenelse{\bdorientation = \bdvert}
659 {\rput[c]{\ticklabelangle}(-\lefttextoffset,0){0}}% this is 0
660 {\rput[c]{\ticklabelangle}(0,-\lefttextoffset){0}}
661 % let's draw ticks; then lines;
662 % they are controlled by \betweenticks variable
663 % on its basis we have computed \numberofticks above (in \diagbegin)
664 %
665 \multido{\n=1+1}{\numberofticks}{%
666 \ifthenelse{\bdorientation = \bdvert}
667 {\setlength{\ytick}{\yunitlength*\real{\betweenticks}*\n}
668 % tick itself
669 \psline[style=tickstyle](-\leftshift,\ytick)(\tickrightedge,\ytick)
670 % level lines
671 \psline[style=levellinestyle](\tickrightedge,\ytick)(\diagwidth,\ytick)
672 % numbers!
673 \FPmul{\whattoprint}{\n}{\betweenticks}
674 \FPclip{\whattoprint}{\whattoprint}
675 \rput[r](-\lefttextoffset,\ytick){\whattoprint}
676 }
677 {\setlength{\ytick}{\xunitlength*\real{\betweenticks}*\n}
678 \psline[style=tickstyle](\ytick,-\leftshift)(\ytick,\tickrightedge)
679 \psline[style=levellinestyle](\ytick,\tickrightedge)(\ytick,\diagheight)
680 \FPmul{\whattoprint}{\n}{\betweenticks}
681 \FPclip{\whattoprint}{\whattoprint}
682 \rput[c](\ytick,-\lefttextoffset){\whattoprint}
683 }
684 }
685 }
686 %- - - - - - - - - - - - - - - - - - - -
687 \newcommand{\printbarlabel}[4]{
688 % x, y, angle, text
689 \ifthenelse{ #3 = 0 \AND \bdorientation = \bdvert}
690 {\rput[tc]{#3}(#1,#2){{#4}}}
691 {\rput[r]{#3}(#1,#2){{#4}}}
692 }
693 %--------------------------------------------------------------------
694 %
695 \InputIfFileExists{bardiag.cfg}
696 {\typeout{BarDiag: Local configuration file bardiag.cfg loaded}}
697 {\typeout{BarDiag: No local configuration loaded}}
698 %
699 %--------------------------------------------------------------------