1#========================================================================== 2# Copyright (c) 1995-1998 Martien Verbruggen 3#-------------------------------------------------------------------------- 4# 5# Name: 6# GD::Graph::points.pm 7# 8# $Id: points.pm,v 1.13 2005/12/14 04:13:32 ben Exp $ 9# 10#========================================================================== 11 12package GD::Graph::points; 13 14($GD::Graph::points::VERSION) = '$Revision: 1.13 $' =~ /\s([\d.]+)/; 15 16use strict; 17 18use GD::Graph::axestype; 19use GD::Graph::utils qw(:all); 20 21@GD::Graph::points::ISA = qw( GD::Graph::axestype ); 22 23# PRIVATE 24sub draw_data_set 25{ 26 my $self = shift; 27 my $ds = shift; 28 29 my @values = $self->{_data}->y_values($ds) or 30 return $self->_set_error("Impossible illegal data set: $ds", 31 $self->{_data}->error); 32 33 # Pick a colour 34 my $dsci = $self->set_clr($self->pick_data_clr($ds)); 35 my $type = $self->pick_marker($ds); 36 37 for (my $i = 0; $i < @values; $i++) 38 { 39 next unless defined $values[$i]; 40 my ($xp, $yp); 41 if (defined($self->{x_min_value}) && defined($self->{x_max_value})) 42 { 43 ($xp, $yp) = $self->val_to_pixel( 44 $self->{_data}->get_x($i), $values[$i], $ds); 45 } 46 else 47 { 48 ($xp, $yp) = $self->val_to_pixel($i+1, $values[$i], $ds); 49 } 50 $self->marker($xp, $yp, $type, $dsci ); 51 $self->{_hotspots}->[$ds]->[$i] = 52 ['rect', $self->marker_coordinates($xp, $yp)]; 53 } 54 55 return $ds; 56} 57 58# Pick a marker type 59 60sub pick_marker # number 61{ 62 my $self = shift; 63 my $num = shift; 64 65 ref $self->{markers} ? 66 $self->{markers}[ $num % (1 + $#{$self->{markers}}) - 1 ] : 67 ($num % 8) || 8; 68} 69 70# Draw a marker 71 72sub marker_coordinates 73{ 74 my $self = shift; 75 my ($xp, $yp) = @_; 76 return ( 77 $xp - $self->{marker_size}, 78 $xp + $self->{marker_size}, 79 $yp + $self->{marker_size}, 80 $yp - $self->{marker_size}, 81 ); 82} 83 84sub marker # $xp, $yp, $type, $colourindex 85{ 86 my $self = shift; 87 my ($xp, $yp, $mtype, $mclr) = @_; 88 return unless defined $mclr; 89 90 my ($l, $r, $b, $t) = $self->marker_coordinates($xp, $yp); 91 92 MARKER: { 93 94 ($mtype == 1) && do 95 { # Square, filled 96 $self->{graph}->filledRectangle($l, $t, $r, $b, $mclr); 97 last MARKER; 98 }; 99 ($mtype == 2) && do 100 { # Square, open 101 $self->{graph}->rectangle($l, $t, $r, $b, $mclr); 102 last MARKER; 103 }; 104 ($mtype == 3) && do 105 { # Cross, horizontal 106 $self->{graph}->line($l, $yp, $r, $yp, $mclr); 107 $self->{graph}->line($xp, $t, $xp, $b, $mclr); 108 last MARKER; 109 }; 110 ($mtype == 4) && do 111 { # Cross, diagonal 112 $self->{graph}->line($l, $b, $r, $t, $mclr); 113 $self->{graph}->line($l, $t, $r, $b, $mclr); 114 last MARKER; 115 }; 116 ($mtype == 5) && do 117 { # Diamond, filled 118 $self->{graph}->line($l, $yp, $xp, $t, $mclr); 119 $self->{graph}->line($xp, $t, $r, $yp, $mclr); 120 $self->{graph}->line($r, $yp, $xp, $b, $mclr); 121 $self->{graph}->line($xp, $b, $l, $yp, $mclr); 122 $self->{graph}->fillToBorder($xp, $yp, $mclr, $mclr); 123 last MARKER; 124 }; 125 ($mtype == 6) && do 126 { # Diamond, open 127 $self->{graph}->line($l, $yp, $xp, $t, $mclr); 128 $self->{graph}->line($xp, $t, $r, $yp, $mclr); 129 $self->{graph}->line($r, $yp, $xp, $b, $mclr); 130 $self->{graph}->line($xp, $b, $l, $yp, $mclr); 131 last MARKER; 132 }; 133 ($mtype == 7) && do 134 { # Circle, filled 135 $self->{graph}->arc($xp, $yp, 2 * $self->{marker_size}, 136 2 * $self->{marker_size}, 0, 360, $mclr); 137 $self->{graph}->fillToBorder($xp, $yp, $mclr, $mclr); 138 last MARKER; 139 }; 140 ($mtype == 8) && do 141 { # Circle, open 142 $self->{graph}->arc($xp, $yp, 2 * $self->{marker_size}, 143 2 * $self->{marker_size}, 0, 360, $mclr); 144 last MARKER; 145 }; 146 ($mtype == 9) && do 147 { # Horizontal line 148 $self->{graph}->line($l, $yp, $r, $yp, $mclr); 149 last MARKER; 150 }; 151 ($mtype == 10) && do 152 { # vertical line 153 $self->{graph}->line($xp, $t, $xp, $b, $mclr); 154 last MARKER; 155 }; 156 } 157} 158 159sub draw_legend_marker 160{ 161 my $self = shift; 162 my $n = shift; 163 my $x = shift; 164 my $y = shift; 165 166 my $ci = $self->set_clr($self->pick_data_clr($n)); 167 168 my $old_ms = $self->{marker_size}; 169 my $ms = _min($self->{legend_marker_height}, $self->{legend_marker_width}); 170 171 ($self->{marker_size} > $ms/2) and $self->{marker_size} = $ms/2; 172 173 $x += int($self->{legend_marker_width}/2); 174 $y += int($self->{lg_el_height}/2); 175 176 $n = $self->pick_marker($n); 177 178 $self->marker($x, $y, $n, $ci); 179 180 $self->{marker_size} = $old_ms; 181} 182 183"Just another true value"; 184