comparison variant_effect_predictor/Bio/Graphics/Glyph/triangle.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1f6dce3d34e0
1 package Bio::Graphics::Glyph::triangle;
2 # DAS-compatible package to use for drawing a triangle
3
4 use strict;
5 use vars '@ISA';
6 @ISA = 'Bio::Graphics::Glyph::generic';
7 use Bio::Graphics::Glyph::generic;
8
9 sub pad_left {
10 my $self = shift;
11 my $left = $self->SUPER::pad_left;
12 return $left unless $self->option('point');
13 my $extra = $self->option('height')/3;
14 return $extra > $left ? $extra : $left;
15 }
16
17 sub pad_right {
18 my $self = shift;
19 my $right = $self->SUPER::pad_right;
20 return $right unless $self->option('point');
21 my $extra = $self->option('height')/3;
22 return $extra > $right ? $extra : $right;
23 }
24
25 sub draw_component {
26 my $self = shift;
27 my $gd = shift;
28 my $fg = $self->fgcolor;
29 my $orient = $self->option('orient') || 'S';
30
31 # find the center and vertices
32 my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_);
33 my $xmid = ($x1+$x2)/2;
34 my $ymid = ($y1+$y2)/2;
35
36 my ($vx1,$vy1,$vx2,$vy2,$vx3,$vy3);
37
38 #make an equilateral
39 my ($p,$q) = ($self->option('height'),($x2-$x1)/2);
40 if ($self->option('point')){
41 $q = $p/sqrt(3); #2;
42 $x1 = $xmid - $q; $x2 = $xmid + $q;
43 $y1 = $ymid - $q; $y2 = $ymid + $q;
44 }
45
46 if ($orient eq 'S'){$vx1=$x1;$vy1=$y1;$vx2=$x2;$vy2=$y1;$vx3=$xmid;$vy3=$y2;}
47 elsif($orient eq 'N'){$vx1=$x1;$vy1=$y2;$vx2=$x2;$vy2=$y2;$vx3=$xmid;$vy3=$y1;}
48 elsif($orient eq 'W'){$vx1=$x2;$vy1=$y1;$vx2=$x2;$vy2=$y2;$vx3=$x2-$p;$vy3=$ymid;}
49 elsif($orient eq 'E'){$vx1=$x1;$vy1=$y1;$vx2=$x1;$vy2=$y2;$vx3=$x1+$p;$vy3=$ymid;}
50
51 # now draw the triangle
52 $gd->line($vx1,$vy1,$vx2,$vy2,$fg);
53 $gd->line($vx2,$vy2,$vx3,$vy3,$fg);
54 $gd->line($vx3,$vy3,$vx1,$vy1,$fg);
55
56 if (my $c = $self->bgcolor){
57 $gd->fillToBorder($xmid,$ymid,$fg,$c) if $orient eq 'S' || $orient eq 'N';
58 $gd->fillToBorder($x1+1,$ymid,$fg,$c) if $orient eq 'E';
59 $gd->fillToBorder($x2-1,$ymid,$fg,$c) if $orient eq 'W';
60 }
61 }
62
63 1;
64
65 __END__
66
67 =head1 NAME
68
69 Bio::Graphics::Glyph::triangle - The "triangle" glyph
70
71 =head1 SYNOPSIS
72
73 See L<Bio::Graphics::Panel> and L<Bio::Graphics::Glyph>.
74
75 =head1 DESCRIPTION
76
77 This glyph draws an equilateral triangle when -point is defined.
78 It draws an isoceles triangle otherwise. It is possible to draw
79 the triangle with the base on the N, S, E, or W side.
80
81 =head2 OPTIONS
82
83 In addition to the common options, the following glyph-specific
84 options are recognized:
85
86 Option Description Default
87 ------ ----------- -------
88
89 -point If true, the triangle 0
90 will drawn at the center
91 of the range, and not scaled
92 to the feature width.
93
94 -orient On which side shall the S
95 base be? (NSEW)
96
97 =head1 BUGS
98
99 Please report them.
100
101 =head1 SEE ALSO
102
103 L<Bio::Graphics::Panel>,
104 L<Bio::Graphics::Glyph>,
105 L<Bio::Graphics::Glyph::arrow>,
106 L<Bio::Graphics::Glyph::cds>,
107 L<Bio::Graphics::Glyph::crossbox>,
108 L<Bio::Graphics::Glyph::diamond>,
109 L<Bio::Graphics::Glyph::dna>,
110 L<Bio::Graphics::Glyph::dot>,
111 L<Bio::Graphics::Glyph::ellipse>,
112 L<Bio::Graphics::Glyph::extending_arrow>,
113 L<Bio::Graphics::Glyph::generic>,
114 L<Bio::Graphics::Glyph::graded_segments>,
115 L<Bio::Graphics::Glyph::heterogeneous_segments>,
116 L<Bio::Graphics::Glyph::line>,
117 L<Bio::Graphics::Glyph::pinsertion>,
118 L<Bio::Graphics::Glyph::primers>,
119 L<Bio::Graphics::Glyph::rndrect>,
120 L<Bio::Graphics::Glyph::segments>,
121 L<Bio::Graphics::Glyph::ruler_arrow>,
122 L<Bio::Graphics::Glyph::toomany>,
123 L<Bio::Graphics::Glyph::transcript>,
124 L<Bio::Graphics::Glyph::transcript2>,
125 L<Bio::Graphics::Glyph::translation>,
126 L<Bio::Graphics::Glyph::triangle>,
127 L<Bio::DB::GFF>,
128 L<Bio::SeqI>,
129 L<Bio::SeqFeatureI>,
130 L<Bio::Das>,
131 L<GD>
132
133 =head1 AUTHOR
134
135 Allen Day E<lt>day@cshl.orgE<gt>.
136
137 Copyright (c) 2001 Cold Spring Harbor Laboratory
138
139 This library is free software; you can redistribute it and/or modify
140 it under the same terms as Perl itself. See DISCLAIMER.txt for
141 disclaimers of warranty.
142
143 =cut