line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Graph::Glyph::wedge; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use base SVG::Graph::Glyph; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
500
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
7
|
use constant PI => 3.14159; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
566
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head2 draw |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Title : draw |
10
|
|
|
|
|
|
|
Usage : |
11
|
|
|
|
|
|
|
Function: |
12
|
|
|
|
|
|
|
Example : |
13
|
|
|
|
|
|
|
Returns : |
14
|
|
|
|
|
|
|
Args : |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub draw{ |
20
|
1
|
|
|
1
|
1
|
3
|
my ($self,@args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
10
|
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
|
|
|
|
|
2
|
my $total = 0; |
32
|
1
|
|
|
|
|
2
|
my $wedge_count = 0; |
33
|
1
|
|
|
|
|
4
|
foreach my $datum ($self->group->data){ |
34
|
20
|
|
|
|
|
22
|
$wedge_count++; |
35
|
20
|
|
|
|
|
55
|
$total += $datum->x; |
36
|
20
|
50
|
|
|
|
49
|
die __PACKAGE__." can't take negative values" if $datum->x < 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
5
|
my $cx = ($self->xsize / 2) + $self->xoffset; |
40
|
1
|
|
|
|
|
3
|
my $cy = ($self->ysize / 2) + $self->yoffset; |
41
|
1
|
|
|
|
|
3
|
my $r = ($self->xsize) / 2; |
42
|
1
|
|
|
|
|
2
|
my $s = $r; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
1
|
my $offset = 0; |
45
|
1
|
|
|
|
|
1
|
my $old_offset; |
46
|
1
|
|
|
|
|
2
|
my $wedge = 0; |
47
|
1
|
|
|
|
|
3
|
foreach my $datum ($self->group->data){ |
48
|
20
|
|
|
|
|
898
|
$wedge++; |
49
|
20
|
|
|
|
|
21
|
$old_offset = $offset; |
50
|
20
|
|
|
|
|
45
|
$offset += ($datum->x / $total); |
51
|
|
|
|
|
|
|
|
52
|
20
|
|
|
|
|
32
|
my $v = $old_offset * 2 * PI; |
53
|
20
|
|
|
|
|
28
|
my $w = $offset * 2 * PI; |
54
|
|
|
|
|
|
|
|
55
|
20
|
|
|
|
|
50
|
my $x1 = $cx + cos($v)*$r; |
56
|
20
|
|
|
|
|
29
|
my $y1 = $cy + sin($v)*$s; |
57
|
20
|
|
|
|
|
38
|
my $x2 = $cx + cos($w)*$r; |
58
|
20
|
|
|
|
|
32
|
my $y2 = $cy + sin($w)*$s; |
59
|
|
|
|
|
|
|
|
60
|
20
|
50
|
|
|
|
47
|
my $large = $datum->x < $total / 2 ? 0 : 1; |
61
|
|
|
|
|
|
|
|
62
|
20
|
|
|
|
|
31
|
my %extra = (); |
63
|
|
|
|
|
|
|
|
64
|
20
|
|
|
|
|
52
|
my $id = 'n'.sprintf("%07d",int(rand(9999999))); |
65
|
20
|
|
|
|
|
44
|
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
|
20
|
|
|
|
|
1228
|
$group->path(d=>"M$cx,$cy L$x1,$y1 A$r,$s 0 $large 1 $x2,$y2 L$cx,$cy", |
71
|
|
|
|
|
|
|
style=>{'fill-opacity'=>0.4,'fill'=>$fill{$wedge},stroke=>$fill{$wedge},'stroke-width'=>1}, |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |