| 1 | package GO::View::GD; | ||
| 2 | |||
| 3 | ####################################################################### | ||
| 4 | # Module Name : GO/View/GD.pm | ||
| 5 | # | ||
| 6 | # Date created : Oct. 2003 | ||
| 7 | # | ||
| 8 | # Cared for by Shuai Weng <shuai@genome.stanford.edu> | ||
| 9 | # | ||
| 10 | # You may distribute this module under the same terms as perl itself | ||
| 11 | ####################################################################### | ||
| 12 | |||
| 13 | =pod | ||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | GO::View::GD - a helper class for GO::View to deal with the image | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | use GO::View::GD; | ||
| 22 | |||
| 23 | To instantiate a new GO::View::GD object, you may use | ||
| 24 | following syntax: | ||
| 25 | |||
| 26 | my $gd = GO::View::GD->new(width => $imgWidth, | ||
| 27 | height => $imgHeight); | ||
| 28 | |||
| 29 | |||
| 30 | my $im = $gd->im; | ||
| 31 | my $white = $gd->white; | ||
| 32 | my $red = $gd->red; | ||
| 33 | |||
| 34 | and more ...... | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | use strict; | ||
| 39 | use warnings; | ||
| 40 | use GD; | ||
| 41 | |||
| 42 | use vars qw ($PACKAGE $VERSION); | ||
| 43 | |||
| 44 | $PACKAGE = "GO::View::GD"; | ||
| 45 | $VERSION = 0.11; | ||
| 46 | |||
| 47 | ####################################################################### | ||
| 48 | sub new { ############ constructor ############################### | ||
| 49 | ####################################################################### | ||
| 50 | |||
| 51 | =head2 new | ||
| 52 | |||
| 53 | Title : new | ||
| 54 | Function : Creates a new GO::View::GD object | ||
| 55 | : recognized named parameters are height and width | ||
| 56 | both of which must be provided. | ||
| 57 | Returns : a GO::View::GD object | ||
| 58 | Args : the named parameters | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | my ($class, %args) = @_; | ||
| 63 | |||
| 64 | my $self = {}; | ||
| 65 | |||
| 66 | bless $self, $class; | ||
| 67 | |||
| 68 | if (!$args{'width'} || !$args{'height'}) { | ||
| 69 | |||
| 70 | die "The image width and height must be passed to $PACKAGE."; | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | $self->{'_im'} = new GD::Image($args{'width'}, $args{'height'}); | ||
| 75 | |||
| 76 | $self->{'_width'} = $args{'width'}; | ||
| 77 | $self->{'_height'} = $args{'height'}; | ||
| 78 | |||
| 79 | $self->_initColors; | ||
| 80 | |||
| 81 | return $self; | ||
| 82 | } | ||
| 83 | |||
| 84 | ####################################################################### | ||
| 85 | sub _initColors { | ||
| 86 | ####################################################################### | ||
| 87 | # This private method simply initializes some colors, and stores them within | ||
| 88 | # the object for subsequent retrieval | ||
| 89 | |||
| 90 | my ($self) = @_; | ||
| 91 | |||
| 92 | $self->{'_white'} = $self->im->colorAllocate(255, 255, 255); | ||
| 93 | $self->{'_white1'} = $self->im->colorAllocate(254, 254, 254); | ||
| 94 | |||
| 95 | $self->{'_black'} = $self->im->colorAllocate(0, 0, 0); | ||
| 96 | |||
| 97 | $self->{'_blue'} = $self->im->colorAllocate(0, 0, 255); | ||
| 98 | $self->{'_blue1'} = $self->im->colorAllocate(0, 0, 125); | ||
| 99 | $self->{'_blue2'} = $self->im->colorAllocate(0, 255, 255); | ||
| 100 | $self->{'_blue3'} = $self->im->colorAllocate(0, 204, 204); | ||
| 101 | $self->{'_blue4'} = $self->im->colorAllocate(80, 153, 255); | ||
| 102 | $self->{'_blue5'} = $self->im->colorAllocate(128, 156, 201); | ||
| 103 | |||
| 104 | $self->{'_lightBlue'} = $self->im->colorAllocate(127, 255, 255); | ||
| 105 | $self->{'_darkBlue'} = $self->im->colorAllocate(10, 80, 161); | ||
| 106 | |||
| 107 | $self->{'_darkGreen'} = $self->im->colorAllocate(47, 79, 47); | ||
| 108 | $self->{'_green'} = $self->im->colorAllocate(0, 255, 0); | ||
| 109 | $self->{'_green1'} = $self->im->colorAllocate(51, 160, 44); | ||
| 110 | $self->{'_green2'} = $self->im->colorAllocate(102, 255, 102); | ||
| 111 | $self->{'_green3'} = $self->im->colorAllocate(153, 212, 127); | ||
| 112 | $self->{'_green4'} = $self->im->colorAllocate(0, 255, 51); | ||
| 113 | $self->{'_green5'} = $self->im->colorAllocate(102, 153, 102); | ||
| 114 | |||
| 115 | |||
| 116 | $self->{'_grey'} = $self->im->colorAllocate(180, 180, 180); | ||
| 117 | $self->{'_darkGrey'} = $self->im->colorAllocate(102, 102, 102); | ||
| 118 | $self->{'_lightGrey'} = $self->im->colorAllocate(215, 215, 215); | ||
| 119 | |||
| 120 | $self->{'_magenta'} = $self->im->colorAllocate(255, 0, 255); | ||
| 121 | $self->{'_magenta1'} = $self->im->colorAllocate(255, 153, 255); | ||
| 122 | $self->{'_magenta2'} = $self->im->colorAllocate(127, 0, 255); | ||
| 123 | $self->{'_magenta3'} = $self->im->colorAllocate(204, 50, 153); | ||
| 124 | $self->{'_magenta4'} = $self->im->colorAllocate(188, 128, 189); | ||
| 125 | $self->{'_magenta5'} = $self->im->colorAllocate(129, 23, 136); | ||
| 126 | |||
| 127 | |||
| 128 | $self->{'_maroon'} = $self->im->colorAllocate(142, 35, 107); | ||
| 129 | |||
| 130 | $self->{'_orange'} = $self->im->colorAllocate(255, 175, 0); | ||
| 131 | $self->{'_orange1'} = $self->im->colorAllocate(255, 125, 0); | ||
| 132 | |||
| 133 | $self->{'_red'} = $self->im->colorAllocate(255, 0, 0); | ||
| 134 | $self->{'_red1'} = $self->im->colorAllocate(255, 152, 153); | ||
| 135 | $self->{'_red2'} = $self->im->colorAllocate(204, 0, 102); | ||
| 136 | $self->{'_red3'} = $self->im->colorAllocate(153, 0, 0); | ||
| 137 | $self->{'_red4'} = $self->im->colorAllocate(251, 128, 95); | ||
| 138 | |||
| 139 | $self->{'_tan1'} = $self->im->colorAllocate(252, 192, 167); | ||
| 140 | $self->{'_tan'} = $self->im->colorAllocate(235, 199, 158); | ||
| 141 | |||
| 142 | $self->{'_yellow'} = $self->im->colorAllocate(255, 255, 0); | ||
| 143 | $self->{'_yellow1'} = $self->im->colorAllocate(255, 204, 51); | ||
| 144 | $self->{'_yellow2'} = $self->im->colorAllocate(255, 204, 102); | ||
| 145 | $self->{'_yellow3'} = $self->im->colorAllocate(255, 204, 153); | ||
| 146 | |||
| 147 | $self->{'_chartreuse'} = $self->im->colorAllocate(204, 236, 244); | ||
| 148 | |||
| 149 | $self->{'_cenColor'} = $self->im->colorAllocate(0, 10, 10); | ||
| 150 | |||
| 151 | $self->{'_sagecolor1'} = $self->im->colorAllocate(255, 127, 0); | ||
| 152 | $self->{'_sagecolor2'} = $self->im->colorAllocate(127, 0, 255); | ||
| 153 | $self->{'_sagecolor3'} = $self->im->colorAllocate(207, 181, 59); | ||
| 154 | $self->{'_sagecolor4'} = $self->im->colorAllocate(204, 50, 153); | ||
| 155 | |||
| 156 | |||
| 157 | } | ||
| 158 | |||
| 159 | sub im { | ||
| 160 | |||
| 161 | =head2 im | ||
| 162 | |||
| 163 | This method returns the internal GD::Image object | ||
| 164 | |||
| 165 | =cut | ||
| 166 | |||
| 167 | $_[0]->{'_im'}; | ||
| 168 | |||
| 169 | } | ||
| 170 | |||
| 171 | sub height { | ||
| 172 | |||
| 173 | =head2 height | ||
| 174 | |||
| 175 | This method returns the height that was used to instantiate the object | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | $_[0]->{'_height'}; | ||
| 180 | |||
| 181 | } | ||
| 182 | |||
| 183 | sub width { | ||
| 184 | |||
| 185 | =head2 width | ||
| 186 | |||
| 187 | This method returns the width that was used to instantiate the object | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | $_[0]->{'_width'}; | ||
| 192 | |||
| 193 | } | ||
| 194 | |||
| 195 | sub white1 { $_[0]->{'_white1'} } | ||
| 196 | sub black { $_[0]->{'_black'} } | ||
| 197 | |||
| 198 | sub blue { $_[0]->{'_blue'} } | ||
| 199 | sub blue1 { $_[0]->{'_blue1'} } | ||
| 200 | sub blue2 { $_[0]->{'_blue2'} } | ||
| 201 | sub blue3 { $_[0]->{'_blue3'} } | ||
| 202 | sub blue4 { $_[0]->{'_blue4'} } | ||
| 203 | sub blue5 { $_[0]->{'_blue5'} } | ||
| 204 | |||
| 205 | sub lightBlue { $_[0]->{'_lightBlue'} } | ||
| 206 | sub darkBlue { $_[0]->{'_darkBlue'} } | ||
| 207 | |||
| 208 | sub darkGreen { $_[0]->{'_darkGreen'} } | ||
| 209 | sub green { $_[0]->{'_green'} } | ||
| 210 | sub green1 { $_[0]->{'_green1'} } | ||
| 211 | sub green2 { $_[0]->{'_green2'} } | ||
| 212 | sub green3 { $_[0]->{'_green3'} } | ||
| 213 | sub green4 { $_[0]->{'_green4'} } | ||
| 214 | sub green5 { $_[0]->{'_green5'} } | ||
| 215 | |||
| 216 | sub grey { $_[0]->{'_grey'} } | ||
| 217 | sub darkGrey { $_[0]->{'_darkGrey'} } | ||
| 218 | sub lightGrey { $_[0]->{'_lightGrey'} } | ||
| 219 | |||
| 220 | sub magenta { $_[0]->{'_magenta'} } | ||
| 221 | sub magenta1 { $_[0]->{'_magenta1'} } | ||
| 222 | sub magenta2 { $_[0]->{'_magenta2'} } | ||
| 223 | sub magenta3 { $_[0]->{'_magenta3'} } | ||
| 224 | sub magenta4 { $_[0]->{'_magenta4'} } | ||
| 225 | sub magenta5 { $_[0]->{'_magenta5'} } | ||
| 226 | |||
| 227 | sub maroon { $_[0]->{'_maroon'} } | ||
| 228 | |||
| 229 | sub orange { $_[0]->{'_orange'} } | ||
| 230 | sub orange1 { $_[0]->{'_orange1'} } | ||
| 231 | |||
| 232 | |||
| 233 | sub red { $_[0]->{'_red'} } | ||
| 234 | sub red1 { $_[0]->{'_red1'} } | ||
| 235 | sub red2 { $_[0]->{'_red2'} } | ||
| 236 | sub red3 { $_[0]->{'_red3'} } | ||
| 237 | sub red4 { $_[0]->{'_red4'} } | ||
| 238 | |||
| 239 | sub tan { $_[0]->{'_tan'} } | ||
| 240 | sub tan1 { $_[0]->{'_tan1'} } | ||
| 241 | |||
| 242 | sub white { $_[0]->{'_white'} } | ||
| 243 | |||
| 244 | sub yellow { $_[0]->{'_yellow'} } | ||
| 245 | sub yellow1 { $_[0]->{'_yellow1'} } | ||
| 246 | sub yellow2 { $_[0]->{'_yellow2'} } | ||
| 247 | sub yellow3 { $_[0]->{'_yellow3'} } | ||
| 248 | |||
| 249 | sub chartreuse { $_[0]->{'_chartreuse'} } | ||
| 250 | |||
| 251 | sub cenColor { $_[0]->{'_cenColor'} } | ||
| 252 | |||
| 253 | sub sagecolor1 { $_[0]->{'_sagecolor1'} } | ||
| 254 | sub sagecolor2 { $_[0]->{'_sagecolor2'} } | ||
| 255 | sub sagecolor3 { $_[0]->{'_sagecolor3'} } | ||
| 256 | sub sagecolor4 { $_[0]->{'_sagecolor4'} } | ||
| 257 | |||
| 258 | |||
| 259 | =pod | ||
| 260 | |||
| 261 | =head2 white1 | ||
| 262 | =head2 black | ||
| 263 | |||
| 264 | =head2 blue | ||
| 265 | =head2 blue1 | ||
| 266 | =head2 blue2 | ||
| 267 | =head2 blue3 | ||
| 268 | =head2 blue4 | ||
| 269 | =head2 blue5 | ||
| 270 | |||
| 271 | =head2 lightBlue | ||
| 272 | =head2 darkBlue | ||
| 273 | |||
| 274 | =head2 darkGreen | ||
| 275 | =head2 green | ||
| 276 | =head2 green1 | ||
| 277 | =head2 green2 | ||
| 278 | =head2 green3 | ||
| 279 | =head2 green4 | ||
| 280 | =head2 green5 | ||
| 281 | |||
| 282 | =head2 grey | ||
| 283 | =head2 darkGrey | ||
| 284 | =head2 lightGrey | ||
| 285 | |||
| 286 | =head2 magenta | ||
| 287 | =head2 magenta1 | ||
| 288 | =head2 magenta2 | ||
| 289 | =head2 magenta3 | ||
| 290 | =head2 magenta4 | ||
| 291 | =head2 magenta5 | ||
| 292 | |||
| 293 | =head2 maroon | ||
| 294 | |||
| 295 | =head2 orange | ||
| 296 | =head2 orange1 | ||
| 297 | |||
| 298 | |||
| 299 | =head2 red | ||
| 300 | =head2 red1 | ||
| 301 | =head2 red2 | ||
| 302 | =head2 red3 | ||
| 303 | =head2 red4 | ||
| 304 | |||
| 305 | =head2 tan | ||
| 306 | =head2 tan1 | ||
| 307 | |||
| 308 | =head2 white | ||
| 309 | |||
| 310 | =head2 yellow | ||
| 311 | =head2 yellow1 | ||
| 312 | =head2 yellow2 | ||
| 313 | =head2 yellow3 | ||
| 314 | |||
| 315 | =head2 chartreuse | ||
| 316 | |||
| 317 | =head2 cenColor | ||
| 318 | |||
| 319 | =head2 sagecolor1 | ||
| 320 | =head2 sagecolor2 | ||
| 321 | =head2 sagecolor3 | ||
| 322 | =head2 sagecolor4 | ||
| 323 | |||
| 324 | =cut | ||
| 325 | |||
| 326 | ###################################################################### | ||
| 327 | sub drawFrameWithLabelAndDate { | ||
| 328 | ###################################################################### | ||
| 329 | |||
| 330 | =head2 drawFrameWithLabelAndDate | ||
| 331 | |||
| 332 | This method draws a blue frame around the image with date at the right | ||
| 333 | bottom corner and image label on the left bottom corner if there is a | ||
| 334 | label passed in. The date and label will be printed in red | ||
| 335 | |||
| 336 | Usage: | ||
| 337 | |||
| 338 | $gd->drawFrameWithLabelAndDate; | ||
| 339 | |||
| 340 | Optional arguments: | ||
| 341 | |||
| 342 | 'date', which is a string indicating the date, otherwise the current | ||
| 343 | date will be determined and used. The date will be printed in red in | ||
| 344 | the lower right hand corner. | ||
| 345 | |||
| 346 | 'text', which is a string that can be used to label the image. This will | ||
| 347 | printed in the lower left hand corner of the image. | ||
| 348 | |||
| 349 | =cut | ||
| 350 | |||
| 351 | my ($self, %args) = @_; | ||
| 352 | |||
| 353 | my $date = $args{'date'}; | ||
| 354 | |||
| 355 | $self->im->rectangle(0, 0, $self->width - 1, $self->height - 1, $self->blue); | ||
| 356 | |||
| 357 | if (!$date) { | ||
| 358 | |||
| 359 | $date = localtime; # gives us something like : Wed Dec 3 14:52:53 2003 | ||
| 360 | |||
| 361 | # now grab the month, day, and year, and reformat | ||
| 362 | |||
| 363 | $date =~ s/^[^ ]+ +([^ ]+) +([0-9]+) .+ ([0-9]+)$/$1 $2\, $3/; | ||
| 364 | |||
| 365 | } | ||
| 366 | |||
| 367 | if ($args{'text'}) { | ||
| 368 | |||
| 369 | $self->im->string(gdSmallFont, 5, $self->height-15, $args{'text'}, $self->red); | ||
| 370 | |||
| 371 | } | ||
| 372 | |||
| 373 | $self->im->string(gdSmallFont, $self->width - length($date) * 6-10, | ||
| 374 | $self->height-15, $date, $self->red); | ||
| 375 | |||
| 376 | } | ||
| 377 | |||
| 378 | ###################################################################### | ||
| 379 | sub drawBar { | ||
| 380 | ###################################################################### | ||
| 381 | |||
| 382 | =head2 drawBar | ||
| 383 | |||
| 384 | This method draws a rectangle for a given coordinate set and creates a | ||
| 385 | link for the box if there is a linkUrl passed in. The link for the | ||
| 386 | box is in the form of text that can be placed in an image map on an | ||
| 387 | html page. The text for that is currently printed to STDOUT. | ||
| 388 | |||
| 389 | Usage: | ||
| 390 | |||
| 391 | $gd->drawBar(barColor => $gd->blue, | ||
| 392 | numX1 => $X1, | ||
| 393 | numX2 => $X2, | ||
| 394 | numY => $Y, | ||
| 395 | linkUrl => $linkUrl, | ||
| 396 | barHeight => $barHeight, | ||
| 397 | outline => 1, | ||
| 398 | arrow => 'up'); | ||
| 399 | |||
| 400 | Required Arguments: | ||
| 401 | |||
| 402 | barColor : The color of the box | ||
| 403 | numX1 : The left-hand x-coordinate of the box | ||
| 404 | numX2 : The right-hand x-coordinate of the box | ||
| 405 | numY : The top y coorinate of the box | ||
| 406 | |||
| 407 | Optional Arguments: | ||
| 408 | |||
| 409 | strand : ??? - left over from use in SGDs ORF Map | ||
| 410 | linkUrl : A url to which you would like the box to be linked | ||
| 411 | barHeight : The height of the box - will be used to determine the bottom | ||
| 412 | y-coordinate of the box - default is 4 pixels | ||
| 413 | outlineColor : The color in which to outline the box | ||
| 414 | onInfoText : Information text that can used for mouseovers | ||
| 415 | |||
| 416 | arrow : The type of arrowhead desired on the box. One of up, down, | ||
| 417 | left, right, which indicates the direction in which the arrow | ||
| 418 | head should point | ||
| 419 | arrowHeight : The height of the arrowhead | ||
| 420 | |||
| 421 | =cut | ||
| 422 | |||
| 423 | my ($self, %args) = @_; | ||
| 424 | |||
| 425 | my $barColor = $args{'barColor'} || $self->_handleMissingArgument('barColor'); | ||
| 426 | my $numX1 = $args{'numX1'} || $self->_handleMissingArgument('numX1'); | ||
| 427 | my $numX2 = $args{'numX2'} || $self->_handleMissingArgument('numX2'); | ||
| 428 | my $numY = $args{'numY'} || $self->_handleMissingArgument('numY'); | ||
| 429 | |||
| 430 | my $linkUrl = $args{'linkUrl'}; | ||
| 431 | my $strand = $args{'strand'}; | ||
| 432 | my $barHeight = $args{'barHeight'} || '4'; | ||
| 433 | my $outlineColor = $args{'outlineColor'}; | ||
| 434 | my $onInfoText = $args{'onInfoText'}; | ||
| 435 | my $arrow = $args{'arrow'}; | ||
| 436 | my $arrowHeight = $args{'arrowHeight'}; | ||
| 437 | |||
| 438 | my $numY1 = $numY; | ||
| 439 | my $numY2 = $numY1 + $barHeight; | ||
| 440 | |||
| 441 | $self->_drawBarWithLink($numX1, $numY1, $numX2, $numY2, | ||
| 442 | $barColor, $linkUrl, $strand, | ||
| 443 | $onInfoText, $outlineColor); | ||
| 444 | |||
| 445 | if ($arrow) { | ||
| 446 | my ($X1, $Y1, $X2, $Y2); | ||
| 447 | if ($arrow =~ /up/i) { | ||
| 448 | $X1 = $numX1; | ||
| 449 | $Y1 = $numY1; | ||
| 450 | $X2 = $numX2; | ||
| 451 | $Y2 = $Y1; | ||
| 452 | } | ||
| 453 | elsif ($arrow =~ /down/i) { | ||
| 454 | $X1 = $numX1; | ||
| 455 | $Y1 = $numY2; | ||
| 456 | $X2 = $numX2; | ||
| 457 | $Y2 = $Y1; | ||
| 458 | } | ||
| 459 | elsif ($arrow =~ /left/) { | ||
| 460 | $X1 = $numX1; | ||
| 461 | $Y1 = $numY1; | ||
| 462 | $X2 = $X1; | ||
| 463 | $Y2 = $numY2; | ||
| 464 | } | ||
| 465 | else { | ||
| 466 | $X1 = $numX2; | ||
| 467 | $Y1 = $numY1; | ||
| 468 | $X2 = $X1; | ||
| 469 | $Y2 = $numY2; | ||
| 470 | } | ||
| 471 | $self->_drawTriangle($barColor, $X1, $Y1, | ||
| 472 | $X2, $Y1, $arrow, $arrowHeight); | ||
| 473 | } | ||
| 474 | |||
| 475 | return $numX2+5; | ||
| 476 | |||
| 477 | } | ||
| 478 | |||
| 479 | |||
| 480 | ###################################################################### | ||
| 481 | sub drawName { | ||
| 482 | ###################################################################### | ||
| 483 | |||
| 484 | =head2 drawName | ||
| 485 | |||
| 486 | This method draws a string and creates a link for it if there is a | ||
| 487 | linkUrl passed in. The link is in the form of text that can be placed | ||
| 488 | in an image map on an html page. The text for that is currently | ||
| 489 | printed to STDOUT. | ||
| 490 | |||
| 491 | Usage: | ||
| 492 | |||
| 493 | $gd->drawName(name=>" = GO term with child(ren)", | ||
| 494 | nameColor=>$gd->black, | ||
| 495 | numX1=>$numX1, | ||
| 496 | numY=>$y-2); | ||
| 497 | |||
| 498 | Required Arguments: | ||
| 499 | |||
| 500 | name : The text that should be printed on the image | ||
| 501 | nameColor : The color in which the text should be written | ||
| 502 | numX1 : The X-coordinate where the text should be printed | ||
| 503 | numY : The Y-coordinate where the text should be printed | ||
| 504 | |||
| 505 | Optional Arguments | ||
| 506 | |||
| 507 | linkUrl : A url to which you would like the text to be linked | ||
| 508 | |||
| 509 | =cut | ||
| 510 | |||
| 511 | my ($self, %args) = @_; | ||
| 512 | |||
| 513 | my $name = $args{'name'} || $self->_handleMissingArgument('name'); | ||
| 514 | my $nameColor = $args{'nameColor'} || $self->_handleMissingArgument('nameColor'); | ||
| 515 | my $numX1 = $args{'numX1'} || $self->_handleMissingArgument('numX1'); | ||
| 516 | my $numY = $args{'numY'} || $self->_handleMissingArgument('numY'); | ||
| 517 | my $linkUrl = $args{'linkUrl'}; | ||
| 518 | |||
| 519 | $self->_drawNameWithLink($name, $nameColor, | ||
| 520 | $linkUrl, $numX1, | ||
| 521 | $numX1+length($name)*6, | ||
| 522 | $numY, $numY+8); | ||
| 523 | |||
| 524 | |||
| 525 | return $numX1+length($name)*6; | ||
| 526 | |||
| 527 | } | ||
| 528 | |||
| 529 | ################################################################ | ||
| 530 | sub imageMap{ | ||
| 531 | ################################################################ | ||
| 532 | |||
| 533 | =head2 imageMap | ||
| 534 | |||
| 535 | Title : imageMap | ||
| 536 | Usage : my $map = $goView->imageMap; | ||
| 537 | Function : returns the text that constitutes an image map for the | ||
| 538 | created image. | ||
| 539 | |||
| 540 | During creation of various glyphs, that have had a URL | ||
| 541 | passed in to which they could link, text that can be used | ||
| 542 | as an image map for the image, within a web page, will be | ||
| 543 | generated. When all glyphs have been added to the image, | ||
| 544 | you can retrieve the image map text. It then needs to be | ||
| 545 | wrapped in a <MAP>...</MAP> declaration, and the html that | ||
| 546 | displays the image will need to refer to the image, eg: | ||
| 547 | |||
| 548 | <MAP NAME='blah'> | ||
| 549 | |||
| 550 | _IMAGE_MAP_TEXT_HERE_ | ||
| 551 | |||
| 552 | </MAP> | ||
| 553 | <img src='http::/some.url.here/xxx/gif' usemap='#blah'> | ||
| 554 | |||
| 555 | Note that the map and the usemap tag have the same name. | ||
| 556 | |||
| 557 | Returns : a string | ||
| 558 | |||
| 559 | =cut | ||
| 560 | |||
| 561 | ######################################################################### | ||
| 562 | |||
| 563 | return $_[0]->{IMAGE_MAP}; | ||
| 564 | |||
| 565 | } | ||
| 566 | |||
| 567 | ################################################################ | ||
| 568 | sub _appendToMap{ | ||
| 569 | ################################################################ | ||
| 570 | |||
| 571 | =head2 _appendToMap | ||
| 572 | |||
| 573 | This protected method appends the passed in string onto the image | ||
| 574 | map that is generated for the image that is also created by this | ||
| 575 | module | ||
| 576 | |||
| 577 | Usage: | ||
| 578 | |||
| 579 | $self->_appendToMap($text); | ||
| 580 | |||
| 581 | =cut | ||
| 582 | |||
| 583 | ################################################################ | ||
| 584 | |||
| 585 | my ($self, $text) = @_; | ||
| 586 | |||
| 587 | $self->{IMAGE_MAP} .= $text if defined $text; | ||
| 588 | |||
| 589 | } | ||
| 590 | |||
| 591 | |||
| 592 | ##################################################################### | ||
| 593 | sub _drawTriangle { | ||
| 594 | ##################################################################### | ||
| 595 | # This method draws a triangle based on the given coordinate set. | ||
| 596 | # | ||
| 597 | my ($self, $color, $numX1, $numY1, $numX2, $numY2, | ||
| 598 | $arrow, $height) = @_; | ||
| 599 | |||
| 600 | if (!$height) { | ||
| 601 | if ($arrow =~ /(up|down)/i) { | ||
| 602 | $height = $numX2 - $numX1; | ||
| 603 | } | ||
| 604 | else { | ||
| 605 | $height = $numY2 - $numY1; | ||
| 606 | } | ||
| 607 | } | ||
| 608 | my ($numX, $numY, $midX, $midY); | ||
| 609 | if ($arrow =~ /up/i) { | ||
| 610 | $numX = ($numX1 + $numX2)/2; | ||
| 611 | $numY = ($numY1 + $numY2)/2 - $height; | ||
| 612 | $midX = $numX; | ||
| 613 | $midY = $numY + $height/2; | ||
| 614 | } | ||
| 615 | elsif ($arrow =~ /down/i) { | ||
| 616 | $numX = ($numX1 + $numX2)/2; | ||
| 617 | $numY = ($numY1 + $numY2)/2 + $height; | ||
| 618 | $midX = $numX; | ||
| 619 | $midY = $numY - $height/2; | ||
| 620 | } | ||
| 621 | elsif ($arrow =~ /left/i) { | ||
| 622 | $numX = ($numX1 + $numX2)/2 - $height; | ||
| 623 | $numY = ($numY1 + $numY2)/2; | ||
| 624 | $midX = $numX - $height/2; | ||
| 625 | $midY = $numY; | ||
| 626 | } | ||
| 627 | else { | ||
| 628 | $numX = ($numX1 + $numX2)/2 + $height; | ||
| 629 | $numY = ($numY1 + $numY2)/2; | ||
| 630 | $midX = $numX + $height/2; | ||
| 631 | $midY = $numY; | ||
| 632 | } | ||
| 633 | |||
| 634 | $self->im->line($numX1, $numY1, $numX2, $numY2, $color); | ||
| 635 | $self->im->line($numX1, $numY1, $numX, $numY, $color); | ||
| 636 | $self->im->line($numX2, $numY2, $numX, $numY, $color); | ||
| 637 | |||
| 638 | $self->im->fillToBorder($midX, $midY, $color, $color); | ||
| 639 | |||
| 640 | } | ||
| 641 | |||
| 642 | ###################################################################### | ||
| 643 | sub _drawBarWithLink { | ||
| 644 | ###################################################################### | ||
| 645 | # This method draws a box (bar) with a link. | ||
| 646 | |||
| 647 | my ($self, $numX1, $numY1, $numX2, $numY2, $barColor, | ||
| 648 | $linkUrl, $strand, $onInfoText, $outlineColor) = @_; | ||
| 649 | |||
| 650 | $onInfoText ||= ""; # avoid warnings | ||
| 651 | |||
| 652 | if (!$strand) { | ||
| 653 | |||
| 654 | $self->im->filledRectangle($numX1, $numY1, $numX2, $numY2, | ||
| 655 | $barColor); | ||
| 656 | |||
| 657 | if ($outlineColor) { | ||
| 658 | $self->im->rectangle($numX1, $numY1, $numX2, $numY2, | ||
| 659 | $outlineColor); | ||
| 660 | } | ||
| 661 | |||
| 662 | }else { | ||
| 663 | |||
| 664 | if (!$outlineColor) { $outlineColor = $barColor; } | ||
| 665 | |||
| 666 | my $midY = ($numY1+$numY2)/2; | ||
| 667 | |||
| 668 | if ($numX2 < $numX1 + 6) { | ||
| 669 | $numX2 = $numX1 + 6; | ||
| 670 | } | ||
| 671 | |||
| 672 | if ($strand =~ /^W/i || $strand == 1) { | ||
| 673 | |||
| 674 | $numX2 -= 4; | ||
| 675 | $self->im->line($numX1, $numY1, $numX1, $numY2, $outlineColor); | ||
| 676 | $self->im->line($numX2, $numY1, $numX2+4, $midY, $outlineColor); | ||
| 677 | $self->im->line($numX2, $numY2, $numX2+4, $midY, $outlineColor); | ||
| 678 | |||
| 679 | }else { | ||
| 680 | |||
| 681 | $numX1 += 4; | ||
| 682 | $self->im->line($numX2, $numY1, $numX2, $numY2, $outlineColor); | ||
| 683 | $self->im->line($numX1, $numY1, $numX1-4, $midY, $outlineColor); | ||
| 684 | $self->im->line($numX1, $numY2, $numX1-4, $midY, $outlineColor); | ||
| 685 | } | ||
| 686 | |||
| 687 | $self->im->line($numX1, $numY1, $numX2, $numY1, $outlineColor); | ||
| 688 | $self->im->line($numX1, $numY2, $numX2, $numY2, $outlineColor); | ||
| 689 | |||
| 690 | $self->im->fillToBorder(($numX1+$numX2)/2, $midY, | ||
| 691 | $outlineColor, $barColor); | ||
| 692 | |||
| 693 | } | ||
| 694 | |||
| 695 | if ($linkUrl) { | ||
| 696 | $numX1 = int($numX1); | ||
| 697 | $numX2 = int($numX2); | ||
| 698 | $numY1 = int($numY1); | ||
| 699 | $numY2 = int($numY2); | ||
| 700 | $self->_appendToMap("<AREA SHAPE='RECT' COORDS='$numX1,$numY1,$numX2,$numY2' HREF='$linkUrl' title=\"$onInfoText\">\n"); | ||
| 701 | } | ||
| 702 | } | ||
| 703 | |||
| 704 | ###################################################################### | ||
| 705 | sub _drawNameWithLink { | ||
| 706 | ###################################################################### | ||
| 707 | # This method draws a string with a link. | ||
| 708 | |||
| 709 | my ($self, $name, $nameColor, $linkUrl, $nX1, $nX2, $nY1, $nY2) = @_; | ||
| 710 | |||
| 711 | $self->im->string(gdSmallFont, $nX1, $nY1, $name, $nameColor); | ||
| 712 | |||
| 713 | if ($linkUrl) { | ||
| 714 | |||
| 715 | $nX1 = int($nX1); | ||
| 716 | $nX2 = int($nX2); | ||
| 717 | $nY1 = int($nY1); | ||
| 718 | $nY2 = int($nY2); | ||
| 719 | |||
| 720 | $self->_appendToMap("<AREA SHAPE=\"RECT\" COORDS=\"$nX1,$nY1,$nX2,$nY2\" HREF=\"$linkUrl\">\n"); | ||
| 721 | |||
| 722 | } | ||
| 723 | |||
| 724 | } | ||
| 725 | |||
| 726 | |||
| 727 | ###################################################################### | ||
| 728 | sub _handleMissingArgument { | ||
| 729 | ###################################################################### | ||
| 730 | # This method will die, with a message to indicate which argument is | ||
| 731 | # missing in which method, etc. if it finds a missing argument. | ||
| 732 | # | ||
| 733 | |||
| 734 | my ($self, $args) = @_; | ||
| 735 | |||
| 736 | my ($file, $line, $method) = (caller(1))[1..3]; | ||
| 737 | |||
| 738 | die "The argument '$args' must be passed to '$method' method.\n". | ||
| 739 | |||
| 740 | "Please add this argument to line $line in $file."; | ||
| 741 | |||
| 742 | } | ||
| 743 | |||
| 744 | 1; # to keep Perl happy | ||
| 745 | |||
| 746 | =pod | ||
| 747 | |||
| 748 | =head1 AUTHOR | ||
| 749 | |||
| 750 | Shuai Weng (shuai@genome.stanford.edu) | ||
| 751 | |||
| 752 | =cut | ||
| 753 | |||
| 754 | |||
| 755 | |||
| 756 | |||
| 757 | |||
| 758 | |||
| 759 | |||
| 760 | |||
| 761 |