[comp.unix.questions] Troff "grap" question

ekkel@idca.tds.PHILIPS.nl (Erik Ekkel) (11/29/88)

I want to use the troff "grap" preprocessor to plot a graph. The problem is
that the input has as x-coordinate weeknumbers. So the range of the
x-axis is e.g. 8801:8852, 8901:8952, ..........

How can i tell "grap" that there is a gap in the x-axis; that week 8901 is the
successor of week 8852 and NOT 8900 !
-- 
    __
   /                   Erik Ekkel, Philips PTDSN (+31 55 433301)
  /--   __  o  /       Domain: ekkel@idca.tds.philips.nl
 /___ _/ (_(_ /(       Uucp  : ...!mcvax!philapd!ekkel

kjk@pbhyf.PacBell.COM (Ken Keirnan) (12/01/88)

In article <618@wc11.idca.tds.philips.nl> ekkel@idca.tds.PHILIPS.nl (Erik Ekkel) writes:
>I want to use the troff "grap" preprocessor to plot a graph. The problem is
>that the input has as x-coordinate weeknumbers. So the range of the
>x-axis is e.g. 8801:8852, 8901:8952, ..........
>
>How can i tell "grap" that there is a gap in the x-axis; that week 8901 is the
>successor of week 8852 and NOT 8900 !


If you know the number of points along the x-axis in advance, one way would be
to specify the number of x-axis intervals with the "coord" keyword and then
make the week numbers tick labels.  For example if you have 52 points on the
x-axis:

coord x 0,52
ticks bot out at 1 "8801",2 "8802" ...

or whatever interval you want between ticks.  I know this is messy, but nothing
else comes to mind.
-- 

Ken Keirnan - Pacific Bell - {att,bellcore,sun,ames,pyramid}!pacbell!pbhyf!kjk
  San Ramon, California	                    kjk@pbhyf.PacBell.COM

jim@hpiacla.HP.COM (Jim Rogers) (12/03/88)

>I want to use the troff "grap" preprocessor to plot a graph. The problem is
>that the input has as x-coordinate weeknumbers. So the range of the
>x-axis is e.g. 8801:8852, 8901:8952, ..........
>
>How can i tell "grap" that there is a gap in the x-axis; that week 8901 is the
>successor of week 8852 and NOT 8900 !


You will have to pass the data through a filter which adds another column.
This new column should be the number of weeks since some starting date.
For instance, if your starting date is 8801 then a week value of 8801
would give a week offset of 0, week value 8801 would give a value of 1, and
8901 would give a week value of 52.

This new column would be used to plot the x-axis values.
The original week date column would be used as labels for the x-axis
tick marks.


Jim (my plotter is a Laserjet II) Rogers        Hewlett Packard
                                                Sunnyvale, California

msb@sq.uucp (Mark Brader) (12/05/88)

> How can i tell "grap" that there is a gap in the x-axis; that week 8901 is the
> successor of week 8852 and NOT 8900 !

Probably the easiest way is to turn that number into something that'll
increase linearly, by arithmetic operations.  You turn 8852 into 88+51/52
and 8901 into 89.  If the year and week number, in combined form as in 8852,
is w, then the value you want to use is: (w%100-1)/52 + int(w/100)

One way to achieve this transformation is to precede the list of data points
with the following grap command:

	copy thru @ next at (($1%100-1)/52 + int($1/100), $2) @

(The @ characters are delimiters for the body of "copy thru".)
Then each data line, say

	8842 166.9

will cause a point to be plotted at

	((88%100-1)/52 + int(88/100), 166.9)

which is (88+41/52, 166.9) which is what you want.

You do still have to declare your own ticks for the x-axis if you want
meaningful labels on them, though.  You might say:

	ticks bot at 87   "Jan 1987", \
		     87.5 "Jul 1987", \
		     88   "Jan 1988", \
		     88.5 "Jul 1988", \
		     89   "Jan 1989", \
		     89.5 "Jul 1989", \
		     90   "Jan 1990"

Or you might have a tick for every week and not label them.

	ticks bot from 87 to 90 by 1/52 ""

Or you might do both.  You can plot multiple sets of ticks on the same axis;
they just overprint on top of each other.

An alternative general approach is to define a new set of coordinates
(using the "coord" keyword) for each year; this involves more nuisance,
but does enable you to get numerical week labels for each year if you want.
The following will again plot from the beginning of 1987 to the beginning
of 1990, but you get ticks at 8701, 8710, 8720, 8730, 8740, 8801, etc.

	coord yr87 x 8701     ,8701+3*52  y 0,200
	coord yr88 x 8801-  52,8801+2*52  y 0,200
	coord yr89 x 8901-2*52,8901+  52  y 0,200
	coord yr90 x 9001-3*52,9001       y 0,200

	ticks bot at yr87 8701
	ticks bot from yr87 8710 to 8740 by 10
	ticks bot at yr88 8801
	ticks bot from yr88 8810 to 8840 by 10
	ticks bot at yr89 8901
	ticks bot from yr89 8910 to 8940 by 10
	ticks bot at yr90 9001

Then you'd have to plot each point in the appropriate coordinate system.
Put the following just above the list of data points:

	copy thru !
		year = int($1/100)
		if (year <= 87) then @ next at yr87 ($1, $2) @
		if (year == 88) then @ next at yr88 ($1, $2) @
		if (year == 89) then @ next at yr89 ($1, $2) @
		if (year >= 90) then @ next at yr90 ($1, $2) @
	!

You could also make it more robust by checking whether "year" was in range.

Note: Both of the above methods have been tested with our version of grap,
which is called sqgrap and is included with SoftQuad Publishing Software.
I have not tried them with any earlier versions of grap.

Mark Brader		   "... there is no such word as 'impossible' in
SoftQuad Inc., Toronto	    my dictionary.  In fact, everything between
utzoo!sq!msb		  'herring' and 'marmalade' appears to be missing."
msb@sq.com	    -- Douglas Adams:  Dirk Gently's Holistic Detective Agency