diff -Naur ChartPlugin_20021011/lib/TWiki/Plugins/ChartPlugin/Chart.pm ChartPlugin_20021011_local/lib/TWiki/Plugins/ChartPlugin/Chart.pm --- ChartPlugin_20021011/lib/TWiki/Plugins/ChartPlugin/Chart.pm Thu Oct 10 19:05:47 2002 +++ ChartPlugin_20021011_local/lib/TWiki/Plugins/ChartPlugin/Chart.pm Sat Jul 5 13:09:23 2003 @@ -140,7 +140,7 @@ setDataTypes getDataTypes setXaxis getXaxis setYaxis getYaxis - setNumYGrids getNumYGrids + setNumYGrids getYLog setYLog getNumYGrids setXgrid getXgrid setYgrid getYgrid setDataLabels getDataLabels @@ -176,6 +176,7 @@ $this->setFont("legend", GD::gdSmallFont());# Set legend font $this->setFont("data", GD::gdSmallFont()); # Set data values font $this->setNumYGrids(10); + $this->setYLog("off"); $this->setNumDigits(0); return $this; } @@ -267,6 +268,22 @@ sub setNumYGrids { my ($this, $numYGrids) = @_; $$this{NUM_Y_GRIDS} = $numYGrids; } sub getNumYGrids { my ($this) = @_; return $$this{NUM_Y_GRIDS}; } +sub setYLog { my ($this, $YLog) = @_; $$this{Y_LOG} = $YLog; } +sub getYLog { my ($this) = @_; return $$this{Y_LOG}; } + +sub ifylog { + my ($this, $val) = @_; + my $orig=$val; + if ( $$this{Y_LOG} eq "on" ) { + if ($val > 0) { + $val=log($val)/log(10); + } else { + $val=0; + } + } + return $val; +} + sub setXgrid { my ($this, $xGrid) = @_; $$this{X_GRID} = $xGrid; } sub getXgrid { my ($this) = @_; return $$this{X_GRID}; } @@ -449,6 +466,8 @@ my $imageWidth = $this->getImageWidth(); my $imageHeight = $this->getImageHeight(); + my $yLog = $this->getYLog(); + # Create empty image to get filled in later. my $im = new GD::Image($imageWidth, $imageHeight); $this->setImage($im); @@ -479,8 +498,8 @@ my @allocatedColors = $this->computeFinalColors(); # Get the Y min/max values to be charted. - my $yMin = $this->getYmin(); - my $yMax = $this->getYmax(); + #my $yMin = $this->ifylog($this->getYmin()); + #my $yMax = $this->ifylog($this->getYmax()); # Calculate the initial pixel locations of lower left side (xLL/yLL) # and upper right side (xUR/yUR) of the chart with respect to the @@ -517,9 +536,15 @@ # number of digits to use when displaying the Y axis labels. $this->computeNumDigits(); } - $yAxisMin = $this->getYminOfData() if (! defined($yAxisMin)); - $yAxisMax = $this->getYmaxOfData() if (! defined($yAxisMax)); - $numYGrids = $this->getNumYGrids(); + $yAxisMin = $this->ifylog($this->getYminOfData()) if (! defined($yAxisMin)); + $yAxisMax = $this->ifylog($this->getYmaxOfData()) if (! defined($yAxisMax)); + if ($yLog eq "on") { $yAxisMax = int($yAxisMax) + 1; } + + if ($yLog eq "on") { + $numYGrids = int($yAxisMax); + } else { + $numYGrids = $this->getNumYGrids(); + } $yAxisDecimalDigits = $this->getNumDigits(); my $chartHeight = $yAxisMax - $yAxisMin; # Check to see if either the user specified ymin/ymax values, or the @@ -546,11 +571,16 @@ my $maxLength = 0; my $len; for my $yAxisIndex (0..$numYGrids) { - my $text = _printNumber($yaxis, $yAxisDecimalDigits); - $yLabels[$yAxisIndex] = $text; - $len = length ($text); - $maxLength = $len if ($len > $maxLength); - $yaxis += $labelInc; + my $text = ""; + if ($yLog eq "on") { + $text = _printNumber(10 ** $yAxisIndex, $yAxisDecimalDigits); + } else { + $text = _printNumber($yaxis, $yAxisDecimalDigits); + } + $yLabels[$yAxisIndex] = $text; + $len = length ($text); + $maxLength = $len if ($len > $maxLength); + $yaxis += $labelInc; } $xLL += $this->getFontWidth("yaxis") * $maxLength; } @@ -616,8 +646,8 @@ my $color = $allocatedColors[$dataSet]; # Draw the line (if an area, it gets filled in below). for my $xIndex (0..($numDataPoints - 2)) { - my $currentValue = $row[$xIndex]; - my $nextValue = $row[$xIndex + 1]; + my $currentValue = $this->ifylog($row[$xIndex]); + my $nextValue = $this->ifylog($row[$xIndex + 1]); my $x1 = $xLL + ($xDrawInc * $xIndex); my $y1 = $yLL - ($currentValue - $yAxisMin) * $yPixelsPerValue; @@ -641,8 +671,8 @@ # area that has separate regions. if ($dataTypes[$dataSet] eq "area") { for my $xIndex (0..($numDataPoints - 2)) { - my $currentValue = $row[$xIndex]; - my $nextValue = $row[$xIndex + 1]; + my $currentValue = $this->ifylog($row[$xIndex]); + my $nextValue = $this->ifylog($row[$xIndex + 1]); my $x1 = $xLL + ($xDrawInc * $xIndex); my $y1 = $yLL - ($currentValue - $yAxisMin) * $yPixelsPerValue; my $x2 = $xLL + ($xDrawInc * ($xIndex + 1)); diff -Naur ChartPlugin_20021011/lib/TWiki/Plugins/ChartPlugin.pm ChartPlugin_20021011_local/lib/TWiki/Plugins/ChartPlugin.pm --- ChartPlugin_20021011/lib/TWiki/Plugins/ChartPlugin.pm Fri Oct 11 10:12:17 2002 +++ ChartPlugin_20021011_local/lib/TWiki/Plugins/ChartPlugin.pm Sat Jul 5 13:09:16 2003 @@ -333,6 +333,9 @@ # See if the parameter 'numygrids' is available. $chart->setNumYGrids( $this->_Parameters->getParameter( "numygrids", $defaultNumYGrids) ); + # See if the parameter 'numygrids' is available. + $chart->setYLog( $this->_Parameters->getParameter( "ylog", "off") ); + # See if the parameter 'xgrid' is available. my $xGrid = $this->_Parameters->getParameter( "xgrid", "dot"); $chart->setXgrid($xGrid);