groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Drawing filled circle segments


From: Ted Harding
Subject: Re: [Groff] Drawing filled circle segments
Date: Fri, 28 Oct 2005 20:17:32 +0100 (BST)

On 28-Oct-05 Werner LEMBERG wrote:
> 
>> Well, here's a skeleton with an example of use.
> 
> *Very* nice!
> 
>> Basically, as it is, you invoke in-line it with
>> 
>> \*[wedge radius(pts) Red Green Blue Angle1 Angle2]
> 
> Aah, you use the new string syntax with arguments!  This means that
> you need at least groff 1.18.

Indeed! Thanks for the reminder.

One can, of course, encapsulate the parameters in a macro.
Thinking about it, I have the idea that one can define the
wedge-drawing strings in a macro and then invoke them when
required. That way, it's classic groff.

Example (using the PS definition which give the segments
with black borders):


\X'ps: def \
/drawwedge { \
  newpath \
  0 0 moveto \
  0 0   rad ang1 ang2 arc \
  closepath \
} def'
\X'ps: def \
/wedge { gsave \
  currentpoint translate 1 -1 scale \
  /ang2 exch def \
  /ang1 exch def \
  /B exch def /G exch def /R exch def \
  /rad exch def \
  R G B setrgbcolor \
  0.01 setlinewidth \
  drawwedge \
  fill stroke \
  0 setgray drawwedge stroke \
  grestore \
} def'
.de mkwdg
.ds sname \\$1
.shift
.ds wedge.\\*[sname] \Z'\X'ps: exec \\$* wedge''
..
.LP
\&
.sp 1i
.mkwdg 01 36 1.0 0.0 0.0 000 045
.mkwdg 02 36 0.5 0.5 0.0 045 100
.mkwdg 03 36 0.0 1.0 0.0 100 170
.mkwdg 04 36 0.0 0.5 0.5 170 250
.mkwdg 05 36 0.0 0.0 1.0 250 360
This is a line with_\h'0.5i'\
\*[wedge.01]\
\*[wedge.02]\
\*[wedge.03]\
\*[wedge.04]\
\*[wedge.05]\
\h'0.5i'_in the middle of it.
.sp 1i
That was a line with a pie-chart.


It's basically the same principle as before, but here the macro

.mkwdg name rad R G B ang1 ang2

creates the string

\*[wedge.name] -> \Z'\X'ps: exec rad R B G ang1 ang2 wedge''

So even the dinosours now have pie-charts! (though my professional
statistician's eye does not consider that pie-charts are always a
good way to present information (despite what the management
might think).



As a further thought, given that the building-block which the
user defines is a parametrised wedge, it occurred to me that
this allows you to present "two-dimensional" information in
the pie-chart.

As an example, suppose we have data on the 5 employees of
a small business, their salaries, and also the profit they
directly generated, as follows:

             Salary    Profit
            -----------------
Red          45,000   120,000

Khaki        55,000    80,000

Green        70,000   200,000

SeaGreen     80,000   250,000

Blue        110,000    50,000
=============================

(colour-coded to protect their identites, though "Blue" is
the Company Director)

and we decide to present this as a pie-chart in which the
angle of the sector is proportional to the salary (i.e. the
cost to the company), and the area of the sector is proportional
to the profit generated.

If we take "Green" to have the "standard" radius of 36p
as above, this then gives the following equivalent in
degrees angle and points radius (rounded):

          Degrees   Radius(pt)
Red            45      35

Khaki          55      26

Green          70      36

SeaGreen       80      38

Blue          110      14

we can then have (append this to the above troff code so as
to get the PS definitions):

.LP
\&
.sp 1i
.mkwdg 01 35 1.0 0.0 0.0 000 045
.mkwdg 02 26 0.5 0.5 0.0 045 100
.mkwdg 03 36 0.0 1.0 0.0 100 170
.mkwdg 04 38 0.0 0.5 0.5 170 250
.mkwdg 05 14 0.0 0.0 1.0 250 360
This is how the personnel performed:\0\0\h'0.5i'\
\*[wedge.01]\
\*[wedge.02]\
\*[wedge.03]\
\*[wedge.04]\
\*[wedge.05]


which just about sums it up ("Red" is the guy who gets to prepare
this stuff; and he's leaving for a better job soon ... ).

Of course, if you think the impact should be different, you can
re-calculate the radii for yourself according to a different rule.

Best wishes to all,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 28-Oct-05                                       Time: 20:17:28
------------------------------ XFMail ------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]