"; int( (\$ymax - \$y)*\${\$self->size}[1]/(\$ymax-\$ymin) ); } # The move and draw subroutines. Arguments are in real world coordinates. sub lineTo { my \$self = shift; my (\$x,\$y,\$color) = @_; \$x=\$self->ii(\$x); \$y=\$self->jj(\$y); \$color = \$self->{'colors'}{\$color} if \$color=~/[A-Za-z]+/ && defined(\$self->{'colors'}{\$color}) ; # colors referenced by name works here. \$color = \$self->{'colors'}{'default_color'} unless defined(\$color); \$self->im->line(@{\$self->position},\$x,\$y,\$color); #warn "color is \$color"; @{\$self->position} = (\$x,\$y); } sub moveTo { my \$self = shift; my \$x=shift; my \$y=shift; \$x=\$self->ii(\$x); \$y=\$self->jj(\$y); #print "moving to \$x,\$y
"; @{\$self->position} = ( \$x,\$y ); } sub v_axis { my \$self = shift; @{\$self->{vaxis}}=@_; # y_value, color } sub h_axis { my \$self = shift; @{\$self->{haxis}}=@_; # x_value, color } sub h_ticks { my \$self = shift; my \$nudge =2; push(@{\$self->{hticks}},\$nudge,@_); # y-value, color, tick x-values. see save_image subroutine } sub v_ticks { my \$self = shift; my \$nudge =2; push(@{\$self->{vticks}},\$nudge,@_); # x-value, color, tick y-values. see save_image subroutine } sub h_grid { my \$self = shift; push(@{\$self->{hgrid}}, @_ ); #color, grid y values } sub v_grid { my \$self = shift; push(@{\$self->{vgrid}},@_ ); #color, grid x values } sub draw { my \$self = shift; my \$im =\$self->{'im'}; my @size = @{\$self->size}; my %colors =%{\$self->colors}; # make the background transparent and interlaced # \$im->transparent(\$colors{'white'}); \$im->interlaced('true'); # Put a black frame around the picture \$im->rectangle(0,0,\$size[0]-1,\$size[1]-1,\$colors{'black'}); # draw functions foreach my \$f (\$self->fn) { #\$self->draw_function(\$f); \$f->draw(\$self); # the graph is passed to the function so that the label can call back as needed. } # and fill the regions foreach my \$r (\$self->fillRegion) { my (\$x,\$y,\$color_name) = @{\$r}; my \$color = \${\$self->colors}{\$color_name}; \$self->im->fill(\$self->ii(\$x),\$self->jj(\$y),\$color); } #draw hticks my \$tk; my @ticks = @{\$self->{hticks}}; if (@ticks) { my \$nudge = shift(@ticks); my \$j = \$self->jj(shift(@ticks)); my \$tk_clr= \$self->{'colors'}{shift(@ticks)}; foreach \$tk (@ticks) { \$tk = \$self->ii(\$tk); # print "tk=\$tk\n"; \$self->im->line(\$tk,\$j+int(\$nudge),\$tk,\$j-int(\$nudge),\$tk_clr); } } #draw vticks @ticks = @{\$self->{vticks}}; if (@ticks) { my \$nudge = shift(@ticks); my \$i = \$self->ii(shift(@ticks)); my \$tk_clr= \$self->{'colors'}{shift(@ticks)}; foreach \$tk (@ticks) { \$tk = \$self->jj(\$tk); # print "tk=\$tk\n"; \$self->im->line(\$i+int(\$nudge),\$tk,\$i-int(\$nudge),\$tk,\$tk_clr); } } #draw vgrid my @grid = @{\$self->{vgrid}}; if (@grid) { my \$x_value; my \$grid_clr= \$self->{'colors'}{shift(@grid)}; foreach \$x_value (@grid) { \$x_value = \$self->ii(\$x_value); # scale #print "grid_line=\$grid_line\n"; \$self->im->dashedLine(\$x_value,0,\$x_value,\$self->{'size'}[1],\$grid_clr); } } #draw hgrid @grid = @{\$self->{hgrid}}; if (@grid) { my \$grid_clr= \$self->{'colors'}{shift(@grid)}; my \$y_value; foreach \$y_value (@grid) { \$y_value = \$self->jj(\$y_value); #print "y_value=\$y_value\n"; #print "width= \$self->{width}\n"; \$self->im->dashedLine(0,\$y_value,\$self->{'size'}[0],\$y_value,\$grid_clr); } } # draw axes if (defined \${\$self->{vaxis}}[0]) { my (\$x, \$color_name) = @{\$self->{vaxis}}; my \$color = \${\$self->colors}{\$color_name}; \$self->moveTo(\$x,\$self->ymin); \$self->lineTo(\$x,\$self->ymax,\$color); #print "draw vaxis", @{\$self->{vaxis}},"\n"; #\$self->im->line(0,0,300,300,\$color); } if (defined \$self->{haxis}[0]) { my (\$y, \$color_name) = @{\$self->{haxis}}; my \$color = \${\$self->colors}{\$color_name}; \$self->moveTo(\$self->xmin,\$y); \$self->lineTo(\$self->xmax,\$y,\$color); #print "draw haxis", @{\$self->{haxis}},"\n"; } # draw functions again foreach my \$f (\$self->fn) { #\$self->draw_function(\$f); \$f->draw(\$self); # the graph is passed to the function so that the label can call back as needed. } #draw labels my \$lb; foreach \$lb (\$self->lb) { \$lb->draw(\$self); # the graph is passed to the label so that the label can call back as needed. } #draw stamps my \$stamp; foreach \$stamp (\$self->stamps) { \$stamp->draw(\$self); # the graph is passed to the label so that the label can call back as needed. } my \$out; if (\$WWPlot::use_png) { \$out = \$im->png; } else { \$out = \$im->gif; } \$out; } sub AUTOLOAD { my \$self = shift; my \$type = ref(\$self) || die "\$self is not an object"; my \$name = \$WWPlot::AUTOLOAD; \$name =~ s/.*://; # strip fully-qualified portion unless (exists \$self->{'_permitted'}->{\$name} ) { die "Can't find '\$name' field in object of class \$type"; } if (@_) { return \$self->{\$name} = shift; } else { return \$self->{\$name}; } } sub DESTROY { # doing nothing about destruction, hope that isn't dangerous } sub save_image { my \$self = shift; warn "The method save_image is no longer supported. Use insertGraph(\\$graph)"; "The method save_image is no longer supported. Use insertGraph(\\$graph)"; } 1;