#======================================================== # GraphFrame #======================================================== package EnergyLevelGraphFrame; use MyTk::GraphFrame; @ISA = qw(GraphFrame); #公開したいサブルーチン #@EXPORT = qw(); use strict; #============================================================ # ローカル大局変数 #============================================================ my @PredefinedColors = ("black", "red", "blue", "brown", "purple", "violet", "cyan", "magenta", "green", "yellow", "pink", "orange1", "grey", "dark red", "dark blue", "brown4", "purple3", "dark violet", "dark cyan", "dark magenta", "dark green", "yellow4", "DeepPink1", "white"); my $nColors = @PredefinedColors; my $CurColor = 0; #============================================================ # 静的メンバー関数 #============================================================ #============================================================ # 変数等取得関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new($$) { my ($module, $mainwindow, $idx) = @_; my $this = {}; bless $this; # $this->SUPER::new($mainwindow, $idx); # $this->{'Canvas'} = $canvas; $this->{'MainWindow'} = $mainwindow; $idx = 0 unless($idx); my @DataArray; $this->{'DataArray'} = \@DataArray; my @array; $this->{'GraphScaleArray'} = \@array; my @SXArray; $this->{'XSynchronousGraphFrameArray'} = \@SXArray; my @SYArray; $this->{'YSynchronousGraphFrameArray'} = \@SYArray; $this->SetIndex($idx); $this->{'XCaption'} = "Energy / eV"; $this->{'YCaption'} = "Intensity / cps"; $this->AddXScale("xbottom", "x"); # $this->AddXScale("xtop", "x"); $this->AddYScale("yleft", "x"); # $this->AddYScale("yright", "x"); $this->SetLinesVisible(1, 1, 1, 1, 1, 1); $this->SetViewRange(0, 0, 1, 1); $CurColor = 0; return $this; } sub DESTROY { my $this = shift; # $this->SUPER::DESTROY(@_); } #============================================================ # 一般関数 #============================================================ sub Draw { my ($this, $canvas) = @_; $canvas = $this->Canvas() unless(defined $canvas); my $rect = $this->SUPER::Draw($canvas); my $pBandNo = $this->{'BandNo'}; my $pXConstant = $this->{'x0'}; my $XConstantName = $this->{'x0_Name'}; my $pBandEnergy = $this->{'y0'}; my $nBandGroup = $this->nDataArray(); # my $pDataArray = $this->{'DataArray'}; # my $pData = $pDataArray->[0]; my $pData = $this->{'pGraphData'}; my ($x0, $y0, $x1, $y1) = $this->GetPosition(); # my ($vx0, $vx1) = $this->GetViewXRange(); my ($vy0, $vy1) = $this->GetViewYRange(); my $BarBoxWidth = int(abs($x1 - $x0) / $nBandGroup); my %TagHash; for(my $id = 0 ; $id < $nBandGroup ; $id++) { #print "id=$id\n"; my $pEnergy = $pData->{"y$id"}; my $pOcc = $pData->{"Occupation$id"}; next unless($pEnergy); my $nData = @$pEnergy; #print "nData: $nData\n"; my $xbase = $x0 + $id*$BarBoxWidth; my $xbase0 = $xbase + $BarBoxWidth * 0.1; my $BarWidth = $BarBoxWidth * 0.8; for(my $i = 0 ; $i < $nData ; $i++) { my $eng = $pEnergy->[$i]; next unless(defined $eng); my $occ = $pOcc->[$i]; $occ = 1.0 unless(defined $occ); my ($x, $y) = $this->ValueToPosition(0, $eng); #print "y: $y0, $y, $y1\n"; my $r = ($y - $y0) / ($y1 - $y0); if(0 <= $r and $r <= 1.0) { my $str = "E=" . sprintf("%7.3f", $eng) . " Ry Ne=" . sprintf("%7.3f", $occ+0.0); my $tag = "$eng-$id-$i"; $tag =~ s/\s/-/g; $TagHash{$tag} = $str; #print "str: $str, $tag\n"; my $w1 = $BarWidth * $occ / 2.0; my $w2 = $BarWidth - $w1; $canvas->DrawLine($xbase0, $y, $xbase0+$w1, $y, 1, "black", $tag); $canvas->DrawLine($xbase0+$w1, $y, $xbase0+$w1+$w2, $y, 1, "grey", $tag); $canvas->bind($tag, "", [\&HoverItem, $this, "Enter", $str, $y]); $canvas->bind($tag, "", [\&HoverItem, $this, "Leave", $str, $y]); } } } $this->mw()->Balloon()->attach($canvas, -balloonposition => 'mouse', -msg => \%TagHash); return $rect; } sub HoverItem { my ($canvas, $this, $event, $str, $y) = @_; if($event eq 'Enter') { $canvas->delete("SelEnergyLevel"); # my $GraphFrameArray = $this->GetGraphFrameArray(); # my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $pGraphFrame = $this; my ($x00, $y00, $x01, $y01) = $this->GetPosition(); # my ($x00, $y00, $x01, $y01) = $pGraphFrame->[0]->GetPosition(); # $canvas->DrawLine($x00, $y, $x01, $y, 1, "grey", "SelEnergyLevel"); $this->mw()->WriteStatusBar($str); } elsif($event eq 'Leave') { $canvas->delete("SelEnergyLevel"); $this->mw()->WriteStatusBar(''); } } 1;