Gtk2-Ex-Graph-GD

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/Graph/GD.pm  view on Meta::CPAN

		my $j=0;
		foreach my $hotspot (@$datameasure) {
			my ($name, @coords) = @$hotspot;
			if (_on_the_line($x, $y, @coords)) {
				my $xvalue0 = $self->{graphdata}->[0]->[$j-1];
				my $yvalue0 = $self->{graphdata}->[$i+1]->[$j-1];
				my $xvalue1 = $self->{graphdata}->[0]->[$j];
				my $yvalue1 = $self->{graphdata}->[$i+1]->[$j];
				my $measure = $self->{graphlegend}->[$i];
				return [$measure, $xvalue0, $yvalue0, $xvalue1, $yvalue1];
			}
			$j++;
		} 
		$i++;	
	}
	$self->{tooltip}->{window}->hide;
	$self->{tooltip}->{displayed} = FALSE;
}

sub _on_the_line {
	my ($x, $y, @linecoords) = @_;
	if (($x <= $linecoords[0] and  $x <= $linecoords[2]) or
		($x >= $linecoords[0] and  $x >= $linecoords[2]) or
		($y <= $linecoords[1] and  $y <= $linecoords[3]) or
		($y >= $linecoords[1] and  $y >= $linecoords[3]) ){
		return FALSE;
	}
	my $slope_diff = 
		($linecoords[1]-$linecoords[3])/($linecoords[0]-$linecoords[2]) 
		- ($linecoords[3]-$y)/($linecoords[2]-$x);
	if ($slope_diff > -0.1 and $slope_diff < 0.1) {
		return TRUE;
	}
	return FALSE;	
}

sub _check_bars_hotspot {
	my ($self, $x, $y) = @_;
	my $i=0;
	my $hotspotlist = $self->{hotspotlist};
	foreach my $datameasure (@$hotspotlist){
		my $j=0;
		foreach my $hotspot (@$datameasure) {			
			my ($name, @coords) = @$hotspot;
			if ($x >= $coords[0] && $x <= $coords[2] && $y >= $coords[1] && $y <= $coords[3]) {
				my $xvalue = $self->{graphdata}->[0]->[$j];
				my $yvalue = $self->{graphdata}->[$i+1]->[$j];
				my $measure = $self->{graphlegend}->[$i];
				return [$measure, $xvalue, $yvalue];
			} 
			$j++;	
		}
		$i++;
	}
	$self->{tooltip}->{window}->hide;
	$self->{tooltip}->{displayed} = FALSE;
}

sub _create_optionsmenu {
	my ($self) = @_;
	my $menu = Gtk2::Menu->new();

	my $bars = Gtk2::MenuItem->new("bars");
	my $lines = Gtk2::MenuItem->new("lines");
	my $linespoints = Gtk2::MenuItem->new("lines with points");
	my $area = Gtk2::MenuItem->new("area");
	my $pie = Gtk2::MenuItem->new("pie");
	my $cumulate = Gtk2::MenuItem->new("cumulate");

	$bars->signal_connect(activate => 
		sub { 
			$self->_set_type('bars');
			$self->_refresh;
		}
	);
	$lines->signal_connect(activate => 
		sub { 
			$self->_set_type('lines');
			$self->_refresh;
		}
	);
	$linespoints->signal_connect(activate => 
		sub { 
			$self->_set_type('linespoints');
			$self->_refresh;
		}
	);
	$area->signal_connect(activate => 
		sub { 
			$self->_set_type('area');
			$self->_refresh;
		}
	);
	$pie->signal_connect(activate => 
		sub { 
			$self->_set_type('pie');
			$self->_refresh;
		}
	);
	$cumulate->signal_connect(activate => 
		sub {
			if (exists($self->{graphhash}->{cumulate})) {
				$self->{graphhash}->{cumulate} = !$self->{graphhash}->{cumulate};
			} else {
				$self->{graphhash}->{cumulate} = TRUE;
			}
			$self->_set_type($self->{graphtype});
			$self->_refresh;
		}
	);
	
	$bars->show();
	$lines->show();
	$linespoints->show();
	$area->show();
	$pie->show();
	$cumulate->show();

	$menu->append($bars);
	$menu->append($lines);
	$menu->append($linespoints);
	$menu->append($area);
	$menu->append($pie);
	$menu->append($cumulate);
	
	return $menu;
}



( run in 0.584 second using v1.01-cache-2.11-cpan-39bf76dae61 )