| 1 | package SVG::Graph::Glyph::barflex; | ||
| 2 | |||
| 3 | use base SVG::Graph::Glyph; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | =head2 draw | ||
| 7 | |||
| 8 | Title : draw | ||
| 9 | Usage : | ||
| 10 | Function: | ||
| 11 | Example : | ||
| 12 | Returns : | ||
| 13 | Args : | ||
| 14 | |||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | sub draw{ | ||
| 19 | my ($self,@args) = @_; | ||
| 20 | |||
| 21 | my $id = 'n'.sprintf("%07d",int(rand(9999999))); | ||
| 22 | my $group = $self->svg->group(id=>"bar$id"); | ||
| 23 | |||
| 24 | my $xscale = $self->xsize / $self->group->xrange; | ||
| 25 | my $yscale = $self->ysize / $self->group->yrange; | ||
| 26 | |||
| 27 | my($x1,$x2,$y1,$y2) = (undef,undef,undef,undef); | ||
| 28 | foreach my $datum (sort {$a->x <=> $b->x} $self->group->data){ | ||
| 29 | if(!defined($x1) and !defined($y1)){ | ||
| 30 | $x1 = (($datum->x - $self->group->xmin) * $xscale) + $self->xoffset; | ||
| 31 | $y1 = ($self->ysize - ($datum->y - $self->group->ymin) * $yscale) + $self->yoffset; | ||
| 32 | next; | ||
| 33 | } | ||
| 34 | |||
| 35 | $x2 = (($datum->x - $self->group->xmin) * $xscale) + $self->xoffset; | ||
| 36 | $y2 = ($self->ysize - ($datum->y - $self->group->ymin) * $yscale) + $self->yoffset; | ||
| 37 | |||
| 38 | # $group->line(x1=>$x1,y1=>$y1,x2=>$x2,y2=>$y2,style=>{$self->_style}); | ||
| 39 | $group->rectangle(x=>$x1, | ||
| 40 | y=>$y1, | ||
| 41 | width=>$x2-$x1, | ||
| 42 | height=>$self->ysize - $y1 + $self->yoffset, | ||
| 43 | style=>{$self->_style}); | ||
| 44 | |||
| 45 | $x1 = $x2; | ||
| 46 | $y1 = $y2; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |