File: line.pm

package info (click to toggle)
libsvg-graph-perl 0.02-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 616 kB
  • sloc: perl: 2,793; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 987 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package SVG::Graph::Glyph::line;

use base SVG::Graph::Glyph;
use strict;

=head2 draw

 Title   : draw
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub draw{
   my ($self,@args) = @_;

   my $id = 'n'.sprintf("%07d",int(rand(9999999)));
   my $group = $self->svg->group(id=>"line$id");

   my $xscale = $self->xsize / $self->group->xrange;
   my $yscale = $self->ysize / $self->group->yrange;

   my($x1,$x2,$y1,$y2);
   foreach my $datum (sort {$a->x <=> $b->x} $self->group->data){
	 if(!defined($x1) and !defined($y1)){
	   $x1 = (($datum->x - $self->group->xmin) * $xscale) + $self->xoffset;
	   $y1 = ($self->ysize - ($datum->y - $self->group->ymin) * $yscale) + $self->yoffset;
	   next;
	 }

	 $x2 = (($datum->x - $self->group->xmin) * $xscale) + $self->xoffset;
	 $y2 = ($self->ysize - ($datum->y - $self->group->ymin) * $yscale) + $self->yoffset;

	 $group->line(x1=>$x1,y1=>$y1,x2=>$x2,y2=>$y2,style=>{$self->_style});

	 $x1 = $x2;
	 $y1 = $y2;
   }
}

1;