#======================================================== # PlotData #======================================================== package PlotData; #@ISA = qw(Tk::Frame); #公開したいサブルーチン #@EXPORT = qw(); use strict; use Rect; sub nData { my $pX=shift->GetXArrayRef(); return scalar @$pX; } sub Visible { return shift->{'Visible'}; } sub SetVisible { my ($this,$f)=@_; return shift->{'Visible'} = $f; } sub GetXArrayRef { return shift->{XDataArray}; } sub GetYArrayRef { return shift->{YDataArray}; } sub GetIArrayRef { return shift->{IDataArray}; } sub GetTagArrayRef { return shift->{TagArray}; } sub GetLine { return shift->{'Line'}; } sub GetSymbol { return shift->{'Symbol'}; } sub GetSymbol2 { return shift->{'Symbol2'}; } sub GetOption { return shift->{'Option'}; } sub SetXName { my ($this,$name)=@_; return $this->{'XName'} = $name; } sub XName { return shift->{'XName'}; } sub GetXName { return shift->{'XName'}; } sub SetYName { my ($this,$name)=@_; return $this->{'YName'} = $name; } sub YName { return shift->{'YName'}; } sub GetYName { return shift->{'YName'}; } sub GetXMinMax { my $this = shift; return ($this->{'XMin'}, $this->{'XMax'}); } sub GetYMinMax { my $this = shift; return ($this->{'YMin'}, $this->{'YMax'}); } sub GetMinMax { my $this = shift; return ($this->{'XMin'}, $this->{'XMax'}, $this->{'YMin'}, $this->{'YMax'}); } sub X { my ($this,$i)=@_; return $this->GetXArrayRef()->[$i]; } sub Y { my ($this,$i)=@_; return $this->GetYArrayRef()->[$i]; } sub SetX { my ($this, $i, $x) = @_; my $pX = $this->GetXArrayRef(); return $pX->[$i] = $x; } sub SetY { my ($this, $i, $y) = @_; my $pY = $this->GetYArrayRef(); return $pY->[$i] = $y; } sub AddData { my ($this, $x, $y) = @_; my $n = $this->nData(); $this->SetX($n, $x); $this->SetY($n, $y); } sub ClearAll { my ($this) = @_; my $pX = $this->GetXArrayRef(); my $pY = $this->GetYArrayRef(); @$pX = (); @$pY = (); $this->CalMinMax(); } #============================================================ # コンストラクタ、デストラクタ #============================================================ BEGIN { } sub new { my ($module) = @_; my $this = {}; bless $this; my @XArray; my @YArray; $this->{'XDataArray'} = \@XArray; $this->{'YDataArray'} = \@YArray; $this->{'Line'} = new Line; $this->{'Symbol'} = new Symbol; $this->{'Option'} = ''; $this->{'XName'} = ''; $this->{'YName'} = ''; $this->{'Visible'} = 1; return $this; } sub DESTROY { my $this = shift; # $this->SUPER::DESTROY(@_); } sub nXDataArray { my $this = shift; for(my $i = 0 ; ; $i++) { return $i unless($this->GetXArrayRef()->[$i]); ; } } sub nYDataArray { my $this = shift; for(my $i = 0 ; ; $i++) { return $i unless($this->GetYArrayRef()->[$i]); } } sub SetPlotData { my ($this, $pXDataArray, $pYDataArray, $LineWidth, $LineColor, $SymbolType, $SymbolSize, $SymbolFillColor, $SymbolLineWidth, $SymbolLineColor, $Option) = @_; # $Option: "XAutoSkip" #print "a LineWidth: $LineWidth SymbolType: $SymbolType\n"; return unless($pXDataArray); return unless($pYDataArray); $this->{'XDataArray'} = $pXDataArray; $this->{'YDataArray'} = $pYDataArray; $this->{'Line'} = new Line; $this->{'Symbol'} = new Symbol; $this->{'Line'}->SetStyle($LineWidth, $LineColor) if($LineWidth); $this->{'Symbol'}->SetStyle($SymbolType, $SymbolSize, $SymbolFillColor, $SymbolLineWidth, $SymbolLineColor) if($SymbolType); $this->{'Option'} = $Option; $this->CalMinMax(); } sub SetDiffractionData { my ($this, $pX, $pY, $pI, $pTag, $SymbolType1, $SymbolSize1, $SymbolColor1, $SymbolType2, $SymbolSize2, $SymbolColor2, $Option) = @_; return if(!$pX or !$pY); $this->{XDataArray} = $pX; $this->{YDataArray} = $pY; $this->{IDataArray} = $pI; $this->{TagArray} = $pTag; # $this->{SymbolType1} = new SymbolType1; # $this->{SymbolSize1} = new SymbolSize1; # $this->{SymbolColor1} = new SymbolColor1; # $this->{SymbolType2} = new SymbolType2; # $this->{SymbolSize2} = new SymbolSize2; # $this->{SymbolColor2} = new SymbolColor2; $this->{Line} = new Line; $this->{Symbol} = new Symbol; $this->{Symbol2} = new Symbol; $this->{Option} = $Option; # $this->{Line}->SetStyle(0, '') if($LineWidth); $this->{Symbol}->SetStyle($SymbolType1, $SymbolSize1, $SymbolColor1, 0, $SymbolColor1) if($SymbolType1); $this->{Symbol2}->SetStyle($SymbolType2, $SymbolSize2, $SymbolColor2, 0, $SymbolColor2) if($SymbolType2); $this->CalMinMax(); } sub CalXMinMax { my ($this) = @_; my $pXArray = $this->{'XDataArray'}; return unless($pXArray); my $nData = scalar @$pXArray; return (0, 0) if($nData <= 0); my $min = $pXArray->[0]; my $max = $min; for(my $i = 1 ; $i < $nData ; $i++) { next if(!defined $pXArray->[$i] or $pXArray->[$i] eq ''); $min = $pXArray->[$i] if(!defined $min or $min > $pXArray->[$i]); $max = $pXArray->[$i] if(!defined $max or $max < $pXArray->[$i]); } $this->{'XMin'} = $min; $this->{'XMax'} = $max; return ($min, $max); } sub CalYMinMax { my ($this) = @_; my $pYArray = $this->{'YDataArray'}; return unless($pYArray); my $nData = scalar @$pYArray; return (0, 0) if($nData <= 0); my $min = $pYArray->[0]; my $max = $min; for(my $i = 1 ; $i < $nData ; $i++) { next if(!defined $pYArray->[$i]); # or $pYArray->[$i] eq ''); $min = $pYArray->[$i] if(!defined $min or $min > $pYArray->[$i]); $max = $pYArray->[$i] if(!defined $max or $max < $pYArray->[$i]); } $this->{'YMin'} = $min; $this->{'YMax'} = $max; return ($min, $max); } sub CalMinMax { my ($this) = @_; my ($xmin, $xmax) = $this->CalXMinMax(); my ($ymin, $ymax) = $this->CalYMinMax(); #print "min,max: $xmin, $xmax y: $ymin, $ymax\n"; } 1;