[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Pie charts with Lout + separate subject: html2lout improved
From: |
Mark Summerfield |
Subject: |
Pie charts with Lout + separate subject: html2lout improved |
Date: |
Mon, 19 Jul 1999 08:58:20 +0100 (British Summer Time) |
Pie charts with Lout + separate subject: html2lout improved
(html2lout is covered at the very end)
Pie charts with Lout: are they implementable?
I've got an idea for expressing pie charts with Lout - but I still don't
understand Lout well enough to know how or even if this is possible. The
syntax idea goes like this:
@Pie {
@Segment
size { 20 } colour { red } olabel { Tomato } pullout { yes }
@Segment
size { 70 } colour { green } olabel { Kiwi }
@Segment
size { 220 } colour { yellow } olabel { Banana }
}
size - only the size option would be mandatory and is a number which is
relative to
the other sizes, i.e. its your data, integer or real any +ve number.
colour or color - optional, the colour of the segment.
olabel - optional, outer label, appears outside the segment.
ilabel - optional, inner label, appears on the segment.
pullout - optional, default no, but if yes the segment is 'pulled out' of the
pie.
Probably needs other options, e.g. outlinecolour.
A simple algorithm to do this:
# Calculate how many degrees wide each unit size is
totalsize = 0
foreach Segment
totalsize += size
sizeangle = 360 / totalsize # In this example 1.161 degrees.
# For the example given the angle of each would be
# 23, 81 and 255 degrees respectively.
# Now draw the arcs
startoffset = 0
foreach Segment
angle = size * sizeangle
drawarc( startoffset, angle, colour )
startoffset += angle
Although I can't write it in Lout (and don't know if its expressible), here's
an example in Perl/Tk.
The data at the end can be changed, added to or reduced so long as each line
is in the form:
<size>,<colour>
#!/usr/bin/perl -w
use strict ;
use Tk ;
my @Pie ;
while( <DATA> ) {
chomp ;
last unless $_ ;
my( $size, $colour ) = split /,/ ;
push @Pie, { -size => $size, -colour => $colour } ;
}
my $Win = new MainWindow ;
my $Canvas = $Win->Canvas->pack ;
&draw_pie ;
MainLoop ;
sub draw_pie {
my $totalsize = 0 ;
foreach my $ref ( @Pie ) {
my $size = $ref->{-size} ;
$totalsize += $size ;
}
my $sizeangle = 360 / $totalsize ;
my $offset = 0 ;
foreach my $ref ( @Pie ) {
my $colour = $ref->{-colour} ;
my $size = $ref->{-size} ;
my $angle = $size * $sizeangle ;
$Canvas->createArc( 0, 0, 200, 200,
-fill => $colour,
-outline => $colour,
-start => $offset + 90,
-extent => $angle,
) ;
$offset += $angle ;
print "$colour * $size * $angle\n" ;
}
print "$totalsize $sizeangle $offset\n" ;
}
__DATA__
30,white
70,violet
100,red
15,blue
150,yellow
40,black
120,green
html2lout in xxx2lout-1.00.tar.gz has been uploaded and should
appear within 24hrs. A link has now been added from the Lout Home Page.
html2lout has been significantly fixed:
* No longer puts @LP's all over the place - this was a bug, now fixed.
* Table handling improved - but still basic and will require hand tweaking.
* List handling improved (mainly due to @LP bugfix).
* New tags supported and some minor fixes implemented.
* Now does full and proper &entity; to address@hidden entity} conversions.
* Provides full control of commented output of handled and unhandled tags.
* For Perl programmers Lout.pm offers txt2lout and htmlentity2lout; and
HTML::LoutParser now gives proper objects (without the scoping bug I started
out with:)
Regards.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
address@hidden Tel: +44 (0)1225 826043
CHEST Software Team Manager Fax: +44 (0)1225 826177
http://www.chest.ac.uk Mobile: 0403 535803