1package Bio::Graphics::Glyph::dashed_line;
2
3use strict;
4use base qw(Bio::Graphics::Glyph::generic);
5
6sub my_description {
7    return <<END;
8This glyph draws a dashed line. The lengths of the dash and the space are configurable.
9The space can be filled with a different color, thus making a two-colored line.
10The junction of the two colors can be "sheared" creating an interlocking effect.
11END
12}
13
14sub my_options {
15    {
16	dash_size => [
17	    'integer',
18	    6,
19	    'Width of the dash.'],
20	space_size => [
21	    'integer',
22	    3,
23	    'Width of the space between dashes.'],
24	space_color => [
25	    'color',
26	    undef,
27	    'Color of the interval between dashes.',
28	    'Nothing will be drawn between dashes if undef.'],
29	shear => [
30	    'boolean',
31	    undef,
32	    'Whether to offset the dash and space to create an interlocking effect.'],
33    }
34}
35
36sub default_linewidth
37{
38  return 1;
39}
40
41sub default_dash_size
42{
43  return 6;
44}
45
46sub default_space_size
47{
48  return 3;
49}
50
51sub draw_component {
52  my $self = shift;
53  my $gd = shift;
54  my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_);
55
56  my $fg = $self->fgcolor;
57
58  my $midY = ($y1+$y2) / 2;
59
60  my $linewidth = defined $self->option('linewidth') ? $self->option('linewidth')  : $self->default_linewidth();
61  my $dash_size = defined $self->option('dash_size') ? $self->option('dash_size') : $self->default_dash_size();
62  my $space_size = defined $self->option('space_size') ? $self->option('space_size') : $self->default_space_size();
63  my $space_color = $self->option('space_color');
64  my $shear = $self->option('shear') || "";
65  $space_color = $self->factory->translate_color($space_color) if $space_color;
66
67  my ($x, $_y1, $_y2);
68  $x = $x1;
69  while ($x<$x2)
70  {
71    my $newX = $x+$dash_size;
72    $newX = $x2 if $newX > $x2;
73    if ($shear == 1)
74    {
75      $_y1 = $midY-$linewidth;
76      $_y2 = $midY;
77    }
78    else
79    {
80      $_y1 = $midY - $linewidth/2;
81      $_y2 = $midY + $linewidth/2;
82    }
83    $self->filled_box($gd,$x,$_y1,$newX,$_y2,$fg,$fg);
84    last if $newX >= $x2;
85
86    $x = $newX;
87    $newX = $x+$space_size;
88    $newX = $x2 if $newX > $x2;
89    if ($space_color)
90    {
91      if ($shear == 1)
92      {
93        $_y1 = $midY;
94        $_y2 = $midY+$linewidth;
95      }
96      else
97      {
98        $_y1 = $midY - $linewidth/2;
99        $_y2 = $midY + $linewidth/2;
100      }
101      $self->filled_box($gd, $x,$_y1,$newX,$_y2,$space_color,$space_color);
102    }
103    $x = $newX;
104  }
105}
106
1071;
108
109__END__
110
111=head1 NAME
112
113Bio::Graphics::Glyph::dashed_line - The "dashed line" glyph
114
115=head1 SYNOPSIS
116
117  See L<Bio::Graphics::Panel> and L<Bio::Graphics::Glyph>.
118
119=head1 DESCRIPTION
120
121This glyph draws a dashed line. The lengths of the dash and the space are configurable.
122The space can be filled with a different color, thus making a two-colored line.
123Also, the two colors can be "sheared".
124
125=head2 OPTIONS
126
127In addition to the common options, the following glyph-specific
128options are recognized:
129
130  Option      Description                  Default
131  ------      -----------                  -------
132
133  -dash_size  Width of one dash              6
134
135  -space_size Width of one space             3
136              between dashes
137
138  -space_color Color of the space            none
139              between dashes
140
141  -shear      Whether to use shearing       0
142              (1 or 0)
143
144  -linewidth  Standard option, but          1
145              important here
146
147=head1 BUGS
148
149Please report them.
150
151=head1 SEE ALSO
152
153L<Bio::Graphics::Panel>,
154L<Bio::Graphics::Glyph>,
155L<Bio::Graphics::Glyph::arrow>,
156L<Bio::Graphics::Glyph::cds>,
157L<Bio::Graphics::Glyph::crossbox>,
158L<Bio::Graphics::Glyph::diamond>,
159L<Bio::Graphics::Glyph::dna>,
160L<Bio::Graphics::Glyph::dot>,
161L<Bio::Graphics::Glyph::ellipse>,
162L<Bio::Graphics::Glyph::extending_arrow>,
163L<Bio::Graphics::Glyph::generic>,
164L<Bio::Graphics::Glyph::graded_segments>,
165L<Bio::Graphics::Glyph::heterogeneous_segments>,
166L<Bio::Graphics::Glyph::line>,
167L<Bio::Graphics::Glyph::pinsertion>,
168L<Bio::Graphics::Glyph::primers>,
169L<Bio::Graphics::Glyph::rndrect>,
170L<Bio::Graphics::Glyph::segments>,
171L<Bio::Graphics::Glyph::ruler_arrow>,
172L<Bio::Graphics::Glyph::toomany>,
173L<Bio::Graphics::Glyph::transcript>,
174L<Bio::Graphics::Glyph::transcript2>,
175L<Bio::Graphics::Glyph::translation>,
176L<Bio::Graphics::Glyph::triangle>,
177L<Bio::DB::GFF>,
178L<Bio::SeqI>,
179L<Bio::SeqFeatureI>,
180L<Bio::Das>,
181L<GD>
182
183=head1 AUTHOR
184
185Vsevolod (Simon) Ilyushchenko E<lt>simonf@cshl.eduE<gt>.
186
187Copyright (c) 2004 Cold Spring Harbor Laboratory
188
189This library is free software; you can redistribute it and/or modify
190it under the same terms as Perl itself.  See DISCLAIMER.txt for
191disclaimers of warranty.
192
193=cut
194