| 1 | package SVG::Graph::Glyph::wedge; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use base SVG::Graph::Glyph; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use constant PI => 3.14159; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head2 draw | ||||||||||
| 8 | |||||||||||
| 9 | Title : draw | ||||||||||
| 10 | Usage : | ||||||||||
| 11 | Function: | ||||||||||
| 12 | Example : | ||||||||||
| 13 | Returns : | ||||||||||
| 14 | Args : | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | sub draw{ | ||||||||
|
Subroutine
draw: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 20 | 1 | my ($self,@args) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 1 | my %fill = (1=>'red', | |||||||||
| 23 | 2=>'orange', | ||||||||||
| 24 | 3=>'yellow', | ||||||||||
| 25 | 4=>'green', | ||||||||||
| 26 | 5=>'blue', | ||||||||||
| 27 | 6=>'indigo', | ||||||||||
| 28 | 7=>'violet', | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 1 | my $total = 0; | |||||||||
| 32 | 1 | my $wedge_count = 0; | |||||||||
| 33 | 1 | foreach my $datum ($self->group->data){ | |||||||||
| 34 | 20 | $wedge_count++; | |||||||||
| 35 | 20 | $total += $datum->x; | |||||||||
| 36 | 20 | ▶ | die __PACKAGE__." can't take negative values" if $datum->x < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | my $cx = ($self->xsize / 2) + $self->xoffset; | |||||||||
| 40 | 1 | my $cy = ($self->ysize / 2) + $self->yoffset; | |||||||||
| 41 | 1 | my $r = ($self->xsize) / 2; | |||||||||
| 42 | 1 | my $s = $r; | |||||||||
| 43 | |||||||||||
| 44 | 1 | my $offset = 0; | |||||||||
| 45 | 1 | my $old_offset; | |||||||||
| 46 | 1 | my $wedge = 0; | |||||||||
| 47 | 1 | foreach my $datum ($self->group->data){ | |||||||||
| 48 | 20 | $wedge++; | |||||||||
| 49 | 20 | $old_offset = $offset; | |||||||||
| 50 | 20 | $offset += ($datum->x / $total); | |||||||||
| 51 | |||||||||||
| 52 | 20 | my $v = $old_offset * 2 * PI; | |||||||||
| 53 | 20 | my $w = $offset * 2 * PI; | |||||||||
| 54 | |||||||||||
| 55 | 20 | my $x1 = $cx + cos($v)*$r; | |||||||||
| 56 | 20 | my $y1 = $cy + sin($v)*$s; | |||||||||
| 57 | 20 | my $x2 = $cx + cos($w)*$r; | |||||||||
| 58 | 20 | my $y2 = $cy + sin($w)*$s; | |||||||||
| 59 | |||||||||||
| 60 | 20 | ▶ | my $large = $datum->x < $total / 2 ? 0 : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 20 | my %extra = (); | |||||||||
| 63 | |||||||||||
| 64 | 20 | my $id = 'n'.sprintf("%07d",int(rand(9999999))); | |||||||||
| 65 | 20 | my $group = $self->svg->group(id=>"wedge$id",%extra); | |||||||||
| 66 | |||||||||||
| 67 | # $group->line(x1=>$cx,y1=>$cy , x2=>$x2 , y2=> $y2,style=>{'stroke-width'=>1,'stroke'=>'black'}); | ||||||||||
| 68 | # $group->ellipse(cx=>$cx,cy=>$cy,rx=>$r,ry=>$s,style=>{'fill-opacity'=>0,'stroke'=>'black'}); | ||||||||||
| 69 | |||||||||||
| 70 | $group->path(d=>"M$cx,$cy L$x1,$y1 A$r,$s 0 $large 1 $x2,$y2 L$cx,$cy", | ||||||||||
| 71 | 20 | style=>{'fill-opacity'=>0.4,'fill'=>$fill{$wedge},stroke=>$fill{$wedge},'stroke-width'=>1}, | |||||||||
| 72 | ); | ||||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | 1; | |||||||||