From 51e565c1913fab6676a4b58d5e42ebcd55eaef2e Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 14 Aug 2009 11:20:32 +0200 Subject: [PATCH] Updated jpgraph classes to latest version 3.0.2, this also removed depreceated warnings in php 5.3 --- src/classes/jpgraph/gd_image.inc.php | 2546 ++--- src/classes/jpgraph/jpg-config.inc.php | 169 +- src/classes/jpgraph/jpgraph.php | 9219 ++++++++--------- src/classes/jpgraph/jpgraph_bar.php | 1787 ++-- .../jpgraph/jpgraph_errhandler.inc.php | 479 +- src/classes/jpgraph/jpgraph_legend.inc.php | 420 + src/classes/jpgraph/jpgraph_line.php | 1034 +- src/classes/jpgraph/jpgraph_pie.php | 2250 ++-- src/classes/jpgraph/jpgraph_pie3d.php | 1558 +-- src/classes/jpgraph/jpgraph_plotband.php | 790 +- src/classes/jpgraph/jpgraph_plotmark.inc.php | 733 +- src/classes/jpgraph/jpgraph_rgb.inc.php | 628 ++ src/classes/jpgraph/jpgraph_text.inc.php | 272 + src/classes/jpgraph/jpgraph_ttf.inc.php | 776 +- src/classes/jpgraph/lang/de.inc.php | 461 +- src/classes/jpgraph/lang/en.inc.php | 62 +- src/classes/jpgraph/lang/prod.inc.php | 26 +- 17 files changed, 12042 insertions(+), 11168 deletions(-) create mode 100644 src/classes/jpgraph/jpgraph_legend.inc.php create mode 100644 src/classes/jpgraph/jpgraph_rgb.inc.php create mode 100644 src/classes/jpgraph/jpgraph_text.inc.php diff --git a/src/classes/jpgraph/gd_image.inc.php b/src/classes/jpgraph/gd_image.inc.php index f8b4b01..fd1286f 100644 --- a/src/classes/jpgraph/gd_image.inc.php +++ b/src/classes/jpgraph/gd_image.inc.php @@ -1,19 +1,37 @@ CreateImgCanvas($aWidth,$aHeight); - if( $aSetAutoMargin ) - $this->SetAutoMargin(); + function __construct($aWidth=0,$aHeight=0,$aFormat=DEFAULT_GFORMAT,$aSetAutoMargin=true) { + $this->CreateImgCanvas($aWidth,$aHeight); - if( !$this->SetImgFormat($aFormat) ) { - JpGraphError::RaiseL(25081,$aFormat);//("JpGraph: Selected graphic format is either not supported or unknown [$aFormat]"); - } - $this->ttf = new TTF(); - $this->langconv = new LanguageConv(); + if( $aSetAutoMargin ) { + $this->SetAutoMargin(); + } + + if( !$this->SetImgFormat($aFormat) ) { + JpGraphError::RaiseL(25081,$aFormat);//("JpGraph: Selected graphic format is either not supported or unknown [$aFormat]"); + } + $this->ttf = new TTF(); + $this->langconv = new LanguageConv(); } // Enable interlacing in images function SetInterlace($aFlg=true) { - $this->iInterlace=$aFlg; + $this->iInterlace=$aFlg; } // Should we use anti-aliasing. Note: This really slows down graphics! function SetAntiAliasing($aFlg=true) { - $this->use_anti_aliasing = $aFlg; - if( function_exists('imageantialias') ) { - imageantialias($this->img,$aFlg); - } - else { - JpGraphError::RaiseL(25128);//('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.') - } + $this->use_anti_aliasing = $aFlg; + if( function_exists('imageantialias') ) { + imageantialias($this->img,$aFlg); + } + else { + JpGraphError::RaiseL(25128);//('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.') + } + } + + function GetAntiAliasing() { + return $this->use_anti_aliasing ; } function CreateRawCanvas($aWidth=0,$aHeight=0) { - if( $aWidth <= 1 || $aHeight <= 1 ) { - JpGraphError::RaiseL(25082,$aWidth,$aHeight);//("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)"); - } + if( $aWidth <= 1 || $aHeight <= 1 ) { + JpGraphError::RaiseL(25082,$aWidth,$aHeight);//("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)"); + } - if( USE_TRUECOLOR ) { - $this->img = @imagecreatetruecolor($aWidth, $aHeight); - if( $this->img < 1 ) { - JpGraphError::RaiseL(25126); - //die("Can't create truecolor image. Check that you really have GD2 library installed."); - } - $this->SetAlphaBlending(); - } else { - $this->img = @imagecreate($aWidth, $aHeight); - if( $this->img < 1 ) { - JpGraphError::RaiseL(25126); - //die("JpGraph Error: Can't create image. Check that you really have the GD library installed."); - } - } + $this->img = @imagecreatetruecolor($aWidth, $aHeight); + if( $this->img < 1 ) { + JpGraphError::RaiseL(25126); + //die("Can't create truecolor image. Check that you really have GD2 library installed."); + } + $this->SetAlphaBlending(); - if( $this->iInterlace ) { - imageinterlace($this->img,1); - } - if( $this->rgb != null ) - $this->rgb->img = $this->img ; - else - $this->rgb = new RGB($this->img); + if( $this->iInterlace ) { + imageinterlace($this->img,1); + } + if( $this->rgb != null ) { + $this->rgb->img = $this->img ; + } + else { + $this->rgb = new RGB($this->img); + } } function CloneCanvasH() { - $oldimage = $this->img; - $this->CreateRawCanvas($this->width,$this->height); - imagecopy($this->img,$oldimage,0,0,0,0,$this->width,$this->height); - return $oldimage; + $oldimage = $this->img; + $this->CreateRawCanvas($this->width,$this->height); + imagecopy($this->img,$oldimage,0,0,0,0,$this->width,$this->height); + return $oldimage; } - + function CreateImgCanvas($aWidth=0,$aHeight=0) { - $old = array($this->img,$this->width,$this->height); - - $aWidth = round($aWidth); - $aHeight = round($aHeight); + $old = array($this->img,$this->width,$this->height); - $this->width=$aWidth; - $this->height=$aHeight; + $aWidth = round($aWidth); + $aHeight = round($aHeight); - - if( $aWidth==0 || $aHeight==0 ) { - // We will set the final size later. - // Note: The size must be specified before any other - // img routines that stroke anything are called. - $this->img = null; - $this->rgb = null; - return $old; - } - - $this->CreateRawCanvas($aWidth,$aHeight); - // Set canvas color (will also be the background color for a - // a pallett image - $this->SetColor($this->canvascolor); - $this->FilledRectangle(0,0,$aWidth,$aHeight); + $this->width=$aWidth; + $this->height=$aHeight; - return $old ; + + if( $aWidth==0 || $aHeight==0 ) { + // We will set the final size later. + // Note: The size must be specified before any other + // img routines that stroke anything are called. + $this->img = null; + $this->rgb = null; + return $old; + } + + $this->CreateRawCanvas($aWidth,$aHeight); + // Set canvas color (will also be the background color for a + // a pallett image + $this->SetColor($this->canvascolor); + $this->FilledRectangle(0,0,$aWidth-1,$aHeight-1); + + return $old ; } function CopyCanvasH($aToHdl,$aFromHdl,$aToX,$aToY,$aFromX,$aFromY,$aWidth,$aHeight,$aw=-1,$ah=-1) { - if( $aw === -1 ) { - $aw = $aWidth; - $ah = $aHeight; - $f = 'imagecopyresized'; - } - else { - $f = 'imagecopyresampled'; - } - $f($aToHdl,$aFromHdl,$aToX,$aToY,$aFromX,$aFromY, $aWidth,$aHeight,$aw,$ah); + if( $aw === -1 ) { + $aw = $aWidth; + $ah = $aHeight; + $f = 'imagecopyresized'; + } + else { + $f = 'imagecopyresampled'; + } + $f($aToHdl,$aFromHdl,$aToX,$aToY,$aFromX,$aFromY, $aWidth,$aHeight,$aw,$ah); } function Copy($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1) { - $this->CopyCanvasH($this->img,$fromImg,$toX,$toY,$fromX,$fromY, - $toWidth,$toHeight,$fromWidth,$fromHeight); + $this->CopyCanvasH($this->img,$fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight); } function CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1,$aMix=100) { - if( $aMix == 100 ) { - $this->CopyCanvasH($this->img,$fromImg, - $toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight); - } - else { - if( ($fromWidth != -1 && ($fromWidth != $toWidth)) || - ($fromHeight != -1 && ($fromHeight != $fromHeight)) ) { - // Create a new canvas that will hold the re-scaled original from image - if( $toWidth <= 1 || $toHeight <= 1 ) { - JpGraphError::RaiseL(25083);//('Illegal image size when copying image. Size for copied to image is 1 pixel or less.'); - } - if( USE_TRUECOLOR ) { - $tmpimg = @imagecreatetruecolor($toWidth, $toHeight); - } else { - $tmpimg = @imagecreate($toWidth, $toHeight); - } - if( $tmpimg < 1 ) { - JpGraphError::RaiseL(25084);//('Failed to create temporary GD canvas. Out of memory ?'); - } - $this->CopyCanvasH($tmpimg,$fromImg,0,0,0,0, - $toWidth,$toHeight,$fromWidth,$fromHeight); - $fromImg = $tmpimg; - } - imagecopymerge($this->img,$fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$aMix); - } + if( $aMix == 100 ) { + $this->CopyCanvasH($this->img,$fromImg, + $toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight); + } + else { + if( ($fromWidth != -1 && ($fromWidth != $toWidth)) || ($fromHeight != -1 && ($fromHeight != $fromHeight)) ) { + // Create a new canvas that will hold the re-scaled original from image + if( $toWidth <= 1 || $toHeight <= 1 ) { + JpGraphError::RaiseL(25083);//('Illegal image size when copying image. Size for copied to image is 1 pixel or less.'); + } + + $tmpimg = @imagecreatetruecolor($toWidth, $toHeight); + + if( $tmpimg < 1 ) { + JpGraphError::RaiseL(25084);//('Failed to create temporary GD canvas. Out of memory ?'); + } + $this->CopyCanvasH($tmpimg,$fromImg,0,0,0,0, + $toWidth,$toHeight,$fromWidth,$fromHeight); + $fromImg = $tmpimg; + } + imagecopymerge($this->img,$fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$aMix); + } } static function GetWidth($aImg=null) { - if( $aImg === null ) - $aImg = $this->img; - return imagesx($aImg); + if( $aImg === null ) { + $aImg = $this->img; + } + return imagesx($aImg); } static function GetHeight($aImg=null) { - if( $aImg === null ) - $aImg = $this->img; - return imagesy($aImg); + if( $aImg === null ) { + $aImg = $this->img; + } + return imagesy($aImg); } - + static function CreateFromString($aStr) { - $img = imagecreatefromstring($aStr); - if( $img === false ) { - JpGraphError::RaiseL(25085);//('An image can not be created from the supplied string. It is either in a format not supported or the string is representing an corrupt image.'); - } - return $img; + $img = imagecreatefromstring($aStr); + if( $img === false ) { + JpGraphError::RaiseL(25085); + //('An image can not be created from the supplied string. It is either in a format not supported or the string is representing an corrupt image.'); + } + return $img; } function SetCanvasH($aHdl) { - $this->img = $aHdl; - $this->rgb->img = $aHdl; + $this->img = $aHdl; + $this->rgb->img = $aHdl; } function SetCanvasColor($aColor) { - $this->canvascolor = $aColor ; + $this->canvascolor = $aColor ; } function SetAlphaBlending($aFlg=true) { - ImageAlphaBlending($this->img,$aFlg); + ImageAlphaBlending($this->img,$aFlg); } - - function SetAutoMargin() { - GLOBAL $gJpgBrandTiming; - $min_bm=5; - /* - if( $gJpgBrandTiming ) - $min_bm=15; - */ - $lm = min(40,$this->width/7); - $rm = min(20,$this->width/10); - $tm = max(5,$this->height/7); - $bm = max($min_bm,$this->height/7); - $this->SetMargin($lm,$rm,$tm,$bm); + + function SetAutoMargin() { + $min_bm=5; + $lm = min(40,$this->width/7); + $rm = min(20,$this->width/10); + $tm = max(5,$this->height/7); + $bm = max($min_bm,$this->height/6); + $this->SetMargin($lm,$rm,$tm,$bm); } - + //--------------- - // PUBLIC METHODS - - function SetFont($family,$style=FS_NORMAL,$size=10) { - $this->font_family=$family; - $this->font_style=$style; - $this->font_size=$size; - $this->font_file=''; - if( ($this->font_family==FF_FONT1 || $this->font_family==FF_FONT2) && $this->font_style==FS_BOLD ){ - ++$this->font_family; - } - if( $this->font_family > FF_FONT2+1 ) { // A TTF font so get the font file + // PUBLIC METHODS - // Check that this PHP has support for TTF fonts - if( !function_exists('imagettfbbox') ) { - JpGraphError::RaiseL(25087);//('This PHP build has not been configured with TTF support. You need to recompile your PHP installation with FreeType support.'); - } - $this->font_file = $this->ttf->File($this->font_family,$this->font_style); - } + function SetFont($family,$style=FS_NORMAL,$size=10) { + $this->font_family=$family; + $this->font_style=$style; + $this->font_size=$size; + $this->font_file=''; + if( ($this->font_family==FF_FONT1 || $this->font_family==FF_FONT2) && $this->font_style==FS_BOLD ){ + ++$this->font_family; + } + if( $this->font_family > FF_FONT2+1 ) { // A TTF font so get the font file + + // Check that this PHP has support for TTF fonts + if( !function_exists('imagettfbbox') ) { + JpGraphError::RaiseL(25087);//('This PHP build has not been configured with TTF support. You need to recompile your PHP installation with FreeType support.'); + } + $this->font_file = $this->ttf->File($this->font_family,$this->font_style); + } } // Get the specific height for a text string function GetTextHeight($txt="",$angle=0) { - $tmp = split("\n",$txt); - $n = count($tmp); - $m=0; - for($i=0; $i< $n; ++$i) - $m = max($m,strlen($tmp[$i])); + $tmp = preg_split('/\n/',$txt); + $n = count($tmp); + $m=0; + for($i=0; $i< $n; ++$i) { + $m = max($m,strlen($tmp[$i])); + } - if( $this->font_family <= FF_FONT2+1 ) { - if( $angle==0 ) { - $h = imagefontheight($this->font_family); - if( $h === false ) { - JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); - } + if( $this->font_family <= FF_FONT2+1 ) { + if( $angle==0 ) { + $h = imagefontheight($this->font_family); + if( $h === false ) { + JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); + } - return $n*$h; - } - else { - $w = @imagefontwidth($this->font_family); - if( $w === false ) { - JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); - } + return $n*$h; + } + else { + $w = @imagefontwidth($this->font_family); + if( $w === false ) { + JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); + } - return $m*$w; - } - } - else { - $bbox = $this->GetTTFBBox($txt,$angle); - return $bbox[1]-$bbox[5]; - } + return $m*$w; + } + } + else { + $bbox = $this->GetTTFBBox($txt,$angle); + return $bbox[1]-$bbox[5]; + } } - + // Estimate font height function GetFontHeight($angle=0) { - $txt = "XOMg"; - return $this->GetTextHeight($txt,$angle); + $txt = "XOMg"; + return $this->GetTextHeight($txt,$angle); } - + // Approximate font width with width of letter "O" function GetFontWidth($angle=0) { - $txt = 'O'; - return $this->GetTextWidth($txt,$angle); + $txt = 'O'; + return $this->GetTextWidth($txt,$angle); } - + // Get actual width of text in absolute pixels function GetTextWidth($txt,$angle=0) { - $tmp = split("\n",$txt); - $n = count($tmp); - if( $this->font_family <= FF_FONT2+1 ) { + $tmp = preg_split('/\n/',$txt); + $n = count($tmp); + if( $this->font_family <= FF_FONT2+1 ) { - $m=0; - for($i=0; $i < $n; ++$i) { - $l=strlen($tmp[$i]); - if( $l > $m ) { - $m = $l; - } - } + $m=0; + for($i=0; $i < $n; ++$i) { + $l=strlen($tmp[$i]); + if( $l > $m ) { + $m = $l; + } + } - if( $angle==0 ) { - $w = @imagefontwidth($this->font_family); - if( $w === false ) { - JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); - } - return $m*$w; - } - else { - // 90 degrees internal so height becomes width - $h = @imagefontheight($this->font_family); - if( $h === false ) { - JpGraphError::RaiseL(25089);//('You have a misconfigured GD font support. The call to imagefontheight() fails.'); - } - return $n*$h; - } - } - else { - // For TTF fonts we must walk through a lines and find the - // widest one which we use as the width of the multi-line - // paragraph - $m=0; - for( $i=0; $i < $n; ++$i ) { - $bbox = $this->GetTTFBBox($tmp[$i],$angle); - $mm = $bbox[2] - $bbox[0]; - if( $mm > $m ) - $m = $mm; - } - return $m; - } + if( $angle==0 ) { + $w = @imagefontwidth($this->font_family); + if( $w === false ) { + JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.'); + } + return $m*$w; + } + else { + // 90 degrees internal so height becomes width + $h = @imagefontheight($this->font_family); + if( $h === false ) { + JpGraphError::RaiseL(25089);//('You have a misconfigured GD font support. The call to imagefontheight() fails.'); + } + return $n*$h; + } + } + else { + // For TTF fonts we must walk through a lines and find the + // widest one which we use as the width of the multi-line + // paragraph + $m=0; + for( $i=0; $i < $n; ++$i ) { + $bbox = $this->GetTTFBBox($tmp[$i],$angle); + $mm = $bbox[2] - $bbox[0]; + if( $mm > $m ) + $m = $mm; + } + return $m; + } } - + // Draw text with a box around it function StrokeBoxedText($x,$y,$txt,$dir=0,$fcolor="white",$bcolor="black", - $shadowcolor=false,$paragraph_align="left", - $xmarg=6,$ymarg=4,$cornerradius=0,$dropwidth=3) { + $shadowcolor=false,$paragraph_align="left", + $xmarg=6,$ymarg=4,$cornerradius=0,$dropwidth=3) { - if( !is_numeric($dir) ) { - if( $dir=="h" ) $dir=0; - elseif( $dir=="v" ) $dir=90; - else JpGraphError::RaiseL(25090,$dir);//(" Unknown direction specified in call to StrokeBoxedText() [$dir]"); - } - - if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) { - $width=$this->GetTextWidth($txt,$dir) ; - $height=$this->GetTextHeight($txt,$dir) ; - } - else { - $width=$this->GetBBoxWidth($txt,$dir) ; - $height=$this->GetBBoxHeight($txt,$dir) ; - } + $oldx = $this->lastx; + $oldy = $this->lasty; - $height += 2*$ymarg; - $width += 2*$xmarg; + if( !is_numeric($dir) ) { + if( $dir=="h" ) $dir=0; + elseif( $dir=="v" ) $dir=90; + else JpGraphError::RaiseL(25090,$dir);//(" Unknown direction specified in call to StrokeBoxedText() [$dir]"); + } - if( $this->text_halign=="right" ) $x -= $width; - elseif( $this->text_halign=="center" ) $x -= $width/2; - if( $this->text_valign=="bottom" ) $y -= $height; - elseif( $this->text_valign=="center" ) $y -= $height/2; - - $olda = $this->SetAngle(0); + if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) { + $width=$this->GetTextWidth($txt,$dir) ; + $height=$this->GetTextHeight($txt,$dir) ; + } + else { + $width=$this->GetBBoxWidth($txt,$dir) ; + $height=$this->GetBBoxHeight($txt,$dir) ; + } - if( $shadowcolor ) { - $this->PushColor($shadowcolor); - $this->FilledRoundedRectangle($x-$xmarg+$dropwidth,$y-$ymarg+$dropwidth, - $x+$width+$dropwidth,$y+$height-$ymarg+$dropwidth, - $cornerradius); - $this->PopColor(); - $this->PushColor($fcolor); - $this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg, - $x+$width,$y+$height-$ymarg, - $cornerradius); - $this->PopColor(); - $this->PushColor($bcolor); - $this->RoundedRectangle($x-$xmarg,$y-$ymarg, - $x+$width,$y+$height-$ymarg,$cornerradius); - $this->PopColor(); - } - else { - if( $fcolor ) { - $oc=$this->current_color; - $this->SetColor($fcolor); - $this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius); - $this->current_color=$oc; - } - if( $bcolor ) { - $oc=$this->current_color; - $this->SetColor($bcolor); - $this->RoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius); - $this->current_color=$oc; - } - } - - $h=$this->text_halign; - $v=$this->text_valign; - $this->SetTextAlign("left","top"); - $this->StrokeText($x, $y, $txt, $dir, $paragraph_align); - $bb = array($x-$xmarg,$y+$height-$ymarg,$x+$width,$y+$height-$ymarg, - $x+$width,$y-$ymarg,$x-$xmarg,$y-$ymarg); - $this->SetTextAlign($h,$v); + $height += 2*$ymarg; + $width += 2*$xmarg; - $this->SetAngle($olda); + if( $this->text_halign=="right" ) $x -= $width; + elseif( $this->text_halign=="center" ) $x -= $width/2; - return $bb; + if( $this->text_valign=="bottom" ) $y -= $height; + elseif( $this->text_valign=="center" ) $y -= $height/2; + + $olda = $this->SetAngle(0); + + if( $shadowcolor ) { + $this->PushColor($shadowcolor); + $this->FilledRoundedRectangle($x-$xmarg+$dropwidth,$y-$ymarg+$dropwidth, + $x+$width+$dropwidth,$y+$height-$ymarg+$dropwidth, + $cornerradius); + $this->PopColor(); + $this->PushColor($fcolor); + $this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg, + $x+$width,$y+$height-$ymarg, + $cornerradius); + $this->PopColor(); + $this->PushColor($bcolor); + $this->RoundedRectangle($x-$xmarg,$y-$ymarg, + $x+$width,$y+$height-$ymarg,$cornerradius); + $this->PopColor(); + } + else { + if( $fcolor ) { + $oc=$this->current_color; + $this->SetColor($fcolor); + $this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius); + $this->current_color=$oc; + } + if( $bcolor ) { + $oc=$this->current_color; + $this->SetColor($bcolor); + $this->RoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius); + $this->current_color=$oc; + } + } + + $h=$this->text_halign; + $v=$this->text_valign; + $this->SetTextAlign("left","top"); + $this->StrokeText($x, $y, $txt, $dir, $paragraph_align); + $bb = array($x-$xmarg,$y+$height-$ymarg,$x+$width,$y+$height-$ymarg, + $x+$width,$y-$ymarg,$x-$xmarg,$y-$ymarg); + $this->SetTextAlign($h,$v); + + $this->SetAngle($olda); + $this->lastx = $oldx; + $this->lasty = $oldy; + + return $bb; } - // Set text alignment + // Set text alignment function SetTextAlign($halign,$valign="bottom") { - $this->text_halign=$halign; - $this->text_valign=$valign; + $this->text_halign=$halign; + $this->text_valign=$valign; } - + function _StrokeBuiltinFont($x,$y,$txt,$dir=0,$paragraph_align="left",&$aBoundingBox,$aDebug=false) { - if( is_numeric($dir) && $dir!=90 && $dir!=0) - JpGraphError::RaiseL(25091);//(" Internal font does not support drawing text at arbitrary angle. Use TTF fonts instead."); + if( is_numeric($dir) && $dir!=90 && $dir!=0) + JpGraphError::RaiseL(25091);//(" Internal font does not support drawing text at arbitrary angle. Use TTF fonts instead."); - $h=$this->GetTextHeight($txt); - $fh=$this->GetFontHeight(); - $w=$this->GetTextWidth($txt); - - if( $this->text_halign=="right") - $x -= $dir==0 ? $w : $h; - elseif( $this->text_halign=="center" ) { - // For center we subtract 1 pixel since this makes the middle - // be prefectly in the middle - $x -= $dir==0 ? $w/2-1 : $h/2; - } - if( $this->text_valign=="top" ) - $y += $dir==0 ? $h : $w; - elseif( $this->text_valign=="center" ) - $y += $dir==0 ? $h/2 : $w/2; - - if( $dir==90 ) { - imagestringup($this->img,$this->font_family,$x,$y,$txt,$this->current_color); - $aBoundingBox = array(round($x),round($y),round($x),round($y-$w),round($x+$h),round($y-$w),round($x+$h),round($y)); + $h=$this->GetTextHeight($txt); + $fh=$this->GetFontHeight(); + $w=$this->GetTextWidth($txt); + + if( $this->text_halign=="right") { + $x -= $dir==0 ? $w : $h; + } + elseif( $this->text_halign=="center" ) { + // For center we subtract 1 pixel since this makes the middle + // be prefectly in the middle + $x -= $dir==0 ? $w/2-1 : $h/2; + } + if( $this->text_valign=="top" ) { + $y += $dir==0 ? $h : $w; + } + elseif( $this->text_valign=="center" ) { + $y += $dir==0 ? $h/2 : $w/2; + } + + if( $dir==90 ) { + imagestringup($this->img,$this->font_family,$x,$y,$txt,$this->current_color); + $aBoundingBox = array(round($x),round($y),round($x),round($y-$w),round($x+$h),round($y-$w),round($x+$h),round($y)); if( $aDebug ) { - // Draw bounding box - $this->PushColor('green'); - $this->Polygon($aBoundingBox,true); - $this->PopColor(); - } - } - else { - if( ereg("\n",$txt) ) { - $tmp = split("\n",$txt); - for($i=0; $i < count($tmp); ++$i) { - $w1 = $this->GetTextWidth($tmp[$i]); - if( $paragraph_align=="left" ) { - imagestring($this->img,$this->font_family,$x,$y-$h+1+$i*$fh,$tmp[$i],$this->current_color); - } - elseif( $paragraph_align=="right" ) { - imagestring($this->img,$this->font_family,$x+($w-$w1), - $y-$h+1+$i*$fh,$tmp[$i],$this->current_color); - } - else { - imagestring($this->img,$this->font_family,$x+$w/2-$w1/2, - $y-$h+1+$i*$fh,$tmp[$i],$this->current_color); - } - } - } - else { - //Put the text - imagestring($this->img,$this->font_family,$x,$y-$h+1,$txt,$this->current_color); - } + // Draw bounding box + $this->PushColor('green'); + $this->Polygon($aBoundingBox,true); + $this->PopColor(); + } + } + else { + if( preg_match('/\n/',$txt) ) { + $tmp = preg_split('/\n/',$txt); + for($i=0; $i < count($tmp); ++$i) { + $w1 = $this->GetTextWidth($tmp[$i]); + if( $paragraph_align=="left" ) { + imagestring($this->img,$this->font_family,$x,$y-$h+1+$i*$fh,$tmp[$i],$this->current_color); + } + elseif( $paragraph_align=="right" ) { + imagestring($this->img,$this->font_family,$x+($w-$w1),$y-$h+1+$i*$fh,$tmp[$i],$this->current_color); + } + else { + imagestring($this->img,$this->font_family,$x+$w/2-$w1/2,$y-$h+1+$i*$fh,$tmp[$i],$this->current_color); + } + } + } + else { + //Put the text + imagestring($this->img,$this->font_family,$x,$y-$h+1,$txt,$this->current_color); + } if( $aDebug ) { - // Draw the bounding rectangle and the bounding box - $p1 = array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y)); - - // Draw bounding box - $this->PushColor('green'); - $this->Polygon($p1,true); - $this->PopColor(); + // Draw the bounding rectangle and the bounding box + $p1 = array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y)); + + // Draw bounding box + $this->PushColor('green'); + $this->Polygon($p1,true); + $this->PopColor(); } - $aBoundingBox=array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y)); - } + $aBoundingBox=array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y)); + } } function AddTxtCR($aTxt) { - // If the user has just specified a '\n' - // instead of '\n\t' we have to add '\r' since - // the width will be too muchy otherwise since when - // we print we stroke the individually lines by hand. - $e = explode("\n",$aTxt); - $n = count($e); - for($i=0; $i<$n; ++$i) { - $e[$i]=str_replace("\r","",$e[$i]); - } - return implode("\n\r",$e); + // If the user has just specified a '\n' + // instead of '\n\t' we have to add '\r' since + // the width will be too muchy otherwise since when + // we print we stroke the individually lines by hand. + $e = explode("\n",$aTxt); + $n = count($e); + for($i=0; $i<$n; ++$i) { + $e[$i]=str_replace("\r","",$e[$i]); + } + return implode("\n\r",$e); } function GetTTFBBox($aTxt,$aAngle=0) { - $bbox = @ImageTTFBBox($this->font_size,$aAngle,$this->font_file,$aTxt); - if( $bbox === false ) { - JpGraphError::RaiseL(25092,$this->font_file); -//("There is either a configuration problem with TrueType or a problem reading font file (".$this->font_file."). Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try uppgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library."); - } - return $bbox; + $bbox = @ImageTTFBBox($this->font_size,$aAngle,$this->font_file,$aTxt); + if( $bbox === false ) { + JpGraphError::RaiseL(25092,$this->font_file); + //("There is either a configuration problem with TrueType or a problem reading font file (".$this->font_file."). Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try uppgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library."); + } + return $bbox; } function GetBBoxTTF($aTxt,$aAngle=0) { - // Normalize the bounding box to become a minimum - // enscribing rectangle + // Normalize the bounding box to become a minimum + // enscribing rectangle - $aTxt = $this->AddTxtCR($aTxt); + $aTxt = $this->AddTxtCR($aTxt); - if( !is_readable($this->font_file) ) { - JpGraphError::RaiseL(25093,$this->font_file); -//('Can not read font file ('.$this->font_file.') in call to Image::GetBBoxTTF. Please make sure that you have set a font before calling this method and that the font is installed in the TTF directory.'); - } - $bbox = $this->GetTTFBBox($aTxt,$aAngle); + if( !is_readable($this->font_file) ) { + JpGraphError::RaiseL(25093,$this->font_file); + //('Can not read font file ('.$this->font_file.') in call to Image::GetBBoxTTF. Please make sure that you have set a font before calling this method and that the font is installed in the TTF directory.'); + } + $bbox = $this->GetTTFBBox($aTxt,$aAngle); - if( $aAngle==0 ) - return $bbox; - if( $aAngle >= 0 ) { - if( $aAngle <= 90 ) { //<=0 - $bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1], - $bbox[2],$bbox[5],$bbox[6],$bbox[5]); - } - elseif( $aAngle <= 180 ) { //<= 2 - $bbox = array($bbox[4],$bbox[7],$bbox[0],$bbox[7], - $bbox[0],$bbox[3],$bbox[4],$bbox[3]); - } - elseif( $aAngle <= 270 ) { //<= 3 - $bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5], - $bbox[6],$bbox[1],$bbox[2],$bbox[1]); - } - else { - $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], - $bbox[4],$bbox[7],$bbox[0],$bbox[7]); - } - } - elseif( $aAngle < 0 ) { - if( $aAngle <= -270 ) { // <= -3 - $bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1], - $bbox[2],$bbox[5],$bbox[6],$bbox[5]); - } - elseif( $aAngle <= -180 ) { // <= -2 - $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], - $bbox[4],$bbox[7],$bbox[0],$bbox[7]); - } - elseif( $aAngle <= -90 ) { // <= -1 - $bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5], - $bbox[6],$bbox[1],$bbox[2],$bbox[1]); - } - else { - $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], - $bbox[4],$bbox[7],$bbox[0],$bbox[7]); - } - } - return $bbox; + if( $aAngle==0 ) return $bbox; + + if( $aAngle >= 0 ) { + if( $aAngle <= 90 ) { //<=0 + $bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1], + $bbox[2],$bbox[5],$bbox[6],$bbox[5]); + } + elseif( $aAngle <= 180 ) { //<= 2 + $bbox = array($bbox[4],$bbox[7],$bbox[0],$bbox[7], + $bbox[0],$bbox[3],$bbox[4],$bbox[3]); + } + elseif( $aAngle <= 270 ) { //<= 3 + $bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5], + $bbox[6],$bbox[1],$bbox[2],$bbox[1]); + } + else { + $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], + $bbox[4],$bbox[7],$bbox[0],$bbox[7]); + } + } + elseif( $aAngle < 0 ) { + if( $aAngle <= -270 ) { // <= -3 + $bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1], + $bbox[2],$bbox[5],$bbox[6],$bbox[5]); + } + elseif( $aAngle <= -180 ) { // <= -2 + $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], + $bbox[4],$bbox[7],$bbox[0],$bbox[7]); + } + elseif( $aAngle <= -90 ) { // <= -1 + $bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5], + $bbox[6],$bbox[1],$bbox[2],$bbox[1]); + } + else { + $bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3], + $bbox[4],$bbox[7],$bbox[0],$bbox[7]); + } + } + return $bbox; } function GetBBoxHeight($aTxt,$aAngle=0) { - $box = $this->GetBBoxTTF($aTxt,$aAngle); - return $box[1]-$box[7]+1; + $box = $this->GetBBoxTTF($aTxt,$aAngle); + return $box[1]-$box[7]+1; } function GetBBoxWidth($aTxt,$aAngle=0) { - $box = $this->GetBBoxTTF($aTxt,$aAngle); - return $box[2]-$box[0]+1; + $box = $this->GetBBoxTTF($aTxt,$aAngle); + return $box[2]-$box[0]+1; } function _StrokeTTF($x,$y,$txt,$dir=0,$paragraph_align="left",&$aBoundingBox,$debug=false) { - // Setupo default inter line margin for paragraphs to - // 25% of the font height. - $ConstLineSpacing = 0.25 ; + // Setupo default inter line margin for paragraphs to + // 25% of the font height. + $ConstLineSpacing = 0.25 ; - // Remember the anchor point before adjustment - if( $debug ) { - $ox=$x; - $oy=$y; - } + // Remember the anchor point before adjustment + if( $debug ) { + $ox=$x; + $oy=$y; + } - if( !ereg("\n",$txt) || ($dir>0 && ereg("\n",$txt)) ) { - // Format a single line + if( !preg_match('/\n/',$txt) || ($dir>0 && preg_match('/\n/',$txt)) ) { + // Format a single line - $txt = $this->AddTxtCR($txt); + $txt = $this->AddTxtCR($txt); - $bbox=$this->GetBBoxTTF($txt,$dir); - - // Align x,y ot lower left corner of bbox - $x -= $bbox[0]; - $y -= $bbox[1]; + $bbox=$this->GetBBoxTTF($txt,$dir); - // Note to self: "topanchor" is deprecated after we changed the - // bopunding box stuff. - if( $this->text_halign=="right" || $this->text_halign=="topanchor" ) - $x -= $bbox[2]-$bbox[0]; - elseif( $this->text_halign=="center" ) $x -= ($bbox[2]-$bbox[0])/2; - - if( $this->text_valign=="top" ) $y += abs($bbox[5])+$bbox[1]; - elseif( $this->text_valign=="center" ) $y -= ($bbox[5]-$bbox[1])/2; + // Align x,y ot lower left corner of bbox + $x -= $bbox[0]; + $y -= $bbox[1]; - ImageTTFText ($this->img, $this->font_size, $dir, $x, $y, - $this->current_color,$this->font_file,$txt); - - // Calculate and return the co-ordinates for the bounding box - $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt); - $p1 = array(); - - - for($i=0; $i < 4; ++$i) { - $p1[] = round($box[$i*2]+$x); - $p1[] = round($box[$i*2+1]+$y); - } - $aBoundingBox = $p1; - - // Debugging code to highlight the bonding box and bounding rectangle - // For text at 0 degrees the bounding box and bounding rectangle are the - // same - if( $debug ) { - // Draw the bounding rectangle and the bounding box - $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt); - $p = array(); - $p1 = array(); - for($i=0; $i < 4; ++$i) { - $p[] = $bbox[$i*2]+$x; - $p[] = $bbox[$i*2+1]+$y; - $p1[] = $box[$i*2]+$x; - $p1[] = $box[$i*2+1]+$y; - } - - // Draw bounding box - $this->PushColor('green'); - $this->Polygon($p1,true); - $this->PopColor(); - - // Draw bounding rectangle - $this->PushColor('darkgreen'); - $this->Polygon($p,true); - $this->PopColor(); - - // Draw a cross at the anchor point - $this->PushColor('red'); - $this->Line($ox-15,$oy,$ox+15,$oy); - $this->Line($ox,$oy-15,$ox,$oy+15); - $this->PopColor(); + // Note to self: "topanchor" is deprecated after we changed the + // bopunding box stuff. + if( $this->text_halign=='right' || $this->text_halign=='topanchor' ) { + $x -= $bbox[2]-$bbox[0]; + } + elseif( $this->text_halign=='center' ) { + $x -= ($bbox[2]-$bbox[0])/2; } - } - else { - // Format a text paragraph - $fh=$this->GetFontHeight(); - // Line margin is 25% of font height - $linemargin=round($fh*$ConstLineSpacing); - $fh += $linemargin; - $w=$this->GetTextWidth($txt); + if( $this->text_valign=='top' ) { + $y += abs($bbox[5])+$bbox[1]; + } + elseif( $this->text_valign=='center' ) { + $y -= ($bbox[5]-$bbox[1])/2; + } - $y -= $linemargin/2; - $tmp = split("\n",$txt); - $nl = count($tmp); - $h = $nl * $fh; + ImageTTFText ($this->img, $this->font_size, $dir, $x, $y, + $this->current_color,$this->font_file,$txt); - if( $this->text_halign=="right") - $x -= $dir==0 ? $w : $h; - elseif( $this->text_halign=="center" ) { - $x -= $dir==0 ? $w/2 : $h/2; - } - - if( $this->text_valign=="top" ) - $y += $dir==0 ? $h : $w; - elseif( $this->text_valign=="center" ) - $y += $dir==0 ? $h/2 : $w/2; + // Calculate and return the co-ordinates for the bounding box + $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt); + $p1 = array(); - // Here comes a tricky bit. - // Since we have to give the position for the string at the - // baseline this means thaht text will move slightly up - // and down depending on any of it's character descend below - // the baseline, for example a 'g'. To adjust the Y-position - // we therefore adjust the text with the baseline Y-offset - // as used for the current font and size. This will keep the - // baseline at a fixed positoned disregarding the actual - // characters in the string. - $standardbox = $this->GetTTFBBox('Gg',$dir); - $yadj = $standardbox[1]; - $xadj = $standardbox[0]; - $aBoundingBox = array(); - for($i=0; $i < $nl; ++$i) { - $wl = $this->GetTextWidth($tmp[$i]); - $bbox = $this->GetTTFBBox($tmp[$i],$dir); - if( $paragraph_align=="left" ) { - $xl = $x; - } - elseif( $paragraph_align=="right" ) { - $xl = $x + ($w-$wl); - } - else { - // Center - $xl = $x + $w/2 - $wl/2 ; - } + for($i=0; $i < 4; ++$i) { + $p1[] = round($box[$i*2]+$x); + $p1[] = round($box[$i*2+1]+$y); + } + $aBoundingBox = $p1; - $xl -= $bbox[0]; - $yl = $y - $yadj; - $xl = $xl - $xadj; - ImageTTFText ($this->img, $this->font_size, $dir, - $xl, $yl-($h-$fh)+$fh*$i, - $this->current_color,$this->font_file,$tmp[$i]); + // Debugging code to highlight the bonding box and bounding rectangle + // For text at 0 degrees the bounding box and bounding rectangle are the + // same + if( $debug ) { + // Draw the bounding rectangle and the bounding box + $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt); + $p = array(); + $p1 = array(); + for($i=0; $i < 4; ++$i) { + $p[] = $bbox[$i*2]+$x; + $p[] = $bbox[$i*2+1]+$y; + $p1[] = $box[$i*2]+$x; + $p1[] = $box[$i*2+1]+$y; + } - if( $debug ) { - // Draw the bounding rectangle around each line - $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$tmp[$i]); - $p = array(); - for($j=0; $j < 4; ++$j) { - $p[] = $bbox[$j*2]+$xl; - $p[] = $bbox[$j*2+1]+$yl-($h-$fh)+$fh*$i; - } - - // Draw bounding rectangle - $this->PushColor('darkgreen'); - $this->Polygon($p,true); - $this->PopColor(); - } - } + // Draw bounding box + $this->PushColor('green'); + $this->Polygon($p1,true); + $this->PopColor(); - // Get the bounding box - $bbox = $this->GetBBoxTTF($txt,$dir); - for($j=0; $j < 4; ++$j) { - $bbox[$j*2]+= round($x); - $bbox[$j*2+1]+= round($y - ($h-$fh) - $yadj); - } - $aBoundingBox = $bbox; + // Draw bounding rectangle + $this->PushColor('darkgreen'); + $this->Polygon($p,true); + $this->PopColor(); - if( $debug ) { - // Draw a cross at the anchor point - $this->PushColor('red'); - $this->Line($ox-25,$oy,$ox+25,$oy); - $this->Line($ox,$oy-25,$ox,$oy+25); - $this->PopColor(); - } + // Draw a cross at the anchor point + $this->PushColor('red'); + $this->Line($ox-15,$oy,$ox+15,$oy); + $this->Line($ox,$oy-15,$ox,$oy+15); + $this->PopColor(); + } + } + else { + // Format a text paragraph + $fh=$this->GetFontHeight(); - } + // Line margin is 25% of font height + $linemargin=round($fh*$ConstLineSpacing); + $fh += $linemargin; + $w=$this->GetTextWidth($txt); + + $y -= $linemargin/2; + $tmp = preg_split('/\n/',$txt); + $nl = count($tmp); + $h = $nl * $fh; + + if( $this->text_halign=='right') { + $x -= $dir==0 ? $w : $h; + } + elseif( $this->text_halign=='center' ) { + $x -= $dir==0 ? $w/2 : $h/2; + } + + if( $this->text_valign=='top' ) { + $y += $dir==0 ? $h : $w; + } + elseif( $this->text_valign=='center' ) { + $y += $dir==0 ? $h/2 : $w/2; + } + + // Here comes a tricky bit. + // Since we have to give the position for the string at the + // baseline this means thaht text will move slightly up + // and down depending on any of it's character descend below + // the baseline, for example a 'g'. To adjust the Y-position + // we therefore adjust the text with the baseline Y-offset + // as used for the current font and size. This will keep the + // baseline at a fixed positoned disregarding the actual + // characters in the string. + $standardbox = $this->GetTTFBBox('Gg',$dir); + $yadj = $standardbox[1]; + $xadj = $standardbox[0]; + $aBoundingBox = array(); + for($i=0; $i < $nl; ++$i) { + $wl = $this->GetTextWidth($tmp[$i]); + $bbox = $this->GetTTFBBox($tmp[$i],$dir); + if( $paragraph_align=='left' ) { + $xl = $x; + } + elseif( $paragraph_align=='right' ) { + $xl = $x + ($w-$wl); + } + else { + // Center + $xl = $x + $w/2 - $wl/2 ; + } + + $xl -= $bbox[0]; + $yl = $y - $yadj; + $xl = $xl - $xadj; + ImageTTFText ($this->img, $this->font_size, $dir, + $xl, $yl-($h-$fh)+$fh*$i, + $this->current_color,$this->font_file,$tmp[$i]); + + if( $debug ) { + // Draw the bounding rectangle around each line + $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$tmp[$i]); + $p = array(); + for($j=0; $j < 4; ++$j) { + $p[] = $bbox[$j*2]+$xl; + $p[] = $bbox[$j*2+1]+$yl-($h-$fh)+$fh*$i; + } + + // Draw bounding rectangle + $this->PushColor('darkgreen'); + $this->Polygon($p,true); + $this->PopColor(); + } + } + + // Get the bounding box + $bbox = $this->GetBBoxTTF($txt,$dir); + for($j=0; $j < 4; ++$j) { + $bbox[$j*2]+= round($x); + $bbox[$j*2+1]+= round($y - ($h-$fh) - $yadj); + } + $aBoundingBox = $bbox; + + if( $debug ) { + // Draw a cross at the anchor point + $this->PushColor('red'); + $this->Line($ox-25,$oy,$ox+25,$oy); + $this->Line($ox,$oy-25,$ox,$oy+25); + $this->PopColor(); + } + + } } - + function StrokeText($x,$y,$txt,$dir=0,$paragraph_align="left",$debug=false) { - $x = round($x); - $y = round($y); + $x = round($x); + $y = round($y); - // Do special language encoding - $txt = $this->langconv->Convert($txt,$this->font_family); + // Do special language encoding + $txt = $this->langconv->Convert($txt,$this->font_family); - if( !is_numeric($dir) ) - JpGraphError::RaiseL(25094);//(" Direction for text most be given as an angle between 0 and 90."); - - if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) { - $this->_StrokeBuiltinFont($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug); - } - elseif($this->font_family >= _FIRST_FONT && $this->font_family <= _LAST_FONT) { - $this->_StrokeTTF($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug); - } - else - JpGraphError::RaiseL(25095);//(" Unknown font font family specification. "); - return $boundingbox; + if( !is_numeric($dir) ) { + JpGraphError::RaiseL(25094);//(" Direction for text most be given as an angle between 0 and 90."); + } + + if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) { + $this->_StrokeBuiltinFont($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug); + } + elseif( $this->font_family >= _FIRST_FONT && $this->font_family <= _LAST_FONT) { + $this->_StrokeTTF($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug); + } + else { + JpGraphError::RaiseL(25095);//(" Unknown font font family specification. "); + } + return $boundingbox; } - + function SetMargin($lm,$rm,$tm,$bm) { - $this->left_margin=$lm; - $this->right_margin=$rm; - $this->top_margin=$tm; - $this->bottom_margin=$bm; - $this->plotwidth=$this->width - $this->left_margin-$this->right_margin ; - $this->plotheight=$this->height - $this->top_margin-$this->bottom_margin ; - if( $this->width > 0 && $this->height > 0 ) { - if( $this->plotwidth < 0 || $this->plotheight < 0 ) - JpGraphError::raise("To small plot area. ($lm,$rm,$tm,$bm : $this->plotwidth x $this->plotheight). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins."); - } + $this->left_margin=$lm; + $this->right_margin=$rm; + $this->top_margin=$tm; + $this->bottom_margin=$bm; + $this->plotwidth=$this->width - $this->left_margin-$this->right_margin ; + $this->plotheight=$this->height - $this->top_margin-$this->bottom_margin ; + if( $this->width > 0 && $this->height > 0 ) { + if( $this->plotwidth < 0 || $this->plotheight < 0 ) { + JpGraphError::RaiseL(25130, $this->plotwidth, $this->plotheight); + //JpGraphError::raise("To small plot area. ($lm,$rm,$tm,$bm : $this->plotwidth x $this->plotheight). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins."); + } + } } function SetTransparent($color) { - imagecolortransparent ($this->img,$this->rgb->allocate($color)); + imagecolortransparent ($this->img,$this->rgb->allocate($color)); } - + function SetColor($color,$aAlpha=0) { - $this->current_color_name = $color; - $this->current_color=$this->rgb->allocate($color,$aAlpha); - if( $this->current_color == -1 ) { - $tc=imagecolorstotal($this->img); - JpGraphError::RaiseL(25096); -//("Can't allocate any more colors. Image has already allocated maximum of $tc colors. This might happen if you have anti-aliasing turned on together with a background image or perhaps gradient fill since this requires many, many colors. Try to turn off anti-aliasing. If there is still a problem try downgrading the quality of the background image to use a smaller pallete to leave some entries for your graphs. You should try to limit the number of colors in your background image to 64. If there is still problem set the constant DEFINE(\"USE_APPROX_COLORS\",true); in jpgraph.php This will use approximative colors when the palette is full. Unfortunately there is not much JpGraph can do about this since the palette size is a limitation of current graphic format and what the underlying GD library suppports."); - } - return $this->current_color; + $this->current_color_name = $color; + $this->current_color=$this->rgb->allocate($color,$aAlpha); + if( $this->current_color == -1 ) { + $tc=imagecolorstotal($this->img); + JpGraphError::RaiseL(25096); + //("Can't allocate any more colors. Image has already allocated maximum of $tc colors. This might happen if you have anti-aliasing turned on together with a background image or perhaps gradient fill since this requires many, many colors. Try to turn off anti-aliasing. If there is still a problem try downgrading the quality of the background image to use a smaller pallete to leave some entries for your graphs. You should try to limit the number of colors in your background image to 64. If there is still problem set the constant DEFINE(\"USE_APPROX_COLORS\",true); in jpgraph.php This will use approximative colors when the palette is full. Unfortunately there is not much JpGraph can do about this since the palette size is a limitation of current graphic format and what the underlying GD library suppports."); + } + return $this->current_color; } - + function PushColor($color) { - if( $color != "" ) { - $this->colorstack[$this->colorstackidx]=$this->current_color_name; - $this->colorstack[$this->colorstackidx+1]=$this->current_color; - $this->colorstackidx+=2; - $this->SetColor($color); - } - else { - JpGraphError::RaiseL(25097);//("Color specified as empty string in PushColor()."); - } + if( $color != "" ) { + $this->colorstack[$this->colorstackidx]=$this->current_color_name; + $this->colorstack[$this->colorstackidx+1]=$this->current_color; + $this->colorstackidx+=2; + $this->SetColor($color); + } + else { + JpGraphError::RaiseL(25097);//("Color specified as empty string in PushColor()."); + } } - + function PopColor() { - if($this->colorstackidx<1) - JpGraphError::RaiseL(25098);//(" Negative Color stack index. Unmatched call to PopColor()"); - $this->current_color=$this->colorstack[--$this->colorstackidx]; - $this->current_color_name=$this->colorstack[--$this->colorstackidx]; + if( $this->colorstackidx < 1 ) { + JpGraphError::RaiseL(25098);//(" Negative Color stack index. Unmatched call to PopColor()"); + } + $this->current_color=$this->colorstack[--$this->colorstackidx]; + $this->current_color_name=$this->colorstack[--$this->colorstackidx]; } - - + + function SetLineWeight($weight) { - imagesetthickness($this->img,$weight); - $this->line_weight = $weight; + $old = $this->line_weight; + imagesetthickness($this->img,$weight); + $this->line_weight = $weight; + return $old; } - + function SetStartPoint($x,$y) { - $this->lastx=round($x); - $this->lasty=round($y); + $this->lastx=round($x); + $this->lasty=round($y); } - + function Arc($cx,$cy,$w,$h,$s,$e) { - // GD Arc doesn't like negative angles - while( $s < 0) $s += 360; - while( $e < 0) $e += 360; - - imagearc($this->img,round($cx),round($cy),round($w),round($h), - $s,$e,$this->current_color); + // GD Arc doesn't like negative angles + while( $s < 0) $s += 360; + while( $e < 0) $e += 360; + imagearc($this->img,round($cx),round($cy),round($w),round($h),$s,$e,$this->current_color); } - + function FilledArc($xc,$yc,$w,$h,$s,$e,$style='') { - while( $s < 0 ) $s += 360; - while( $e < 0 ) $e += 360; - if( $style=='' ) - $style=IMG_ARC_PIE; - if( abs($s-$e) > 0.001 ) { - imagefilledarc($this->img,round($xc),round($yc),round($w),round($h), - round($s),round($e),$this->current_color,$style); - } + $s = round($s); + $e = round($e); + while( $s < 0 ) $s += 360; + while( $e < 0 ) $e += 360; + if( $style=='' ) + $style=IMG_ARC_PIE; + if( abs($s-$e) > 0 ) { + imagefilledarc($this->img,round($xc),round($yc),round($w),round($h),$s,$e,$this->current_color,$style); + } } function FilledCakeSlice($cx,$cy,$w,$h,$s,$e) { - $this->CakeSlice($cx,$cy,$w,$h,$s,$e,$this->current_color_name); + $this->CakeSlice($cx,$cy,$w,$h,$s,$e,$this->current_color_name); } function CakeSlice($xc,$yc,$w,$h,$s,$e,$fillcolor="",$arccolor="") { - $s = round($s); $e = round($e); - $w = round($w); $h = round($h); - $xc = round($xc); $yc = round($yc); - if( $s ==$e ) { - // A full circle. We draw this a plain circle - $this->PushColor($fillcolor); - imagefilledellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color); - $this->PopColor(); - $this->PushColor($arccolor); - imageellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color); - $this->Line($xc,$yc,cos($s*M_PI/180)*$w+$xc,$yc+sin($s*M_PI/180)*$h); - $this->PopColor(); - } - else { - $this->PushColor($fillcolor); - $this->FilledArc($xc,$yc,2*$w,2*$h,$s,$e); - $this->PopColor(); - if( $arccolor != "" ) { - $this->PushColor($arccolor); - // We add 2 pixels to make the Arc() better aligned with - // the filled arc. - imagefilledarc($this->img,$xc,$yc,2*$w,2*$h,$s,$e,$this->current_color,IMG_ARC_NOFILL | IMG_ARC_EDGED ) ; - $this->PopColor(); - } - } + $s = round($s); $e = round($e); + $w = round($w); $h = round($h); + $xc = round($xc); $yc = round($yc); + if( $s ==$e ) { + // A full circle. We draw this a plain circle + $this->PushColor($fillcolor); + imagefilledellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color); + $this->PopColor(); + $this->PushColor($arccolor); + imageellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color); + $this->Line($xc,$yc,cos($s*M_PI/180)*$w+$xc,$yc+sin($s*M_PI/180)*$h); + $this->PopColor(); + } + else { + $this->PushColor($fillcolor); + $this->FilledArc($xc,$yc,2*$w,2*$h,$s,$e); + $this->PopColor(); + if( $arccolor != "" ) { + $this->PushColor($arccolor); + // We add 2 pixels to make the Arc() better aligned with + // the filled arc. + imagefilledarc($this->img,$xc,$yc,2*$w,2*$h,$s,$e,$this->current_color,IMG_ARC_NOFILL | IMG_ARC_EDGED ) ; + $this->PopColor(); + } + } } function Ellipse($xc,$yc,$w,$h) { - $this->Arc($xc,$yc,$w,$h,0,360); + $this->Arc($xc,$yc,$w,$h,0,360); } - + function Circle($xc,$yc,$r) { - imageellipse($this->img,round($xc),round($yc),$r*2,$r*2,$this->current_color); + imageellipse($this->img,round($xc),round($yc),$r*2,$r*2,$this->current_color); } - + function FilledCircle($xc,$yc,$r) { - imagefilledellipse($this->img,round($xc),round($yc),2*$r,2*$r,$this->current_color); + imagefilledellipse($this->img,round($xc),round($yc),2*$r,2*$r,$this->current_color); } - + // Linear Color InterPolation function lip($f,$t,$p) { - $p = round($p,1); - $r = $f[0] + ($t[0]-$f[0])*$p; - $g = $f[1] + ($t[1]-$f[1])*$p; - $b = $f[2] + ($t[2]-$f[2])*$p; - return array($r,$g,$b); + $p = round($p,1); + $r = $f[0] + ($t[0]-$f[0])*$p; + $g = $f[1] + ($t[1]-$f[1])*$p; + $b = $f[2] + ($t[2]-$f[2])*$p; + return array($r,$g,$b); } // Set line style dashed, dotted etc function SetLineStyle($s) { - if( is_numeric($s) ) { - if( $s<1 || $s>4 ) - JpGraphError::RaiseL(25101,$s);//(" Illegal numeric argument to SetLineStyle(): ($s)"); - } - elseif( is_string($s) ) { - if( $s == "solid" ) $s=1; - elseif( $s == "dotted" ) $s=2; - elseif( $s == "dashed" ) $s=3; - elseif( $s == "longdashed" ) $s=4; - else JpGraphError::RaiseL(25102,$s);//(" Illegal string argument to SetLineStyle(): $s"); - } - else { - JpGraphError::RaiseL(25103,$s);//(" Illegal argument to SetLineStyle $s"); - } - $old = $this->line_style; - $this->line_style=$s; - return $old; + if( is_numeric($s) ) { + if( $s<1 || $s>4 ) { + JpGraphError::RaiseL(25101,$s);//(" Illegal numeric argument to SetLineStyle(): ($s)"); + } + } + elseif( is_string($s) ) { + if( $s == "solid" ) $s=1; + elseif( $s == "dotted" ) $s=2; + elseif( $s == "dashed" ) $s=3; + elseif( $s == "longdashed" ) $s=4; + else { + JpGraphError::RaiseL(25102,$s);//(" Illegal string argument to SetLineStyle(): $s"); + } + } + else { + JpGraphError::RaiseL(25103,$s);//(" Illegal argument to SetLineStyle $s"); + } + $old = $this->line_style; + $this->line_style=$s; + return $old; } - + // Same as Line but take the line_style into account function StyleLine($x1,$y1,$x2,$y2,$aStyle='') { - if( $this->line_weight <= 0 ) - return; + if( $this->line_weight <= 0 ) return; - if( $aStyle === '' ) { - $aStyle = $this->line_style; - } + if( $aStyle === '' ) { + $aStyle = $this->line_style; + } - // Add error check since dashed line will only work if anti-alias is disabled - // this is a limitation in GD + // Add error check since dashed line will only work if anti-alias is disabled + // this is a limitation in GD - switch( $aStyle ) { - case 1:// Solid - $this->Line($x1,$y1,$x2,$y2); - break; - case 2: // Dotted - $this->DashedLine($x1,$y1,$x2,$y2,2,6); - break; - case 3: // Dashed - $this->DashedLine($x1,$y1,$x2,$y2,5,9); - break; - case 4: // Longdashes - $this->DashedLine($x1,$y1,$x2,$y2,9,13); - break; - default: - JpGraphError::RaiseL(25104,$this->line_style);//(" Unknown line style: $this->line_style "); - break; - } + if( $aStyle == 1 ) { + // Solid style. We can handle anti-aliasing for this + $this->Line($x1,$y1,$x2,$y2); + } + else { + // Since the GD routines doesn't handle AA for styled line + // we have no option than to turn it off to get any lines at + // all if the weight > 1 + $oldaa = $this->GetAntiAliasing(); + if( $oldaa && $this->line_weight > 1 ) { + $this->SetAntiAliasing(false); + } + + switch( $aStyle ) { + case 2: // Dotted + $this->DashedLine($x1,$y1,$x2,$y2,2,6); + break; + case 3: // Dashed + $this->DashedLine($x1,$y1,$x2,$y2,5,9); + break; + case 4: // Longdashes + $this->DashedLine($x1,$y1,$x2,$y2,9,13); + break; + default: + JpGraphError::RaiseL(25104,$this->line_style);//(" Unknown line style: $this->line_style "); + break; + } + if( $oldaa ) { + $this->SetAntiAliasing(true); + } + } } - + function DashedLine($x1,$y1,$x2,$y2,$dash_length=1,$dash_space=4) { - if( $this->line_weight <= 0 ) - return; + if( $this->line_weight <= 0 ) return; - // Add error check to make sure anti-alias is not enabled. - // Dashed line does not work with anti-alias enabled. This - // is a limitation in GD. - if( $this->use_anti_aliasing ) { - JpGraphError::RaiseL(25129); // Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines. - } - + // Add error check to make sure anti-alias is not enabled. + // Dashed line does not work with anti-alias enabled. This + // is a limitation in GD. + if( $this->use_anti_aliasing ) { + JpGraphError::RaiseL(25129); // Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines. + } - $x1 = round($x1); - $x2 = round($x2); - $y1 = round($y1); - $y2 = round($y2); - $style = array_fill(0,$dash_length,$this->current_color); - $style = array_pad($style,$dash_space,IMG_COLOR_TRANSPARENT); - imagesetstyle($this->img, $style); - imageline($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); - $this->lastx=$x2; $this->lasty=$y2; - } + $x1 = round($x1); + $x2 = round($x2); + $y1 = round($y1); + $y2 = round($y2); + + $style = array_fill(0,$dash_length,$this->current_color); + $style = array_pad($style,$dash_space,IMG_COLOR_TRANSPARENT); + imagesetstyle($this->img, $style); + imageline($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); + $this->lastx = $x2; + $this->lasty = $y2; + } function Line($x1,$y1,$x2,$y2) { - if( $this->line_weight <= 0 ) - return; + if( $this->line_weight <= 0 ) return; - $x1 = round($x1); - $x2 = round($x2); - $y1 = round($y1); - $y2 = round($y2); + $x1 = round($x1); + $x2 = round($x2); + $y1 = round($y1); + $y2 = round($y2); - imageline($this->img,$x1,$y1,$x2,$y2,$this->current_color); - $this->lastx=$x2; $this->lasty=$y2; + imageline($this->img,$x1,$y1,$x2,$y2,$this->current_color); + $this->lastx=$x2; + $this->lasty=$y2; } function Polygon($p,$closed=FALSE,$fast=FALSE) { - if( $this->line_weight <= 0 ) - return; + if( $this->line_weight <= 0 ) return; - $n=count($p); - $oldx = $p[0]; - $oldy = $p[1]; - if( $fast ) { - for( $i=2; $i < $n; $i+=2 ) { - imageline($this->img,$oldx,$oldy,$p[$i],$p[$i+1],$this->current_color); - $oldx = $p[$i]; - $oldy = $p[$i+1]; - } - if( $closed ) { - imageline($this->img,$p[$n*2-2],$p[$n*2-1],$p[0],$p[1],$this->current_color); - } - } - else { - for( $i=2; $i < $n; $i+=2 ) { - $this->StyleLine($oldx,$oldy,$p[$i],$p[$i+1]); - $oldx = $p[$i]; - $oldy = $p[$i+1]; - } - if( $closed ) - $this->StyleLine($oldx,$oldy,$p[0],$p[1]); - } + $n=count($p); + $oldx = $p[0]; + $oldy = $p[1]; + if( $fast ) { + for( $i=2; $i < $n; $i+=2 ) { + imageline($this->img,$oldx,$oldy,$p[$i],$p[$i+1],$this->current_color); + $oldx = $p[$i]; + $oldy = $p[$i+1]; + } + if( $closed ) { + imageline($this->img,$p[$n*2-2],$p[$n*2-1],$p[0],$p[1],$this->current_color); + } + } + else { + for( $i=2; $i < $n; $i+=2 ) { + $this->StyleLine($oldx,$oldy,$p[$i],$p[$i+1]); + $oldx = $p[$i]; + $oldy = $p[$i+1]; + } + if( $closed ) { + $this->StyleLine($oldx,$oldy,$p[0],$p[1]); + } + } } - + function FilledPolygon($pts) { - $n=count($pts); - if( $n == 0 ) { - JpGraphError::RaiseL(25105);//('NULL data specified for a filled polygon. Check that your data is not NULL.'); - } - for($i=0; $i < $n; ++$i) - $pts[$i] = round($pts[$i]); - imagefilledpolygon($this->img,$pts,count($pts)/2,$this->current_color); + $n=count($pts); + if( $n == 0 ) { + JpGraphError::RaiseL(25105);//('NULL data specified for a filled polygon. Check that your data is not NULL.'); + } + for($i=0; $i < $n; ++$i) { + $pts[$i] = round($pts[$i]); + } + imagefilledpolygon($this->img,$pts,count($pts)/2,$this->current_color); } - + function Rectangle($xl,$yu,$xr,$yl) { - $this->Polygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl,$xl,$yu)); + $this->Polygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl,$xl,$yu)); } - + function FilledRectangle($xl,$yu,$xr,$yl) { - $this->FilledPolygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl)); + $this->FilledPolygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl)); } function FilledRectangle2($xl,$yu,$xr,$yl,$color1,$color2,$style=1) { - // Fill a rectangle with lines of two colors - if( $style===1 ) { - // Horizontal stripe - if( $yl < $yu ) { - $t = $yl; $yl=$yu; $yu=$t; - } - for( $y=$yu; $y <= $yl; ++$y) { - $this->SetColor($color1); - $this->Line($xl,$y,$xr,$y); - ++$y; - $this->SetColor($color2); - $this->Line($xl,$y,$xr,$y); - } - } - else { - if( $xl < $xl ) { - $t = $xl; $xl=$xr; $xr=$t; - } - for( $x=$xl; $x <= $xr; ++$x) { - $this->SetColor($color1); - $this->Line($x,$yu,$x,$yl); - ++$x; - $this->SetColor($color2); - $this->Line($x,$yu,$x,$yl); - } - } + // Fill a rectangle with lines of two colors + if( $style===1 ) { + // Horizontal stripe + if( $yl < $yu ) { + $t = $yl; $yl=$yu; $yu=$t; + } + for( $y=$yu; $y <= $yl; ++$y) { + $this->SetColor($color1); + $this->Line($xl,$y,$xr,$y); + ++$y; + $this->SetColor($color2); + $this->Line($xl,$y,$xr,$y); + } + } + else { + if( $xl < $xl ) { + $t = $xl; $xl=$xr; $xr=$t; + } + for( $x=$xl; $x <= $xr; ++$x) { + $this->SetColor($color1); + $this->Line($x,$yu,$x,$yl); + ++$x; + $this->SetColor($color2); + $this->Line($x,$yu,$x,$yl); + } + } } function ShadowRectangle($xl,$yu,$xr,$yl,$fcolor=false,$shadow_width=3,$shadow_color=array(102,102,102)) { - // This is complicated by the fact that we must also handle the case where + // This is complicated by the fact that we must also handle the case where // the reactangle has no fill color - $this->PushColor($shadow_color); - $this->FilledRectangle($xr-$shadow_width,$yu+$shadow_width,$xr,$yl-$shadow_width-1); - $this->FilledRectangle($xl+$shadow_width,$yl-$shadow_width,$xr,$yl); - //$this->FilledRectangle($xl+$shadow_width,$yu+$shadow_width,$xr,$yl); - $this->PopColor(); - if( $fcolor==false ) - $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); - else { - $this->PushColor($fcolor); - $this->FilledRectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); - $this->PopColor(); - $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); - } + $this->PushColor($shadow_color); + $this->FilledRectangle($xr-$shadow_width,$yu+$shadow_width,$xr,$yl-$shadow_width-1); + $this->FilledRectangle($xl+$shadow_width,$yl-$shadow_width,$xr,$yl); + //$this->FilledRectangle($xl+$shadow_width,$yu+$shadow_width,$xr,$yl); + $this->PopColor(); + if( $fcolor==false ) { + $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); + } + else { + $this->PushColor($fcolor); + $this->FilledRectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); + $this->PopColor(); + $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1); + } } function FilledRoundedRectangle($xt,$yt,$xr,$yl,$r=5) { - if( $r==0 ) { - $this->FilledRectangle($xt,$yt,$xr,$yl); - return; - } + if( $r==0 ) { + $this->FilledRectangle($xt,$yt,$xr,$yl); + return; + } - // To avoid overlapping fillings (which will look strange - // when alphablending is enabled) we have no choice but - // to fill the five distinct areas one by one. - - // Center square - $this->FilledRectangle($xt+$r,$yt+$r,$xr-$r,$yl-$r); - // Top band - $this->FilledRectangle($xt+$r,$yt,$xr-$r,$yt+$r-1); - // Bottom band - $this->FilledRectangle($xt+$r,$yl-$r+1,$xr-$r,$yl); - // Left band - $this->FilledRectangle($xt,$yt+$r+1,$xt+$r-1,$yl-$r); - // Right band - $this->FilledRectangle($xr-$r+1,$yt+$r,$xr,$yl-$r); + // To avoid overlapping fillings (which will look strange + // when alphablending is enabled) we have no choice but + // to fill the five distinct areas one by one. - // Topleft & Topright arc - $this->FilledArc($xt+$r,$yt+$r,$r*2,$r*2,180,270); - $this->FilledArc($xr-$r,$yt+$r,$r*2,$r*2,270,360); + // Center square + $this->FilledRectangle($xt+$r,$yt+$r,$xr-$r,$yl-$r); + // Top band + $this->FilledRectangle($xt+$r,$yt,$xr-$r,$yt+$r-1); + // Bottom band + $this->FilledRectangle($xt+$r,$yl-$r+1,$xr-$r,$yl); + // Left band + $this->FilledRectangle($xt,$yt+$r+1,$xt+$r-1,$yl-$r); + // Right band + $this->FilledRectangle($xr-$r+1,$yt+$r,$xr,$yl-$r); - // Bottomleft & Bottom right arc - $this->FilledArc($xt+$r,$yl-$r,$r*2,$r*2,90,180); - $this->FilledArc($xr-$r,$yl-$r,$r*2,$r*2,0,90); + // Topleft & Topright arc + $this->FilledArc($xt+$r,$yt+$r,$r*2,$r*2,180,270); + $this->FilledArc($xr-$r,$yt+$r,$r*2,$r*2,270,360); + + // Bottomleft & Bottom right arc + $this->FilledArc($xt+$r,$yl-$r,$r*2,$r*2,90,180); + $this->FilledArc($xr-$r,$yl-$r,$r*2,$r*2,0,90); } - function RoundedRectangle($xt,$yt,$xr,$yl,$r=5) { + function RoundedRectangle($xt,$yt,$xr,$yl,$r=5) { - if( $r==0 ) { - $this->Rectangle($xt,$yt,$xr,$yl); - return; - } + if( $r==0 ) { + $this->Rectangle($xt,$yt,$xr,$yl); + return; + } - // Top & Bottom line - $this->Line($xt+$r,$yt,$xr-$r,$yt); - $this->Line($xt+$r,$yl,$xr-$r,$yl); + // Top & Bottom line + $this->Line($xt+$r,$yt,$xr-$r,$yt); + $this->Line($xt+$r,$yl,$xr-$r,$yl); - // Left & Right line - $this->Line($xt,$yt+$r,$xt,$yl-$r); - $this->Line($xr,$yt+$r,$xr,$yl-$r); + // Left & Right line + $this->Line($xt,$yt+$r,$xt,$yl-$r); + $this->Line($xr,$yt+$r,$xr,$yl-$r); - // Topleft & Topright arc - $this->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270); - $this->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360); + // Topleft & Topright arc + $this->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270); + $this->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360); - // Bottomleft & Bottomright arc - $this->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180); - $this->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90); + // Bottomleft & Bottomright arc + $this->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180); + $this->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90); } function FilledBevel($x1,$y1,$x2,$y2,$depth=2,$color1='white@0.4',$color2='darkgray@0.4') { - $this->FilledRectangle($x1,$y1,$x2,$y2); - $this->Bevel($x1,$y1,$x2,$y2,$depth,$color1,$color2); + $this->FilledRectangle($x1,$y1,$x2,$y2); + $this->Bevel($x1,$y1,$x2,$y2,$depth,$color1,$color2); } function Bevel($x1,$y1,$x2,$y2,$depth=2,$color1='white@0.4',$color2='black@0.5') { - $this->PushColor($color1); - for( $i=0; $i < $depth; ++$i ) { - $this->Line($x1+$i,$y1+$i,$x1+$i,$y2-$i); - $this->Line($x1+$i,$y1+$i,$x2-$i,$y1+$i); - } - $this->PopColor(); - - $this->PushColor($color2); - for( $i=0; $i < $depth; ++$i ) { - $this->Line($x1+$i,$y2-$i,$x2-$i,$y2-$i); - $this->Line($x2-$i,$y1+$i,$x2-$i,$y2-$i-1); - } - $this->PopColor(); + $this->PushColor($color1); + for( $i=0; $i < $depth; ++$i ) { + $this->Line($x1+$i,$y1+$i,$x1+$i,$y2-$i); + $this->Line($x1+$i,$y1+$i,$x2-$i,$y1+$i); + } + $this->PopColor(); + + $this->PushColor($color2); + for( $i=0; $i < $depth; ++$i ) { + $this->Line($x1+$i,$y2-$i,$x2-$i,$y2-$i); + $this->Line($x2-$i,$y1+$i,$x2-$i,$y2-$i-1); + } + $this->PopColor(); } function StyleLineTo($x,$y) { - $this->StyleLine($this->lastx,$this->lasty,$x,$y); - $this->lastx=$x; - $this->lasty=$y; + $this->StyleLine($this->lastx,$this->lasty,$x,$y); + $this->lastx=$x; + $this->lasty=$y; } - + function LineTo($x,$y) { - $this->Line($this->lastx,$this->lasty,$x,$y); - $this->lastx=$x; - $this->lasty=$y; + $this->Line($this->lastx,$this->lasty,$x,$y); + $this->lastx=$x; + $this->lasty=$y; } - + function Point($x,$y) { - imagesetpixel($this->img,round($x),round($y),$this->current_color); + imagesetpixel($this->img,round($x),round($y),$this->current_color); } - + function Fill($x,$y) { - imagefill($this->img,round($x),round($y),$this->current_color); + imagefill($this->img,round($x),round($y),$this->current_color); } function FillToBorder($x,$y,$aBordColor) { - $bc = $this->rgb->allocate($aBordColor); - if( $bc == -1 ) { - JpGraphError::RaiseL(25106);//('Image::FillToBorder : Can not allocate more colors'); - } - imagefilltoborder($this->img,round($x),round($y),$bc,$this->current_color); + $bc = $this->rgb->allocate($aBordColor); + if( $bc == -1 ) { + JpGraphError::RaiseL(25106);//('Image::FillToBorder : Can not allocate more colors'); + } + imagefilltoborder($this->img,round($x),round($y),$bc,$this->current_color); } function SetExpired($aFlg=true) { - $this->expired = $aFlg; + $this->expired = $aFlg; } - + // Generate image header function Headers() { - - // In case we are running from the command line with the client version of - // PHP we can't send any headers. - $sapi = php_sapi_name(); - if( $sapi == 'cli' ) - return; - // These parameters are set by headers_sent() but they might cause - // an undefined variable error unless they are initilized - $file=''; - $lineno=''; - if( headers_sent($file,$lineno) ) { - $file=basename($file); - $t = new ErrMsgText(); - $msg = $t->Get(10,$file,$lineno); - die($msg); - } - - if ($this->expired) { - header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); - header("Cache-Control: no-cache, must-revalidate"); - header("Pragma: no-cache"); - } - header("Content-type: image/$this->img_format"); + // In case we are running from the command line with the client version of + // PHP we can't send any headers. + $sapi = php_sapi_name(); + if( $sapi == 'cli' ) return; + + // These parameters are set by headers_sent() but they might cause + // an undefined variable error unless they are initilized + $file=''; + $lineno=''; + if( headers_sent($file,$lineno) ) { + $file=basename($file); + $t = new ErrMsgText(); + $msg = $t->Get(10,$file,$lineno); + die($msg); + } + + if ($this->expired) { + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); + header("Cache-Control: no-cache, must-revalidate"); + header("Pragma: no-cache"); + } + header("Content-type: image/$this->img_format"); } // Adjust image quality for formats that allow this function SetQuality($q) { - $this->quality = $q; + $this->quality = $q; } - + // Stream image to browser or to file function Stream($aFile="") { - $func="image".$this->img_format; - if( $this->img_format=="jpeg" && $this->quality != null ) { - $res = @$func($this->img,$aFile,$this->quality); - } - else { - if( $aFile != "" ) { - $res = @$func($this->img,$aFile); - if( !$res ) - JpGraphError::RaiseL(25107,$aFile);//("Can't write to file '$aFile'. Check that the process running PHP has enough permission."); - } - else { - $res = @$func($this->img); - if( !$res ) - JpGraphError::RaiseL(25108);//("Can't stream image. This is most likely due to a faulty PHP/GD setup. Try to recompile PHP and use the built-in GD library that comes with PHP."); - - } - } + $func="image".$this->img_format; + if( $this->img_format=="jpeg" && $this->quality != null ) { + $res = @$func($this->img,$aFile,$this->quality); + } + else { + if( $aFile != "" ) { + $res = @$func($this->img,$aFile); + if( !$res ) { + JpGraphError::RaiseL(25107,$aFile);//("Can't write to file '$aFile'. Check that the process running PHP has enough permission."); + } + } + else { + $res = @$func($this->img); + if( !$res ) { + JpGraphError::RaiseL(25108);//("Can't stream image. This is most likely due to a faulty PHP/GD setup. Try to recompile PHP and use the built-in GD library that comes with PHP."); + } + + } + } } - - // Clear resource tide up by image + + // Clear resources used by image (this is normally not used since all resources are/should be + // returned when the script terminates function Destroy() { - imagedestroy($this->img); + imagedestroy($this->img); } - + // Specify image format. Note depending on your installation // of PHP not all formats may be supported. - function SetImgFormat($aFormat,$aQuality=75) { - $this->quality = $aQuality; - $aFormat = strtolower($aFormat); - $tst = true; - $supported = imagetypes(); - if( $aFormat=="auto" ) { - if( $supported & IMG_PNG ) - $this->img_format="png"; - elseif( $supported & IMG_JPG ) - $this->img_format="jpeg"; - elseif( $supported & IMG_GIF ) - $this->img_format="gif"; - elseif( $supported & IMG_WBMP ) - $this->img_format="wbmp"; - elseif( $supported & IMG_XPM ) - $this->img_format="xpm"; - else - JpGraphError::RaiseL(25109);//("Your PHP (and GD-lib) installation does not appear to support any known graphic formats. You need to first make sure GD is compiled as a module to PHP. If you also want to use JPEG images you must get the JPEG library. Please see the PHP docs for details."); - - return true; - } - else { - if( $aFormat=="jpeg" || $aFormat=="png" || $aFormat=="gif" ) { - if( $aFormat=="jpeg" && !($supported & IMG_JPG) ) - $tst=false; - elseif( $aFormat=="png" && !($supported & IMG_PNG) ) - $tst=false; - elseif( $aFormat=="gif" && !($supported & IMG_GIF) ) - $tst=false; - elseif( $aFormat=="wbmp" && !($supported & IMG_WBMP) ) - $tst=false; - elseif( $aFormat=="xpm" && !($supported & IMG_XPM) ) - $tst=false; - else { - $this->img_format=$aFormat; - return true; - } - } - else - $tst=false; - if( !$tst ) - JpGraphError::RaiseL(25110,$aFormat);//(" Your PHP installation does not support the chosen graphic format: $aFormat"); - } - } + function SetImgFormat($aFormat,$aQuality=75) { + $this->quality = $aQuality; + $aFormat = strtolower($aFormat); + $tst = true; + $supported = imagetypes(); + if( $aFormat=="auto" ) { + if( $supported & IMG_PNG ) $this->img_format="png"; + elseif( $supported & IMG_JPG ) $this->img_format="jpeg"; + elseif( $supported & IMG_GIF ) $this->img_format="gif"; + elseif( $supported & IMG_WBMP ) $this->img_format="wbmp"; + elseif( $supported & IMG_XPM ) $this->img_format="xpm"; + else { + JpGraphError::RaiseL(25109);//("Your PHP (and GD-lib) installation does not appear to support any known graphic formats. You need to first make sure GD is compiled as a module to PHP. If you also want to use JPEG images you must get the JPEG library. Please see the PHP docs for details."); + } + return true; + } + else { + if( $aFormat=="jpeg" || $aFormat=="png" || $aFormat=="gif" ) { + if( $aFormat=="jpeg" && !($supported & IMG_JPG) ) $tst=false; + elseif( $aFormat=="png" && !($supported & IMG_PNG) ) $tst=false; + elseif( $aFormat=="gif" && !($supported & IMG_GIF) ) $tst=false; + elseif( $aFormat=="wbmp" && !($supported & IMG_WBMP) ) $tst=false; + elseif( $aFormat=="xpm" && !($supported & IMG_XPM) ) $tst=false; + else { + $this->img_format=$aFormat; + return true; + } + } + else { + $tst=false; + } + if( !$tst ) { + JpGraphError::RaiseL(25110,$aFormat);//(" Your PHP installation does not support the chosen graphic format: $aFormat"); + } + } + } } // CLASS //=================================================== @@ -1302,318 +1350,352 @@ class Image { //=================================================== class RotImage extends Image { public $a=0; - public $dx=0,$dy=0,$transx=0,$transy=0; + public $dx=0,$dy=0,$transx=0,$transy=0; private $m=array(); - - function RotImage($aWidth,$aHeight,$a=0,$aFormat=DEFAULT_GFORMAT,$aSetAutoMargin=true) { - $this->Image($aWidth,$aHeight,$aFormat,$aSetAutoMargin); - $this->dx=$this->left_margin+$this->plotwidth/2; - $this->dy=$this->top_margin+$this->plotheight/2; - $this->SetAngle($a); + + function __construct($aWidth,$aHeight,$a=0,$aFormat=DEFAULT_GFORMAT,$aSetAutoMargin=true) { + parent::__construct($aWidth,$aHeight,$aFormat,$aSetAutoMargin); + $this->dx=$this->left_margin+$this->plotwidth/2; + $this->dy=$this->top_margin+$this->plotheight/2; + $this->SetAngle($a); } - + function SetCenter($dx,$dy) { - $old_dx = $this->dx; - $old_dy = $this->dy; - $this->dx=$dx; - $this->dy=$dy; - $this->SetAngle($this->a); - return array($old_dx,$old_dy); + $old_dx = $this->dx; + $old_dy = $this->dy; + $this->dx=$dx; + $this->dy=$dy; + $this->SetAngle($this->a); + return array($old_dx,$old_dy); } - + function SetTranslation($dx,$dy) { - $old = array($this->transx,$this->transy); - $this->transx = $dx; - $this->transy = $dy; - return $old; + $old = array($this->transx,$this->transy); + $this->transx = $dx; + $this->transy = $dy; + return $old; } function UpdateRotMatrice() { - $a = $this->a; - $a *= M_PI/180; - $sa=sin($a); $ca=cos($a); - // Create the rotation matrix - $this->m[0][0] = $ca; - $this->m[0][1] = -$sa; - $this->m[0][2] = $this->dx*(1-$ca) + $sa*$this->dy ; - $this->m[1][0] = $sa; - $this->m[1][1] = $ca; - $this->m[1][2] = $this->dy*(1-$ca) - $sa*$this->dx ; + $a = $this->a; + $a *= M_PI/180; + $sa=sin($a); $ca=cos($a); + // Create the rotation matrix + $this->m[0][0] = $ca; + $this->m[0][1] = -$sa; + $this->m[0][2] = $this->dx*(1-$ca) + $sa*$this->dy ; + $this->m[1][0] = $sa; + $this->m[1][1] = $ca; + $this->m[1][2] = $this->dy*(1-$ca) - $sa*$this->dx ; } function SetAngle($a) { - $tmp = $this->a; - $this->a = $a; - $this->UpdateRotMatrice(); - return $tmp; + $tmp = $this->a; + $this->a = $a; + $this->UpdateRotMatrice(); + return $tmp; } function Circle($xc,$yc,$r) { - list($xc,$yc) = $this->Rotate($xc,$yc); - parent::Circle($xc,$yc,$r); + list($xc,$yc) = $this->Rotate($xc,$yc); + parent::Circle($xc,$yc,$r); } function FilledCircle($xc,$yc,$r) { - list($xc,$yc) = $this->Rotate($xc,$yc); - parent::FilledCircle($xc,$yc,$r); + list($xc,$yc) = $this->Rotate($xc,$yc); + parent::FilledCircle($xc,$yc,$r); } - + function Arc($xc,$yc,$w,$h,$s,$e) { - list($xc,$yc) = $this->Rotate($xc,$yc); - $s += $this->a; - $e += $this->a; - parent::Arc($xc,$yc,$w,$h,$s,$e); + list($xc,$yc) = $this->Rotate($xc,$yc); + $s += $this->a; + $e += $this->a; + parent::Arc($xc,$yc,$w,$h,$s,$e); } function FilledArc($xc,$yc,$w,$h,$s,$e,$style='') { - list($xc,$yc) = $this->Rotate($xc,$yc); - $s += $this->a; - $e += $this->a; - parent::FilledArc($xc,$yc,$w,$h,$s,$e); + list($xc,$yc) = $this->Rotate($xc,$yc); + $s += $this->a; + $e += $this->a; + parent::FilledArc($xc,$yc,$w,$h,$s,$e); } function SetMargin($lm,$rm,$tm,$bm) { - parent::SetMargin($lm,$rm,$tm,$bm); - $this->dx=$this->left_margin+$this->plotwidth/2; - $this->dy=$this->top_margin+$this->plotheight/2; - $this->UpdateRotMatrice(); + parent::SetMargin($lm,$rm,$tm,$bm); + $this->dx=$this->left_margin+$this->plotwidth/2; + $this->dy=$this->top_margin+$this->plotheight/2; + $this->UpdateRotMatrice(); } - + function Rotate($x,$y) { - // Optimization. Ignore rotation if Angle==0 || Angle==360 - if( $this->a == 0 || $this->a == 360 ) { - return array($x + $this->transx, $y + $this->transy ); - } - else { - $x1=round($this->m[0][0]*$x + $this->m[0][1]*$y,1) + $this->m[0][2] + $this->transx; - $y1=round($this->m[1][0]*$x + $this->m[1][1]*$y,1) + $this->m[1][2] + $this->transy; - return array($x1,$y1); - } + // Optimization. Ignore rotation if Angle==0 || Angle==360 + if( $this->a == 0 || $this->a == 360 ) { + return array($x + $this->transx, $y + $this->transy ); + } + else { + $x1=round($this->m[0][0]*$x + $this->m[0][1]*$y,1) + $this->m[0][2] + $this->transx; + $y1=round($this->m[1][0]*$x + $this->m[1][1]*$y,1) + $this->m[1][2] + $this->transy; + return array($x1,$y1); + } } - + function CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1,$aMix=100) { - list($toX,$toY) = $this->Rotate($toX,$toY); - parent::CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight,$aMix); + list($toX,$toY) = $this->Rotate($toX,$toY); + parent::CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight,$aMix); } function ArrRotate($pnts) { - $n = count($pnts)-1; - for($i=0; $i < $n; $i+=2) { - list ($x,$y) = $this->Rotate($pnts[$i],$pnts[$i+1]); - $pnts[$i] = $x; $pnts[$i+1] = $y; - } - return $pnts; + $n = count($pnts)-1; + for($i=0; $i < $n; $i+=2) { + list ($x,$y) = $this->Rotate($pnts[$i],$pnts[$i+1]); + $pnts[$i] = $x; $pnts[$i+1] = $y; + } + return $pnts; } function DashedLine($x1,$y1,$x2,$y2,$dash_length=1,$dash_space=4) { - list($x1,$y1) = $this->Rotate($x1,$y1); - list($x2,$y2) = $this->Rotate($x2,$y2); - parent::DashedLine($x1,$y1,$x2,$y2,$dash_length,$dash_space); + list($x1,$y1) = $this->Rotate($x1,$y1); + list($x2,$y2) = $this->Rotate($x2,$y2); + parent::DashedLine($x1,$y1,$x2,$y2,$dash_length,$dash_space); } - + function Line($x1,$y1,$x2,$y2) { - list($x1,$y1) = $this->Rotate($x1,$y1); - list($x2,$y2) = $this->Rotate($x2,$y2); - parent::Line($x1,$y1,$x2,$y2); + list($x1,$y1) = $this->Rotate($x1,$y1); + list($x2,$y2) = $this->Rotate($x2,$y2); + parent::Line($x1,$y1,$x2,$y2); } function Rectangle($x1,$y1,$x2,$y2) { - // Rectangle uses Line() so it will be rotated through that call - parent::Rectangle($x1,$y1,$x2,$y2); + // Rectangle uses Line() so it will be rotated through that call + parent::Rectangle($x1,$y1,$x2,$y2); } - + function FilledRectangle($x1,$y1,$x2,$y2) { - if( $y1==$y2 || $x1==$x2 ) - $this->Line($x1,$y1,$x2,$y2); - else - $this->FilledPolygon(array($x1,$y1,$x2,$y1,$x2,$y2,$x1,$y2)); + if( $y1==$y2 || $x1==$x2 ) + $this->Line($x1,$y1,$x2,$y2); + else + $this->FilledPolygon(array($x1,$y1,$x2,$y1,$x2,$y2,$x1,$y2)); } - + function Polygon($pnts,$closed=FALSE,$fast=FALSE) { - // Polygon uses Line() so it will be rotated through that call unless - // fast drawing routines are used in which case a rotate is needed - if( $fast ) { - parent::Polygon($this->ArrRotate($pnts)); - } - else - parent::Polygon($pnts,$closed,$fast); + // Polygon uses Line() so it will be rotated through that call unless + // fast drawing routines are used in which case a rotate is needed + if( $fast ) { + parent::Polygon($this->ArrRotate($pnts)); + } + else { + parent::Polygon($pnts,$closed,$fast); + } } - + function FilledPolygon($pnts) { - parent::FilledPolygon($this->ArrRotate($pnts)); + parent::FilledPolygon($this->ArrRotate($pnts)); } - + function Point($x,$y) { - list($xp,$yp) = $this->Rotate($x,$y); - parent::Point($xp,$yp); + list($xp,$yp) = $this->Rotate($x,$y); + parent::Point($xp,$yp); } - + function StrokeText($x,$y,$txt,$dir=0,$paragraph_align="left",$debug=false) { - list($xp,$yp) = $this->Rotate($x,$y); - return parent::StrokeText($xp,$yp,$txt,$dir,$paragraph_align,$debug); + list($xp,$yp) = $this->Rotate($x,$y); + return parent::StrokeText($xp,$yp,$txt,$dir,$paragraph_align,$debug); } } -//=================================================== +//======================================================================= // CLASS ImgStreamCache -// Description: Handle caching of graphs to files -//=================================================== +// Description: Handle caching of graphs to files. All image output goes +// through this class +//======================================================================= class ImgStreamCache { - private $cache_dir, $img=null, $timeout=0; // Infinite timeout + private $cache_dir, $timeout=0; // Infinite timeout //--------------- // CONSTRUCTOR - function ImgStreamCache($aImg, $aCacheDir=CACHE_DIR) { - $this->img = $aImg; - $this->cache_dir = $aCacheDir; + function __construct($aCacheDir=CACHE_DIR) { + $this->cache_dir = $aCacheDir; } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS // Specify a timeout (in minutes) for the file. If the file is older then the // timeout value it will be overwritten with a newer version. // If timeout is set to 0 this is the same as infinite large timeout and if // timeout is set to -1 this is the same as infinite small timeout function SetTimeout($aTimeout) { - $this->timeout=$aTimeout; + $this->timeout=$aTimeout; } - + // Output image to browser and also write it to the cache function PutAndStream($aImage,$aCacheFileName,$aInline,$aStrokeFileName) { - // Some debugging code to brand the image with numbe of colors - // used - GLOBAL $gJpgBrandTiming; - if( $gJpgBrandTiming ) { - global $tim; - $t=$tim->Pop()/1000.0; - $c=$aImage->SetColor("black"); - $t=sprintf(BRAND_TIME_FORMAT,round($t,3)); - imagestring($this->img->img,2,5,$this->img->height-20,$t,$c); - } + // Check if we should always stroke the image to a file + if( _FORCE_IMGTOFILE ) { + $aStrokeFileName = _FORCE_IMGDIR.GenImgName(); + } - // Check if we should stroke the image to an arbitrary file - if( _FORCE_IMGTOFILE ) { - $aStrokeFileName = _FORCE_IMGDIR.GenImgName(); - } + if( $aStrokeFileName != '' ) { - if( $aStrokeFileName!="" ) { - if( $aStrokeFileName == "auto" ) - $aStrokeFileName = GenImgName(); - if( file_exists($aStrokeFileName) ) { - // Delete the old file - if( !@unlink($aStrokeFileName) ) - JpGraphError::RaiseL(25111,$aStrokeFileName);//(" Can't delete cached image $aStrokeFileName. Permission problem?"); - } - $aImage->Stream($aStrokeFileName); - return; - } + if( $aStrokeFileName == 'auto' ) { + $aStrokeFileName = GenImgName(); + } - if( $aCacheFileName != "" && USE_CACHE) { + if( file_exists($aStrokeFileName) ) { - $aCacheFileName = $this->cache_dir . $aCacheFileName; - if( file_exists($aCacheFileName) ) { - if( !$aInline ) { - // If we are generating image off-line (just writing to the cache) - // and the file exists and is still valid (no timeout) - // then do nothing, just return. - $diff=time()-filemtime($aCacheFileName); - if( $diff < 0 ) - JpGraphError::RaiseL(25112,$aCacheFileName);//(" Cached imagefile ($aCacheFileName) has file date in the future!!"); - if( $this->timeout>0 && ($diff <= $this->timeout*60) ) - return; - } - if( !@unlink($aCacheFileName) ) - JpGraphError::RaiseL(25113,$aStrokeFileName);//(" Can't delete cached image $aStrokeFileName. Permission problem?"); - $aImage->Stream($aCacheFileName); - } - else { - $this->MakeDirs(dirname($aCacheFileName)); - if( !is_writeable(dirname($aCacheFileName)) ) { - JpGraphError::RaiseL(25114,$aCacheFileName);//('PHP has not enough permissions to write to the cache file '.$aCacheFileName.'. Please make sure that the user running PHP has write permission for this file if you wan to use the cache system with JpGraph.'); - } - $aImage->Stream($aCacheFileName); - } - - $res=true; - // Set group to specified - if( CACHE_FILE_GROUP != "" ) - $res = @chgrp($aCacheFileName,CACHE_FILE_GROUP); - if( CACHE_FILE_MOD != "" ) - $res = @chmod($aCacheFileName,CACHE_FILE_MOD); - if( !$res ) - JpGraphError::RaiseL(25115,$aStrokeFileName);//(" Can't set permission for cached image $aStrokeFileName. Permission problem?"); - - $aImage->Destroy(); - if( $aInline ) { - if ($fh = @fopen($aCacheFileName, "rb") ) { - $this->img->Headers(); - fpassthru($fh); - return; - } - else - JpGraphError::RaiseL(25116,$aFile);//(" Cant open file from cache [$aFile]"); - } - } - elseif( $aInline ) { - $this->img->Headers(); - $aImage->Stream(); - return; - } + // Wait for lock (to make sure no readers are trying to access the image) + $fd = fopen($aStrokeFileName,'w'); + $lock = flock($fd, LOCK_EX); + + // Since the image write routines only accepts a filename which must not + // exist we need to delete the old file first + if( !@unlink($aStrokeFileName) ) { + $lock = flock($fd, LOCK_UN); + JpGraphError::RaiseL(25111,$aStrokeFileName); + //(" Can't delete cached image $aStrokeFileName. Permission problem?"); + } + $aImage->Stream($aStrokeFileName); + $lock = flock($fd, LOCK_UN); + fclose($fd); + + } + else { + $aImage->Stream($aStrokeFileName); + } + + return; + } + + if( $aCacheFileName != '' && USE_CACHE) { + + $aCacheFileName = $this->cache_dir . $aCacheFileName; + if( file_exists($aCacheFileName) ) { + if( !$aInline ) { + // If we are generating image off-line (just writing to the cache) + // and the file exists and is still valid (no timeout) + // then do nothing, just return. + $diff=time()-filemtime($aCacheFileName); + if( $diff < 0 ) { + JpGraphError::RaiseL(25112,$aCacheFileName); + //(" Cached imagefile ($aCacheFileName) has file date in the future!!"); + } + if( $this->timeout>0 && ($diff <= $this->timeout*60) ) return; + } + + // Wait for lock (to make sure no readers are trying to access the image) + $fd = fopen($aCacheFileName,'w'); + $lock = flock($fd, LOCK_EX); + + if( !@unlink($aCacheFileName) ) { + $lock = flock($fd, LOCK_UN); + JpGraphError::RaiseL(25113,$aStrokeFileName); + //(" Can't delete cached image $aStrokeFileName. Permission problem?"); + } + $aImage->Stream($aCacheFileName); + $lock = flock($fd, LOCK_UN); + fclose($fd); + + } + else { + $this->MakeDirs(dirname($aCacheFileName)); + if( !is_writeable(dirname($aCacheFileName)) ) { + JpGraphError::RaiseL(25114,$aCacheFileName); + //('PHP has not enough permissions to write to the cache file '.$aCacheFileName.'. Please make sure that the user running PHP has write permission for this file if you wan to use the cache system with JpGraph.'); + } + $aImage->Stream($aCacheFileName); + } + + $res=true; + // Set group to specified + if( CACHE_FILE_GROUP != '' ) { + $res = @chgrp($aCacheFileName,CACHE_FILE_GROUP); + } + if( CACHE_FILE_MOD != '' ) { + $res = @chmod($aCacheFileName,CACHE_FILE_MOD); + } + if( !$res ) { + JpGraphError::RaiseL(25115,$aStrokeFileName); + //(" Can't set permission for cached image $aStrokeFileName. Permission problem?"); + } + + $aImage->Destroy(); + if( $aInline ) { + if ($fh = @fopen($aCacheFileName, "rb") ) { + $aImage->Headers(); + fpassthru($fh); + return; + } + else { + JpGraphError::RaiseL(25116,$aFile);//(" Cant open file from cache [$aFile]"); + } + } + } + elseif( $aInline ) { + $aImage->Headers(); + $aImage->Stream(); + return; + } } - + // Check if a given image is in cache and in that case // pass it directly on to web browser. Return false if the // image file doesn't exist or exists but is to old - function GetAndStream($aCacheFileName) { - $aCacheFileName = $this->cache_dir.$aCacheFileName; - if ( USE_CACHE && file_exists($aCacheFileName) && $this->timeout>=0 ) { - $diff=time()-filemtime($aCacheFileName); - if( $this->timeout>0 && ($diff > $this->timeout*60) ) { - return false; - } - else { - if ($fh = @fopen($aCacheFileName, "rb")) { - $this->img->Headers(); - fpassthru($fh); - return true; - } - else - JpGraphError::RaiseL(25117,$aCacheFileName);//(" Can't open cached image \"$aCacheFileName\" for reading."); - } - } - return false; + function GetAndStream($aImage,$aCacheFileName) { + $aCacheFileName = $this->cache_dir.$aCacheFileName; + if ( USE_CACHE && file_exists($aCacheFileName) && $this->timeout >= 0 ) { + $diff=time()-filemtime($aCacheFileName); + if( $this->timeout>0 && ($diff > $this->timeout*60) ) { + return false; + } + else { + if ($fh = @fopen($aCacheFileName, 'rb')) { + $lock = flock($fh, LOCK_SH); + $aImage->Headers(); + fpassthru($fh); + $lock = flock($fh, LOCK_UN); + fclose($fh); + return true; + } + else { + JpGraphError::RaiseL(25117,$aCacheFileName);//(" Can't open cached image \"$aCacheFileName\" for reading."); + } + } + } + return false; } - + //--------------- - // PRIVATE METHODS + // PRIVATE METHODS // Create all necessary directories in a path function MakeDirs($aFile) { - $dirs = array(); - while ( !(file_exists($aFile)) ) { - $dirs[] = $aFile; - $aFile = dirname($aFile); - } - for ($i = sizeof($dirs)-1; $i>=0; $i--) { - if(! @mkdir($dirs[$i],0777) ) - JpGraphError::RaiseL(25118,$aFile);//(" Can't create directory $aFile. Make sure PHP has write permission to this directory."); - // We also specify mode here after we have changed group. - // This is necessary if Apache user doesn't belong the - // default group and hence can't specify group permission - // in the previous mkdir() call - if( CACHE_FILE_GROUP != "" ) { - $res=true; - $res =@chgrp($dirs[$i],CACHE_FILE_GROUP); - $res = @chmod($dirs[$i],0777); - if( !$res ) - JpGraphError::RaiseL(25119,$aFile);//(" Can't set permissions for $aFile. Permission problems?"); - } - } - return true; - } + $dirs = array(); + // In order to better work when open_basedir is enabled + // we do not create directories in the root path + while ( $aFile != '/' && !(file_exists($aFile)) ) { + $dirs[] = $aFile.'/'; + $aFile = dirname($aFile); + } + for ($i = sizeof($dirs)-1; $i>=0; $i--) { + if(! @mkdir($dirs[$i],0777) ) { + JpGraphError::RaiseL(25118,$aFile);//(" Can't create directory $aFile. Make sure PHP has write permission to this directory."); + } + // We also specify mode here after we have changed group. + // This is necessary if Apache user doesn't belong the + // default group and hence can't specify group permission + // in the previous mkdir() call + if( CACHE_FILE_GROUP != "" ) { + $res=true; + $res =@chgrp($dirs[$i],CACHE_FILE_GROUP); + $res = @chmod($dirs[$i],0777); + if( !$res ) { + JpGraphError::RaiseL(25119,$aFile);//(" Can't set permissions for $aFile. Permission problems?"); + } + } + } + return true; + } } // CLASS Cache - ?> diff --git a/src/classes/jpgraph/jpg-config.inc.php b/src/classes/jpgraph/jpg-config.inc.php index b148bf8..93df0c8 100644 --- a/src/classes/jpgraph/jpg-config.inc.php +++ b/src/classes/jpgraph/jpg-config.inc.php @@ -1,17 +1,16 @@ diff --git a/src/classes/jpgraph/jpgraph.php b/src/classes/jpgraph/jpgraph.php index 9626fac..04eae45 100644 --- a/src/classes/jpgraph/jpgraph.php +++ b/src/classes/jpgraph/jpgraph.php @@ -1,9 +1,9 @@ Get(11,$file,$lineno); - die($msg); - } - else { - DEFINE('CACHE_DIR', $_SERVER['TEMP'] . '/'); - } - } else { - DEFINE('CACHE_DIR','/tmp/jpgraph_cache/'); - } + if ( strstr( PHP_OS, 'WIN') ) { + if( empty($_SERVER['TEMP']) ) { + $t = new ErrMsgText(); + $msg = $t->Get(11,$file,$lineno); + die($msg); + } + else { + define('CACHE_DIR', $_SERVER['TEMP'] . '/'); + } + } else { + define('CACHE_DIR','/tmp/jpgraph_cache/'); + } } } elseif( !defined('CACHE_DIR') ) { - DEFINE('CACHE_DIR', ''); + define('CACHE_DIR', ''); } +// +// Setup path for western/latin TTF fonts +// if (!defined('TTF_DIR')) { if (strstr( PHP_OS, 'WIN') ) { - $sroot = getenv('SystemRoot'); + $sroot = getenv('SystemRoot'); if( empty($sroot) ) { - $t = new ErrMsgText(); - $msg = $t->Get(12,$file,$lineno); - die($msg); + $t = new ErrMsgText(); + $msg = $t->Get(12,$file,$lineno); + die($msg); } - else { - DEFINE('TTF_DIR', $sroot.'/fonts/'); + else { + define('TTF_DIR', $sroot.'/fonts/'); } } else { - DEFINE('TTF_DIR','/usr/X11R6/lib/X11/fonts/truetype/'); + define('TTF_DIR','/usr/share/fonts/truetype/'); } } +// +// Setup path for MultiByte TTF fonts (japanese, chinese etc.) +// if (!defined('MBTTF_DIR')) { - DEFINE('MBTTF_DIR','/usr/share/fonts/ja/TrueType/'); + if (strstr( PHP_OS, 'WIN') ) { + $sroot = getenv('SystemRoot'); + if( empty($sroot) ) { + $t = new ErrMsgText(); + $msg = $t->Get(12,$file,$lineno); + die($msg); + } + else { + define('MBTTF_DIR', $sroot.'/fonts/'); + } + } else { + define('MBTTF_DIR','/usr/share/fonts/truetype/'); + } } -//------------------------------------------------------------------ -// Constants which are used as parameters for the method calls -//------------------------------------------------------------------ +// +// Check minimum PHP version +// +function CheckPHPVersion($aMinVersion) { + list($majorC, $minorC, $editC) = preg_split('/[\/.-]/', PHP_VERSION); + list($majorR, $minorR, $editR) = preg_split('/[\/.-]/', $aMinVersion); - -// Tick density -DEFINE("TICKD_DENSE",1); -DEFINE("TICKD_NORMAL",2); -DEFINE("TICKD_SPARSE",3); -DEFINE("TICKD_VERYSPARSE",4); - -// Side for ticks and labels. -DEFINE("SIDE_LEFT",-1); -DEFINE("SIDE_RIGHT",1); -DEFINE("SIDE_DOWN",-1); -DEFINE("SIDE_BOTTOM",-1); -DEFINE("SIDE_UP",1); -DEFINE("SIDE_TOP",1); - -// Legend type stacked vertical or horizontal -DEFINE("LEGEND_VERT",0); -DEFINE("LEGEND_HOR",1); - -// Mark types for plot marks -DEFINE("MARK_SQUARE",1); -DEFINE("MARK_UTRIANGLE",2); -DEFINE("MARK_DTRIANGLE",3); -DEFINE("MARK_DIAMOND",4); -DEFINE("MARK_CIRCLE",5); -DEFINE("MARK_FILLEDCIRCLE",6); -DEFINE("MARK_CROSS",7); -DEFINE("MARK_STAR",8); -DEFINE("MARK_X",9); -DEFINE("MARK_LEFTTRIANGLE",10); -DEFINE("MARK_RIGHTTRIANGLE",11); -DEFINE("MARK_FLASH",12); -DEFINE("MARK_IMG",13); -DEFINE("MARK_FLAG1",14); -DEFINE("MARK_FLAG2",15); -DEFINE("MARK_FLAG3",16); -DEFINE("MARK_FLAG4",17); - -// Builtin images -DEFINE("MARK_IMG_PUSHPIN",50); -DEFINE("MARK_IMG_SPUSHPIN",50); -DEFINE("MARK_IMG_LPUSHPIN",51); -DEFINE("MARK_IMG_DIAMOND",52); -DEFINE("MARK_IMG_SQUARE",53); -DEFINE("MARK_IMG_STAR",54); -DEFINE("MARK_IMG_BALL",55); -DEFINE("MARK_IMG_SBALL",55); -DEFINE("MARK_IMG_MBALL",56); -DEFINE("MARK_IMG_LBALL",57); -DEFINE("MARK_IMG_BEVEL",58); - -// Inline defines -DEFINE("INLINE_YES",1); -DEFINE("INLINE_NO",0); - -// Format for background images -DEFINE("BGIMG_FILLPLOT",1); -DEFINE("BGIMG_FILLFRAME",2); -DEFINE("BGIMG_COPY",3); -DEFINE("BGIMG_CENTER",4); - -// Depth of objects -DEFINE("DEPTH_BACK",0); -DEFINE("DEPTH_FRONT",1); - -// Direction -DEFINE("VERTICAL",1); -DEFINE("HORIZONTAL",0); - - -// Axis styles for scientific style axis -DEFINE('AXSTYLE_SIMPLE',1); -DEFINE('AXSTYLE_BOXIN',2); -DEFINE('AXSTYLE_BOXOUT',3); -DEFINE('AXSTYLE_YBOXIN',4); -DEFINE('AXSTYLE_YBOXOUT',5); - -// Style for title backgrounds -DEFINE('TITLEBKG_STYLE1',1); -DEFINE('TITLEBKG_STYLE2',2); -DEFINE('TITLEBKG_STYLE3',3); -DEFINE('TITLEBKG_FRAME_NONE',0); -DEFINE('TITLEBKG_FRAME_FULL',1); -DEFINE('TITLEBKG_FRAME_BOTTOM',2); -DEFINE('TITLEBKG_FRAME_BEVEL',3); -DEFINE('TITLEBKG_FILLSTYLE_HSTRIPED',1); -DEFINE('TITLEBKG_FILLSTYLE_VSTRIPED',2); -DEFINE('TITLEBKG_FILLSTYLE_SOLID',3); - -// Style for background gradient fills -DEFINE('BGRAD_FRAME',1); -DEFINE('BGRAD_MARGIN',2); -DEFINE('BGRAD_PLOT',3); - -// Width of tab titles -DEFINE('TABTITLE_WIDTHFIT',0); -DEFINE('TABTITLE_WIDTHFULL',-1); - -// Defines for 3D skew directions -DEFINE('SKEW3D_UP',0); -DEFINE('SKEW3D_DOWN',1); -DEFINE('SKEW3D_LEFT',2); -DEFINE('SKEW3D_RIGHT',3); - -// Line styles -DEFINE('LINESTYLE_SOLID',1); -DEFINE('LINESTYLE_DOTTED',2); -DEFINE('LINESTYLE_DASHED',3); -DEFINE('LINESTYLE_LONGDASH',4); - -// For internal use only -DEFINE("_JPG_DEBUG",false); -DEFINE("_FORCE_IMGTOFILE",false); -DEFINE("_FORCE_IMGDIR",'/tmp/jpgimg/'); - -require_once('gd_image.inc.php'); - -function CheckPHPVersion($aMinVersion) -{ - list($majorC, $minorC, $editC) = split('[/.-]', PHP_VERSION); - list($majorR, $minorR, $editR) = split('[/.-]', $aMinVersion); - if ($majorC != $majorR) return false; if ($majorC < $majorR) return false; - // same major - check ninor + // same major - check minor if ($minorC > $minorR) return true; if ($minorC < $minorR) return false; // and same minor @@ -210,13 +247,12 @@ if( !CheckPHPVersion(MIN_PHPVERSION) ) { die(); } - // // Make GD sanity check // if( !function_exists("imagetypes") || !function_exists('imagecreatefromstring') ) { JpGraphError::RaiseL(25001); -//("This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)"); + //("This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)"); } // @@ -225,7 +261,7 @@ if( !function_exists("imagetypes") || !function_exists('imagecreatefromstring') function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) { // Respect current error level if( $errno & error_reporting() ) { - JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg); + JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg); } } @@ -234,47 +270,48 @@ if( INSTALL_PHP_ERR_HANDLER ) { } // -//Check if there were any warnings, perhaps some wrong includes by the -//user +// Check if there were any warnings, perhaps some wrong includes by the user. In this +// case we raise it immediately since otherwise the image will not show and makes +// debugging difficult. This is controlled by the user setting CATCH_PHPERRMSG // -if( isset($GLOBALS['php_errormsg']) && CATCH_PHPERRMSG && - !preg_match('/|Deprecated|/i', $GLOBALS['php_errormsg']) ) { +if( isset($GLOBALS['php_errormsg']) && CATCH_PHPERRMSG && !preg_match('/|Deprecated|/i', $GLOBALS['php_errormsg']) ) { JpGraphError::RaiseL(25004,$GLOBALS['php_errormsg']); } - // Useful mathematical function function sign($a) {return $a >= 0 ? 1 : -1;} +// // Utility function to generate an image name based on the filename we // are running from and assuming we use auto detection of graphic format // (top level), i.e it is safe to call this function // from a script that uses JpGraph +// function GenImgName() { // Determine what format we should use when we save the images $supported = imagetypes(); - if( $supported & IMG_PNG ) $img_format="png"; + if( $supported & IMG_PNG ) $img_format="png"; elseif( $supported & IMG_GIF ) $img_format="gif"; elseif( $supported & IMG_JPG ) $img_format="jpeg"; elseif( $supported & IMG_WBMP ) $img_format="wbmp"; elseif( $supported & IMG_XPM ) $img_format="xpm"; - if( !isset($_SERVER['PHP_SELF']) ) - JpGraphError::RaiseL(25005); -//(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files."); + if( !isset($_SERVER['PHP_SELF']) ) { + JpGraphError::RaiseL(25005); + //(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files."); + } $fname = basename($_SERVER['PHP_SELF']); if( !empty($_SERVER['QUERY_STRING']) ) { - $q = @$_SERVER['QUERY_STRING']; - $fname .= '_'.preg_replace("/\W/", "_", $q).'.'.$img_format; + $q = @$_SERVER['QUERY_STRING']; + $fname .= '_'.preg_replace("/\W/", "_", $q).'.'.$img_format; } else { - $fname = substr($fname,0,strlen($fname)-4).'.'.$img_format; + $fname = substr($fname,0,strlen($fname)-4).'.'.$img_format; } return $fname; } - //=================================================== // CLASS JpgTimer // Description: General timing utility class to handle @@ -282,129 +319,119 @@ function GenImgName() { // timers can be started. //=================================================== class JpgTimer { - private $start, $idx; -//--------------- -// CONSTRUCTOR - function JpgTimer() { - $this->idx=0; - } + private $start, $idx; -//--------------- -// PUBLIC METHODS + function __construct() { + $this->idx=0; + } // Push a new timer start on stack function Push() { - list($ms,$s)=explode(" ",microtime()); - $this->start[$this->idx++]=floor($ms*1000) + 1000*$s; + list($ms,$s)=explode(" ",microtime()); + $this->start[$this->idx++]=floor($ms*1000) + 1000*$s; } // Pop the latest timer start and return the diff with the // current time function Pop() { - assert($this->idx>0); - list($ms,$s)=explode(" ",microtime()); - $etime=floor($ms*1000) + (1000*$s); - $this->idx--; - return $etime-$this->start[$this->idx]; + assert($this->idx>0); + list($ms,$s)=explode(" ",microtime()); + $etime=floor($ms*1000) + (1000*$s); + $this->idx--; + return $etime-$this->start[$this->idx]; } } // Class -$gJpgBrandTiming = BRAND_TIMING; //=================================================== // CLASS DateLocale // Description: Hold localized text used in dates //=================================================== class DateLocale { - + public $iLocale = 'C'; // environmental locale be used by default private $iDayAbb = null, $iShortDay = null, $iShortMonth = null, $iMonthName = null; -//--------------- -// CONSTRUCTOR - function DateLocale() { - settype($this->iDayAbb, 'array'); - settype($this->iShortDay, 'array'); - settype($this->iShortMonth, 'array'); - settype($this->iMonthName, 'array'); - - - $this->Set('C'); + function __construct() { + settype($this->iDayAbb, 'array'); + settype($this->iShortDay, 'array'); + settype($this->iShortMonth, 'array'); + settype($this->iMonthName, 'array'); + $this->Set('C'); } -//--------------- -// PUBLIC METHODS function Set($aLocale) { - if ( in_array($aLocale, array_keys($this->iDayAbb)) ){ - $this->iLocale = $aLocale; - return TRUE; // already cached nothing else to do! - } + if ( in_array($aLocale, array_keys($this->iDayAbb)) ){ + $this->iLocale = $aLocale; + return TRUE; // already cached nothing else to do! + } - $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME + $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME - if (is_array($aLocale)) { - foreach ($aLocale as $loc) { - $res = @setlocale(LC_TIME, $loc); - if ( $res ) { - $aLocale = $loc; - break; - } - } - } - else { - $res = @setlocale(LC_TIME, $aLocale); - } + if (is_array($aLocale)) { + foreach ($aLocale as $loc) { + $res = @setlocale(LC_TIME, $loc); + if ( $res ) { + $aLocale = $loc; + break; + } + } + } + else { + $res = @setlocale(LC_TIME, $aLocale); + } - if ( ! $res ){ - JpGraphError::RaiseL(25007,$aLocale); -//("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region."); - return FALSE; - } - - $this->iLocale = $aLocale; - for ( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ){ - $day = strftime('%a', strtotime("$ofs day")); - $day[0] = strtoupper($day[0]); - $this->iDayAbb[$aLocale][]= $day[0]; - $this->iShortDay[$aLocale][]= $day; - } + if ( ! $res ) { + JpGraphError::RaiseL(25007,$aLocale); + //("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region."); + return FALSE; + } - for($i=1; $i<=12; ++$i) { - list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01"))); - $this->iShortMonth[$aLocale][] = ucfirst($short); - $this->iMonthName [$aLocale][] = ucfirst($full); - } - - setlocale(LC_TIME, $pLocale); + $this->iLocale = $aLocale; + for( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ) { + $day = strftime('%a', strtotime("$ofs day")); + $day[0] = strtoupper($day[0]); + $this->iDayAbb[$aLocale][]= $day[0]; + $this->iShortDay[$aLocale][]= $day; + } - return TRUE; + for($i=1; $i<=12; ++$i) { + list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01"))); + $this->iShortMonth[$aLocale][] = ucfirst($short); + $this->iMonthName [$aLocale][] = ucfirst($full); + } + + setlocale(LC_TIME, $pLocale); + + return TRUE; } function GetDayAbb() { - return $this->iDayAbb[$this->iLocale]; + return $this->iDayAbb[$this->iLocale]; } - + function GetShortDay() { - return $this->iShortDay[$this->iLocale]; + return $this->iShortDay[$this->iLocale]; } function GetShortMonth() { - return $this->iShortMonth[$this->iLocale]; + return $this->iShortMonth[$this->iLocale]; } - + function GetShortMonthName($aNbr) { - return $this->iShortMonth[$this->iLocale][$aNbr]; + return $this->iShortMonth[$this->iLocale][$aNbr]; } function GetLongMonthName($aNbr) { - return $this->iMonthName[$this->iLocale][$aNbr]; + return $this->iMonthName[$this->iLocale][$aNbr]; } function GetMonth() { - return $this->iMonthName[$this->iLocale]; + return $this->iMonthName[$this->iLocale]; } } +// Global object handlers $gDateLocale = new DateLocale(); $gJpgDateLocale = new DateLocale(); @@ -415,35 +442,44 @@ $gJpgDateLocale = new DateLocale(); class Footer { public $iLeftMargin = 3, $iRightMargin = 3, $iBottomMargin = 3 ; public $left,$center,$right; + private $iTimer=null, $itimerpoststring=''; - function Footer() { - $this->left = new Text(); - $this->left->ParagraphAlign('left'); - $this->center = new Text(); - $this->center->ParagraphAlign('center'); - $this->right = new Text(); - $this->right->ParagraphAlign('right'); + function __construct() { + $this->left = new Text(); + $this->left->ParagraphAlign('left'); + $this->center = new Text(); + $this->center->ParagraphAlign('center'); + $this->right = new Text(); + $this->right->ParagraphAlign('right'); + } + + function SetTimer($aTimer,$aTimerPostString='') { + $this->iTimer = $aTimer; + $this->itimerpoststring = $aTimerPostString; } function SetMargin($aLeft=3,$aRight=3,$aBottom=3) { - $this->iLeftMargin = $aLeft; - $this->iRightMargin = $aRight; - $this->iBottomMargin = $aBottom; + $this->iLeftMargin = $aLeft; + $this->iRightMargin = $aRight; + $this->iBottomMargin = $aBottom; } function Stroke($aImg) { - $y = $aImg->height - $this->iBottomMargin; - $x = $this->iLeftMargin; - $this->left->Align('left','bottom'); - $this->left->Stroke($aImg,$x,$y); + $y = $aImg->height - $this->iBottomMargin; + $x = $this->iLeftMargin; + $this->left->Align('left','bottom'); + $this->left->Stroke($aImg,$x,$y); - $x = ($aImg->width - $this->iLeftMargin - $this->iRightMargin)/2; - $this->center->Align('center','bottom'); - $this->center->Stroke($aImg,$x,$y); + $x = ($aImg->width - $this->iLeftMargin - $this->iRightMargin)/2; + $this->center->Align('center','bottom'); + $this->center->Stroke($aImg,$x,$y); - $x = $aImg->width - $this->iRightMargin; - $this->right->Align('right','bottom'); - $this->right->Stroke($aImg,$x,$y); + $x = $aImg->width - $this->iRightMargin; + $this->right->Align('right','bottom'); + if( $this->iTimer != null ) { + $this->right->Set( $this->right->t . sprintf('%.3f',$this->iTimer->Pop()/1000.0) . $this->itimerpoststring ); + } + $this->right->Stroke($aImg,$x,$y); } } @@ -453,37 +489,38 @@ class Footer { // Description: Main class to handle graphs //=================================================== class Graph { - public $cache=null; // Cache object (singleton) - public $img=null; // Img object (singleton) - public $plots=array(); // Array of all plot object in the graph (for Y 1 axis) - public $y2plots=array();// Array of all plot object in the graph (for Y 2 axis) + public $cache=null; // Cache object (singleton) + public $img=null; // Img object (singleton) + public $plots=array(); // Array of all plot object in the graph (for Y 1 axis) + public $y2plots=array(); // Array of all plot object in the graph (for Y 2 axis) public $ynplots=array(); - public $xscale=null; // X Scale object (could be instance of LinearScale or LogScale + public $xscale=null; // X Scale object (could be instance of LinearScale or LogScale public $yscale=null,$y2scale=null, $ynscale=array(); - public $iIcons = array(); // Array of Icons to add to - public $cache_name; // File name to be used for the current graph in the cache directory - public $xgrid=null; // X Grid object (linear or logarithmic) + public $iIcons = array(); // Array of Icons to add to + public $cache_name; // File name to be used for the current graph in the cache directory + public $xgrid=null; // X Grid object (linear or logarithmic) public $ygrid=null,$y2grid=null; //dito for Y - public $doframe=true,$frame_color=array(0,0,0), $frame_weight=1; // Frame around graph - public $boxed=false, $box_color=array(0,0,0), $box_weight=1; // Box around plot area - public $doshadow=false,$shadow_width=4,$shadow_color=array(102,102,102); // Shadow for graph - public $xaxis=null; // X-axis (instane of Axis class) - public $yaxis=null, $y2axis=null, $ynaxis=array(); // Y axis (instance of Axis class) - public $margin_color=array(200,200,200); // Margin color of graph - public $plotarea_color=array(255,255,255); // Plot area color - public $title,$subtitle,$subsubtitle; // Title and subtitle(s) text object - public $axtype="linlin"; // Type of axis - public $xtick_factor,$ytick_factor; // Factor to determine the maximum number of ticks depending on the plot width - public $texts=null, $y2texts=null; // Text object to ge shown in the graph + public $doframe=true,$frame_color='black', $frame_weight=1; // Frame around graph + public $boxed=false, $box_color='black', $box_weight=1; // Box around plot area + public $doshadow=false,$shadow_width=4,$shadow_color='gray@0.5'; // Shadow for graph + public $xaxis=null; // X-axis (instane of Axis class) + public $yaxis=null, $y2axis=null, $ynaxis=array(); // Y axis (instance of Axis class) + public $margin_color=array(230,230,230); // Margin color of graph + public $plotarea_color=array(255,255,255); // Plot area color + public $title,$subtitle,$subsubtitle; // Title and subtitle(s) text object + public $axtype="linlin"; // Type of axis + public $xtick_factor,$ytick_factor; // Factor to determine the maximum number of ticks depending on the plot width + public $texts=null, $y2texts=null; // Text object to ge shown in the graph public $lines=null, $y2lines=null; public $bands=null, $y2bands=null; - public $text_scale_off=0, $text_scale_abscenteroff=-1; // Text scale in fractions and for centering bars - public $background_image="",$background_image_type=-1,$background_image_format="png"; + public $text_scale_off=0, $text_scale_abscenteroff=-1; // Text scale in fractions and for centering bars + public $background_image='',$background_image_type=-1,$background_image_format="png"; public $background_image_bright=0,$background_image_contr=0,$background_image_sat=0; + public $background_image_xpos=0,$background_image_ypos=0; public $image_bright=0, $image_contr=0, $image_sat=0; public $inline; - public $showcsim=0,$csimcolor="red"; //debug stuff, draw the csim boundaris on the image if <>0 - public $grid_depth=DEPTH_BACK; // Draw grid under all plots as default + public $showcsim=0,$csimcolor="red";//debug stuff, draw the csim boundaris on the image if <>0 + public $grid_depth=DEPTH_BACK; // Draw grid under all plots as default public $iAxisStyle = AXSTYLE_SIMPLE; public $iCSIMdisplay=false,$iHasStroked = false; public $footer; @@ -495,11 +532,11 @@ class Graph { public $bkg_gradfrom='navy', $bkg_gradto='silver'; public $titlebackground = false; public $titlebackground_color = 'lightblue', - $titlebackground_style = 1, - $titlebackground_framecolor = 'blue', - $titlebackground_framestyle = 2, - $titlebackground_frameweight = 1, - $titlebackground_bevelheight = 3 ; + $titlebackground_style = 1, + $titlebackground_framecolor = 'blue', + $titlebackground_framestyle = 2, + $titlebackground_frameweight = 1, + $titlebackground_bevelheight = 3 ; public $titlebkg_fillstyle=TITLEBKG_FILLSTYLE_SOLID; public $titlebkg_scolor1='black',$titlebkg_scolor2='white'; public $framebevel = false, $framebeveldepth = 2 ; @@ -510,2281 +547,2411 @@ class Graph { public $background_cflag_type = BGIMG_FILLPLOT; public $background_cflag_mix = 100; public $iImgTrans=false, - $iImgTransHorizon = 100,$iImgTransSkewDist=150, - $iImgTransDirection = 1, $iImgTransMinSize = true, - $iImgTransFillColor='white',$iImgTransHighQ=false, - $iImgTransBorder=false,$iImgTransHorizonPos=0.5; + $iImgTransHorizon = 100,$iImgTransSkewDist=150, + $iImgTransDirection = 1, $iImgTransMinSize = true, + $iImgTransFillColor='white',$iImgTransHighQ=false, + $iImgTransBorder=false,$iImgTransHorizonPos=0.5; public $legend; protected $iYAxisDeltaPos=50; protected $iIconDepth=DEPTH_BACK; protected $iAxisLblBgType = 0, - $iXAxisLblBgFillColor = 'lightgray', $iXAxisLblBgColor = 'black', - $iYAxisLblBgFillColor = 'lightgray', $iYAxisLblBgColor = 'black'; + $iXAxisLblBgFillColor = 'lightgray', $iXAxisLblBgColor = 'black', + $iYAxisLblBgFillColor = 'lightgray', $iYAxisLblBgColor = 'black'; protected $iTables=NULL; -//--------------- -// CONSTRUCTOR + // aWIdth Width in pixels of image + // aHeight Height in pixels of image + // aCachedName Name for image file in cache directory + // aTimeOut Timeout in minutes for image in cache + // aInline If true the image is streamed back in the call to Stroke() + // If false the image is just created in the cache + function __construct($aWidth=300,$aHeight=200,$aCachedName='',$aTimeOut=0,$aInline=true) { - // aWIdth Width in pixels of image - // aHeight Height in pixels of image - // aCachedName Name for image file in cache directory - // aTimeOut Timeout in minutes for image in cache - // aInline If true the image is streamed back in the call to Stroke() - // If false the image is just created in the cache - function Graph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) { - GLOBAL $gJpgBrandTiming; - // If timing is used create a new timing object - if( $gJpgBrandTiming ) { - global $tim; - $tim = new JpgTimer(); - $tim->Push(); - } + if( !is_numeric($aWidth) || !is_numeric($aHeight) ) { + JpGraphError::RaiseL(25008);//('Image width/height argument in Graph::Graph() must be numeric'); + } - if( !is_numeric($aWidth) || !is_numeric($aHeight) ) { - JpGraphError::RaiseL(25008);//('Image width/height argument in Graph::Graph() must be numeric'); - } + // Automatically generate the image file name based on the name of the script that + // generates the graph + if( $aCachedName == 'auto' ) { + $aCachedName=GenImgName(); + } - // Automatically generate the image file name based on the name of the script that - // generates the graph - if( $aCachedName=="auto" ) - $aCachedName=GenImgName(); - - // Should the image be streamed back to the browser or only to the cache? - $this->inline=$aInline; - - $this->img = new RotImage($aWidth,$aHeight); + // Should the image be streamed back to the browser or only to the cache? + $this->inline=$aInline; - $this->cache = new ImgStreamCache($this->img); - $this->cache->SetTimeOut($aTimeOut); + $this->img = new RotImage($aWidth,$aHeight); - $this->title = new Text(); - $this->title->ParagraphAlign('center'); - $this->title->SetFont(FF_FONT2,FS_BOLD); - $this->title->SetMargin(3); - $this->title->SetAlign('center'); + $this->cache = new ImgStreamCache(); + $this->cache->SetTimeOut($aTimeOut); - $this->subtitle = new Text(); - $this->subtitle->ParagraphAlign('center'); - $this->subtitle->SetMargin(2); - $this->subtitle->SetAlign('center'); + $this->title = new Text(); + $this->title->ParagraphAlign('center'); + $this->title->SetFont(FF_FONT2,FS_BOLD); + $this->title->SetMargin(5); + $this->title->SetAlign('center'); - $this->subsubtitle = new Text(); - $this->subsubtitle->ParagraphAlign('center'); - $this->subsubtitle->SetMargin(2); - $this->subsubtitle->SetAlign('center'); + $this->subtitle = new Text(); + $this->subtitle->ParagraphAlign('center'); + $this->subtitle->SetMargin(3); + $this->subtitle->SetAlign('center'); - $this->legend = new Legend(); - $this->footer = new Footer(); + $this->subsubtitle = new Text(); + $this->subsubtitle->ParagraphAlign('center'); + $this->subsubtitle->SetMargin(3); + $this->subsubtitle->SetAlign('center'); - // Window doesn't like '?' in the file name so replace it with an '_' - $aCachedName = str_replace("?","_",$aCachedName); + $this->legend = new Legend(); + $this->footer = new Footer(); - // If the cached version exist just read it directly from the - // cache, stream it back to browser and exit - if( $aCachedName!="" && READ_CACHE && $aInline ) - if( $this->cache->GetAndStream($aCachedName) ) { - exit(); - } - - $this->cache_name = $aCachedName; - $this->SetTickDensity(); // Normal density + // Window doesn't like '?' in the file name so replace it with an '_' + $aCachedName = str_replace("?","_",$aCachedName); - $this->tabtitle = new GraphTabTitle(); + // If the cached version exist just read it directly from the + // cache, stream it back to browser and exit + if( $aCachedName!='' && READ_CACHE && $aInline ) { + if( $this->cache->GetAndStream($this->img,$aCachedName) ) { + exit(); + } + } + + $this->cache_name = $aCachedName; + $this->SetTickDensity(); // Normal density + + $this->tabtitle = new GraphTabTitle(); } -//--------------- -// PUBLIC METHODS - + // Enable final image perspective transformation function Set3DPerspective($aDir=1,$aHorizon=100,$aSkewDist=120,$aQuality=false,$aFillColor='#FFFFFF',$aBorder=false,$aMinSize=true,$aHorizonPos=0.5) { - $this->iImgTrans = true; - $this->iImgTransHorizon = $aHorizon; - $this->iImgTransSkewDist= $aSkewDist; - $this->iImgTransDirection = $aDir; - $this->iImgTransMinSize = $aMinSize; - $this->iImgTransFillColor=$aFillColor; - $this->iImgTransHighQ=$aQuality; - $this->iImgTransBorder=$aBorder; - $this->iImgTransHorizonPos=$aHorizonPos; + $this->iImgTrans = true; + $this->iImgTransHorizon = $aHorizon; + $this->iImgTransSkewDist= $aSkewDist; + $this->iImgTransDirection = $aDir; + $this->iImgTransMinSize = $aMinSize; + $this->iImgTransFillColor=$aFillColor; + $this->iImgTransHighQ=$aQuality; + $this->iImgTransBorder=$aBorder; + $this->iImgTransHorizonPos=$aHorizonPos; + } + + function SetUserFont($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->img->ttf->SetUserFont($aNormal,$aBold,$aItalic,$aBoldIt); + } + + function SetUserFont1($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->img->ttf->SetUserFont1($aNormal,$aBold,$aItalic,$aBoldIt); + } + + function SetUserFont2($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->img->ttf->SetUserFont2($aNormal,$aBold,$aItalic,$aBoldIt); + } + + function SetUserFont3($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->img->ttf->SetUserFont3($aNormal,$aBold,$aItalic,$aBoldIt); } // Set Image format and optional quality function SetImgFormat($aFormat,$aQuality=75) { - $this->img->SetImgFormat($aFormat,$aQuality); + $this->img->SetImgFormat($aFormat,$aQuality); } // Should the grid be in front or back of the plot? function SetGridDepth($aDepth) { - $this->grid_depth=$aDepth; + $this->grid_depth=$aDepth; } function SetIconDepth($aDepth) { - $this->iIconDepth=$aDepth; + $this->iIconDepth=$aDepth; } - + // Specify graph angle 0-360 degrees. function SetAngle($aAngle) { - $this->img->SetAngle($aAngle); + $this->img->SetAngle($aAngle); } function SetAlphaBlending($aFlg=true) { - $this->img->SetAlphaBlending($aFlg); + $this->img->SetAlphaBlending($aFlg); } // Shortcut to image margin function SetMargin($lm,$rm,$tm,$bm) { - $this->img->SetMargin($lm,$rm,$tm,$bm); + $this->img->SetMargin($lm,$rm,$tm,$bm); } function SetY2OrderBack($aBack=true) { - $this->y2orderback = $aBack; + $this->y2orderback = $aBack; } - // Rotate the graph 90 degrees and set the margin + // Rotate the graph 90 degrees and set the margin // when we have done a 90 degree rotation function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) { - $lm = $lm ==0 ? floor(0.2 * $this->img->width) : $lm ; - $rm = $rm ==0 ? floor(0.1 * $this->img->width) : $rm ; - $tm = $tm ==0 ? floor(0.2 * $this->img->height) : $tm ; - $bm = $bm ==0 ? floor(0.1 * $this->img->height) : $bm ; + $lm = $lm ==0 ? floor(0.2 * $this->img->width) : $lm ; + $rm = $rm ==0 ? floor(0.1 * $this->img->width) : $rm ; + $tm = $tm ==0 ? floor(0.2 * $this->img->height) : $tm ; + $bm = $bm ==0 ? floor(0.1 * $this->img->height) : $bm ; - $adj = ($this->img->height - $this->img->width)/2; - $this->img->SetMargin($tm-$adj,$bm-$adj,$rm+$adj,$lm+$adj); - $this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2)); - $this->SetAngle(90); - if( empty($this->yaxis) || empty($this->xaxis) ) { - JpgraphError::RaiseL(25009);//('You must specify what scale to use with a call to Graph::SetScale()'); - } - $this->xaxis->SetLabelAlign('right','center'); - $this->yaxis->SetLabelAlign('center','bottom'); + $adj = ($this->img->height - $this->img->width)/2; + $this->img->SetMargin($tm-$adj,$bm-$adj,$rm+$adj,$lm+$adj); + $this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2)); + $this->SetAngle(90); + if( empty($this->yaxis) || empty($this->xaxis) ) { + JpgraphError::RaiseL(25009);//('You must specify what scale to use with a call to Graph::SetScale()'); + } + $this->xaxis->SetLabelAlign('right','center'); + $this->yaxis->SetLabelAlign('center','bottom'); } - + function SetClipping($aFlg=true) { - $this->iDoClipping = $aFlg ; + $this->iDoClipping = $aFlg ; } // Add a plot object to the graph function Add($aPlot) { - if( $aPlot == null ) - JpGraphError::RaiseL(25010);//("Graph::Add() You tried to add a null plot to the graph."); - if( is_array($aPlot) && count($aPlot) > 0 ) - $cl = $aPlot[0]; - else - $cl = $aPlot; + if( $aPlot == null ) { + JpGraphError::RaiseL(25010);//("Graph::Add() You tried to add a null plot to the graph."); + } + if( is_array($aPlot) && count($aPlot) > 0 ) { + $cl = $aPlot[0]; + } + else { + $cl = $aPlot; + } - if( $cl instanceof Text ) - $this->AddText($aPlot); - elseif( $cl instanceof PlotLine ) - $this->AddLine($aPlot); - elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) - $this->AddBand($aPlot); - elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) - $this->AddIcon($aPlot); - elseif( class_exists('GTextTable',false) && ($cl instanceof GTextTable) ) - $this->AddTable($aPlot); - else - $this->plots[] = $aPlot; + if( $cl instanceof Text ) $this->AddText($aPlot); + elseif( class_exists('PlotLine') && ($cl instanceof PlotLine) ) $this->AddLine($aPlot); + elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) $this->AddBand($aPlot); + elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) $this->AddIcon($aPlot); + elseif( class_exists('GTextTable',false) && ($cl instanceof GTextTable) ) $this->AddTable($aPlot); + else { + if( is_array($aPlot) ) { + $this->plots = array_merge($this->plots,$aPlot); + } + else { + $this->plots[] = $aPlot; + } + } } function AddTable($aTable) { - if( is_array($aTable) ) { - for($i=0; $i < count($aTable); ++$i ) - $this->iTables[]=$aTable[$i]; - } - else { - $this->iTables[] = $aTable ; - } + if( is_array($aTable) ) { + for($i=0; $i < count($aTable); ++$i ) { + $this->iTables[]=$aTable[$i]; + } + } + else { + $this->iTables[] = $aTable ; + } } function AddIcon($aIcon) { - if( is_array($aIcon) ) { - for($i=0; $i < count($aIcon); ++$i ) - $this->iIcons[]=$aIcon[$i]; - } - else { - $this->iIcons[] = $aIcon ; - } + if( is_array($aIcon) ) { + for($i=0; $i < count($aIcon); ++$i ) { + $this->iIcons[]=$aIcon[$i]; + } + } + else { + $this->iIcons[] = $aIcon ; + } } // Add plot to second Y-scale function AddY2($aPlot) { - if( $aPlot == null ) - JpGraphError::RaiseL(25011);//("Graph::AddY2() You tried to add a null plot to the graph."); + if( $aPlot == null ) { + JpGraphError::RaiseL(25011);//("Graph::AddY2() You tried to add a null plot to the graph."); + } - if( is_array($aPlot) && count($aPlot) > 0 ) - $cl = $aPlot[0]; - else - $cl = $aPlot; + if( is_array($aPlot) && count($aPlot) > 0 ) { + $cl = $aPlot[0]; + } + else { + $cl = $aPlot; + } - if( $cl instanceof Text ) - $this->AddText($aPlot,true); - elseif( $cl instanceof PlotLine ) - $this->AddLine($aPlot,true); - elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) - $this->AddBand($aPlot,true); - else - $this->y2plots[] = $aPlot; + if( $cl instanceof Text ) { + $this->AddText($aPlot,true); + } + elseif( class_exists('PlotLine',false) && ($cl instanceof PlotLine) ) { + $this->AddLine($aPlot,true); + } + elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) { + $this->AddBand($aPlot,true); + } + else { + $this->y2plots[] = $aPlot; + } } - + // Add plot to the extra Y-axises function AddY($aN,$aPlot) { - if( $aPlot == null ) - JpGraphError::RaiseL(25012);//("Graph::AddYN() You tried to add a null plot to the graph."); + if( $aPlot == null ) { + JpGraphError::RaiseL(25012);//("Graph::AddYN() You tried to add a null plot to the graph."); + } - if( is_array($aPlot) && count($aPlot) > 0 ) - $cl = $aPlot[0]; - else - $cl = $aPlot; + if( is_array($aPlot) && count($aPlot) > 0 ) { + $cl = $aPlot[0]; + } + else { + $cl = $aPlot; + } - if( ($cl instanceof Text) || ($cl instanceof PlotLine) || - (class_exists('PlotBand',false) && ($cl instanceof PlotBand)) ) - JpGraph::RaiseL(25013);//('You can only add standard plots to multiple Y-axis'); - else - $this->ynplots[$aN][] = $aPlot; + if( ($cl instanceof Text) || + (class_exists('PlotLine',false) && ($cl instanceof PlotLine)) || + (class_exists('PlotBand',false) && ($cl instanceof PlotBand)) ) { + JpGraph::RaiseL(25013);//('You can only add standard plots to multiple Y-axis'); + } + else { + $this->ynplots[$aN][] = $aPlot; + } } // Add text object to the graph function AddText($aTxt,$aToY2=false) { - if( $aTxt == null ) - JpGraphError::RaiseL(25014);//("Graph::AddText() You tried to add a null text to the graph."); - if( $aToY2 ) { - if( is_array($aTxt) ) { - for($i=0; $i < count($aTxt); ++$i ) - $this->y2texts[]=$aTxt[$i]; - } - else - $this->y2texts[] = $aTxt; - } - else { - if( is_array($aTxt) ) { - for($i=0; $i < count($aTxt); ++$i ) - $this->texts[]=$aTxt[$i]; - } - else - $this->texts[] = $aTxt; - } + if( $aTxt == null ) { + JpGraphError::RaiseL(25014);//("Graph::AddText() You tried to add a null text to the graph."); + } + if( $aToY2 ) { + if( is_array($aTxt) ) { + for($i=0; $i < count($aTxt); ++$i ) { + $this->y2texts[]=$aTxt[$i]; + } + } + else { + $this->y2texts[] = $aTxt; + } + } + else { + if( is_array($aTxt) ) { + for($i=0; $i < count($aTxt); ++$i ) { + $this->texts[]=$aTxt[$i]; + } + } + else { + $this->texts[] = $aTxt; + } + } } - + // Add a line object (class PlotLine) to the graph function AddLine($aLine,$aToY2=false) { - if( $aLine == null ) - JpGraphError::RaiseL(25015);//("Graph::AddLine() You tried to add a null line to the graph."); + if( $aLine == null ) { + JpGraphError::RaiseL(25015);//("Graph::AddLine() You tried to add a null line to the graph."); + } - if( $aToY2 ) { - if( is_array($aLine) ) { - for($i=0; $i < count($aLine); ++$i ) - $this->y2lines[]=$aLine[$i]; - } - else - $this->y2lines[] = $aLine; - } - else { - if( is_array($aLine) ) { - for($i=0; $ilines[]=$aLine[$i]; - } - else - $this->lines[] = $aLine; - } + if( $aToY2 ) { + if( is_array($aLine) ) { + for($i=0; $i < count($aLine); ++$i ) { + $this->y2lines[]=$aLine[$i]; + } + } + else { + $this->y2lines[] = $aLine; + } + } + else { + if( is_array($aLine) ) { + for($i=0; $ilines[]=$aLine[$i]; + } + } + else { + $this->lines[] = $aLine; + } + } } // Add vertical or horizontal band function AddBand($aBand,$aToY2=false) { - if( $aBand == null ) - JpGraphError::RaiseL(25016);//(" Graph::AddBand() You tried to add a null band to the graph."); + if( $aBand == null ) { + JpGraphError::RaiseL(25016);//(" Graph::AddBand() You tried to add a null band to the graph."); + } - if( $aToY2 ) { - if( is_array($aBand) ) { - for($i=0; $i < count($aBand); ++$i ) - $this->y2bands[] = $aBand[$i]; - } - else - $this->y2bands[] = $aBand; - } - else { - if( is_array($aBand) ) { - for($i=0; $i < count($aBand); ++$i ) - $this->bands[] = $aBand[$i]; - } - else - $this->bands[] = $aBand; - } + if( $aToY2 ) { + if( is_array($aBand) ) { + for($i=0; $i < count($aBand); ++$i ) { + $this->y2bands[] = $aBand[$i]; + } + } + else { + $this->y2bands[] = $aBand; + } + } + else { + if( is_array($aBand) ) { + for($i=0; $i < count($aBand); ++$i ) { + $this->bands[] = $aBand[$i]; + } + } + else { + $this->bands[] = $aBand; + } + } } function SetBackgroundGradient($aFrom='navy',$aTo='silver',$aGradType=2,$aStyle=BGRAD_FRAME) { - $this->bkg_gradtype=$aGradType; - $this->bkg_gradstyle=$aStyle; - $this->bkg_gradfrom = $aFrom; - $this->bkg_gradto = $aTo; - } - + $this->bkg_gradtype=$aGradType; + $this->bkg_gradstyle=$aStyle; + $this->bkg_gradfrom = $aFrom; + $this->bkg_gradto = $aTo; + } + // Set a country flag in the background function SetBackgroundCFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) { - $this->background_cflag = $aName; - $this->background_cflag_type = $aBgType; - $this->background_cflag_mix = $aMix; + $this->background_cflag = $aName; + $this->background_cflag_type = $aBgType; + $this->background_cflag_mix = $aMix; } // Alias for the above method function SetBackgroundCountryFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) { - $this->background_cflag = $aName; - $this->background_cflag_type = $aBgType; - $this->background_cflag_mix = $aMix; + $this->background_cflag = $aName; + $this->background_cflag_type = $aBgType; + $this->background_cflag_mix = $aMix; } // Specify a background image - function SetBackgroundImage($aFileName,$aBgType=BGIMG_FILLPLOT,$aImgFormat="auto") { + function SetBackgroundImage($aFileName,$aBgType=BGIMG_FILLPLOT,$aImgFormat='auto') { - if( !USE_TRUECOLOR ) { - JpGraphError::RaiseL(25017);//("You are using GD 2.x and are trying to use a background images on a non truecolor image. To use background images with GD 2.x you must enable truecolor by setting the USE_TRUECOLOR constant to TRUE. Due to a bug in GD 2.0.1 using any truetype fonts with truecolor images will result in very poor quality fonts."); - } + // Get extension to determine image type + if( $aImgFormat == 'auto' ) { + $e = explode('.',$aFileName); + if( !$e ) { + JpGraphError::RaiseL(25018,$aFileName);//('Incorrect file name for Graph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type'); + } - // Get extension to determine image type - if( $aImgFormat == "auto" ) { - $e = explode('.',$aFileName); - if( !$e ) { - JpGraphError::RaiseL(25018,$aFileName);//('Incorrect file name for Graph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type'); - } + $valid_formats = array('png', 'jpg', 'gif'); + $aImgFormat = strtolower($e[count($e)-1]); + if ($aImgFormat == 'jpeg') { + $aImgFormat = 'jpg'; + } + elseif (!in_array($aImgFormat, $valid_formats) ) { + JpGraphError::RaiseL(25019,$aImgFormat);//('Unknown file extension ($aImgFormat) in Graph::SetBackgroundImage() for filename: '.$aFileName); + } + } - $valid_formats = array('png', 'jpg', 'gif'); - $aImgFormat = strtolower($e[count($e)-1]); - if ($aImgFormat == 'jpeg') { - $aImgFormat = 'jpg'; - } - elseif (!in_array($aImgFormat, $valid_formats) ) { - JpGraphError::RaiseL(25019,$aImgFormat);//('Unknown file extension ($aImgFormat) in Graph::SetBackgroundImage() for filename: '.$aFileName); - } - } - - $this->background_image = $aFileName; - $this->background_image_type=$aBgType; - $this->background_image_format=$aImgFormat; + $this->background_image = $aFileName; + $this->background_image_type=$aBgType; + $this->background_image_format=$aImgFormat; } function SetBackgroundImageMix($aMix) { - $this->background_image_mix = $aMix ; + $this->background_image_mix = $aMix ; } - + + // Adjust background image position + function SetBackgroundImagePos($aXpos,$aYpos) { + $this->background_image_xpos = $aXpos ; + $this->background_image_ypos = $aYpos ; + } + // Specify axis style (boxed or single) function SetAxisStyle($aStyle) { $this->iAxisStyle = $aStyle ; } - + // Set a frame around the plot area function SetBox($aDrawPlotFrame=true,$aPlotFrameColor=array(0,0,0),$aPlotFrameWeight=1) { - $this->boxed = $aDrawPlotFrame; - $this->box_weight = $aPlotFrameWeight; - $this->box_color = $aPlotFrameColor; + $this->boxed = $aDrawPlotFrame; + $this->box_weight = $aPlotFrameWeight; + $this->box_color = $aPlotFrameColor; } - + // Specify color for the plotarea (not the margins) function SetColor($aColor) { - $this->plotarea_color=$aColor; + $this->plotarea_color=$aColor; } - + // Specify color for the margins (all areas outside the plotarea) function SetMarginColor($aColor) { - $this->margin_color=$aColor; + $this->margin_color=$aColor; } - + // Set a frame around the entire image function SetFrame($aDrawImgFrame=true,$aImgFrameColor=array(0,0,0),$aImgFrameWeight=1) { - $this->doframe = $aDrawImgFrame; - $this->frame_color = $aImgFrameColor; - $this->frame_weight = $aImgFrameWeight; + $this->doframe = $aDrawImgFrame; + $this->frame_color = $aImgFrameColor; + $this->frame_weight = $aImgFrameWeight; } function SetFrameBevel($aDepth=3,$aBorder=false,$aBorderColor='black',$aColor1='white@0.4',$aColor2='darkgray@0.4',$aFlg=true) { - $this->framebevel = $aFlg ; - $this->framebeveldepth = $aDepth ; - $this->framebevelborder = $aBorder ; - $this->framebevelbordercolor = $aBorderColor ; - $this->framebevelcolor1 = $aColor1 ; - $this->framebevelcolor2 = $aColor2 ; + $this->framebevel = $aFlg ; + $this->framebeveldepth = $aDepth ; + $this->framebevelborder = $aBorder ; + $this->framebevelbordercolor = $aBorderColor ; + $this->framebevelcolor1 = $aColor1 ; + $this->framebevelcolor2 = $aColor2 ; - $this->doshadow = false ; + $this->doshadow = false ; } // Set the shadow around the whole image - function SetShadow($aShowShadow=true,$aShadowWidth=5,$aShadowColor=array(102,102,102)) { - $this->doshadow = $aShowShadow; - $this->shadow_color = $aShadowColor; - $this->shadow_width = $aShadowWidth; - $this->footer->iBottomMargin += $aShadowWidth; - $this->footer->iRightMargin += $aShadowWidth; + function SetShadow($aShowShadow=true,$aShadowWidth=4,$aShadowColor='gray@0.3') { + $this->doshadow = $aShowShadow; + $this->shadow_color = $aShadowColor; + $this->shadow_width = $aShadowWidth; + $this->footer->iBottomMargin += $aShadowWidth; + $this->footer->iRightMargin += $aShadowWidth; } // Specify x,y scale. Note that if you manually specify the scale // you must also specify the tick distance with a call to Ticks::Set() function SetScale($aAxisType,$aYMin=1,$aYMax=1,$aXMin=1,$aXMax=1) { - $this->axtype = $aAxisType; + $this->axtype = $aAxisType; - if( $aYMax < $aYMin || $aXMax < $aXMin ) - JpGraphError::RaiseL(25020);//('Graph::SetScale(): Specified Max value must be larger than the specified Min value.'); + if( $aYMax < $aYMin || $aXMax < $aXMin ) { + JpGraphError::RaiseL(25020);//('Graph::SetScale(): Specified Max value must be larger than the specified Min value.'); + } - $yt=substr($aAxisType,-3,3); - if( $yt=="lin" ) - $this->yscale = new LinearScale($aYMin,$aYMax); - elseif( $yt == "int" ) { - $this->yscale = new LinearScale($aYMin,$aYMax); - $this->yscale->SetIntScale(); - } - elseif( $yt=="log" ) - $this->yscale = new LogScale($aYMin,$aYMax); - else - JpGraphError::RaiseL(25021,$aAxisType);//("Unknown scale specification for Y-scale. ($aAxisType)"); - - $xt=substr($aAxisType,0,3); - if( $xt == "lin" || $xt == "tex" ) { - $this->xscale = new LinearScale($aXMin,$aXMax,"x"); - $this->xscale->textscale = ($xt == "tex"); - } - elseif( $xt == "int" ) { - $this->xscale = new LinearScale($aXMin,$aXMax,"x"); - $this->xscale->SetIntScale(); - } - elseif( $xt == "dat" ) { - $this->xscale = new DateScale($aXMin,$aXMax,"x"); - } - elseif( $xt == "log" ) - $this->xscale = new LogScale($aXMin,$aXMax,"x"); - else - JpGraphError::RaiseL(25022,$aAxisType);//(" Unknown scale specification for X-scale. ($aAxisType)"); + $yt=substr($aAxisType,-3,3); + if( $yt == 'lin' ) { + $this->yscale = new LinearScale($aYMin,$aYMax); + } + elseif( $yt == 'int' ) { + $this->yscale = new LinearScale($aYMin,$aYMax); + $this->yscale->SetIntScale(); + } + elseif( $yt == 'log' ) { + $this->yscale = new LogScale($aYMin,$aYMax); + } + else { + JpGraphError::RaiseL(25021,$aAxisType);//("Unknown scale specification for Y-scale. ($aAxisType)"); + } - $this->xaxis = new Axis($this->img,$this->xscale); - $this->yaxis = new Axis($this->img,$this->yscale); - $this->xgrid = new Grid($this->xaxis); - $this->ygrid = new Grid($this->yaxis); - $this->ygrid->Show(); + $xt=substr($aAxisType,0,3); + if( $xt == 'lin' || $xt == 'tex' ) { + $this->xscale = new LinearScale($aXMin,$aXMax,'x'); + $this->xscale->textscale = ($xt == 'tex'); + } + elseif( $xt == 'int' ) { + $this->xscale = new LinearScale($aXMin,$aXMax,'x'); + $this->xscale->SetIntScale(); + } + elseif( $xt == 'dat' ) { + $this->xscale = new DateScale($aXMin,$aXMax,'x'); + } + elseif( $xt == 'log' ) { + $this->xscale = new LogScale($aXMin,$aXMax,'x'); + } + else { + JpGraphError::RaiseL(25022,$aAxisType);//(" Unknown scale specification for X-scale. ($aAxisType)"); + } + + $this->xaxis = new Axis($this->img,$this->xscale); + $this->yaxis = new Axis($this->img,$this->yscale); + $this->xgrid = new Grid($this->xaxis); + $this->ygrid = new Grid($this->yaxis); + $this->ygrid->Show(); } - + // Specify secondary Y scale - function SetY2Scale($aAxisType="lin",$aY2Min=1,$aY2Max=1) { - if( $aAxisType=="lin" ) - $this->y2scale = new LinearScale($aY2Min,$aY2Max); - elseif( $aAxisType == "int" ) { - $this->y2scale = new LinearScale($aY2Min,$aY2Max); - $this->y2scale->SetIntScale(); - } - elseif( $aAxisType=="log" ) { - $this->y2scale = new LogScale($aY2Min,$aY2Max); - } - else JpGraphError::RaiseL(25023,$aAxisType);//("JpGraph: Unsupported Y2 axis type: $aAxisType\nMust be one of (lin,log,int)"); - - $this->y2axis = new Axis($this->img,$this->y2scale); - $this->y2axis->scale->ticks->SetDirection(SIDE_LEFT); - $this->y2axis->SetLabelSide(SIDE_RIGHT); - $this->y2axis->SetPos('max'); - $this->y2axis->SetTitleSide(SIDE_RIGHT); - - // Deafult position is the max x-value - $this->y2grid = new Grid($this->y2axis); + function SetY2Scale($aAxisType='lin',$aY2Min=1,$aY2Max=1) { + if( $aAxisType == 'lin' ) { + $this->y2scale = new LinearScale($aY2Min,$aY2Max); + } + elseif( $aAxisType == 'int' ) { + $this->y2scale = new LinearScale($aY2Min,$aY2Max); + $this->y2scale->SetIntScale(); + } + elseif( $aAxisType == 'log' ) { + $this->y2scale = new LogScale($aY2Min,$aY2Max); + } + else { + JpGraphError::RaiseL(25023,$aAxisType);//("JpGraph: Unsupported Y2 axis type: $aAxisType\nMust be one of (lin,log,int)"); + } + + $this->y2axis = new Axis($this->img,$this->y2scale); + $this->y2axis->scale->ticks->SetDirection(SIDE_LEFT); + $this->y2axis->SetLabelSide(SIDE_RIGHT); + $this->y2axis->SetPos('max'); + $this->y2axis->SetTitleSide(SIDE_RIGHT); + + // Deafult position is the max x-value + $this->y2grid = new Grid($this->y2axis); } // Set the delta position (in pixels) between the multiple Y-axis function SetYDeltaDist($aDist) { - $this->iYAxisDeltaPos = $aDist; + $this->iYAxisDeltaPos = $aDist; } // Specify secondary Y scale function SetYScale($aN,$aAxisType="lin",$aYMin=1,$aYMax=1) { - if( $aAxisType=="lin" ) - $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); - elseif( $aAxisType == "int" ) { - $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); - $this->ynscale[$aN]->SetIntScale(); - } - elseif( $aAxisType=="log" ) { - $this->ynscale[$aN] = new LogScale($aYMin,$aYMax); - } - else JpGraphError::RaiseL(25024,$aAxisType);//("JpGraph: Unsupported Y axis type: $aAxisType\nMust be one of (lin,log,int)"); - - $this->ynaxis[$aN] = new Axis($this->img,$this->ynscale[$aN]); - $this->ynaxis[$aN]->scale->ticks->SetDirection(SIDE_LEFT); - $this->ynaxis[$aN]->SetLabelSide(SIDE_RIGHT); + if( $aAxisType == 'lin' ) { + $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); + } + elseif( $aAxisType == 'int' ) { + $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); + $this->ynscale[$aN]->SetIntScale(); + } + elseif( $aAxisType == 'log' ) { + $this->ynscale[$aN] = new LogScale($aYMin,$aYMax); + } + else { + JpGraphError::RaiseL(25024,$aAxisType);//("JpGraph: Unsupported Y axis type: $aAxisType\nMust be one of (lin,log,int)"); + } + + $this->ynaxis[$aN] = new Axis($this->img,$this->ynscale[$aN]); + $this->ynaxis[$aN]->scale->ticks->SetDirection(SIDE_LEFT); + $this->ynaxis[$aN]->SetLabelSide(SIDE_RIGHT); } // Specify density of ticks when autoscaling 'normal', 'dense', 'sparse', 'verysparse' - // The dividing factor have been determined heuristically according to my aesthetic + // The dividing factor have been determined heuristically according to my aesthetic // sense (or lack off) y.m.m.v ! function SetTickDensity($aYDensity=TICKD_NORMAL,$aXDensity=TICKD_NORMAL) { - $this->xtick_factor=30; - $this->ytick_factor=25; - switch( $aYDensity ) { - case TICKD_DENSE: - $this->ytick_factor=12; - break; - case TICKD_NORMAL: - $this->ytick_factor=25; - break; - case TICKD_SPARSE: - $this->ytick_factor=40; - break; - case TICKD_VERYSPARSE: - $this->ytick_factor=100; - break; - default: - JpGraphError::RaiseL(25025,$densy);//("JpGraph: Unsupported Tick density: $densy"); - } - switch( $aXDensity ) { - case TICKD_DENSE: - $this->xtick_factor=15; - break; - case TICKD_NORMAL: - $this->xtick_factor=30; - break; - case TICKD_SPARSE: - $this->xtick_factor=45; - break; - case TICKD_VERYSPARSE: - $this->xtick_factor=60; - break; - default: - JpGraphError::RaiseL(25025,$densx);//("JpGraph: Unsupported Tick density: $densx"); - } + $this->xtick_factor=30; + $this->ytick_factor=25; + switch( $aYDensity ) { + case TICKD_DENSE: + $this->ytick_factor=12; + break; + case TICKD_NORMAL: + $this->ytick_factor=25; + break; + case TICKD_SPARSE: + $this->ytick_factor=40; + break; + case TICKD_VERYSPARSE: + $this->ytick_factor=100; + break; + default: + JpGraphError::RaiseL(25025,$densy);//("JpGraph: Unsupported Tick density: $densy"); + } + switch( $aXDensity ) { + case TICKD_DENSE: + $this->xtick_factor=15; + break; + case TICKD_NORMAL: + $this->xtick_factor=30; + break; + case TICKD_SPARSE: + $this->xtick_factor=45; + break; + case TICKD_VERYSPARSE: + $this->xtick_factor=60; + break; + default: + JpGraphError::RaiseL(25025,$densx);//("JpGraph: Unsupported Tick density: $densx"); + } } - - // Get a string of all image map areas + + // Get a string of all image map areas function GetCSIMareas() { - if( !$this->iHasStroked ) - $this->Stroke(_CSIM_SPECIALFILE); + if( !$this->iHasStroked ) { + $this->Stroke(_CSIM_SPECIALFILE); + } - $csim = $this->title->GetCSIMAreas(); - $csim .= $this->subtitle->GetCSIMAreas(); - $csim .= $this->subsubtitle->GetCSIMAreas(); - $csim .= $this->legend->GetCSIMAreas(); + $csim = $this->title->GetCSIMAreas(); + $csim .= $this->subtitle->GetCSIMAreas(); + $csim .= $this->subsubtitle->GetCSIMAreas(); + $csim .= $this->legend->GetCSIMAreas(); - if( $this->y2axis != NULL ) { - $csim .= $this->y2axis->title->GetCSIMAreas(); - } + if( $this->y2axis != NULL ) { + $csim .= $this->y2axis->title->GetCSIMAreas(); + } - if( $this->texts != null ) { - $n = count($this->texts); - for($i=0; $i < $n; ++$i ) { - $csim .= $this->texts[$i]->GetCSIMAreas(); - } - } + if( $this->texts != null ) { + $n = count($this->texts); + for($i=0; $i < $n; ++$i ) { + $csim .= $this->texts[$i]->GetCSIMAreas(); + } + } - if( $this->y2texts != null && $this->y2scale != null ) { - $n = count($this->y2texts); - for($i=0; $i < $n; ++$i ) { - $csim .= $this->y2texts[$i]->GetCSIMAreas(); - } - } + if( $this->y2texts != null && $this->y2scale != null ) { + $n = count($this->y2texts); + for($i=0; $i < $n; ++$i ) { + $csim .= $this->y2texts[$i]->GetCSIMAreas(); + } + } - if( $this->yaxis != null && $this->xaxis != null ) { - $csim .= $this->yaxis->title->GetCSIMAreas(); - $csim .= $this->xaxis->title->GetCSIMAreas(); - } + if( $this->yaxis != null && $this->xaxis != null ) { + $csim .= $this->yaxis->title->GetCSIMAreas(); + $csim .= $this->xaxis->title->GetCSIMAreas(); + } - $n = count($this->plots); - for( $i=0; $i < $n; ++$i ) - $csim .= $this->plots[$i]->GetCSIMareas(); + $n = count($this->plots); + for( $i=0; $i < $n; ++$i ) { + $csim .= $this->plots[$i]->GetCSIMareas(); + } - $n = count($this->y2plots); - for( $i=0; $i < $n; ++$i ) - $csim .= $this->y2plots[$i]->GetCSIMareas(); + $n = count($this->y2plots); + for( $i=0; $i < $n; ++$i ) { + $csim .= $this->y2plots[$i]->GetCSIMareas(); + } - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - $m = count($this->ynplots[$i]); - for($j=0; $j < $m; ++$j ) { - $csim .= $this->ynplots[$i][$j]->GetCSIMareas(); - } - } + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + $m = count($this->ynplots[$i]); + for($j=0; $j < $m; ++$j ) { + $csim .= $this->ynplots[$i][$j]->GetCSIMareas(); + } + } - $n = count($this->iTables); - for( $i=0; $i < $n; ++$i ) { - $csim .= $this->iTables[$i]->GetCSIMareas(); - } + $n = count($this->iTables); + for( $i=0; $i < $n; ++$i ) { + $csim .= $this->iTables[$i]->GetCSIMareas(); + } - return $csim; + return $csim; } - + // Get a complete .. tag for the final image map function GetHTMLImageMap($aMapName) { - $im = "\n"; - $im .= $this->GetCSIMareas(); - $im .= ""; - return $im; + $im = "\n"; + $im .= $this->GetCSIMareas(); + $im .= ""; + return $im; } function CheckCSIMCache($aCacheName,$aTimeOut=60) { - global $_SERVER; + global $_SERVER; - if( $aCacheName=='auto' ) - $aCacheName=basename($_SERVER['PHP_SELF']); + if( $aCacheName=='auto' ) { + $aCacheName=basename($_SERVER['PHP_SELF']); + } - $urlarg = $this->GetURLArguments(); - $this->csimcachename = CSIMCACHE_DIR.$aCacheName.$urlarg; - $this->csimcachetimeout = $aTimeOut; + $urlarg = $this->GetURLArguments(); + $this->csimcachename = CSIMCACHE_DIR.$aCacheName.$urlarg; + $this->csimcachetimeout = $aTimeOut; - // First determine if we need to check for a cached version - // This differs from the standard cache in the sense that the - // image and CSIM map HTML file is written relative to the directory - // the script executes in and not the specified cache directory. - // The reason for this is that the cache directory is not necessarily - // accessible from the HTTP server. - if( $this->csimcachename != '' ) { - $dir = dirname($this->csimcachename); - $base = basename($this->csimcachename); - $base = strtok($base,'.'); - $suffix = strtok('.'); - $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html'; - $baseimg = $dir.'/'.$base.'?'.$urlarg.'.'.$this->img->img_format; + // First determine if we need to check for a cached version + // This differs from the standard cache in the sense that the + // image and CSIM map HTML file is written relative to the directory + // the script executes in and not the specified cache directory. + // The reason for this is that the cache directory is not necessarily + // accessible from the HTTP server. + if( $this->csimcachename != '' ) { + $dir = dirname($this->csimcachename); + $base = basename($this->csimcachename); + $base = strtok($base,'.'); + $suffix = strtok('.'); + $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html'; + $baseimg = $dir.'/'.$base.'?'.$urlarg.'.'.$this->img->img_format; - $timedout=false; - // Does it exist at all ? - - if( file_exists($basecsim) && file_exists($baseimg) ) { - // Check that it hasn't timed out - $diff=time()-filemtime($basecsim); - if( $this->csimcachetimeout>0 && ($diff > $this->csimcachetimeout*60) ) { - $timedout=true; - @unlink($basecsim); - @unlink($baseimg); - } - else { - if ($fh = @fopen($basecsim, "r")) { - fpassthru($fh); - return true; - } - else - JpGraphError::RaiseL(25027,$basecsim);//(" Can't open cached CSIM \"$basecsim\" for reading."); - } - } - } - return false; + $timedout=false; + // Does it exist at all ? + + if( file_exists($basecsim) && file_exists($baseimg) ) { + // Check that it hasn't timed out + $diff=time()-filemtime($basecsim); + if( $this->csimcachetimeout>0 && ($diff > $this->csimcachetimeout*60) ) { + $timedout=true; + @unlink($basecsim); + @unlink($baseimg); + } + else { + if ($fh = @fopen($basecsim, "r")) { + fpassthru($fh); + return true; + } + else { + JpGraphError::RaiseL(25027,$basecsim);//(" Can't open cached CSIM \"$basecsim\" for reading."); + } + } + } + } + return false; } // Build the argument string to be used with the csim images - function GetURLArguments() { - - // This is a JPGRAPH internal defined that prevents - // us from recursively coming here again - $urlarg = _CSIM_DISPLAY.'=1'; + static function GetURLArguments($aAddRecursiveBlocker=false) { - // Now reconstruct any user URL argument - reset($_GET); - while( list($key,$value) = each($_GET) ) { - if( is_array($value) ) { - foreach ( $value as $k => $v ) { - $urlarg .= '&'.$key.'%5B'.$k.'%5D='.urlencode($v); - } - } - else { - $urlarg .= '&'.$key.'='.urlencode($value); - } - } + if( $aAddRecursiveBlocker ) { + // This is a JPGRAPH internal defined that prevents + // us from recursively coming here again + $urlarg = _CSIM_DISPLAY.'=1'; + } - // It's not ideal to convert POST argument to GET arguments - // but there is little else we can do. One idea for the - // future might be recreate the POST header in case. - reset($_POST); - while( list($key,$value) = each($_POST) ) { - if( is_array($value) ) { - foreach ( $value as $k => $v ) { - $urlarg .= '&'.$key.'%5B'.$k.'%5D='.urlencode($v); - } - } - else { - $urlarg .= '&'.$key.'='.urlencode($value); - } - } + // Now reconstruct any user URL argument + reset($_GET); + while( list($key,$value) = each($_GET) ) { + if( is_array($value) ) { + foreach ( $value as $k => $v ) { + $urlarg .= '&'.$key.'%5B'.$k.'%5D='.urlencode($v); + } + } + else { + $urlarg .= '&'.$key.'='.urlencode($value); + } + } - return $urlarg; + // It's not ideal to convert POST argument to GET arguments + // but there is little else we can do. One idea for the + // future might be recreate the POST header in case. + reset($_POST); + while( list($key,$value) = each($_POST) ) { + if( is_array($value) ) { + foreach ( $value as $k => $v ) { + $urlarg .= '&'.$key.'%5B'.$k.'%5D='.urlencode($v); + } + } + else { + $urlarg .= '&'.$key.'='.urlencode($value); + } + } + + return $urlarg; } function SetCSIMImgAlt($aAlt) { - $this->iCSIMImgAlt = $aAlt; + $this->iCSIMImgAlt = $aAlt; } function StrokeCSIM($aScriptName='auto',$aCSIMName='',$aBorder=0) { - if( $aCSIMName=='' ) { - // create a random map name - srand ((double) microtime() * 1000000); - $r = rand(0,100000); - $aCSIMName='__mapname'.$r.'__'; - } + if( $aCSIMName=='' ) { + // create a random map name + srand ((double) microtime() * 1000000); + $r = rand(0,100000); + $aCSIMName='__mapname'.$r.'__'; + } - if( $aScriptName=='auto' ) - $aScriptName=basename($_SERVER['PHP_SELF']); + if( $aScriptName=='auto' ) { + $aScriptName=basename($_SERVER['PHP_SELF']); + } - $urlarg = $this->GetURLArguments(); + $urlarg = $this->GetURLArguments(true); - if( empty($_GET[_CSIM_DISPLAY]) ) { - // First determine if we need to check for a cached version - // This differs from the standard cache in the sense that the - // image and CSIM map HTML file is written relative to the directory - // the script executes in and not the specified cache directory. - // The reason for this is that the cache directory is not necessarily - // accessible from the HTTP server. - if( $this->csimcachename != '' ) { - $dir = dirname($this->csimcachename); - $base = basename($this->csimcachename); - $base = strtok($base,'.'); - $suffix = strtok('.'); - $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html'; - $baseimg = $base.'?'.$urlarg.'.'.$this->img->img_format; + if( empty($_GET[_CSIM_DISPLAY]) ) { + // First determine if we need to check for a cached version + // This differs from the standard cache in the sense that the + // image and CSIM map HTML file is written relative to the directory + // the script executes in and not the specified cache directory. + // The reason for this is that the cache directory is not necessarily + // accessible from the HTTP server. + if( $this->csimcachename != '' ) { + $dir = dirname($this->csimcachename); + $base = basename($this->csimcachename); + $base = strtok($base,'.'); + $suffix = strtok('.'); + $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html'; + $baseimg = $base.'?'.$urlarg.'.'.$this->img->img_format; - // Check that apache can write to directory specified + // Check that apache can write to directory specified - if( file_exists($dir) && !is_writeable($dir) ) { - JpgraphError::RaiseL(25028,$dir);//('Apache/PHP does not have permission to write to the CSIM cache directory ('.$dir.'). Check permissions.'); - } - - // Make sure directory exists - $this->cache->MakeDirs($dir); + if( file_exists($dir) && !is_writeable($dir) ) { + JpgraphError::RaiseL(25028,$dir);//('Apache/PHP does not have permission to write to the CSIM cache directory ('.$dir.'). Check permissions.'); + } - // Write the image file - $this->Stroke(CSIMCACHE_DIR.$baseimg); + // Make sure directory exists + $this->cache->MakeDirs($dir); - // Construct wrapper HTML and write to file and send it back to browser + // Write the image file + $this->Stroke(CSIMCACHE_DIR.$baseimg); - // In the src URL we must replace the '?' with its encoding to prevent the arguments - // to be converted to real arguments. - $tmp = str_replace('?','%3f',$baseimg); - $htmlwrap = $this->GetHTMLImageMap($aCSIMName)."\n". - '\"".$this-iCSIMImgAlt."\" />\n"; + // Construct wrapper HTML and write to file and send it back to browser - if($fh = @fopen($basecsim,'w') ) { - fwrite($fh,$htmlwrap); - fclose($fh); - echo $htmlwrap; - } - else - JpGraphError::RaiseL(25029,$basecsim);//(" Can't write CSIM \"$basecsim\" for writing. Check free space and permissions."); - } - else { + // In the src URL we must replace the '?' with its encoding to prevent the arguments + // to be converted to real arguments. + $tmp = str_replace('?','%3f',$baseimg); + $htmlwrap = $this->GetHTMLImageMap($aCSIMName)."\n". + '\"".$this-iCSIMImgAlt."\" />\n"; - if( $aScriptName=='' ) { - JpGraphError::RaiseL(25030);//('Missing script name in call to StrokeCSIM(). You must specify the name of the actual image script as the first parameter to StrokeCSIM().'); - } - echo $this->GetHTMLImageMap($aCSIMName); - echo "\"".$this-iCSIMImgAlt."\" />\n"; - } - } - else { - $this->Stroke(); - } + if($fh = @fopen($basecsim,'w') ) { + fwrite($fh,$htmlwrap); + fclose($fh); + echo $htmlwrap; + } + else { + JpGraphError::RaiseL(25029,$basecsim);//(" Can't write CSIM \"$basecsim\" for writing. Check free space and permissions."); + } + } + else { + + if( $aScriptName=='' ) { + JpGraphError::RaiseL(25030);//('Missing script name in call to StrokeCSIM(). You must specify the name of the actual image script as the first parameter to StrokeCSIM().'); + } + echo $this->GetHTMLImageMap($aCSIMName) . $this->GetCSIMImgHTML($aCSIMName, $aScriptName, $aBorder); + } + } + else { + $this->Stroke(); + } + } + + function StrokeCSIMImage() { + if( @$_GET[_CSIM_DISPLAY] == 1 ) { + $this->Stroke(); + } + } + + function GetCSIMImgHTML($aCSIMName, $aScriptName='auto', $aBorder=0 ) { + if( $aScriptName=='auto' ) { + $aScriptName=basename($_SERVER['PHP_SELF']); + } + $urlarg = $this->GetURLArguments(true); + return "\"".$this-iCSIMImgAlt."\" />\n"; } function GetTextsYMinMax($aY2=false) { - if( $aY2 ) - $txts = $this->y2texts; - else - $txts = $this->texts; - $n = count($txts); - $min=null; - $max=null; - for( $i=0; $i < $n; ++$i ) { - if( $txts[$i]->iScalePosY !== null && - $txts[$i]->iScalePosX !== null ) { - if( $min === null ) { - $min = $max = $txts[$i]->iScalePosY ; - } - else { - $min = min($min,$txts[$i]->iScalePosY); - $max = max($max,$txts[$i]->iScalePosY); - } - } - } - if( $min !== null ) { - return array($min,$max); - } - else - return null; + if( $aY2 ) { + $txts = $this->y2texts; + } + else { + $txts = $this->texts; + } + $n = count($txts); + $min=null; + $max=null; + for( $i=0; $i < $n; ++$i ) { + if( $txts[$i]->iScalePosY !== null && $txts[$i]->iScalePosX !== null ) { + if( $min === null ) { + $min = $max = $txts[$i]->iScalePosY ; + } + else { + $min = min($min,$txts[$i]->iScalePosY); + $max = max($max,$txts[$i]->iScalePosY); + } + } + } + if( $min !== null ) { + return array($min,$max); + } + else { + return null; + } } function GetTextsXMinMax($aY2=false) { - if( $aY2 ) - $txts = $this->y2texts; - else - $txts = $this->texts; - $n = count($txts); - $min=null; - $max=null; - for( $i=0; $i < $n; ++$i ) { - if( $txts[$i]->iScalePosY !== null && - $txts[$i]->iScalePosX !== null ) { - if( $min === null ) { - $min = $max = $txts[$i]->iScalePosX ; - } - else { - $min = min($min,$txts[$i]->iScalePosX); - $max = max($max,$txts[$i]->iScalePosX); - } - } - } - if( $min !== null ) { - return array($min,$max); - } - else - return null; + if( $aY2 ) { + $txts = $this->y2texts; + } + else { + $txts = $this->texts; + } + $n = count($txts); + $min=null; + $max=null; + for( $i=0; $i < $n; ++$i ) { + if( $txts[$i]->iScalePosY !== null && $txts[$i]->iScalePosX !== null ) { + if( $min === null ) { + $min = $max = $txts[$i]->iScalePosX ; + } + else { + $min = min($min,$txts[$i]->iScalePosX); + $max = max($max,$txts[$i]->iScalePosX); + } + } + } + if( $min !== null ) { + return array($min,$max); + } + else { + return null; + } } function GetXMinMax() { - list($min,$ymin) = $this->plots[0]->Min(); - list($max,$ymax) = $this->plots[0]->Max(); - foreach( $this->plots as $p ) { - list($xmin,$ymin) = $p->Min(); - list($xmax,$ymax) = $p->Max(); - $min = Min($xmin,$min); - $max = Max($xmax,$max); - } + list($min,$ymin) = $this->plots[0]->Min(); + list($max,$ymax) = $this->plots[0]->Max(); + foreach( $this->plots as $p ) { + list($xmin,$ymin) = $p->Min(); + list($xmax,$ymax) = $p->Max(); + $min = Min($xmin,$min); + $max = Max($xmax,$max); + } - if( $this->y2axis != null ) { - foreach( $this->y2plots as $p ) { - list($xmin,$ymin) = $p->Min(); - list($xmax,$ymax) = $p->Max(); - $min = Min($xmin,$min); - $max = Max($xmax,$max); - } - } + if( $this->y2axis != null ) { + foreach( $this->y2plots as $p ) { + list($xmin,$ymin) = $p->Min(); + list($xmax,$ymax) = $p->Max(); + $min = Min($xmin,$min); + $max = Max($xmax,$max); + } + } - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - if( $this->ynaxis[$i] != null) { - foreach( $this->ynplots[$i] as $p ) { - list($xmin,$ymin) = $p->Min(); - list($xmax,$ymax) = $p->Max(); - $min = Min($xmin,$min); - $max = Max($xmax,$max); - } - } - } - return array($min,$max); + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + if( $this->ynaxis[$i] != null) { + foreach( $this->ynplots[$i] as $p ) { + list($xmin,$ymin) = $p->Min(); + list($xmax,$ymax) = $p->Max(); + $min = Min($xmin,$min); + $max = Max($xmax,$max); + } + } + } + return array($min,$max); } function AdjustMarginsForTitles() { - $totrequired = - ($this->title->t != '' ? - $this->title->GetTextHeight($this->img) + $this->title->margin + 5 : 0 ) + - ($this->subtitle->t != '' ? - $this->subtitle->GetTextHeight($this->img) + $this->subtitle->margin + 5 : 0 ) + - ($this->subsubtitle->t != '' ? - $this->subsubtitle->GetTextHeight($this->img) + $this->subsubtitle->margin + 5 : 0 ) ; - + $totrequired = ($this->title->t != '' ? $this->title->GetTextHeight($this->img) + $this->title->margin + 5 : 0 ) + + ($this->subtitle->t != '' ? $this->subtitle->GetTextHeight($this->img) + $this->subtitle->margin + 5 : 0 ) + + ($this->subsubtitle->t != '' ? $this->subsubtitle->GetTextHeight($this->img) + $this->subsubtitle->margin + 5 : 0 ) ; - $btotrequired = 0; - if($this->xaxis != null && !$this->xaxis->hide && !$this->xaxis->hide_labels ) { - // Minimum bottom margin - if( $this->xaxis->title->t != '' ) { - if( $this->img->a == 90 ) - $btotrequired = $this->yaxis->title->GetTextHeight($this->img) + 5 ; - else - $btotrequired = $this->xaxis->title->GetTextHeight($this->img) + 5 ; - } - else - $btotrequired = 0; - - if( $this->img->a == 90 ) { - $this->img->SetFont($this->yaxis->font_family,$this->yaxis->font_style, - $this->yaxis->font_size); - $lh = $this->img->GetTextHeight('Mg',$this->yaxis->label_angle); - } - else { - $this->img->SetFont($this->xaxis->font_family,$this->xaxis->font_style, - $this->xaxis->font_size); - $lh = $this->img->GetTextHeight('Mg',$this->xaxis->label_angle); - } - - $btotrequired += $lh + 5; - } + $btotrequired = 0; + if($this->xaxis != null && !$this->xaxis->hide && !$this->xaxis->hide_labels ) { + // Minimum bottom margin + if( $this->xaxis->title->t != '' ) { + if( $this->img->a == 90 ) { + $btotrequired = $this->yaxis->title->GetTextHeight($this->img) + 7 ; + } + else { + $btotrequired = $this->xaxis->title->GetTextHeight($this->img) + 7 ; + } + } + else { + $btotrequired = 0; + } - if( $this->img->a == 90 ) { - // DO Nothing. It gets too messy to do this properly for 90 deg... - } - else{ - if( $this->img->top_margin < $totrequired ) { - $this->SetMargin($this->img->left_margin,$this->img->right_margin, - $totrequired,$this->img->bottom_margin); - } - if( $this->img->bottom_margin < $btotrequired ) { - $this->SetMargin($this->img->left_margin,$this->img->right_margin, - $this->img->top_margin,$btotrequired); - } - } + if( $this->img->a == 90 ) { + $this->img->SetFont($this->yaxis->font_family,$this->yaxis->font_style, + $this->yaxis->font_size); + $lh = $this->img->GetTextHeight('Mg',$this->yaxis->label_angle); + } + else { + $this->img->SetFont($this->xaxis->font_family,$this->xaxis->font_style, + $this->xaxis->font_size); + $lh = $this->img->GetTextHeight('Mg',$this->xaxis->label_angle); + } + + $btotrequired += $lh + 6; + } + + if( $this->img->a == 90 ) { + // DO Nothing. It gets too messy to do this properly for 90 deg... + } + else{ + if( $this->img->top_margin < $totrequired ) { + $this->SetMargin($this->img->left_margin,$this->img->right_margin, + $totrequired,$this->img->bottom_margin); + } + if( $this->img->bottom_margin < $btotrequired ) { + $this->SetMargin($this->img->left_margin,$this->img->right_margin, + $this->img->top_margin,$btotrequired); + } + } + } + + function StrokeStore($aStrokeFileName) { + // Get the handler to prevent the library from sending the + // image to the browser + $ih = $this->Stroke(_IMG_HANDLER); + + // Stroke it to a file + $this->img->Stream($aStrokeFileName); + + // Send it back to browser + $this->img->Headers(); + $this->img->Stream(); } // Stroke the graph - // $aStrokeFileName If != "" the image will be written to this file and NOT + // $aStrokeFileName If != "" the image will be written to this file and NOT // streamed back to the browser - function Stroke($aStrokeFileName="") { + function Stroke($aStrokeFileName='') { - // Fist make a sanity check that user has specified a scale - if( empty($this->yscale) ) { - JpGraphError::RaiseL(25031);//('You must specify what scale to use with a call to Graph::SetScale().'); - } + // Fist make a sanity check that user has specified a scale + if( empty($this->yscale) ) { + JpGraphError::RaiseL(25031);//('You must specify what scale to use with a call to Graph::SetScale().'); + } - // Start by adjusting the margin so that potential titles will fit. - $this->AdjustMarginsForTitles(); + // Start by adjusting the margin so that potential titles will fit. + $this->AdjustMarginsForTitles(); - // Setup scale constants - if( $this->yscale ) $this->yscale->InitConstants($this->img); - if( $this->xscale ) $this->xscale->InitConstants($this->img); - if( $this->y2scale ) $this->y2scale->InitConstants($this->img); - - $n=count($this->ynscale); - for($i=0; $i < $n; ++$i) { - if( $this->ynscale[$i] ) $this->ynscale[$i]->InitConstants($this->img); - } + // Give the plot a chance to do any scale adjuments the individual plots + // wants to do. Right now this is only used by the contour plot to set scale + // limits - // If the filename is the predefined value = '_csim_special_' - // we assume that the call to stroke only needs to do enough - // to correctly generate the CSIM maps. - // We use this variable to skip things we don't strictly need - // to do to generate the image map to improve performance - // a best we can. Therefor you will see a lot of tests !$_csim in the - // code below. - $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE); + for($i=0; $i < count($this->plots) ; ++$i ) { + $this->plots[$i]->PreScaleSetup($this); + } - // We need to know if we have stroked the plot in the - // GetCSIMareas. Otherwise the CSIM hasn't been generated - // and in the case of GetCSIM called before stroke to generate - // CSIM without storing an image to disk GetCSIM must call Stroke. - $this->iHasStroked = true; + // Setup scale constants + if( $this->yscale ) $this->yscale->InitConstants($this->img); + if( $this->xscale ) $this->xscale->InitConstants($this->img); + if( $this->y2scale ) $this->y2scale->InitConstants($this->img); - // Do any pre-stroke adjustment that is needed by the different plot types - // (i.e bar plots want's to add an offset to the x-labels etc) - for($i=0; $i < count($this->plots) ; ++$i ) { - $this->plots[$i]->PreStrokeAdjust($this); - $this->plots[$i]->DoLegend($this); - } - - // Any plots on the second Y scale? - if( $this->y2scale != null ) { - for($i=0; $iy2plots) ; ++$i ) { - $this->y2plots[$i]->PreStrokeAdjust($this); - $this->y2plots[$i]->DoLegend($this); - } - } + $n=count($this->ynscale); + for($i=0; $i < $n; ++$i) { + if( $this->ynscale[$i] ) { + $this->ynscale[$i]->InitConstants($this->img); + } + } - // Any plots on the extra Y axises? - $n = count($this->ynaxis); - for($i=0; $i<$n ; ++$i ) { - if( $this->ynplots == null || $this->ynplots[$i] == null) { - JpGraphError::RaiseL(25032,$i);//("No plots for Y-axis nbr:$i"); - } - $m = count($this->ynplots[$i]); - for($j=0; $j < $m; ++$j ) { - $this->ynplots[$i][$j]->PreStrokeAdjust($this); - $this->ynplots[$i][$j]->DoLegend($this); - } - } + // If the filename is the predefined value = '_csim_special_' + // we assume that the call to stroke only needs to do enough + // to correctly generate the CSIM maps. + // We use this variable to skip things we don't strictly need + // to do to generate the image map to improve performance + // a best we can. Therefor you will see a lot of tests !$_csim in the + // code below. + $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE); - // Bail out if any of the Y-axis not been specified and - // has no plots. (This means it is impossible to do autoscaling and - // no other scale was given so we can't possible draw anything). If you use manual - // scaling you also have to supply the tick steps as well. - if( (!$this->yscale->IsSpecified() && count($this->plots)==0) || - ($this->y2scale!=null && !$this->y2scale->IsSpecified() && count($this->y2plots)==0) ) { - //$e = "n=".count($this->y2plots)."\n"; - // $e = "Can't draw unspecified Y-scale.
\nYou have either:
\n"; - // $e .= "1. Specified an Y axis for autoscaling but have not supplied any plots
\n"; - // $e .= "2. Specified a scale manually but have forgot to specify the tick steps"; - JpGraphError::RaiseL(25026); - } - - // Bail out if no plots and no specified X-scale - if( (!$this->xscale->IsSpecified() && count($this->plots)==0 && count($this->y2plots)==0) ) - JpGraphError::RaiseL(25034);//("JpGraph: Can't draw unspecified X-scale.
No plots.
"); - - //Check if we should autoscale y-axis - if( !$this->yscale->IsSpecified() && count($this->plots)>0 ) { - list($min,$max) = $this->GetPlotsYMinMax($this->plots); - $lres = $this->GetLinesYMinMax($this->lines); - if( is_array($lres) ) { - list($linmin,$linmax) = $lres ; - $min = min($min,$linmin); - $max = max($max,$linmax); - } - $tres = $this->GetTextsYMinMax(); - if( is_array($tres) ) { - list($tmin,$tmax) = $tres ; - $min = min($min,$tmin); - $max = max($max,$tmax); - } - $this->yscale->AutoScale($this->img,$min,$max, - $this->img->plotheight/$this->ytick_factor); - } - elseif( $this->yscale->IsSpecified() && - ( $this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified()) ) { - // The tick calculation will use the user suplied min/max values to determine - // the ticks. If auto_ticks is false the exact user specifed min and max - // values will be used for the scale. - // If auto_ticks is true then the scale might be slightly adjusted - // so that the min and max values falls on an even major step. - $min = $this->yscale->scale[0]; - $max = $this->yscale->scale[1]; - $this->yscale->AutoScale($this->img,$min,$max, - $this->img->plotheight/$this->ytick_factor, - $this->yscale->auto_ticks); - - // Now make sure we show enough precision to accurate display the - // labels. If this is not done then the user might end up with - // a scale that might actually start with, say 13.5, butdue to rounding - // the scale label will ony show 14. - if( abs(floor($min)-$min) > 0 ) { - - // If the user has set a format then we bail out - if( $this->yscale->ticks->label_formatstr == '' && $this->yscale->ticks->label_dateformatstr == '' ) { - $this->yscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; - } - } - } - - if( $this->y2scale != null) { - if( !$this->y2scale->IsSpecified() && count($this->y2plots)>0 ) { - list($min,$max) = $this->GetPlotsYMinMax($this->y2plots); - - $lres = $this->GetLinesYMinMax($this->y2lines); - if( is_array($lres) ) { - list($linmin,$linmax) = $lres ; - $min = min($min,$linmin); - $max = max($max,$linmax); - } - $tres = $this->GetTextsYMinMax(true); - if( is_array($tres) ) { - list($tmin,$tmax) = $tres ; - $min = min($min,$tmin); - $max = max($max,$tmax); - } - $this->y2scale->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor); - } - elseif( $this->y2scale->IsSpecified() && - ( $this->y2scale->auto_ticks || !$this->y2scale->ticks->IsSpecified()) ) { - // The tick calculation will use the user suplied min/max values to determine - // the ticks. If auto_ticks is false the exact user specifed min and max - // values will be used for the scale. - // If auto_ticks is true then the scale might be slightly adjusted - // so that the min and max values falls on an even major step. - $min = $this->y2scale->scale[0]; - $max = $this->y2scale->scale[1]; - $this->y2scale->AutoScale($this->img,$min,$max, - $this->img->plotheight/$this->ytick_factor, - $this->y2scale->auto_ticks); - - // Now make sure we show enough precision to accurate display the - // labels. If this is not done then the user might end up with - // a scale that might actually start with, say 13.5, butdue to rounding - // the scale label will ony show 14. - if( abs(floor($min)-$min) > 0 ) { - - // If the user has set a format then we bail out - if( $this->y2scale->ticks->label_formatstr == '' && $this->y2scale->ticks->label_dateformatstr == '' ) { - $this->y2scale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; - } - } - - } - } - - // - // Autoscale the extra Y-axises - // - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - if( $this->ynscale[$i] != null) { - if( !$this->ynscale[$i]->IsSpecified() && count($this->ynplots[$i])>0 ) { - list($min,$max) = $this->GetPlotsYMinMax($this->ynplots[$i]); - $this->ynscale[$i]->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor); - } - elseif( $this->ynscale[$i]->IsSpecified() && - ( $this->ynscale[$i]->auto_ticks || !$this->ynscale[$i]->ticks->IsSpecified()) ) { - // The tick calculation will use the user suplied min/max values to determine - // the ticks. If auto_ticks is false the exact user specifed min and max - // values will be used for the scale. - // If auto_ticks is true then the scale might be slightly adjusted - // so that the min and max values falls on an even major step. - $min = $this->ynscale[$i]->scale[0]; - $max = $this->ynscale[$i]->scale[1]; - $this->ynscale[$i]->AutoScale($this->img,$min,$max, - $this->img->plotheight/$this->ytick_factor, - $this->ynscale[$i]->auto_ticks); - - // Now make sure we show enough precision to accurate display the - // labels. If this is not done then the user might end up with - // a scale that might actually start with, say 13.5, butdue to rounding - // the scale label will ony show 14. - if( abs(floor($min)-$min) > 0 ) { - - // If the user has set a format then we bail out - if( $this->ynscale[$i]->ticks->label_formatstr == '' && $this->ynscale[$i]->ticks->label_dateformatstr == '' ) { - $this->ynscale[$i]->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; - } - } - - } - } - } - - //Check if we should autoscale x-axis - if( !$this->xscale->IsSpecified() ) { - if( substr($this->axtype,0,4) == "text" ) { - $max=0; - $n = count($this->plots); - for($i=0; $i < $n; ++$i ) { - $p = $this->plots[$i]; - // We need some unfortunate sub class knowledge here in order - // to increase number of data points in case it is a line plot - // which has the barcenter set. If not it could mean that the - // last point of the data is outside the scale since the barcenter - // settings means that we will shift the entire plot half a tick step - // to the right in oder to align with the center of the bars. - if( class_exists('BarPlot',false) ) { - $cl = strtolower(get_class($p)); - if( (class_exists('BarPlot',false) && ($p instanceof BarPlot)) || - empty($p->barcenter) ) - $max=max($max,$p->numpoints-1); - else { - $max=max($max,$p->numpoints); - } - } - else { - if( empty($p->barcenter) ) { - $max=max($max,$p->numpoints-1); - } - else { - $max=max($max,$p->numpoints); - } - } - } - $min=0; - if( $this->y2axis != null ) { - foreach( $this->y2plots as $p ) { - $max=max($max,$p->numpoints-1); - } - } - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - if( $this->ynaxis[$i] != null) { - foreach( $this->ynplots[$i] as $p ) { - $max=max($max,$p->numpoints-1); - } - } - } - - $this->xscale->Update($this->img,$min,$max); - $this->xscale->ticks->Set($this->xaxis->tick_step,1); - $this->xscale->ticks->SupressMinorTickMarks(); - } - else { - list($min,$max) = $this->GetXMinMax(); - - $lres = $this->GetLinesXMinMax($this->lines); - if( $lres ) { - list($linmin,$linmax) = $lres ; - $min = min($min,$linmin); - $max = max($max,$linmax); - } - - $lres = $this->GetLinesXMinMax($this->y2lines); - if( $lres ) { - list($linmin,$linmax) = $lres ; - $min = min($min,$linmin); - $max = max($max,$linmax); - } - - $tres = $this->GetTextsXMinMax(); - if( $tres ) { - list($tmin,$tmax) = $tres ; - $min = min($min,$tmin); - $max = max($max,$tmax); - } - - $tres = $this->GetTextsXMinMax(true); - if( $tres ) { - list($tmin,$tmax) = $tres ; - $min = min($min,$tmin); - $max = max($max,$tmax); - } - - $this->xscale->AutoScale($this->img,$min,$max,round($this->img->plotwidth/$this->xtick_factor)); - } - - //Adjust position of y-axis and y2-axis to minimum/maximum of x-scale - if( !is_numeric($this->yaxis->pos) && !is_string($this->yaxis->pos) ) - $this->yaxis->SetPos($this->xscale->GetMinVal()); - if( $this->y2axis != null ) { - if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) ) - $this->y2axis->SetPos($this->xscale->GetMaxVal()); - $this->y2axis->SetTitleSide(SIDE_RIGHT); - } - $n = count($this->ynaxis); - $nY2adj = $this->y2axis != null ? $this->iYAxisDeltaPos : 0; - for( $i=0; $i < $n; ++$i ) { - if( $this->ynaxis[$i] != null ) { - if( !is_numeric($this->ynaxis[$i]->pos) && !is_string($this->ynaxis[$i]->pos) ) { - $this->ynaxis[$i]->SetPos($this->xscale->GetMaxVal()); - $this->ynaxis[$i]->SetPosAbsDelta($i*$this->iYAxisDeltaPos + $nY2adj); - } - $this->ynaxis[$i]->SetTitleSide(SIDE_RIGHT); - } - } - - } - elseif( $this->xscale->IsSpecified() && - ( $this->xscale->auto_ticks || !$this->xscale->ticks->IsSpecified()) ) { - // The tick calculation will use the user suplied min/max values to determine - // the ticks. If auto_ticks is false the exact user specifed min and max - // values will be used for the scale. - // If auto_ticks is true then the scale might be slightly adjusted - // so that the min and max values falls on an even major step. - $min = $this->xscale->scale[0]; - $max = $this->xscale->scale[1]; - $this->xscale->AutoScale($this->img,$min,$max, - round($this->img->plotwidth/$this->xtick_factor), - false); - - // Now make sure we show enough precision to accurate display the - // labels. If this is not done then the user might end up with - // a scale that might actually start with, say 13.5, butdue to rounding - // the scale label will ony show 14. - if( abs(floor($min)-$min) > 0 ) { - - // If the user has set a format then we bail out - if( $this->xscale->ticks->label_formatstr == '' && $this->xscale->ticks->label_dateformatstr == '' ) { - $this->xscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; - } - } + // If we are called the second time (perhaps the user has called GetHTMLImageMap() + // himself then the legends have alsready been populated once in order to get the + // CSIM coordinats. Since we do not want the legends to be populated a second time + // we clear the legends + $this->legend->Clear(); - if( $this->y2axis != null ) { - if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) ) - $this->y2axis->SetPos($this->xscale->GetMaxVal()); - $this->y2axis->SetTitleSide(SIDE_RIGHT); - } + // We need to know if we have stroked the plot in the + // GetCSIMareas. Otherwise the CSIM hasn't been generated + // and in the case of GetCSIM called before stroke to generate + // CSIM without storing an image to disk GetCSIM must call Stroke. + $this->iHasStroked = true; - } - - // If we have a negative values and x-axis position is at 0 - // we need to supress the first and possible the last tick since - // they will be drawn on top of the y-axis (and possible y2 axis) - // The test below might seem strange the reasone being that if - // the user hasn't specified a value for position this will not - // be set until we do the stroke for the axis so as of now it - // is undefined. - // For X-text scale we ignore all this since the tick are usually - // much further in and not close to the Y-axis. Hence the test - // for 'text' + // Do any pre-stroke adjustment that is needed by the different plot types + // (i.e bar plots want's to add an offset to the x-labels etc) + for($i=0; $i < count($this->plots) ; ++$i ) { + $this->plots[$i]->PreStrokeAdjust($this); + $this->plots[$i]->DoLegend($this); + } - if( ($this->yaxis->pos==$this->xscale->GetMinVal() || - (is_string($this->yaxis->pos) && $this->yaxis->pos=='min')) && - !is_numeric($this->xaxis->pos) && $this->yscale->GetMinVal() < 0 && - substr($this->axtype,0,4) != 'text' && $this->xaxis->pos!="min" ) { + // Any plots on the second Y scale? + if( $this->y2scale != null ) { + for($i=0; $iy2plots) ; ++$i ) { + $this->y2plots[$i]->PreStrokeAdjust($this); + $this->y2plots[$i]->DoLegend($this); + } + } - //$this->yscale->ticks->SupressZeroLabel(false); - $this->xscale->ticks->SupressFirst(); - if( $this->y2axis != null ) { - $this->xscale->ticks->SupressLast(); - } - } - elseif( !is_numeric($this->yaxis->pos) && $this->yaxis->pos=='max' ) { - $this->xscale->ticks->SupressLast(); - } - + // Any plots on the extra Y axises? + $n = count($this->ynaxis); + for($i=0; $i<$n ; ++$i ) { + if( $this->ynplots == null || $this->ynplots[$i] == null) { + JpGraphError::RaiseL(25032,$i);//("No plots for Y-axis nbr:$i"); + } + $m = count($this->ynplots[$i]); + for($j=0; $j < $m; ++$j ) { + $this->ynplots[$i][$j]->PreStrokeAdjust($this); + $this->ynplots[$i][$j]->DoLegend($this); + } + } - if( !$_csim ) { - $this->StrokePlotArea(); - if( $this->iIconDepth == DEPTH_BACK ) { - $this->StrokeIcons(); - } - } - $this->StrokeAxis(false); + // Bail out if any of the Y-axis not been specified and + // has no plots. (This means it is impossible to do autoscaling and + // no other scale was given so we can't possible draw anything). If you use manual + // scaling you also have to supply the tick steps as well. + if( (!$this->yscale->IsSpecified() && count($this->plots)==0) || + ($this->y2scale!=null && !$this->y2scale->IsSpecified() && count($this->y2plots)==0) ) { + //$e = "n=".count($this->y2plots)."\n"; + // $e = "Can't draw unspecified Y-scale.
\nYou have either:
\n"; + // $e .= "1. Specified an Y axis for autoscaling but have not supplied any plots
\n"; + // $e .= "2. Specified a scale manually but have forgot to specify the tick steps"; + JpGraphError::RaiseL(25026); + } - // Stroke bands - if( $this->bands != null && !$_csim) - for($i=0; $i < count($this->bands); ++$i) { - // Stroke all bands that asks to be in the background - if( $this->bands[$i]->depth == DEPTH_BACK ) - $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale); - } + // Bail out if no plots and no specified X-scale + if( (!$this->xscale->IsSpecified() && count($this->plots)==0 && count($this->y2plots)==0) ) { + JpGraphError::RaiseL(25034);//("JpGraph: Can't draw unspecified X-scale.
No plots.
"); + } - if( $this->y2bands != null && $this->y2scale != null && !$_csim ) - for($i=0; $i < count($this->y2bands); ++$i) { - // Stroke all bands that asks to be in the foreground - if( $this->y2bands[$i]->depth == DEPTH_BACK ) - $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale); - } + //Check if we should autoscale y-axis + if( !$this->yscale->IsSpecified() && count($this->plots)>0 ) { + list($min,$max) = $this->GetPlotsYMinMax($this->plots); + $lres = $this->GetLinesYMinMax($this->lines); + if( is_array($lres) ) { + list($linmin,$linmax) = $lres ; + $min = min($min,$linmin); + $max = max($max,$linmax); + } + $tres = $this->GetTextsYMinMax(); + if( is_array($tres) ) { + list($tmin,$tmax) = $tres ; + $min = min($min,$tmin); + $max = max($max,$tmax); + } + $this->yscale->AutoScale($this->img,$min,$max, + $this->img->plotheight/$this->ytick_factor); + } + elseif( $this->yscale->IsSpecified() && ( $this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified()) ) { + // The tick calculation will use the user suplied min/max values to determine + // the ticks. If auto_ticks is false the exact user specifed min and max + // values will be used for the scale. + // If auto_ticks is true then the scale might be slightly adjusted + // so that the min and max values falls on an even major step. + $min = $this->yscale->scale[0]; + $max = $this->yscale->scale[1]; + $this->yscale->AutoScale($this->img,$min,$max, + $this->img->plotheight/$this->ytick_factor, + $this->yscale->auto_ticks); + + // Now make sure we show enough precision to accurate display the + // labels. If this is not done then the user might end up with + // a scale that might actually start with, say 13.5, butdue to rounding + // the scale label will ony show 14. + if( abs(floor($min)-$min) > 0 ) { + + // If the user has set a format then we bail out + if( $this->yscale->ticks->label_formatstr == '' && $this->yscale->ticks->label_dateformatstr == '' ) { + $this->yscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; + } + } + } + + if( $this->y2scale != null) { + if( !$this->y2scale->IsSpecified() && count($this->y2plots)>0 ) { + list($min,$max) = $this->GetPlotsYMinMax($this->y2plots); + + $lres = $this->GetLinesYMinMax($this->y2lines); + if( is_array($lres) ) { + list($linmin,$linmax) = $lres ; + $min = min($min,$linmin); + $max = max($max,$linmax); + } + $tres = $this->GetTextsYMinMax(true); + if( is_array($tres) ) { + list($tmin,$tmax) = $tres ; + $min = min($min,$tmin); + $max = max($max,$tmax); + } + $this->y2scale->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor); + } + elseif( $this->y2scale->IsSpecified() && ( $this->y2scale->auto_ticks || !$this->y2scale->ticks->IsSpecified()) ) { + // The tick calculation will use the user suplied min/max values to determine + // the ticks. If auto_ticks is false the exact user specifed min and max + // values will be used for the scale. + // If auto_ticks is true then the scale might be slightly adjusted + // so that the min and max values falls on an even major step. + $min = $this->y2scale->scale[0]; + $max = $this->y2scale->scale[1]; + $this->y2scale->AutoScale($this->img,$min,$max, + $this->img->plotheight/$this->ytick_factor, + $this->y2scale->auto_ticks); + + // Now make sure we show enough precision to accurate display the + // labels. If this is not done then the user might end up with + // a scale that might actually start with, say 13.5, butdue to rounding + // the scale label will ony show 14. + if( abs(floor($min)-$min) > 0 ) { + // If the user has set a format then we bail out + if( $this->y2scale->ticks->label_formatstr == '' && $this->y2scale->ticks->label_dateformatstr == '' ) { + $this->y2scale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; + } + } + + } + } + + // + // Autoscale the extra Y-axises + // + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + if( $this->ynscale[$i] != null) { + if( !$this->ynscale[$i]->IsSpecified() && count($this->ynplots[$i])>0 ) { + list($min,$max) = $this->GetPlotsYMinMax($this->ynplots[$i]); + $this->ynscale[$i]->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor); + } + elseif( $this->ynscale[$i]->IsSpecified() && ( $this->ynscale[$i]->auto_ticks || !$this->ynscale[$i]->ticks->IsSpecified()) ) { + // The tick calculation will use the user suplied min/max values to determine + // the ticks. If auto_ticks is false the exact user specifed min and max + // values will be used for the scale. + // If auto_ticks is true then the scale might be slightly adjusted + // so that the min and max values falls on an even major step. + $min = $this->ynscale[$i]->scale[0]; + $max = $this->ynscale[$i]->scale[1]; + $this->ynscale[$i]->AutoScale($this->img,$min,$max, + $this->img->plotheight/$this->ytick_factor, + $this->ynscale[$i]->auto_ticks); + + // Now make sure we show enough precision to accurate display the + // labels. If this is not done then the user might end up with + // a scale that might actually start with, say 13.5, butdue to rounding + // the scale label will ony show 14. + if( abs(floor($min)-$min) > 0 ) { + + // If the user has set a format then we bail out + if( $this->ynscale[$i]->ticks->label_formatstr == '' && $this->ynscale[$i]->ticks->label_dateformatstr == '' ) { + $this->ynscale[$i]->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; + } + } + } + } + } + + //Check if we should autoscale x-axis + if( !$this->xscale->IsSpecified() ) { + if( substr($this->axtype,0,4) == "text" ) { + $max=0; + $n = count($this->plots); + for($i=0; $i < $n; ++$i ) { + $p = $this->plots[$i]; + // We need some unfortunate sub class knowledge here in order + // to increase number of data points in case it is a line plot + // which has the barcenter set. If not it could mean that the + // last point of the data is outside the scale since the barcenter + // settings means that we will shift the entire plot half a tick step + // to the right in oder to align with the center of the bars. + if( class_exists('BarPlot',false) ) { + $cl = strtolower(get_class($p)); + if( (class_exists('BarPlot',false) && ($p instanceof BarPlot)) || empty($p->barcenter) ) { + $max=max($max,$p->numpoints-1); + } + else { + $max=max($max,$p->numpoints); + } + } + else { + if( empty($p->barcenter) ) { + $max=max($max,$p->numpoints-1); + } + else { + $max=max($max,$p->numpoints); + } + } + } + $min=0; + if( $this->y2axis != null ) { + foreach( $this->y2plots as $p ) { + $max=max($max,$p->numpoints-1); + } + } + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + if( $this->ynaxis[$i] != null) { + foreach( $this->ynplots[$i] as $p ) { + $max=max($max,$p->numpoints-1); + } + } + } + + $this->xscale->Update($this->img,$min,$max); + $this->xscale->ticks->Set($this->xaxis->tick_step,1); + $this->xscale->ticks->SupressMinorTickMarks(); + } + else { + list($min,$max) = $this->GetXMinMax(); + + $lres = $this->GetLinesXMinMax($this->lines); + if( $lres ) { + list($linmin,$linmax) = $lres ; + $min = min($min,$linmin); + $max = max($max,$linmax); + } + + $lres = $this->GetLinesXMinMax($this->y2lines); + if( $lres ) { + list($linmin,$linmax) = $lres ; + $min = min($min,$linmin); + $max = max($max,$linmax); + } + + $tres = $this->GetTextsXMinMax(); + if( $tres ) { + list($tmin,$tmax) = $tres ; + $min = min($min,$tmin); + $max = max($max,$tmax); + } + + $tres = $this->GetTextsXMinMax(true); + if( $tres ) { + list($tmin,$tmax) = $tres ; + $min = min($min,$tmin); + $max = max($max,$tmax); + } + + $this->xscale->AutoScale($this->img,$min,$max,round($this->img->plotwidth/$this->xtick_factor)); + } + + //Adjust position of y-axis and y2-axis to minimum/maximum of x-scale + if( !is_numeric($this->yaxis->pos) && !is_string($this->yaxis->pos) ) { + $this->yaxis->SetPos($this->xscale->GetMinVal()); + } + if( $this->y2axis != null ) { + if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) ) { + $this->y2axis->SetPos($this->xscale->GetMaxVal()); + } + $this->y2axis->SetTitleSide(SIDE_RIGHT); + } + $n = count($this->ynaxis); + $nY2adj = $this->y2axis != null ? $this->iYAxisDeltaPos : 0; + for( $i=0; $i < $n; ++$i ) { + if( $this->ynaxis[$i] != null ) { + if( !is_numeric($this->ynaxis[$i]->pos) && !is_string($this->ynaxis[$i]->pos) ) { + $this->ynaxis[$i]->SetPos($this->xscale->GetMaxVal()); + $this->ynaxis[$i]->SetPosAbsDelta($i*$this->iYAxisDeltaPos + $nY2adj); + } + $this->ynaxis[$i]->SetTitleSide(SIDE_RIGHT); + } + } + + } + elseif( $this->xscale->IsSpecified() && ( $this->xscale->auto_ticks || !$this->xscale->ticks->IsSpecified()) ) { + // The tick calculation will use the user suplied min/max values to determine + // the ticks. If auto_ticks is false the exact user specifed min and max + // values will be used for the scale. + // If auto_ticks is true then the scale might be slightly adjusted + // so that the min and max values falls on an even major step. + $min = $this->xscale->scale[0]; + $max = $this->xscale->scale[1]; + $this->xscale->AutoScale($this->img,$min,$max,round($this->img->plotwidth/$this->xtick_factor),false); + + // Now make sure we show enough precision to accurate display the + // labels. If this is not done then the user might end up with + // a scale that might actually start with, say 13.5, butdue to rounding + // the scale label will ony show 14. + if( abs(floor($min)-$min) > 0 ) { + + // If the user has set a format then we bail out + if( $this->xscale->ticks->label_formatstr == '' && $this->xscale->ticks->label_dateformatstr == '' ) { + $this->xscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1; + } + } + + if( $this->y2axis != null ) { + if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) ) { + $this->y2axis->SetPos($this->xscale->GetMaxVal()); + } + $this->y2axis->SetTitleSide(SIDE_RIGHT); + } + + $n = count($this->ynaxis); + $nY2adj = $this->y2axis != null ? $this->iYAxisDeltaPos : 0; + for( $i=0; $i < $n; ++$i ) { + if( $this->ynaxis[$i] != null ) { + if( !is_numeric($this->ynaxis[$i]->pos) && !is_string($this->ynaxis[$i]->pos) ) { + $this->ynaxis[$i]->SetPos($this->xscale->GetMaxVal()); + $this->ynaxis[$i]->SetPosAbsDelta($i*$this->iYAxisDeltaPos + $nY2adj); + } + $this->ynaxis[$i]->SetTitleSide(SIDE_RIGHT); + } + } + + } + + // If we have a negative values and x-axis position is at 0 + // we need to supress the first and possible the last tick since + // they will be drawn on top of the y-axis (and possible y2 axis) + // The test below might seem strange the reasone being that if + // the user hasn't specified a value for position this will not + // be set until we do the stroke for the axis so as of now it + // is undefined. + // For X-text scale we ignore all this since the tick are usually + // much further in and not close to the Y-axis. Hence the test + // for 'text' + + if( ($this->yaxis->pos==$this->xscale->GetMinVal() || (is_string($this->yaxis->pos) && $this->yaxis->pos=='min')) && + !is_numeric($this->xaxis->pos) && $this->yscale->GetMinVal() < 0 && + substr($this->axtype,0,4) != 'text' && $this->xaxis->pos != 'min' ) { + + //$this->yscale->ticks->SupressZeroLabel(false); + $this->xscale->ticks->SupressFirst(); + if( $this->y2axis != null ) { + $this->xscale->ticks->SupressLast(); + } + } + elseif( !is_numeric($this->yaxis->pos) && $this->yaxis->pos=='max' ) { + $this->xscale->ticks->SupressLast(); + } - if( $this->grid_depth == DEPTH_BACK && !$_csim) { - $this->ygrid->Stroke(); - $this->xgrid->Stroke(); - } - - // Stroke Y2-axis - if( $this->y2axis != null && !$_csim) { - $this->y2axis->Stroke($this->xscale); - $this->y2grid->Stroke(); - } + if( !$_csim ) { + $this->StrokePlotArea(); + if( $this->iIconDepth == DEPTH_BACK ) { + $this->StrokeIcons(); + } + } + $this->StrokeAxis(false); - // Stroke yn-axis - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - $this->ynaxis[$i]->Stroke($this->xscale); - } + // Stroke bands + if( $this->bands != null && !$_csim) { + for($i=0; $i < count($this->bands); ++$i) { + // Stroke all bands that asks to be in the background + if( $this->bands[$i]->depth == DEPTH_BACK ) { + $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale); + } + } + } - $oldoff=$this->xscale->off; - if(substr($this->axtype,0,4)=="text") { - if( $this->text_scale_abscenteroff > -1 ) { - // For a text scale the scale factor is the number of pixel per step. - // Hence we can use the scale factor as a substitute for number of pixels - // per major scale step and use that in order to adjust the offset so that - // an object of width "abscenteroff" becomes centered. - $this->xscale->off += round($this->xscale->scale_factor/2)-round($this->text_scale_abscenteroff/2); - } - else { - $this->xscale->off += - ceil($this->xscale->scale_factor*$this->text_scale_off*$this->xscale->ticks->minor_step); - } - } + if( $this->y2bands != null && $this->y2scale != null && !$_csim ) { + for($i=0; $i < count($this->y2bands); ++$i) { + // Stroke all bands that asks to be in the foreground + if( $this->y2bands[$i]->depth == DEPTH_BACK ) { + $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale); + } + } + } - if( $this->iDoClipping ) { - $oldimage = $this->img->CloneCanvasH(); - } + if( $this->grid_depth == DEPTH_BACK && !$_csim) { + $this->ygrid->Stroke(); + $this->xgrid->Stroke(); + } - if( ! $this->y2orderback ) { - // Stroke all plots for Y1 axis - for($i=0; $i < count($this->plots); ++$i) { - $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale); - $this->plots[$i]->StrokeMargin($this->img); - } - } + // Stroke Y2-axis + if( $this->y2axis != null && !$_csim) { + $this->y2axis->Stroke($this->xscale); + $this->y2grid->Stroke(); + } - // Stroke all plots for Y2 axis - if( $this->y2scale != null ) - for($i=0; $i< count($this->y2plots); ++$i ) { - $this->y2plots[$i]->Stroke($this->img,$this->xscale,$this->y2scale); - } + // Stroke yn-axis + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + $this->ynaxis[$i]->Stroke($this->xscale); + } - if( $this->y2orderback ) { - // Stroke all plots for Y1 axis - for($i=0; $i < count($this->plots); ++$i) { - $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale); - $this->plots[$i]->StrokeMargin($this->img); - } - } + $oldoff=$this->xscale->off; + if( substr($this->axtype,0,4) == 'text' ) { + if( $this->text_scale_abscenteroff > -1 ) { + // For a text scale the scale factor is the number of pixel per step. + // Hence we can use the scale factor as a substitute for number of pixels + // per major scale step and use that in order to adjust the offset so that + // an object of width "abscenteroff" becomes centered. + $this->xscale->off += round($this->xscale->scale_factor/2)-round($this->text_scale_abscenteroff/2); + } + else { + $this->xscale->off += + ceil($this->xscale->scale_factor*$this->text_scale_off*$this->xscale->ticks->minor_step); + } + } - $n = count($this->ynaxis); - for( $i=0; $i < $n; ++$i ) { - $m = count($this->ynplots[$i]); - for( $j=0; $j < $m; ++$j ) { - $this->ynplots[$i][$j]->Stroke($this->img,$this->xscale,$this->ynscale[$i]); - $this->ynplots[$i][$j]->StrokeMargin($this->img); - } - } + if( $this->iDoClipping ) { + $oldimage = $this->img->CloneCanvasH(); + } - if( $this->iIconDepth == DEPTH_FRONT) { - $this->StrokeIcons(); - } - - if( $this->iDoClipping ) { - // Clipping only supports graphs at 0 and 90 degrees - if( $this->img->a == 0 ) { - $this->img->CopyCanvasH($oldimage,$this->img->img, - $this->img->left_margin,$this->img->top_margin, - $this->img->left_margin,$this->img->top_margin, - $this->img->plotwidth+1,$this->img->plotheight); - } - elseif( $this->img->a == 90 ) { - $adj = ($this->img->height - $this->img->width)/2; - $this->img->CopyCanvasH($oldimage,$this->img->img, - $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, - $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, - $this->img->plotheight+1,$this->img->plotwidth); - } - else { - JpGraphError::RaiseL(25035,$this->img->a);//('You have enabled clipping. Cliping is only supported for graphs at 0 or 90 degrees rotation. Please adjust you current angle (='.$this->img->a.' degrees) or disable clipping.'); - } - $this->img->Destroy(); - $this->img->SetCanvasH($oldimage); - } + if( ! $this->y2orderback ) { + // Stroke all plots for Y1 axis + for($i=0; $i < count($this->plots); ++$i) { + $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale); + $this->plots[$i]->StrokeMargin($this->img); + } + } - $this->xscale->off=$oldoff; - - if( $this->grid_depth == DEPTH_FRONT && !$_csim ) { - $this->ygrid->Stroke(); - $this->xgrid->Stroke(); - } + // Stroke all plots for Y2 axis + if( $this->y2scale != null ) { + for($i=0; $i< count($this->y2plots); ++$i ) { + $this->y2plots[$i]->Stroke($this->img,$this->xscale,$this->y2scale); + } + } - // Stroke bands - if( $this->bands!= null ) - for($i=0; $i < count($this->bands); ++$i) { - // Stroke all bands that asks to be in the foreground - if( $this->bands[$i]->depth == DEPTH_FRONT ) - $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale); - } + if( $this->y2orderback ) { + // Stroke all plots for Y1 axis + for($i=0; $i < count($this->plots); ++$i) { + $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale); + $this->plots[$i]->StrokeMargin($this->img); + } + } - if( $this->y2bands!= null && $this->y2scale != null ) - for($i=0; $i < count($this->y2bands); ++$i) { - // Stroke all bands that asks to be in the foreground - if( $this->y2bands[$i]->depth == DEPTH_FRONT ) - $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale); - } + $n = count($this->ynaxis); + for( $i=0; $i < $n; ++$i ) { + $m = count($this->ynplots[$i]); + for( $j=0; $j < $m; ++$j ) { + $this->ynplots[$i][$j]->Stroke($this->img,$this->xscale,$this->ynscale[$i]); + $this->ynplots[$i][$j]->StrokeMargin($this->img); + } + } + + if( $this->iIconDepth == DEPTH_FRONT) { + $this->StrokeIcons(); + } + + if( $this->iDoClipping ) { + // Clipping only supports graphs at 0 and 90 degrees + if( $this->img->a == 0 ) { + $this->img->CopyCanvasH($oldimage,$this->img->img, + $this->img->left_margin,$this->img->top_margin, + $this->img->left_margin,$this->img->top_margin, + $this->img->plotwidth+1,$this->img->plotheight); + } + elseif( $this->img->a == 90 ) { + $adj = ($this->img->height - $this->img->width)/2; + $this->img->CopyCanvasH($oldimage,$this->img->img, + $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, + $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, + $this->img->plotheight+1,$this->img->plotwidth); + } + else { + JpGraphError::RaiseL(25035,$this->img->a);//('You have enabled clipping. Cliping is only supported for graphs at 0 or 90 degrees rotation. Please adjust you current angle (='.$this->img->a.' degrees) or disable clipping.'); + } + $this->img->Destroy(); + $this->img->SetCanvasH($oldimage); + } + + $this->xscale->off=$oldoff; + + if( $this->grid_depth == DEPTH_FRONT && !$_csim ) { + $this->ygrid->Stroke(); + $this->xgrid->Stroke(); + } + + // Stroke bands + if( $this->bands!= null ) { + for($i=0; $i < count($this->bands); ++$i) { + // Stroke all bands that asks to be in the foreground + if( $this->bands[$i]->depth == DEPTH_FRONT ) { + $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale); + } + } + } + + if( $this->y2bands!= null && $this->y2scale != null ) { + for($i=0; $i < count($this->y2bands); ++$i) { + // Stroke all bands that asks to be in the foreground + if( $this->y2bands[$i]->depth == DEPTH_FRONT ) { + $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale); + } + } + } - // Stroke any lines added - if( $this->lines != null ) { - for($i=0; $i < count($this->lines); ++$i) { - $this->lines[$i]->Stroke($this->img,$this->xscale,$this->yscale); - $this->lines[$i]->DoLegend($this); - } - } + // Stroke any lines added + if( $this->lines != null ) { + for($i=0; $i < count($this->lines); ++$i) { + $this->lines[$i]->Stroke($this->img,$this->xscale,$this->yscale); + $this->lines[$i]->DoLegend($this); + } + } - if( $this->y2lines != null && $this->y2scale != null ) { - for($i=0; $i < count($this->y2lines); ++$i) { - $this->y2lines[$i]->Stroke($this->img,$this->xscale,$this->y2scale); - $this->y2lines[$i]->DoLegend($this); - } - } + if( $this->y2lines != null && $this->y2scale != null ) { + for($i=0; $i < count($this->y2lines); ++$i) { + $this->y2lines[$i]->Stroke($this->img,$this->xscale,$this->y2scale); + $this->y2lines[$i]->DoLegend($this); + } + } - // Finally draw the axis again since some plots may have nagged - // the axis in the edges. - if( !$_csim ) { - $this->StrokeAxis(); - } + // Finally draw the axis again since some plots may have nagged + // the axis in the edges. + if( !$_csim ) { + $this->StrokeAxis(); + } - if( $this->y2scale != null && !$_csim ) - $this->y2axis->Stroke($this->xscale,false); - - if( !$_csim ) { - $this->StrokePlotBox(); - } - - // The titles and legends never gets rotated so make sure - // that the angle is 0 before stroking them - $aa = $this->img->SetAngle(0); - $this->StrokeTitles(); - $this->footer->Stroke($this->img); - $this->legend->Stroke($this->img); - $this->img->SetAngle($aa); - $this->StrokeTexts(); - $this->StrokeTables(); + if( $this->y2scale != null && !$_csim ) { + $this->y2axis->Stroke($this->xscale,false); + } - if( !$_csim ) { + if( !$_csim ) { + $this->StrokePlotBox(); + } - $this->img->SetAngle($aa); - - // Draw an outline around the image map - if(_JPG_DEBUG) { - $this->DisplayClientSideaImageMapAreas(); - } - - // Should we do any final image transformation - if( $this->iImgTrans ) { - if( !class_exists('ImgTrans',false) ) { - require_once('jpgraph_imgtrans.php'); - //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.'); - } - - $tform = new ImgTrans($this->img->img); - $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist, - $this->iImgTransDirection,$this->iImgTransHighQ, - $this->iImgTransMinSize,$this->iImgTransFillColor, - $this->iImgTransBorder); - } + // The titles and legends never gets rotated so make sure + // that the angle is 0 before stroking them + $aa = $this->img->SetAngle(0); + $this->StrokeTitles(); + $this->footer->Stroke($this->img); + $this->legend->Stroke($this->img); + $this->img->SetAngle($aa); + $this->StrokeTexts(); + $this->StrokeTables(); - // If the filename is given as the special "__handle" - // then the image handler is returned and the image is NOT - // streamed back - if( $aStrokeFileName == _IMG_HANDLER ) { - return $this->img->img; - } - else { - // Finally stream the generated picture - $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,$aStrokeFileName); - } - } + if( !$_csim ) { + + $this->img->SetAngle($aa); + + // Draw an outline around the image map + if(_JPG_DEBUG) { + $this->DisplayClientSideaImageMapAreas(); + } + + // Should we do any final image transformation + if( $this->iImgTrans ) { + if( !class_exists('ImgTrans',false) ) { + require_once('jpgraph_imgtrans.php'); + //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.'); + } + + $tform = new ImgTrans($this->img->img); + $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist, + $this->iImgTransDirection,$this->iImgTransHighQ, + $this->iImgTransMinSize,$this->iImgTransFillColor, + $this->iImgTransBorder); + } + + // If the filename is given as the special "__handle" + // then the image handler is returned and the image is NOT + // streamed back + if( $aStrokeFileName == _IMG_HANDLER ) { + return $this->img->img; + } + else { + // Finally stream the generated picture + $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,$aStrokeFileName); + } + } } function SetAxisLabelBackground($aType,$aXFColor='lightgray',$aXColor='black',$aYFColor='lightgray',$aYColor='black') { - $this->iAxisLblBgType = $aType; - $this->iXAxisLblBgFillColor = $aXFColor; - $this->iXAxisLblBgColor = $aXColor; - $this->iYAxisLblBgFillColor = $aYFColor; - $this->iYAxisLblBgColor = $aYColor; + $this->iAxisLblBgType = $aType; + $this->iXAxisLblBgFillColor = $aXFColor; + $this->iXAxisLblBgColor = $aXColor; + $this->iYAxisLblBgFillColor = $aYFColor; + $this->iYAxisLblBgColor = $aYColor; } -//--------------- -// PRIVATE METHODS - function StrokeAxisLabelBackground() { - // Types - // 0 = No background - // 1 = Only X-labels, length of axis - // 2 = Only Y-labels, length of axis - // 3 = As 1 but extends to width of graph - // 4 = As 2 but extends to height of graph - // 5 = Combination of 3 & 4 - // 6 = Combination of 1 & 2 - - $t = $this->iAxisLblBgType ; - if( $t < 1 ) return; - // Stroke optional X-axis label background color - if( $t == 1 || $t == 3 || $t == 5 || $t == 6 ) { - $this->img->PushColor($this->iXAxisLblBgFillColor); - if( $t == 1 || $t == 6 ) { - $xl = $this->img->left_margin; - $yu = $this->img->height - $this->img->bottom_margin + 1; - $xr = $this->img->width - $this->img->right_margin ; - $yl = $this->img->height-1-$this->frame_weight; - } - else { // t==3 || t==5 - $xl = $this->frame_weight; - $yu = $this->img->height - $this->img->bottom_margin + 1; - $xr = $this->img->width - 1 - $this->frame_weight; - $yl = $this->img->height-1-$this->frame_weight; - } + // Types + // 0 = No background + // 1 = Only X-labels, length of axis + // 2 = Only Y-labels, length of axis + // 3 = As 1 but extends to width of graph + // 4 = As 2 but extends to height of graph + // 5 = Combination of 3 & 4 + // 6 = Combination of 1 & 2 - $this->img->FilledRectangle($xl,$yu,$xr,$yl); - $this->img->PopColor(); + $t = $this->iAxisLblBgType ; + if( $t < 1 ) return; - // Check if we should add the vertical lines at left and right edge - if( $this->iXAxisLblBgColor !== '' ) { - $this->img->PushColor($this->iXAxisLblBgColor); - if( $t == 1 || $t == 6 ) { - $this->img->Line($xl,$yu,$xl,$yl); - $this->img->Line($xr,$yu,$xr,$yl); - } - else { - $xl = $this->img->width - $this->img->right_margin ; - $this->img->Line($xl,$yu-1,$xr,$yu-1); - } - $this->img->PopColor(); - } - } + // Stroke optional X-axis label background color + if( $t == 1 || $t == 3 || $t == 5 || $t == 6 ) { + $this->img->PushColor($this->iXAxisLblBgFillColor); + if( $t == 1 || $t == 6 ) { + $xl = $this->img->left_margin; + $yu = $this->img->height - $this->img->bottom_margin + 1; + $xr = $this->img->width - $this->img->right_margin ; + $yl = $this->img->height-1-$this->frame_weight; + } + else { // t==3 || t==5 + $xl = $this->frame_weight; + $yu = $this->img->height - $this->img->bottom_margin + 1; + $xr = $this->img->width - 1 - $this->frame_weight; + $yl = $this->img->height-1-$this->frame_weight; + } - if( $t == 2 || $t == 4 || $t == 5 || $t == 6 ) { - $this->img->PushColor($this->iYAxisLblBgFillColor); - if( $t == 2 || $t == 6 ) { - $xl = $this->frame_weight; - $yu = $this->frame_weight+$this->img->top_margin; - $xr = $this->img->left_margin - 1; - $yl = $this->img->height - $this->img->bottom_margin + 1; - } - else { - $xl = $this->frame_weight; - $yu = $this->frame_weight; - $xr = $this->img->left_margin - 1; - $yl = $this->img->height-1-$this->frame_weight; - } + $this->img->FilledRectangle($xl,$yu,$xr,$yl); + $this->img->PopColor(); - $this->img->FilledRectangle($xl,$yu,$xr,$yl); - $this->img->PopColor(); + // Check if we should add the vertical lines at left and right edge + if( $this->iXAxisLblBgColor !== '' ) { + // Hardcode to one pixel wide + $this->img->SetLineWeight(1); + $this->img->PushColor($this->iXAxisLblBgColor); + if( $t == 1 || $t == 6 ) { + $this->img->Line($xl,$yu,$xl,$yl); + $this->img->Line($xr,$yu,$xr,$yl); + } + else { + $xl = $this->img->width - $this->img->right_margin ; + $this->img->Line($xl,$yu-1,$xr,$yu-1); + } + $this->img->PopColor(); + } + } - // Check if we should add the vertical lines at left and right edge - if( $this->iXAxisLblBgColor !== '' ) { - $this->img->PushColor($this->iXAxisLblBgColor); - if( $t == 2 || $t == 6 ) { - $this->img->Line($xl,$yu-1,$xr,$yu-1); - $this->img->Line($xl,$yl-1,$xr,$yl-1); - } - else { - $this->img->Line($xr+1,$yu,$xr+1,$this->img->top_margin); - } - $this->img->PopColor(); - } + if( $t == 2 || $t == 4 || $t == 5 || $t == 6 ) { + $this->img->PushColor($this->iYAxisLblBgFillColor); + if( $t == 2 || $t == 6 ) { + $xl = $this->frame_weight; + $yu = $this->frame_weight+$this->img->top_margin; + $xr = $this->img->left_margin - 1; + $yl = $this->img->height - $this->img->bottom_margin + 1; + } + else { + $xl = $this->frame_weight; + $yu = $this->frame_weight; + $xr = $this->img->left_margin - 1; + $yl = $this->img->height-1-$this->frame_weight; + } - } + $this->img->FilledRectangle($xl,$yu,$xr,$yl); + $this->img->PopColor(); + + // Check if we should add the vertical lines at left and right edge + if( $this->iXAxisLblBgColor !== '' ) { + $this->img->PushColor($this->iXAxisLblBgColor); + if( $t == 2 || $t == 6 ) { + $this->img->Line($xl,$yu-1,$xr,$yu-1); + $this->img->Line($xl,$yl-1,$xr,$yl-1); + } + else { + $this->img->Line($xr+1,$yu,$xr+1,$this->img->top_margin); + } + $this->img->PopColor(); + } + + } } function StrokeAxis($aStrokeLabels=true) { - - if( $aStrokeLabels ) { - $this->StrokeAxisLabelBackground(); - } - // Stroke axis - if( $this->iAxisStyle != AXSTYLE_SIMPLE ) { - switch( $this->iAxisStyle ) { - case AXSTYLE_BOXIN : - $toppos = SIDE_DOWN; - $bottompos = SIDE_UP; - $leftpos = SIDE_RIGHT; - $rightpos = SIDE_LEFT; - break; - case AXSTYLE_BOXOUT : - $toppos = SIDE_UP; - $bottompos = SIDE_DOWN; - $leftpos = SIDE_LEFT; - $rightpos = SIDE_RIGHT; - break; - case AXSTYLE_YBOXIN: - $toppos = FALSE; - $bottompos = SIDE_UP; - $leftpos = SIDE_RIGHT; - $rightpos = SIDE_LEFT; - break; - case AXSTYLE_YBOXOUT: - $toppos = FALSE; - $bottompos = SIDE_DOWN; - $leftpos = SIDE_LEFT; - $rightpos = SIDE_RIGHT; - break; - default: - JpGRaphError::RaiseL(25036,$this->iAxisStyle); //('Unknown AxisStyle() : '.$this->iAxisStyle); - break; - } - - // By default we hide the first label so it doesn't cross the - // Y-axis in case the positon hasn't been set by the user. - // However, if we use a box we always want the first value - // displayed so we make sure it will be displayed. - $this->xscale->ticks->SupressFirst(false); + if( $aStrokeLabels ) { + $this->StrokeAxisLabelBackground(); + } - // Now draw the bottom X-axis - $this->xaxis->SetPos('min'); - $this->xaxis->SetLabelSide(SIDE_DOWN); - $this->xaxis->scale->ticks->SetSide($bottompos); - $this->xaxis->Stroke($this->yscale,$aStrokeLabels); + // Stroke axis + if( $this->iAxisStyle != AXSTYLE_SIMPLE ) { + switch( $this->iAxisStyle ) { + case AXSTYLE_BOXIN : + $toppos = SIDE_DOWN; + $bottompos = SIDE_UP; + $leftpos = SIDE_RIGHT; + $rightpos = SIDE_LEFT; + break; + case AXSTYLE_BOXOUT : + $toppos = SIDE_UP; + $bottompos = SIDE_DOWN; + $leftpos = SIDE_LEFT; + $rightpos = SIDE_RIGHT; + break; + case AXSTYLE_YBOXIN: + $toppos = FALSE; + $bottompos = SIDE_UP; + $leftpos = SIDE_RIGHT; + $rightpos = SIDE_LEFT; + break; + case AXSTYLE_YBOXOUT: + $toppos = FALSE; + $bottompos = SIDE_DOWN; + $leftpos = SIDE_LEFT; + $rightpos = SIDE_RIGHT; + break; + default: + JpGRaphError::RaiseL(25036,$this->iAxisStyle); //('Unknown AxisStyle() : '.$this->iAxisStyle); + break; + } - if( $toppos !== FALSE ) { - // We also want a top X-axis - $this->xaxis = $this->xaxis; - $this->xaxis->SetPos('max'); - $this->xaxis->SetLabelSide(SIDE_UP); - // No title for the top X-axis - if( $aStrokeLabels ) { - $this->xaxis->title->Set(''); - } - $this->xaxis->scale->ticks->SetSide($toppos); - $this->xaxis->Stroke($this->yscale,$aStrokeLabels); - } + // By default we hide the first label so it doesn't cross the + // Y-axis in case the positon hasn't been set by the user. + // However, if we use a box we always want the first value + // displayed so we make sure it will be displayed. + $this->xscale->ticks->SupressFirst(false); - // Stroke the left Y-axis - $this->yaxis->SetPos('min'); - $this->yaxis->SetLabelSide(SIDE_LEFT); - $this->yaxis->scale->ticks->SetSide($leftpos); - $this->yaxis->Stroke($this->xscale,$aStrokeLabels); + // Now draw the bottom X-axis + $this->xaxis->SetPos('min'); + $this->xaxis->SetLabelSide(SIDE_DOWN); + $this->xaxis->scale->ticks->SetSide($bottompos); + $this->xaxis->Stroke($this->yscale,$aStrokeLabels); - // Stroke the right Y-axis - $this->yaxis->SetPos('max'); - // No title for the right side - if( $aStrokeLabels ) { - $this->yaxis->title->Set(''); - } - $this->yaxis->SetLabelSide(SIDE_RIGHT); - $this->yaxis->scale->ticks->SetSide($rightpos); - $this->yaxis->Stroke($this->xscale,$aStrokeLabels); - } - else { - $this->xaxis->Stroke($this->yscale,$aStrokeLabels); - $this->yaxis->Stroke($this->xscale,$aStrokeLabels); - } + if( $toppos !== FALSE ) { + // We also want a top X-axis + $this->xaxis = $this->xaxis; + $this->xaxis->SetPos('max'); + $this->xaxis->SetLabelSide(SIDE_UP); + // No title for the top X-axis + if( $aStrokeLabels ) { + $this->xaxis->title->Set(''); + } + $this->xaxis->scale->ticks->SetSide($toppos); + $this->xaxis->Stroke($this->yscale,$aStrokeLabels); + } + + // Stroke the left Y-axis + $this->yaxis->SetPos('min'); + $this->yaxis->SetLabelSide(SIDE_LEFT); + $this->yaxis->scale->ticks->SetSide($leftpos); + $this->yaxis->Stroke($this->xscale,$aStrokeLabels); + + // Stroke the right Y-axis + $this->yaxis->SetPos('max'); + // No title for the right side + if( $aStrokeLabels ) { + $this->yaxis->title->Set(''); + } + $this->yaxis->SetLabelSide(SIDE_RIGHT); + $this->yaxis->scale->ticks->SetSide($rightpos); + $this->yaxis->Stroke($this->xscale,$aStrokeLabels); + } + else { + $this->xaxis->Stroke($this->yscale,$aStrokeLabels); + $this->yaxis->Stroke($this->xscale,$aStrokeLabels); + } } // Private helper function for backgound image static function LoadBkgImage($aImgFormat='',$aFile='',$aImgStr='') { - if( $aImgStr != '' ) { - return Image::CreateFromString($aImgStr); - } + if( $aImgStr != '' ) { + return Image::CreateFromString($aImgStr); + } - // Remove case sensitivity and setup appropriate function to create image - // Get file extension. This should be the LAST '.' separated part of the filename - $e = explode('.',$aFile); - $ext = strtolower($e[count($e)-1]); - if ($ext == "jpeg") { - $ext = "jpg"; - } - - if( trim($ext) == '' ) - $ext = 'png'; // Assume PNG if no extension specified + // Remove case sensitivity and setup appropriate function to create image + // Get file extension. This should be the LAST '.' separated part of the filename + $e = explode('.',$aFile); + $ext = strtolower($e[count($e)-1]); + if ($ext == "jpeg") { + $ext = "jpg"; + } - if( $aImgFormat == '' ) - $imgtag = $ext; - else - $imgtag = $aImgFormat; + if( trim($ext) == '' ) { + $ext = 'png'; // Assume PNG if no extension specified + } - $supported = imagetypes(); - if( ( $ext == 'jpg' && !($supported & IMG_JPG) ) || - ( $ext == 'gif' && !($supported & IMG_GIF) ) || - ( $ext == 'png' && !($supported & IMG_PNG) ) || - ( $ext == 'bmp' && !($supported & IMG_WBMP) ) || - ( $ext == 'xpm' && !($supported & IMG_XPM) ) ) { + if( $aImgFormat == '' ) { + $imgtag = $ext; + } + else { + $imgtag = $aImgFormat; + } - JpGraphError::RaiseL(25037,$aFile);//('The image format of your background image ('.$aFile.') is not supported in your system configuration. '); - } + $supported = imagetypes(); + if( ( $ext == 'jpg' && !($supported & IMG_JPG) ) || + ( $ext == 'gif' && !($supported & IMG_GIF) ) || + ( $ext == 'png' && !($supported & IMG_PNG) ) || + ( $ext == 'bmp' && !($supported & IMG_WBMP) ) || + ( $ext == 'xpm' && !($supported & IMG_XPM) ) ) { + + JpGraphError::RaiseL(25037,$aFile);//('The image format of your background image ('.$aFile.') is not supported in your system configuration. '); + } - if( $imgtag == "jpg" || $imgtag == "jpeg") - { - $f = "imagecreatefromjpeg"; - $imgtag = "jpg"; - } - else - { - $f = "imagecreatefrom".$imgtag; - } + if( $imgtag == "jpg" || $imgtag == "jpeg") { + $f = "imagecreatefromjpeg"; + $imgtag = "jpg"; + } + else { + $f = "imagecreatefrom".$imgtag; + } - // Compare specified image type and file extension - if( $imgtag != $ext ) { - //$t = "Background image seems to be of different type (has different file extension) than specified imagetype. Specified: '".$aImgFormat."'File: '".$aFile."'"; - JpGraphError::RaiseL(25038, $aImgFormat, $aFile); - } + // Compare specified image type and file extension + if( $imgtag != $ext ) { + //$t = "Background image seems to be of different type (has different file extension) than specified imagetype. Specified: '".$aImgFormat."'File: '".$aFile."'"; + JpGraphError::RaiseL(25038, $aImgFormat, $aFile); + } - $img = @$f($aFile); - if( !$img ) { - JpGraphError::RaiseL(25039,$aFile);//(" Can't read background image: '".$aFile."'"); - } - return $img; - } + $img = @$f($aFile); + if( !$img ) { + JpGraphError::RaiseL(25039,$aFile);//(" Can't read background image: '".$aFile."'"); + } + return $img; + } function StrokeBackgroundGrad() { - if( $this->bkg_gradtype < 0 ) - return; - $grad = new Gradient($this->img); - if( $this->bkg_gradstyle == BGRAD_PLOT ) { - $xl = $this->img->left_margin; - $yt = $this->img->top_margin; - $xr = $xl + $this->img->plotwidth+1 ; - $yb = $yt + $this->img->plotheight ; - $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype); - } - else { - $xl = 0; - $yt = 0; - $xr = $xl + $this->img->width - 1; - $yb = $yt + $this->img->height ; - if( $this->doshadow ) { - $xr -= $this->shadow_width; - $yb -= $this->shadow_width; - } - if( $this->doframe ) { - $yt += $this->frame_weight; - $yb -= $this->frame_weight; - $xl += $this->frame_weight; - $xr -= $this->frame_weight; - } - $aa = $this->img->SetAngle(0); - $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype); - $aa = $this->img->SetAngle($aa); - } + if( $this->bkg_gradtype < 0 ) + return; + + $grad = new Gradient($this->img); + if( $this->bkg_gradstyle == BGRAD_PLOT ) { + $xl = $this->img->left_margin; + $yt = $this->img->top_margin; + $xr = $xl + $this->img->plotwidth+1 ; + $yb = $yt + $this->img->plotheight ; + $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype); + } + else { + $xl = 0; + $yt = 0; + $xr = $xl + $this->img->width - 1; + $yb = $yt + $this->img->height - 1 ; + if( $this->doshadow ) { + $xr -= $this->shadow_width; + $yb -= $this->shadow_width; + } + if( $this->doframe ) { + $yt += $this->frame_weight; + $yb -= $this->frame_weight; + $xl += $this->frame_weight; + $xr -= $this->frame_weight; + } + $aa = $this->img->SetAngle(0); + $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype); + $aa = $this->img->SetAngle($aa); + } } function StrokeFrameBackground() { - if( $this->background_image != "" && $this->background_cflag != "" ) { - JpGraphError::RaiseL(25040);//('It is not possible to specify both a background image and a background country flag.'); - } - if( $this->background_image != "" ) { - $bkgimg = $this->LoadBkgImage($this->background_image_format,$this->background_image); - } - elseif( $this->background_cflag != "" ) { - if( ! class_exists('FlagImages',false) ) { - JpGraphError::RaiseL(25041);//('In order to use Country flags as backgrounds you must include the "jpgraph_flags.php" file.'); - } - $fobj = new FlagImages(FLAGSIZE4); - $dummy=''; - $bkgimg = $fobj->GetImgByName($this->background_cflag,$dummy); - $this->background_image_mix = $this->background_cflag_mix; - $this->background_image_type = $this->background_cflag_type; - } - else { - return ; - } + if( $this->background_image != '' && $this->background_cflag != '' ) { + JpGraphError::RaiseL(25040);//('It is not possible to specify both a background image and a background country flag.'); + } + if( $this->background_image != '' ) { + $bkgimg = $this->LoadBkgImage($this->background_image_format,$this->background_image); + } + elseif( $this->background_cflag != '' ) { + if( ! class_exists('FlagImages',false) ) { + JpGraphError::RaiseL(25041);//('In order to use Country flags as backgrounds you must include the "jpgraph_flags.php" file.'); + } + $fobj = new FlagImages(FLAGSIZE4); + $dummy=''; + $bkgimg = $fobj->GetImgByName($this->background_cflag,$dummy); + $this->background_image_mix = $this->background_cflag_mix; + $this->background_image_type = $this->background_cflag_type; + } + else { + return ; + } - $bw = ImageSX($bkgimg); - $bh = ImageSY($bkgimg); + $bw = ImageSX($bkgimg); + $bh = ImageSY($bkgimg); - // No matter what the angle is we always stroke the image and frame - // assuming it is 0 degree - $aa = $this->img->SetAngle(0); - - switch( $this->background_image_type ) { - case BGIMG_FILLPLOT: // Resize to just fill the plotarea - $this->FillMarginArea(); - $this->StrokeFrame(); - // Special case to hande 90 degree rotated graph corectly - if( $aa == 90 ) { - $this->img->SetAngle(90); - $this->FillPlotArea(); - $aa = $this->img->SetAngle(0); - $adj = ($this->img->height - $this->img->width)/2; - $this->img->CopyMerge($bkgimg, - $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, - 0,0, - $this->img->plotheight+1,$this->img->plotwidth, - $bw,$bh,$this->background_image_mix); + // No matter what the angle is we always stroke the image and frame + // assuming it is 0 degree + $aa = $this->img->SetAngle(0); - } - else { - $this->FillPlotArea(); - $this->img->CopyMerge($bkgimg, - $this->img->left_margin,$this->img->top_margin, - 0,0,$this->img->plotwidth+1,$this->img->plotheight, - $bw,$bh,$this->background_image_mix); - } - break; - case BGIMG_FILLFRAME: // Fill the whole area from upper left corner, resize to just fit - $hadj=0; $vadj=0; - if( $this->doshadow ) { - $hadj = $this->shadow_width; - $vadj = $this->shadow_width; - } - $this->FillMarginArea(); - $this->FillPlotArea(); - $this->img->CopyMerge($bkgimg,0,0,0,0,$this->img->width-$hadj,$this->img->height-$vadj, - $bw,$bh,$this->background_image_mix); - $this->StrokeFrame(); - break; - case BGIMG_COPY: // Just copy the image from left corner, no resizing - $this->FillMarginArea(); - $this->FillPlotArea(); - $this->img->CopyMerge($bkgimg,0,0,0,0,$bw,$bh, - $bw,$bh,$this->background_image_mix); - $this->StrokeFrame(); - break; - case BGIMG_CENTER: // Center original image in the plot area - $this->FillMarginArea(); - $this->FillPlotArea(); - $centerx = round($this->img->plotwidth/2+$this->img->left_margin-$bw/2); - $centery = round($this->img->plotheight/2+$this->img->top_margin-$bh/2); - $this->img->CopyMerge($bkgimg,$centerx,$centery,0,0,$bw,$bh, - $bw,$bh,$this->background_image_mix); - $this->StrokeFrame(); - break; - default: - JpGraphError::RaiseL(25042);//(" Unknown background image layout"); - } - $this->img->SetAngle($aa); + switch( $this->background_image_type ) { + case BGIMG_FILLPLOT: // Resize to just fill the plotarea + $this->FillMarginArea(); + $this->StrokeFrame(); + // Special case to hande 90 degree rotated graph corectly + if( $aa == 90 ) { + $this->img->SetAngle(90); + $this->FillPlotArea(); + $aa = $this->img->SetAngle(0); + $adj = ($this->img->height - $this->img->width)/2; + $this->img->CopyMerge($bkgimg, + $this->img->bottom_margin-$adj,$this->img->left_margin+$adj, + 0,0, + $this->img->plotheight+1,$this->img->plotwidth, + $bw,$bh,$this->background_image_mix); + } + else { + $this->FillPlotArea(); + $this->img->CopyMerge($bkgimg, + $this->img->left_margin,$this->img->top_margin+1, + 0,0,$this->img->plotwidth+1,$this->img->plotheight, + $bw,$bh,$this->background_image_mix); + } + break; + case BGIMG_FILLFRAME: // Fill the whole area from upper left corner, resize to just fit + $hadj=0; $vadj=0; + if( $this->doshadow ) { + $hadj = $this->shadow_width; + $vadj = $this->shadow_width; + } + $this->FillMarginArea(); + $this->FillPlotArea(); + $this->img->CopyMerge($bkgimg,0,0,0,0,$this->img->width-$hadj,$this->img->height-$vadj, + $bw,$bh,$this->background_image_mix); + $this->StrokeFrame(); + break; + case BGIMG_COPY: // Just copy the image from left corner, no resizing + $this->FillMarginArea(); + $this->FillPlotArea(); + $this->img->CopyMerge($bkgimg,0,0,0,0,$bw,$bh, + $bw,$bh,$this->background_image_mix); + $this->StrokeFrame(); + break; + case BGIMG_CENTER: // Center original image in the plot area + $this->FillMarginArea(); + $this->FillPlotArea(); + $centerx = round($this->img->plotwidth/2+$this->img->left_margin-$bw/2); + $centery = round($this->img->plotheight/2+$this->img->top_margin-$bh/2); + $this->img->CopyMerge($bkgimg,$centerx,$centery,0,0,$bw,$bh, + $bw,$bh,$this->background_image_mix); + $this->StrokeFrame(); + break; + case BGIMG_FREE: // Just copy the image to the specified location + $this->img->CopyMerge($bkgimg, + $this->background_image_xpos,$this->background_image_ypos, + 0,0,$bw,$bh,$bw,$bh,$this->background_image_mix); + $this->StrokeFrame(); // New + break; + default: + JpGraphError::RaiseL(25042);//(" Unknown background image layout"); + } + $this->img->SetAngle($aa); } // Private // Draw a frame around the image function StrokeFrame() { - if( !$this->doframe ) return; + if( !$this->doframe ) return; - if( $this->background_image_type <= 1 && - ($this->bkg_gradtype < 0 || ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_PLOT)) ) { - $c = $this->margin_color; - } - else { - $c = false; - } - - if( $this->doshadow ) { - $this->img->SetColor($this->frame_color); - $this->img->ShadowRectangle(0,0,$this->img->width,$this->img->height, - $c,$this->shadow_width,$this->shadow_color); - } - elseif( $this->framebevel ) { - if( $c ) { - $this->img->SetColor($this->margin_color); - $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1); - } - $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2, - $this->framebeveldepth, - $this->framebevelcolor1,$this->framebevelcolor2); - if( $this->framebevelborder ) { - $this->img->SetColor($this->framebevelbordercolor); - $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); - } - } - else { - $this->img->SetLineWeight($this->frame_weight); - if( $c ) { - $this->img->SetColor($this->margin_color); - $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1); - } - $this->img->SetColor($this->frame_color); - $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); - } + if( $this->background_image_type <= 1 && ($this->bkg_gradtype < 0 || ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_PLOT)) ) { + $c = $this->margin_color; + } + else { + $c = false; + } + + if( $this->doshadow ) { + $this->img->SetColor($this->frame_color); + $this->img->ShadowRectangle(0,0,$this->img->width,$this->img->height, + $c,$this->shadow_width,$this->shadow_color); + } + elseif( $this->framebevel ) { + if( $c ) { + $this->img->SetColor($this->margin_color); + $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1); + } + $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2, + $this->framebeveldepth, + $this->framebevelcolor1,$this->framebevelcolor2); + if( $this->framebevelborder ) { + $this->img->SetColor($this->framebevelbordercolor); + $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); + } + } + else { + $this->img->SetLineWeight($this->frame_weight); + if( $c ) { + $this->img->SetColor($this->margin_color); + $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1); + } + $this->img->SetColor($this->frame_color); + $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); + } } function FillMarginArea() { - $hadj=0; $vadj=0; - if( $this->doshadow ) { - $hadj = $this->shadow_width; - $vadj = $this->shadow_width; - } + $hadj=0; $vadj=0; + if( $this->doshadow ) { + $hadj = $this->shadow_width; + $vadj = $this->shadow_width; + } - $this->img->SetColor($this->margin_color); -// $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->height-1-$vadj); + $this->img->SetColor($this->margin_color); + // $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->height-1-$vadj); - $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->top_margin); - $this->img->FilledRectangle(0,$this->img->top_margin,$this->img->left_margin,$this->img->height-1-$hadj); - $this->img->FilledRectangle($this->img->left_margin+1, - $this->img->height-$this->img->bottom_margin, - $this->img->width-1-$hadj, - $this->img->height-1-$hadj); - $this->img->FilledRectangle($this->img->width-$this->img->right_margin, - $this->img->top_margin+1, - $this->img->width-1-$hadj, - $this->img->height-$this->img->bottom_margin-1); + $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->top_margin); + $this->img->FilledRectangle(0,$this->img->top_margin,$this->img->left_margin,$this->img->height-1-$hadj); + $this->img->FilledRectangle($this->img->left_margin+1, + $this->img->height-$this->img->bottom_margin, + $this->img->width-1-$hadj, + $this->img->height-1-$hadj); + $this->img->FilledRectangle($this->img->width-$this->img->right_margin, + $this->img->top_margin+1, + $this->img->width-1-$hadj, + $this->img->height-$this->img->bottom_margin-1); } function FillPlotArea() { - $this->img->PushColor($this->plotarea_color); - $this->img->FilledRectangle($this->img->left_margin, - $this->img->top_margin, - $this->img->width-$this->img->right_margin, - $this->img->height-$this->img->bottom_margin); - $this->img->PopColor(); + $this->img->PushColor($this->plotarea_color); + $this->img->FilledRectangle($this->img->left_margin, + $this->img->top_margin, + $this->img->width-$this->img->right_margin, + $this->img->height-$this->img->bottom_margin); + $this->img->PopColor(); } - + // Stroke the plot area with either a solid color or a background image function StrokePlotArea() { - // Note: To be consistent we really should take a possible shadow - // into account. However, that causes some problem for the LinearScale class - // since in the current design it does not have any links to class Graph which - // means it has no way of compensating for the adjusted plotarea in case of a - // shadow. So, until I redesign LinearScale we can't compensate for this. - // So just set the two adjustment parameters to zero for now. - $boxadj = 0; //$this->doframe ? $this->frame_weight : 0 ; - $adj = 0; //$this->doshadow ? $this->shadow_width : 0 ; + // Note: To be consistent we really should take a possible shadow + // into account. However, that causes some problem for the LinearScale class + // since in the current design it does not have any links to class Graph which + // means it has no way of compensating for the adjusted plotarea in case of a + // shadow. So, until I redesign LinearScale we can't compensate for this. + // So just set the two adjustment parameters to zero for now. + $boxadj = 0; //$this->doframe ? $this->frame_weight : 0 ; + $adj = 0; //$this->doshadow ? $this->shadow_width : 0 ; - if( $this->background_image != "" || $this->background_cflag != "" ) { - $this->StrokeFrameBackground(); - } - else { - $aa = $this->img->SetAngle(0); - $this->StrokeFrame(); - $aa = $this->img->SetAngle($aa); - $this->StrokeBackgroundGrad(); - if( $this->bkg_gradtype < 0 || - ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_MARGIN) ) { - $this->FillPlotArea(); - } - } - } + if( $this->background_image != '' || $this->background_cflag != '' ) { + $this->StrokeFrameBackground(); + } + else { + $aa = $this->img->SetAngle(0); + $this->StrokeFrame(); + $aa = $this->img->SetAngle($aa); + $this->StrokeBackgroundGrad(); + if( $this->bkg_gradtype < 0 || ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_MARGIN) ) { + $this->FillPlotArea(); + } + } + } function StrokeIcons() { - $n = count($this->iIcons); - for( $i=0; $i < $n; ++$i ) { - $this->iIcons[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); - } + $n = count($this->iIcons); + for( $i=0; $i < $n; ++$i ) { + $this->iIcons[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); + } } - + function StrokePlotBox() { - // Should we draw a box around the plot area? - if( $this->boxed ) { - $this->img->SetLineWeight(1); - $this->img->SetLineStyle('solid'); - $this->img->SetColor($this->box_color); - for($i=0; $i < $this->box_weight; ++$i ) { - $this->img->Rectangle( - $this->img->left_margin-$i,$this->img->top_margin-$i, - $this->img->width-$this->img->right_margin+$i, - $this->img->height-$this->img->bottom_margin+$i); - } - } - } + // Should we draw a box around the plot area? + if( $this->boxed ) { + $this->img->SetLineWeight(1); + $this->img->SetLineStyle('solid'); + $this->img->SetColor($this->box_color); + for($i=0; $i < $this->box_weight; ++$i ) { + $this->img->Rectangle( + $this->img->left_margin-$i,$this->img->top_margin-$i, + $this->img->width-$this->img->right_margin+$i, + $this->img->height-$this->img->bottom_margin+$i); + } + } + } function SetTitleBackgroundFillStyle($aStyle,$aColor1='black',$aColor2='white') { - $this->titlebkg_fillstyle = $aStyle; - $this->titlebkg_scolor1 = $aColor1; - $this->titlebkg_scolor2 = $aColor2; + $this->titlebkg_fillstyle = $aStyle; + $this->titlebkg_scolor1 = $aColor1; + $this->titlebkg_scolor2 = $aColor2; } function SetTitleBackground($aBackColor='gray', $aStyle=TITLEBKG_STYLE1, $aFrameStyle=TITLEBKG_FRAME_NONE, $aFrameColor='black', $aFrameWeight=1, $aBevelHeight=3, $aEnable=true) { - $this->titlebackground = $aEnable; - $this->titlebackground_color = $aBackColor; - $this->titlebackground_style = $aStyle; - $this->titlebackground_framecolor = $aFrameColor; - $this->titlebackground_framestyle = $aFrameStyle; - $this->titlebackground_frameweight = $aFrameWeight; - $this->titlebackground_bevelheight = $aBevelHeight ; + $this->titlebackground = $aEnable; + $this->titlebackground_color = $aBackColor; + $this->titlebackground_style = $aStyle; + $this->titlebackground_framecolor = $aFrameColor; + $this->titlebackground_framestyle = $aFrameStyle; + $this->titlebackground_frameweight = $aFrameWeight; + $this->titlebackground_bevelheight = $aBevelHeight ; } function StrokeTitles() { - $margin=3; + $margin=3; - if( $this->titlebackground ) { + if( $this->titlebackground ) { + // Find out height + $this->title->margin += 2 ; + $h = $this->title->GetTextHeight($this->img)+$this->title->margin+$margin; + if( $this->subtitle->t != '' && !$this->subtitle->hide ) { + $h += $this->subtitle->GetTextHeight($this->img)+$margin+ + $this->subtitle->margin; + $h += 2; + } + if( $this->subsubtitle->t != '' && !$this->subsubtitle->hide ) { + $h += $this->subsubtitle->GetTextHeight($this->img)+$margin+ + $this->subsubtitle->margin; + $h += 2; + } + $this->img->PushColor($this->titlebackground_color); + if( $this->titlebackground_style === TITLEBKG_STYLE1 ) { + // Inside the frame + if( $this->framebevel ) { + $x1 = $y1 = $this->framebeveldepth + 1 ; + $x2 = $this->img->width - $this->framebeveldepth - 2 ; + $this->title->margin += $this->framebeveldepth + 1 ; + $h += $y1 ; + $h += 2; + } + else { + $x1 = $y1 = $this->frame_weight; + $x2 = $this->img->width - $this->frame_weight-1; + } + } + elseif( $this->titlebackground_style === TITLEBKG_STYLE2 ) { + // Cover the frame as well + $x1 = $y1 = 0; + $x2 = $this->img->width - 1 ; + } + elseif( $this->titlebackground_style === TITLEBKG_STYLE3 ) { + // Cover the frame as well (the difference is that + // for style==3 a bevel frame border is on top + // of the title background) + $x1 = $y1 = 0; + $x2 = $this->img->width - 1 ; + $h += $this->framebeveldepth ; + $this->title->margin += $this->framebeveldepth ; + } + else { + JpGraphError::RaiseL(25043);//('Unknown title background style.'); + } - // Find out height - $this->title->margin += 2 ; - $h = $this->title->GetTextHeight($this->img)+$this->title->margin+$margin; - if( $this->subtitle->t != "" && !$this->subtitle->hide ) { - $h += $this->subtitle->GetTextHeight($this->img)+$margin+ - $this->subtitle->margin; - $h += 2; - } - if( $this->subsubtitle->t != "" && !$this->subsubtitle->hide ) { - $h += $this->subsubtitle->GetTextHeight($this->img)+$margin+ - $this->subsubtitle->margin; - $h += 2; - } - $this->img->PushColor($this->titlebackground_color); - if( $this->titlebackground_style === TITLEBKG_STYLE1 ) { - // Inside the frame - if( $this->framebevel ) { - $x1 = $y1 = $this->framebeveldepth + 1 ; - $x2 = $this->img->width - $this->framebeveldepth - 2 ; - $this->title->margin += $this->framebeveldepth + 1 ; - $h += $y1 ; - $h += 2; - } - else { - $x1 = $y1 = $this->frame_weight; - $x2 = $this->img->width - 2*$x1; - } - } - elseif( $this->titlebackground_style === TITLEBKG_STYLE2 ) { - // Cover the frame as well - $x1 = $y1 = 0; - $x2 = $this->img->width - 1 ; - } - elseif( $this->titlebackground_style === TITLEBKG_STYLE3 ) { - // Cover the frame as well (the difference is that - // for style==3 a bevel frame border is on top - // of the title background) - $x1 = $y1 = 0; - $x2 = $this->img->width - 1 ; - $h += $this->framebeveldepth ; - $this->title->margin += $this->framebeveldepth ; - } - else { - JpGraphError::RaiseL(25043);//('Unknown title background style.'); - } + if( $this->titlebackground_framestyle === 3 ) { + $h += $this->titlebackground_bevelheight*2 + 1 ; + $this->title->margin += $this->titlebackground_bevelheight ; + } - if( $this->titlebackground_framestyle === 3 ) { - $h += $this->titlebackground_bevelheight*2 + 1 ; - $this->title->margin += $this->titlebackground_bevelheight ; - } + if( $this->doshadow ) { + $x2 -= $this->shadow_width ; + } - if( $this->doshadow ) { - $x2 -= $this->shadow_width ; - } - - $indent=0; - if( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) { - $ind = $this->titlebackground_bevelheight; - } + $indent=0; + if( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) { + $indent = $this->titlebackground_bevelheight; + } - if( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_HSTRIPED ) { - $this->img->FilledRectangle2($x1+$ind,$y1+$ind,$x2-$ind,$h-$ind, - $this->titlebkg_scolor1, - $this->titlebkg_scolor2); - } - elseif( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_VSTRIPED ) { - $this->img->FilledRectangle2($x1+$ind,$y1+$ind,$x2-$ind,$h-$ind, - $this->titlebkg_scolor1, - $this->titlebkg_scolor2,2); - } - else { - // Solid fill - $this->img->FilledRectangle($x1,$y1,$x2,$h); - } - $this->img->PopColor(); + if( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_HSTRIPED ) { + $this->img->FilledRectangle2($x1+$indent,$y1+$indent,$x2-$indent,$h-$indent, + $this->titlebkg_scolor1, + $this->titlebkg_scolor2); + } + elseif( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_VSTRIPED ) { + $this->img->FilledRectangle2($x1+$indent,$y1+$indent,$x2-$indent,$h-$indent, + $this->titlebkg_scolor1, + $this->titlebkg_scolor2,2); + } + else { + // Solid fill + $this->img->FilledRectangle($x1,$y1,$x2,$h); + } + $this->img->PopColor(); - $this->img->PushColor($this->titlebackground_framecolor); - $this->img->SetLineWeight($this->titlebackground_frameweight); - if( $this->titlebackground_framestyle == TITLEBKG_FRAME_FULL ) { - // Frame background - $this->img->Rectangle($x1,$y1,$x2,$h); - } - elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BOTTOM ) { - // Bottom line only - $this->img->Line($x1,$h,$x2,$h); - } - elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) { - $this->img->Bevel($x1,$y1,$x2,$h,$this->titlebackground_bevelheight); - } - $this->img->PopColor(); + $this->img->PushColor($this->titlebackground_framecolor); + $this->img->SetLineWeight($this->titlebackground_frameweight); + if( $this->titlebackground_framestyle == TITLEBKG_FRAME_FULL ) { + // Frame background + $this->img->Rectangle($x1,$y1,$x2,$h); + } + elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BOTTOM ) { + // Bottom line only + $this->img->Line($x1,$h,$x2,$h); + } + elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) { + $this->img->Bevel($x1,$y1,$x2,$h,$this->titlebackground_bevelheight); + } + $this->img->PopColor(); - // This is clumsy. But we neeed to stroke the whole graph frame if it is - // set to bevel to get the bevel shading on top of the text background - if( $this->framebevel && $this->doframe && - $this->titlebackground_style === 3 ) { - $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2, - $this->framebeveldepth, - $this->framebevelcolor1,$this->framebevelcolor2); - if( $this->framebevelborder ) { - $this->img->SetColor($this->framebevelbordercolor); - $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); - } - } - } + // This is clumsy. But we neeed to stroke the whole graph frame if it is + // set to bevel to get the bevel shading on top of the text background + if( $this->framebevel && $this->doframe && $this->titlebackground_style === 3 ) { + $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2, + $this->framebeveldepth, + $this->framebevelcolor1,$this->framebevelcolor2); + if( $this->framebevelborder ) { + $this->img->SetColor($this->framebevelbordercolor); + $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1); + } + } + } - // Stroke title - $y = $this->title->margin; - if( $this->title->halign == 'center' ) - $this->title->Center(0,$this->img->width,$y); - elseif( $this->title->halign == 'left' ) { - $this->title->SetPos($this->title->margin+2,$y); - } - elseif( $this->title->halign == 'right' ) { - $indent = 0; - if( $this->doshadow ) - $indent = $this->shadow_width+2; - $this->title->SetPos($this->img->width-$this->title->margin-$indent,$y,'right'); - } - $this->title->Stroke($this->img); - - // ... and subtitle - $y += $this->title->GetTextHeight($this->img) + $margin + $this->subtitle->margin; - if( $this->subtitle->halign == 'center' ) - $this->subtitle->Center(0,$this->img->width,$y); - elseif( $this->subtitle->halign == 'left' ) { - $this->subtitle->SetPos($this->subtitle->margin+2,$y); - } - elseif( $this->subtitle->halign == 'right' ) { - $indent = 0; - if( $this->doshadow ) - $indent = $this->shadow_width+2; - $this->subtitle->SetPos($this->img->width-$this->subtitle->margin-$indent,$y,'right'); - } - $this->subtitle->Stroke($this->img); + // Stroke title + $y = $this->title->margin; + if( $this->title->halign == 'center' ) { + $this->title->Center(0,$this->img->width,$y); + } + elseif( $this->title->halign == 'left' ) { + $this->title->SetPos($this->title->margin+2,$y); + } + elseif( $this->title->halign == 'right' ) { + $indent = 0; + if( $this->doshadow ) { + $indent = $this->shadow_width+2; + } + $this->title->SetPos($this->img->width-$this->title->margin-$indent,$y,'right'); + } + $this->title->Stroke($this->img); - // ... and subsubtitle - $y += $this->subtitle->GetTextHeight($this->img) + $margin + $this->subsubtitle->margin; - if( $this->subsubtitle->halign == 'center' ) - $this->subsubtitle->Center(0,$this->img->width,$y); - elseif( $this->subsubtitle->halign == 'left' ) { - $this->subsubtitle->SetPos($this->subsubtitle->margin+2,$y); - } - elseif( $this->subsubtitle->halign == 'right' ) { - $indent = 0; - if( $this->doshadow ) - $indent = $this->shadow_width+2; - $this->subsubtitle->SetPos($this->img->width-$this->subsubtitle->margin-$indent,$y,'right'); - } - $this->subsubtitle->Stroke($this->img); + // ... and subtitle + $y += $this->title->GetTextHeight($this->img) + $margin + $this->subtitle->margin; + if( $this->subtitle->halign == 'center' ) { + $this->subtitle->Center(0,$this->img->width,$y); + } + elseif( $this->subtitle->halign == 'left' ) { + $this->subtitle->SetPos($this->subtitle->margin+2,$y); + } + elseif( $this->subtitle->halign == 'right' ) { + $indent = 0; + if( $this->doshadow ) + $indent = $this->shadow_width+2; + $this->subtitle->SetPos($this->img->width-$this->subtitle->margin-$indent,$y,'right'); + } + $this->subtitle->Stroke($this->img); - // ... and fancy title - $this->tabtitle->Stroke($this->img); + // ... and subsubtitle + $y += $this->subtitle->GetTextHeight($this->img) + $margin + $this->subsubtitle->margin; + if( $this->subsubtitle->halign == 'center' ) { + $this->subsubtitle->Center(0,$this->img->width,$y); + } + elseif( $this->subsubtitle->halign == 'left' ) { + $this->subsubtitle->SetPos($this->subsubtitle->margin+2,$y); + } + elseif( $this->subsubtitle->halign == 'right' ) { + $indent = 0; + if( $this->doshadow ) + $indent = $this->shadow_width+2; + $this->subsubtitle->SetPos($this->img->width-$this->subsubtitle->margin-$indent,$y,'right'); + } + $this->subsubtitle->Stroke($this->img); + + // ... and fancy title + $this->tabtitle->Stroke($this->img); } function StrokeTexts() { - // Stroke any user added text objects - if( $this->texts != null ) { - for($i=0; $i < count($this->texts); ++$i) { - $this->texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); - } - } + // Stroke any user added text objects + if( $this->texts != null ) { + for($i=0; $i < count($this->texts); ++$i) { + $this->texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); + } + } - if( $this->y2texts != null && $this->y2scale != null ) { - for($i=0; $i < count($this->y2texts); ++$i) { - $this->y2texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->y2scale); - } - } + if( $this->y2texts != null && $this->y2scale != null ) { + for($i=0; $i < count($this->y2texts); ++$i) { + $this->y2texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->y2scale); + } + } } function StrokeTables() { - if( $this->iTables != null ) { - $n = count($this->iTables); - for( $i=0; $i < $n; ++$i ) { - $this->iTables[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); - } - } + if( $this->iTables != null ) { + $n = count($this->iTables); + for( $i=0; $i < $n; ++$i ) { + $this->iTables[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale); + } + } } function DisplayClientSideaImageMapAreas() { - // Debug stuff - display the outline of the image map areas - $csim=''; - foreach ($this->plots as $p) { - $csim.= $p->GetCSIMareas(); - } - $csim .= $this->legend->GetCSIMareas(); - if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) { - $this->img->SetColor($this->csimcolor); - $n = count($coords[0]); - for ($i=0; $i < $n; $i++) { - if ($coords[1][$i]=="poly") { - preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts); - $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]); - $m = count($pts[0]); - for ($j=0; $j < $m; $j++) { - $this->img->LineTo($pts[1][$j],$pts[2][$j]); - } - } else if ($coords[1][$i]=="rect") { - $pts = preg_split('/,/', $coords[2][$i]); - $this->img->SetStartPoint($pts[0],$pts[1]); - $this->img->LineTo($pts[2],$pts[1]); - $this->img->LineTo($pts[2],$pts[3]); - $this->img->LineTo($pts[0],$pts[3]); - $this->img->LineTo($pts[0],$pts[1]); - } - } - } + // Debug stuff - display the outline of the image map areas + $csim=''; + foreach ($this->plots as $p) { + $csim.= $p->GetCSIMareas(); + } + $csim .= $this->legend->GetCSIMareas(); + if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) { + $this->img->SetColor($this->csimcolor); + $n = count($coords[0]); + for ($i=0; $i < $n; $i++) { + if ( $coords[1][$i] == 'poly' ) { + preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts); + $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]); + $m = count($pts[0]); + for ($j=0; $j < $m; $j++) { + $this->img->LineTo($pts[1][$j],$pts[2][$j]); + } + } elseif ( $coords[1][$i] == 'rect' ) { + $pts = preg_split('/,/', $coords[2][$i]); + $this->img->SetStartPoint($pts[0],$pts[1]); + $this->img->LineTo($pts[2],$pts[1]); + $this->img->LineTo($pts[2],$pts[3]); + $this->img->LineTo($pts[0],$pts[3]); + $this->img->LineTo($pts[0],$pts[1]); + } + } + } } // Text scale offset in world coordinates function SetTextScaleOff($aOff) { - $this->text_scale_off = $aOff; - $this->xscale->text_scale_off = $aOff; + $this->text_scale_off = $aOff; + $this->xscale->text_scale_off = $aOff; } // Text width of bar to be centered in absolute pixels function SetTextScaleAbsCenterOff($aOff) { - $this->text_scale_abscenteroff = $aOff; + $this->text_scale_abscenteroff = $aOff; } // Get Y min and max values for added lines function GetLinesYMinMax( $aLines ) { - $n = count($aLines); - if( $n == 0 ) return false; - $min = $aLines[0]->scaleposition ; - $max = $min ; - $flg = false; - for( $i=0; $i < $n; ++$i ) { - if( $aLines[$i]->direction == HORIZONTAL ) { - $flg = true ; - $v = $aLines[$i]->scaleposition ; - if( $min > $v ) $min = $v ; - if( $max < $v ) $max = $v ; - } - } - return $flg ? array($min,$max) : false ; + $n = count($aLines); + if( $n == 0 ) return false; + $min = $aLines[0]->scaleposition ; + $max = $min ; + $flg = false; + for( $i=0; $i < $n; ++$i ) { + if( $aLines[$i]->direction == HORIZONTAL ) { + $flg = true ; + $v = $aLines[$i]->scaleposition ; + if( $min > $v ) $min = $v ; + if( $max < $v ) $max = $v ; + } + } + return $flg ? array($min,$max) : false ; } // Get X min and max values for added lines function GetLinesXMinMax( $aLines ) { - $n = count($aLines); - if( $n == 0 ) return false ; - $min = $aLines[0]->scaleposition ; - $max = $min ; - $flg = false; - for( $i=0; $i < $n; ++$i ) { - if( $aLines[$i]->direction == VERTICAL ) { - $flg = true ; - $v = $aLines[$i]->scaleposition ; - if( $min > $v ) $min = $v ; - if( $max < $v ) $max = $v ; - } - } - return $flg ? array($min,$max) : false ; + $n = count($aLines); + if( $n == 0 ) return false ; + $min = $aLines[0]->scaleposition ; + $max = $min ; + $flg = false; + for( $i=0; $i < $n; ++$i ) { + if( $aLines[$i]->direction == VERTICAL ) { + $flg = true ; + $v = $aLines[$i]->scaleposition ; + if( $min > $v ) $min = $v ; + if( $max < $v ) $max = $v ; + } + } + return $flg ? array($min,$max) : false ; } // Get min and max values for all included plots function GetPlotsYMinMax($aPlots) { - $n = count($aPlots); - $i=0; - do { - list($xmax,$max) = $aPlots[$i]->Max(); - } while( ++$i < $n && !is_numeric($max) ); + $n = count($aPlots); + $i=0; + do { + list($xmax,$max) = $aPlots[$i]->Max(); + } while( ++$i < $n && !is_numeric($max) ); - $i=0; - do { - list($xmin,$min) = $aPlots[$i]->Min(); - } while( ++$i < $n && !is_numeric($min) ); - - if( !is_numeric($min) || !is_numeric($max) ) { - JpGraphError::RaiseL(25044);//('Cannot use autoscaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).'); - } + $i=0; + do { + list($xmin,$min) = $aPlots[$i]->Min(); + } while( ++$i < $n && !is_numeric($min) ); - for($i=0; $i < $n; ++$i ) { - list($xmax,$ymax)=$aPlots[$i]->Max(); - list($xmin,$ymin)=$aPlots[$i]->Min(); - if (is_numeric($ymax)) $max=max($max,$ymax); - if (is_numeric($ymin)) $min=min($min,$ymin); - } - if( $min == '' ) $min = 0; - if( $max == '' ) $max = 0; - if( $min == 0 && $max == 0 ) { - // Special case if all values are 0 - $min=0;$max=1; - } - return array($min,$max); + if( !is_numeric($min) || !is_numeric($max) ) { + JpGraphError::RaiseL(25044);//('Cannot use autoscaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).'); + } + + for($i=0; $i < $n; ++$i ) { + list($xmax,$ymax)=$aPlots[$i]->Max(); + list($xmin,$ymin)=$aPlots[$i]->Min(); + if (is_numeric($ymax)) $max=max($max,$ymax); + if (is_numeric($ymin)) $min=min($min,$ymin); + } + if( $min == '' ) $min = 0; + if( $max == '' ) $max = 0; + if( $min == 0 && $max == 0 ) { + // Special case if all values are 0 + $min=0;$max=1; + } + return array($min,$max); } } // Class @@ -2794,416 +2961,168 @@ class Graph { // Description: Holds properties for a line //=================================================== class LineProperty { - public $iWeight=1, $iColor="black",$iStyle="solid",$iShow=true; - -//--------------- -// PUBLIC METHODS - function SetColor($aColor) { - $this->iColor = $aColor; - } - - function SetWeight($aWeight) { - $this->iWeight = $aWeight; - } - - function SetStyle($aStyle) { - $this->iStyle = $aStyle; - } - - function Show($aShow=true) { - $this->iShow=$aShow; - } - - function Stroke($aImg,$aX1,$aY1,$aX2,$aY2) { - if( $this->iShow ) { - $aImg->PushColor($this->iColor); - $oldls = $aImg->line_style; - $oldlw = $aImg->line_weight; - $aImg->SetLineWeight($this->iWeight); - $aImg->SetLineStyle($this->iStyle); - $aImg->StyleLine($aX1,$aY1,$aX2,$aY2); - $aImg->PopColor($this->iColor); - $aImg->line_style = $oldls; - $aImg->line_weight = $oldlw; + public $iWeight=1, $iColor='black', $iStyle='solid', $iShow=true; - } + function __construct($aWeight=1,$aColor='black',$aStyle='solid') { + $this->iWeight = $aWeight; + $this->iColor = $aColor; + $this->iStyle = $aStyle; + } + + function SetColor($aColor) { + $this->iColor = $aColor; + } + + function SetWeight($aWeight) { + $this->iWeight = $aWeight; + } + + function SetStyle($aStyle) { + $this->iStyle = $aStyle; + } + + function Show($aShow=true) { + $this->iShow=$aShow; + } + + function Stroke($aImg,$aX1,$aY1,$aX2,$aY2) { + if( $this->iShow ) { + $aImg->PushColor($this->iColor); + $oldls = $aImg->line_style; + $oldlw = $aImg->line_weight; + $aImg->SetLineWeight($this->iWeight); + $aImg->SetLineStyle($this->iStyle); + $aImg->StyleLine($aX1,$aY1,$aX2,$aY2); + $aImg->PopColor($this->iColor); + $aImg->line_style = $oldls; + $aImg->line_weight = $oldlw; + + } } } - //=================================================== -// CLASS Text -// Description: Arbitrary text object that can be added to the graph +// CLASS GraphTabTitle +// Description: Draw "tab" titles on top of graphs //=================================================== -class Text { - public $t,$margin=0; - public $x=0,$y=0,$halign="left",$valign="top",$color=array(0,0,0); - public $hide=false, $dir=0; - public $iScalePosY=null,$iScalePosX=null; - public $iWordwrap=0; - public $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12; - protected $boxed=false; // Should the text be boxed - protected $paragraph_align="left"; - protected $icornerradius=0,$ishadowwidth=3; - protected $fcolor='white',$bcolor='black',$shadow=false; - protected $iCSIMarea='',$iCSIMalt='',$iCSIMtarget='',$iCSIMWinTarget=''; - -//--------------- -// CONSTRUCTOR - - // Create new text at absolute pixel coordinates - function Text($aTxt="",$aXAbsPos=0,$aYAbsPos=0) { - if( ! is_string($aTxt) ) { - JpGraphError::RaiseL(25050);//('First argument to Text::Text() must be s atring.'); - } - $this->t = $aTxt; - $this->x = round($aXAbsPos); - $this->y = round($aYAbsPos); - $this->margin = 0; - } -//--------------- -// PUBLIC METHODS - // Set the string in the text object - function Set($aTxt) { - $this->t = $aTxt; - } - - // Alias for Pos() - function SetPos($aXAbsPos=0,$aYAbsPos=0,$aHAlign="left",$aVAlign="top") { - //$this->Pos($aXAbsPos,$aYAbsPos,$aHAlign,$aVAlign); - $this->x = $aXAbsPos; - $this->y = $aYAbsPos; - $this->halign = $aHAlign; - $this->valign = $aVAlign; - } - - function SetScalePos($aX,$aY) { - $this->iScalePosX = $aX; - $this->iScalePosY = $aY; - } - - // Specify alignment for the text - function Align($aHAlign,$aVAlign="top",$aParagraphAlign="") { - $this->halign = $aHAlign; - $this->valign = $aVAlign; - if( $aParagraphAlign != "" ) - $this->paragraph_align = $aParagraphAlign; - } - - // Alias - function SetAlign($aHAlign,$aVAlign="top",$aParagraphAlign="") { - $this->Align($aHAlign,$aVAlign,$aParagraphAlign); - } - - // Specifies the alignment for a multi line text - function ParagraphAlign($aAlign) { - $this->paragraph_align = $aAlign; - } - - // Specifies the alignment for a multi line text - function SetParagraphAlign($aAlign) { - $this->paragraph_align = $aAlign; - } - - function SetShadow($aShadowColor='gray',$aShadowWidth=3) { - $this->ishadowwidth=$aShadowWidth; - $this->shadow=$aShadowColor; - $this->boxed=true; - } - - function SetWordWrap($aCol) { - $this->iWordwrap = $aCol ; - } - - // Specify that the text should be boxed. fcolor=frame color, bcolor=border color, - // $shadow=drop shadow should be added around the text. - function SetBox($aFrameColor=array(255,255,255),$aBorderColor=array(0,0,0),$aShadowColor=false,$aCornerRadius=4,$aShadowWidth=3) { - if( $aFrameColor==false ) - $this->boxed=false; - else - $this->boxed=true; - $this->fcolor=$aFrameColor; - $this->bcolor=$aBorderColor; - // For backwards compatibility when shadow was just true or false - if( $aShadowColor === true ) - $aShadowColor = 'gray'; - $this->shadow=$aShadowColor; - $this->icornerradius=$aCornerRadius; - $this->ishadowwidth=$aShadowWidth; - } - - // Hide the text - function Hide($aHide=true) { - $this->hide=$aHide; - } - - // This looks ugly since it's not a very orthogonal design - // but I added this "inverse" of Hide() to harmonize - // with some classes which I designed more recently (especially) - // jpgraph_gantt - function Show($aShow=true) { - $this->hide=!$aShow; - } - - // Specify font - function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) { - $this->font_family=$aFamily; - $this->font_style=$aStyle; - $this->font_size=$aSize; - } - - // Center the text between $left and $right coordinates - function Center($aLeft,$aRight,$aYAbsPos=false) { - $this->x = $aLeft + ($aRight-$aLeft )/2; - $this->halign = "center"; - if( is_numeric($aYAbsPos) ) - $this->y = $aYAbsPos; - } - - // Set text color - function SetColor($aColor) { - $this->color = $aColor; - } - - function SetAngle($aAngle) { - $this->SetOrientation($aAngle); - } - - // Orientation of text. Note only TTF fonts can have an arbitrary angle - function SetOrientation($aDirection=0) { - if( is_numeric($aDirection) ) - $this->dir=$aDirection; - elseif( $aDirection=="h" ) - $this->dir = 0; - elseif( $aDirection=="v" ) - $this->dir = 90; - else JpGraphError::RaiseL(25051);//(" Invalid direction specified for text."); - } - - // Total width of text - function GetWidth($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $w = $aImg->GetTextWidth($this->t,$this->dir); - return $w; - } - - // Hight of font - function GetFontHeight($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $h = $aImg->GetFontHeight(); - return $h; - - } - - function GetTextHeight($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $h = $aImg->GetTextHeight($this->t,$this->dir); - return $h; - } - - function GetHeight($aImg) { - // Synonym for GetTextHeight() - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $h = $aImg->GetTextHeight($this->t,$this->dir); - return $h; - } - - // Set the margin which will be interpretated differently depending - // on the context. - function SetMargin($aMarg) { - $this->margin = $aMarg; - } - - function StrokeWithScale($aImg,$axscale,$ayscale) { - if( $this->iScalePosX === null || - $this->iScalePosY === null ) { - $this->Stroke($aImg); - } - else { - $this->Stroke($aImg, - round($axscale->Translate($this->iScalePosX)), - round($ayscale->Translate($this->iScalePosY))); - } - } - - function SetCSIMTarget($aURITarget,$aAlt='',$aWinTarget='') { - $this->iCSIMtarget = $aURITarget; - $this->iCSIMalt = $aAlt; - $this->iCSIMWinTarget = $aWinTarget; - } - - function GetCSIMareas() { - if( $this->iCSIMtarget !== '' ) - return $this->iCSIMarea; - else - return ''; - } - - // Display text in image - function Stroke($aImg,$x=null,$y=null) { - - if( !empty($x) ) $this->x = round($x); - if( !empty($y) ) $this->y = round($y); - - // Insert newlines - if( $this->iWordwrap > 0 ) { - $this->t = wordwrap($this->t,$this->iWordwrap,"\n"); - } - - // If position been given as a fraction of the image size - // calculate the absolute position - if( $this->x < 1 && $this->x > 0 ) $this->x *= $aImg->width; - if( $this->y < 1 && $this->y > 0 ) $this->y *= $aImg->height; - - $aImg->PushColor($this->color); - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $aImg->SetTextAlign($this->halign,$this->valign); - if( $this->boxed ) { - if( $this->fcolor=="nofill" ) - $this->fcolor=false; - $aImg->SetLineWeight(1); - $bbox = $aImg->StrokeBoxedText($this->x,$this->y,$this->t, - $this->dir,$this->fcolor,$this->bcolor,$this->shadow, - $this->paragraph_align,5,5,$this->icornerradius, - $this->ishadowwidth); - } - else { - $bbox = $aImg->StrokeText($this->x,$this->y,$this->t,$this->dir,$this->paragraph_align); - } - - // Create CSIM targets - $coords = $bbox[0].','.$bbox[1].','.$bbox[2].','.$bbox[3].','.$bbox[4].','.$bbox[5].','.$bbox[6].','.$bbox[7]; - $this->iCSIMarea = "iCSIMtarget)."\" "; - if( trim($this->iCSIMalt) != '' ) { - $this->iCSIMarea .= " alt=\"".$this->iCSIMalt."\" "; - $this->iCSIMarea .= " title=\"".$this->iCSIMalt."\" "; - } - if( trim($this->iCSIMWinTarget) != '' ) { - $this->iCSIMarea .= " target=\"".$this->iCSIMWinTarget."\" "; - } - $this->iCSIMarea .= " />\n"; - - $aImg->PopColor($this->color); - - } -} // Class - class GraphTabTitle extends Text{ private $corner = 6 , $posx = 7, $posy = 4; private $fillcolor='lightyellow',$bordercolor='black'; private $align = 'left', $width=TABTITLE_WIDTHFIT; - function GraphTabTitle() { - $this->t = ''; - $this->font_style = FS_BOLD; - $this->hide = true; - $this->color = 'darkred'; + function __construct() { + $this->t = ''; + $this->font_style = FS_BOLD; + $this->hide = true; + $this->color = 'darkred'; } function SetColor($aTxtColor,$aFillColor='lightyellow',$aBorderColor='black') { - $this->color = $aTxtColor; - $this->fillcolor = $aFillColor; - $this->bordercolor = $aBorderColor; + $this->color = $aTxtColor; + $this->fillcolor = $aFillColor; + $this->bordercolor = $aBorderColor; } function SetFillColor($aFillColor) { - $this->fillcolor = $aFillColor; + $this->fillcolor = $aFillColor; } function SetTabAlign($aAlign) { - $this->align = $aAlign; + $this->align = $aAlign; } - + function SetWidth($aWidth) { - $this->width = $aWidth ; + $this->width = $aWidth ; } function Set($t) { - $this->t = $t; - $this->hide = false; + $this->t = $t; + $this->hide = false; } function SetCorner($aD) { - $this->corner = $aD ; + $this->corner = $aD ; } function Stroke($aImg,$aDummy1=null,$aDummy2=null) { - if( $this->hide ) - return; - $this->boxed = false; - $w = $this->GetWidth($aImg) + 2*$this->posx; - $h = $this->GetTextHeight($aImg) + 2*$this->posy; + if( $this->hide ) + return; + $this->boxed = false; + $w = $this->GetWidth($aImg) + 2*$this->posx; + $h = $this->GetTextHeight($aImg) + 2*$this->posy; - $x = $aImg->left_margin; - $y = $aImg->top_margin; + $x = $aImg->left_margin; + $y = $aImg->top_margin; - if( $this->width === TABTITLE_WIDTHFIT ) { - if( $this->align == 'left' ) { - $p = array($x, $y, - $x, $y-$h+$this->corner, - $x + $this->corner,$y-$h, - $x + $w - $this->corner, $y-$h, - $x + $w, $y-$h+$this->corner, - $x + $w, $y); - } - elseif( $this->align == 'center' ) { - $x += round($aImg->plotwidth/2) - round($w/2); - $p = array($x, $y, - $x, $y-$h+$this->corner, - $x + $this->corner, $y-$h, - $x + $w - $this->corner, $y-$h, - $x + $w, $y-$h+$this->corner, - $x + $w, $y); - } - else { - $x += $aImg->plotwidth -$w; - $p = array($x, $y, - $x, $y-$h+$this->corner, - $x + $this->corner,$y-$h, - $x + $w - $this->corner, $y-$h, - $x + $w, $y-$h+$this->corner, - $x + $w, $y); - } - } - else { - if( $this->width === TABTITLE_WIDTHFULL ) - $w = $aImg->plotwidth ; - else - $w = $this->width ; + if( $this->width === TABTITLE_WIDTHFIT ) { + if( $this->align == 'left' ) { + $p = array($x, $y, + $x, $y-$h+$this->corner, + $x + $this->corner,$y-$h, + $x + $w - $this->corner, $y-$h, + $x + $w, $y-$h+$this->corner, + $x + $w, $y); + } + elseif( $this->align == 'center' ) { + $x += round($aImg->plotwidth/2) - round($w/2); + $p = array($x, $y, + $x, $y-$h+$this->corner, + $x + $this->corner, $y-$h, + $x + $w - $this->corner, $y-$h, + $x + $w, $y-$h+$this->corner, + $x + $w, $y); + } + else { + $x += $aImg->plotwidth -$w; + $p = array($x, $y, + $x, $y-$h+$this->corner, + $x + $this->corner,$y-$h, + $x + $w - $this->corner, $y-$h, + $x + $w, $y-$h+$this->corner, + $x + $w, $y); + } + } + else { + if( $this->width === TABTITLE_WIDTHFULL ) { + $w = $aImg->plotwidth ; + } + else { + $w = $this->width ; + } - // Make the tab fit the width of the plot area - $p = array($x, $y, - $x, $y-$h+$this->corner, - $x + $this->corner,$y-$h, - $x + $w - $this->corner, $y-$h, - $x + $w, $y-$h+$this->corner, - $x + $w, $y); - - } - if( $this->halign == 'left' ) { - $aImg->SetTextAlign('left','bottom'); - $x += $this->posx; - $y -= $this->posy; - } - elseif( $this->halign == 'center' ) { - $aImg->SetTextAlign('center','bottom'); - $x += $w/2; - $y -= $this->posy; - } - else { - $aImg->SetTextAlign('right','bottom'); - $x += $w - $this->posx; - $y -= $this->posy; - } + // Make the tab fit the width of the plot area + $p = array($x, $y, + $x, $y-$h+$this->corner, + $x + $this->corner,$y-$h, + $x + $w - $this->corner, $y-$h, + $x + $w, $y-$h+$this->corner, + $x + $w, $y); - $aImg->SetColor($this->fillcolor); - $aImg->FilledPolygon($p); + } + if( $this->halign == 'left' ) { + $aImg->SetTextAlign('left','bottom'); + $x += $this->posx; + $y -= $this->posy; + } + elseif( $this->halign == 'center' ) { + $aImg->SetTextAlign('center','bottom'); + $x += $w/2; + $y -= $this->posy; + } + else { + $aImg->SetTextAlign('right','bottom'); + $x += $w - $this->posx; + $y -= $this->posy; + } - $aImg->SetColor($this->bordercolor); - $aImg->Polygon($p,true); - - $aImg->SetColor($this->color); - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $aImg->StrokeText($x,$y,$this->t,0,'center'); + $aImg->SetColor($this->fillcolor); + $aImg->FilledPolygon($p); + + $aImg->SetColor($this->bordercolor); + $aImg->Polygon($p,true); + + $aImg->SetColor($this->color); + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $aImg->StrokeText($x,$y,$this->t,0,'center'); } } @@ -3213,173 +3132,177 @@ class GraphTabTitle extends Text{ // Description: Format a superscript text //=================================================== class SuperScriptText extends Text { - private $iSuper=""; - private $sfont_family="",$sfont_style="",$sfont_size=8; + private $iSuper=''; + private $sfont_family='',$sfont_style='',$sfont_size=8; private $iSuperMargin=2,$iVertOverlap=4,$iSuperScale=0.65; private $iSDir=0; private $iSimple=false; - function SuperScriptText($aTxt="",$aSuper="",$aXAbsPos=0,$aYAbsPos=0) { - parent::Text($aTxt,$aXAbsPos,$aYAbsPos); - $this->iSuper = $aSuper; + function __construct($aTxt='',$aSuper='',$aXAbsPos=0,$aYAbsPos=0) { + parent::__construct($aTxt,$aXAbsPos,$aYAbsPos); + $this->iSuper = $aSuper; } function FromReal($aVal,$aPrecision=2) { - // Convert a floating point number to scientific notation - $neg=1.0; - if( $aVal < 0 ) { - $neg = -1.0; - $aVal = -$aVal; - } - - $l = floor(log10($aVal)); - $a = sprintf("%0.".$aPrecision."f",round($aVal / pow(10,$l),$aPrecision)); - $a *= $neg; - if( $this->iSimple && ($a == 1 || $a==-1) ) $a = ''; - - if( $a != '' ) - $this->t = $a.' * 10'; - else { - if( $neg == 1 ) - $this->t = '10'; - else - $this->t = '-10'; - } - $this->iSuper = $l; + // Convert a floating point number to scientific notation + $neg=1.0; + if( $aVal < 0 ) { + $neg = -1.0; + $aVal = -$aVal; + } + + $l = floor(log10($aVal)); + $a = sprintf("%0.".$aPrecision."f",round($aVal / pow(10,$l),$aPrecision)); + $a *= $neg; + if( $this->iSimple && ($a == 1 || $a==-1) ) $a = ''; + + if( $a != '' ) { + $this->t = $a.' * 10'; + } + else { + if( $neg == 1 ) { + $this->t = '10'; + } + else { + $this->t = '-10'; + } + } + $this->iSuper = $l; } - function Set($aTxt,$aSuper="") { - $this->t = $aTxt; - $this->iSuper = $aSuper; + function Set($aTxt,$aSuper='') { + $this->t = $aTxt; + $this->iSuper = $aSuper; } function SetSuperFont($aFontFam,$aFontStyle=FS_NORMAL,$aFontSize=8) { - $this->sfont_family = $aFontFam; - $this->sfont_style = $aFontStyle; - $this->sfont_size = $aFontSize; + $this->sfont_family = $aFontFam; + $this->sfont_style = $aFontStyle; + $this->sfont_size = $aFontSize; } // Total width of text function GetWidth($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $w = $aImg->GetTextWidth($this->t); - $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); - $w += $aImg->GetTextWidth($this->iSuper); - $w += $this->iSuperMargin; - return $w; + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $w = $aImg->GetTextWidth($this->t); + $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); + $w += $aImg->GetTextWidth($this->iSuper); + $w += $this->iSuperMargin; + return $w; } - + // Hight of font (approximate the height of the text) function GetFontHeight($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $h = $aImg->GetFontHeight(); - $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); - $h += $aImg->GetFontHeight(); - return $h; + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $h = $aImg->GetFontHeight(); + $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); + $h += $aImg->GetFontHeight(); + return $h; } // Hight of text function GetTextHeight($aImg) { - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $h = $aImg->GetTextHeight($this->t); - $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); - $h += $aImg->GetTextHeight($this->iSuper); - return $h; + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $h = $aImg->GetTextHeight($this->t); + $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size); + $h += $aImg->GetTextHeight($this->iSuper); + return $h; } function Stroke($aImg,$ax=-1,$ay=-1) { - + // To position the super script correctly we need different - // cases to handle the alignmewnt specified since that will - // determine how we can interpret the x,y coordinates - - $w = parent::GetWidth($aImg); - $h = parent::GetTextHeight($aImg); - switch( $this->valign ) { - case 'top': - $sy = $this->y; - break; - case 'center': - $sy = $this->y - $h/2; - break; - case 'bottom': - $sy = $this->y - $h; - break; - default: - JpGraphError::RaiseL(25052);//('PANIC: Internal error in SuperScript::Stroke(). Unknown vertical alignment for text'); - break; - } + // cases to handle the alignmewnt specified since that will + // determine how we can interpret the x,y coordinates - switch( $this->halign ) { - case 'left': - $sx = $this->x + $w; - break; - case 'center': - $sx = $this->x + $w/2; - break; - case 'right': - $sx = $this->x; - break; - default: - JpGraphError::RaiseL(25053);//('PANIC: Internal error in SuperScript::Stroke(). Unknown horizontal alignment for text'); - break; - } + $w = parent::GetWidth($aImg); + $h = parent::GetTextHeight($aImg); + switch( $this->valign ) { + case 'top': + $sy = $this->y; + break; + case 'center': + $sy = $this->y - $h/2; + break; + case 'bottom': + $sy = $this->y - $h; + break; + default: + JpGraphError::RaiseL(25052);//('PANIC: Internal error in SuperScript::Stroke(). Unknown vertical alignment for text'); + break; + } - $sx += $this->iSuperMargin; - $sy += $this->iVertOverlap; + switch( $this->halign ) { + case 'left': + $sx = $this->x + $w; + break; + case 'center': + $sx = $this->x + $w/2; + break; + case 'right': + $sx = $this->x; + break; + default: + JpGraphError::RaiseL(25053);//('PANIC: Internal error in SuperScript::Stroke(). Unknown horizontal alignment for text'); + break; + } - // Should we automatically determine the font or - // has the user specified it explicetly? - if( $this->sfont_family == "" ) { - if( $this->font_family <= FF_FONT2 ) { - if( $this->font_family == FF_FONT0 ) { - $sff = FF_FONT0; - } - elseif( $this->font_family == FF_FONT1 ) { - if( $this->font_style == FS_NORMAL ) - $sff = FF_FONT0; - else - $sff = FF_FONT1; - } - else { - $sff = FF_FONT1; - } - $sfs = $this->font_style; - $sfz = $this->font_size; - } - else { - // TTF fonts - $sff = $this->font_family; - $sfs = $this->font_style; - $sfz = floor($this->font_size*$this->iSuperScale); - if( $sfz < 8 ) $sfz = 8; - } - $this->sfont_family = $sff; - $this->sfont_style = $sfs; - $this->sfont_size = $sfz; - } - else { - $sff = $this->sfont_family; - $sfs = $this->sfont_style; - $sfz = $this->sfont_size; - } + $sx += $this->iSuperMargin; + $sy += $this->iVertOverlap; - parent::Stroke($aImg,$ax,$ay); + // Should we automatically determine the font or + // has the user specified it explicetly? + if( $this->sfont_family == '' ) { + if( $this->font_family <= FF_FONT2 ) { + if( $this->font_family == FF_FONT0 ) { + $sff = FF_FONT0; + } + elseif( $this->font_family == FF_FONT1 ) { + if( $this->font_style == FS_NORMAL ) { + $sff = FF_FONT0; + } + else { + $sff = FF_FONT1; + } + } + else { + $sff = FF_FONT1; + } + $sfs = $this->font_style; + $sfz = $this->font_size; + } + else { + // TTF fonts + $sff = $this->font_family; + $sfs = $this->font_style; + $sfz = floor($this->font_size*$this->iSuperScale); + if( $sfz < 8 ) $sfz = 8; + } + $this->sfont_family = $sff; + $this->sfont_style = $sfs; + $this->sfont_size = $sfz; + } + else { + $sff = $this->sfont_family; + $sfs = $this->sfont_style; + $sfz = $this->sfont_size; + } + parent::Stroke($aImg,$ax,$ay); - // For the builtin fonts we need to reduce the margins - // since the bounding bx reported for the builtin fonts - // are much larger than for the TTF fonts. - if( $sff <= FF_FONT2 ) { - $sx -= 2; - $sy += 3; - } + // For the builtin fonts we need to reduce the margins + // since the bounding bx reported for the builtin fonts + // are much larger than for the TTF fonts. + if( $sff <= FF_FONT2 ) { + $sx -= 2; + $sy += 3; + } - $aImg->SetTextAlign('left','bottom'); - $aImg->SetFont($sff,$sfs,$sfz); - $aImg->PushColor($this->color); - $aImg->StrokeText($sx,$sy,$this->iSuper,$this->iSDir,'left'); - $aImg->PopColor(); + $aImg->SetTextAlign('left','bottom'); + $aImg->SetFont($sff,$sfs,$sfz); + $aImg->PushColor($this->color); + $aImg->StrokeText($sx,$sy,$this->iSuper,$this->iSDir,'left'); + $aImg->PopColor(); } } @@ -3392,143 +3315,136 @@ class Grid { protected $img; protected $scale; protected $grid_color='#DDDDDD',$grid_mincolor='#DDDDDD'; - protected $type="solid"; + protected $type='solid'; protected $show=false, $showMinor=false,$weight=1; protected $fill=false,$fillcolor=array('#EFEFEF','#BBCCFF'); -//--------------- -// CONSTRUCTOR - function Grid($aAxis) { - $this->scale = $aAxis->scale; - $this->img = $aAxis->img; + + function __construct($aAxis) { + $this->scale = $aAxis->scale; + $this->img = $aAxis->img; } -//--------------- -// PUBLIC METHODS + function SetColor($aMajColor,$aMinColor=false) { - $this->grid_color=$aMajColor; - if( $aMinColor === false ) - $aMinColor = $aMajColor ; - $this->grid_mincolor = $aMinColor; + $this->grid_color=$aMajColor; + if( $aMinColor === false ) { + $aMinColor = $aMajColor ; + } + $this->grid_mincolor = $aMinColor; } - + function SetWeight($aWeight) { - $this->weight=$aWeight; + $this->weight=$aWeight; } - + // Specify if grid should be dashed, dotted or solid function SetLineStyle($aType) { - $this->type = $aType; + $this->type = $aType; } - + // Decide if both major and minor grid should be displayed function Show($aShowMajor=true,$aShowMinor=false) { - $this->show=$aShowMajor; - $this->showMinor=$aShowMinor; + $this->show=$aShowMajor; + $this->showMinor=$aShowMinor; } - + function SetFill($aFlg=true,$aColor1='lightgray',$aColor2='lightblue') { - $this->fill = $aFlg; - $this->fillcolor = array( $aColor1, $aColor2 ); + $this->fill = $aFlg; + $this->fillcolor = array( $aColor1, $aColor2 ); } - + // Display the grid function Stroke() { - if( $this->showMinor && !$this->scale->textscale ) { - $tmp = $this->grid_color; - $this->grid_color = $this->grid_mincolor; - $this->DoStroke($this->scale->ticks->ticks_pos); - - $this->grid_color = $tmp; - $this->DoStroke($this->scale->ticks->maj_ticks_pos); - } - else { - $this->DoStroke($this->scale->ticks->maj_ticks_pos); - } + if( $this->showMinor && !$this->scale->textscale ) { + $tmp = $this->grid_color; + $this->grid_color = $this->grid_mincolor; + $this->DoStroke($this->scale->ticks->ticks_pos); + $this->grid_color = $tmp; + $this->DoStroke($this->scale->ticks->maj_ticks_pos); + } + else { + $this->DoStroke($this->scale->ticks->maj_ticks_pos); + } } - -//-------------- -// Private methods + + //-------------- + // Private methods // Draw the grid function DoStroke($aTicksPos) { - if( !$this->show ) - return; - $nbrgrids = count($aTicksPos); + if( !$this->show ) return; + $nbrgrids = count($aTicksPos); - if( $this->scale->type=="y" ) { - $xl=$this->img->left_margin; - $xr=$this->img->width-$this->img->right_margin; - - if( $this->fill ) { - // Draw filled areas - $y2 = $aTicksPos[0]; - $i=1; - while( $i < $nbrgrids ) { - $y1 = $y2; - $y2 = $aTicksPos[$i++]; - $this->img->SetColor($this->fillcolor[$i & 1]); - $this->img->FilledRectangle($xl,$y1,$xr,$y2); - } - } + if( $this->scale->type == 'y' ) { + $xl=$this->img->left_margin; + $xr=$this->img->width-$this->img->right_margin; - $this->img->SetColor($this->grid_color); - $this->img->SetLineWeight($this->weight); + if( $this->fill ) { + // Draw filled areas + $y2 = $aTicksPos[0]; + $i=1; + while( $i < $nbrgrids ) { + $y1 = $y2; + $y2 = $aTicksPos[$i++]; + $this->img->SetColor($this->fillcolor[$i & 1]); + $this->img->FilledRectangle($xl,$y1,$xr,$y2); + } + } - // Draw grid lines - switch( $this->type ) { - case "solid": $style = LINESTYLE_SOLID; break; - case "dotted": $style = LINESTYLE_DOTTED; break; - case "dashed": $style = LINESTYLE_DASHED; break; - case "longdashed": $style = LINESTYLE_LONGDASH; break; - default: - $style = LINESTYLE_SOLID; break; - } + $this->img->SetColor($this->grid_color); + $this->img->SetLineWeight($this->weight); - for($i=0; $i < $nbrgrids; ++$i) { - $y=$aTicksPos[$i]; - $this->img->StyleLine($xl,$y,$xr,$y,$style); - } - } - elseif( $this->scale->type=="x" ) { - $yu=$this->img->top_margin; - $yl=$this->img->height-$this->img->bottom_margin; - $limit=$this->img->width-$this->img->right_margin; + // Draw grid lines + switch( $this->type ) { + case 'solid': $style = LINESTYLE_SOLID; break; + case 'dotted': $style = LINESTYLE_DOTTED; break; + case 'dashed': $style = LINESTYLE_DASHED; break; + case 'longdashed': $style = LINESTYLE_LONGDASH; break; + default: + $style = LINESTYLE_SOLID; break; + } - if( $this->fill ) { - // Draw filled areas - $x2 = $aTicksPos[0]; - $i=1; - while( $i < $nbrgrids ) { - $x1 = $x2; - $x2 = min($aTicksPos[$i++],$limit) ; - $this->img->SetColor($this->fillcolor[$i & 1]); - $this->img->FilledRectangle($x1,$yu,$x2,$yl); - } - } + for($i=0; $i < $nbrgrids; ++$i) { + $y=$aTicksPos[$i]; + $this->img->StyleLine($xl,$y,$xr,$y,$style); + } + } + elseif( $this->scale->type == 'x' ) { + $yu=$this->img->top_margin; + $yl=$this->img->height-$this->img->bottom_margin; + $limit=$this->img->width-$this->img->right_margin; - $this->img->SetColor($this->grid_color); - $this->img->SetLineWeight($this->weight); + if( $this->fill ) { + // Draw filled areas + $x2 = $aTicksPos[0]; + $i=1; + while( $i < $nbrgrids ) { + $x1 = $x2; + $x2 = min($aTicksPos[$i++],$limit) ; + $this->img->SetColor($this->fillcolor[$i & 1]); + $this->img->FilledRectangle($x1,$yu,$x2,$yl); + } + } - // We must also test for limit since we might have - // an offset and the number of ticks is calculated with - // assumption offset==0 so we might end up drawing one - // to many gridlines - $i=0; - $x=$aTicksPos[$i]; - while( $itype == "solid" ) - $this->img->Line($x,$yl,$x,$yu); - elseif( $this->type == "dotted" ) - $this->img->DashedLine($x,$yl,$x,$yu,1,6); - elseif( $this->type == "dashed" ) - $this->img->DashedLine($x,$yl,$x,$yu,2,4); - elseif( $this->type == "longdashed" ) - $this->img->DashedLine($x,$yl,$x,$yu,8,6); - ++$i; - } - } - else { - JpGraphError::RaiseL(25054,$this->scale->type);//('Internal error: Unknown grid axis ['.$this->scale->type.']'); - } - return true; + $this->img->SetColor($this->grid_color); + $this->img->SetLineWeight($this->weight); + + // We must also test for limit since we might have + // an offset and the number of ticks is calculated with + // assumption offset==0 so we might end up drawing one + // to many gridlines + $i=0; + $x=$aTicksPos[$i]; + while( $itype == 'solid' ) $this->img->Line($x,$yl,$x,$yu); + elseif( $this->type == 'dotted' ) $this->img->DashedLine($x,$yl,$x,$yu,1,6); + elseif( $this->type == 'dashed' ) $this->img->DashedLine($x,$yl,$x,$yu,2,4); + elseif( $this->type == 'longdashed' ) $this->img->DashedLine($x,$yl,$x,$yu,8,6); + ++$i; + } + } + else { + JpGraphError::RaiseL(25054,$this->scale->type);//('Internal error: Unknown grid axis ['.$this->scale->type.']'); + } + return true; } } // Class @@ -3538,10 +3454,10 @@ class Grid { // moment the code is not really good since the axis on // several occasion must know wheter it's an X or Y axis. // This was a design decision to make the code easier to -// follow. +// follow. //=================================================== class AxisPrototype { - public $scale=null; + public $scale=null; public $img=null; public $hide=false,$hide_labels=false; public $title=null; @@ -3563,221 +3479,191 @@ class AxisPrototype { protected $hide_line=false; protected $iDeltaAbsPos=0; -//--------------- -// CONSTRUCTOR - function Axis($img,$aScale,$color=array(0,0,0)) { - $this->img = $img; - $this->scale = $aScale; - $this->color = $color; - $this->title=new Text(""); - - if( $aScale->type=="y" ) { - $this->title_margin = 25; - $this->title_adjust="middle"; - $this->title->SetOrientation(90); - $this->tick_label_margin=7; - $this->labelPos=SIDE_LEFT; - } - else { - $this->title_margin = 5; - $this->title_adjust="high"; - $this->title->SetOrientation(0); - $this->tick_label_margin=7; - $this->labelPos=SIDE_DOWN; - $this->title_side=SIDE_DOWN; - } + function __construct($img,$aScale,$color = array(0,0,0)) { + $this->img = $img; + $this->scale = $aScale; + $this->color = $color; + $this->title=new Text(''); + + if( $aScale->type == 'y' ) { + $this->title_margin = 25; + $this->title_adjust = 'middle'; + $this->title->SetOrientation(90); + $this->tick_label_margin=7; + $this->labelPos=SIDE_LEFT; + } + else { + $this->title_margin = 5; + $this->title_adjust = 'high'; + $this->title->SetOrientation(0); + $this->tick_label_margin=7; + $this->labelPos=SIDE_DOWN; + $this->title_side=SIDE_DOWN; + } } -//--------------- -// PUBLIC METHODS - + function SetLabelFormat($aFormStr) { - $this->scale->ticks->SetLabelFormat($aFormStr); + $this->scale->ticks->SetLabelFormat($aFormStr); } function SetLabelFormatString($aFormStr,$aDate=false) { - $this->scale->ticks->SetLabelFormat($aFormStr,$aDate); - } - - function SetLabelFormatCallback($aFuncName) { - $this->scale->ticks->SetFormatCallback($aFuncName); + $this->scale->ticks->SetLabelFormat($aFormStr,$aDate); } - function SetLabelAlign($aHAlign,$aVAlign="top",$aParagraphAlign='left') { - $this->label_halign = $aHAlign; - $this->label_valign = $aVAlign; - $this->label_para_align = $aParagraphAlign; - } + function SetLabelFormatCallback($aFuncName) { + $this->scale->ticks->SetFormatCallback($aFuncName); + } + + function SetLabelAlign($aHAlign,$aVAlign='top',$aParagraphAlign='left') { + $this->label_halign = $aHAlign; + $this->label_valign = $aVAlign; + $this->label_para_align = $aParagraphAlign; + } // Don't display the first label function HideFirstTickLabel($aShow=false) { - $this->show_first_label=$aShow; + $this->show_first_label=$aShow; } function HideLastTickLabel($aShow=false) { - $this->show_last_label=$aShow; + $this->show_last_label=$aShow; } // Manually specify the major and (optional) minor tick position and labels function SetTickPositions($aMajPos,$aMinPos=NULL,$aLabels=NULL) { - $this->scale->ticks->SetTickPositions($aMajPos,$aMinPos,$aLabels); + $this->scale->ticks->SetTickPositions($aMajPos,$aMinPos,$aLabels); } // Manually specify major tick positions and optional labels function SetMajTickPositions($aMajPos,$aLabels=NULL) { - $this->scale->ticks->SetTickPositions($aMajPos,NULL,$aLabels); + $this->scale->ticks->SetTickPositions($aMajPos,NULL,$aLabels); } // Hide minor or major tick marks function HideTicks($aHideMinor=true,$aHideMajor=true) { - $this->scale->ticks->SupressMinorTickMarks($aHideMinor); - $this->scale->ticks->SupressTickMarks($aHideMajor); + $this->scale->ticks->SupressMinorTickMarks($aHideMinor); + $this->scale->ticks->SupressTickMarks($aHideMajor); } // Hide zero label function HideZeroLabel($aFlag=true) { - $this->scale->ticks->SupressZeroLabel(); + $this->scale->ticks->SupressZeroLabel(); } - + function HideFirstLastLabel() { - // The two first calls to ticks method will supress - // automatically generated scale values. However, that - // will not affect manually specified value, e.g text-scales. - // therefor we also make a kludge here to supress manually - // specified scale labels. - $this->scale->ticks->SupressLast(); - $this->scale->ticks->SupressFirst(); - $this->show_first_label = false; - $this->show_last_label = false; + // The two first calls to ticks method will supress + // automatically generated scale values. However, that + // will not affect manually specified value, e.g text-scales. + // therefor we also make a kludge here to supress manually + // specified scale labels. + $this->scale->ticks->SupressLast(); + $this->scale->ticks->SupressFirst(); + $this->show_first_label = false; + $this->show_last_label = false; } - + // Hide the axis function Hide($aHide=true) { - $this->hide=$aHide; + $this->hide=$aHide; } // Hide the actual axis-line, but still print the labels function HideLine($aHide=true) { - $this->hide_line = $aHide; + $this->hide_line = $aHide; } function HideLabels($aHide=true) { - $this->hide_labels = $aHide; + $this->hide_labels = $aHide; } - // Weight of axis function SetWeight($aWeight) { - $this->weight = $aWeight; + $this->weight = $aWeight; } // Axis color function SetColor($aColor,$aLabelColor=false) { - $this->color = $aColor; - if( !$aLabelColor ) $this->label_color = $aColor; - else $this->label_color = $aLabelColor; - } - - // Title on axis - function SetTitle($aTitle,$aAdjustAlign="high") { - $this->title->Set($aTitle); - $this->title_adjust=$aAdjustAlign; - } - - // Specify distance from the axis - function SetTitleMargin($aMargin) { - $this->title_margin=$aMargin; - } - - // Which side of the axis should the axis title be? - function SetTitleSide($aSideOfAxis) { - $this->title_side = $aSideOfAxis; + $this->color = $aColor; + if( !$aLabelColor ) $this->label_color = $aColor; + else $this->label_color = $aLabelColor; } - // Utility function to set the direction for tick marks - function SetTickDirection($aDir) { - // Will be deprecated from 1.7 - if( ERR_DEPRECATED ) - JpGraphError::RaiseL(25055);//('Axis::SetTickDirection() is deprecated. Use Axis::SetTickSide() instead'); - $this->scale->ticks->SetSide($aDir); + // Title on axis + function SetTitle($aTitle,$aAdjustAlign='high') { + $this->title->Set($aTitle); + $this->title_adjust=$aAdjustAlign; } - + + // Specify distance from the axis + function SetTitleMargin($aMargin) { + $this->title_margin=$aMargin; + } + + // Which side of the axis should the axis title be? + function SetTitleSide($aSideOfAxis) { + $this->title_side = $aSideOfAxis; + } + function SetTickSide($aDir) { - $this->scale->ticks->SetSide($aDir); + $this->scale->ticks->SetSide($aDir); } - + + function SetTickSize($aMajSize,$aMinSize=3) { + $this->scale->ticks->SetSize($aMajSize,$aMinSize=3); + } + // Specify text labels for the ticks. One label for each data point function SetTickLabels($aLabelArray,$aLabelColorArray=null) { - $this->ticks_label = $aLabelArray; - $this->ticks_label_colors = $aLabelColorArray; - } - - // How far from the axis should the labels be drawn - function SetTickLabelMargin($aMargin) { - if( ERR_DEPRECATED ) - JpGraphError::RaiseL(25056);//('SetTickLabelMargin() is deprecated. Use Axis::SetLabelMargin() instead.'); - $this->tick_label_margin=$aMargin; + $this->ticks_label = $aLabelArray; + $this->ticks_label_colors = $aLabelColorArray; } function SetLabelMargin($aMargin) { - $this->tick_label_margin=$aMargin; - } - - // Specify that every $step of the ticks should be displayed starting - // at $start - // DEPRECATED FUNCTION: USE SetTextTickInterval() INSTEAD - function SetTextTicks($step,$start=0) { - JpGraphError::RaiseL(25057);//(" SetTextTicks() is deprecated. Use SetTextTickInterval() instead."); + $this->tick_label_margin=$aMargin; } // Specify that every $step of the ticks should be displayed starting - // at $start + // at $start function SetTextTickInterval($aStep,$aStart=0) { - $this->scale->ticks->SetTextLabelStart($aStart); - $this->tick_step=$aStep; + $this->scale->ticks->SetTextLabelStart($aStart); + $this->tick_step=$aStep; } - - // Specify that every $step tick mark should have a label + + // Specify that every $step tick mark should have a label // should be displayed starting function SetTextLabelInterval($aStep) { - if( $aStep < 1 ) - JpGraphError::RaiseL(25058);//(" Text label interval must be specified >= 1."); - $this->label_step=$aStep; + if( $aStep < 1 ) { + JpGraphError::RaiseL(25058);//(" Text label interval must be specified >= 1."); + } + $this->label_step=$aStep; } - - // Which side of the axis should the labels be on? - function SetLabelPos($aSidePos) { - // This will be deprecated from 1.7 - if( ERR_DEPRECATED ) - JpGraphError::RaiseL(25059);//('SetLabelPos() is deprecated. Use Axis::SetLabelSide() instead.'); - $this->labelPos=$aSidePos; - } - + function SetLabelSide($aSidePos) { - $this->labelPos=$aSidePos; + $this->labelPos=$aSidePos; } // Set the font function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) { - $this->font_family = $aFamily; - $this->font_style = $aStyle; - $this->font_size = $aSize; + $this->font_family = $aFamily; + $this->font_style = $aStyle; + $this->font_size = $aSize; } // Position for axis line on the "other" scale function SetPos($aPosOnOtherScale) { - $this->pos=$aPosOnOtherScale; + $this->pos=$aPosOnOtherScale; } - // Set the position of the axis to be X-pixels delta to the right + // Set the position of the axis to be X-pixels delta to the right // of the max X-position (used to position the multiple Y-axis) function SetPosAbsDelta($aDelta) { - $this->iDeltaAbsPos=$aDelta; + $this->iDeltaAbsPos=$aDelta; } - + // Specify the angle for the tick labels function SetLabelAngle($aAngle) { - $this->label_angle = $aAngle; - } + $this->label_angle = $aAngle; + } } // Class @@ -3788,218 +3674,252 @@ class AxisPrototype { // moment the code is not really good since the axis on // several occasion must know wheter it's an X or Y axis. // This was a design decision to make the code easier to -// follow. +// follow. //=================================================== class Axis extends AxisPrototype { - function Axis($img,$aScale,$color=array(0,0,0)) { - parent::Axis($img,$aScale,$color); + function __construct($img,$aScale,$color='black') { + parent::__construct($img,$aScale,$color); } - + // Stroke the axis. - function Stroke($aOtherAxisScale,$aStrokeLabels=true) { - if( $this->hide ) return; - if( is_numeric($this->pos) ) { - $pos=$aOtherAxisScale->Translate($this->pos); - } - else { // Default to minimum of other scale if pos not set - if( ($aOtherAxisScale->GetMinVal() >= 0 && $this->pos==false) || $this->pos=="min" ) { - $pos = $aOtherAxisScale->scale_abs[0]; - } - elseif($this->pos == "max") { - $pos = $aOtherAxisScale->scale_abs[1]; - } - else { // If negative set x-axis at 0 - $this->pos=0; - $pos=$aOtherAxisScale->Translate(0); - } - } - $pos += $this->iDeltaAbsPos; - $this->img->SetLineWeight($this->weight); - $this->img->SetColor($this->color); - $this->img->SetFont($this->font_family,$this->font_style,$this->font_size); - if( $this->scale->type == "x" ) { - if( !$this->hide_line ) - $this->img->FilledRectangle($this->img->left_margin,$pos, - $this->img->width-$this->img->right_margin,$pos+$this->weight-1); - if( $this->title_side == SIDE_DOWN ) { - $y = $pos + $this->img->GetFontHeight() + $this->title_margin + $this->title->margin; - $yalign = 'top'; - } - else { - $y = $pos - $this->img->GetFontHeight() - $this->title_margin - $this->title->margin; - $yalign = 'bottom'; - } + function Stroke($aOtherAxisScale,$aStrokeLabels=true) { + if( $this->hide ) + return; + if( is_numeric($this->pos) ) { + $pos=$aOtherAxisScale->Translate($this->pos); + } + else { // Default to minimum of other scale if pos not set + if( ($aOtherAxisScale->GetMinVal() >= 0 && $this->pos==false) || $this->pos == 'min' ) { + $pos = $aOtherAxisScale->scale_abs[0]; + } + elseif($this->pos == "max") { + $pos = $aOtherAxisScale->scale_abs[1]; + } + else { // If negative set x-axis at 0 + $this->pos=0; + $pos=$aOtherAxisScale->Translate(0); + } + } + $pos += $this->iDeltaAbsPos; + $this->img->SetLineWeight($this->weight); + $this->img->SetColor($this->color); + $this->img->SetFont($this->font_family,$this->font_style,$this->font_size); + if( $this->scale->type == "x" ) { + if( !$this->hide_line ) { + $this->img->FilledRectangle($this->img->left_margin,$pos,$this->img->width-$this->img->right_margin,$pos+$this->weight-1); + } + if( $this->title_side == SIDE_DOWN ) { + $y = $pos + $this->img->GetFontHeight() + $this->title_margin + $this->title->margin; + $yalign = 'top'; + } + else { + $y = $pos - $this->img->GetFontHeight() - $this->title_margin - $this->title->margin; + $yalign = 'bottom'; + } - if( $this->title_adjust=='high' ) - $this->title->SetPos($this->img->width-$this->img->right_margin,$y,'right',$yalign); - elseif( $this->title_adjust=='middle' || $this->title_adjust=='center' ) - $this->title->SetPos(($this->img->width-$this->img->left_margin-$this->img->right_margin)/2+$this->img->left_margin,$y,'center',$yalign); - elseif($this->title_adjust=='low') - $this->title->SetPos($this->img->left_margin,$y,'left',$yalign); - else { - JpGraphError::RaiseL(25060,$this->title_adjust);//('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')'); - } - } - elseif( $this->scale->type == "y" ) { - // Add line weight to the height of the axis since - // the x-axis could have a width>1 and we want the axis to fit nicely together. - if( !$this->hide_line ) - $this->img->FilledRectangle($pos-$this->weight+1,$this->img->top_margin, - $pos,$this->img->height-$this->img->bottom_margin+$this->weight-1); - $x=$pos ; - if( $this->title_side == SIDE_LEFT ) { - $x -= $this->title_margin; - $x -= $this->title->margin; - $halign="right"; - } - else { - $x += $this->title_margin; - $x += $this->title->margin; - $halign="left"; - } - // If the user has manually specified an hor. align - // then we override the automatic settings with this - // specifed setting. Since default is 'left' we compare - // with that. (This means a manually set 'left' align - // will have no effect.) - if( $this->title->halign != 'left' ) - $halign = $this->title->halign; - if( $this->title_adjust=="high" ) - $this->title->SetPos($x,$this->img->top_margin,$halign,"top"); - elseif($this->title_adjust=="middle" || $this->title_adjust=="center") - $this->title->SetPos($x,($this->img->height-$this->img->top_margin-$this->img->bottom_margin)/2+$this->img->top_margin,$halign,"center"); - elseif($this->title_adjust=="low") - $this->title->SetPos($x,$this->img->height-$this->img->bottom_margin,$halign,"bottom"); - else - JpGraphError::RaiseL(25061,$this->title_adjust);//('Unknown alignment specified for Y-axis title. ('.$this->title_adjust.')'); - - } - $this->scale->ticks->Stroke($this->img,$this->scale,$pos); - if( $aStrokeLabels ) { - if( !$this->hide_labels ) - $this->StrokeLabels($pos); - $this->title->Stroke($this->img); - } + if( $this->title_adjust=='high' ) { + $this->title->SetPos($this->img->width-$this->img->right_margin,$y,'right',$yalign); + } + elseif( $this->title_adjust=='middle' || $this->title_adjust=='center' ) { + $this->title->SetPos(($this->img->width-$this->img->left_margin-$this->img->right_margin)/2+$this->img->left_margin,$y,'center',$yalign); + } + elseif($this->title_adjust=='low') { + $this->title->SetPos($this->img->left_margin,$y,'left',$yalign); + } + else { + JpGraphError::RaiseL(25060,$this->title_adjust);//('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')'); + } + } + elseif( $this->scale->type == "y" ) { + // Add line weight to the height of the axis since + // the x-axis could have a width>1 and we want the axis to fit nicely together. + if( !$this->hide_line ) { + $this->img->FilledRectangle($pos-$this->weight+1,$this->img->top_margin,$pos,$this->img->height-$this->img->bottom_margin+$this->weight-1); + } + $x=$pos ; + if( $this->title_side == SIDE_LEFT ) { + $x -= $this->title_margin; + $x -= $this->title->margin; + $halign = 'right'; + } + else { + $x += $this->title_margin; + $x += $this->title->margin; + $halign = 'left'; + } + // If the user has manually specified an hor. align + // then we override the automatic settings with this + // specifed setting. Since default is 'left' we compare + // with that. (This means a manually set 'left' align + // will have no effect.) + if( $this->title->halign != 'left' ) { + $halign = $this->title->halign; + } + if( $this->title_adjust == 'high' ) { + $this->title->SetPos($x,$this->img->top_margin,$halign,'top'); + } + elseif($this->title_adjust=='middle' || $this->title_adjust=='center') { + $this->title->SetPos($x,($this->img->height-$this->img->top_margin-$this->img->bottom_margin)/2+$this->img->top_margin,$halign,"center"); + } + elseif($this->title_adjust=='low') { + $this->title->SetPos($x,$this->img->height-$this->img->bottom_margin,$halign,'bottom'); + } + else { + JpGraphError::RaiseL(25061,$this->title_adjust);//('Unknown alignment specified for Y-axis title. ('.$this->title_adjust.')'); + } + } + $this->scale->ticks->Stroke($this->img,$this->scale,$pos); + if( $aStrokeLabels ) { + if( !$this->hide_labels ) { + $this->StrokeLabels($pos); + } + $this->title->Stroke($this->img); + } } -//--------------- -// PRIVATE METHODS + //--------------- + // PRIVATE METHODS // Draw all the tick labels on major tick marks function StrokeLabels($aPos,$aMinor=false,$aAbsLabel=false) { - $this->img->SetColor($this->label_color); - $this->img->SetFont($this->font_family,$this->font_style,$this->font_size); - $yoff=$this->img->GetFontHeight()/2; + if( is_array($this->label_color) && count($this->label_color) > 3 ) { + $this->ticks_label_colors = $this->label_color; + $this->img->SetColor($this->label_color[0]); + } + else { + $this->img->SetColor($this->label_color); + } + $this->img->SetFont($this->font_family,$this->font_style,$this->font_size); + $yoff=$this->img->GetFontHeight()/2; - // Only draw labels at major tick marks - $nbr = count($this->scale->ticks->maj_ticks_label); + // Only draw labels at major tick marks + $nbr = count($this->scale->ticks->maj_ticks_label); - // We have the option to not-display the very first mark - // (Usefull when the first label might interfere with another - // axis.) - $i = $this->show_first_label ? 0 : 1 ; - if( !$this->show_last_label ) --$nbr; - // Now run through all labels making sure we don't overshoot the end - // of the scale. - $ncolor=0; - if( isset($this->ticks_label_colors) ) - $ncolor=count($this->ticks_label_colors); - while( $i<$nbr ) { - // $tpos holds the absolute text position for the label - $tpos=$this->scale->ticks->maj_ticklabels_pos[$i]; + // We have the option to not-display the very first mark + // (Usefull when the first label might interfere with another + // axis.) + $i = $this->show_first_label ? 0 : 1 ; + if( !$this->show_last_label ) { + --$nbr; + } + // Now run through all labels making sure we don't overshoot the end + // of the scale. + $ncolor=0; + if( isset($this->ticks_label_colors) ) { + $ncolor=count($this->ticks_label_colors); + } + while( $i < $nbr ) { + // $tpos holds the absolute text position for the label + $tpos=$this->scale->ticks->maj_ticklabels_pos[$i]; - // Note. the $limit is only used for the x axis since we - // might otherwise overshoot if the scale has been centered - // This is due to us "loosing" the last tick mark if we center. - if( $this->scale->type=="x" && $tpos > $this->img->width-$this->img->right_margin+1 ) { - return; - } - // we only draw every $label_step label - if( ($i % $this->label_step)==0 ) { + // Note. the $limit is only used for the x axis since we + // might otherwise overshoot if the scale has been centered + // This is due to us "loosing" the last tick mark if we center. + if( $this->scale->type == 'x' && $tpos > $this->img->width-$this->img->right_margin+1 ) { + return; + } + // we only draw every $label_step label + if( ($i % $this->label_step)==0 ) { - // Set specific label color if specified - if( $ncolor > 0 ) - $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]); - - // If the label has been specified use that and in other case - // just label the mark with the actual scale value - $m=$this->scale->ticks->GetMajor(); - - // ticks_label has an entry for each data point and is the array - // that holds the labels set by the user. If the user hasn't - // specified any values we use whats in the automatically asigned - // labels in the maj_ticks_label - if( isset($this->ticks_label[$i*$m]) ) - $label=$this->ticks_label[$i*$m]; - else { - if( $aAbsLabel ) - $label=abs($this->scale->ticks->maj_ticks_label[$i]); - else - $label=$this->scale->ticks->maj_ticks_label[$i]; - if( $this->scale->textscale && $this->scale->ticks->label_formfunc == '' ) { - ++$label; - } - } - - if( $this->scale->type == "x" ) { - if( $this->labelPos == SIDE_DOWN ) { - if( $this->label_angle==0 || $this->label_angle==90 ) { - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign('center','top'); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - - } - else { - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign("right","top"); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - } - $this->img->StrokeText($tpos,$aPos+$this->tick_label_margin+1,$label, - $this->label_angle,$this->label_para_align); - } - else { - if( $this->label_angle==0 || $this->label_angle==90 ) { - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign("center","bottom"); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - } - else { - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign("right","bottom"); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - } - $this->img->StrokeText($tpos,$aPos-$this->tick_label_margin-1,$label, - $this->label_angle,$this->label_para_align); - } - } - else { - // scale->type == "y" - //if( $this->label_angle!=0 ) - //JpGraphError::Raise(" Labels at an angle are not supported on Y-axis"); - if( $this->labelPos == SIDE_LEFT ) { // To the left of y-axis - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign("right","center"); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - $this->img->StrokeText($aPos-$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align); - } - else { // To the right of the y-axis - if( $this->label_halign=='' && $this->label_valign=='') - $this->img->SetTextAlign("left","center"); - else - $this->img->SetTextAlign($this->label_halign,$this->label_valign); - $this->img->StrokeText($aPos+$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align); - } - } - } - ++$i; - } - } + // Set specific label color if specified + if( $ncolor > 0 ) { + $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]); + } + + // If the label has been specified use that and in other case + // just label the mark with the actual scale value + $m=$this->scale->ticks->GetMajor(); + + // ticks_label has an entry for each data point and is the array + // that holds the labels set by the user. If the user hasn't + // specified any values we use whats in the automatically asigned + // labels in the maj_ticks_label + if( isset($this->ticks_label[$i*$m]) ) { + $label=$this->ticks_label[$i*$m]; + } + else { + if( $aAbsLabel ) { + $label=abs($this->scale->ticks->maj_ticks_label[$i]); + } + else { + $label=$this->scale->ticks->maj_ticks_label[$i]; + } + if( $this->scale->textscale && $this->scale->ticks->label_formfunc == '' ) { + ++$label; + } + } + + if( $this->scale->type == "x" ) { + if( $this->labelPos == SIDE_DOWN ) { + if( $this->label_angle==0 || $this->label_angle==90 ) { + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign('center','top'); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + + } + else { + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign("right","top"); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + } + $this->img->StrokeText($tpos,$aPos+$this->tick_label_margin+1,$label, + $this->label_angle,$this->label_para_align); + } + else { + if( $this->label_angle==0 || $this->label_angle==90 ) { + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign("center","bottom"); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + } + else { + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign("right","bottom"); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + } + $this->img->StrokeText($tpos,$aPos-$this->tick_label_margin-1,$label, + $this->label_angle,$this->label_para_align); + } + } + else { + // scale->type == "y" + //if( $this->label_angle!=0 ) + //JpGraphError::Raise(" Labels at an angle are not supported on Y-axis"); + if( $this->labelPos == SIDE_LEFT ) { // To the left of y-axis + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign("right","center"); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + $this->img->StrokeText($aPos-$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align); + } + else { // To the right of the y-axis + if( $this->label_halign=='' && $this->label_valign=='') { + $this->img->SetTextAlign("left","center"); + } + else { + $this->img->SetTextAlign($this->label_halign,$this->label_valign); + } + $this->img->StrokeText($aPos+$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align); + } + } + } + ++$i; + } + } } @@ -4015,122 +3935,112 @@ class Ticks { public $label_dateformatstr=''; public $direction=1; // Should ticks be in(=1) the plot area or outside (=-1) public $supress_last=false,$supress_tickmarks=false,$supress_minor_tickmarks=false; - public $maj_ticks_pos = array(), $maj_ticklabels_pos = array(), - $ticks_pos = array(), $maj_ticks_label = array(); + public $maj_ticks_pos = array(), $maj_ticklabels_pos = array(), + $ticks_pos = array(), $maj_ticks_label = array(); public $precision; protected $minor_abs_size=3, $major_abs_size=5; protected $scale; protected $is_set=false; protected $supress_zerolabel=false,$supress_first=false; - protected $mincolor="",$majcolor=""; + protected $mincolor='',$majcolor=''; protected $weight=1; protected $label_usedateformat=FALSE; -//--------------- -// CONSTRUCTOR - function Ticks($aScale) { - $this->scale=$aScale; - $this->precision = -1; + function __construct($aScale) { + $this->scale=$aScale; + $this->precision = -1; } -//--------------- -// PUBLIC METHODS // Set format string for automatic labels function SetLabelFormat($aFormatString,$aDate=FALSE) { - $this->label_formatstr=$aFormatString; - $this->label_usedateformat=$aDate; + $this->label_formatstr=$aFormatString; + $this->label_usedateformat=$aDate; } - + function SetLabelDateFormat($aFormatString) { - $this->label_dateformatstr=$aFormatString; + $this->label_dateformatstr=$aFormatString; } - + function SetFormatCallback($aCallbackFuncName) { - $this->label_formfunc = $aCallbackFuncName; + $this->label_formfunc = $aCallbackFuncName; } - + // Don't display the first zero label function SupressZeroLabel($aFlag=true) { - $this->supress_zerolabel=$aFlag; + $this->supress_zerolabel=$aFlag; } - + // Don't display minor tick marks function SupressMinorTickMarks($aHide=true) { - $this->supress_minor_tickmarks=$aHide; + $this->supress_minor_tickmarks=$aHide; } - + // Don't display major tick marks function SupressTickMarks($aHide=true) { - $this->supress_tickmarks=$aHide; + $this->supress_tickmarks=$aHide; } - + // Hide the first tick mark function SupressFirst($aHide=true) { - $this->supress_first=$aHide; + $this->supress_first=$aHide; } - + // Hide the last tick mark function SupressLast($aHide=true) { - $this->supress_last=$aHide; + $this->supress_last=$aHide; } // Size (in pixels) of minor tick marks function GetMinTickAbsSize() { - return $this->minor_abs_size; + return $this->minor_abs_size; } - + // Size (in pixels) of major tick marks function GetMajTickAbsSize() { - return $this->major_abs_size; + return $this->major_abs_size; } - + function SetSize($aMajSize,$aMinSize=3) { - $this->major_abs_size = $aMajSize; - $this->minor_abs_size = $aMinSize; + $this->major_abs_size = $aMajSize; + $this->minor_abs_size = $aMinSize; } // Have the ticks been specified function IsSpecified() { - return $this->is_set; - } - - // Specify number of decimals in automatic labels - // Deprecated from 1.4. Use SetFormatString() instead - function SetPrecision($aPrecision) { - if( ERR_DEPRECATED ) - JpGraphError::RaiseL(25063);//('Ticks::SetPrecision() is deprecated. Use Ticks::SetLabelFormat() (or Ticks::SetFormatCallback()) instead'); - $this->precision=$aPrecision; + return $this->is_set; } function SetSide($aSide) { - $this->direction=$aSide; + $this->direction=$aSide; } - + // Which side of the axis should the ticks be on function SetDirection($aSide=SIDE_RIGHT) { - $this->direction=$aSide; + $this->direction=$aSide; } - + // Set colors for major and minor tick marks - function SetMarkColor($aMajorColor,$aMinorColor="") { - $this->SetColor($aMajorColor,$aMinorColor); + function SetMarkColor($aMajorColor,$aMinorColor='') { + $this->SetColor($aMajorColor,$aMinorColor); } - - function SetColor($aMajorColor,$aMinorColor="") { - $this->majcolor=$aMajorColor; - - // If not specified use same as major - if( $aMinorColor=="" ) - $this->mincolor=$aMajorColor; - else - $this->mincolor=$aMinorColor; + + function SetColor($aMajorColor,$aMinorColor='') { + $this->majcolor=$aMajorColor; + + // If not specified use same as major + if( $aMinorColor == '' ) { + $this->mincolor=$aMajorColor; + } + else { + $this->mincolor=$aMinorColor; + } } - + function SetWeight($aWeight) { - $this->weight=$aWeight; + $this->weight=$aWeight; } - + } // Class //=================================================== @@ -4146,349 +4056,361 @@ class LinearTicks extends Ticks { private $iManualTickPos = NULL, $iManualMinTickPos = NULL, $iManualTickLabels = NULL; private $iAdjustForDST = false; // If a date falls within the DST period add one hour to the diaplyed time -//--------------- -// CONSTRUCTOR - function LinearTicks() { - $this->precision = -1; + function __construct() { + $this->precision = -1; } -//--------------- -// PUBLIC METHODS - - // Return major step size in world coordinates function GetMajor() { - return $this->major_step; + return $this->major_step; } - + // Return minor step size in world coordinates function GetMinor() { - return $this->minor_step; + return $this->minor_step; } - + // Set Minor and Major ticks (in world coordinates) function Set($aMajStep,$aMinStep=false) { - if( $aMinStep==false ) - $aMinStep=$aMajStep; - - if( $aMajStep <= 0 || $aMinStep <= 0 ) { - JpGraphError::RaiseL(25064); -//(" Minor or major step size is 0. Check that you haven't got an accidental SetTextTicks(0) in your code. If this is not the case you might have stumbled upon a bug in JpGraph. Please report this and if possible include the data that caused the problem."); - } - - $this->major_step=$aMajStep; - $this->minor_step=$aMinStep; - $this->is_set = true; + if( $aMinStep==false ) { + $aMinStep=$aMajStep; + } + + if( $aMajStep <= 0 || $aMinStep <= 0 ) { + JpGraphError::RaiseL(25064); + //(" Minor or major step size is 0. Check that you haven't got an accidental SetTextTicks(0) in your code. If this is not the case you might have stumbled upon a bug in JpGraph. Please report this and if possible include the data that caused the problem."); + } + + $this->major_step=$aMajStep; + $this->minor_step=$aMinStep; + $this->is_set = true; } function SetMajTickPositions($aMajPos,$aLabels=NULL) { - $this->SetTickPositions($aMajPos,NULL,$aLabels); + $this->SetTickPositions($aMajPos,NULL,$aLabels); } function SetTickPositions($aMajPos,$aMinPos=NULL,$aLabels=NULL) { - if( !is_array($aMajPos) || ($aMinPos!==NULL && !is_array($aMinPos)) ) { - JpGraphError::RaiseL(25065);//('Tick positions must be specifued as an array()'); - return; - } - $n=count($aMajPos); - if( is_array($aLabels) && (count($aLabels) != $n) ) { - JpGraphError::RaiseL(25066);//('When manually specifying tick positions and labels the number of labels must be the same as the number of specified ticks.'); - return; - } - $this->iManualTickPos = $aMajPos; - $this->iManualMinTickPos = $aMinPos; - $this->iManualTickLabels = $aLabels; + if( !is_array($aMajPos) || ($aMinPos!==NULL && !is_array($aMinPos)) ) { + JpGraphError::RaiseL(25065);//('Tick positions must be specifued as an array()'); + return; + } + $n=count($aMajPos); + if( is_array($aLabels) && (count($aLabels) != $n) ) { + JpGraphError::RaiseL(25066);//('When manually specifying tick positions and labels the number of labels must be the same as the number of specified ticks.'); + } + $this->iManualTickPos = $aMajPos; + $this->iManualMinTickPos = $aMinPos; + $this->iManualTickLabels = $aLabels; } - // Specify all the tick positions manually and possible also the exact labels - function _doManualTickPos($aScale) { - $n=count($this->iManualTickPos); - $m=count($this->iManualMinTickPos); - $doLbl=count($this->iManualTickLabels) > 0; + // Specify all the tick positions manually and possible also the exact labels + function _doManualTickPos($aScale) { + $n=count($this->iManualTickPos); + $m=count($this->iManualMinTickPos); + $doLbl=count($this->iManualTickLabels) > 0; - $this->maj_ticks_pos = array(); - $this->maj_ticklabels_pos = array(); - $this->ticks_pos = array(); + $this->maj_ticks_pos = array(); + $this->maj_ticklabels_pos = array(); + $this->ticks_pos = array(); - // Now loop through the supplied positions and translate them to screen coordinates - // and store them in the maj_label_positions - $minScale = $aScale->scale[0]; - $maxScale = $aScale->scale[1]; - $j=0; - for($i=0; $i < $n ; ++$i ) { - // First make sure that the first tick is not lower than the lower scale value - if( !isset($this->iManualTickPos[$i]) || - $this->iManualTickPos[$i] < $minScale || $this->iManualTickPos[$i] > $maxScale) { - continue; - } + // Now loop through the supplied positions and translate them to screen coordinates + // and store them in the maj_label_positions + $minScale = $aScale->scale[0]; + $maxScale = $aScale->scale[1]; + $j=0; + for($i=0; $i < $n ; ++$i ) { + // First make sure that the first tick is not lower than the lower scale value + if( !isset($this->iManualTickPos[$i]) || $this->iManualTickPos[$i] < $minScale || $this->iManualTickPos[$i] > $maxScale) { + continue; + } + $this->maj_ticks_pos[$j] = $aScale->Translate($this->iManualTickPos[$i]); + $this->maj_ticklabels_pos[$j] = $this->maj_ticks_pos[$j]; - $this->maj_ticks_pos[$j] = $aScale->Translate($this->iManualTickPos[$i]); - $this->maj_ticklabels_pos[$j] = $this->maj_ticks_pos[$j]; + // Set the minor tick marks the same as major if not specified + if( $m <= 0 ) { + $this->ticks_pos[$j] = $this->maj_ticks_pos[$j]; + } + if( $doLbl ) { + $this->maj_ticks_label[$j] = $this->iManualTickLabels[$i]; + } + else { + $this->maj_ticks_label[$j]=$this->_doLabelFormat($this->iManualTickPos[$i],$i,$n); + } + ++$j; + } - // Set the minor tick marks the same as major if not specified - if( $m <= 0 ) { - $this->ticks_pos[$j] = $this->maj_ticks_pos[$j]; - } + // Some sanity check + if( count($this->maj_ticks_pos) < 2 ) { + JpGraphError::RaiseL(25067);//('Your manually specified scale and ticks is not correct. The scale seems to be too small to hold any of the specified tickl marks.'); + } - if( $doLbl ) { - $this->maj_ticks_label[$j] = $this->iManualTickLabels[$i]; - } - else { - $this->maj_ticks_label[$j]=$this->_doLabelFormat($this->iManualTickPos[$i],$i,$n); - } - ++$j; - } - - // Some sanity check - if( count($this->maj_ticks_pos) < 2 ) { - JpGraphError::RaiseL(25067);//('Your manually specified scale and ticks is not correct. The scale seems to be too small to hold any of the specified tickl marks.'); - } - - // Setup the minor tick marks - $j=0; - for($i=0; $i < $m; ++$i ) { - if( empty($this->iManualMinTickPos[$i]) || - $this->iManualMinTickPos[$i] < $minScale || $this->iManualMinTickPos[$i] > $maxScale) - continue; - $this->ticks_pos[$j] = $aScale->Translate($this->iManualMinTickPos[$i]); - ++$j; - } + // Setup the minor tick marks + $j=0; + for($i=0; $i < $m; ++$i ) { + if( empty($this->iManualMinTickPos[$i]) || $this->iManualMinTickPos[$i] < $minScale || $this->iManualMinTickPos[$i] > $maxScale) { + continue; + } + $this->ticks_pos[$j] = $aScale->Translate($this->iManualMinTickPos[$i]); + ++$j; + } } function _doAutoTickPos($aScale) { - $maj_step_abs = $aScale->scale_factor*$this->major_step; - $min_step_abs = $aScale->scale_factor*$this->minor_step; + $maj_step_abs = $aScale->scale_factor*$this->major_step; + $min_step_abs = $aScale->scale_factor*$this->minor_step; - if( $min_step_abs==0 || $maj_step_abs==0 ) { - JpGraphError::RaiseL(25068);//("A plot has an illegal scale. This could for example be that you are trying to use text autoscaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')"); - } - // We need to make this an int since comparing it below - // with the result from round() can give wrong result, such that - // (40 < 40) == TRUE !!! - $limit = (int)$aScale->scale_abs[1]; + if( $min_step_abs==0 || $maj_step_abs==0 ) { + JpGraphError::RaiseL(25068);//("A plot has an illegal scale. This could for example be that you are trying to use text autoscaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')"); + } + // We need to make this an int since comparing it below + // with the result from round() can give wrong result, such that + // (40 < 40) == TRUE !!! + $limit = (int)$aScale->scale_abs[1]; - if( $aScale->textscale ) { - // This can only be true for a X-scale (horizontal) - // Define ticks for a text scale. This is slightly different from a - // normal linear type of scale since the position might be adjusted - // and the labels start at on - $label = (float)$aScale->GetMinVal()+$this->text_label_start+$this->label_offset; - $start_abs=$aScale->scale_factor*$this->text_label_start; - $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; + if( $aScale->textscale ) { + // This can only be true for a X-scale (horizontal) + // Define ticks for a text scale. This is slightly different from a + // normal linear type of scale since the position might be adjusted + // and the labels start at on + $label = (float)$aScale->GetMinVal()+$this->text_label_start+$this->label_offset; + $start_abs=$aScale->scale_factor*$this->text_label_start; + $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; - $x = $aScale->scale_abs[0]+$start_abs+$this->xlabel_offset*$min_step_abs; - for( $i=0; $label <= $aScale->GetMaxVal()+$this->label_offset; ++$i ) { - // Apply format to label - $this->maj_ticks_label[$i]=$this->_doLabelFormat($label,$i,$nbrmajticks); - $label+=$this->major_step; + $x = $aScale->scale_abs[0]+$start_abs+$this->xlabel_offset*$min_step_abs; + for( $i=0; $label <= $aScale->GetMaxVal()+$this->label_offset; ++$i ) { + // Apply format to label + $this->maj_ticks_label[$i]=$this->_doLabelFormat($label,$i,$nbrmajticks); + $label+=$this->major_step; - // The x-position of the tick marks can be different from the labels. - // Note that we record the tick position (not the label) so that the grid - // happen upon tick marks and not labels. - $xtick=$aScale->scale_abs[0]+$start_abs+$this->xtick_offset*$min_step_abs+$i*$maj_step_abs; - $this->maj_ticks_pos[$i]=$xtick; - $this->maj_ticklabels_pos[$i] = round($x); - $x += $maj_step_abs; - } - } - else { - $label = $aScale->GetMinVal(); - $abs_pos = $aScale->scale_abs[0]; - $j=0; $i=0; - $step = round($maj_step_abs/$min_step_abs); - if( $aScale->type == "x" ) { - // For a normal linear type of scale the major ticks will always be multiples - // of the minor ticks. In order to avoid any rounding issues the major ticks are - // defined as every "step" minor ticks and not calculated separately - $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; - while( round($abs_pos) <= $limit ) { - $this->ticks_pos[] = round($abs_pos); - $this->ticks_label[] = $label; - if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks ) { - $this->maj_ticks_pos[$j] = round($abs_pos); - $this->maj_ticklabels_pos[$j] = round($abs_pos); - $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks); - ++$j; - } - ++$i; - $abs_pos += $min_step_abs; - $label+=$this->minor_step; - } - } - elseif( $aScale->type == "y" ) { - $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal())/$this->major_step)+1; - while( round($abs_pos) >= $limit ) { - $this->ticks_pos[$i] = round($abs_pos); - $this->ticks_label[$i]=$label; - if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks) { - $this->maj_ticks_pos[$j] = round($abs_pos); - $this->maj_ticklabels_pos[$j] = round($abs_pos); - $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks); - ++$j; - } - ++$i; - $abs_pos += $min_step_abs; - $label += $this->minor_step; - } - } - } + // The x-position of the tick marks can be different from the labels. + // Note that we record the tick position (not the label) so that the grid + // happen upon tick marks and not labels. + $xtick=$aScale->scale_abs[0]+$start_abs+$this->xtick_offset*$min_step_abs+$i*$maj_step_abs; + $this->maj_ticks_pos[$i]=$xtick; + $this->maj_ticklabels_pos[$i] = round($x); + $x += $maj_step_abs; + } + } + else { + $label = $aScale->GetMinVal(); + $abs_pos = $aScale->scale_abs[0]; + $j=0; $i=0; + $step = round($maj_step_abs/$min_step_abs); + if( $aScale->type == "x" ) { + // For a normal linear type of scale the major ticks will always be multiples + // of the minor ticks. In order to avoid any rounding issues the major ticks are + // defined as every "step" minor ticks and not calculated separately + $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; + while( round($abs_pos) <= $limit ) { + $this->ticks_pos[] = round($abs_pos); + $this->ticks_label[] = $label; + if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks ) { + $this->maj_ticks_pos[$j] = round($abs_pos); + $this->maj_ticklabels_pos[$j] = round($abs_pos); + $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks); + ++$j; + } + ++$i; + $abs_pos += $min_step_abs; + $label+=$this->minor_step; + } + } + elseif( $aScale->type == "y" ) { + $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal())/$this->major_step)+1; + while( round($abs_pos) >= $limit ) { + $this->ticks_pos[$i] = round($abs_pos); + $this->ticks_label[$i]=$label; + if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks) { + $this->maj_ticks_pos[$j] = round($abs_pos); + $this->maj_ticklabels_pos[$j] = round($abs_pos); + $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks); + ++$j; + } + ++$i; + $abs_pos += $min_step_abs; + $label += $this->minor_step; + } + } + } } function AdjustForDST($aFlg=true) { - $this->iAdjustForDST = $aFlg; + $this->iAdjustForDST = $aFlg; } function _doLabelFormat($aVal,$aIdx,$aNbrTicks) { - // If precision hasn't been specified set it to a sensible value - if( $this->precision==-1 ) { - $t = log10($this->minor_step); - if( $t > 0 ) - $precision = 0; - else - $precision = -floor($t); - } - else - $precision = $this->precision; + // If precision hasn't been specified set it to a sensible value + if( $this->precision==-1 ) { + $t = log10($this->minor_step); + if( $t > 0 ) { + $precision = 0; + } + else { + $precision = -floor($t); + } + } + else { + $precision = $this->precision; + } - if( $this->label_formfunc != '' ) { - $f=$this->label_formfunc; - $l = call_user_func($f,$aVal); - } - elseif( $this->label_formatstr != '' || $this->label_dateformatstr != '' ) { - if( $this->label_usedateformat ) { - // Adjust the value to take daylight savings into account - if (date("I",$aVal)==1 && $this->iAdjustForDST ) // DST - $aVal+=3600; + if( $this->label_formfunc != '' ) { + $f=$this->label_formfunc; + $l = call_user_func($f,$aVal); + } + elseif( $this->label_formatstr != '' || $this->label_dateformatstr != '' ) { + if( $this->label_usedateformat ) { + // Adjust the value to take daylight savings into account + if (date("I",$aVal)==1 && $this->iAdjustForDST ) { + // DST + $aVal+=3600; + } - $l = date($this->label_formatstr,$aVal); - if( $this->label_formatstr == 'W' ) { - // If we use week formatting then add a single 'w' in front of the - // week number to differentiate it from dates - $l = 'w'.$l; - } - } - else { - if( $this->label_dateformatstr !== '' ) { - // Adjust the value to take daylight savings into account - if (date("I",$aVal)==1 && $this->iAdjustForDST ) // DST - $aVal+=3600; + $l = date($this->label_formatstr,$aVal); + if( $this->label_formatstr == 'W' ) { + // If we use week formatting then add a single 'w' in front of the + // week number to differentiate it from dates + $l = 'w'.$l; + } + } + else { + if( $this->label_dateformatstr !== '' ) { + // Adjust the value to take daylight savings into account + if (date("I",$aVal)==1 && $this->iAdjustForDST ) { + // DST + $aVal+=3600; + } - $l = date($this->label_dateformatstr,$aVal); - if( $this->label_formatstr == 'W' ) { - // If we use week formatting then add a single 'w' in front of the - // week number to differentiate it from dates - $l = 'w'.$l; - } - } - else - $l = sprintf($this->label_formatstr,$aVal); - } - } - else { - $l = sprintf('%01.'.$precision.'f',round($aVal,$precision)); - } - - if( ($this->supress_zerolabel && $l==0) || ($this->supress_first && $aIdx==0) || - ($this->supress_last && $aIdx==$aNbrTicks-1) ) { - $l=''; - } - return $l; + $l = date($this->label_dateformatstr,$aVal); + if( $this->label_formatstr == 'W' ) { + // If we use week formatting then add a single 'w' in front of the + // week number to differentiate it from dates + $l = 'w'.$l; + } + } + else { + $l = sprintf($this->label_formatstr,$aVal); + } + } + } + else { + $l = sprintf('%01.'.$precision.'f',round($aVal,$precision)); + } + + if( ($this->supress_zerolabel && $l==0) || ($this->supress_first && $aIdx==0) || ($this->supress_last && $aIdx==$aNbrTicks-1) ) { + $l=''; + } + return $l; } // Stroke ticks on either X or Y axis function _StrokeTicks($aImg,$aScale,$aPos) { - $hor = $aScale->type == 'x'; - $aImg->SetLineWeight($this->weight); + $hor = $aScale->type == 'x'; + $aImg->SetLineWeight($this->weight); - // We need to make this an int since comparing it below - // with the result from round() can give wrong result, such that - // (40 < 40) == TRUE !!! - $limit = (int)$aScale->scale_abs[1]; - - // A text scale doesn't have any minor ticks - if( !$aScale->textscale ) { - // Stroke minor ticks - $yu = $aPos - $this->direction*$this->GetMinTickAbsSize(); - $xr = $aPos + $this->direction*$this->GetMinTickAbsSize(); - $n = count($this->ticks_pos); - for($i=0; $i < $n; ++$i ) { - if( !$this->supress_tickmarks && !$this->supress_minor_tickmarks) { - if( $this->mincolor!="" ) $aImg->PushColor($this->mincolor); - if( $hor ) { - //if( $this->ticks_pos[$i] <= $limit ) - $aImg->Line($this->ticks_pos[$i],$aPos,$this->ticks_pos[$i],$yu); - } - else { - //if( $this->ticks_pos[$i] >= $limit ) - $aImg->Line($aPos,$this->ticks_pos[$i],$xr,$this->ticks_pos[$i]); - } - if( $this->mincolor!="" ) $aImg->PopColor(); - } - } - } + // We need to make this an int since comparing it below + // with the result from round() can give wrong result, such that + // (40 < 40) == TRUE !!! + $limit = (int)$aScale->scale_abs[1]; + + // A text scale doesn't have any minor ticks + if( !$aScale->textscale ) { + // Stroke minor ticks + $yu = $aPos - $this->direction*$this->GetMinTickAbsSize(); + $xr = $aPos + $this->direction*$this->GetMinTickAbsSize(); + $n = count($this->ticks_pos); + for($i=0; $i < $n; ++$i ) { + if( !$this->supress_tickmarks && !$this->supress_minor_tickmarks) { + if( $this->mincolor != '') { + $aImg->PushColor($this->mincolor); + } + if( $hor ) { + //if( $this->ticks_pos[$i] <= $limit ) + $aImg->Line($this->ticks_pos[$i],$aPos,$this->ticks_pos[$i],$yu); + } + else { + //if( $this->ticks_pos[$i] >= $limit ) + $aImg->Line($aPos,$this->ticks_pos[$i],$xr,$this->ticks_pos[$i]); + } + if( $this->mincolor != '' ) { + $aImg->PopColor(); + } + } + } + } + + // Stroke major ticks + $yu = $aPos - $this->direction*$this->GetMajTickAbsSize(); + $xr = $aPos + $this->direction*$this->GetMajTickAbsSize(); + $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; + $n = count($this->maj_ticks_pos); + for($i=0; $i < $n ; ++$i ) { + if(!($this->xtick_offset > 0 && $i==$nbrmajticks-1) && !$this->supress_tickmarks) { + if( $this->majcolor != '') { + $aImg->PushColor($this->majcolor); + } + if( $hor ) { + //if( $this->maj_ticks_pos[$i] <= $limit ) + $aImg->Line($this->maj_ticks_pos[$i],$aPos,$this->maj_ticks_pos[$i],$yu); + } + else { + //if( $this->maj_ticks_pos[$i] >= $limit ) + $aImg->Line($aPos,$this->maj_ticks_pos[$i],$xr,$this->maj_ticks_pos[$i]); + } + if( $this->majcolor != '') { + $aImg->PopColor(); + } + } + } - // Stroke major ticks - $yu = $aPos - $this->direction*$this->GetMajTickAbsSize(); - $xr = $aPos + $this->direction*$this->GetMajTickAbsSize(); - $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1; - $n = count($this->maj_ticks_pos); - for($i=0; $i < $n ; ++$i ) { - if(!($this->xtick_offset > 0 && $i==$nbrmajticks-1) && !$this->supress_tickmarks) { - if( $this->majcolor!="" ) $aImg->PushColor($this->majcolor); - if( $hor ) { - //if( $this->maj_ticks_pos[$i] <= $limit ) - $aImg->Line($this->maj_ticks_pos[$i],$aPos,$this->maj_ticks_pos[$i],$yu); - } - else { - //if( $this->maj_ticks_pos[$i] >= $limit ) - $aImg->Line($aPos,$this->maj_ticks_pos[$i],$xr,$this->maj_ticks_pos[$i]); - } - if( $this->majcolor!="" ) $aImg->PopColor(); - } - } - } // Draw linear ticks function Stroke($aImg,$aScale,$aPos) { - if( $this->iManualTickPos != NULL ) - $this->_doManualTickPos($aScale); - else - $this->_doAutoTickPos($aScale); - $this->_StrokeTicks($aImg,$aScale,$aPos, $aScale->type == 'x' ); + if( $this->iManualTickPos != NULL ) { + $this->_doManualTickPos($aScale); + } + else { + $this->_doAutoTickPos($aScale); + } + $this->_StrokeTicks($aImg,$aScale,$aPos, $aScale->type == 'x' ); } -//--------------- -// PRIVATE METHODS + //--------------- + // PRIVATE METHODS // Spoecify the offset of the displayed tick mark with the tick "space" - // Legal values for $o is [0,1] used to adjust where the tick marks and label + // Legal values for $o is [0,1] used to adjust where the tick marks and label // should be positioned within the major tick-size // $lo specifies the label offset and $to specifies the tick offset // this comes in handy for example in bar graphs where we wont no offset for the // tick but have the labels displayed halfway under the bars. function SetXLabelOffset($aLabelOff,$aTickOff=-1) { - $this->xlabel_offset=$aLabelOff; - if( $aTickOff==-1 ) // Same as label offset - $this->xtick_offset=$aLabelOff; - else - $this->xtick_offset=$aTickOff; - if( $aLabelOff>0 ) - $this->SupressLast(); // The last tick wont fit + $this->xlabel_offset=$aLabelOff; + if( $aTickOff==-1 ) { + // Same as label offset + $this->xtick_offset=$aLabelOff; + } + else { + $this->xtick_offset=$aTickOff; + } + if( $aLabelOff>0 ) { + $this->SupressLast(); // The last tick wont fit + } } // Which tick label should we start with? function SetTextLabelStart($aTextLabelOff) { - $this->text_label_start=$aTextLabelOff; + $this->text_label_start=$aTextLabelOff; } - + } // Class //=================================================== // CLASS LinearScale -// Description: Handle linear scaling between screen and world +// Description: Handle linear scaling between screen and world //=================================================== class LinearScale { public $textscale=false; // Just a flag to let the Plot class find out if @@ -4507,1476 +4429,546 @@ class LinearScale { public $name = 'lin'; public $auto_ticks=false; // When using manual scale should the ticks be automatically set? public $world_abs_size; // Plot area size in pixels (Needed public in jpgraph_radar.php) - public $world_size; // Plot area size in world coordinates + public $world_size; // Plot area size in world coordinates public $intscale=false; // Restrict autoscale to integers protected $autoscale_min=false; // Forced minimum value, auto determine max protected $autoscale_max=false; // Forced maximum value, auto determine min private $gracetop=0,$gracebottom=0; -//--------------- -// CONSTRUCTOR - function LinearScale($aMin=0,$aMax=0,$aType="y") { - assert($aType=="x" || $aType=="y" ); - assert($aMin<=$aMax); - - $this->type=$aType; - $this->scale=array($aMin,$aMax); - $this->world_size=$aMax-$aMin; - $this->ticks = new LinearTicks(); + + function __construct($aMin=0,$aMax=0,$aType='y') { + assert($aType=='x' || $aType=='y' ); + assert($aMin<=$aMax); + + $this->type=$aType; + $this->scale=array($aMin,$aMax); + $this->world_size=$aMax-$aMin; + $this->ticks = new LinearTicks(); } -//--------------- -// PUBLIC METHODS // Check if scale is set or if we should autoscale // We should do this is either scale or ticks has not been set function IsSpecified() { - if( $this->GetMinVal()==$this->GetMaxVal() ) { // Scale not set - return false; - } - return true; + if( $this->GetMinVal()==$this->GetMaxVal() ) { // Scale not set + return false; + } + return true; } - - // Set the minimum data value when the autoscaling is used. + + // Set the minimum data value when the autoscaling is used. // Usefull if you want a fix minimum (like 0) but have an // automatic maximum function SetAutoMin($aMin) { - $this->autoscale_min=$aMin; + $this->autoscale_min=$aMin; } - // Set the minimum data value when the autoscaling is used. + // Set the minimum data value when the autoscaling is used. // Usefull if you want a fix minimum (like 0) but have an // automatic maximum function SetAutoMax($aMax) { - $this->autoscale_max=$aMax; + $this->autoscale_max=$aMax; } // If the user manually specifies a scale should the ticks // still be set automatically? function SetAutoTicks($aFlag=true) { - $this->auto_ticks = $aFlag; + $this->auto_ticks = $aFlag; } // Specify scale "grace" value (top and bottom) function SetGrace($aGraceTop,$aGraceBottom=0) { - if( $aGraceTop<0 || $aGraceBottom < 0 ) - JpGraphError::RaiseL(25069);//(" Grace must be larger then 0"); - $this->gracetop=$aGraceTop; - $this->gracebottom=$aGraceBottom; + if( $aGraceTop<0 || $aGraceBottom < 0 ) { + JpGraphError::RaiseL(25069);//(" Grace must be larger then 0"); + } + $this->gracetop=$aGraceTop; + $this->gracebottom=$aGraceBottom; } - + // Get the minimum value in the scale function GetMinVal() { - return $this->scale[0]; + return $this->scale[0]; } - + // get maximum value for scale function GetMaxVal() { - return $this->scale[1]; + return $this->scale[1]; } - - // Specify a new min/max value for sclae + + // Specify a new min/max value for sclae function Update($aImg,$aMin,$aMax) { - $this->scale=array($aMin,$aMax); - $this->world_size=$aMax-$aMin; - $this->InitConstants($aImg); + $this->scale=array($aMin,$aMax); + $this->world_size=$aMax-$aMin; + $this->InitConstants($aImg); } - + // Translate between world and screen function Translate($aCoord) { - if( !is_numeric($aCoord) ) { - if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' ) - JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.'); - return 0; - } - else { - return $this->off+($aCoord - $this->scale[0]) * $this->scale_factor; - } + if( !is_numeric($aCoord) ) { + if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' ) { + JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.'); + } + return 0; + } + else { + return round($this->off+($aCoord - $this->scale[0]) * $this->scale_factor); + } } - + // Relative translate (don't include offset) usefull when we just want // to know the relative position (in pixels) on the axis function RelTranslate($aCoord) { - if( !is_numeric($aCoord) ) { - if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' ) - JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.'); - return 0; - } - else { - return ($aCoord - $this->scale[0]) * $this->scale_factor; - } + if( !is_numeric($aCoord) ) { + if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' ) { + JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.'); + } + return 0; + } + else { + return ($aCoord - $this->scale[0]) * $this->scale_factor; + } } - + // Restrict autoscaling to only use integers function SetIntScale($aIntScale=true) { - $this->intscale=$aIntScale; + $this->intscale=$aIntScale; } - + // Calculate an integer autoscale function IntAutoScale($img,$min,$max,$maxsteps,$majend=true) { - // Make sure limits are integers - $min=floor($min); - $max=ceil($max); - if( abs($min-$max)==0 ) { - --$min; ++$max; - } - $maxsteps = floor($maxsteps); - - $gracetop=round(($this->gracetop/100.0)*abs($max-$min)); - $gracebottom=round(($this->gracebottom/100.0)*abs($max-$min)); - if( is_numeric($this->autoscale_min) ) { - $min = ceil($this->autoscale_min); - if( $min >= $max ) { - JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.'); - } - } + // Make sure limits are integers + $min=floor($min); + $max=ceil($max); + if( abs($min-$max)==0 ) { + --$min; ++$max; + } + $maxsteps = floor($maxsteps); - if( is_numeric($this->autoscale_max) ) { - $max = ceil($this->autoscale_max); - if( $min >= $max ) { - JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.'); - } - } + $gracetop=round(($this->gracetop/100.0)*abs($max-$min)); + $gracebottom=round(($this->gracebottom/100.0)*abs($max-$min)); + if( is_numeric($this->autoscale_min) ) { + $min = ceil($this->autoscale_min); + if( $min >= $max ) { + JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.'); + } + } - if( abs($min-$max ) == 0 ) { - ++$max; - --$min; - } - - $min -= $gracebottom; - $max += $gracetop; + if( is_numeric($this->autoscale_max) ) { + $max = ceil($this->autoscale_max); + if( $min >= $max ) { + JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.'); + } + } - // First get tickmarks as multiples of 1, 10, ... - if( $majend ) { - list($num1steps,$adj1min,$adj1max,$maj1step) = - $this->IntCalcTicks($maxsteps,$min,$max,1); - } - else { - $adj1min = $min; - $adj1max = $max; - list($num1steps,$maj1step) = - $this->IntCalcTicksFreeze($maxsteps,$min,$max,1); - } + if( abs($min-$max ) == 0 ) { + ++$max; + --$min; + } - if( abs($min-$max) > 2 ) { - // Then get tick marks as 2:s 2, 20, ... - if( $majend ) { - list($num2steps,$adj2min,$adj2max,$maj2step) = - $this->IntCalcTicks($maxsteps,$min,$max,5); - } - else { - $adj2min = $min; - $adj2max = $max; - list($num2steps,$maj2step) = - $this->IntCalcTicksFreeze($maxsteps,$min,$max,5); - } - } - else { - $num2steps = 10000; // Dummy high value so we don't choose this - } - - if( abs($min-$max) > 5 ) { - // Then get tickmarks as 5:s 5, 50, 500, ... - if( $majend ) { - list($num5steps,$adj5min,$adj5max,$maj5step) = - $this->IntCalcTicks($maxsteps,$min,$max,2); - } - else { - $adj5min = $min; - $adj5max = $max; - list($num5steps,$maj5step) = - $this->IntCalcTicksFreeze($maxsteps,$min,$max,2); - } - } - else { - $num5steps = 10000; // Dummy high value so we don't choose this - } - - // Check to see whichof 1:s, 2:s or 5:s fit better with - // the requested number of major ticks - $match1=abs($num1steps-$maxsteps); - $match2=abs($num2steps-$maxsteps); - if( !empty($maj5step) && $maj5step > 1 ) - $match5=abs($num5steps-$maxsteps); - else - $match5=10000; // Dummy high value - - // Compare these three values and see which is the closest match - // We use a 0.6 weight to gravitate towards multiple of 5:s - if( $match1 < $match2 ) { - if( $match1 < $match5 ) - $r=1; - else - $r=3; - } - else { - if( $match2 < $match5 ) - $r=2; - else - $r=3; - } - // Minsteps are always the same as maxsteps for integer scale - switch( $r ) { - case 1: - $this->ticks->Set($maj1step,$maj1step); - $this->Update($img,$adj1min,$adj1max); - break; - case 2: - $this->ticks->Set($maj2step,$maj2step); - $this->Update($img,$adj2min,$adj2max); - break; - case 3: - $this->ticks->Set($maj5step,$maj5step); - $this->Update($img,$adj5min,$adj5max); - break; - default: - JpGraphError::RaiseL(25073,$r);//('Internal error. Integer scale algorithm comparison out of bound (r=$r)'); - } + $min -= $gracebottom; + $max += $gracetop; + + // First get tickmarks as multiples of 1, 10, ... + if( $majend ) { + list($num1steps,$adj1min,$adj1max,$maj1step) = $this->IntCalcTicks($maxsteps,$min,$max,1); + } + else { + $adj1min = $min; + $adj1max = $max; + list($num1steps,$maj1step) = $this->IntCalcTicksFreeze($maxsteps,$min,$max,1); + } + + if( abs($min-$max) > 2 ) { + // Then get tick marks as 2:s 2, 20, ... + if( $majend ) { + list($num2steps,$adj2min,$adj2max,$maj2step) = $this->IntCalcTicks($maxsteps,$min,$max,5); + } + else { + $adj2min = $min; + $adj2max = $max; + list($num2steps,$maj2step) = $this->IntCalcTicksFreeze($maxsteps,$min,$max,5); + } + } + else { + $num2steps = 10000; // Dummy high value so we don't choose this + } + + if( abs($min-$max) > 5 ) { + // Then get tickmarks as 5:s 5, 50, 500, ... + if( $majend ) { + list($num5steps,$adj5min,$adj5max,$maj5step) = $this->IntCalcTicks($maxsteps,$min,$max,2); + } + else { + $adj5min = $min; + $adj5max = $max; + list($num5steps,$maj5step) = $this->IntCalcTicksFreeze($maxsteps,$min,$max,2); + } + } + else { + $num5steps = 10000; // Dummy high value so we don't choose this + } + + // Check to see whichof 1:s, 2:s or 5:s fit better with + // the requested number of major ticks + $match1=abs($num1steps-$maxsteps); + $match2=abs($num2steps-$maxsteps); + if( !empty($maj5step) && $maj5step > 1 ) { + $match5=abs($num5steps-$maxsteps); + } + else { + $match5=10000; // Dummy high value + } + + // Compare these three values and see which is the closest match + // We use a 0.6 weight to gravitate towards multiple of 5:s + if( $match1 < $match2 ) { + if( $match1 < $match5 ) $r=1; + else $r=3; + } + else { + if( $match2 < $match5 ) $r=2; + else $r=3; + } + // Minsteps are always the same as maxsteps for integer scale + switch( $r ) { + case 1: + $this->ticks->Set($maj1step,$maj1step); + $this->Update($img,$adj1min,$adj1max); + break; + case 2: + $this->ticks->Set($maj2step,$maj2step); + $this->Update($img,$adj2min,$adj2max); + break; + case 3: + $this->ticks->Set($maj5step,$maj5step); + $this->Update($img,$adj5min,$adj5max); + break; + default: + JpGraphError::RaiseL(25073,$r);//('Internal error. Integer scale algorithm comparison out of bound (r=$r)'); + } } - - + + // Calculate autoscale. Used if user hasn't given a scale and ticks // $maxsteps is the maximum number of major tickmarks allowed. function AutoScale($img,$min,$max,$maxsteps,$majend=true) { - if( $this->intscale ) { - $this->IntAutoScale($img,$min,$max,$maxsteps,$majend); - return; - } - if( abs($min-$max) < 0.00001 ) { - // We need some difference to be able to autoscale - // make it 5% above and 5% below value - if( $min==0 && $max==0 ) { // Special case - $min=-1; $max=1; - } - else { - $delta = (abs($max)+abs($min))*0.005; - $min -= $delta; - $max += $delta; - } - } - - $gracetop=($this->gracetop/100.0)*abs($max-$min); - $gracebottom=($this->gracebottom/100.0)*abs($max-$min); - if( is_numeric($this->autoscale_min) ) { - $min = $this->autoscale_min; - if( $min >= $max ) { - JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.'); - } - if( abs($min-$max ) < 0.00001 ) - $max *= 1.2; - } + if( $this->intscale ) { + $this->IntAutoScale($img,$min,$max,$maxsteps,$majend); + return; + } + if( abs($min-$max) < 0.00001 ) { + // We need some difference to be able to autoscale + // make it 5% above and 5% below value + if( $min==0 && $max==0 ) { // Special case + $min=-1; $max=1; + } + else { + $delta = (abs($max)+abs($min))*0.005; + $min -= $delta; + $max += $delta; + } + } - if( is_numeric($this->autoscale_max) ) { - $max = $this->autoscale_max; - if( $min >= $max ) { - JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.'); - } - if( abs($min-$max ) < 0.00001 ) - $min *= 0.8; - } + $gracetop=($this->gracetop/100.0)*abs($max-$min); + $gracebottom=($this->gracebottom/100.0)*abs($max-$min); + if( is_numeric($this->autoscale_min) ) { + $min = $this->autoscale_min; + if( $min >= $max ) { + JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.'); + } + if( abs($min-$max ) < 0.001 ) { + $max *= 1.2; + } + } - $min -= $gracebottom; - $max += $gracetop; + if( is_numeric($this->autoscale_max) ) { + $max = $this->autoscale_max; + if( $min >= $max ) { + JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.'); + } + if( abs($min-$max ) < 0.001 ) { + $min *= 0.8; + } + } + $min -= $gracebottom; + $max += $gracetop; - // First get tickmarks as multiples of 0.1, 1, 10, ... - if( $majend ) { - list($num1steps,$adj1min,$adj1max,$min1step,$maj1step) = - $this->CalcTicks($maxsteps,$min,$max,1,2); - } - else { - $adj1min=$min; - $adj1max=$max; - list($num1steps,$min1step,$maj1step) = - $this->CalcTicksFreeze($maxsteps,$min,$max,1,2,false); - } - - // Then get tick marks as 2:s 0.2, 2, 20, ... - if( $majend ) { - list($num2steps,$adj2min,$adj2max,$min2step,$maj2step) = - $this->CalcTicks($maxsteps,$min,$max,5,2); - } - else { - $adj2min=$min; - $adj2max=$max; - list($num2steps,$min2step,$maj2step) = - $this->CalcTicksFreeze($maxsteps,$min,$max,5,2,false); - } - - // Then get tickmarks as 5:s 0.05, 0.5, 5, 50, ... - if( $majend ) { - list($num5steps,$adj5min,$adj5max,$min5step,$maj5step) = - $this->CalcTicks($maxsteps,$min,$max,2,5); - } - else { - $adj5min=$min; - $adj5max=$max; - list($num5steps,$min5step,$maj5step) = - $this->CalcTicksFreeze($maxsteps,$min,$max,2,5,false); - } + // First get tickmarks as multiples of 0.1, 1, 10, ... + if( $majend ) { + list($num1steps,$adj1min,$adj1max,$min1step,$maj1step) = $this->CalcTicks($maxsteps,$min,$max,1,2); + } + else { + $adj1min=$min; + $adj1max=$max; + list($num1steps,$min1step,$maj1step) = $this->CalcTicksFreeze($maxsteps,$min,$max,1,2,false); + } - // Check to see whichof 1:s, 2:s or 5:s fit better with - // the requested number of major ticks - $match1=abs($num1steps-$maxsteps); - $match2=abs($num2steps-$maxsteps); - $match5=abs($num5steps-$maxsteps); - // Compare these three values and see which is the closest match - // We use a 0.8 weight to gravitate towards multiple of 5:s - $r=$this->MatchMin3($match1,$match2,$match5,0.8); - switch( $r ) { - case 1: - $this->Update($img,$adj1min,$adj1max); - $this->ticks->Set($maj1step,$min1step); - break; - case 2: - $this->Update($img,$adj2min,$adj2max); - $this->ticks->Set($maj2step,$min2step); - break; - case 3: - $this->Update($img,$adj5min,$adj5max); - $this->ticks->Set($maj5step,$min5step); - break; - } + // Then get tick marks as 2:s 0.2, 2, 20, ... + if( $majend ) { + list($num2steps,$adj2min,$adj2max,$min2step,$maj2step) = $this->CalcTicks($maxsteps,$min,$max,5,2); + } + else { + $adj2min=$min; + $adj2max=$max; + list($num2steps,$min2step,$maj2step) = $this->CalcTicksFreeze($maxsteps,$min,$max,5,2,false); + } + + // Then get tickmarks as 5:s 0.05, 0.5, 5, 50, ... + if( $majend ) { + list($num5steps,$adj5min,$adj5max,$min5step,$maj5step) = $this->CalcTicks($maxsteps,$min,$max,2,5); + } + else { + $adj5min=$min; + $adj5max=$max; + list($num5steps,$min5step,$maj5step) = $this->CalcTicksFreeze($maxsteps,$min,$max,2,5,false); + } + + // Check to see whichof 1:s, 2:s or 5:s fit better with + // the requested number of major ticks + $match1=abs($num1steps-$maxsteps); + $match2=abs($num2steps-$maxsteps); + $match5=abs($num5steps-$maxsteps); + + // Compare these three values and see which is the closest match + // We use a 0.8 weight to gravitate towards multiple of 5:s + $r=$this->MatchMin3($match1,$match2,$match5,0.8); + switch( $r ) { + case 1: + $this->Update($img,$adj1min,$adj1max); + $this->ticks->Set($maj1step,$min1step); + break; + case 2: + $this->Update($img,$adj2min,$adj2max); + $this->ticks->Set($maj2step,$min2step); + break; + case 3: + $this->Update($img,$adj5min,$adj5max); + $this->ticks->Set($maj5step,$min5step); + break; + } } -//--------------- -// PRIVATE METHODS + //--------------- + // PRIVATE METHODS // This method recalculates all constants that are depending on the // margins in the image. If the margins in the image are changed // this method should be called for every scale that is registred with // that image. Should really be installed as an observer of that image. function InitConstants($img) { - if( $this->type=="x" ) { - $this->world_abs_size=$img->width - $img->left_margin - $img->right_margin; - $this->off=$img->left_margin; - $this->scale_factor = 0; - if( $this->world_size > 0 ) - $this->scale_factor=$this->world_abs_size/($this->world_size*1.0); - } - else { // y scale - $this->world_abs_size=$img->height - $img->top_margin - $img->bottom_margin; - $this->off=$img->top_margin+$this->world_abs_size; - $this->scale_factor = 0; - if( $this->world_size > 0 ) - $this->scale_factor=-$this->world_abs_size/($this->world_size*1.0); - } - $size = $this->world_size * $this->scale_factor; - $this->scale_abs=array($this->off,$this->off + $size); + if( $this->type=='x' ) { + $this->world_abs_size=$img->width - $img->left_margin - $img->right_margin; + $this->off=$img->left_margin; + $this->scale_factor = 0; + if( $this->world_size > 0 ) { + $this->scale_factor=$this->world_abs_size/($this->world_size*1.0); + } + } + else { // y scale + $this->world_abs_size=$img->height - $img->top_margin - $img->bottom_margin; + $this->off=$img->top_margin+$this->world_abs_size; + $this->scale_factor = 0; + if( $this->world_size > 0 ) { + $this->scale_factor=-$this->world_abs_size/($this->world_size*1.0); + } + } + $size = $this->world_size * $this->scale_factor; + $this->scale_abs=array($this->off,$this->off + $size); } - + // Initialize the conversion constants for this scale // This tries to pre-calculate as much as possible to speed up the // actual conversion (with Translate()) later on - // $start =scale start in absolute pixels (for x-scale this is an y-position - // and for an y-scale this is an x-position - // $len =absolute length in pixels of scale + // $start =scale start in absolute pixels (for x-scale this is an y-position + // and for an y-scale this is an x-position + // $len =absolute length in pixels of scale function SetConstants($aStart,$aLen) { - $this->world_abs_size=$aLen; - $this->off=$aStart; - - if( $this->world_size<=0 ) { - // This should never ever happen !! - JpGraphError::RaiseL(25074); -//("You have unfortunately stumbled upon a bug in JpGraph. It seems like the scale range is ".$this->world_size." [for ".$this->type." scale]
Please report Bug #01 to jpgraph@aditus.nu and include the script that gave this error. This problem could potentially be caused by trying to use \"illegal\" values in the input data arrays (like trying to send in strings or only NULL values) which causes the autoscaling to fail."); + $this->world_abs_size=$aLen; + $this->off=$aStart; - } - - // scale_factor = number of pixels per world unit - $this->scale_factor=$this->world_abs_size/($this->world_size*1.0); - - // scale_abs = start and end points of scale in absolute pixels - $this->scale_abs=array($this->off,$this->off+$this->world_size*$this->scale_factor); + if( $this->world_size<=0 ) { + // This should never ever happen !! + JpGraphError::RaiseL(25074); + //("You have unfortunately stumbled upon a bug in JpGraph. It seems like the scale range is ".$this->world_size." [for ".$this->type." scale]
Please report Bug #01 to jpgraph@aditus.nu and include the script that gave this error. This problem could potentially be caused by trying to use \"illegal\" values in the input data arrays (like trying to send in strings or only NULL values) which causes the autoscaling to fail."); + } + + // scale_factor = number of pixels per world unit + $this->scale_factor=$this->world_abs_size/($this->world_size*1.0); + + // scale_abs = start and end points of scale in absolute pixels + $this->scale_abs=array($this->off,$this->off+$this->world_size*$this->scale_factor); } - - + + // Calculate number of ticks steps with a specific division // $a is the divisor of 10**x to generate the first maj tick intervall // $a=1, $b=2 give major ticks with multiple of 10, ...,0.1,1,10,... // $a=5, $b=2 give major ticks with multiple of 2:s ...,0.2,2,20,... // $a=2, $b=5 give major ticks with multiple of 5:s ...,0.5,5,50,... // We return a vector of - // [$numsteps,$adjmin,$adjmax,$minstep,$majstep] + // [$numsteps,$adjmin,$adjmax,$minstep,$majstep] // If $majend==true then the first and last marks on the axis will be major // labeled tick marks otherwise it will be adjusted to the closest min tick mark function CalcTicks($maxsteps,$min,$max,$a,$b,$majend=true) { - $diff=$max-$min; - if( $diff==0 ) - $ld=0; - else - $ld=floor(log10($diff)); + $diff=$max-$min; + if( $diff==0 ) { + $ld=0; + } + else { + $ld=floor(log10($diff)); + } - // Gravitate min towards zero if we are close - if( $min>0 && $min < pow(10,$ld) ) $min=0; - - //$majstep=pow(10,$ld-1)/$a; - $majstep=pow(10,$ld)/$a; - $minstep=$majstep/$b; - - $adjmax=ceil($max/$minstep)*$minstep; - $adjmin=floor($min/$minstep)*$minstep; - $adjdiff = $adjmax-$adjmin; - $numsteps=$adjdiff/$majstep; - - while( $numsteps>$maxsteps ) { - $majstep=pow(10,$ld)/$a; - $numsteps=$adjdiff/$majstep; - ++$ld; - } + // Gravitate min towards zero if we are close + if( $min>0 && $min < pow(10,$ld) ) $min=0; - $minstep=$majstep/$b; - $adjmin=floor($min/$minstep)*$minstep; - $adjdiff = $adjmax-$adjmin; - if( $majend ) { - $adjmin = floor($min/$majstep)*$majstep; - $adjdiff = $adjmax-$adjmin; - $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin; - } - else - $adjmax=ceil($max/$minstep)*$minstep; + //$majstep=pow(10,$ld-1)/$a; + $majstep=pow(10,$ld)/$a; + $minstep=$majstep/$b; - return array($numsteps,$adjmin,$adjmax,$minstep,$majstep); + $adjmax=ceil($max/$minstep)*$minstep; + $adjmin=floor($min/$minstep)*$minstep; + $adjdiff = $adjmax-$adjmin; + $numsteps=$adjdiff/$majstep; + + while( $numsteps>$maxsteps ) { + $majstep=pow(10,$ld)/$a; + $numsteps=$adjdiff/$majstep; + ++$ld; + } + + $minstep=$majstep/$b; + $adjmin=floor($min/$minstep)*$minstep; + $adjdiff = $adjmax-$adjmin; + if( $majend ) { + $adjmin = floor($min/$majstep)*$majstep; + $adjdiff = $adjmax-$adjmin; + $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin; + } + else { + $adjmax=ceil($max/$minstep)*$minstep; + } + + return array($numsteps,$adjmin,$adjmax,$minstep,$majstep); } function CalcTicksFreeze($maxsteps,$min,$max,$a,$b) { - // Same as CalcTicks but don't adjust min/max values - $diff=$max-$min; - if( $diff==0 ) - $ld=0; - else - $ld=floor(log10($diff)); + // Same as CalcTicks but don't adjust min/max values + $diff=$max-$min; + if( $diff==0 ) { + $ld=0; + } + else { + $ld=floor(log10($diff)); + } - //$majstep=pow(10,$ld-1)/$a; - $majstep=pow(10,$ld)/$a; - $minstep=$majstep/$b; - $numsteps=floor($diff/$majstep); - - while( $numsteps > $maxsteps ) { - $majstep=pow(10,$ld)/$a; - $numsteps=floor($diff/$majstep); - ++$ld; - } - $minstep=$majstep/$b; - return array($numsteps,$minstep,$majstep); + //$majstep=pow(10,$ld-1)/$a; + $majstep=pow(10,$ld)/$a; + $minstep=$majstep/$b; + $numsteps=floor($diff/$majstep); + + while( $numsteps > $maxsteps ) { + $majstep=pow(10,$ld)/$a; + $numsteps=floor($diff/$majstep); + ++$ld; + } + $minstep=$majstep/$b; + return array($numsteps,$minstep,$majstep); } - - function IntCalcTicks($maxsteps,$min,$max,$a,$majend=true) { - $diff=$max-$min; - if( $diff==0 ) - JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.'); - else - $ld=floor(log10($diff)); - - // Gravitate min towards zero if we are close - if( $min>0 && $min < pow(10,$ld) ) $min=0; - - if( $ld == 0 ) $ld=1; - - if( $a == 1 ) - $majstep = 1; - else - $majstep=pow(10,$ld)/$a; - $adjmax=ceil($max/$majstep)*$majstep; - $adjmin=floor($min/$majstep)*$majstep; - $adjdiff = $adjmax-$adjmin; - $numsteps=$adjdiff/$majstep; - while( $numsteps>$maxsteps ) { - $majstep=pow(10,$ld)/$a; - $numsteps=$adjdiff/$majstep; - ++$ld; - } - - $adjmin=floor($min/$majstep)*$majstep; - $adjdiff = $adjmax-$adjmin; - if( $majend ) { - $adjmin = floor($min/$majstep)*$majstep; - $adjdiff = $adjmax-$adjmin; - $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin; - } - else - $adjmax=ceil($max/$majstep)*$majstep; - - return array($numsteps,$adjmin,$adjmax,$majstep); + function IntCalcTicks($maxsteps,$min,$max,$a,$majend=true) { + $diff=$max-$min; + if( $diff==0 ) { + JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.'); + } + else { + $ld=floor(log10($diff)); + } + + // Gravitate min towards zero if we are close + if( $min>0 && $min < pow(10,$ld) ) { + $min=0; + } + if( $ld == 0 ) { + $ld=1; + } + if( $a == 1 ) { + $majstep = 1; + } + else { + $majstep=pow(10,$ld)/$a; + } + $adjmax=ceil($max/$majstep)*$majstep; + + $adjmin=floor($min/$majstep)*$majstep; + $adjdiff = $adjmax-$adjmin; + $numsteps=$adjdiff/$majstep; + while( $numsteps>$maxsteps ) { + $majstep=pow(10,$ld)/$a; + $numsteps=$adjdiff/$majstep; + ++$ld; + } + + $adjmin=floor($min/$majstep)*$majstep; + $adjdiff = $adjmax-$adjmin; + if( $majend ) { + $adjmin = floor($min/$majstep)*$majstep; + $adjdiff = $adjmax-$adjmin; + $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin; + } + else { + $adjmax=ceil($max/$majstep)*$majstep; + } + + return array($numsteps,$adjmin,$adjmax,$majstep); } function IntCalcTicksFreeze($maxsteps,$min,$max,$a) { - // Same as IntCalcTick but don't change min/max values - $diff=$max-$min; - if( $diff==0 ) - JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.'); - else - $ld=floor(log10($diff)); - - if( $ld == 0 ) $ld=1; - - if( $a == 1 ) - $majstep = 1; - else - $majstep=pow(10,$ld)/$a; + // Same as IntCalcTick but don't change min/max values + $diff=$max-$min; + if( $diff==0 ) { + JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.'); + } + else { + $ld=floor(log10($diff)); + } + if( $ld == 0 ) { + $ld=1; + } + if( $a == 1 ) { + $majstep = 1; + } + else { + $majstep=pow(10,$ld)/$a; + } - $numsteps=floor($diff/$majstep); - while( $numsteps > $maxsteps ) { - $majstep=pow(10,$ld)/$a; - $numsteps=floor($diff/$majstep); - ++$ld; - } - - return array($numsteps,$majstep); + $numsteps=floor($diff/$majstep); + while( $numsteps > $maxsteps ) { + $majstep=pow(10,$ld)/$a; + $numsteps=floor($diff/$majstep); + ++$ld; + } + + return array($numsteps,$majstep); } - - // Determine the minimum of three values witha weight for last value function MatchMin3($a,$b,$c,$weight) { - if( $a < $b ) { - if( $a < ($c*$weight) ) - return 1; // $a smallest - else - return 3; // $c smallest - } - elseif( $b < ($c*$weight) ) - return 2; // $b smallest - return 3; // $c smallest + if( $a < $b ) { + if( $a < ($c*$weight) ) { + return 1; // $a smallest + } + else { + return 3; // $c smallest + } + } + elseif( $b < ($c*$weight) ) { + return 2; // $b smallest + } + return 3; // $c smallest } } // Class -//=================================================== -// CLASS RGB -// Description: Color definitions as RGB triples -//=================================================== -class RGB { - public $rgb_table; - public $img; - - function RGB($aImg=null) { - $this->img = $aImg; - - // Conversion array between color names and RGB - $this->rgb_table = array( - "aqua"=> array(0,255,255), - "lime"=> array(0,255,0), - "teal"=> array(0,128,128), - "whitesmoke"=>array(245,245,245), - "gainsboro"=>array(220,220,220), - "oldlace"=>array(253,245,230), - "linen"=>array(250,240,230), - "antiquewhite"=>array(250,235,215), - "papayawhip"=>array(255,239,213), - "blanchedalmond"=>array(255,235,205), - "bisque"=>array(255,228,196), - "peachpuff"=>array(255,218,185), - "navajowhite"=>array(255,222,173), - "moccasin"=>array(255,228,181), - "cornsilk"=>array(255,248,220), - "ivory"=>array(255,255,240), - "lemonchiffon"=>array(255,250,205), - "seashell"=>array(255,245,238), - "mintcream"=>array(245,255,250), - "azure"=>array(240,255,255), - "aliceblue"=>array(240,248,255), - "lavender"=>array(230,230,250), - "lavenderblush"=>array(255,240,245), - "mistyrose"=>array(255,228,225), - "white"=>array(255,255,255), - "black"=>array(0,0,0), - "darkslategray"=>array(47,79,79), - "dimgray"=>array(105,105,105), - "slategray"=>array(112,128,144), - "lightslategray"=>array(119,136,153), - "gray"=>array(190,190,190), - "lightgray"=>array(211,211,211), - "midnightblue"=>array(25,25,112), - "navy"=>array(0,0,128), - "cornflowerblue"=>array(100,149,237), - "darkslateblue"=>array(72,61,139), - "slateblue"=>array(106,90,205), - "mediumslateblue"=>array(123,104,238), - "lightslateblue"=>array(132,112,255), - "mediumblue"=>array(0,0,205), - "royalblue"=>array(65,105,225), - "blue"=>array(0,0,255), - "dodgerblue"=>array(30,144,255), - "deepskyblue"=>array(0,191,255), - "skyblue"=>array(135,206,235), - "lightskyblue"=>array(135,206,250), - "steelblue"=>array(70,130,180), - "lightred"=>array(211,167,168), - "lightsteelblue"=>array(176,196,222), - "lightblue"=>array(173,216,230), - "powderblue"=>array(176,224,230), - "paleturquoise"=>array(175,238,238), - "darkturquoise"=>array(0,206,209), - "mediumturquoise"=>array(72,209,204), - "turquoise"=>array(64,224,208), - "cyan"=>array(0,255,255), - "lightcyan"=>array(224,255,255), - "cadetblue"=>array(95,158,160), - "mediumaquamarine"=>array(102,205,170), - "aquamarine"=>array(127,255,212), - "darkgreen"=>array(0,100,0), - "darkolivegreen"=>array(85,107,47), - "darkseagreen"=>array(143,188,143), - "seagreen"=>array(46,139,87), - "mediumseagreen"=>array(60,179,113), - "lightseagreen"=>array(32,178,170), - "palegreen"=>array(152,251,152), - "springgreen"=>array(0,255,127), - "lawngreen"=>array(124,252,0), - "green"=>array(0,255,0), - "chartreuse"=>array(127,255,0), - "mediumspringgreen"=>array(0,250,154), - "greenyellow"=>array(173,255,47), - "limegreen"=>array(50,205,50), - "yellowgreen"=>array(154,205,50), - "forestgreen"=>array(34,139,34), - "olivedrab"=>array(107,142,35), - "darkkhaki"=>array(189,183,107), - "khaki"=>array(240,230,140), - "palegoldenrod"=>array(238,232,170), - "lightgoldenrodyellow"=>array(250,250,210), - "lightyellow"=>array(255,255,200), - "yellow"=>array(255,255,0), - "gold"=>array(255,215,0), - "lightgoldenrod"=>array(238,221,130), - "goldenrod"=>array(218,165,32), - "darkgoldenrod"=>array(184,134,11), - "rosybrown"=>array(188,143,143), - "indianred"=>array(205,92,92), - "saddlebrown"=>array(139,69,19), - "sienna"=>array(160,82,45), - "peru"=>array(205,133,63), - "burlywood"=>array(222,184,135), - "beige"=>array(245,245,220), - "wheat"=>array(245,222,179), - "sandybrown"=>array(244,164,96), - "tan"=>array(210,180,140), - "chocolate"=>array(210,105,30), - "firebrick"=>array(178,34,34), - "brown"=>array(165,42,42), - "darksalmon"=>array(233,150,122), - "salmon"=>array(250,128,114), - "lightsalmon"=>array(255,160,122), - "orange"=>array(255,165,0), - "darkorange"=>array(255,140,0), - "coral"=>array(255,127,80), - "lightcoral"=>array(240,128,128), - "tomato"=>array(255,99,71), - "orangered"=>array(255,69,0), - "red"=>array(255,0,0), - "hotpink"=>array(255,105,180), - "deeppink"=>array(255,20,147), - "pink"=>array(255,192,203), - "lightpink"=>array(255,182,193), - "palevioletred"=>array(219,112,147), - "maroon"=>array(176,48,96), - "mediumvioletred"=>array(199,21,133), - "violetred"=>array(208,32,144), - "magenta"=>array(255,0,255), - "violet"=>array(238,130,238), - "plum"=>array(221,160,221), - "orchid"=>array(218,112,214), - "mediumorchid"=>array(186,85,211), - "darkorchid"=>array(153,50,204), - "darkviolet"=>array(148,0,211), - "blueviolet"=>array(138,43,226), - "purple"=>array(160,32,240), - "mediumpurple"=>array(147,112,219), - "thistle"=>array(216,191,216), - "snow1"=>array(255,250,250), - "snow2"=>array(238,233,233), - "snow3"=>array(205,201,201), - "snow4"=>array(139,137,137), - "seashell1"=>array(255,245,238), - "seashell2"=>array(238,229,222), - "seashell3"=>array(205,197,191), - "seashell4"=>array(139,134,130), - "AntiqueWhite1"=>array(255,239,219), - "AntiqueWhite2"=>array(238,223,204), - "AntiqueWhite3"=>array(205,192,176), - "AntiqueWhite4"=>array(139,131,120), - "bisque1"=>array(255,228,196), - "bisque2"=>array(238,213,183), - "bisque3"=>array(205,183,158), - "bisque4"=>array(139,125,107), - "peachPuff1"=>array(255,218,185), - "peachpuff2"=>array(238,203,173), - "peachpuff3"=>array(205,175,149), - "peachpuff4"=>array(139,119,101), - "navajowhite1"=>array(255,222,173), - "navajowhite2"=>array(238,207,161), - "navajowhite3"=>array(205,179,139), - "navajowhite4"=>array(139,121,94), - "lemonchiffon1"=>array(255,250,205), - "lemonchiffon2"=>array(238,233,191), - "lemonchiffon3"=>array(205,201,165), - "lemonchiffon4"=>array(139,137,112), - "ivory1"=>array(255,255,240), - "ivory2"=>array(238,238,224), - "ivory3"=>array(205,205,193), - "ivory4"=>array(139,139,131), - "honeydew"=>array(193,205,193), - "lavenderblush1"=>array(255,240,245), - "lavenderblush2"=>array(238,224,229), - "lavenderblush3"=>array(205,193,197), - "lavenderblush4"=>array(139,131,134), - "mistyrose1"=>array(255,228,225), - "mistyrose2"=>array(238,213,210), - "mistyrose3"=>array(205,183,181), - "mistyrose4"=>array(139,125,123), - "azure1"=>array(240,255,255), - "azure2"=>array(224,238,238), - "azure3"=>array(193,205,205), - "azure4"=>array(131,139,139), - "slateblue1"=>array(131,111,255), - "slateblue2"=>array(122,103,238), - "slateblue3"=>array(105,89,205), - "slateblue4"=>array(71,60,139), - "royalblue1"=>array(72,118,255), - "royalblue2"=>array(67,110,238), - "royalblue3"=>array(58,95,205), - "royalblue4"=>array(39,64,139), - "dodgerblue1"=>array(30,144,255), - "dodgerblue2"=>array(28,134,238), - "dodgerblue3"=>array(24,116,205), - "dodgerblue4"=>array(16,78,139), - "steelblue1"=>array(99,184,255), - "steelblue2"=>array(92,172,238), - "steelblue3"=>array(79,148,205), - "steelblue4"=>array(54,100,139), - "deepskyblue1"=>array(0,191,255), - "deepskyblue2"=>array(0,178,238), - "deepskyblue3"=>array(0,154,205), - "deepskyblue4"=>array(0,104,139), - "skyblue1"=>array(135,206,255), - "skyblue2"=>array(126,192,238), - "skyblue3"=>array(108,166,205), - "skyblue4"=>array(74,112,139), - "lightskyblue1"=>array(176,226,255), - "lightskyblue2"=>array(164,211,238), - "lightskyblue3"=>array(141,182,205), - "lightskyblue4"=>array(96,123,139), - "slategray1"=>array(198,226,255), - "slategray2"=>array(185,211,238), - "slategray3"=>array(159,182,205), - "slategray4"=>array(108,123,139), - "lightsteelblue1"=>array(202,225,255), - "lightsteelblue2"=>array(188,210,238), - "lightsteelblue3"=>array(162,181,205), - "lightsteelblue4"=>array(110,123,139), - "lightblue1"=>array(191,239,255), - "lightblue2"=>array(178,223,238), - "lightblue3"=>array(154,192,205), - "lightblue4"=>array(104,131,139), - "lightcyan1"=>array(224,255,255), - "lightcyan2"=>array(209,238,238), - "lightcyan3"=>array(180,205,205), - "lightcyan4"=>array(122,139,139), - "paleturquoise1"=>array(187,255,255), - "paleturquoise2"=>array(174,238,238), - "paleturquoise3"=>array(150,205,205), - "paleturquoise4"=>array(102,139,139), - "cadetblue1"=>array(152,245,255), - "cadetblue2"=>array(142,229,238), - "cadetblue3"=>array(122,197,205), - "cadetblue4"=>array(83,134,139), - "turquoise1"=>array(0,245,255), - "turquoise2"=>array(0,229,238), - "turquoise3"=>array(0,197,205), - "turquoise4"=>array(0,134,139), - "cyan1"=>array(0,255,255), - "cyan2"=>array(0,238,238), - "cyan3"=>array(0,205,205), - "cyan4"=>array(0,139,139), - "darkslategray1"=>array(151,255,255), - "darkslategray2"=>array(141,238,238), - "darkslategray3"=>array(121,205,205), - "darkslategray4"=>array(82,139,139), - "aquamarine1"=>array(127,255,212), - "aquamarine2"=>array(118,238,198), - "aquamarine3"=>array(102,205,170), - "aquamarine4"=>array(69,139,116), - "darkseagreen1"=>array(193,255,193), - "darkseagreen2"=>array(180,238,180), - "darkseagreen3"=>array(155,205,155), - "darkseagreen4"=>array(105,139,105), - "seagreen1"=>array(84,255,159), - "seagreen2"=>array(78,238,148), - "seagreen3"=>array(67,205,128), - "seagreen4"=>array(46,139,87), - "palegreen1"=>array(154,255,154), - "palegreen2"=>array(144,238,144), - "palegreen3"=>array(124,205,124), - "palegreen4"=>array(84,139,84), - "springgreen1"=>array(0,255,127), - "springgreen2"=>array(0,238,118), - "springgreen3"=>array(0,205,102), - "springgreen4"=>array(0,139,69), - "chartreuse1"=>array(127,255,0), - "chartreuse2"=>array(118,238,0), - "chartreuse3"=>array(102,205,0), - "chartreuse4"=>array(69,139,0), - "olivedrab1"=>array(192,255,62), - "olivedrab2"=>array(179,238,58), - "olivedrab3"=>array(154,205,50), - "olivedrab4"=>array(105,139,34), - "darkolivegreen1"=>array(202,255,112), - "darkolivegreen2"=>array(188,238,104), - "darkolivegreen3"=>array(162,205,90), - "darkolivegreen4"=>array(110,139,61), - "khaki1"=>array(255,246,143), - "khaki2"=>array(238,230,133), - "khaki3"=>array(205,198,115), - "khaki4"=>array(139,134,78), - "lightgoldenrod1"=>array(255,236,139), - "lightgoldenrod2"=>array(238,220,130), - "lightgoldenrod3"=>array(205,190,112), - "lightgoldenrod4"=>array(139,129,76), - "yellow1"=>array(255,255,0), - "yellow2"=>array(238,238,0), - "yellow3"=>array(205,205,0), - "yellow4"=>array(139,139,0), - "gold1"=>array(255,215,0), - "gold2"=>array(238,201,0), - "gold3"=>array(205,173,0), - "gold4"=>array(139,117,0), - "goldenrod1"=>array(255,193,37), - "goldenrod2"=>array(238,180,34), - "goldenrod3"=>array(205,155,29), - "goldenrod4"=>array(139,105,20), - "darkgoldenrod1"=>array(255,185,15), - "darkgoldenrod2"=>array(238,173,14), - "darkgoldenrod3"=>array(205,149,12), - "darkgoldenrod4"=>array(139,101,8), - "rosybrown1"=>array(255,193,193), - "rosybrown2"=>array(238,180,180), - "rosybrown3"=>array(205,155,155), - "rosybrown4"=>array(139,105,105), - "indianred1"=>array(255,106,106), - "indianred2"=>array(238,99,99), - "indianred3"=>array(205,85,85), - "indianred4"=>array(139,58,58), - "sienna1"=>array(255,130,71), - "sienna2"=>array(238,121,66), - "sienna3"=>array(205,104,57), - "sienna4"=>array(139,71,38), - "burlywood1"=>array(255,211,155), - "burlywood2"=>array(238,197,145), - "burlywood3"=>array(205,170,125), - "burlywood4"=>array(139,115,85), - "wheat1"=>array(255,231,186), - "wheat2"=>array(238,216,174), - "wheat3"=>array(205,186,150), - "wheat4"=>array(139,126,102), - "tan1"=>array(255,165,79), - "tan2"=>array(238,154,73), - "tan3"=>array(205,133,63), - "tan4"=>array(139,90,43), - "chocolate1"=>array(255,127,36), - "chocolate2"=>array(238,118,33), - "chocolate3"=>array(205,102,29), - "chocolate4"=>array(139,69,19), - "firebrick1"=>array(255,48,48), - "firebrick2"=>array(238,44,44), - "firebrick3"=>array(205,38,38), - "firebrick4"=>array(139,26,26), - "brown1"=>array(255,64,64), - "brown2"=>array(238,59,59), - "brown3"=>array(205,51,51), - "brown4"=>array(139,35,35), - "salmon1"=>array(255,140,105), - "salmon2"=>array(238,130,98), - "salmon3"=>array(205,112,84), - "salmon4"=>array(139,76,57), - "lightsalmon1"=>array(255,160,122), - "lightsalmon2"=>array(238,149,114), - "lightsalmon3"=>array(205,129,98), - "lightsalmon4"=>array(139,87,66), - "orange1"=>array(255,165,0), - "orange2"=>array(238,154,0), - "orange3"=>array(205,133,0), - "orange4"=>array(139,90,0), - "darkorange1"=>array(255,127,0), - "darkorange2"=>array(238,118,0), - "darkorange3"=>array(205,102,0), - "darkorange4"=>array(139,69,0), - "coral1"=>array(255,114,86), - "coral2"=>array(238,106,80), - "coral3"=>array(205,91,69), - "coral4"=>array(139,62,47), - "tomato1"=>array(255,99,71), - "tomato2"=>array(238,92,66), - "tomato3"=>array(205,79,57), - "tomato4"=>array(139,54,38), - "orangered1"=>array(255,69,0), - "orangered2"=>array(238,64,0), - "orangered3"=>array(205,55,0), - "orangered4"=>array(139,37,0), - "deeppink1"=>array(255,20,147), - "deeppink2"=>array(238,18,137), - "deeppink3"=>array(205,16,118), - "deeppink4"=>array(139,10,80), - "hotpink1"=>array(255,110,180), - "hotpink2"=>array(238,106,167), - "hotpink3"=>array(205,96,144), - "hotpink4"=>array(139,58,98), - "pink1"=>array(255,181,197), - "pink2"=>array(238,169,184), - "pink3"=>array(205,145,158), - "pink4"=>array(139,99,108), - "lightpink1"=>array(255,174,185), - "lightpink2"=>array(238,162,173), - "lightpink3"=>array(205,140,149), - "lightpink4"=>array(139,95,101), - "palevioletred1"=>array(255,130,171), - "palevioletred2"=>array(238,121,159), - "palevioletred3"=>array(205,104,137), - "palevioletred4"=>array(139,71,93), - "maroon1"=>array(255,52,179), - "maroon2"=>array(238,48,167), - "maroon3"=>array(205,41,144), - "maroon4"=>array(139,28,98), - "violetred1"=>array(255,62,150), - "violetred2"=>array(238,58,140), - "violetred3"=>array(205,50,120), - "violetred4"=>array(139,34,82), - "magenta1"=>array(255,0,255), - "magenta2"=>array(238,0,238), - "magenta3"=>array(205,0,205), - "magenta4"=>array(139,0,139), - "mediumred"=>array(140,34,34), - "orchid1"=>array(255,131,250), - "orchid2"=>array(238,122,233), - "orchid3"=>array(205,105,201), - "orchid4"=>array(139,71,137), - "plum1"=>array(255,187,255), - "plum2"=>array(238,174,238), - "plum3"=>array(205,150,205), - "plum4"=>array(139,102,139), - "mediumorchid1"=>array(224,102,255), - "mediumorchid2"=>array(209,95,238), - "mediumorchid3"=>array(180,82,205), - "mediumorchid4"=>array(122,55,139), - "darkorchid1"=>array(191,62,255), - "darkorchid2"=>array(178,58,238), - "darkorchid3"=>array(154,50,205), - "darkorchid4"=>array(104,34,139), - "purple1"=>array(155,48,255), - "purple2"=>array(145,44,238), - "purple3"=>array(125,38,205), - "purple4"=>array(85,26,139), - "mediumpurple1"=>array(171,130,255), - "mediumpurple2"=>array(159,121,238), - "mediumpurple3"=>array(137,104,205), - "mediumpurple4"=>array(93,71,139), - "thistle1"=>array(255,225,255), - "thistle2"=>array(238,210,238), - "thistle3"=>array(205,181,205), - "thistle4"=>array(139,123,139), - "gray1"=>array(10,10,10), - "gray2"=>array(40,40,30), - "gray3"=>array(70,70,70), - "gray4"=>array(100,100,100), - "gray5"=>array(130,130,130), - "gray6"=>array(160,160,160), - "gray7"=>array(190,190,190), - "gray8"=>array(210,210,210), - "gray9"=>array(240,240,240), - "darkgray"=>array(100,100,100), - "darkblue"=>array(0,0,139), - "darkcyan"=>array(0,139,139), - "darkmagenta"=>array(139,0,139), - "darkred"=>array(139,0,0), - "silver"=>array(192, 192, 192), - "eggplant"=>array(144,176,168), - "lightgreen"=>array(144,238,144)); - } -//---------------- -// PUBLIC METHODS - // Colors can be specified as either - // 1. #xxxxxx HTML style - // 2. "colorname" as a named color - // 3. array(r,g,b) RGB triple - // This function translates this to a native RGB format and returns an - // RGB triple. - function Color($aColor) { - if (is_string($aColor)) { - // Strip of any alpha factor - $pos = strpos($aColor,'@'); - if( $pos === false ) { - $alpha = 0; - } - else { - $pos2 = strpos($aColor,':'); - if( $pos2===false ) - $pos2 = $pos-1; // Sentinel - if( $pos > $pos2 ) { - $alpha = str_replace(',','.',substr($aColor,$pos+1)); - $aColor = substr($aColor,0,$pos); - } - else { - $alpha = substr($aColor,$pos+1,$pos2-$pos-1); - $aColor = substr($aColor,0,$pos).substr($aColor,$pos2); - } - } - - // Extract potential adjustment figure at end of color - // specification - $pos = strpos($aColor,":"); - if( $pos === false ) { - $adj = 1.0; - } - else { - $adj = 0.0 + str_replace(',','.',substr($aColor,$pos+1)); - $aColor = substr($aColor,0,$pos); - } - if( $adj < 0 ) - JpGraphError::RaiseL(25077);//('Adjustment factor for color must be > 0'); - - if (substr($aColor, 0, 1) == "#") { - $r = hexdec(substr($aColor, 1, 2)); - $g = hexdec(substr($aColor, 3, 2)); - $b = hexdec(substr($aColor, 5, 2)); - } else { - if(!isset($this->rgb_table[$aColor]) ) - JpGraphError::RaiseL(25078,$aColor);//(" Unknown color: $aColor"); - $tmp=$this->rgb_table[$aColor]; - $r = $tmp[0]; - $g = $tmp[1]; - $b = $tmp[2]; - } - // Scale adj so that an adj=2 always - // makes the color 100% white (i.e. 255,255,255. - // and adj=1 neutral and adj=0 black. - if( $adj > 1 ) { - $m = ($adj-1.0)*(255-min(255,min($r,min($g,$b)))); - return array(min(255,$r+$m), min(255,$g+$m), min(255,$b+$m),$alpha); - } - elseif( $adj < 1 ) { - $m = ($adj-1.0)*max(255,max($r,max($g,$b))); - return array(max(0,$r+$m), max(0,$g+$m), max(0,$b+$m),$alpha); - } - else { - return array($r,$g,$b,$alpha); - } - - } elseif( is_array($aColor) ) { - if( count($aColor)==3 ) { - $aColor[3]=0; - return $aColor; - } - else - return $aColor; - } - else - JpGraphError::RaiseL(25079,$aColor,count($aColor));//(" Unknown color specification: $aColor , size=".count($aColor)); - } - - // Compare two colors - // return true if equal - function Equal($aCol1,$aCol2) { - $c1 = $this->Color($aCol1); - $c2 = $this->Color($aCol2); - if( $c1[0]==$c2[0] && $c1[1]==$c2[1] && $c1[2]==$c2[2] ) - return true; - else - return false; - } - - // Allocate a new color in the current image - // Return new color index, -1 if no more colors could be allocated - function Allocate($aColor,$aAlpha=0.0) { - list ($r, $g, $b, $a) = $this->color($aColor); - // If alpha is specified in the color string then this - // takes precedence over the second argument - if( $a > 0 ) - $aAlpha = $a; - if( $aAlpha < 0 || $aAlpha > 1 ) { - JpGraphError::RaiseL(25080);//('Alpha parameter for color must be between 0.0 and 1.0'); - } - return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); - } -} // Class - - -//=================================================== -// CLASS Legend -// Description: Responsible for drawing the box containing -// all the legend text for the graph -//=================================================== -DEFINE('_DEFAULT_LPM_SIZE',8); -class Legend { - public $txtcol=array(); - private $color=array(0,0,0); // Default fram color - private $fill_color=array(235,235,235); // Default fill color - private $shadow=true; // Shadow around legend "box" - private $shadow_color='darkgray@0.5'; - private $mark_abs_hsize=_DEFAULT_LPM_SIZE,$mark_abs_vsize=_DEFAULT_LPM_SIZE; - private $xmargin=10,$ymargin=3,$shadow_width=2; - private $xlmargin=2, $ylmargin=''; - private $xpos=0.05, $ypos=0.15, $xabspos=-1, $yabspos=-1; - private $halign="right", $valign="top"; - private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12; - private $font_color='black'; - private $hide=false,$layout_n=1; - private $weight=1,$frameweight=1; - private $csimareas=''; - private $reverse = false ; -//--------------- -// CONSTRUCTOR - function Legend() { - // Empty - } -//--------------- -// PUBLIC METHODS - function Hide($aHide=true) { - $this->hide=$aHide; - } - - function SetHColMargin($aXMarg) { - $this->xmargin = $aXMarg; - } - - function SetVColMargin($aSpacing) { - $this->ymargin = $aSpacing ; - } - - function SetLeftMargin($aXMarg) { - $this->xlmargin = $aXMarg; - } - - - // Synonym - function SetLineSpacing($aSpacing) { - $this->ymargin = $aSpacing ; - } - - function SetShadow($aShow='gray',$aWidth=2) { - if( is_string($aShow) ) { - $this->shadow_color = $aShow; - $this->shadow=true; - } - else - $this->shadow=$aShow; - $this->shadow_width=$aWidth; - } - - function SetMarkAbsSize($aSize) { - $this->mark_abs_vsize = $aSize ; - $this->mark_abs_hsize = $aSize ; - } - - function SetMarkAbsVSize($aSize) { - $this->mark_abs_vsize = $aSize ; - } - - function SetMarkAbsHSize($aSize) { - $this->mark_abs_hsize = $aSize ; - } - - function SetLineWeight($aWeight) { - $this->weight = $aWeight; - } - - function SetFrameWeight($aWeight) { - $this->frameweight = $aWeight; - } - - function SetLayout($aDirection=LEGEND_VERT) { - $this->layout_n = $aDirection==LEGEND_VERT ? 1 : 99 ; - } - - function SetColumns($aCols) { - $this->layout_n = $aCols ; - } - - function SetReverse($f=true) { - $this->reverse = $f ; - } - - // Set color on frame around box - function SetColor($aFontColor,$aColor='black') { - $this->font_color=$aFontColor; - $this->color=$aColor; - } - - function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) { - $this->font_family = $aFamily; - $this->font_style = $aStyle; - $this->font_size = $aSize; - } - - function SetPos($aX,$aY,$aHAlign="right",$aVAlign="top") { - $this->Pos($aX,$aY,$aHAlign,$aVAlign); - } - - function SetAbsPos($aX,$aY,$aHAlign="right",$aVAlign="top") { - $this->xabspos=$aX; - $this->yabspos=$aY; - $this->halign=$aHAlign; - $this->valign=$aVAlign; - } - - - function Pos($aX,$aY,$aHAlign="right",$aVAlign="top") { - if( !($aX<1 && $aY<1) ) - JpGraphError::RaiseL(25120);//(" Position for legend must be given as percentage in range 0-1"); - $this->xpos=$aX; - $this->ypos=$aY; - $this->halign=$aHAlign; - $this->valign=$aVAlign; - } - - function SetFillColor($aColor) { - $this->fill_color=$aColor; - } - - function Add($aTxt,$aColor,$aPlotmark='',$aLinestyle=0,$csimtarget='',$csimalt='',$csimwintarget='') { - $this->txtcol[]=array($aTxt,$aColor,$aPlotmark,$aLinestyle,$csimtarget,$csimalt,$csimwintarget); - } - - function GetCSIMAreas() { - return $this->csimareas; - } - - function Stroke(&$aImg) { - // Constant - $fillBoxFrameWeight=1; - - if( $this->hide ) return; - - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - - if( $this->reverse ) { - $this->txtcol = array_reverse($this->txtcol); - } - - $n=count($this->txtcol); - if( $n == 0 ) return; - - // Find out the max width and height of each column to be able - // to size the legend box. - $numcolumns = ($n > $this->layout_n ? $this->layout_n : $n); - for( $i=0; $i < $numcolumns; ++$i ) { - $colwidth[$i] = $aImg->GetTextWidth($this->txtcol[$i][0]) + - 2*$this->xmargin + 2*$this->mark_abs_hsize; - $colheight[$i] = 0; - } - - // Find our maximum height in each row - $rows = 0 ; $rowheight[0] = 0; - for( $i=0; $i < $n; ++$i ) { - $h = max($this->mark_abs_vsize,$aImg->GetTextHeight($this->txtcol[$i][0]))+$this->ymargin; - if( $i % $numcolumns == 0 ) { - $rows++; - $rowheight[$rows-1] = 0; - } - $rowheight[$rows-1] = max($rowheight[$rows-1],$h); - } - - $abs_height = 0; - for( $i=0; $i < $rows; ++$i ) { - $abs_height += $rowheight[$i] ; - } - - // Make sure that the height is at least as high as mark size + ymargin - $abs_height = max($abs_height,$this->mark_abs_vsize); - - // We add 3 extra pixels height to compensate for the difficult in - // calculating font height - $abs_height += $this->ymargin+3; - - // Find out the maximum width in each column - for( $i=$numcolumns; $i < $n; ++$i ) { - $colwidth[$i % $numcolumns] = max( - $aImg->GetTextWidth($this->txtcol[$i][0])+2*$this->xmargin+2*$this->mark_abs_hsize,$colwidth[$i % $numcolumns]); - } - - // Get the total width - $mtw = 0; - for( $i=0; $i < $numcolumns; ++$i ) { - $mtw += $colwidth[$i] ; - } - - // Find out maximum width we need for legend box - $abs_width = $mtw+$this->xlmargin; - - if( $this->xabspos === -1 && $this->yabspos === -1 ) { - $this->xabspos = $this->xpos*$aImg->width ; - $this->yabspos = $this->ypos*$aImg->height ; - } - - // Positioning of the legend box - if( $this->halign == 'left' ) - $xp = $this->xabspos; - elseif( $this->halign == 'center' ) - $xp = $this->xabspos - $abs_width/2; - else - $xp = $aImg->width - $this->xabspos - $abs_width; - - $yp=$this->yabspos; - if( $this->valign == 'center' ) - $yp-=$abs_height/2; - elseif( $this->valign == 'bottom' ) - $yp-=$abs_height; - - // Stroke legend box - $aImg->SetColor($this->color); - $aImg->SetLineWeight($this->frameweight); - $aImg->SetLineStyle('solid'); - - if( $this->shadow ) - $aImg->ShadowRectangle($xp,$yp,$xp+$abs_width+$this->shadow_width, - $yp+$abs_height+$this->shadow_width, - $this->fill_color,$this->shadow_width,$this->shadow_color); - else { - $aImg->SetColor($this->fill_color); - $aImg->FilledRectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height); - $aImg->SetColor($this->color); - $aImg->Rectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height); - } - - // x1,y1 is the position for the legend mark - $x1=$xp+$this->mark_abs_hsize+$this->xlmargin; - $y1=$yp + $this->ymargin; - - $f2 = round($aImg->GetTextHeight('X')/2); - - $grad = new Gradient($aImg); - $patternFactory = null; - - // Now stroke each legend in turn - // Each plot has added the following information to the legend - // p[0] = Legend text - // p[1] = Color, - // p[2] = For markers a reference to the PlotMark object - // p[3] = For lines the line style, for gradient the negative gradient style - // p[4] = CSIM target - // p[5] = CSIM Alt text - $i = 1 ; $row = 0; - foreach($this->txtcol as $p) { - - // STROKE DEBUG BOX - if( _JPG_DEBUG ) { - $aImg->SetLineWeight(1); - $aImg->SetColor('red'); - $aImg->SetLineStyle('solid'); - $aImg->Rectangle($xp,$y1,$xp+$abs_width,$y1+$rowheight[$row]); - } - - $aImg->SetLineWeight($this->weight); - $x1 = round($x1); $y1=round($y1); - if ( !empty($p[2]) && $p[2]->GetType() > -1 ) { - // Make a plot mark legend - $aImg->SetColor($p[1]); - if( is_string($p[3]) || $p[3]>0 ) { - $aImg->SetLineStyle($p[3]); - $aImg->StyleLine($x1-$this->mark_abs_hsize,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2); - } - // Stroke a mark with the standard size - // (As long as it is not an image mark ) - if( $p[2]->GetType() != MARK_IMG ) { - - // Clear any user callbacks since we ont want them called for - // the legend marks - $p[2]->iFormatCallback = ''; - $p[2]->iFormatCallback2 = ''; - - // Since size for circles is specified as the radius - // this means that we must half the size to make the total - // width behave as the other marks - if( $p[2]->GetType() == MARK_FILLEDCIRCLE || $p[2]->GetType() == MARK_CIRCLE ) { - $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize)/2); - $p[2]->Stroke($aImg,$x1,$y1+$f2); - } - else { - $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize)); - $p[2]->Stroke($aImg,$x1,$y1+$f2); - } - } - } - elseif ( !empty($p[2]) && (is_string($p[3]) || $p[3]>0 ) ) { - // Draw a styled line - $aImg->SetColor($p[1]); - $aImg->SetLineStyle($p[3]); - $aImg->StyleLine($x1-1,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2); - $aImg->StyleLine($x1-1,$y1+$f2+1,$x1+$this->mark_abs_hsize,$y1+$f2+1); - } - else { - // Draw a colored box - $color = $p[1] ; - // We make boxes slightly larger to better show - $boxsize = min($this->mark_abs_vsize,$this->mark_abs_hsize) + 2 ; - $ym = round($y1 + $f2 - $boxsize/2); - // We either need to plot a gradient or a - // pattern. To differentiate we use a kludge. - // Patterns have a p[3] value of < -100 - if( $p[3] < -100 ) { - // p[1][0] == iPattern, p[1][1] == iPatternColor, p[1][2] == iPatternDensity - if( $patternFactory == null ) { - $patternFactory = new RectPatternFactory(); - } - $prect = $patternFactory->Create($p[1][0],$p[1][1],1); - $prect->SetBackground($p[1][3]); - $prect->SetDensity($p[1][2]+1); - $prect->SetPos(new Rectangle($x1,$ym,$boxsize,$boxsize)); - $prect->Stroke($aImg); - $prect=null; - } - else { - if( is_array($color) && count($color)==2 ) { - // The client want a gradient color - $grad->FilledRectangle($x1,$ym, - $x1+$boxsize,$ym+$boxsize, - $color[0],$color[1],-$p[3]); - } - else { - $aImg->SetColor($p[1]); - $aImg->FilledRectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize); - } - $aImg->SetColor($this->color); - $aImg->SetLineWeight($fillBoxFrameWeight); - $aImg->Rectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize); - } - } - $aImg->SetColor($this->font_color); - $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); - $aImg->SetTextAlign("left","top"); - $aImg->StrokeText(round($x1+$this->mark_abs_hsize+$this->xmargin),$y1,$p[0]); - - // Add CSIM for Legend if defined - if( !empty($p[4]) ) { - - $xe = $x1 + $this->xmargin+$this->mark_abs_hsize+$aImg->GetTextWidth($p[0]); - $ye = $y1 + max($this->mark_abs_vsize,$aImg->GetTextHeight($p[0])); - $coords = "$x1,$y1,$xe,$y1,$xe,$ye,$x1,$ye"; - if( ! empty($p[4]) ) { - $this->csimareas .= "csimareas .= " target=\"".$p[6]."\""; - } - - if( !empty($p[5]) ) { - $tmp=sprintf($p[5],$p[0]); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; - } - } - if( $i >= $this->layout_n ) { - $x1 = $xp+$this->mark_abs_hsize+$this->xlmargin; - $y1 += $rowheight[$row++]; - $i = 1; - } - else { - $x1 += $colwidth[($i-1) % $numcolumns] ; - ++$i; - } - } - } -} // Class - //=================================================== // CLASS DisplayValue @@ -5985,111 +4977,130 @@ class Legend { class DisplayValue { public $margin=5; public $show=false; - public $valign="",$halign="center"; - public $format="%.1f",$negformat=""; + public $valign='',$halign='center'; + public $format='%.1f',$negformat=''; private $ff=FF_FONT1,$fs=FS_NORMAL,$fsize=10; private $iFormCallback=''; private $angle=0; - private $color="navy",$negcolor=""; + private $color='navy',$negcolor=''; private $iHideZero=false; + public $txt=null; - function Show($aFlag=true) { - $this->show=$aFlag; + function __construct() { + $this->txt = new Text(); } - function SetColor($aColor,$aNegcolor="") { - $this->color = $aColor; - $this->negcolor = $aNegcolor; + function Show($aFlag=true) { + $this->show=$aFlag; + } + + function SetColor($aColor,$aNegcolor='') { + $this->color = $aColor; + $this->negcolor = $aNegcolor; } function SetFont($aFontFamily,$aFontStyle=FS_NORMAL,$aFontSize=10) { - $this->ff=$aFontFamily; - $this->fs=$aFontStyle; - $this->fsize=$aFontSize; + $this->ff=$aFontFamily; + $this->fs=$aFontStyle; + $this->fsize=$aFontSize; } function ApplyFont($aImg) { - $aImg->SetFont($this->ff,$this->fs,$this->fsize); + $aImg->SetFont($this->ff,$this->fs,$this->fsize); } function SetMargin($aMargin) { - $this->margin = $aMargin; + $this->margin = $aMargin; } function SetAngle($aAngle) { - $this->angle = $aAngle; + $this->angle = $aAngle; } function SetAlign($aHAlign,$aVAlign='') { - $this->halign = $aHAlign; - $this->valign = $aVAlign; + $this->halign = $aHAlign; + $this->valign = $aVAlign; } - function SetFormat($aFormat,$aNegFormat="") { - $this->format= $aFormat; - $this->negformat= $aNegFormat; + function SetFormat($aFormat,$aNegFormat='') { + $this->format= $aFormat; + $this->negformat= $aNegFormat; } function SetFormatCallback($aFunc) { - $this->iFormCallback = $aFunc; + $this->iFormCallback = $aFunc; } function HideZero($aFlag=true) { - $this->iHideZero=$aFlag; + $this->iHideZero=$aFlag; } function Stroke($img,$aVal,$x,$y) { - - if( $this->show ) - { - if( $this->negformat=="" ) $this->negformat=$this->format; - if( $this->negcolor=="" ) $this->negcolor=$this->color; - if( $aVal===NULL || (is_string($aVal) && ($aVal=="" || $aVal=="-" || $aVal=="x" ) ) ) - return; + if( $this->show ) + { + if( $this->negformat=='' ) { + $this->negformat=$this->format; + } + if( $this->negcolor=='' ) { + $this->negcolor=$this->color; + } - if( is_numeric($aVal) && $aVal==0 && $this->iHideZero ) { - return; - } + if( $aVal===NULL || (is_string($aVal) && ($aVal=='' || $aVal=='-' || $aVal=='x' ) ) ) { + return; + } - // Since the value is used in different cirumstances we need to check what - // kind of formatting we shall use. For example, to display values in a line - // graph we simply display the formatted value, but in the case where the user - // has already specified a text string we don't fo anything. - if( $this->iFormCallback != '' ) { - $f = $this->iFormCallback; - $sval = call_user_func($f,$aVal); - } - elseif( is_numeric($aVal) ) { - if( $aVal >= 0 ) - $sval=sprintf($this->format,$aVal); - else - $sval=sprintf($this->negformat,$aVal); - } - else - $sval=$aVal; + if( is_numeric($aVal) && $aVal==0 && $this->iHideZero ) { + return; + } - $y = $y-sign($aVal)*$this->margin; + // Since the value is used in different cirumstances we need to check what + // kind of formatting we shall use. For example, to display values in a line + // graph we simply display the formatted value, but in the case where the user + // has already specified a text string we don't fo anything. + if( $this->iFormCallback != '' ) { + $f = $this->iFormCallback; + $sval = call_user_func($f,$aVal); + } + elseif( is_numeric($aVal) ) { + if( $aVal >= 0 ) { + $sval=sprintf($this->format,$aVal); + } + else { + $sval=sprintf($this->negformat,$aVal); + } + } + else { + $sval=$aVal; + } - $txt = new Text($sval,$x,$y); - $txt->SetFont($this->ff,$this->fs,$this->fsize); - if( $this->valign == "" ) { - if( $aVal >= 0 ) - $valign = "bottom"; - else - $valign = "top"; - } - else - $valign = $this->valign; - $txt->Align($this->halign,$valign); + $y = $y-sign($aVal)*$this->margin; - $txt->SetOrientation($this->angle); - if( $aVal > 0 ) - $txt->SetColor($this->color); - else - $txt->SetColor($this->negcolor); - $txt->Stroke($img); - } + $this->txt->Set($sval); + $this->txt->SetPos($x,$y); + $this->txt->SetFont($this->ff,$this->fs,$this->fsize); + if( $this->valign == '' ) { + if( $aVal >= 0 ) { + $valign = "bottom"; + } + else { + $valign = "top"; + } + } + else { + $valign = $this->valign; + } + $this->txt->Align($this->halign,$valign); + + $this->txt->SetOrientation($this->angle); + if( $aVal > 0 ) { + $this->txt->SetColor($this->color); + } + else { + $this->txt->SetColor($this->negcolor); + } + $this->txt->Stroke($img); + } } } @@ -6102,289 +5113,237 @@ class Plot { public $value; public $legend=''; public $coords=array(); - public $color="black"; + public $color='black'; public $hidelegend=false; public $line_weight=1; public $csimtargets=array(),$csimwintargets=array(); // Array of targets for CSIM - public $csimareas=""; // Resultant CSIM area tags - public $csimalts=null; // ALT:s for corresponding target + public $csimareas=''; // Resultant CSIM area tags + public $csimalts=null; // ALT:s for corresponding target public $legendcsimtarget='',$legendcsimwintarget=''; public $legendcsimalt=''; - protected $weight=1; + protected $weight=1; protected $center=false; -//--------------- -// CONSTRUCTOR - function Plot($aDatay,$aDatax=false) { - $this->numpoints = count($aDatay); - if( $this->numpoints==0 ) - JpGraphError::RaiseL(25121);//("Empty input data array specified for plot. Must have at least one data point."); - $this->coords[0]=$aDatay; - if( is_array($aDatax) ) { - $this->coords[1]=$aDatax; - $n = count($aDatax); - for($i=0; $i < $n; ++$i ) { - if( !is_numeric($aDatax[$i]) ) { - JpGraphError::RaiseL(25070); - } - } - } - $this->value = new DisplayValue(); - } -//--------------- -// PUBLIC METHODS + function __construct($aDatay,$aDatax=false) { + $this->numpoints = count($aDatay); + if( $this->numpoints==0 ) { + JpGraphError::RaiseL(25121);//("Empty input data array specified for plot. Must have at least one data point."); + } + $this->coords[0]=$aDatay; + if( is_array($aDatax) ) { + $this->coords[1]=$aDatax; + $n = count($aDatax); + for( $i=0; $i < $n; ++$i ) { + if( !is_numeric($aDatax[$i]) ) { + JpGraphError::RaiseL(25070); + } + } + } + $this->value = new DisplayValue(); + } // Stroke the plot // "virtual" function which must be implemented by // the subclasses function Stroke($aImg,$aXScale,$aYScale) { - JpGraphError::RaiseL(25122);//("JpGraph: Stroke() must be implemented by concrete subclass to class Plot"); + JpGraphError::RaiseL(25122);//("JpGraph: Stroke() must be implemented by concrete subclass to class Plot"); } function HideLegend($f=true) { - $this->hidelegend = $f; + $this->hidelegend = $f; } function DoLegend($graph) { - if( !$this->hidelegend ) - $this->Legend($graph); + if( !$this->hidelegend ) + $this->Legend($graph); } function StrokeDataValue($img,$aVal,$x,$y) { - $this->value->Stroke($img,$aVal,$x,$y); + $this->value->Stroke($img,$aVal,$x,$y); } - - // Set href targets for CSIM + + // Set href targets for CSIM function SetCSIMTargets($aTargets,$aAlts='',$aWinTargets='') { - $this->csimtargets=$aTargets; - $this->csimwintargets=$aWinTargets; - $this->csimalts=$aAlts; + $this->csimtargets=$aTargets; + $this->csimwintargets=$aWinTargets; + $this->csimalts=$aAlts; } - + // Get all created areas function GetCSIMareas() { - return $this->csimareas; - } - + return $this->csimareas; + } + // "Virtual" function which gets called before any scale // or axis are stroked used to do any plot specific adjustment function PreStrokeAdjust($aGraph) { - if( substr($aGraph->axtype,0,4) == "text" && (isset($this->coords[1])) ) - JpGraphError::RaiseL(25123);//("JpGraph: You can't use a text X-scale with specified X-coords. Use a \"int\" or \"lin\" scale instead."); - return true; + if( substr($aGraph->axtype,0,4) == "text" && (isset($this->coords[1])) ) { + JpGraphError::RaiseL(25123);//("JpGraph: You can't use a text X-scale with specified X-coords. Use a \"int\" or \"lin\" scale instead."); + } + return true; } - + + // Virtual function to the the concrete plot class to make any changes to the graph + // and scale before the stroke process begins + function PreScaleSetup($aGraph) { + // Empty + } + // Get minimum values in plot function Min() { - if( isset($this->coords[1]) ) - $x=$this->coords[1]; - else - $x=""; - if( $x != "" && count($x) > 0 ) { - $xm=min($x); - } - else - $xm=0; - $y=$this->coords[0]; - $cnt = count($y); - if( $cnt > 0 ) { - /* - if( ! isset($y[0]) ) { - JpGraphError('The input data array must have consecutive values from position 0 and forward. The given y-array starts with empty values (NULL)'); - } - $ym = $y[0]; - */ - $i=0; - while( $i<$cnt && !is_numeric($ym=$y[$i]) ) - $i++; - while( $i < $cnt) { - if( is_numeric($y[$i]) ) - $ym=min($ym,$y[$i]); - ++$i; - } - } - else - $ym=""; - return array($xm,$ym); + if( isset($this->coords[1]) ) { + $x=$this->coords[1]; + } + else { + $x=''; + } + if( $x != '' && count($x) > 0 ) { + $xm=min($x); + } + else { + $xm=0; + } + $y=$this->coords[0]; + $cnt = count($y); + if( $cnt > 0 ) { + $i=0; + while( $i<$cnt && !is_numeric($ym=$y[$i]) ) { + $i++; + } + while( $i < $cnt) { + if( is_numeric($y[$i]) ) { + $ym=min($ym,$y[$i]); + } + ++$i; + } + } + else { + $ym=''; + } + return array($xm,$ym); } - + // Get maximum value in plot function Max() { - if( isset($this->coords[1]) ) - $x=$this->coords[1]; - else - $x=""; + if( isset($this->coords[1]) ) { + $x=$this->coords[1]; + } + else { + $x=''; + } - if( $x!="" && count($x) > 0 ) - $xm=max($x); - else { - $xm = $this->numpoints-1; - } - $y=$this->coords[0]; - if( count($y) > 0 ) { - /* - if( !isset($y[0]) ) { - JpGraphError::Raise('The input data array must have consecutive values from position 0 and forward. The given y-array starts with empty values (NULL)'); -// $y[0] = 0; -// Change in 1.5.1 Don't treat this as an error any more. Just silently convert to 0 -// Change in 1.17 Treat his as an error again !! This is the right way to do !! - } - */ - $cnt = count($y); - $i=0; - while( $i<$cnt && !is_numeric($ym=$y[$i]) ) - $i++; - while( $i < $cnt ) { - if( is_numeric($y[$i]) ) - $ym=max($ym,$y[$i]); - ++$i; - } - } - else - $ym=""; - return array($xm,$ym); + if( $x!='' && count($x) > 0 ) { + $xm=max($x); + } + else { + $xm = $this->numpoints-1; + } + $y=$this->coords[0]; + if( count($y) > 0 ) { + $cnt = count($y); + $i=0; + while( $i<$cnt && !is_numeric($ym=$y[$i]) ) { + $i++; + } + while( $i < $cnt ) { + if( is_numeric($y[$i]) ) { + $ym=max($ym,$y[$i]); + } + ++$i; + } + } + else { + $ym=''; + } + return array($xm,$ym); } - + function SetColor($aColor) { - $this->color=$aColor; + $this->color=$aColor; } - + function SetLegend($aLegend,$aCSIM='',$aCSIMAlt='',$aCSIMWinTarget='') { - $this->legend = $aLegend; - $this->legendcsimtarget = $aCSIM; - $this->legendcsimwintarget = $aCSIMWinTarget; - $this->legendcsimalt = $aCSIMAlt; + $this->legend = $aLegend; + $this->legendcsimtarget = $aCSIM; + $this->legendcsimwintarget = $aCSIMWinTarget; + $this->legendcsimalt = $aCSIMAlt; } function SetWeight($aWeight) { - $this->weight=$aWeight; + $this->weight=$aWeight; } - + function SetLineWeight($aWeight=1) { - $this->line_weight=$aWeight; + $this->line_weight=$aWeight; } - + function SetCenter($aCenter=true) { - $this->center = $aCenter; + $this->center = $aCenter; } - + // This method gets called by Graph class to plot anything that should go // into the margin after the margin color has been set. function StrokeMargin($aImg) { - return true; + return true; } // Framework function the chance for each plot class to set a legend function Legend($aGraph) { - if( $this->legend != "" ) - $aGraph->legend->Add($this->legend,$this->color,"",0,$this->legendcsimtarget, - $this->legendcsimalt,$this->legendcsimwintarget); + if( $this->legend != '' ) { + $aGraph->legend->Add($this->legend,$this->color,'',0,$this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } } - + } // Class -//=================================================== -// CLASS PlotLine -// Description: -// Data container class to hold properties for a static -// line that is drawn directly in the plot area. -// Usefull to add static borders inside a plot to show -// for example set-values -//=================================================== -class PlotLine { - public $scaleposition, $direction=-1; - protected $weight=1; - protected $color="black"; - private $legend='',$hidelegend=false, $legendcsimtarget='', $legendcsimalt='',$legendcsimwintarget=''; - private $iLineStyle='solid'; +// Provide a deterministic list of new colors whenever the getColor() method +// is called. Used to automatically set colors of plots. +class ColorFactory { -//--------------- -// CONSTRUCTOR - function PlotLine($aDir=HORIZONTAL,$aPos=0,$aColor="black",$aWeight=1) { - $this->direction = $aDir; - $this->color=$aColor; - $this->weight=$aWeight; - $this->scaleposition=$aPos; - } - -//--------------- -// PUBLIC METHODS + static private $iIdx = 0; + static private $iColorList = array( + 'black', + 'blue', + 'orange', + 'darkgreen', + 'red', + 'AntiqueWhite3', + 'aquamarine3', + 'azure4', + 'brown', + 'cadetblue3', + 'chartreuse4', + 'chocolate', + 'darkblue', + 'darkgoldenrod3', + 'darkorchid3', + 'darksalmon', + 'darkseagreen4', + 'deepskyblue2', + 'dodgerblue4', + 'gold3', + 'hotpink', + 'lawngreen', + 'lightcoral', + 'lightpink3', + 'lightseagreen', + 'lightslateblue', + 'mediumpurple', + 'olivedrab', + 'orangered1', + 'peru', + 'slategray', + 'yellow4', + 'springgreen2'); + static private $iNum = 33; - function SetLegend($aLegend,$aCSIM='',$aCSIMAlt='',$aCSIMWinTarget='') { - $this->legend = $aLegend; - $this->legendcsimtarget = $aCSIM; - $this->legendcsimwintarget = $aCSIMWinTarget; - $this->legendcsimalt = $aCSIMAlt; + static function getColor() { + if( ColorFactory::$iIdx >= ColorFactory::$iNum ) + ColorFactory::$iIdx = 0; + return ColorFactory::$iColorList[ColorFactory::$iIdx++]; } - function HideLegend($f=true) { - $this->hidelegend = $f; - } - - function SetPosition($aScalePosition) { - $this->scaleposition=$aScalePosition; - } - - function SetDirection($aDir) { - $this->direction = $aDir; - } - - function SetColor($aColor) { - $this->color=$aColor; - } - - function SetWeight($aWeight) { - $this->weight=$aWeight; - } - - function SetLineStyle($aStyle) { - $this->iLineStyle = $aStyle; - } - -//--------------- -// PRIVATE METHODS - - function DoLegend(&$graph) { - if( !$this->hidelegend ) - $this->Legend($graph); - } - - // Framework function the chance for each plot class to set a legend - function Legend(&$aGraph) { - if( $this->legend != "" ) { - $dummyPlotMark = new PlotMark(); - $lineStyle = 1; - $aGraph->legend->Add($this->legend,$this->color,$dummyPlotMark,$lineStyle, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - } - - function PreStrokeAdjust($aGraph) { - // Nothing to do - } - - function Stroke($aImg,$aXScale,$aYScale) { - $aImg->SetColor($this->color); - $aImg->SetLineWeight($this->weight); - $oldStyle = $aImg->SetLineStyle($this->iLineStyle); - if( $this->direction == VERTICAL ) { - $ymin_abs=$aYScale->Translate($aYScale->GetMinVal()); - $ymax_abs=$aYScale->Translate($aYScale->GetMaxVal()); - $xpos_abs=$aXScale->Translate($this->scaleposition); - $aImg->StyleLine($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs); - } - elseif( $this->direction == HORIZONTAL ) { - $xmin_abs=$aXScale->Translate($aXScale->GetMinVal()); - $xmax_abs=$aXScale->Translate($aXScale->GetMaxVal()); - $ypos_abs=$aYScale->Translate($this->scaleposition); - $aImg->StyleLine($xmin_abs, $ypos_abs, $xmax_abs, $ypos_abs); - } - else { - JpGraphError::RaiseL(25125);//(" Illegal direction for static line"); - } - $aImg->SetLineStyle($oldStyle); - } } // diff --git a/src/classes/jpgraph/jpgraph_bar.php b/src/classes/jpgraph/jpgraph_bar.php index bcf6fdd..d68c746 100644 --- a/src/classes/jpgraph/jpgraph_bar.php +++ b/src/classes/jpgraph/jpgraph_bar.php @@ -1,13 +1,13 @@ Plot($datay,$datax); - ++$this->numpoints; + protected $bar_shadow_hsize=3,$bar_shadow_vsize=3; + + //--------------- + // CONSTRUCTOR + function __construct($datay,$datax=false) { + parent::__construct($datay,$datax); + ++$this->numpoints; } -//--------------- -// PUBLIC METHODS - + //--------------- + // PUBLIC METHODS + // Set a drop shadow for the bar (or rather an "up-right" shadow) - function SetShadow($color="black",$hsize=3,$vsize=3,$show=true) { - $this->bar_shadow=$show; - $this->bar_shadow_color=$color; - $this->bar_shadow_vsize=$vsize; - $this->bar_shadow_hsize=$hsize; - - // Adjust the value margin to compensate for shadow - $this->value->margin += $vsize; + function SetShadow($aColor="black",$aHSize=3,$aVSize=3,$aShow=true) { + $this->bar_shadow=$aShow; + $this->bar_shadow_color=$aColor; + $this->bar_shadow_vsize=$aVSize; + $this->bar_shadow_hsize=$aHSize; + + // Adjust the value margin to compensate for shadow + $this->value->margin += $aVSize; } - + // DEPRECATED use SetYBase instead function SetYMin($aYStartValue) { - //die("JpGraph Error: Deprecated function SetYMin. Use SetYBase() instead."); - $this->ybase=$aYStartValue; + //die("JpGraph Error: Deprecated function SetYMin. Use SetYBase() instead."); + $this->ybase=$aYStartValue; } // Specify the base value for the bars function SetYBase($aYStartValue) { - $this->ybase=$aYStartValue; + $this->ybase=$aYStartValue; } - + + // The method will take the specified pattern anre + // return a pattern index that corresponds to the original + // patterm being rotated 90 degreees. This is needed when plottin + // Horizontal bars + function RotatePattern($aPat,$aRotate=true) { + $rotate = array(1 => 2, 2 => 1, 3 => 3, 4 => 5, 5 => 4, 6 => 6, 7 => 7, 8 => 8); + if( $aRotate ) { + return $rotate[$aPat]; + } + else { + return $aPat; + } + } + function Legend($graph) { - if( $this->grad && $this->legend!="" && !$this->fill ) { - $color=array($this->grad_fromcolor,$this->grad_tocolor); - // In order to differentiate between gradients and cooors specified as an RGB triple - $graph->legend->Add($this->legend,$color,"",-$this->grad_style, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - elseif( $this->legend!="" && ($this->iPattern > -1 || is_array($this->iPattern)) ) { - if( is_array($this->iPattern) ) { - $p1 = $this->iPattern[0]; - $p2 = $this->iPatternColor[0]; - $p3 = $this->iPatternDensity[0]; - } - else { - $p1 = $this->iPattern; - $p2 = $this->iPatternColor; - $p3 = $this->iPatternDensity; - } - $color = array($p1,$p2,$p3,$this->fill_color); - // A kludge: Too mark that we add a pattern we use a type value of < 100 - $graph->legend->Add($this->legend,$color,"",-101, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - elseif( $this->fill_color && $this->legend!="" ) { - if( is_array($this->fill_color) ) { - $graph->legend->Add($this->legend,$this->fill_color[0],"",0, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - else { - $graph->legend->Add($this->legend,$this->fill_color,"",0, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - } + if( $this->grad && $this->legend!="" && !$this->fill ) { + $color=array($this->grad_fromcolor,$this->grad_tocolor); + // In order to differentiate between gradients and cooors specified as an RGB triple + $graph->legend->Add($this->legend,$color,"",-$this->grad_style, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + elseif( $this->legend!="" && ($this->iPattern > -1 || is_array($this->iPattern)) ) { + if( is_array($this->iPattern) ) { + $p1 = $this->RotatePattern( $this->iPattern[0], $graph->img->a == 90 ); + $p2 = $this->iPatternColor[0]; + $p3 = $this->iPatternDensity[0]; + } + else { + $p1 = $this->RotatePattern( $this->iPattern, $graph->img->a == 90 ); + $p2 = $this->iPatternColor; + $p3 = $this->iPatternDensity; + } + if( $p3 < 90 ) $p3 += 5; + $color = array($p1,$p2,$p3,$this->fill_color); + // A kludge: Too mark that we add a pattern we use a type value of < 100 + $graph->legend->Add($this->legend,$color,"",-101, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + elseif( $this->fill_color && $this->legend!="" ) { + if( is_array($this->fill_color) ) { + $graph->legend->Add($this->legend,$this->fill_color[0],"",0, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + else { + $graph->legend->Add($this->legend,$this->fill_color,"",0, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + } } // Gets called before any axis are stroked function PreStrokeAdjust($graph) { - parent::PreStrokeAdjust($graph); + parent::PreStrokeAdjust($graph); - // If we are using a log Y-scale we want the base to be at the - // minimum Y-value unless the user have specifically set some other - // value than the default. - if( substr($graph->axtype,-3,3)=="log" && $this->ybase==0 ) - $this->ybase = $graph->yaxis->scale->GetMinVal(); - - // For a "text" X-axis scale we will adjust the - // display of the bars a little bit. - if( substr($graph->axtype,0,3)=="tex" ) { - // Position the ticks between the bars - $graph->xaxis->scale->ticks->SetXLabelOffset(0.5,0); + // If we are using a log Y-scale we want the base to be at the + // minimum Y-value unless the user have specifically set some other + // value than the default. + if( substr($graph->axtype,-3,3)=="log" && $this->ybase==0 ) + $this->ybase = $graph->yaxis->scale->GetMinVal(); - // Center the bars - if( $this->abswidth > -1 ) { - $graph->SetTextScaleAbsCenterOff($this->abswidth); - } - else { - if( $this->align == "center" ) - $graph->SetTextScaleOff(0.5-$this->width/2); - elseif( $this->align == "right" ) - $graph->SetTextScaleOff(1-$this->width); - } - } - elseif( ($this instanceof AccBarPlot) || ($this instanceof GroupBarPlot) ) { - // We only set an absolute width for linear and int scale - // for text scale the width will be set to a fraction of - // the majstep width. - if( $this->abswidth == -1 ) { + // For a "text" X-axis scale we will adjust the + // display of the bars a little bit. + if( substr($graph->axtype,0,3)=="tex" ) { + // Position the ticks between the bars + $graph->xaxis->scale->ticks->SetXLabelOffset(0.5,0); + + // Center the bars + if( $this->abswidth > -1 ) { + $graph->SetTextScaleAbsCenterOff($this->abswidth); + } + else { + if( $this->align == "center" ) + $graph->SetTextScaleOff(0.5-$this->width/2); + elseif( $this->align == "right" ) + $graph->SetTextScaleOff(1-$this->width); + } + } + elseif( ($this instanceof AccBarPlot) || ($this instanceof GroupBarPlot) ) { + // We only set an absolute width for linear and int scale + // for text scale the width will be set to a fraction of + // the majstep width. + if( $this->abswidth == -1 ) { // Not set - // set width to a visuable sensible default - $this->abswidth = $graph->img->plotwidth/(2*count($this->coords[0])); - } - } + // set width to a visuable sensible default + $this->abswidth = $graph->img->plotwidth/(2*$this->numpoints); + } + } } function Min() { - $m = parent::Min(); - if( $m[1] >= $this->ybase ) - $m[1] = $this->ybase; - return $m; + $m = parent::Min(); + if( $m[1] >= $this->ybase ) $m[1] = $this->ybase; + return $m; } function Max() { - $m = parent::Max(); - if( $m[1] <= $this->ybase ) - $m[1] = $this->ybase; - return $m; - } - + $m = parent::Max(); + if( $m[1] <= $this->ybase ) $m[1] = $this->ybase; + return $m; + } + // Specify width as fractions of the major stepo size function SetWidth($aWidth) { - if( $aWidth > 1 ) { - // Interpret this as absolute width - $this->abswidth=$aWidth; - } - else - $this->width=$aWidth; + if( $aWidth > 1 ) { + // Interpret this as absolute width + $this->abswidth=$aWidth; + } + else { + $this->width=$aWidth; + } } - + // Specify width in absolute pixels. If specified this // overrides SetWidth() function SetAbsWidth($aWidth) { - $this->abswidth=$aWidth; + $this->abswidth=$aWidth; } - + function SetAlign($aAlign) { - $this->align=$aAlign; + $this->align=$aAlign; } - + function SetNoFill() { - $this->grad = false; - $this->fill_color=false; - $this->fill=false; + $this->grad = false; + $this->fill_color=false; + $this->fill=false; } - + function SetFillColor($aColor) { - $this->fill = true ; - $this->fill_color=$aColor; + // Do an extra error check if the color is specified as an RG array triple + // In that case convert it to a hex string since it will otherwise be + // interpretated as an array of colors for each individual bar. + + $aColor = RGB::tryHexConversion($aColor); + $this->fill = true ; + $this->fill_color=$aColor; + } - + function SetFillGradient($aFromColor,$aToColor=null,$aStyle=null) { - $this->grad = true; - $this->grad_fromcolor = $aFromColor; - $this->grad_tocolor = $aToColor; - $this->grad_style = $aStyle; + $this->grad = true; + $this->grad_fromcolor = $aFromColor; + $this->grad_tocolor = $aToColor; + $this->grad_style = $aStyle; } - + function SetValuePos($aPos) { - $this->valuepos = $aPos; + $this->valuepos = $aPos; } function SetPattern($aPattern, $aColor='black'){ - if( is_array($aPattern) ) { - $n = count($aPattern); - $this->iPattern = array(); - $this->iPatternDensity = array(); - if( is_array($aColor) ) { - $this->iPatternColor = array(); - if( count($aColor) != $n ) { - JpGraphError::Raise('NUmber of colors is not the same as the number of patterns in BarPlot::SetPattern()'); - } - } - else - $this->iPatternColor = $aColor; - for( $i=0; $i < $n; ++$i ) { - $this->_SetPatternHelper($aPattern[$i], $this->iPattern[$i], $this->iPatternDensity[$i]); - if( is_array($aColor) ) { - $this->iPatternColor[$i] = $aColor[$i]; - } - } - } - else { - $this->_SetPatternHelper($aPattern, $this->iPattern, $this->iPatternDensity); - $this->iPatternColor = $aColor; - } + if( is_array($aPattern) ) { + $n = count($aPattern); + $this->iPattern = array(); + $this->iPatternDensity = array(); + if( is_array($aColor) ) { + $this->iPatternColor = array(); + if( count($aColor) != $n ) { + JpGraphError::RaiseL(2001);//('NUmber of colors is not the same as the number of patterns in BarPlot::SetPattern()'); + } + } + else { + $this->iPatternColor = $aColor; + } + for( $i=0; $i < $n; ++$i ) { + $this->_SetPatternHelper($aPattern[$i], $this->iPattern[$i], $this->iPatternDensity[$i]); + if( is_array($aColor) ) { + $this->iPatternColor[$i] = $aColor[$i]; + } + } + } + else { + $this->_SetPatternHelper($aPattern, $this->iPattern, $this->iPatternDensity); + $this->iPatternColor = $aColor; + } } function _SetPatternHelper($aPattern, &$aPatternValue, &$aDensity){ - switch( $aPattern ) { - case PATTERN_DIAG1: - $aPatternValue= 1; - $aDensity = 90; - break; - case PATTERN_DIAG2: - $aPatternValue= 1; - $aDensity = 75; - break; - case PATTERN_DIAG3: - $aPatternValue= 2; - $aDensity = 90; - break; - case PATTERN_DIAG4: - $aPatternValue= 2; - $aDensity = 75; - break; - case PATTERN_CROSS1: - $aPatternValue= 8; - $aDensity = 90; - break; - case PATTERN_CROSS2: - $aPatternValue= 8; - $aDensity = 78; - break; - case PATTERN_CROSS3: - $aPatternValue= 8; - $aDensity = 65; - break; - case PATTERN_CROSS4: - $aPatternValue= 7; - $aDensity = 90; - break; - case PATTERN_STRIPE1: - $aPatternValue= 5; - $aDensity = 90; - break; - case PATTERN_STRIPE2: - $aPatternValue= 5; - $aDensity = 75; - break; - default: - JpGraphError::Raise('Unknown pattern specified in call to BarPlot::SetPattern()'); - } + switch( $aPattern ) { + case PATTERN_DIAG1: + $aPatternValue= 1; + $aDensity = 92; + break; + case PATTERN_DIAG2: + $aPatternValue= 1; + $aDensity = 78; + break; + case PATTERN_DIAG3: + $aPatternValue= 2; + $aDensity = 92; + break; + case PATTERN_DIAG4: + $aPatternValue= 2; + $aDensity = 78; + break; + case PATTERN_CROSS1: + $aPatternValue= 8; + $aDensity = 90; + break; + case PATTERN_CROSS2: + $aPatternValue= 8; + $aDensity = 78; + break; + case PATTERN_CROSS3: + $aPatternValue= 8; + $aDensity = 65; + break; + case PATTERN_CROSS4: + $aPatternValue= 7; + $aDensity = 90; + break; + case PATTERN_STRIPE1: + $aPatternValue= 5; + $aDensity = 94; + break; + case PATTERN_STRIPE2: + $aPatternValue= 5; + $aDensity = 85; + break; + default: + JpGraphError::RaiseL(2002); + //('Unknown pattern specified in call to BarPlot::SetPattern()'); + } } - function Stroke($img,$xscale,$yscale) { - - $numpoints = count($this->coords[0]); - if( isset($this->coords[1]) ) { - if( count($this->coords[1])!=$numpoints ) - JpGraphError::Raise("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])."Number of Y-points:$numpoints"); - else - $exist_x = true; - } - else - $exist_x = false; - - - $numbars=count($this->coords[0]); + function Stroke($img,$xscale,$yscale) { - // Use GetMinVal() instead of scale[0] directly since in the case - // of log scale we get a correct value. Log scales will have negative - // values for values < 1 while still not representing negative numbers. - if( $yscale->GetMinVal() >= 0 ) - $zp=$yscale->scale_abs[0]; - else { - $zp=$yscale->Translate(0); - } + $numpoints = count($this->coords[0]); + if( isset($this->coords[1]) ) { + if( count($this->coords[1])!=$numpoints ) { + JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints); + //"Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])."Number of Y-points:$numpoints"); + } + else { + $exist_x = true; + } + } + else { + $exist_x = false; + } - if( $this->abswidth > -1 ) { - $abswidth=$this->abswidth; - } - else - $abswidth=round($this->width*$xscale->scale_factor,0); - // Count pontetial pattern array to avoid doing the count for each iteration - if( is_array($this->iPattern) ) { - $np = count($this->iPattern); - } - - $grad = null; - for($i=0; $i < $numbars; ++$i) { + $numbars=count($this->coords[0]); - // If value is NULL, or 0 then don't draw a bar at all - if ($this->coords[0][$i] === null || $this->coords[0][$i] === '' ) - continue; + // Use GetMinVal() instead of scale[0] directly since in the case + // of log scale we get a correct value. Log scales will have negative + // values for values < 1 while still not representing negative numbers. + if( $yscale->GetMinVal() >= 0 ) + $zp=$yscale->scale_abs[0]; + else { + $zp=$yscale->Translate(0); + } - if( $exist_x ) $x=$this->coords[1][$i]; - else $x=$i; - - $x=$xscale->Translate($x); + if( $this->abswidth > -1 ) { + $abswidth=$this->abswidth; + } + else { + $abswidth=round($this->width*$xscale->scale_factor,0); + } -// Comment Note: This confuses the positioning when using acc together with -// grouped bars. Workaround for fixing #191 -/* - if( !$xscale->textscale ) { - if($this->align=="center") - $x -= $abswidth/2; - elseif($this->align=="right") - $x -= $abswidth; - } -*/ - // Stroke fill color and fill gradient - $pts=array( - $x,$zp, - $x,$yscale->Translate($this->coords[0][$i]), - $x+$abswidth,$yscale->Translate($this->coords[0][$i]), - $x+$abswidth,$zp); - if( $this->grad ) { - if( $grad === null ) - $grad = new Gradient($img); - if( is_array($this->grad_fromcolor) ) { - // The first argument (grad_fromcolor) can be either an array or a single color. If it is an array - // then we have two choices. It can either a) be a single color specified as an RGB triple or it can be - // an array to specify both (from, to style) for each individual bar. The way to know the difference is - // to investgate the first element. If this element is an integer [0,255] then we assume it is an RGB - // triple. - $ng = count($this->grad_fromcolor); - if( $ng === 3 ) { - if( is_numeric($this->grad_fromcolor[0]) && $this->grad_fromcolor[0] > 0 && $this->grad_fromcolor[0] < 256 ) { - // RGB Triple - $fromcolor = $this->grad_fromcolor; - $tocolor = $this->grad_tocolor; - $style = $this->grad_style; - } - } - else { - $fromcolor = $this->grad_fromcolor[$i % $ng][0]; - $tocolor = $this->grad_fromcolor[$i % $ng][1]; - $style = $this->grad_fromcolor[$i % $ng][2]; - } - $grad->FilledRectangle($pts[2],$pts[3], - $pts[6],$pts[7], - $fromcolor,$tocolor,$style); - } - else { - $grad->FilledRectangle($pts[2],$pts[3], - $pts[6],$pts[7], - $this->grad_fromcolor,$this->grad_tocolor,$this->grad_style); - } - } - elseif( !empty($this->fill_color) ) { - if(is_array($this->fill_color)) { - $img->PushColor($this->fill_color[$i % count($this->fill_color)]); - } else { - $img->PushColor($this->fill_color); - } - $img->FilledPolygon($pts); - $img->PopColor(); - } - - - // Remember value of this bar - $val=$this->coords[0][$i]; + // Count pontetial pattern array to avoid doing the count for each iteration + if( is_array($this->iPattern) ) { + $np = count($this->iPattern); + } - if( !empty($val) && !is_numeric($val) ) { - JpGraphError::Raise('All values for a barplot must be numeric. You have specified value['.$i.'] == \''.$val.'\''); - } + $grad = null; + for($i=0; $i < $numbars; ++$i) { - // Determine the shadow - if( $this->bar_shadow && $val != 0) { + // If value is NULL, or 0 then don't draw a bar at all + if ($this->coords[0][$i] === null || $this->coords[0][$i] === '' ) + continue; - $ssh = $this->bar_shadow_hsize; - $ssv = $this->bar_shadow_vsize; - // Create points to create a "upper-right" shadow - if( $val > 0 ) { - $sp[0]=$pts[6]; $sp[1]=$pts[7]; - $sp[2]=$pts[4]; $sp[3]=$pts[5]; - $sp[4]=$pts[2]; $sp[5]=$pts[3]; - $sp[6]=$pts[2]+$ssh; $sp[7]=$pts[3]-$ssv; - $sp[8]=$pts[4]+$ssh; $sp[9]=$pts[5]-$ssv; - $sp[10]=$pts[6]+$ssh; $sp[11]=$pts[7]-$ssv; - } - elseif( $val < 0 ) { - $sp[0]=$pts[4]; $sp[1]=$pts[5]; - $sp[2]=$pts[6]; $sp[3]=$pts[7]; - $sp[4]=$pts[0]; $sp[5]=$pts[1]; - $sp[6]=$pts[0]+$ssh; $sp[7]=$pts[1]-$ssv; - $sp[8]=$pts[6]+$ssh; $sp[9]=$pts[7]-$ssv; - $sp[10]=$pts[4]+$ssh; $sp[11]=$pts[5]-$ssv; - } - if( is_array($this->bar_shadow_color) ) { - $numcolors = count($this->bar_shadow_color); - if( $numcolors == 0 ) { - JpGraphError::Raise('You have specified an empty array for shadow colors in the bar plot.'); - } - $img->PushColor($this->bar_shadow_color[$i % $numcolors]); - } - else { - $img->PushColor($this->bar_shadow_color); - } - $img->FilledPolygon($sp); - $img->PopColor(); - } - - // Stroke the pattern - if( is_array($this->iPattern) ) { - $f = new RectPatternFactory(); - if( is_array($this->iPatternColor) ) { - $pcolor = $this->iPatternColor[$i % $np]; - } - else - $pcolor = $this->iPatternColor; - $prect = $f->Create($this->iPattern[$i % $np],$pcolor,1); - $prect->SetDensity($this->iPatternDensity[$i % $np]); + if( $exist_x ) { + $x=$this->coords[1][$i]; + } + else { + $x=$i; + } - if( $val < 0 ) { - $rx = $pts[0]; - $ry = $pts[1]; - } - else { - $rx = $pts[2]; - $ry = $pts[3]; - } - $width = abs($pts[4]-$pts[0])+1; - $height = abs($pts[1]-$pts[3])+1; - $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); - $prect->Stroke($img); - } - else { - if( $this->iPattern > -1 ) { - $f = new RectPatternFactory(); - $prect = $f->Create($this->iPattern,$this->iPatternColor,1); - $prect->SetDensity($this->iPatternDensity); - if( $val < 0 ) { - $rx = $pts[0]; - $ry = $pts[1]; - } - else { - $rx = $pts[2]; - $ry = $pts[3]; - } - $width = abs($pts[4]-$pts[0])+1; - $height = abs($pts[1]-$pts[3])+1; - $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); - $prect->Stroke($img); - } - } - // Stroke the outline of the bar - if( is_array($this->color) ) - $img->SetColor($this->color[$i % count($this->color)]); - else - $img->SetColor($this->color); + $x=$xscale->Translate($x); - $pts[] = $pts[0]; - $pts[] = $pts[1]; + // Comment Note: This confuses the positioning when using acc together with + // grouped bars. Workaround for fixing #191 + /* + if( !$xscale->textscale ) { + if($this->align=="center") + $x -= $abswidth/2; + elseif($this->align=="right") + $x -= $abswidth; + } + */ + // Stroke fill color and fill gradient + $pts=array( + $x,$zp, + $x,$yscale->Translate($this->coords[0][$i]), + $x+$abswidth,$yscale->Translate($this->coords[0][$i]), + $x+$abswidth,$zp); + if( $this->grad ) { + if( $grad === null ) { + $grad = new Gradient($img); + } + if( is_array($this->grad_fromcolor) ) { + // The first argument (grad_fromcolor) can be either an array or a single color. If it is an array + // then we have two choices. It can either a) be a single color specified as an RGB triple or it can be + // an array to specify both (from, to style) for each individual bar. The way to know the difference is + // to investgate the first element. If this element is an integer [0,255] then we assume it is an RGB + // triple. + $ng = count($this->grad_fromcolor); + if( $ng === 3 ) { + if( is_numeric($this->grad_fromcolor[0]) && $this->grad_fromcolor[0] > 0 && $this->grad_fromcolor[0] < 256 ) { + // RGB Triple + $fromcolor = $this->grad_fromcolor; + $tocolor = $this->grad_tocolor; + $style = $this->grad_style; + } + } + else { + $fromcolor = $this->grad_fromcolor[$i % $ng][0]; + $tocolor = $this->grad_fromcolor[$i % $ng][1]; + $style = $this->grad_fromcolor[$i % $ng][2]; + } + $grad->FilledRectangle($pts[2],$pts[3], + $pts[6],$pts[7], + $fromcolor,$tocolor,$style); + } + else { + $grad->FilledRectangle($pts[2],$pts[3], + $pts[6],$pts[7], + $this->grad_fromcolor,$this->grad_tocolor,$this->grad_style); + } + } + elseif( !empty($this->fill_color) ) { + if(is_array($this->fill_color)) { + $img->PushColor($this->fill_color[$i % count($this->fill_color)]); + } else { + $img->PushColor($this->fill_color); + } + $img->FilledPolygon($pts); + $img->PopColor(); + } - if( $this->weight > 0 ) { - $img->SetLineWeight($this->weight); - $img->Polygon($pts); - } - - // Determine how to best position the values of the individual bars - $x=$pts[2]+($pts[4]-$pts[2])/2; - if( $this->valuepos=='top' ) { - $y=$pts[3]; - if( $img->a === 90 ) { - if( $val < 0 ) - $this->value->SetAlign('right','center'); - else - $this->value->SetAlign('left','center'); - - } - $this->value->Stroke($img,$val,$x,$y); - } - elseif( $this->valuepos=='max' ) { - $y=$pts[3]; - if( $img->a === 90 ) { - if( $val < 0 ) - $this->value->SetAlign('left','center'); - else - $this->value->SetAlign('right','center'); - } - else { - $this->value->SetAlign('center','top'); - } - $this->value->SetMargin(-3); - $this->value->Stroke($img,$val,$x,$y); - } - elseif( $this->valuepos=='center' ) { - $y = ($pts[3] + $pts[1])/2; - $this->value->SetAlign('center','center'); - $this->value->SetMargin(0); - $this->value->Stroke($img,$val,$x,$y); - } - elseif( $this->valuepos=='bottom' || $this->valuepos=='min' ) { - $y=$pts[1]; - if( $img->a === 90 ) { - if( $val < 0 ) - $this->value->SetAlign('right','center'); - else - $this->value->SetAlign('left','center'); - } - $this->value->SetMargin(3); - $this->value->Stroke($img,$val,$x,$y); - } - else { - JpGraphError::Raise('Unknown position for values on bars :'.$this->valuepos); - } - // Create the client side image map - $rpts = $img->ArrRotate($pts); - $csimcoord=round($rpts[0]).", ".round($rpts[1]); - for( $j=1; $j < 4; ++$j){ - $csimcoord .= ", ".round($rpts[2*$j]).", ".round($rpts[2*$j+1]); - } - if( !empty($this->csimtargets[$i]) ) { - $this->csimareas .= 'csimareas .= " href=\"".htmlentities($this->csimtargets[$i])."\""; - if( !empty($this->csimwintargets[$i]) ) { - $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; - } + // Remember value of this bar + $val=$this->coords[0][$i]; - $sval=''; - if( !empty($this->csimalts[$i]) ) { - $sval=sprintf($this->csimalts[$i],$this->coords[0][$i]); - $this->csimareas .= " title=\"$sval\" alt=\"$sval\" "; - } - $this->csimareas .= " />\n"; - } - } - return true; + if( !empty($val) && !is_numeric($val) ) { + JpGraphError::RaiseL(2004,$i,$val); + //'All values for a barplot must be numeric. You have specified value['.$i.'] == \''.$val.'\''); + } + + // Determine the shadow + if( $this->bar_shadow && $val != 0) { + + $ssh = $this->bar_shadow_hsize; + $ssv = $this->bar_shadow_vsize; + // Create points to create a "upper-right" shadow + if( $val > 0 ) { + $sp[0]=$pts[6]; $sp[1]=$pts[7]; + $sp[2]=$pts[4]; $sp[3]=$pts[5]; + $sp[4]=$pts[2]; $sp[5]=$pts[3]; + $sp[6]=$pts[2]+$ssh; $sp[7]=$pts[3]-$ssv; + $sp[8]=$pts[4]+$ssh; $sp[9]=$pts[5]-$ssv; + $sp[10]=$pts[6]+$ssh; $sp[11]=$pts[7]-$ssv; + } + elseif( $val < 0 ) { + $sp[0]=$pts[4]; $sp[1]=$pts[5]; + $sp[2]=$pts[6]; $sp[3]=$pts[7]; + $sp[4]=$pts[0]; $sp[5]=$pts[1]; + $sp[6]=$pts[0]+$ssh; $sp[7]=$pts[1]-$ssv; + $sp[8]=$pts[6]+$ssh; $sp[9]=$pts[7]-$ssv; + $sp[10]=$pts[4]+$ssh; $sp[11]=$pts[5]-$ssv; + } + if( is_array($this->bar_shadow_color) ) { + $numcolors = count($this->bar_shadow_color); + if( $numcolors == 0 ) { + JpGraphError::RaiseL(2005);//('You have specified an empty array for shadow colors in the bar plot.'); + } + $img->PushColor($this->bar_shadow_color[$i % $numcolors]); + } + else { + $img->PushColor($this->bar_shadow_color); + } + $img->FilledPolygon($sp); + $img->PopColor(); + } + + // Stroke the pattern + if( is_array($this->iPattern) ) { + $f = new RectPatternFactory(); + if( is_array($this->iPatternColor) ) { + $pcolor = $this->iPatternColor[$i % $np]; + } + else { + $pcolor = $this->iPatternColor; + } + $prect = $f->Create($this->iPattern[$i % $np],$pcolor,1); + $prect->SetDensity($this->iPatternDensity[$i % $np]); + + if( $val < 0 ) { + $rx = $pts[0]; + $ry = $pts[1]; + } + else { + $rx = $pts[2]; + $ry = $pts[3]; + } + $width = abs($pts[4]-$pts[0])+1; + $height = abs($pts[1]-$pts[3])+1; + $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); + $prect->Stroke($img); + } + else { + if( $this->iPattern > -1 ) { + $f = new RectPatternFactory(); + $prect = $f->Create($this->iPattern,$this->iPatternColor,1); + $prect->SetDensity($this->iPatternDensity); + if( $val < 0 ) { + $rx = $pts[0]; + $ry = $pts[1]; + } + else { + $rx = $pts[2]; + $ry = $pts[3]; + } + $width = abs($pts[4]-$pts[0])+1; + $height = abs($pts[1]-$pts[3])+1; + $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); + $prect->Stroke($img); + } + } + + // Stroke the outline of the bar + if( is_array($this->color) ) { + $img->SetColor($this->color[$i % count($this->color)]); + } + else { + $img->SetColor($this->color); + } + + $pts[] = $pts[0]; + $pts[] = $pts[1]; + + if( $this->weight > 0 ) { + $img->SetLineWeight($this->weight); + $img->Polygon($pts); + } + + // Determine how to best position the values of the individual bars + $x=$pts[2]+($pts[4]-$pts[2])/2; + $this->value->SetMargin(5); + + if( $this->valuepos=='top' ) { + $y=$pts[3]; + if( $img->a === 90 ) { + if( $val < 0 ) { + $this->value->SetAlign('right','center'); + } + else { + $this->value->SetAlign('left','center'); + } + + } + else { + if( $val < 0 ) { + $this->value->SetMargin(-5); + $y=$pts[1]; + $this->value->SetAlign('center','bottom'); + } + else { + $this->value->SetAlign('center','bottom'); + } + + } + $this->value->Stroke($img,$val,$x,$y); + } + elseif( $this->valuepos=='max' ) { + $y=$pts[3]; + if( $img->a === 90 ) { + if( $val < 0 ) + $this->value->SetAlign('left','center'); + else + $this->value->SetAlign('right','center'); + } + else { + if( $val < 0 ) { + $this->value->SetAlign('center','bottom'); + } + else { + $this->value->SetAlign('center','top'); + } + } + $this->value->SetMargin(-5); + $this->value->Stroke($img,$val,$x,$y); + } + elseif( $this->valuepos=='center' ) { + $y = ($pts[3] + $pts[1])/2; + $this->value->SetAlign('center','center'); + $this->value->SetMargin(0); + $this->value->Stroke($img,$val,$x,$y); + } + elseif( $this->valuepos=='bottom' || $this->valuepos=='min' ) { + $y=$pts[1]; + if( $img->a === 90 ) { + if( $val < 0 ) + $this->value->SetAlign('right','center'); + else + $this->value->SetAlign('left','center'); + } + $this->value->SetMargin(3); + $this->value->Stroke($img,$val,$x,$y); + } + else { + JpGraphError::RaiseL(2006,$this->valuepos); + //'Unknown position for values on bars :'.$this->valuepos); + } + // Create the client side image map + $rpts = $img->ArrRotate($pts); + $csimcoord=round($rpts[0]).", ".round($rpts[1]); + for( $j=1; $j < 4; ++$j){ + $csimcoord .= ", ".round($rpts[2*$j]).", ".round($rpts[2*$j+1]); + } + if( !empty($this->csimtargets[$i]) ) { + $this->csimareas .= 'csimareas .= " href=\"".htmlentities($this->csimtargets[$i])."\""; + + if( !empty($this->csimwintargets[$i]) ) { + $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; + } + + $sval=''; + if( !empty($this->csimalts[$i]) ) { + $sval=sprintf($this->csimalts[$i],$this->coords[0][$i]); + $this->csimareas .= " title=\"$sval\" alt=\"$sval\" "; + } + $this->csimareas .= " />\n"; + } + } + return true; } } // Class @@ -563,87 +621,88 @@ class BarPlot extends Plot { //=================================================== class GroupBarPlot extends BarPlot { private $plots, $nbrplots=0; -//--------------- -// CONSTRUCTOR + //--------------- + // CONSTRUCTOR function GroupBarPlot($plots) { - $this->width=0.7; - $this->plots = $plots; - $this->nbrplots = count($plots); - if( $this->nbrplots < 1 ) { - JpGraphError::Raise('Cannot create GroupBarPlot from empty plot array.'); - } - for($i=0; $i < $this->nbrplots; ++$i ) { - if( empty($this->plots[$i]) || !isset($this->plots[$i]) ) { - JpGraphError::Raise("Group bar plot element nbr $i is undefined or empty."); - } - } - $this->numpoints = $plots[0]->numpoints; - $this->width=0.7; + $this->width=0.7; + $this->plots = $plots; + $this->nbrplots = count($plots); + if( $this->nbrplots < 1 ) { + JpGraphError::RaiseL(2007);//('Cannot create GroupBarPlot from empty plot array.'); + } + for($i=0; $i < $this->nbrplots; ++$i ) { + if( empty($this->plots[$i]) || !isset($this->plots[$i]) ) { + JpGraphError::RaiseL(2008,$i);//("Group bar plot element nbr $i is undefined or empty."); + } + } + $this->numpoints = $plots[0]->numpoints; + $this->width=0.7; } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function Legend($graph) { - $n = count($this->plots); - for($i=0; $i < $n; ++$i) { - $c = get_class($this->plots[$i]); - if( !($this->plots[$i] instanceof BarPlot) ) { - JpGraphError::Raise('One of the objects submitted to GroupBar is not a BarPlot. Make sure that you create the Group Bar plot from an array of BarPlot or AccBarPlot objects. (Class = '.$c.')'); - } - $this->plots[$i]->DoLegend($graph); - } + $n = count($this->plots); + for($i=0; $i < $n; ++$i) { + $c = get_class($this->plots[$i]); + if( !($this->plots[$i] instanceof BarPlot) ) { + JpGraphError::RaiseL(2009,$c); + //('One of the objects submitted to GroupBar is not a BarPlot. Make sure that you create the Group Bar plot from an array of BarPlot or AccBarPlot objects. (Class = '.$c.')'); + } + $this->plots[$i]->DoLegend($graph); + } } - - function Min() { - list($xmin,$ymin) = $this->plots[0]->Min(); - $n = count($this->plots); - for($i=0; $i < $n; ++$i) { - list($xm,$ym) = $this->plots[$i]->Min(); - $xmin = max($xmin,$xm); - $ymin = min($ymin,$ym); - } - return array($xmin,$ymin); - } - - function Max() { - list($xmax,$ymax) = $this->plots[0]->Max(); - $n = count($this->plots); - for($i=0; $i < $n; ++$i) { - list($xm,$ym) = $this->plots[$i]->Max(); - $xmax = max($xmax,$xm); - $ymax = max($ymax,$ym); - } - return array($xmax,$ymax); - } - - function GetCSIMareas() { - $n = count($this->plots); - $csimareas=''; - for($i=0; $i < $n; ++$i) { - $csimareas .= $this->plots[$i]->csimareas; - } - return $csimareas; - } - - // Stroke all the bars next to each other - function Stroke($img,$xscale,$yscale) { - $tmp=$xscale->off; - $n = count($this->plots); - $subwidth = $this->width/$this->nbrplots ; - for( $i=0; $i < $n; ++$i ) { - $this->plots[$i]->ymin=$this->ybase; - $this->plots[$i]->SetWidth($subwidth); - - // If the client have used SetTextTickInterval() then - // major_step will be > 1 and the positioning will fail. - // If we assume it is always one the positioning will work - // fine with a text scale but this will not work with - // arbitrary linear scale - $xscale->off = $tmp+$i*round($xscale->scale_factor* $subwidth); - $this->plots[$i]->Stroke($img,$xscale,$yscale); - } - $xscale->off=$tmp; + function Min() { + list($xmin,$ymin) = $this->plots[0]->Min(); + $n = count($this->plots); + for($i=0; $i < $n; ++$i) { + list($xm,$ym) = $this->plots[$i]->Min(); + $xmin = max($xmin,$xm); + $ymin = min($ymin,$ym); + } + return array($xmin,$ymin); + } + + function Max() { + list($xmax,$ymax) = $this->plots[0]->Max(); + $n = count($this->plots); + for($i=0; $i < $n; ++$i) { + list($xm,$ym) = $this->plots[$i]->Max(); + $xmax = max($xmax,$xm); + $ymax = max($ymax,$ym); + } + return array($xmax,$ymax); + } + + function GetCSIMareas() { + $n = count($this->plots); + $csimareas=''; + for($i=0; $i < $n; ++$i) { + $csimareas .= $this->plots[$i]->csimareas; + } + return $csimareas; + } + + // Stroke all the bars next to each other + function Stroke($img,$xscale,$yscale) { + $tmp=$xscale->off; + $n = count($this->plots); + $subwidth = $this->width/$this->nbrplots ; + + for( $i=0; $i < $n; ++$i ) { + $this->plots[$i]->ymin=$this->ybase; + $this->plots[$i]->SetWidth($subwidth); + + // If the client have used SetTextTickInterval() then + // major_step will be > 1 and the positioning will fail. + // If we assume it is always one the positioning will work + // fine with a text scale but this will not work with + // arbitrary linear scale + $xscale->off = $tmp+$i*round($xscale->scale_factor* $subwidth); + $this->plots[$i]->Stroke($img,$xscale,$yscale); + } + $xscale->off=$tmp; } } // Class @@ -653,355 +712,383 @@ class GroupBarPlot extends BarPlot { //=================================================== class AccBarPlot extends BarPlot { private $plots=null,$nbrplots=0; -//--------------- -// CONSTRUCTOR - function AccBarPlot($plots) { - $this->plots = $plots; - $this->nbrplots = count($plots); - if( $this->nbrplots < 1 ) { - JpGraphError::Raise('Cannot create AccBarPlot from empty plot array.'); - } - for($i=0; $i < $this->nbrplots; ++$i ) { - if( empty($this->plots[$i]) || !isset($this->plots[$i]) ) { - JpGraphError::Raise("Acc bar plot element nbr $i is undefined or empty."); - } - } - $this->numpoints = $plots[0]->numpoints; - $this->value = new DisplayValue(); + //--------------- + // CONSTRUCTOR + function __construct($plots) { + $this->plots = $plots; + $this->nbrplots = count($plots); + if( $this->nbrplots < 1 ) { + JpGraphError::RaiseL(2010);//('Cannot create AccBarPlot from empty plot array.'); + } + for($i=0; $i < $this->nbrplots; ++$i ) { + if( empty($this->plots[$i]) || !isset($this->plots[$i]) ) { + JpGraphError::RaiseL(2011,$i);//("Acc bar plot element nbr $i is undefined or empty."); + } + } + + // We can only allow individual plost which do not have specified X-positions + for($i=0; $i < $this->nbrplots; ++$i ) { + if( !empty($this->plots[$i]->coords[1]) ) { + JpGraphError::RaiseL(2015); + //'Individual bar plots in an AccBarPlot or GroupBarPlot can not have specified X-positions.'); + } + } + + // Use 0 weight by default which means that the individual bar + // weights will be used per part n the accumulated bar + $this->SetWeight(0); + + $this->numpoints = $plots[0]->numpoints; + $this->value = new DisplayValue(); } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function Legend($graph) { - $n = count($this->plots); - for( $i=$n-1; $i >= 0; --$i ) { - $c = get_class($this->plots[$i]); - if( !($this->plots[$i] instanceof BarPlot) ) { - JpGraphError::Raise('One of the objects submitted to AccBar is not a BarPlot. Make sure that you create the AccBar plot from an array of BarPlot objects.(Class='.$c.')'); - } - $this->plots[$i]->DoLegend($graph); - } + $n = count($this->plots); + for( $i=$n-1; $i >= 0; --$i ) { + $c = get_class($this->plots[$i]); + if( !($this->plots[$i] instanceof BarPlot) ) { + JpGraphError::RaiseL(2012,$c); + //('One of the objects submitted to AccBar is not a BarPlot. Make sure that you create the AccBar plot from an array of BarPlot objects.(Class='.$c.')'); + } + $this->plots[$i]->DoLegend($graph); + } } function Max() { - list($xmax) = $this->plots[0]->Max(); - $nmax=0; - for($i=0; $i < count($this->plots); ++$i) { - $n = count($this->plots[$i]->coords[0]); - $nmax = max($nmax,$n); - list($x) = $this->plots[$i]->Max(); - $xmax = max($xmax,$x); - } - for( $i = 0; $i < $nmax; $i++ ) { - // Get y-value for bar $i by adding the - // individual bars from all the plots added. - // It would be wrong to just add the - // individual plots max y-value since that - // would in most cases give to large y-value. - $y=0; - if( !isset($this->plots[0]->coords[0][$i]) ) { - JpGraphError::RaiseL(2014); - } - if( $this->plots[0]->coords[0][$i] > 0 ) - $y=$this->plots[0]->coords[0][$i]; - for( $j = 1; $j < $this->nbrplots; $j++ ) { - if( !isset($this->plots[$j]->coords[0][$i]) ) { - JpGraphError::RaiseL(2014); - } - if( $this->plots[$j]->coords[0][$i] > 0 ) - $y += $this->plots[$j]->coords[0][$i]; - } - $ymax[$i] = $y; - } - $ymax = max($ymax); + list($xmax) = $this->plots[0]->Max(); + $nmax=0; + for($i=0; $i < count($this->plots); ++$i) { + $n = count($this->plots[$i]->coords[0]); + $nmax = max($nmax,$n); + list($x) = $this->plots[$i]->Max(); + $xmax = max($xmax,$x); + } + for( $i = 0; $i < $nmax; $i++ ) { + // Get y-value for bar $i by adding the + // individual bars from all the plots added. + // It would be wrong to just add the + // individual plots max y-value since that + // would in most cases give to large y-value. + $y=0; + if( !isset($this->plots[0]->coords[0][$i]) ) { + JpGraphError::RaiseL(2014); + } + if( $this->plots[0]->coords[0][$i] > 0 ) + $y=$this->plots[0]->coords[0][$i]; + for( $j = 1; $j < $this->nbrplots; $j++ ) { + if( !isset($this->plots[$j]->coords[0][$i]) ) { + JpGraphError::RaiseL(2014); + } + if( $this->plots[$j]->coords[0][$i] > 0 ) + $y += $this->plots[$j]->coords[0][$i]; + } + $ymax[$i] = $y; + } + $ymax = max($ymax); - // Bar always start at baseline - if( $ymax <= $this->ybase ) - $ymax = $this->ybase; - return array($xmax,$ymax); + // Bar always start at baseline + if( $ymax <= $this->ybase ) + $ymax = $this->ybase; + return array($xmax,$ymax); } function Min() { - $nmax=0; - list($xmin,$ysetmin) = $this->plots[0]->Min(); - for($i=0; $i < count($this->plots); ++$i) { - $n = count($this->plots[$i]->coords[0]); - $nmax = max($nmax,$n); - list($x,$y) = $this->plots[$i]->Min(); - $xmin = Min($xmin,$x); - $ysetmin = Min($y,$ysetmin); - } - for( $i = 0; $i < $nmax; $i++ ) { - // Get y-value for bar $i by adding the - // individual bars from all the plots added. - // It would be wrong to just add the - // individual plots max y-value since that - // would in most cases give to large y-value. - $y=0; - if( $this->plots[0]->coords[0][$i] < 0 ) - $y=$this->plots[0]->coords[0][$i]; - for( $j = 1; $j < $this->nbrplots; $j++ ) { - if( $this->plots[$j]->coords[0][$i] < 0 ) - $y += $this->plots[ $j ]->coords[0][$i]; - } - $ymin[$i] = $y; - } - $ymin = Min($ysetmin,Min($ymin)); - // Bar always start at baseline - if( $ymin >= $this->ybase ) - $ymin = $this->ybase; - return array($xmin,$ymin); + $nmax=0; + list($xmin,$ysetmin) = $this->plots[0]->Min(); + for($i=0; $i < count($this->plots); ++$i) { + $n = count($this->plots[$i]->coords[0]); + $nmax = max($nmax,$n); + list($x,$y) = $this->plots[$i]->Min(); + $xmin = Min($xmin,$x); + $ysetmin = Min($y,$ysetmin); + } + for( $i = 0; $i < $nmax; $i++ ) { + // Get y-value for bar $i by adding the + // individual bars from all the plots added. + // It would be wrong to just add the + // individual plots max y-value since that + // would in most cases give to large y-value. + $y=0; + if( $this->plots[0]->coords[0][$i] < 0 ) + $y=$this->plots[0]->coords[0][$i]; + for( $j = 1; $j < $this->nbrplots; $j++ ) { + if( $this->plots[$j]->coords[0][$i] < 0 ) + $y += $this->plots[ $j ]->coords[0][$i]; + } + $ymin[$i] = $y; + } + $ymin = Min($ysetmin,Min($ymin)); + // Bar always start at baseline + if( $ymin >= $this->ybase ) + $ymin = $this->ybase; + return array($xmin,$ymin); } // Stroke acc bar plot function Stroke($img,$xscale,$yscale) { - $pattern=NULL; - $img->SetLineWeight($this->weight); - for($i=0; $i < $this->numpoints-1; $i++) { - $accy = 0; - $accy_neg = 0; - for($j=0; $j < $this->nbrplots; ++$j ) { - $img->SetColor($this->plots[$j]->color); + $pattern=NULL; + $img->SetLineWeight($this->weight); + for($i=0; $i < $this->numpoints-1; $i++) { + $accy = 0; + $accy_neg = 0; + for($j=0; $j < $this->nbrplots; ++$j ) { + $img->SetColor($this->plots[$j]->color); - if ( $this->plots[$j]->coords[0][$i] >= 0) { - $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy); - $accyt=$yscale->Translate($accy); - $accy+=$this->plots[$j]->coords[0][$i]; - } - else { - //if ( $this->plots[$j]->coords[0][$i] < 0 || $accy_neg < 0 ) { - $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy_neg); - $accyt=$yscale->Translate($accy_neg); - $accy_neg+=$this->plots[$j]->coords[0][$i]; - } - - $xt=$xscale->Translate($i); + if ( $this->plots[$j]->coords[0][$i] >= 0) { + $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy); + $accyt=$yscale->Translate($accy); + $accy+=$this->plots[$j]->coords[0][$i]; + } + else { + //if ( $this->plots[$j]->coords[0][$i] < 0 || $accy_neg < 0 ) { + $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy_neg); + $accyt=$yscale->Translate($accy_neg); + $accy_neg+=$this->plots[$j]->coords[0][$i]; + } - if( $this->abswidth > -1 ) - $abswidth=$this->abswidth; - else - $abswidth=round($this->width*$xscale->scale_factor,0); - - $pts=array($xt,$accyt,$xt,$yt,$xt+$abswidth,$yt,$xt+$abswidth,$accyt); + $xt=$xscale->Translate($i); - if( $this->bar_shadow ) { - $ssh = $this->bar_shadow_hsize; - $ssv = $this->bar_shadow_vsize; - - // We must also differ if we are a positive or negative bar. - if( $j === 0 ) { - // This gets extra complicated since we have to - // see all plots to see if we are negative. It could - // for example be that all plots are 0 until the very - // last one. We therefore need to save the initial setup - // for both the negative and positive case + if( $this->abswidth > -1 ) { + $abswidth=$this->abswidth; + } + else { + $abswidth=round($this->width*$xscale->scale_factor,0); + } - // In case the final bar is positive - $sp[0]=$pts[6]+1; $sp[1]=$pts[7]; - $sp[2]=$pts[6]+$ssh; $sp[3]=$pts[7]-$ssv; + $pts=array($xt,$accyt,$xt,$yt,$xt+$abswidth,$yt,$xt+$abswidth,$accyt); - // In case the final bar is negative - $nsp[0]=$pts[0]; $nsp[1]=$pts[1]; - $nsp[2]=$pts[0]+$ssh; $nsp[3]=$pts[1]-$ssv; - $nsp[4]=$pts[6]+$ssh; $nsp[5]=$pts[7]-$ssv; - $nsp[10]=$pts[6]+1; $nsp[11]=$pts[7]; - } + if( $this->bar_shadow ) { + $ssh = $this->bar_shadow_hsize; + $ssv = $this->bar_shadow_vsize; - if( $j === $this->nbrplots-1 ) { - // If this is the last plot of the bar and - // the total value is larger than 0 then we - // add the shadow. - if( is_array($this->bar_shadow_color) ) { - $numcolors = count($this->bar_shadow_color); - if( $numcolors == 0 ) { - JpGraphError::Raise('You have specified an empty array for shadow colors in the bar plot.'); - } - $img->PushColor($this->bar_shadow_color[$i % $numcolors]); - } - else { - $img->PushColor($this->bar_shadow_color); - } + // We must also differ if we are a positive or negative bar. + if( $j === 0 ) { + // This gets extra complicated since we have to + // see all plots to see if we are negative. It could + // for example be that all plots are 0 until the very + // last one. We therefore need to save the initial setup + // for both the negative and positive case - if( $accy > 0 ) { - $sp[4]=$pts[4]+$ssh; $sp[5]=$pts[5]-$ssv; - $sp[6]=$pts[2]+$ssh; $sp[7]=$pts[3]-$ssv; - $sp[8]=$pts[2]; $sp[9]=$pts[3]-1; - $sp[10]=$pts[4]+1; $sp[11]=$pts[5]; - $img->FilledPolygon($sp,4); - } - elseif( $accy_neg < 0 ) { - $nsp[6]=$pts[4]+$ssh; $nsp[7]=$pts[5]-$ssv; - $nsp[8]=$pts[4]+1; $nsp[9]=$pts[5]; - $img->FilledPolygon($nsp,4); - } - $img->PopColor(); - } - } + // In case the final bar is positive + $sp[0]=$pts[6]+1; $sp[1]=$pts[7]; + $sp[2]=$pts[6]+$ssh; $sp[3]=$pts[7]-$ssv; + + // In case the final bar is negative + $nsp[0]=$pts[0]; $nsp[1]=$pts[1]; + $nsp[2]=$pts[0]+$ssh; $nsp[3]=$pts[1]-$ssv; + $nsp[4]=$pts[6]+$ssh; $nsp[5]=$pts[7]-$ssv; + $nsp[10]=$pts[6]+1; $nsp[11]=$pts[7]; + } + + if( $j === $this->nbrplots-1 ) { + // If this is the last plot of the bar and + // the total value is larger than 0 then we + // add the shadow. + if( is_array($this->bar_shadow_color) ) { + $numcolors = count($this->bar_shadow_color); + if( $numcolors == 0 ) { + JpGraphError::RaiseL(2013);//('You have specified an empty array for shadow colors in the bar plot.'); + } + $img->PushColor($this->bar_shadow_color[$i % $numcolors]); + } + else { + $img->PushColor($this->bar_shadow_color); + } + + if( $accy > 0 ) { + $sp[4]=$pts[4]+$ssh; $sp[5]=$pts[5]-$ssv; + $sp[6]=$pts[2]+$ssh; $sp[7]=$pts[3]-$ssv; + $sp[8]=$pts[2]; $sp[9]=$pts[3]-1; + $sp[10]=$pts[4]+1; $sp[11]=$pts[5]; + $img->FilledPolygon($sp,4); + } + elseif( $accy_neg < 0 ) { + $nsp[6]=$pts[4]+$ssh; $nsp[7]=$pts[5]-$ssv; + $nsp[8]=$pts[4]+1; $nsp[9]=$pts[5]; + $img->FilledPolygon($nsp,4); + } + $img->PopColor(); + } + } - // If value is NULL or 0, then don't draw a bar at all - if ($this->plots[$j]->coords[0][$i] == 0 ) continue; + // If value is NULL or 0, then don't draw a bar at all + if ($this->plots[$j]->coords[0][$i] == 0 ) continue; - if( $this->plots[$j]->grad ) { - $grad = new Gradient($img); - $grad->FilledRectangle( - $pts[2],$pts[3], - $pts[6],$pts[7], - $this->plots[$j]->grad_fromcolor, - $this->plots[$j]->grad_tocolor, - $this->plots[$j]->grad_style); - } else { - if (is_array($this->plots[$j]->fill_color) ) { - $numcolors = count($this->plots[$j]->fill_color); - $fillcolor = $this->plots[$j]->fill_color[$i % $numcolors]; - // If the bar is specified to be non filled then the fill color is false - if( $fillcolor !== false ) - $img->SetColor($this->plots[$j]->fill_color[$i % $numcolors]); - } - else { - $fillcolor = $this->plots[$j]->fill_color; - if( $fillcolor !== false ) - $img->SetColor($this->plots[$j]->fill_color); - } - if( $fillcolor !== false ) - $img->FilledPolygon($pts); - $img->SetColor($this->plots[$j]->color); - } + if( $this->plots[$j]->grad ) { + $grad = new Gradient($img); + $grad->FilledRectangle( $pts[2],$pts[3], + $pts[6],$pts[7], + $this->plots[$j]->grad_fromcolor, + $this->plots[$j]->grad_tocolor, + $this->plots[$j]->grad_style); + } else { + if (is_array($this->plots[$j]->fill_color) ) { + $numcolors = count($this->plots[$j]->fill_color); + $fillcolor = $this->plots[$j]->fill_color[$i % $numcolors]; + // If the bar is specified to be non filled then the fill color is false + if( $fillcolor !== false ) { + $img->SetColor($this->plots[$j]->fill_color[$i % $numcolors]); + } + } + else { + $fillcolor = $this->plots[$j]->fill_color; + if( $fillcolor !== false ) { + $img->SetColor($this->plots[$j]->fill_color); + } + } + if( $fillcolor !== false ) { + $img->FilledPolygon($pts); + } + } - // Stroke the pattern - if( $this->plots[$j]->iPattern > -1 ) { - if( $pattern===NULL ) - $pattern = new RectPatternFactory(); - - $prect = $pattern->Create($this->plots[$j]->iPattern,$this->plots[$j]->iPatternColor,1); - $prect->SetDensity($this->plots[$j]->iPatternDensity); - if( $this->plots[$j]->coords[0][$i] < 0 ) { - $rx = $pts[0]; - $ry = $pts[1]; - } - else { - $rx = $pts[2]; - $ry = $pts[3]; - } - $width = abs($pts[4]-$pts[0])+1; - $height = abs($pts[1]-$pts[3])+1; - $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); - $prect->Stroke($img); - } + $img->SetColor($this->plots[$j]->color); + + // Stroke the pattern + if( $this->plots[$j]->iPattern > -1 ) { + if( $pattern===NULL ) { + $pattern = new RectPatternFactory(); + } + + $prect = $pattern->Create($this->plots[$j]->iPattern,$this->plots[$j]->iPatternColor,1); + $prect->SetDensity($this->plots[$j]->iPatternDensity); + if( $this->plots[$j]->coords[0][$i] < 0 ) { + $rx = $pts[0]; + $ry = $pts[1]; + } + else { + $rx = $pts[2]; + $ry = $pts[3]; + } + $width = abs($pts[4]-$pts[0])+1; + $height = abs($pts[1]-$pts[3])+1; + $prect->SetPos(new Rectangle($rx,$ry,$width,$height)); + $prect->Stroke($img); + } - // CSIM array + // CSIM array - if( $i < count($this->plots[$j]->csimtargets) ) { - // Create the client side image map - $rpts = $img->ArrRotate($pts); - $csimcoord=round($rpts[0]).", ".round($rpts[1]); - for( $k=1; $k < 4; ++$k){ - $csimcoord .= ", ".round($rpts[2*$k]).", ".round($rpts[2*$k+1]); - } - if( ! empty($this->plots[$j]->csimtargets[$i]) ) { - $this->csimareas.= 'csimareas.= " href=\"".$this->plots[$j]->csimtargets[$i]."\" "; + if( $i < count($this->plots[$j]->csimtargets) ) { + // Create the client side image map + $rpts = $img->ArrRotate($pts); + $csimcoord=round($rpts[0]).", ".round($rpts[1]); + for( $k=1; $k < 4; ++$k){ + $csimcoord .= ", ".round($rpts[2*$k]).", ".round($rpts[2*$k+1]); + } + if( ! empty($this->plots[$j]->csimtargets[$i]) ) { + $this->csimareas.= 'csimareas.= " href=\"".$this->plots[$j]->csimtargets[$i]."\" "; - if( ! empty($this->plots[$j]->csimwintargets[$i]) ) { - $this->csimareas.= " target=\"".$this->plots[$j]->csimwintargets[$i]."\" "; - } + if( ! empty($this->plots[$j]->csimwintargets[$i]) ) { + $this->csimareas.= " target=\"".$this->plots[$j]->csimwintargets[$i]."\" "; + } - $sval=''; - if( !empty($this->plots[$j]->csimalts[$i]) ) { - $sval=sprintf($this->plots[$j]->csimalts[$i],$this->plots[$j]->coords[0][$i]); - $this->csimareas .= " title=\"$sval\" "; - } - $this->csimareas .= " alt=\"$sval\" />\n"; - } - } + $sval=''; + if( !empty($this->plots[$j]->csimalts[$i]) ) { + $sval=sprintf($this->plots[$j]->csimalts[$i],$this->plots[$j]->coords[0][$i]); + $this->csimareas .= " title=\"$sval\" "; + } + $this->csimareas .= " alt=\"$sval\" />\n"; + } + } - $pts[] = $pts[0]; - $pts[] = $pts[1]; - $img->SetLineWeight($this->plots[$j]->line_weight); - $img->Polygon($pts); - $img->SetLineWeight(1); - } - - // Draw labels for each acc.bar - - $x=$pts[2]+($pts[4]-$pts[2])/2; - if($this->bar_shadow) $x += $ssh; + $pts[] = $pts[0]; + $pts[] = $pts[1]; + $img->SetLineWeight($this->plots[$j]->weight); + $img->Polygon($pts); + $img->SetLineWeight(1); + } - // First stroke the accumulated value for the entire bar - // This value is always placed at the top/bottom of the bars - if( $accy_neg < 0 ) { - $y=$yscale->Translate($accy_neg); - $this->value->Stroke($img,$accy_neg,$x,$y); - } - else { - $y=$yscale->Translate($accy); - $this->value->Stroke($img,$accy,$x,$y); - } + // Daw potential bar around the entire accbar bar + if( $this->weight > 0 ) { + $y=$yscale->Translate(0); + $img->SetColor($this->color); + $img->SetLineWeight($this->weight); + $img->Rectangle($pts[0],$y,$pts[6],$pts[5]); + } - $accy = 0; - $accy_neg = 0; - for($j=0; $j < $this->nbrplots; ++$j ) { + // Draw labels for each acc.bar - // We don't print 0 values in an accumulated bar plot - if( $this->plots[$j]->coords[0][$i] == 0 ) continue; - - if ($this->plots[$j]->coords[0][$i] > 0) { - $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy); - $accyt=$yscale->Translate($accy); - if( $this->plots[$j]->valuepos=='center' ) { - $y = $accyt-($accyt-$yt)/2; - } - elseif( $this->plots[$j]->valuepos=='bottom' ) { - $y = $accyt; - } - else { // top or max - $y = $accyt-($accyt-$yt); - } - $accy+=$this->plots[$j]->coords[0][$i]; - if( $this->plots[$j]->valuepos=='center' ) { - $this->plots[$j]->value->SetAlign("center","center"); - $this->plots[$j]->value->SetMargin(0); - } - elseif( $this->plots[$j]->valuepos=='bottom' ) { - $this->plots[$j]->value->SetAlign('center','bottom'); - $this->plots[$j]->value->SetMargin(2); - } - else { - $this->plots[$j]->value->SetAlign('center','top'); - $this->plots[$j]->value->SetMargin(1); - } - } else { - $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy_neg); - $accyt=$yscale->Translate($accy_neg); - $accy_neg+=$this->plots[$j]->coords[0][$i]; - if( $this->plots[$j]->valuepos=='center' ) { - $y = $accyt-($accyt-$yt)/2; - } - elseif( $this->plots[$j]->valuepos=='bottom' ) { - $y = $accyt; - } - else { - $y = $accyt-($accyt-$yt); - } - if( $this->plots[$j]->valuepos=='center' ) { - $this->plots[$j]->value->SetAlign("center","center"); - $this->plots[$j]->value->SetMargin(0); - } - elseif( $this->plots[$j]->valuepos=='bottom' ) { - $this->plots[$j]->value->SetAlign('center',$j==0 ? 'bottom':'top'); - $this->plots[$j]->value->SetMargin(-2); - } - else { - $this->plots[$j]->value->SetAlign('center','bottom'); - $this->plots[$j]->value->SetMargin(-1); - } - } - $this->plots[$j]->value->Stroke($img,$this->plots[$j]->coords[0][$i],$x,$y); - } + $x=$pts[2]+($pts[4]-$pts[2])/2; + if($this->bar_shadow) $x += $ssh; - } - return true; + // First stroke the accumulated value for the entire bar + // This value is always placed at the top/bottom of the bars + if( $accy_neg < 0 ) { + $y=$yscale->Translate($accy_neg); + $this->value->Stroke($img,$accy_neg,$x,$y); + } + else { + $y=$yscale->Translate($accy); + $this->value->Stroke($img,$accy,$x,$y); + } + + $accy = 0; + $accy_neg = 0; + for($j=0; $j < $this->nbrplots; ++$j ) { + + // We don't print 0 values in an accumulated bar plot + if( $this->plots[$j]->coords[0][$i] == 0 ) continue; + + if ($this->plots[$j]->coords[0][$i] > 0) { + $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy); + $accyt=$yscale->Translate($accy); + if( $this->plots[$j]->valuepos=='center' ) { + $y = $accyt-($accyt-$yt)/2; + } + elseif( $this->plots[$j]->valuepos=='bottom' ) { + $y = $accyt; + } + else { // top or max + $y = $accyt-($accyt-$yt); + } + $accy+=$this->plots[$j]->coords[0][$i]; + if( $this->plots[$j]->valuepos=='center' ) { + $this->plots[$j]->value->SetAlign("center","center"); + $this->plots[$j]->value->SetMargin(0); + } + elseif( $this->plots[$j]->valuepos=='bottom' ) { + $this->plots[$j]->value->SetAlign('center','bottom'); + $this->plots[$j]->value->SetMargin(2); + } + else { + $this->plots[$j]->value->SetAlign('center','top'); + $this->plots[$j]->value->SetMargin(1); + } + } else { + $yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy_neg); + $accyt=$yscale->Translate($accy_neg); + $accy_neg+=$this->plots[$j]->coords[0][$i]; + if( $this->plots[$j]->valuepos=='center' ) { + $y = $accyt-($accyt-$yt)/2; + } + elseif( $this->plots[$j]->valuepos=='bottom' ) { + $y = $accyt; + } + else { + $y = $accyt-($accyt-$yt); + } + if( $this->plots[$j]->valuepos=='center' ) { + $this->plots[$j]->value->SetAlign("center","center"); + $this->plots[$j]->value->SetMargin(0); + } + elseif( $this->plots[$j]->valuepos=='bottom' ) { + $this->plots[$j]->value->SetAlign('center',$j==0 ? 'bottom':'top'); + $this->plots[$j]->value->SetMargin(-2); + } + else { + $this->plots[$j]->value->SetAlign('center','bottom'); + $this->plots[$j]->value->SetMargin(-1); + } + } + $this->plots[$j]->value->Stroke($img,$this->plots[$j]->coords[0][$i],$x,$y); + } + + } + return true; } } // Class diff --git a/src/classes/jpgraph/jpgraph_errhandler.inc.php b/src/classes/jpgraph/jpgraph_errhandler.inc.php index 3c00cb4..d042bf4 100644 --- a/src/classes/jpgraph/jpgraph_errhandler.inc.php +++ b/src/classes/jpgraph/jpgraph_errhandler.inc.php @@ -1,112 +1,185 @@ lt = $_jpg_messages; + $file = 'lang/'.$__jpg_err_locale.'.inc.php'; + if( !file_exists(dirname(__FILE__).'/'.$file) ) { + die('Chosen locale file ("'.$file.'") for error messages does not exist or is not readable for the PHP process. Please make sure that the file exists and that the file permissions are such that the PHP process is allowed to read this file.'); + } + require($file); + $this->lt = $_jpg_messages; } function Get($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) { - GLOBAL $__jpg_err_locale; - if( !isset($this->lt[$errnbr]) ) { - return 'Internal error: The specified error message ('.$errnbr.') does not exist in the chosen locale ('.$__jpg_err_locale.')'; - } - $ea = $this->lt[$errnbr]; - $j=0; - if( $a1 !== null ) { - $argv[$j++] = $a1; - if( $a2 !== null ) { - $argv[$j++] = $a2; - if( $a3 !== null ) { - $argv[$j++] = $a3; - if( $a4 !== null ) { - $argv[$j++] = $a4; - if( $a5 !== null ) { - $argv[$j++] = $a5; - } - } - } - } - } - $numargs = $j; - if( $ea[1] != $numargs ) { - // Error message argument count do not match. - // Just return the error message without arguments. - return $ea[0]; - } - switch( $numargs ) { - case 1: - $msg = sprintf($ea[0],$argv[0]); - break; - case 2: - $msg = sprintf($ea[0],$argv[0],$argv[1]); - break; - case 3: - $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2]); - break; - case 4: - $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3]); - break; - case 5: - $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3],$argv[4]); - break; - case 0: - default: - $msg = sprintf($ea[0]); - break; - } - return $msg; + GLOBAL $__jpg_err_locale; + if( !isset($this->lt[$errnbr]) ) { + return 'Internal error: The specified error message ('.$errnbr.') does not exist in the chosen locale ('.$__jpg_err_locale.')'; + } + $ea = $this->lt[$errnbr]; + $j=0; + if( $a1 !== null ) { + $argv[$j++] = $a1; + if( $a2 !== null ) { + $argv[$j++] = $a2; + if( $a3 !== null ) { + $argv[$j++] = $a3; + if( $a4 !== null ) { + $argv[$j++] = $a4; + if( $a5 !== null ) { + $argv[$j++] = $a5; + } + } + } + } + } + $numargs = $j; + if( $ea[1] != $numargs ) { + // Error message argument count do not match. + // Just return the error message without arguments. + return $ea[0]; + } + switch( $numargs ) { + case 1: + $msg = sprintf($ea[0],$argv[0]); + break; + case 2: + $msg = sprintf($ea[0],$argv[0],$argv[1]); + break; + case 3: + $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2]); + break; + case 4: + $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3]); + break; + case 5: + $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3],$argv[4]); + break; + case 0: + default: + $msg = sprintf($ea[0]); + break; + } + return $msg; } } - + // // A wrapper class that is used to access the specified error object // (to hide the global error parameter and avoid having a GLOBAL directive // in all methods. // class JpGraphError { - private static $__jpg_err; - public static function Install($aErrObject) { - self::$__jpg_err = new $aErrObject; - } + private static $__iImgFlg = true; + private static $__iLogFile = ''; + private static $__iTitle = 'JpGraph Error: '; public static function Raise($aMsg,$aHalt=true){ - self::$__jpg_err->Raise($aMsg,$aHalt); + throw new JpGraphException($aMsg); } public static function SetErrLocale($aLoc) { - GLOBAL $__jpg_err_locale ; - $__jpg_err_locale = $aLoc; + GLOBAL $__jpg_err_locale ; + $__jpg_err_locale = $aLoc; } public static function RaiseL($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) { - $t = new ErrMsgText(); - $msg = $t->Get($errnbr,$a1,$a2,$a3,$a4,$a5); - self::$__jpg_err->Raise($msg); + throw new JpGraphExceptionL($errnbr,$a1,$a2,$a3,$a4,$a5); + } + public static function SetImageFlag($aFlg=true) { + self::$__iImgFlg = $aFlg; + } + public static function GetImageFlag() { + return self::$__iImgFlg; + } + public static function SetLogFile($aFile) { + self::$__iLogFile = $aFile; + } + public static function GetLogFile() { + return self::$__iLogFile; + } + public static function SetTitle($aTitle) { + self::$__iTitle = $aTitle; + } + public static function GetTitle() { + return self::$__iTitle; + } +} + +// Setup the default handler +global $__jpg_OldHandler; +$__jpg_OldHandler = set_exception_handler(array('JpGraphException','defaultHandler')); + +class JpGraphException extends Exception { + // Redefine the exception so message isn't optional + public function __construct($message, $code = 0) { + // make sure everything is assigned properly + parent::__construct($message, $code); + } + // custom string representation of object + public function _toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message} at " . basename($this->getFile()) . ":" . $this->getLine() . "\n" . $this->getTraceAsString() . "\n"; + } + // custom representation of error as an image + public function Stroke() { + if( JpGraphError::GetImageFlag() ) { + $errobj = new JpGraphErrObjectImg(); + $errobj->SetTitle(JpGraphError::GetTitle()); + } + else { + $errobj = new JpGraphErrObject(); + $errobj->SetTitle(JpGraphError::GetTitle()); + $errobj->SetStrokeDest(JpGraphError::GetLogFile()); + } + $errobj->Raise($this->getMessage()); + } + static public function defaultHandler(Exception $exception) { + global $__jpg_OldHandler; + if( $exception instanceof JpGraphException ) { + $exception->Stroke(); + } + else { + // Restore old handler + if( $__jpg_OldHandler !== NULL ) { + set_exception_handler($__jpg_OldHandler); + } + throw $exception; + } + } +} + +class JpGraphExceptionL extends JpGraphException { + // Redefine the exception so message isn't optional + public function __construct($errcode,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) { + // make sure everything is assigned properly + $errtxt = new ErrMsgText(); + parent::__construct($errtxt->Get($errcode,$a1,$a2,$a3,$a4,$a5), 0); } } @@ -119,37 +192,50 @@ class JpGraphError { //============================================================= class JpGraphErrObject { - protected $iTitle = "JpGraph Error"; + protected $iTitle = "JpGraph error: "; protected $iDest = false; - function JpGraphErrObject() { - // Empty. Reserved for future use + function __construct() { + // Empty. Reserved for future use } function SetTitle($aTitle) { - $this->iTitle = $aTitle; + $this->iTitle = $aTitle; } - function SetStrokeDest($aDest) { - $this->iDest = $aDest; + function SetStrokeDest($aDest) { + $this->iDest = $aDest; } // If aHalt is true then execution can't continue. Typical used for fatal errors - function Raise($aMsg,$aHalt=true) { - $aMsg = $this->iTitle.' '.$aMsg; - if ($this->iDest) { - $f = @fopen($this->iDest,'a'); - if( $f ) { - @fwrite($f,$aMsg); - @fclose($f); - } - } - else { - echo $aMsg; - } - if( $aHalt ) - die(); + function Raise($aMsg,$aHalt=false) { + if( $this->iDest != '' ) { + if( $this->iDest == 'syslog' ) { + error_log($this->iTitle.$aMsg); + } + else { + $str = '['.date('r').'] '.$this->iTitle.$aMsg."\n"; + $f = @fopen($this->iDest,'a'); + if( $f ) { + @fwrite($f,$str); + @fclose($f); + } + } + } + else { + $aMsg = $this->iTitle.$aMsg; + // Check SAPI and if we are called from the command line + // send the error to STDERR instead + if( PHP_SAPI == 'cli' ) { + fwrite(STDERR,$aMsg); + } + else { + echo $aMsg; + } + } + if( $aHalt ) + exit(1); } } @@ -157,122 +243,125 @@ class JpGraphErrObject { // An image based error handler //============================================================== class JpGraphErrObjectImg extends JpGraphErrObject { + + function __construct() { + parent::__construct(); + // Empty. Reserved for future use + } function Raise($aMsg,$aHalt=true) { - $img_iconerror = - 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV'. - 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/'. - 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY'. - 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea'. - 'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx'. - 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4'. - '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+'. - 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6'. - 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3'. - 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0'. - '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS'. - 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk'. - 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc'. - 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx'. - 'qL72fwAAAABJRU5ErkJggg==' ; + $img_iconerror = + 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV'. + 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/'. + 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY'. + 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea'. + 'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx'. + 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4'. + '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+'. + 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6'. + 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3'. + 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0'. + '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS'. + 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk'. + 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc'. + 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx'. + 'qL72fwAAAABJRU5ErkJggg==' ; - if( function_exists("imagetypes") ) - $supported = imagetypes(); - else - $supported = 0; + + if( function_exists("imagetypes") ) { + $supported = imagetypes(); + } else { + $supported = 0; + } - if( !function_exists('imagecreatefromstring') ) - $supported = 0; + if( !function_exists('imagecreatefromstring') ) { + $supported = 0; + } + + if( ob_get_length() || headers_sent() || !($supported & IMG_PNG) ) { + // Special case for headers already sent or that the installation doesn't support + // the PNG format (which the error icon is encoded in). + // Dont return an image since it can't be displayed + die($this->iTitle.' '.$aMsg); + } - if( ob_get_length() || headers_sent() || !($supported & IMG_PNG) ) { - // Special case for headers already sent or that the installation doesn't support - // the PNG format (which the error icon is encoded in). - // Dont return an image since it can't be displayed - die($this->iTitle.' '.$aMsg); - } + $aMsg = wordwrap($aMsg,55); + $lines = substr_count($aMsg,"\n"); - $aMsg = wordwrap($aMsg,55); - $lines = substr_count($aMsg,"\n"); + // Create the error icon GD + $erricon = Image::CreateFromString(base64_decode($img_iconerror)); - // Create the error icon GD - $erricon = Image::CreateFromString(base64_decode($img_iconerror)); + // Create an image that contains the error text. + $w=400; + $h=100 + 15*max(0,$lines-3); - // Create an image that contains the error text. - $w=400; - $h=100 + 15*max(0,$lines-3); - - $img = new Image($w,$h); + $img = new Image($w,$h); - // Drop shadow - $img->SetColor("gray"); - $img->FilledRectangle(5,5,$w-1,$h-1,10); - $img->SetColor("gray:0.7"); - $img->FilledRectangle(5,5,$w-3,$h-3,10); - - // Window background - $img->SetColor("lightblue"); - $img->FilledRectangle(1,1,$w-5,$h-5); - $img->CopyCanvasH($img->img,$erricon,5,30,0,0,40,40); + // Drop shadow + $img->SetColor("gray"); + $img->FilledRectangle(5,5,$w-1,$h-1,10); + $img->SetColor("gray:0.7"); + $img->FilledRectangle(5,5,$w-3,$h-3,10); - // Window border - $img->SetColor("black"); - $img->Rectangle(1,1,$w-5,$h-5); - $img->Rectangle(0,0,$w-4,$h-4); - - // Window top row - $img->SetColor("darkred"); - for($y=3; $y < 18; $y += 2 ) - $img->Line(1,$y,$w-6,$y); + // Window background + $img->SetColor("lightblue"); + $img->FilledRectangle(1,1,$w-5,$h-5); + $img->CopyCanvasH($img->img,$erricon,5,30,0,0,40,40); - // "White shadow" - $img->SetColor("white"); + // Window border + $img->SetColor("black"); + $img->Rectangle(1,1,$w-5,$h-5); + $img->Rectangle(0,0,$w-4,$h-4); - // Left window edge - $img->Line(2,2,2,$h-5); - $img->Line(2,2,$w-6,2); + // Window top row + $img->SetColor("darkred"); + for($y=3; $y < 18; $y += 2 ) + $img->Line(1,$y,$w-6,$y); - // "Gray button shadow" - $img->SetColor("darkgray"); + // "White shadow" + $img->SetColor("white"); - // Gray window shadow - $img->Line(2,$h-6,$w-5,$h-6); - $img->Line(3,$h-7,$w-5,$h-7); + // Left window edge + $img->Line(2,2,2,$h-5); + $img->Line(2,2,$w-6,2); - // Window title - $m = floor($w/2-5); - $l = 100; - $img->SetColor("lightgray:1.3"); - $img->FilledRectangle($m-$l,2,$m+$l,16); + // "Gray button shadow" + $img->SetColor("darkgray"); - // Stroke text - $img->SetColor("darkred"); - $img->SetFont(FF_FONT2,FS_BOLD); - $img->StrokeText($m-50,15,$this->iTitle); - $img->SetColor("black"); - $img->SetFont(FF_FONT1,FS_NORMAL); - $txt = new Text($aMsg,52,25); - $txt->Align("left","top"); - $txt->Stroke($img); - if ($this->iDest) { - $img->Stream($this->iDest); - } else { - $img->Headers(); - $img->Stream(); - } - if( $aHalt ) - die(); + // Gray window shadow + $img->Line(2,$h-6,$w-5,$h-6); + $img->Line(3,$h-7,$w-5,$h-7); + + // Window title + $m = floor($w/2-5); + $l = 100; + $img->SetColor("lightgray:1.3"); + $img->FilledRectangle($m-$l,2,$m+$l,16); + + // Stroke text + $img->SetColor("darkred"); + $img->SetFont(FF_FONT2,FS_BOLD); + $img->StrokeText($m-50,15,$this->iTitle); + $img->SetColor("black"); + $img->SetFont(FF_FONT1,FS_NORMAL); + $txt = new Text($aMsg,52,25); + $txt->Align("left","top"); + $txt->Stroke($img); + if ($this->iDest) { + $img->Stream($this->iDest); + } else { + $img->Headers(); + $img->Stream(); + } + if( $aHalt ) + die(); } } -// Install the default error handler -if( USE_IMAGE_ERROR_HANDLER ) { - JpGraphError::Install("JpGraphErrObjectImg"); -} -else { - JpGraphError::Install("JpGraphErrObject"); -} - +if( ! USE_IMAGE_ERROR_HANDLER ) { + JpGraphError::SetImageFlag(false); +} ?> diff --git a/src/classes/jpgraph/jpgraph_legend.inc.php b/src/classes/jpgraph/jpgraph_legend.inc.php new file mode 100644 index 0000000..fc7bcaa --- /dev/null +++ b/src/classes/jpgraph/jpgraph_legend.inc.php @@ -0,0 +1,420 @@ +hide=$aHide; + } + + function SetHColMargin($aXMarg) { + $this->xmargin = $aXMarg; + } + + function SetVColMargin($aSpacing) { + $this->ymargin = $aSpacing ; + } + + function SetLeftMargin($aXMarg) { + $this->xlmargin = $aXMarg; + } + + // Synonym + function SetLineSpacing($aSpacing) { + $this->ymargin = $aSpacing ; + } + + function SetShadow($aShow='gray',$aWidth=2) { + if( is_string($aShow) ) { + $this->shadow_color = $aShow; + $this->shadow=true; + } + else + $this->shadow=$aShow; + $this->shadow_width=$aWidth; + } + + function SetMarkAbsSize($aSize) { + $this->mark_abs_vsize = $aSize ; + $this->mark_abs_hsize = $aSize ; + } + + function SetMarkAbsVSize($aSize) { + $this->mark_abs_vsize = $aSize ; + } + + function SetMarkAbsHSize($aSize) { + $this->mark_abs_hsize = $aSize ; + } + + function SetLineWeight($aWeight) { + $this->weight = $aWeight; + } + + function SetFrameWeight($aWeight) { + $this->frameweight = $aWeight; + } + + function SetLayout($aDirection=LEGEND_VERT) { + $this->layout_n = $aDirection==LEGEND_VERT ? 1 : 99 ; + } + + function SetColumns($aCols) { + $this->layout_n = $aCols ; + } + + function SetReverse($f=true) { + $this->reverse = $f ; + } + + // Set color on frame around box + function SetColor($aFontColor,$aColor='black') { + $this->font_color=$aFontColor; + $this->color=$aColor; + } + + function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) { + $this->font_family = $aFamily; + $this->font_style = $aStyle; + $this->font_size = $aSize; + } + + function SetPos($aX,$aY,$aHAlign='right',$aVAlign='top') { + $this->Pos($aX,$aY,$aHAlign,$aVAlign); + } + + function SetAbsPos($aX,$aY,$aHAlign='right',$aVAlign='top') { + $this->xabspos=$aX; + $this->yabspos=$aY; + $this->halign=$aHAlign; + $this->valign=$aVAlign; + } + + + function Pos($aX,$aY,$aHAlign='right',$aVAlign='top') { + if( !($aX<1 && $aY<1) ) + JpGraphError::RaiseL(25120);//(" Position for legend must be given as percentage in range 0-1"); + $this->xpos=$aX; + $this->ypos=$aY; + $this->halign=$aHAlign; + $this->valign=$aVAlign; + } + + function SetFillColor($aColor) { + $this->fill_color=$aColor; + } + + function Clear() { + $this->txtcol = array(); + } + + function Add($aTxt,$aColor,$aPlotmark='',$aLinestyle=0,$csimtarget='',$csimalt='',$csimwintarget='') { + $this->txtcol[]=array($aTxt,$aColor,$aPlotmark,$aLinestyle,$csimtarget,$csimalt,$csimwintarget); + } + + function GetCSIMAreas() { + return $this->csimareas; + } + + function Stroke(&$aImg) { + // Constant + $fillBoxFrameWeight=1; + + if( $this->hide ) return; + + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + + if( $this->reverse ) { + $this->txtcol = array_reverse($this->txtcol); + } + + $n=count($this->txtcol); + if( $n == 0 ) return; + + // Find out the max width and height of each column to be able + // to size the legend box. + $numcolumns = ($n > $this->layout_n ? $this->layout_n : $n); + for( $i=0; $i < $numcolumns; ++$i ) { + $colwidth[$i] = $aImg->GetTextWidth($this->txtcol[$i][0]) + + 2*$this->xmargin + 2*$this->mark_abs_hsize; + $colheight[$i] = 0; + + } + + // Find our maximum height in each row + $rows = 0 ; $rowheight[0] = 0; + for( $i=0; $i < $n; ++$i ) { + $h = max($this->mark_abs_vsize,$aImg->GetTextHeight($this->txtcol[$i][0]))+$this->ymargin; + // Makes sure we always have a minimum of 1/4 (1/2 on each side) of the mark as space + // between two vertical legend entries + $h = round(max($h,$this->mark_abs_vsize+$this->mark_abs_vsize/2)); + //echo "Textheight:".$aImg->GetTextHeight($this->txtcol[$i][0]).', '; + //echo "h=$h ({$this->mark_abs_vsize},{$this->ymargin})
"; + if( $i % $numcolumns == 0 ) { + $rows++; + $rowheight[$rows-1] = 0; + } + $rowheight[$rows-1] = max($rowheight[$rows-1],$h); + } + + $abs_height = 0; + for( $i=0; $i < $rows; ++$i ) { + $abs_height += $rowheight[$i] ; + } + + // Make sure that the height is at least as high as mark size + ymargin + // We add 1.5 y-margin to add some space at the top+bottom part of the + // legend. + $abs_height = max($abs_height,$this->mark_abs_vsize); + $abs_height += 3*$this->ymargin; + + // Find out the maximum width in each column + for( $i=$numcolumns; $i < $n; ++$i ) { + $colwidth[$i % $numcolumns] = max( + $aImg->GetTextWidth($this->txtcol[$i][0])+2*$this->xmargin+2*$this->mark_abs_hsize, + $colwidth[$i % $numcolumns]); + } + + + // Get the total width + $mtw = 0; + for( $i=0; $i < $numcolumns; ++$i ) { + $mtw += $colwidth[$i] ; + } + + // Find out maximum width we need for legend box + $abs_width = $mtw+$this->xlmargin; + + if( $this->xabspos === -1 && $this->yabspos === -1 ) { + $this->xabspos = $this->xpos*$aImg->width ; + $this->yabspos = $this->ypos*$aImg->height ; + } + + // Positioning of the legend box + if( $this->halign == 'left' ) { + $xp = $this->xabspos; + } + elseif( $this->halign == 'center' ) { + $xp = $this->xabspos - $abs_width/2; + } + else { + $xp = $aImg->width - $this->xabspos - $abs_width; + } + + $yp=$this->yabspos; + if( $this->valign == 'center' ) { + $yp-=$abs_height/2; + } + elseif( $this->valign == 'bottom' ) { + $yp-=$abs_height; + } + + // Stroke legend box + $aImg->SetColor($this->color); + $aImg->SetLineWeight($this->frameweight); + $aImg->SetLineStyle('solid'); + + if( $this->shadow ) { + $aImg->ShadowRectangle($xp,$yp,$xp+$abs_width+$this->shadow_width, + $yp+$abs_height+$this->shadow_width, + $this->fill_color,$this->shadow_width,$this->shadow_color); + } + else { + $aImg->SetColor($this->fill_color); + $aImg->FilledRectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height); + $aImg->SetColor($this->color); + $aImg->Rectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height); + } + + // x1,y1 is the position for the legend mark + $x1=$xp+round($this->mark_abs_hsize/2)+$this->xlmargin; + $y1=$yp + $this->ymargin; + + // Remember 1/2 of the font height since we need that later + // as a minimum value for correctly position the markers + $f2 = round($aImg->GetTextHeight('X')/2); + + $grad = new Gradient($aImg); + $patternFactory = null; + + // Now stroke each legend in turn + // Each plot has added the following information to the legend + // p[0] = Legend text + // p[1] = Color, + // p[2] = For markers a reference to the PlotMark object + // p[3] = For lines the line style, for gradient the negative gradient style + // p[4] = CSIM target + // p[5] = CSIM Alt text + $i = 1 ; $row = 0; + foreach($this->txtcol as $p) { + + // STROKE DEBUG BOX + if( _JPG_DEBUG ) { + $aImg->SetLineWeight(1); + $aImg->SetColor('red'); + $aImg->SetLineStyle('solid'); + $aImg->Rectangle($xp,$y1,$xp+$abs_width,$y1+$rowheight[$row]); + } + + $aImg->SetLineWeight($this->weight); + $x1 = round($x1); $y1=round($y1); + if ( !empty($p[2]) && $p[2]->GetType() > -1 ) { + // Make a plot mark legend + $aImg->SetColor($p[1]); + if( is_string($p[3]) || $p[3]>0 ) { + $aImg->SetLineStyle($p[3]); + $aImg->StyleLine($x1-$this->mark_abs_hsize,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2); + } + // Stroke a mark with the standard size + // (As long as it is not an image mark ) + if( $p[2]->GetType() != MARK_IMG ) { + + // Clear any user callbacks since we ont want them called for + // the legend marks + $p[2]->iFormatCallback = ''; + $p[2]->iFormatCallback2 = ''; + + // Since size for circles is specified as the radius + // this means that we must half the size to make the total + // width behave as the other marks + if( $p[2]->GetType() == MARK_FILLEDCIRCLE || $p[2]->GetType() == MARK_CIRCLE ) { + $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize)/2); + $p[2]->Stroke($aImg,$x1,$y1+$f2); + } + else { + $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize)); + $p[2]->Stroke($aImg,$x1,$y1+$f2); + } + } + } + elseif ( !empty($p[2]) && (is_string($p[3]) || $p[3]>0 ) ) { + // Draw a styled line + $aImg->SetColor($p[1]); + $aImg->SetLineStyle($p[3]); + $aImg->StyleLine($x1-1,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2); + $aImg->StyleLine($x1-1,$y1+$f2+1,$x1+$this->mark_abs_hsize,$y1+$f2+1); + } + else { + // Draw a colored box + $color = $p[1] ; + + // We make boxes slightly larger to better show + $boxsize = max($this->mark_abs_vsize,$this->mark_abs_hsize) + 2 ; + + // $y1 is the top border of the "box" we have to draw the marker + // and legend text in. We position the marker in the vertical center + // of this box + $ym = $y1 + round($rowheight[$row]/2)-round($this->mark_abs_vsize/2); + + // We either need to plot a gradient or a + // pattern. To differentiate we use a kludge. + // Patterns have a p[3] value of < -100 + if( $p[3] < -100 ) { + // p[1][0] == iPattern, p[1][1] == iPatternColor, p[1][2] == iPatternDensity + if( $patternFactory == null ) { + $patternFactory = new RectPatternFactory(); + } + $prect = $patternFactory->Create($p[1][0],$p[1][1],1); + $prect->SetBackground($p[1][3]); + $prect->SetDensity($p[1][2]+1); + $prect->SetPos(new Rectangle($x1,$ym,$boxsize,$boxsize)); + $prect->Stroke($aImg); + $prect=null; + } + else { + if( is_array($color) && count($color)==2 ) { + // The client want a gradient color + $grad->FilledRectangle($x1,$ym, + $x1+$boxsize,$ym+$boxsize, + $color[0],$color[1],-$p[3]); + } + else { + $aImg->SetColor($p[1]); + $aImg->FilledRectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize); + } + $aImg->SetColor($this->color); + $aImg->SetLineWeight($fillBoxFrameWeight); + $aImg->Rectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize); + } + } + $aImg->SetColor($this->font_color); + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $aImg->SetTextAlign('left','center'); + $aImg->StrokeText(round($x1+$this->mark_abs_hsize+$this->xmargin), + $y1+round($rowheight[$row]/2),$p[0]); + + // Add CSIM for Legend if defined + if( !empty($p[4]) ) { + + $xe = $x1 + $this->xmargin+$this->mark_abs_hsize+$aImg->GetTextWidth($p[0]); + $ye = $y1 + max($this->mark_abs_vsize,$aImg->GetTextHeight($p[0])); + $coords = "$x1,$y1,$xe,$y1,$xe,$ye,$x1,$ye"; + if( ! empty($p[4]) ) { + $this->csimareas .= "csimareas .= " target=\"".$p[6]."\""; + } + + if( !empty($p[5]) ) { + $tmp=sprintf($p[5],$p[0]); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } + } + if( $i >= $this->layout_n ) { + $x1 = $xp+round($this->mark_abs_hsize/2)+$this->xlmargin; + $y1 += $rowheight[$row++]; + $i = 1; + } + else { + $x1 += $colwidth[($i-1) % $numcolumns] ; + ++$i; + } + } + } +} // Class + +?> diff --git a/src/classes/jpgraph/jpgraph_line.php b/src/classes/jpgraph/jpgraph_line.php index 26eb622..b7b7939 100644 --- a/src/classes/jpgraph/jpgraph_line.php +++ b/src/classes/jpgraph/jpgraph_line.php @@ -1,13 +1,13 @@ Plot($datay,$datax); - $this->mark = new PlotMark() ; + parent::__construct($datay,$datax); + $this->mark = new PlotMark() ; + $this->color = ColorFactory::getColor(); + $this->fill_color = $this->color; } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS - // Set style, filled or open - function SetFilled($aFlag=true) { - JpGraphError::RaiseL(10001);//('LinePlot::SetFilled() is deprecated. Use SetFillColor()'); + function SetFilled($aFlg=true) { + $this->filled = $aFlg; } - + function SetBarCenter($aFlag=true) { - $this->barcenter=$aFlag; + $this->barcenter=$aFlag; } function SetStyle($aStyle) { - $this->line_style=$aStyle; + $this->line_style=$aStyle; } - + function SetStepStyle($aFlag=true) { - $this->step_style = $aFlag; + $this->step_style = $aFlag; } - + function SetColor($aColor) { - parent::SetColor($aColor); + parent::SetColor($aColor); } - + function SetFillFromYMin($f=true) { - $this->fillFromMin = $f ; + $this->fillFromMin = $f ; } - + + function SetFillFromYMax($f=true) { + $this->fillFromMax = $f ; + } + function SetFillColor($aColor,$aFilled=true) { - $this->fill_color=$aColor; - $this->filled=$aFilled; + $this->color = $aColor; + $this->fill_color=$aColor; + $this->filled=$aFilled; } function SetFillGradient($aFromColor,$aToColor,$aNumColors=100,$aFilled=true) { - $this->fillgrad_fromcolor = $aFromColor; - $this->fillgrad_tocolor = $aToColor; - $this->fillgrad_numcolors = $aNumColors; - $this->filled = $aFilled; - $this->fillgrad = true; + $this->fillgrad_fromcolor = $aFromColor; + $this->fillgrad_tocolor = $aToColor; + $this->fillgrad_numcolors = $aNumColors; + $this->filled = $aFilled; + $this->fillgrad = true; } - + function Legend($graph) { - if( $this->legend!="" ) { - if( $this->filled && !$this->fillgrad ) { - $graph->legend->Add($this->legend, - $this->fill_color,$this->mark,0, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - elseif( $this->fillgrad ) { - $color=array($this->fillgrad_fromcolor,$this->fillgrad_tocolor); - // In order to differentiate between gradients and cooors specified as an RGB triple - $graph->legend->Add($this->legend,$color,"",-2 /* -GRAD_HOR */, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } else { - $graph->legend->Add($this->legend, - $this->color,$this->mark,$this->line_style, - $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); - } - } + if( $this->legend!="" ) { + if( $this->filled && !$this->fillgrad ) { + $graph->legend->Add($this->legend, + $this->fill_color,$this->mark,0, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + elseif( $this->fillgrad ) { + $color=array($this->fillgrad_fromcolor,$this->fillgrad_tocolor); + // In order to differentiate between gradients and cooors specified as an RGB triple + $graph->legend->Add($this->legend,$color,"",-2 /* -GRAD_HOR */, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } else { + $graph->legend->Add($this->legend, + $this->color,$this->mark,$this->line_style, + $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); + } + } } function AddArea($aMin=0,$aMax=0,$aFilled=LP_AREA_NOT_FILLED,$aColor="gray9",$aBorder=LP_AREA_BORDER) { - if($aMin > $aMax) { - // swap - $tmp = $aMin; - $aMin = $aMax; - $aMax = $tmp; - } - $this->filledAreas[] = array($aMin,$aMax,$aColor,$aFilled,$aBorder); + if($aMin > $aMax) { + // swap + $tmp = $aMin; + $aMin = $aMax; + $aMax = $tmp; + } + $this->filledAreas[] = array($aMin,$aMax,$aColor,$aFilled,$aBorder); } - + // Gets called before any axis are stroked function PreStrokeAdjust($graph) { - // If another plot type have already adjusted the - // offset we don't touch it. - // (We check for empty in case the scale is a log scale - // and hence doesn't contain any xlabel_offset) - if( empty($graph->xaxis->scale->ticks->xlabel_offset) || - $graph->xaxis->scale->ticks->xlabel_offset == 0 ) { - if( $this->center ) { - ++$this->numpoints; - $a=0.5; $b=0.5; - } else { - $a=0; $b=0; - } - $graph->xaxis->scale->ticks->SetXLabelOffset($a); - $graph->SetTextScaleOff($b); - //$graph->xaxis->scale->ticks->SupressMinorTickMarks(); - } + // If another plot type have already adjusted the + // offset we don't touch it. + // (We check for empty in case the scale is a log scale + // and hence doesn't contain any xlabel_offset) + if( empty($graph->xaxis->scale->ticks->xlabel_offset) || $graph->xaxis->scale->ticks->xlabel_offset == 0 ) { + if( $this->center ) { + ++$this->numpoints; + $a=0.5; $b=0.5; + } else { + $a=0; $b=0; + } + $graph->xaxis->scale->ticks->SetXLabelOffset($a); + $graph->SetTextScaleOff($b); + //$graph->xaxis->scale->ticks->SupressMinorTickMarks(); + } } - + function SetFastStroke($aFlg=true) { - $this->iFastStroke = $aFlg; + $this->iFastStroke = $aFlg; } function FastStroke($img,$xscale,$yscale,$aStartPoint=0,$exist_x=true) { - // An optimized stroke for many data points with no extra - // features but 60% faster. You can't have values or line styles, or null - // values in plots. - $numpoints=count($this->coords[0]); - if( $this->barcenter ) - $textadj = 0.5-$xscale->text_scale_off; - else - $textadj = 0; + // An optimized stroke for many data points with no extra + // features but 60% faster. You can't have values or line styles, or null + // values in plots. + $numpoints=count($this->coords[0]); + if( $this->barcenter ) { + $textadj = 0.5-$xscale->text_scale_off; + } + else { + $textadj = 0; + } - $img->SetColor($this->color); - $img->SetLineWeight($this->weight); - $pnts=$aStartPoint; - while( $pnts < $numpoints ) { - if( $exist_x ) $x=$this->coords[1][$pnts]; - else $x=$pnts+$textadj; - $xt = $xscale->Translate($x); - $y=$this->coords[0][$pnts]; - $yt = $yscale->Translate($y); - if( is_numeric($y) ) { - $cord[] = $xt; - $cord[] = $yt; - } - elseif( $y == '-' && $pnts > 0 ) { - // Just ignore - } - else { - JpGraphError::RaiseL(10002);//('Plot too complicated for fast line Stroke. Use standard Stroke()'); - } - ++$pnts; - } // WHILE + $img->SetColor($this->color); + $img->SetLineWeight($this->weight); + $pnts=$aStartPoint; + while( $pnts < $numpoints ) { + if( $exist_x ) { + $x=$this->coords[1][$pnts]; + } + else { + $x=$pnts+$textadj; + } + $xt = $xscale->Translate($x); + $y=$this->coords[0][$pnts]; + $yt = $yscale->Translate($y); + if( is_numeric($y) ) { + $cord[] = $xt; + $cord[] = $yt; + } + elseif( $y == '-' && $pnts > 0 ) { + // Just ignore + } + else { + JpGraphError::RaiseL(10002);//('Plot too complicated for fast line Stroke. Use standard Stroke()'); + } + ++$pnts; + } // WHILE - $img->Polygon($cord,false,true); + $img->Polygon($cord,false,true); } - + function Stroke($img,$xscale,$yscale) { - $idx=0; - $numpoints=count($this->coords[0]); - if( isset($this->coords[1]) ) { - if( count($this->coords[1])!=$numpoints ) - JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints); -//("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints"); - else - $exist_x = true; - } - else - $exist_x = false; + $idx=0; + $numpoints=count($this->coords[0]); + if( isset($this->coords[1]) ) { + if( count($this->coords[1])!=$numpoints ) { + JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints); + //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints"); + } + else { + $exist_x = true; + } + } + else { + $exist_x = false; + } - if( $this->barcenter ) - $textadj = 0.5-$xscale->text_scale_off; - else - $textadj = 0; + if( $this->barcenter ) { + $textadj = 0.5-$xscale->text_scale_off; + } + else { + $textadj = 0; + } - // Find the first numeric data point - $startpoint=0; - while( $startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint]) ) - ++$startpoint; + // Find the first numeric data point + $startpoint=0; + while( $startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint]) ) { + ++$startpoint; + } - // Bail out if no data points - if( $startpoint == $numpoints ) - return; + // Bail out if no data points + if( $startpoint == $numpoints ) return; - if( $this->iFastStroke ) { - $this->FastStroke($img,$xscale,$yscale,$startpoint,$exist_x); - return; - } + if( $this->iFastStroke ) { + $this->FastStroke($img,$xscale,$yscale,$startpoint,$exist_x); + return; + } - if( $exist_x ) - $xs=$this->coords[1][$startpoint]; - else - $xs= $textadj+$startpoint; + if( $exist_x ) { + $xs=$this->coords[1][$startpoint]; + } + else { + $xs= $textadj+$startpoint; + } - $img->SetStartPoint($xscale->Translate($xs), - $yscale->Translate($this->coords[0][$startpoint])); + $img->SetStartPoint($xscale->Translate($xs), + $yscale->Translate($this->coords[0][$startpoint])); - - if( $this->filled ) { - $min = $yscale->GetMinVal(); - if( $min > 0 || $this->fillFromMin ) - $fillmin = $yscale->scale_abs[0];//Translate($min); - else - $fillmin = $yscale->Translate(0); + if( $this->filled ) { + if( $this->fillFromMax ) { + //$max = $yscale->GetMaxVal(); + $cord[$idx++] = $xscale->Translate($xs); + $cord[$idx++] = $yscale->scale_abs[1]; + } + else { + $min = $yscale->GetMinVal(); + if( $min > 0 || $this->fillFromMin ) { + $fillmin = $yscale->scale_abs[0];//Translate($min); + } + else { + $fillmin = $yscale->Translate(0); + } - $cord[$idx++] = $xscale->Translate($xs); - $cord[$idx++] = $fillmin; - } - $xt = $xscale->Translate($xs); - $yt = $yscale->Translate($this->coords[0][$startpoint]); - $cord[$idx++] = $xt; - $cord[$idx++] = $yt; - $yt_old = $yt; - $xt_old = $xt; - $y_old = $this->coords[0][$startpoint]; + $cord[$idx++] = $xscale->Translate($xs); + $cord[$idx++] = $fillmin; + } + } + $xt = $xscale->Translate($xs); + $yt = $yscale->Translate($this->coords[0][$startpoint]); + $cord[$idx++] = $xt; + $cord[$idx++] = $yt; + $yt_old = $yt; + $xt_old = $xt; + $y_old = $this->coords[0][$startpoint]; - $this->value->Stroke($img,$this->coords[0][$startpoint],$xt,$yt); + $this->value->Stroke($img,$this->coords[0][$startpoint],$xt,$yt); - $img->SetColor($this->color); - $img->SetLineWeight($this->weight); - $img->SetLineStyle($this->line_style); - $pnts=$startpoint+1; - $firstnonumeric = false; + $img->SetColor($this->color); + $img->SetLineWeight($this->weight); + $img->SetLineStyle($this->line_style); + $pnts=$startpoint+1; + $firstnonumeric = false; - while( $pnts < $numpoints ) { - - if( $exist_x ) $x=$this->coords[1][$pnts]; - else $x=$pnts+$textadj; - $xt = $xscale->Translate($x); - $yt = $yscale->Translate($this->coords[0][$pnts]); - - $y=$this->coords[0][$pnts]; - if( $this->step_style ) { - // To handle null values within step style we need to record the - // first non numeric value so we know from where to start if the - // non value is '-'. - if( is_numeric($y) ) { - $firstnonumeric = false; - if( is_numeric($y_old) ) { - $img->StyleLine($xt_old,$yt_old,$xt,$yt_old); - $img->StyleLine($xt,$yt_old,$xt,$yt); - } - elseif( $y_old == '-' ) { - $img->StyleLine($xt_first,$yt_first,$xt,$yt_first); - $img->StyleLine($xt,$yt_first,$xt,$yt); - } - else { - $yt_old = $yt; - $xt_old = $xt; - } - $cord[$idx++] = $xt; - $cord[$idx++] = $yt_old; - $cord[$idx++] = $xt; - $cord[$idx++] = $yt; - } - elseif( $firstnonumeric==false ) { - $firstnonumeric = true; - $yt_first = $yt_old; - $xt_first = $xt_old; - } - } - else { - $tmp1=$y; - $prev=$this->coords[0][$pnts-1]; - if( $tmp1==='' || $tmp1===NULL || $tmp1==='X' ) $tmp1 = 'x'; - if( $prev==='' || $prev===null || $prev==='X' ) $prev = 'x'; + while( $pnts < $numpoints ) { - if( is_numeric($y) || (is_string($y) && $y != '-') ) { - if( is_numeric($y) && (is_numeric($prev) || $prev === '-' ) ) { - $img->StyleLineTo($xt,$yt); - } - else { - $img->SetStartPoint($xt,$yt); - } - } - if( $this->filled && $tmp1 !== '-' ) { - if( $tmp1 === 'x' ) { - $cord[$idx++] = $cord[$idx-3]; - $cord[$idx++] = $fillmin; - } - elseif( $prev === 'x' ) { - $cord[$idx++] = $xt; - $cord[$idx++] = $fillmin; - $cord[$idx++] = $xt; - $cord[$idx++] = $yt; - } - else { - $cord[$idx++] = $xt; - $cord[$idx++] = $yt; - } - } - else { - if( is_numeric($tmp1) && (is_numeric($prev) || $prev === '-' ) ) { - $cord[$idx++] = $xt; - $cord[$idx++] = $yt; - } - } - } - $yt_old = $yt; - $xt_old = $xt; - $y_old = $y; + if( $exist_x ) { + $x=$this->coords[1][$pnts]; + } + else { + $x=$pnts+$textadj; + } + $xt = $xscale->Translate($x); + $yt = $yscale->Translate($this->coords[0][$pnts]); - $this->StrokeDataValue($img,$this->coords[0][$pnts],$xt,$yt); + $y=$this->coords[0][$pnts]; + if( $this->step_style ) { + // To handle null values within step style we need to record the + // first non numeric value so we know from where to start if the + // non value is '-'. + if( is_numeric($y) ) { + $firstnonumeric = false; + if( is_numeric($y_old) ) { + $img->StyleLine($xt_old,$yt_old,$xt,$yt_old); + $img->StyleLine($xt,$yt_old,$xt,$yt); + } + elseif( $y_old == '-' ) { + $img->StyleLine($xt_first,$yt_first,$xt,$yt_first); + $img->StyleLine($xt,$yt_first,$xt,$yt); + } + else { + $yt_old = $yt; + $xt_old = $xt; + } + $cord[$idx++] = $xt; + $cord[$idx++] = $yt_old; + $cord[$idx++] = $xt; + $cord[$idx++] = $yt; + } + elseif( $firstnonumeric==false ) { + $firstnonumeric = true; + $yt_first = $yt_old; + $xt_first = $xt_old; + } + } + else { + $tmp1=$y; + $prev=$this->coords[0][$pnts-1]; + if( $tmp1==='' || $tmp1===NULL || $tmp1==='X' ) $tmp1 = 'x'; + if( $prev==='' || $prev===null || $prev==='X' ) $prev = 'x'; - ++$pnts; - } + if( is_numeric($y) || (is_string($y) && $y != '-') ) { + if( is_numeric($y) && (is_numeric($prev) || $prev === '-' ) ) { + $img->StyleLineTo($xt,$yt); + } + else { + $img->SetStartPoint($xt,$yt); + } + } + if( $this->filled && $tmp1 !== '-' ) { + if( $tmp1 === 'x' ) { + $cord[$idx++] = $cord[$idx-3]; + $cord[$idx++] = $fillmin; + } + elseif( $prev === 'x' ) { + $cord[$idx++] = $xt; + $cord[$idx++] = $fillmin; + $cord[$idx++] = $xt; + $cord[$idx++] = $yt; + } + else { + $cord[$idx++] = $xt; + $cord[$idx++] = $yt; + } + } + else { + if( is_numeric($tmp1) && (is_numeric($prev) || $prev === '-' ) ) { + $cord[$idx++] = $xt; + $cord[$idx++] = $yt; + } + } + } + $yt_old = $yt; + $xt_old = $xt; + $y_old = $y; - if( $this->filled ) { - $cord[$idx++] = $xt; - if( $min > 0 || $this->fillFromMin ) - $cord[$idx++] = $yscale->Translate($min); - else - $cord[$idx++] = $yscale->Translate(0); - if( $this->fillgrad ) { - $img->SetLineWeight(1); - $grad = new Gradient($img); - $grad->SetNumColors($this->fillgrad_numcolors); - $grad->FilledFlatPolygon($cord,$this->fillgrad_fromcolor,$this->fillgrad_tocolor); - $img->SetLineWeight($this->weight); - } - else { - $img->SetColor($this->fill_color); - $img->FilledPolygon($cord); - } - if( $this->line_weight > 0 ) { - $img->SetColor($this->color); - $img->Polygon($cord); - } - } + $this->StrokeDataValue($img,$this->coords[0][$pnts],$xt,$yt); - if(!empty($this->filledAreas)) { + ++$pnts; + } - $minY = $yscale->Translate($yscale->GetMinVal()); - $factor = ($this->step_style ? 4 : 2); + if( $this->filled ) { + $cord[$idx++] = $xt; + if( $this->fillFromMax ) { + $cord[$idx++] = $yscale->scale_abs[1]; + } + else { + if( $min > 0 || $this->fillFromMin ) { + $cord[$idx++] = $yscale->Translate($min); + } + else { + $cord[$idx++] = $yscale->Translate(0); + } + } + if( $this->fillgrad ) { + $img->SetLineWeight(1); + $grad = new Gradient($img); + $grad->SetNumColors($this->fillgrad_numcolors); + $grad->FilledFlatPolygon($cord,$this->fillgrad_fromcolor,$this->fillgrad_tocolor); + $img->SetLineWeight($this->weight); + } + else { + $img->SetColor($this->fill_color); + $img->FilledPolygon($cord); + } + if( $this->line_weight > 0 ) { + $img->SetColor($this->color); + $img->Polygon($cord); + } + } - for($i = 0; $i < sizeof($this->filledAreas); ++$i) { - // go through all filled area elements ordered by insertion - // fill polygon array - $areaCoords[] = $cord[$this->filledAreas[$i][0] * $factor]; - $areaCoords[] = $minY; + if(!empty($this->filledAreas)) { - $areaCoords = - array_merge($areaCoords, - array_slice($cord, - $this->filledAreas[$i][0] * $factor, - ($this->filledAreas[$i][1] - $this->filledAreas[$i][0] + ($this->step_style ? 0 : 1)) * $factor)); - $areaCoords[] = $areaCoords[sizeof($areaCoords)-2]; // last x - $areaCoords[] = $minY; // last y - - if($this->filledAreas[$i][3]) { - $img->SetColor($this->filledAreas[$i][2]); - $img->FilledPolygon($areaCoords); - $img->SetColor($this->color); - } - // Check if we should draw the frame. - // If not we still re-draw the line since it might have been - // partially overwritten by the filled area and it doesn't look - // very good. - // TODO: The behaviour is undefined if the line does not have - // any line at the position of the area. - if( $this->filledAreas[$i][4] ) - $img->Polygon($areaCoords); - else - $img->Polygon($cord); + $minY = $yscale->Translate($yscale->GetMinVal()); + $factor = ($this->step_style ? 4 : 2); - $areaCoords = array(); - } - } + for($i = 0; $i < sizeof($this->filledAreas); ++$i) { + // go through all filled area elements ordered by insertion + // fill polygon array + $areaCoords[] = $cord[$this->filledAreas[$i][0] * $factor]; + $areaCoords[] = $minY; - if( $this->mark->type == -1 || $this->mark->show == false ) - return; + $areaCoords = + array_merge($areaCoords, + array_slice($cord, + $this->filledAreas[$i][0] * $factor, + ($this->filledAreas[$i][1] - $this->filledAreas[$i][0] + ($this->step_style ? 0 : 1)) * $factor)); + $areaCoords[] = $areaCoords[sizeof($areaCoords)-2]; // last x + $areaCoords[] = $minY; // last y - for( $pnts=0; $pnts<$numpoints; ++$pnts) { + if($this->filledAreas[$i][3]) { + $img->SetColor($this->filledAreas[$i][2]); + $img->FilledPolygon($areaCoords); + $img->SetColor($this->color); + } + // Check if we should draw the frame. + // If not we still re-draw the line since it might have been + // partially overwritten by the filled area and it doesn't look + // very good. + if( $this->filledAreas[$i][4] ) { + $img->Polygon($areaCoords); + } + else { + $img->Polygon($cord); + } - if( $exist_x ) $x=$this->coords[1][$pnts]; - else $x=$pnts+$textadj; - $xt = $xscale->Translate($x); - $yt = $yscale->Translate($this->coords[0][$pnts]); + $areaCoords = array(); + } + } - if( is_numeric($this->coords[0][$pnts]) ) { - if( !empty($this->csimtargets[$pnts]) ) { - if( !empty($this->csimwintargets[$pnts]) ) { - $this->mark->SetCSIMTarget($this->csimtargets[$pnts],$this->csimwintargets[$pnts]); - } - else { - $this->mark->SetCSIMTarget($this->csimtargets[$pnts]); - } - $this->mark->SetCSIMAlt($this->csimalts[$pnts]); - } - if( $exist_x ) - $x=$this->coords[1][$pnts]; - else - $x=$pnts; - $this->mark->SetCSIMAltVal($this->coords[0][$pnts],$x); - $this->mark->Stroke($img,$xt,$yt); - $this->csimareas .= $this->mark->GetCSIMAreas(); - } - } + if( $this->mark->type == -1 || $this->mark->show == false ) + return; + + for( $pnts=0; $pnts<$numpoints; ++$pnts) { + + if( $exist_x ) { + $x=$this->coords[1][$pnts]; + } + else { + $x=$pnts+$textadj; + } + $xt = $xscale->Translate($x); + $yt = $yscale->Translate($this->coords[0][$pnts]); + + if( is_numeric($this->coords[0][$pnts]) ) { + if( !empty($this->csimtargets[$pnts]) ) { + if( !empty($this->csimwintargets[$pnts]) ) { + $this->mark->SetCSIMTarget($this->csimtargets[$pnts],$this->csimwintargets[$pnts]); + } + else { + $this->mark->SetCSIMTarget($this->csimtargets[$pnts]); + } + $this->mark->SetCSIMAlt($this->csimalts[$pnts]); + } + if( $exist_x ) { + $x=$this->coords[1][$pnts]; + } + else { + $x=$pnts; + } + $this->mark->SetCSIMAltVal($this->coords[0][$pnts],$x); + $this->mark->Stroke($img,$xt,$yt); + $this->csimareas .= $this->mark->GetCSIMAreas(); + } + } } } // Class //=================================================== // CLASS AccLinePlot -// Description: +// Description: //=================================================== class AccLinePlot extends Plot { protected $plots=null,$nbrplots=0; private $iStartEndZero=true; -//--------------- -// CONSTRUCTOR - function AccLinePlot($plots) { + //--------------- + // CONSTRUCTOR + function __construct($plots) { $this->plots = $plots; - $this->nbrplots = count($plots); - $this->numpoints = $plots[0]->numpoints; + $this->nbrplots = count($plots); + $this->numpoints = $plots[0]->numpoints; - // Verify that all plots have the same number of data points - for( $i=1; $i < $this->nbrplots; ++$i ) { - if( $plots[$i]->numpoints != $this->numpoints ) { - JpGraphError::RaiseL(10003);//('Each plot in an accumulated lineplot must have the same number of data points',0) - } - } + // Verify that all plots have the same number of data points + for( $i=1; $i < $this->nbrplots; ++$i ) { + if( $plots[$i]->numpoints != $this->numpoints ) { + JpGraphError::RaiseL(10003);//('Each plot in an accumulated lineplot must have the same number of data points',0) + } + } - for($i=0; $i < $this->nbrplots; ++$i ) { - $this->LineInterpolate($this->plots[$i]->coords[0]); - } + for($i=0; $i < $this->nbrplots; ++$i ) { + $this->LineInterpolate($this->plots[$i]->coords[0]); + } } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function Legend($graph) { - foreach( $this->plots as $p ) - $p->DoLegend($graph); + foreach( $this->plots as $p ) { + $p->DoLegend($graph); + } } - + function Max() { - list($xmax) = $this->plots[0]->Max(); - $nmax=0; - $n = count($this->plots); - for($i=0; $i < $n; ++$i) { - $nc = count($this->plots[$i]->coords[0]); - $nmax = max($nmax,$nc); - list($x) = $this->plots[$i]->Max(); - $xmax = Max($xmax,$x); - } - for( $i = 0; $i < $nmax; $i++ ) { - // Get y-value for line $i by adding the - // individual bars from all the plots added. - // It would be wrong to just add the - // individual plots max y-value since that - // would in most cases give to large y-value. - $y=$this->plots[0]->coords[0][$i]; - for( $j = 1; $j < $this->nbrplots; $j++ ) { - $y += $this->plots[ $j ]->coords[0][$i]; - } - $ymax[$i] = $y; - } - $ymax = max($ymax); - return array($xmax,$ymax); - } + list($xmax) = $this->plots[0]->Max(); + $nmax=0; + $n = count($this->plots); + for($i=0; $i < $n; ++$i) { + $nc = count($this->plots[$i]->coords[0]); + $nmax = max($nmax,$nc); + list($x) = $this->plots[$i]->Max(); + $xmax = Max($xmax,$x); + } + for( $i = 0; $i < $nmax; $i++ ) { + // Get y-value for line $i by adding the + // individual bars from all the plots added. + // It would be wrong to just add the + // individual plots max y-value since that + // would in most cases give to large y-value. + $y=$this->plots[0]->coords[0][$i]; + for( $j = 1; $j < $this->nbrplots; $j++ ) { + $y += $this->plots[ $j ]->coords[0][$i]; + } + $ymax[$i] = $y; + } + $ymax = max($ymax); + return array($xmax,$ymax); + } function Min() { - $nmax=0; - list($xmin,$ysetmin) = $this->plots[0]->Min(); - $n = count($this->plots); - for($i=0; $i < $n; ++$i) { - $nc = count($this->plots[$i]->coords[0]); - $nmax = max($nmax,$nc); - list($x,$y) = $this->plots[$i]->Min(); - $xmin = Min($xmin,$x); - $ysetmin = Min($y,$ysetmin); - } - for( $i = 0; $i < $nmax; $i++ ) { - // Get y-value for line $i by adding the - // individual bars from all the plots added. - // It would be wrong to just add the - // individual plots min y-value since that - // would in most cases give to small y-value. - $y=$this->plots[0]->coords[0][$i]; - for( $j = 1; $j < $this->nbrplots; $j++ ) { - $y += $this->plots[ $j ]->coords[0][$i]; - } - $ymin[$i] = $y; - } - $ymin = Min($ysetmin,Min($ymin)); - return array($xmin,$ymin); + $nmax=0; + list($xmin,$ysetmin) = $this->plots[0]->Min(); + $n = count($this->plots); + for($i=0; $i < $n; ++$i) { + $nc = count($this->plots[$i]->coords[0]); + $nmax = max($nmax,$nc); + list($x,$y) = $this->plots[$i]->Min(); + $xmin = Min($xmin,$x); + $ysetmin = Min($y,$ysetmin); + } + for( $i = 0; $i < $nmax; $i++ ) { + // Get y-value for line $i by adding the + // individual bars from all the plots added. + // It would be wrong to just add the + // individual plots min y-value since that + // would in most cases give to small y-value. + $y=$this->plots[0]->coords[0][$i]; + for( $j = 1; $j < $this->nbrplots; $j++ ) { + $y += $this->plots[ $j ]->coords[0][$i]; + } + $ymin[$i] = $y; + } + $ymin = Min($ysetmin,Min($ymin)); + return array($xmin,$ymin); } // Gets called before any axis are stroked function PreStrokeAdjust($graph) { - // If another plot type have already adjusted the - // offset we don't touch it. - // (We check for empty in case the scale is a log scale - // and hence doesn't contain any xlabel_offset) - - if( empty($graph->xaxis->scale->ticks->xlabel_offset) || - $graph->xaxis->scale->ticks->xlabel_offset == 0 ) { - if( $this->center ) { - ++$this->numpoints; - $a=0.5; $b=0.5; - } else { - $a=0; $b=0; - } - $graph->xaxis->scale->ticks->SetXLabelOffset($a); - $graph->SetTextScaleOff($b); - $graph->xaxis->scale->ticks->SupressMinorTickMarks(); - } - + // If another plot type have already adjusted the + // offset we don't touch it. + // (We check for empty in case the scale is a log scale + // and hence doesn't contain any xlabel_offset) + + if( empty($graph->xaxis->scale->ticks->xlabel_offset) || + $graph->xaxis->scale->ticks->xlabel_offset == 0 ) { + if( $this->center ) { + ++$this->numpoints; + $a=0.5; $b=0.5; + } else { + $a=0; $b=0; + } + $graph->xaxis->scale->ticks->SetXLabelOffset($a); + $graph->SetTextScaleOff($b); + $graph->xaxis->scale->ticks->SupressMinorTickMarks(); + } + } function SetInterpolateMode($aIntMode) { - $this->iStartEndZero=$aIntMode; + $this->iStartEndZero=$aIntMode; } // Replace all '-' with an interpolated value. We use straightforward @@ -534,66 +578,67 @@ class AccLinePlot extends Plot { // will be replaced by the the first valid data point function LineInterpolate(&$aData) { - $n=count($aData); - $i=0; - - // If first point is undefined we will set it to the same as the first - // valid data - if( $aData[$i]==='-' ) { - // Find the first valid data - while( $i < $n && $aData[$i]==='-' ) { - ++$i; - } - if( $i < $n ) { - for($j=0; $j < $i; ++$j ) { - if( $this->iStartEndZero ) - $aData[$i] = 0; - else - $aData[$j] = $aData[$i]; - } - } - else { - // All '-' => Error - return false; - } - } + $n=count($aData); + $i=0; - while($i < $n) { - while( $i < $n && $aData[$i] !== '-' ) { - ++$i; - } - if( $i < $n ) { - $pstart=$i-1; + // If first point is undefined we will set it to the same as the first + // valid data + if( $aData[$i]==='-' ) { + // Find the first valid data + while( $i < $n && $aData[$i]==='-' ) { + ++$i; + } + if( $i < $n ) { + for($j=0; $j < $i; ++$j ) { + if( $this->iStartEndZero ) + $aData[$i] = 0; + else + $aData[$j] = $aData[$i]; + } + } + else { + // All '-' => Error + return false; + } + } - // Now see how long this segment of '-' are - while( $i < $n && $aData[$i] === '-' ) - ++$i; - if( $i < $n ) { - $pend=$i; - $size=$pend-$pstart; - $k=($aData[$pend]-$aData[$pstart])/$size; - // Replace the segment of '-' with a linear interpolated value. - for($j=1; $j < $size; ++$j ) { - $aData[$pstart+$j] = $aData[$pstart] + $j*$k ; - } - } - else { - // There are no valid end point. The '-' goes all the way to the end - // In that case we just set all the remaining values the the same as the - // last valid data point. - for( $j=$pstart+1; $j < $n; ++$j ) - if( $this->iStartEndZero ) - $aData[$j] = 0; - else - $aData[$j] = $aData[$pstart] ; - } - } - } - return true; + while($i < $n) { + while( $i < $n && $aData[$i] !== '-' ) { + ++$i; + } + if( $i < $n ) { + $pstart=$i-1; + + // Now see how long this segment of '-' are + while( $i < $n && $aData[$i] === '-' ) { + ++$i; + } + if( $i < $n ) { + $pend=$i; + $size=$pend-$pstart; + $k=($aData[$pend]-$aData[$pstart])/$size; + // Replace the segment of '-' with a linear interpolated value. + for($j=1; $j < $size; ++$j ) { + $aData[$pstart+$j] = $aData[$pstart] + $j*$k ; + } + } + else { + // There are no valid end point. The '-' goes all the way to the end + // In that case we just set all the remaining values the the same as the + // last valid data point. + for( $j=$pstart+1; $j < $n; ++$j ) + if( $this->iStartEndZero ) { + $aData[$j] = 0; + } + else { + $aData[$j] = $aData[$pstart] ; + } + } + } + } + return true; } - - // To avoid duplicate of line drawing code here we just // change the y-values for each plot and then restore it // after we have made the stroke. We must do this copy since @@ -601,29 +646,30 @@ class AccLinePlot extends Plot { // with the same graphs, i.e AccLinePlot(array($pl,$pl,$pl)); // since this method would have a side effect. function Stroke($img,$xscale,$yscale) { - $img->SetLineWeight($this->weight); - $this->numpoints = count($this->plots[0]->coords[0]); - // Allocate array - $coords[$this->nbrplots][$this->numpoints]=0; - for($i=0; $i<$this->numpoints; $i++) { - $coords[0][$i]=$this->plots[0]->coords[0][$i]; - $accy=$coords[0][$i]; - for($j=1; $j<$this->nbrplots; ++$j ) { - $coords[$j][$i] = $this->plots[$j]->coords[0][$i]+$accy; - $accy = $coords[$j][$i]; - } - } - for($j=$this->nbrplots-1; $j>=0; --$j) { - $p=$this->plots[$j]; - for( $i=0; $i<$this->numpoints; ++$i) { - $tmp[$i]=$p->coords[0][$i]; - $p->coords[0][$i]=$coords[$j][$i]; - } - $p->Stroke($img,$xscale,$yscale); - for( $i=0; $i<$this->numpoints; ++$i) - $p->coords[0][$i]=$tmp[$i]; - $p->coords[0][]=$tmp; - } + $img->SetLineWeight($this->weight); + $this->numpoints = count($this->plots[0]->coords[0]); + // Allocate array + $coords[$this->nbrplots][$this->numpoints]=0; + for($i=0; $i<$this->numpoints; $i++) { + $coords[0][$i]=$this->plots[0]->coords[0][$i]; + $accy=$coords[0][$i]; + for($j=1; $j<$this->nbrplots; ++$j ) { + $coords[$j][$i] = $this->plots[$j]->coords[0][$i]+$accy; + $accy = $coords[$j][$i]; + } + } + for($j=$this->nbrplots-1; $j>=0; --$j) { + $p=$this->plots[$j]; + for( $i=0; $i<$this->numpoints; ++$i) { + $tmp[$i]=$p->coords[0][$i]; + $p->coords[0][$i]=$coords[$j][$i]; + } + $p->Stroke($img,$xscale,$yscale); + for( $i=0; $i<$this->numpoints; ++$i) { + $p->coords[0][$i]=$tmp[$i]; + } + $p->coords[0][]=$tmp; + } } } // Class diff --git a/src/classes/jpgraph/jpgraph_pie.php b/src/classes/jpgraph/jpgraph_pie.php index 0a9c57d..ba824be 100644 --- a/src/classes/jpgraph/jpgraph_pie.php +++ b/src/classes/jpgraph/jpgraph_pie.php @@ -1,21 +1,21 @@ array(136,34,40,45,46,62,63,134,74,10,120,136,141,168,180,77,209,218,346,395,89,430), - "pastel" => array(27,415,128,59,66,79,105,110,42,147,152,230,236,240,331,337,405,38), - "water" => array(8,370,24,40,335,56,213,237,268,14,326,387,10,388), - "sand" => array(27,168,34,170,19,50,65,72,131,209,46,393)); + "earth" => array(136,34,40,45,46,62,63,134,74,10,120,136,141,168,180,77,209,218,346,395,89,430), + "pastel" => array(27,415,128,59,66,79,105,110,42,147,152,230,236,240,331,337,405,38), + "water" => array(8,370,24,40,335,56,213,237,268,14,326,387,10,388), + "sand" => array(27,168,34,170,19,50,65,72,131,209,46,393)); protected $theme="earth"; protected $setslicecolors=array(); protected $labeltype=0; // Default to percentage @@ -53,1149 +53,1150 @@ class PiePlot { protected $guidelinemargin=10,$iShowGuideLineForSingle = false; protected $iGuideLineCurve = false,$iGuideVFactor=1.4,$iGuideLineRFactor=0.8; protected $la = array(); // Holds the exact angle for each label - -//--------------- -// CONSTRUCTOR - function PiePlot($data) { - $this->data = array_reverse($data); - $this->title = new Text(""); - $this->title->SetFont(FF_FONT1,FS_BOLD); - $this->value = new DisplayValue(); - $this->value->Show(); - $this->value->SetFormat('%.1f%%'); - $this->guideline = new LineProperty(); + + //--------------- + // CONSTRUCTOR + function __construct($data) { + $this->data = array_reverse($data); + $this->title = new Text(""); + $this->title->SetFont(FF_FONT1,FS_BOLD); + $this->value = new DisplayValue(); + $this->value->Show(); + $this->value->SetFormat('%.1f%%'); + $this->guideline = new LineProperty(); } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function SetCenter($x,$y=0.5) { - $this->posx = $x; - $this->posy = $y; + $this->posx = $x; + $this->posy = $y; } // Enable guideline and set drwaing policy function SetGuideLines($aFlg=true,$aCurved=true,$aAlways=false) { - $this->guideline->Show($aFlg); - $this->iShowGuideLineForSingle = $aAlways; - $this->iGuideLineCurve = $aCurved; + $this->guideline->Show($aFlg); + $this->iShowGuideLineForSingle = $aAlways; + $this->iGuideLineCurve = $aCurved; } // Adjuste the distance between labels and labels and pie function SetGuideLinesAdjust($aVFactor,$aRFactor=0.8) { - $this->iGuideVFactor=$aVFactor; - $this->iGuideLineRFactor=$aRFactor; + $this->iGuideVFactor=$aVFactor; + $this->iGuideLineRFactor=$aRFactor; } function SetColor($aColor) { - $this->color = $aColor; + $this->color = $aColor; } - + function SetSliceColors($aColors) { - $this->setslicecolors = $aColors; + $this->setslicecolors = $aColors; } - + function SetShadow($aColor='darkgray',$aDropWidth=4) { - $this->ishadowcolor = $aColor; - $this->ishadowdrop = $aDropWidth; + $this->ishadowcolor = $aColor; + $this->ishadowdrop = $aDropWidth; } function SetCSIMTargets($aTargets,$aAlts='',$aWinTargets='') { - $this->csimtargets=array_reverse($aTargets); - if( is_array($aWinTargets) ) - $this->csimwintargets=array_reverse($aWinTargets); - if( is_array($aAlts) ) - $this->csimalts=array_reverse($aAlts); + $this->csimtargets=array_reverse($aTargets); + if( is_array($aWinTargets) ) + $this->csimwintargets=array_reverse($aWinTargets); + if( is_array($aAlts) ) + $this->csimalts=array_reverse($aAlts); } - + function GetCSIMareas() { - return $this->csimareas; + return $this->csimareas; } - function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) { + function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) { //Slice number, ellipse centre (x,y), height, width, start angle, end angle - while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI; - while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI; + while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI; + while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI; - $sa = 2*M_PI - $sa; - $ea = 2*M_PI - $ea; + $sa = 2*M_PI - $sa; + $ea = 2*M_PI - $ea; - // Special case when we have only one slice since then both start and end - // angle will be == 0 - if( abs($sa - $ea) < 0.0001 ) { - $sa=2*M_PI; $ea=0; - } + // Special case when we have only one slice since then both start and end + // angle will be == 0 + if( abs($sa - $ea) < 0.0001 ) { + $sa=2*M_PI; $ea=0; + } - //add coordinates of the centre to the map - $xc = floor($xc);$yc=floor($yc); - $coords = "$xc, $yc"; + //add coordinates of the centre to the map + $xc = floor($xc);$yc=floor($yc); + $coords = "$xc, $yc"; - //add coordinates of the first point on the arc to the map - $xp = floor(($radius*cos($ea))+$xc); - $yp = floor($yc-$radius*sin($ea)); - $coords.= ", $xp, $yp"; - - //add coordinates every 0.2 radians - $a=$ea+0.2; + //add coordinates of the first point on the arc to the map + $xp = floor(($radius*cos($ea))+$xc); + $yp = floor($yc-$radius*sin($ea)); + $coords.= ", $xp, $yp"; - // If we cross the 360-limit with a slice we need to handle - // the fact that end angle is smaller than start - if( $sa < $ea ) { - while ($a <= 2*M_PI) { - $xp = floor($radius*cos($a)+$xc); - $yp = floor($yc-$radius*sin($a)); - $coords.= ", $xp, $yp"; - $a += 0.2; - } - $a -= 2*M_PI; - } + //add coordinates every 0.2 radians + $a=$ea+0.2; + + // If we cross the 360-limit with a slice we need to handle + // the fact that end angle is smaller than start + if( $sa < $ea ) { + while ($a <= 2*M_PI) { + $xp = floor($radius*cos($a)+$xc); + $yp = floor($yc-$radius*sin($a)); + $coords.= ", $xp, $yp"; + $a += 0.2; + } + $a -= 2*M_PI; + } - while ($a < $sa) { - $xp = floor($radius*cos($a)+$xc); - $yp = floor($yc-$radius*sin($a)); - $coords.= ", $xp, $yp"; - $a += 0.2; - } - - //Add the last point on the arc - $xp = floor($radius*cos($sa)+$xc); - $yp = floor($yc-$radius*sin($sa)); - $coords.= ", $xp, $yp"; - if( !empty($this->csimtargets[$i]) ) { - $this->csimareas .= "csimtargets[$i]."\""; - $tmp=""; - if( !empty($this->csimwintargets[$i]) ) { - $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; - } - if( !empty($this->csimalts[$i]) ) { - $tmp=sprintf($this->csimalts[$i],$this->data[$i]); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; - } + while ($a < $sa) { + $xp = floor($radius*cos($a)+$xc); + $yp = floor($yc-$radius*sin($a)); + $coords.= ", $xp, $yp"; + $a += 0.2; + } + + //Add the last point on the arc + $xp = floor($radius*cos($sa)+$xc); + $yp = floor($yc-$radius*sin($sa)); + $coords.= ", $xp, $yp"; + if( !empty($this->csimtargets[$i]) ) { + $this->csimareas .= "csimtargets[$i]."\""; + $tmp=""; + if( !empty($this->csimwintargets[$i]) ) { + $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; + } + if( !empty($this->csimalts[$i]) ) { + $tmp=sprintf($this->csimalts[$i],$this->data[$i]); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } } - + function SetTheme($aTheme) { - if( in_array($aTheme,array_keys($this->themearr)) ) - $this->theme = $aTheme; - else - JpGraphError::RaiseL(15001,$aTheme);//("PiePLot::SetTheme() Unknown theme: $aTheme"); + if( in_array($aTheme,array_keys($this->themearr)) ) + $this->theme = $aTheme; + else + JpGraphError::RaiseL(15001,$aTheme);//("PiePLot::SetTheme() Unknown theme: $aTheme"); } - + function ExplodeSlice($e,$radius=20) { - if( ! is_integer($e) ) - JpGraphError::RaiseL(15002);//('Argument to PiePlot::ExplodeSlice() must be an integer'); - $this->explode_radius[$e]=$radius; + if( ! is_integer($e) ) + JpGraphError::RaiseL(15002);//('Argument to PiePlot::ExplodeSlice() must be an integer'); + $this->explode_radius[$e]=$radius; } function ExplodeAll($radius=20) { - $this->explode_all=true; - $this->explode_r = $radius; + $this->explode_all=true; + $this->explode_r = $radius; } function Explode($aExplodeArr) { - if( !is_array($aExplodeArr) ) { - JpGraphError::RaiseL(15003); -//("Argument to PiePlot::Explode() must be an array with integer distances."); - } - $this->explode_radius = $aExplodeArr; + if( !is_array($aExplodeArr) ) { + JpGraphError::RaiseL(15003); + //("Argument to PiePlot::Explode() must be an array with integer distances."); + } + $this->explode_radius = $aExplodeArr; } function SetStartAngle($aStart) { - if( $aStart < 0 || $aStart > 360 ) { - JpGraphError::RaiseL(15004);//('Slice start angle must be between 0 and 360 degrees.'); - } - $this->startangle = 360-$aStart; - $this->startangle *= M_PI/180; - } - - function SetFont($family,$style=FS_NORMAL,$size=10) { - JpGraphError::RaiseL(15005);//('PiePlot::SetFont() is deprecated. Use PiePlot->value->SetFont() instead.'); - } - - // Size in percentage - function SetSize($aSize) { - if( ($aSize>0 && $aSize<=0.5) || ($aSize>10 && $aSize<1000) ) - $this->radius = $aSize; - else - JpGraphError::RaiseL(15006); -//("PiePlot::SetSize() Radius for pie must either be specified as a fraction [0, 0.5] of the size of the image or as an absolute size in pixels in the range [10, 1000]"); - } - - function SetFontColor($aColor) { - JpGraphError::RaiseL(15007); -//('PiePlot::SetFontColor() is deprecated. Use PiePlot->value->SetColor() instead.'); - } - - // Set label arrays - function SetLegends($aLegend) { - $this->legends = $aLegend; + if( $aStart < 0 || $aStart > 360 ) { + JpGraphError::RaiseL(15004);//('Slice start angle must be between 0 and 360 degrees.'); + } + $this->startangle = 360-$aStart; + $this->startangle *= M_PI/180; } - // Set text labels for slices + // Size in percentage + function SetSize($aSize) { + if( ($aSize>0 && $aSize<=0.5) || ($aSize>10 && $aSize<1000) ) + $this->radius = $aSize; + else + JpGraphError::RaiseL(15006); + //("PiePlot::SetSize() Radius for pie must either be specified as a fraction [0, 0.5] of the size of the image or as an absolute size in pixels in the range [10, 1000]"); + } + + // Set label arrays + function SetLegends($aLegend) { + $this->legends = $aLegend; + } + + // Set text labels for slices function SetLabels($aLabels,$aLblPosAdj="auto") { - $this->labels = array_reverse($aLabels); - $this->ilabelposadj=$aLblPosAdj; + $this->labels = array_reverse($aLabels); + $this->ilabelposadj=$aLblPosAdj; } function SetLabelPos($aLblPosAdj) { - $this->ilabelposadj=$aLblPosAdj; - } - - // Should we display actual value or percentage? - function SetLabelType($t) { - if( $t < 0 || $t > 2 ) - JpGraphError::RaiseL(15008,$t); -//("PiePlot::SetLabelType() Type for pie plots must be 0 or 1 (not $t)."); - $this->labeltype=$t; + $this->ilabelposadj=$aLblPosAdj; } - // Deprecated. + // Should we display actual value or percentage? + function SetLabelType($aType) { + if( $aType < 0 || $aType > 2 ) + JpGraphError::RaiseL(15008,$aType); + //("PiePlot::SetLabelType() Type for pie plots must be 0 or 1 (not $t)."); + $this->labeltype = $aType; + } + + // Deprecated. function SetValueType($aType) { - $this->SetLabelType($aType); + $this->SetLabelType($aType); } // Should the circle around a pie plot be displayed function ShowBorder($exterior=true,$interior=true) { - $this->pie_border = $exterior; - $this->pie_interior_border = $interior; + $this->pie_border = $exterior; + $this->pie_interior_border = $interior; } - + // Setup the legends function Legend($graph) { - $colors = array_keys($graph->img->rgb->rgb_table); - sort($colors); - $ta=$this->themearr[$this->theme]; - $n = count($this->data); + $colors = array_keys($graph->img->rgb->rgb_table); + sort($colors); + $ta=$this->themearr[$this->theme]; + $n = count($this->data); - if( $this->setslicecolors==null ) { - $numcolors=count($ta); - if( class_exists('PiePlot3D',false) && ($this instanceof PiePlot3D) ) { - $ta = array_reverse(array_slice($ta,0,$n)); - } - } - else { - $this->setslicecolors = array_slice($this->setslicecolors,0,$n); - $numcolors=count($this->setslicecolors); - if( $graph->pieaa && !($this instanceof PiePlot3D) ) { - $this->setslicecolors = array_reverse($this->setslicecolors); - } - } - - $sum=0; - for($i=0; $i < $n; ++$i) - $sum += $this->data[$i]; + if( $this->setslicecolors==null ) { + $numcolors=count($ta); + if( class_exists('PiePlot3D',false) && ($this instanceof PiePlot3D) ) { + $ta = array_reverse(array_slice($ta,0,$n)); + } + } + else { + $this->setslicecolors = array_slice($this->setslicecolors,0,$n); + $numcolors=count($this->setslicecolors); + if( $graph->pieaa && !($this instanceof PiePlot3D) ) { + $this->setslicecolors = array_reverse($this->setslicecolors); + } + } - // Bail out with error if the sum is 0 - if( $sum==0 ) - JpGraphError::RaiseL(15009);//("Illegal pie plot. Sum of all data is zero for Pie!"); + $sum=0; + for($i=0; $i < $n; ++$i) + $sum += $this->data[$i]; - // Make sure we don't plot more values than data points - // (in case the user added more legends than data points) - $n = min(count($this->legends),count($this->data)); - if( $this->legends != "" ) { - $this->legends = array_reverse(array_slice($this->legends,0,$n)); - } - for( $i=$n-1; $i >= 0; --$i ) { - $l = $this->legends[$i]; - // Replace possible format with actual values - if( count($this->csimalts) > $i ) { - $fmt = $this->csimalts[$i]; - } - else { - $fmt = "%d"; // Deafult Alt if no other has been specified - } - if( $this->labeltype==0 ) { - $l = sprintf($l,100*$this->data[$i]/$sum); - $alt = sprintf($fmt,$this->data[$i]); - - } - elseif( $this->labeltype == 1) { - $l = sprintf($l,$this->data[$i]); - $alt = sprintf($fmt,$this->data[$i]); - - } - else { - $l = sprintf($l,$this->adjusted_data[$i]); - $alt = sprintf($fmt,$this->adjusted_data[$i]); - } + // Bail out with error if the sum is 0 + if( $sum==0 ) + JpGraphError::RaiseL(15009);//("Illegal pie plot. Sum of all data is zero for Pie!"); - if( empty($this->csimwintargets[$i]) ) { - $wintarg = ''; - } - else { - $wintarg = $this->csimwintargets[$i]; - } + // Make sure we don't plot more values than data points + // (in case the user added more legends than data points) + $n = min(count($this->legends),count($this->data)); + if( $this->legends != "" ) { + $this->legends = array_reverse(array_slice($this->legends,0,$n)); + } + for( $i=$n-1; $i >= 0; --$i ) { + $l = $this->legends[$i]; + // Replace possible format with actual values + if( count($this->csimalts) > $i ) { + $fmt = $this->csimalts[$i]; + } + else { + $fmt = "%d"; // Deafult Alt if no other has been specified + } + if( $this->labeltype==0 ) { + $l = sprintf($l,100*$this->data[$i]/$sum); + $alt = sprintf($fmt,$this->data[$i]); - if( $this->setslicecolors==null ) { - $graph->legend->Add($l,$colors[$ta[$i%$numcolors]],"",0,$this->csimtargets[$i],$alt,$wintarg); - } - else { - $graph->legend->Add($l,$this->setslicecolors[$i%$numcolors],"",0,$this->csimtargets[$i],$alt,$wintarg); - } - } + } + elseif( $this->labeltype == 1) { + $l = sprintf($l,$this->data[$i]); + $alt = sprintf($fmt,$this->data[$i]); + + } + else { + $l = sprintf($l,$this->adjusted_data[$i]); + $alt = sprintf($fmt,$this->adjusted_data[$i]); + } + + if( empty($this->csimwintargets[$i]) ) { + $wintarg = ''; + } + else { + $wintarg = $this->csimwintargets[$i]; + } + + if( $this->setslicecolors==null ) { + $graph->legend->Add($l,$colors[$ta[$i%$numcolors]],"",0,$this->csimtargets[$i],$alt,$wintarg); + } + else { + $graph->legend->Add($l,$this->setslicecolors[$i%$numcolors],"",0,$this->csimtargets[$i],$alt,$wintarg); + } + } } - + // Adjust the rounded percetage value so that the sum of // of the pie slices are always 100% // Using the Hare/Niemeyer method function AdjPercentage($aData,$aPrec=0) { - $mul=100; - if( $aPrec > 0 && $aPrec < 3 ) { - if( $aPrec == 1 ) - $mul=1000; - else - $mul=10000; - } - - $tmp = array(); - $result = array(); - $quote_sum=0; - $n = count($aData) ; - for( $i=0, $sum=0; $i < $n; ++$i ) - $sum+=$aData[$i]; - foreach($aData as $index => $value) { - $tmp_percentage=$value/$sum*$mul; - $result[$index]=floor($tmp_percentage); - $tmp[$index]=$tmp_percentage-$result[$index]; - $quote_sum+=$result[$index]; - } - if( $quote_sum == $mul) { - if( $mul > 100 ) { - $tmp = $mul / 100; - for( $i=0; $i < $n; ++$i ) { - $result[$i] /= $tmp ; - } - } - return $result; - } - arsort($tmp,SORT_NUMERIC); - reset($tmp); - for($i=0; $i < $mul-$quote_sum; $i++) - { - $result[key($tmp)]++; - next($tmp); - } - if( $mul > 100 ) { - $tmp = $mul / 100; - for( $i=0; $i < $n; ++$i ) { - $result[$i] /= $tmp ; - } - } - return $result; + $mul=100; + if( $aPrec > 0 && $aPrec < 3 ) { + if( $aPrec == 1 ) + $mul=1000; + else + $mul=10000; + } + + $tmp = array(); + $result = array(); + $quote_sum=0; + $n = count($aData) ; + for( $i=0, $sum=0; $i < $n; ++$i ) + $sum+=$aData[$i]; + foreach($aData as $index => $value) { + $tmp_percentage=$value/$sum*$mul; + $result[$index]=floor($tmp_percentage); + $tmp[$index]=$tmp_percentage-$result[$index]; + $quote_sum+=$result[$index]; + } + if( $quote_sum == $mul) { + if( $mul > 100 ) { + $tmp = $mul / 100; + for( $i=0; $i < $n; ++$i ) { + $result[$i] /= $tmp ; + } + } + return $result; + } + arsort($tmp,SORT_NUMERIC); + reset($tmp); + for($i=0; $i < $mul-$quote_sum; $i++) + { + $result[key($tmp)]++; + next($tmp); + } + if( $mul > 100 ) { + $tmp = $mul / 100; + for( $i=0; $i < $n; ++$i ) { + $result[$i] /= $tmp ; + } + } + return $result; } function Stroke($img,$aaoption=0) { - // aaoption is used to handle antialias - // aaoption == 0 a normal pie - // aaoption == 1 just the body - // aaoption == 2 just the values + // aaoption is used to handle antialias + // aaoption == 0 a normal pie + // aaoption == 1 just the body + // aaoption == 2 just the values - // Explode scaling. If anti anti alias we scale the image - // twice and we also need to scale the exploding distance - $expscale = $aaoption === 1 ? 2 : 1; + // Explode scaling. If anti anti alias we scale the image + // twice and we also need to scale the exploding distance + $expscale = $aaoption === 1 ? 2 : 1; - if( $this->labeltype == 2 ) { - // Adjust the data so that it will add up to 100% - $this->adjusted_data = $this->AdjPercentage($this->data); - } + if( $this->labeltype == 2 ) { + // Adjust the data so that it will add up to 100% + $this->adjusted_data = $this->AdjPercentage($this->data); + } - $colors = array_keys($img->rgb->rgb_table); - sort($colors); - $ta=$this->themearr[$this->theme]; - $n = count($this->data); - - if( $this->setslicecolors==null ) { - $numcolors=count($ta); - } - else { - // We need to create an array of colors as long as the data - // since we need to reverse it to get the colors in the right order - $numcolors=count($this->setslicecolors); - $i = 2*$numcolors; - while( $n > $i ) { - $this->setslicecolors = array_merge($this->setslicecolors,$this->setslicecolors); - $i += $n; - } - $tt = array_slice($this->setslicecolors,0,$n % $numcolors); - $this->setslicecolors = array_merge($this->setslicecolors,$tt); - $this->setslicecolors = array_reverse($this->setslicecolors); - } + $colors = array_keys($img->rgb->rgb_table); + sort($colors); + $ta=$this->themearr[$this->theme]; + $n = count($this->data); - // Draw the slices - $sum=0; - for($i=0; $i < $n; ++$i) - $sum += $this->data[$i]; - - // Bail out with error if the sum is 0 - if( $sum==0 ) - JpGraphError::RaiseL(15009);//("Sum of all data is 0 for Pie."); - - // Set up the pie-circle - if( $this->radius <= 1 ) - $radius = floor($this->radius*min($img->width,$img->height)); - else { - $radius = $aaoption === 1 ? $this->radius*2 : $this->radius; - } + if( $this->setslicecolors==null ) { + $numcolors=count($ta); + } + else { + // We need to create an array of colors as long as the data + // since we need to reverse it to get the colors in the right order + $numcolors=count($this->setslicecolors); + $i = 2*$numcolors; + while( $n > $i ) { + $this->setslicecolors = array_merge($this->setslicecolors,$this->setslicecolors); + $i += $n; + } + $tt = array_slice($this->setslicecolors,0,$n % $numcolors); + $this->setslicecolors = array_merge($this->setslicecolors,$tt); + $this->setslicecolors = array_reverse($this->setslicecolors); + } - if( $this->posx <= 1 && $this->posx > 0 ) - $xc = round($this->posx*$img->width); - else - $xc = $this->posx ; - - if( $this->posy <= 1 && $this->posy > 0 ) - $yc = round($this->posy*$img->height); - else - $yc = $this->posy ; - - $n = count($this->data); + // Draw the slices + $sum=0; + for($i=0; $i < $n; ++$i) + $sum += $this->data[$i]; - if( $this->explode_all ) - for($i=0; $i < $n; ++$i) - $this->explode_radius[$i]=$this->explode_r; + // Bail out with error if the sum is 0 + if( $sum==0 ) + JpGraphError::RaiseL(15009);//("Sum of all data is 0 for Pie."); - // If we have a shadow and not just drawing the labels - if( $this->ishadowcolor != "" && $aaoption !== 2) { - $accsum=0; - $angle2 = $this->startangle; - $img->SetColor($this->ishadowcolor); - for($i=0; $sum > 0 && $i < $n; ++$i) { - $j = $n-$i-1; - $d = $this->data[$i]; - $angle1 = $angle2; - $accsum += $d; - $angle2 = $this->startangle+2*M_PI*$accsum/$sum; - if( empty($this->explode_radius[$j]) ) - $this->explode_radius[$j]=0; + // Set up the pie-circle + if( $this->radius <= 1 ) + $radius = floor($this->radius*min($img->width,$img->height)); + else { + $radius = $aaoption === 1 ? $this->radius*2 : $this->radius; + } - if( $d < 0.00001 ) continue; + if( $this->posx <= 1 && $this->posx > 0 ) + $xc = round($this->posx*$img->width); + else + $xc = $this->posx ; - $la = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1); + if( $this->posy <= 1 && $this->posy > 0 ) + $yc = round($this->posy*$img->height); + else + $yc = $this->posy ; - $xcm = $xc + $this->explode_radius[$j]*cos($la)*$expscale; - $ycm = $yc - $this->explode_radius[$j]*sin($la)*$expscale; - - $xcm += $this->ishadowdrop*$expscale; - $ycm += $this->ishadowdrop*$expscale; + $n = count($this->data); - $_sa = round($angle1*180/M_PI); - $_ea = round($angle2*180/M_PI); + if( $this->explode_all ) + for($i=0; $i < $n; ++$i) + $this->explode_radius[$i]=$this->explode_r; - // The CakeSlice method draws a full circle in case of start angle = end angle - // for pie slices we don't want this behaviour unless we only have one - // slice in the pie in case it is the wanted behaviour - if( $_ea-$_sa > 0.1 || $n==1 ) { - $img->CakeSlice($xcm,$ycm,$radius-1,$radius-1, - $angle1*180/M_PI,$angle2*180/M_PI,$slicecolor,$arccolor); - } - } - } + // If we have a shadow and not just drawing the labels + if( $this->ishadowcolor != "" && $aaoption !== 2) { + $accsum=0; + $angle2 = $this->startangle; + $img->SetColor($this->ishadowcolor); + for($i=0; $sum > 0 && $i < $n; ++$i) { + $j = $n-$i-1; + $d = $this->data[$i]; + $angle1 = $angle2; + $accsum += $d; + $angle2 = $this->startangle+2*M_PI*$accsum/$sum; + if( empty($this->explode_radius[$j]) ) + $this->explode_radius[$j]=0; - //-------------------------------------------------------------------------------- - // This is the main loop to draw each cake slice - //-------------------------------------------------------------------------------- + if( $d < 0.00001 ) continue; - // Set up the accumulated sum, start angle for first slice and border color - $accsum=0; - $angle2 = $this->startangle; - $img->SetColor($this->color); + $la = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1); - // Loop though all the slices if there is a pie to draw (sum>0) - // There are n slices in total - for($i=0; $sum>0 && $i < $n; ++$i) { + $xcm = $xc + $this->explode_radius[$j]*cos($la)*$expscale; + $ycm = $yc - $this->explode_radius[$j]*sin($la)*$expscale; - // $j is the actual index used for the slice - $j = $n-$i-1; + $xcm += $this->ishadowdrop*$expscale; + $ycm += $this->ishadowdrop*$expscale; - // Make sure we havea valid distance to explode the slice - if( empty($this->explode_radius[$j]) ) - $this->explode_radius[$j]=0; + $_sa = round($angle1*180/M_PI); + $_ea = round($angle2*180/M_PI); - // The actual numeric value for the slice - $d = $this->data[$i]; + // The CakeSlice method draws a full circle in case of start angle = end angle + // for pie slices we don't want this behaviour unless we only have one + // slice in the pie in case it is the wanted behaviour + if( $_ea-$_sa > 0.1 || $n==1 ) { + $img->CakeSlice($xcm,$ycm,$radius-1,$radius-1, + $angle1*180/M_PI,$angle2*180/M_PI,$this->ishadowcolor); + } + } + } - $angle1 = $angle2; + //-------------------------------------------------------------------------------- + // This is the main loop to draw each cake slice + //-------------------------------------------------------------------------------- - // Accumlate the sum - $accsum += $d; + // Set up the accumulated sum, start angle for first slice and border color + $accsum=0; + $angle2 = $this->startangle; + $img->SetColor($this->color); - // The new angle when we add the "size" of this slice - // angle1 is then the start and angle2 the end of this slice - $angle2 = $this->NormAngle($this->startangle+2*M_PI*$accsum/$sum); + // Loop though all the slices if there is a pie to draw (sum>0) + // There are n slices in total + for($i=0; $sum>0 && $i < $n; ++$i) { - // We avoid some trouble by not allowing end angle to be 0, in that case - // we translate to 360 + // $j is the actual index used for the slice + $j = $n-$i-1; + + // Make sure we havea valid distance to explode the slice + if( empty($this->explode_radius[$j]) ) + $this->explode_radius[$j]=0; + + // The actual numeric value for the slice + $d = $this->data[$i]; + + $angle1 = $angle2; + + // Accumlate the sum + $accsum += $d; + + // The new angle when we add the "size" of this slice + // angle1 is then the start and angle2 the end of this slice + $angle2 = $this->NormAngle($this->startangle+2*M_PI*$accsum/$sum); + + // We avoid some trouble by not allowing end angle to be 0, in that case + // we translate to 360 - // la is used to hold the label angle, which is centered on the slice - if( $angle2 < 0.0001 && $angle1 > 0.0001 ) { - $this->la[$i] = 2*M_PI - (abs(2*M_PI-$angle1)/2.0+$angle1); - } - else - $this->la[$i] = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1); + // la is used to hold the label angle, which is centered on the slice + if( $angle2 < 0.0001 && $angle1 > 0.0001 ) { + $this->la[$i] = 2*M_PI - (abs(2*M_PI-$angle1)/2.0+$angle1); + } + elseif( $angle1 > $angle2 ) { + // The case where the slice crosses the 3 a'clock line + // Remember that the slices are counted clockwise and + // labels are counted counter clockwise so we need to revert with 2 PI + $this->la[$i] = 2*M_PI-$this->NormAngle($angle1 + ((2*M_PI - $angle1)+$angle2)/2); + } + else { + $this->la[$i] = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1); + } - $_sa = round($angle1*180/M_PI); - $_ea = round($angle2*180/M_PI); - $_la = round($this->la[$i]*180/M_PI); - //echo "ang1=$_sa , ang2=$_ea - la=$_la
"; + // Too avoid rounding problems we skip the slice if it is too small + if( $d < 0.00001 ) continue; - // Too avoid rounding problems we skip the slice if it is too small - if( $d < 0.00001 ) continue; + // If the user has specified an array of colors for each slice then use + // that a color otherwise use the theme array (ta) of colors + if( $this->setslicecolors==null ) + $slicecolor=$colors[$ta[$i%$numcolors]]; + else + $slicecolor=$this->setslicecolors[$i%$numcolors]; - // If the user has specified an array of colors for each slice then use - // that a color otherwise use the theme array (ta) of colors - if( $this->setslicecolors==null ) - $slicecolor=$colors[$ta[$i%$numcolors]]; - else - $slicecolor=$this->setslicecolors[$i%$numcolors]; - - // If we have enabled antialias then we don't draw any border so - // make the bordedr color the same as the slice color - if( $this->pie_interior_border && $aaoption===0 ) - $img->SetColor($this->color); - else - $img->SetColor($slicecolor); - $arccolor = $this->pie_border && $aaoption===0 ? $this->color : ""; - // Calculate the x,y coordinates for the base of this slice taking - // the exploded distance into account. Here we use the mid angle as the - // ray of extension and we have the mid angle handy as it is also the - // label angle - $xcm = $xc + $this->explode_radius[$j]*cos($this->la[$i])*$expscale; - $ycm = $yc - $this->explode_radius[$j]*sin($this->la[$i])*$expscale; - // If we are not just drawing the labels then draw this cake slice - if( $aaoption !== 2 ) { + //$_sa = round($angle1*180/M_PI); + //$_ea = round($angle2*180/M_PI); + //$_la = round($this->la[$i]*180/M_PI); + //echo "ang1=$_sa , ang2=$_ea, la=$_la, color=$slicecolor
"; - - $_sa = round($angle1*180/M_PI); - $_ea = round($angle2*180/M_PI); - $_la = round($this->la[$i]*180/M_PI); - //echo "[$i] sa=$_sa, ea=$_ea, la[$i]=$_la, (color=$slicecolor)
"; - - // The CakeSlice method draws a full circle in case of start angle = end angle - // for pie slices we don't want this behaviour unless we only have one - // slice in the pie in case it is the wanted behaviour - if( abs($_ea-$_sa) > 0.1 || $n==1 ) { - $img->CakeSlice($xcm,$ycm,$radius-1,$radius-1,$_sa,$_ea,$slicecolor,$arccolor); - } - } + // If we have enabled antialias then we don't draw any border so + // make the bordedr color the same as the slice color + if( $this->pie_interior_border && $aaoption===0 ) + $img->SetColor($this->color); + else + $img->SetColor($slicecolor); + $arccolor = $this->pie_border && $aaoption===0 ? $this->color : ""; - // If the CSIM is used then make sure we register a CSIM area for this slice as well - if( $this->csimtargets && $aaoption !== 1 ) { - $this->AddSliceToCSIM($i,$xcm,$ycm,$radius,$angle1,$angle2); - } - } + // Calculate the x,y coordinates for the base of this slice taking + // the exploded distance into account. Here we use the mid angle as the + // ray of extension and we have the mid angle handy as it is also the + // label angle + $xcm = $xc + $this->explode_radius[$j]*cos($this->la[$i])*$expscale; + $ycm = $yc - $this->explode_radius[$j]*sin($this->la[$i])*$expscale; - // Format the titles for each slice - if( $aaoption !== 2 ) { - for( $i=0; $i < $n; ++$i) { - if( $this->labeltype==0 ) { - if( $sum != 0 ) - $l = 100.0*$this->data[$i]/$sum; - else - $l = 0.0; - } - elseif( $this->labeltype==1 ) { - $l = $this->data[$i]*1.0; - } - else { - $l = $this->adjusted_data[$i]; - } - if( isset($this->labels[$i]) && is_string($this->labels[$i]) ) - $this->labels[$i]=sprintf($this->labels[$i],$l); - else - $this->labels[$i]=$l; - } - } + // If we are not just drawing the labels then draw this cake slice + if( $aaoption !== 2 ) { - if( $this->value->show && $aaoption !== 1 ) { - $this->StrokeAllLabels($img,$xc,$yc,$radius); - } - // Adjust title position - if( $aaoption !== 1 ) { - $this->title->SetPos($xc, - $yc-$this->title->GetFontHeight($img)-$radius-$this->title->margin, - "center","bottom"); - $this->title->Stroke($img); - } + $_sa = round($angle1*180/M_PI); + $_ea = round($angle2*180/M_PI); + $_la = round($this->la[$i]*180/M_PI); + //echo "[$i] sa=$_sa, ea=$_ea, la[$i]=$_la, (color=$slicecolor)
"; + + + // The CakeSlice method draws a full circle in case of start angle = end angle + // for pie slices we don't want this behaviour unless we only have one + // slice in the pie in case it is the wanted behaviour + if( abs($_ea-$_sa) > 0.1 || $n==1 ) { + $img->CakeSlice($xcm,$ycm,$radius-1,$radius-1,$_sa,$_ea,$slicecolor,$arccolor); + } + } + + // If the CSIM is used then make sure we register a CSIM area for this slice as well + if( $this->csimtargets && $aaoption !== 1 ) { + $this->AddSliceToCSIM($i,$xcm,$ycm,$radius,$angle1,$angle2); + } + } + + // Format the titles for each slice + if( $aaoption !== 2 ) { + for( $i=0; $i < $n; ++$i) { + if( $this->labeltype==0 ) { + if( $sum != 0 ) + $l = 100.0*$this->data[$i]/$sum; + else + $l = 0.0; + } + elseif( $this->labeltype==1 ) { + $l = $this->data[$i]*1.0; + } + else { + $l = $this->adjusted_data[$i]; + } + if( isset($this->labels[$i]) && is_string($this->labels[$i]) ) + $this->labels[$i]=sprintf($this->labels[$i],$l); + else + $this->labels[$i]=$l; + } + } + + if( $this->value->show && $aaoption !== 1 ) { + $this->StrokeAllLabels($img,$xc,$yc,$radius); + } + + // Adjust title position + if( $aaoption !== 1 ) { + $this->title->SetPos($xc, + $yc-$this->title->GetFontHeight($img)-$radius-$this->title->margin, + "center","bottom"); + $this->title->Stroke($img); + } } -//--------------- -// PRIVATE METHODS + //--------------- + // PRIVATE METHODS function NormAngle($a) { - while( $a < 0 ) $a += 2*M_PI; - while( $a > 2*M_PI ) $a -= 2*M_PI; - return $a; + while( $a < 0 ) $a += 2*M_PI; + while( $a > 2*M_PI ) $a -= 2*M_PI; + return $a; } function Quadrant($a) { - $a=$this->NormAngle($a); - if( $a > 0 && $a <= M_PI/2 ) - return 0; - if( $a > M_PI/2 && $a <= M_PI ) - return 1; - if( $a > M_PI && $a <= 1.5*M_PI ) - return 2; - if( $a > 1.5*M_PI ) - return 3; + $a=$this->NormAngle($a); + if( $a > 0 && $a <= M_PI/2 ) + return 0; + if( $a > M_PI/2 && $a <= M_PI ) + return 1; + if( $a > M_PI && $a <= 1.5*M_PI ) + return 2; + if( $a > 1.5*M_PI ) + return 3; } function StrokeGuideLabels($img,$xc,$yc,$radius) { - $n = count($this->labels); + $n = count($this->labels); - //----------------------------------------------------------------------- - // Step 1 of the algorithm is to construct a number of clusters - // a cluster is defined as all slices within the same quadrant (almost) - // that has an angular distance less than the treshold - //----------------------------------------------------------------------- - $tresh_hold=25 * M_PI/180; // 25 degrees difference to be in a cluster - $incluster=false; // flag if we are currently in a cluster or not - $clusters = array(); // array of clusters - $cidx=-1; // running cluster index + //----------------------------------------------------------------------- + // Step 1 of the algorithm is to construct a number of clusters + // a cluster is defined as all slices within the same quadrant (almost) + // that has an angular distance less than the treshold + //----------------------------------------------------------------------- + $tresh_hold=25 * M_PI/180; // 25 degrees difference to be in a cluster + $incluster=false; // flag if we are currently in a cluster or not + $clusters = array(); // array of clusters + $cidx=-1; // running cluster index - // Go through all the labels and construct a number of clusters - for($i=0; $i < $n-1; ++$i) { - // Calc the angle distance between two consecutive slices - $a1=$this->la[$i]; - $a2=$this->la[$i+1]; - $q1 = $this->Quadrant($a1); - $q2 = $this->Quadrant($a2); - $diff = abs($a1-$a2); - if( $diff < $tresh_hold ) { - if( $incluster ) { - $clusters[$cidx][1]++; - // Each cluster can only cover one quadrant - // Do we cross a quadrant ( and must break the cluster) - if( $q1 != $q2 ) { - // If we cross a quadrant boundary we normally start a - // new cluster. However we need to take the 12'a clock - // and 6'a clock positions into a special consideration. - // Case 1: WE go from q=1 to q=2 if the last slice on - // the cluster for q=1 is close to 12'a clock and the - // first slice in q=0 is small we extend the previous - // cluster - if( $q1 == 1 && $q2 == 0 && $a2 > (90-15)*M_PI/180 ) { - if( $i < $n-2 ) { - $a3 = $this->la[$i+2]; - // If there isn't a cluster coming up with the next-next slice - // we extend the previous cluster to cover this slice as well - if( abs($a3-$a2) >= $tresh_hold ) { - $clusters[$cidx][1]++; - $i++; - } - } - } - elseif( $q1 == 3 && $q2 == 2 && $a2 > (270-15)*M_PI/180 ) { - if( $i < $n-2 ) { - $a3 = $this->la[$i+2]; - // If there isn't a cluster coming up with the next-next slice - // we extend the previous cluster to cover this slice as well - if( abs($a3-$a2) >= $tresh_hold ) { - $clusters[$cidx][1]++; - $i++; - } - } - } + // Go through all the labels and construct a number of clusters + for($i=0; $i < $n-1; ++$i) { + // Calc the angle distance between two consecutive slices + $a1=$this->la[$i]; + $a2=$this->la[$i+1]; + $q1 = $this->Quadrant($a1); + $q2 = $this->Quadrant($a2); + $diff = abs($a1-$a2); + if( $diff < $tresh_hold ) { + if( $incluster ) { + $clusters[$cidx][1]++; + // Each cluster can only cover one quadrant + // Do we cross a quadrant ( and must break the cluster) + if( $q1 != $q2 ) { + // If we cross a quadrant boundary we normally start a + // new cluster. However we need to take the 12'a clock + // and 6'a clock positions into a special consideration. + // Case 1: WE go from q=1 to q=2 if the last slice on + // the cluster for q=1 is close to 12'a clock and the + // first slice in q=0 is small we extend the previous + // cluster + if( $q1 == 1 && $q2 == 0 && $a2 > (90-15)*M_PI/180 ) { + if( $i < $n-2 ) { + $a3 = $this->la[$i+2]; + // If there isn't a cluster coming up with the next-next slice + // we extend the previous cluster to cover this slice as well + if( abs($a3-$a2) >= $tresh_hold ) { + $clusters[$cidx][1]++; + $i++; + } + } + } + elseif( $q1 == 3 && $q2 == 2 && $a2 > (270-15)*M_PI/180 ) { + if( $i < $n-2 ) { + $a3 = $this->la[$i+2]; + // If there isn't a cluster coming up with the next-next slice + // we extend the previous cluster to cover this slice as well + if( abs($a3-$a2) >= $tresh_hold ) { + $clusters[$cidx][1]++; + $i++; + } + } + } - if( $q1==2 && $q2==1 && $a2 > (180-15)*M_PI/180 ) { - $clusters[$cidx][1]++; - $i++; - } - - $incluster = false; - } - } - elseif( $q1 == $q2) { - $incluster = true; - // Now we have a special case for quadrant 0. If we previously - // have a cluster of one in quadrant 0 we just extend that - // cluster. If we don't do this then we risk that the label - // for the cluster of one will cross the guide-line - if( $q1 == 0 && $cidx > -1 && - $clusters[$cidx][1] == 1 && - $this->Quadrant($this->la[$clusters[$cidx][0]]) == 0 ) { - $clusters[$cidx][1]++; - } - else { - $cidx++; - $clusters[$cidx][0] = $i; - $clusters[$cidx][1] = 1; - } - } - else { - // Create a "cluster" of one since we are just crossing - // a quadrant - $cidx++; - $clusters[$cidx][0] = $i; - $clusters[$cidx][1] = 1; - } - } - else { - if( $incluster ) { - // Add the last slice - $clusters[$cidx][1]++; - $incluster = false; - } - else { // Create a "cluster" of one - $cidx++; - $clusters[$cidx][0] = $i; - $clusters[$cidx][1] = 1; - } - } - } - // Handle the very last slice - if( $incluster ) { - $clusters[$cidx][1]++; - } - else { // Create a "cluster" of one - $cidx++; - $clusters[$cidx][0] = $i; - $clusters[$cidx][1] = 1; - } + if( $q1==2 && $q2==1 && $a2 > (180-15)*M_PI/180 ) { + $clusters[$cidx][1]++; + $i++; + } - /* - if( true ) { - // Debug printout in labels - for( $i=0; $i <= $cidx; ++$i ) { - for( $j=0; $j < $clusters[$i][1]; ++$j ) { - $a = $this->la[$clusters[$i][0]+$j]; - $aa = round($a*180/M_PI); - $q = $this->Quadrant($a); - $this->labels[$clusters[$i][0]+$j]="[$q:$aa] $i:$j"; - } - } - } - */ + $incluster = false; + } + } + elseif( $q1 == $q2) { + $incluster = true; + // Now we have a special case for quadrant 0. If we previously + // have a cluster of one in quadrant 0 we just extend that + // cluster. If we don't do this then we risk that the label + // for the cluster of one will cross the guide-line + if( $q1 == 0 && $cidx > -1 && + $clusters[$cidx][1] == 1 && + $this->Quadrant($this->la[$clusters[$cidx][0]]) == 0 ) { + $clusters[$cidx][1]++; + } + else { + $cidx++; + $clusters[$cidx][0] = $i; + $clusters[$cidx][1] = 1; + } + } + else { + // Create a "cluster" of one since we are just crossing + // a quadrant + $cidx++; + $clusters[$cidx][0] = $i; + $clusters[$cidx][1] = 1; + } + } + else { + if( $incluster ) { + // Add the last slice + $clusters[$cidx][1]++; + $incluster = false; + } + else { // Create a "cluster" of one + $cidx++; + $clusters[$cidx][0] = $i; + $clusters[$cidx][1] = 1; + } + } + } + // Handle the very last slice + if( $incluster ) { + $clusters[$cidx][1]++; + } + else { // Create a "cluster" of one + $cidx++; + $clusters[$cidx][0] = $i; + $clusters[$cidx][1] = 1; + } - //----------------------------------------------------------------------- - // Step 2 of the algorithm is use the clusters and draw the labels - // and guidelines - //----------------------------------------------------------------------- + /* + if( true ) { + // Debug printout in labels + for( $i=0; $i <= $cidx; ++$i ) { + for( $j=0; $j < $clusters[$i][1]; ++$j ) { + $a = $this->la[$clusters[$i][0]+$j]; + $aa = round($a*180/M_PI); + $q = $this->Quadrant($a); + $this->labels[$clusters[$i][0]+$j]="[$q:$aa] $i:$j"; + } + } + } + */ - // We use the font height as the base factor for how far we need to - // spread the labels in the Y-direction. - $this->value->ApplyFont($img); - $fh = $img->GetFontHeight(); - $origvstep=$fh*$this->iGuideVFactor; - $this->value->SetMargin(0); + //----------------------------------------------------------------------- + // Step 2 of the algorithm is use the clusters and draw the labels + // and guidelines + //----------------------------------------------------------------------- - // Number of clusters found - $nc = count($clusters); + // We use the font height as the base factor for how far we need to + // spread the labels in the Y-direction. + $this->value->ApplyFont($img); + $fh = $img->GetFontHeight(); + $origvstep=$fh*$this->iGuideVFactor; + $this->value->SetMargin(0); - // Walk through all the clusters - for($i=0; $i < $nc; ++$i) { + // Number of clusters found + $nc = count($clusters); - // Start angle and number of slices in this cluster - $csize = $clusters[$i][1]; - $a = $this->la[$clusters[$i][0]]; - $q = $this->Quadrant($a); + // Walk through all the clusters + for($i=0; $i < $nc; ++$i) { - // Now set up the start and end conditions to make sure that - // in each cluster we walk through the all the slices starting with the slice - // closest to the equator. Since all slices are numbered clockwise from "3'a clock" - // we have different conditions depending on in which quadrant the slice lies within. - if( $q == 0 ) { - $start = $csize-1; $idx = $start; $step = -1; $vstep = -$origvstep; - } - elseif( $q == 1 ) { - $start = 0; $idx = $start; $step = 1; $vstep = -$origvstep; - } - elseif( $q == 2 ) { - $start = $csize-1; $idx = $start; $step = -1; $vstep = $origvstep; - } - elseif( $q == 3 ) { - $start = 0; $idx = $start; $step = 1; $vstep = $origvstep; - } + // Start angle and number of slices in this cluster + $csize = $clusters[$i][1]; + $a = $this->la[$clusters[$i][0]]; + $q = $this->Quadrant($a); - // Walk through all slices within this cluster - for($j=0; $j < $csize; ++$j) { - // Now adjust the position of the labels in each cluster starting - // with the slice that is closest to the equator of the pie - $a = $this->la[$clusters[$i][0]+$idx]; - - // Guide line start in the center of the arc of the slice - $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)]; - $x = round($r*cos($a)+$xc); - $y = round($yc-$r*sin($a)); - - // The distance from the arc depends on chosen font and the "R-Factor" - $r += $fh*$this->iGuideLineRFactor; + // Now set up the start and end conditions to make sure that + // in each cluster we walk through the all the slices starting with the slice + // closest to the equator. Since all slices are numbered clockwise from "3'a clock" + // we have different conditions depending on in which quadrant the slice lies within. + if( $q == 0 ) { + $start = $csize-1; $idx = $start; $step = -1; $vstep = -$origvstep; + } + elseif( $q == 1 ) { + $start = 0; $idx = $start; $step = 1; $vstep = -$origvstep; + } + elseif( $q == 2 ) { + $start = $csize-1; $idx = $start; $step = -1; $vstep = $origvstep; + } + elseif( $q == 3 ) { + $start = 0; $idx = $start; $step = 1; $vstep = $origvstep; + } - // Should the labels be placed curved along the pie or in straight columns - // outside the pie? - if( $this->iGuideLineCurve ) - $xt=round($r*cos($a)+$xc); + // Walk through all slices within this cluster + for($j=0; $j < $csize; ++$j) { + // Now adjust the position of the labels in each cluster starting + // with the slice that is closest to the equator of the pie + $a = $this->la[$clusters[$i][0]+$idx]; - // If this is the first slice in the cluster we need some first time - // proessing - if( $idx == $start ) { - if( ! $this->iGuideLineCurve ) - $xt=round($r*cos($a)+$xc); - $yt=round($yc-$r*sin($a)); + // Guide line start in the center of the arc of the slice + $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)]; + $x = round($r*cos($a)+$xc); + $y = round($yc-$r*sin($a)); - // Some special consideration in case this cluster starts - // in quadrant 1 or 3 very close to the "equator" (< 20 degrees) - // and the previous clusters last slice is within the tolerance. - // In that case we add a font height to this labels Y-position - // so it doesn't collide with - // the slice in the previous cluster - $prevcluster = ($i + ($nc-1) ) % $nc; - $previdx=$clusters[$prevcluster][0]+$clusters[$prevcluster][1]-1; - if( $q == 1 && $a > 160*M_PI/180 ) { - // Get the angle for the previous clusters last slice - $diff = abs($a-$this->la[$previdx]); - if( $diff < $tresh_hold ) { - $yt -= $fh; - } - } - elseif( $q == 3 && $a > 340*M_PI/180 ) { - // We need to subtract 360 to compare angle distance between - // q=0 and q=3 - $diff = abs($a-$this->la[$previdx]-360*M_PI/180); - if( $diff < $tresh_hold ) { - $yt += $fh; - } - } + // The distance from the arc depends on chosen font and the "R-Factor" + $r += $fh*$this->iGuideLineRFactor; - } - else { - // The step is at minimum $vstep but if the slices are relatively large - // we make sure that we add at least a step that corresponds to the vertical - // distance between the centers at the arc on the slice - $prev_a = $this->la[$clusters[$i][0]+($idx-$step)]; - $dy = abs($radius*(sin($a)-sin($prev_a))*1.2); - if( $vstep > 0 ) - $yt += max($vstep,$dy); - else - $yt += min($vstep,-$dy); - } + // Should the labels be placed curved along the pie or in straight columns + // outside the pie? + if( $this->iGuideLineCurve ) + $xt=round($r*cos($a)+$xc); - $label = $this->labels[$clusters[$i][0]+$idx]; + // If this is the first slice in the cluster we need some first time + // proessing + if( $idx == $start ) { + if( ! $this->iGuideLineCurve ) + $xt=round($r*cos($a)+$xc); + $yt=round($yc-$r*sin($a)); - if( $csize == 1 ) { - // A "meta" cluster with only one slice - $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)]; - $rr = $r+$img->GetFontHeight()/2; - $xt=round($rr*cos($a)+$xc); - $yt=round($yc-$rr*sin($a)); - $this->StrokeLabel($label,$img,$xc,$yc,$a,$r); - if( $this->iShowGuideLineForSingle ) - $this->guideline->Stroke($img,$x,$y,$xt,$yt); - } - else { - $this->guideline->Stroke($img,$x,$y,$xt,$yt); - if( $q==1 || $q==2 ) { - // Left side of Pie - $this->guideline->Stroke($img,$xt,$yt,$xt-$this->guidelinemargin,$yt); - $lbladj = -$this->guidelinemargin-5; - $this->value->halign = "right"; - $this->value->valign = "center"; - } - else { - // Right side of pie - $this->guideline->Stroke($img,$xt,$yt,$xt+$this->guidelinemargin,$yt); - $lbladj = $this->guidelinemargin+5; - $this->value->halign = "left"; - $this->value->valign = "center"; - } - $this->value->Stroke($img,$label,$xt+$lbladj,$yt); - } + // Some special consideration in case this cluster starts + // in quadrant 1 or 3 very close to the "equator" (< 20 degrees) + // and the previous clusters last slice is within the tolerance. + // In that case we add a font height to this labels Y-position + // so it doesn't collide with + // the slice in the previous cluster + $prevcluster = ($i + ($nc-1) ) % $nc; + $previdx=$clusters[$prevcluster][0]+$clusters[$prevcluster][1]-1; + if( $q == 1 && $a > 160*M_PI/180 ) { + // Get the angle for the previous clusters last slice + $diff = abs($a-$this->la[$previdx]); + if( $diff < $tresh_hold ) { + $yt -= $fh; + } + } + elseif( $q == 3 && $a > 340*M_PI/180 ) { + // We need to subtract 360 to compare angle distance between + // q=0 and q=3 + $diff = abs($a-$this->la[$previdx]-360*M_PI/180); + if( $diff < $tresh_hold ) { + $yt += $fh; + } + } - // Udate idx to point to next slice in the cluster to process - $idx += $step; - } - } + } + else { + // The step is at minimum $vstep but if the slices are relatively large + // we make sure that we add at least a step that corresponds to the vertical + // distance between the centers at the arc on the slice + $prev_a = $this->la[$clusters[$i][0]+($idx-$step)]; + $dy = abs($radius*(sin($a)-sin($prev_a))*1.2); + if( $vstep > 0 ) + $yt += max($vstep,$dy); + else + $yt += min($vstep,-$dy); + } + + $label = $this->labels[$clusters[$i][0]+$idx]; + + if( $csize == 1 ) { + // A "meta" cluster with only one slice + $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)]; + $rr = $r+$img->GetFontHeight()/2; + $xt=round($rr*cos($a)+$xc); + $yt=round($yc-$rr*sin($a)); + $this->StrokeLabel($label,$img,$xc,$yc,$a,$r); + if( $this->iShowGuideLineForSingle ) + $this->guideline->Stroke($img,$x,$y,$xt,$yt); + } + else { + $this->guideline->Stroke($img,$x,$y,$xt,$yt); + if( $q==1 || $q==2 ) { + // Left side of Pie + $this->guideline->Stroke($img,$xt,$yt,$xt-$this->guidelinemargin,$yt); + $lbladj = -$this->guidelinemargin-5; + $this->value->halign = "right"; + $this->value->valign = "center"; + } + else { + // Right side of pie + $this->guideline->Stroke($img,$xt,$yt,$xt+$this->guidelinemargin,$yt); + $lbladj = $this->guidelinemargin+5; + $this->value->halign = "left"; + $this->value->valign = "center"; + } + $this->value->Stroke($img,$label,$xt+$lbladj,$yt); + } + + // Udate idx to point to next slice in the cluster to process + $idx += $step; + } + } } function StrokeAllLabels($img,$xc,$yc,$radius) { - // First normalize all angles for labels - $n = count($this->la); - for($i=0; $i < $n; ++$i) { - $this->la[$i] = $this->NormAngle($this->la[$i]); - } - if( $this->guideline->iShow ) { - $this->StrokeGuideLabels($img,$xc,$yc,$radius); - } - else { - $n = count($this->labels); - for($i=0; $i < $n; ++$i) { - $this->StrokeLabel($this->labels[$i],$img,$xc,$yc, - $this->la[$i], - $radius + $this->explode_radius[$n-1-$i]); - } - } + // First normalize all angles for labels + $n = count($this->la); + for($i=0; $i < $n; ++$i) { + $this->la[$i] = $this->NormAngle($this->la[$i]); + } + if( $this->guideline->iShow ) { + $this->StrokeGuideLabels($img,$xc,$yc,$radius); + } + else { + $n = count($this->labels); + for($i=0; $i < $n; ++$i) { + $this->StrokeLabel($this->labels[$i],$img,$xc,$yc, + $this->la[$i], + $radius + $this->explode_radius[$n-1-$i]); + } + } } // Position the labels of each slice function StrokeLabel($label,$img,$xc,$yc,$a,$r) { - // Default value - if( $this->ilabelposadj === 'auto' ) - $this->ilabelposadj = 0.65; + // Default value + if( $this->ilabelposadj === 'auto' ) + $this->ilabelposadj = 0.65; - // We position the values diferently depending on if they are inside - // or outside the pie - if( $this->ilabelposadj < 1.0 ) { + // We position the values diferently depending on if they are inside + // or outside the pie + if( $this->ilabelposadj < 1.0 ) { - $this->value->SetAlign('center','center'); - $this->value->margin = 0; - - $xt=round($this->ilabelposadj*$r*cos($a)+$xc); - $yt=round($yc-$this->ilabelposadj*$r*sin($a)); - - $this->value->Stroke($img,$label,$xt,$yt); - } - else { + $this->value->SetAlign('center','center'); + $this->value->margin = 0; - $this->value->halign = "left"; - $this->value->valign = "top"; - $this->value->margin = 0; - - // Position the axis title. - // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text - // that intersects with the extension of the corresponding axis. The code looks a little - // bit messy but this is really the only way of having a reasonable position of the - // axis titles. - $this->value->ApplyFont($img); - $h=$img->GetTextHeight($label); - // For numeric values the format of the display value - // must be taken into account - if( is_numeric($label) ) { - if( $label > 0 ) - $w=$img->GetTextWidth(sprintf($this->value->format,$label)); - else - $w=$img->GetTextWidth(sprintf($this->value->negformat,$label)); - } - else - $w=$img->GetTextWidth($label); + $xt=round($this->ilabelposadj*$r*cos($a)+$xc); + $yt=round($yc-$this->ilabelposadj*$r*sin($a)); - if( $this->ilabelposadj > 1.0 && $this->ilabelposadj < 5.0) { - $r *= $this->ilabelposadj; - } - - $r += $img->GetFontHeight()/1.5; + $this->value->Stroke($img,$label,$xt,$yt); + } + else { - $xt=round($r*cos($a)+$xc); - $yt=round($yc-$r*sin($a)); + $this->value->halign = "left"; + $this->value->valign = "top"; + $this->value->margin = 0; - // Normalize angle - while( $a < 0 ) $a += 2*M_PI; - while( $a > 2*M_PI ) $a -= 2*M_PI; + // Position the axis title. + // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text + // that intersects with the extension of the corresponding axis. The code looks a little + // bit messy but this is really the only way of having a reasonable position of the + // axis titles. + $this->value->ApplyFont($img); + $h=$img->GetTextHeight($label); + // For numeric values the format of the display value + // must be taken into account + if( is_numeric($label) ) { + if( $label > 0 ) + $w=$img->GetTextWidth(sprintf($this->value->format,$label)); + else + $w=$img->GetTextWidth(sprintf($this->value->negformat,$label)); + } + else + $w=$img->GetTextWidth($label); - if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0; - if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI; - if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1; - if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI); - - if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI; - if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI); - if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1; - if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI); - if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0; - - $this->value->Stroke($img,$label,$xt-$dx*$w,$yt-$dy*$h); - } - } + if( $this->ilabelposadj > 1.0 && $this->ilabelposadj < 5.0) { + $r *= $this->ilabelposadj; + } + + $r += $img->GetFontHeight()/1.5; + + $xt=round($r*cos($a)+$xc); + $yt=round($yc-$r*sin($a)); + + // Normalize angle + while( $a < 0 ) $a += 2*M_PI; + while( $a > 2*M_PI ) $a -= 2*M_PI; + + if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0; + if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI; + if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1; + if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI); + + if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI; + if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI); + if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1; + if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI); + if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0; + + $this->value->Stroke($img,$label,$xt-$dx*$w,$yt-$dy*$h); + } + } } // Class //=================================================== // CLASS PiePlotC -// Description: Same as a normal pie plot but with a +// Description: Same as a normal pie plot but with a // filled circle in the center //=================================================== class PiePlotC extends PiePlot { - private $imidsize=0.5; // Fraction of total width + private $imidsize=0.5; // Fraction of total width private $imidcolor='white'; public $midtitle=''; private $middlecsimtarget='',$middlecsimwintarget='',$middlecsimalt=''; - function PiePlotC($data,$aCenterTitle='') { - parent::PiePlot($data); - $this->midtitle = new Text(); - $this->midtitle->ParagraphAlign('center'); + function __construct($data,$aCenterTitle='') { + parent::__construct($data); + $this->midtitle = new Text(); + $this->midtitle->ParagraphAlign('center'); } function SetMid($aTitle,$aColor='white',$aSize=0.5) { - $this->midtitle->Set($aTitle); + $this->midtitle->Set($aTitle); - $this->imidsize = $aSize ; - $this->imidcolor = $aColor ; + $this->imidsize = $aSize ; + $this->imidcolor = $aColor ; } function SetMidTitle($aTitle) { - $this->midtitle->Set($aTitle); + $this->midtitle->Set($aTitle); } function SetMidSize($aSize) { - $this->imidsize = $aSize ; + $this->imidsize = $aSize ; } function SetMidColor($aColor) { - $this->imidcolor = $aColor ; + $this->imidcolor = $aColor ; } function SetMidCSIM($aTarget,$aAlt='',$aWinTarget='') { - $this->middlecsimtarget = $aTarget; - $this->middlecsimwintarget = $aWinTarget; - $this->middlecsimalt = $aAlt; + $this->middlecsimtarget = $aTarget; + $this->middlecsimwintarget = $aWinTarget; + $this->middlecsimalt = $aAlt; } - function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) { + function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) { //Slice number, ellipse centre (x,y), radius, start angle, end angle - while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI; - while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI; + while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI; + while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI; - $sa = 2*M_PI - $sa; - $ea = 2*M_PI - $ea; + $sa = 2*M_PI - $sa; + $ea = 2*M_PI - $ea; - // Special case when we have only one slice since then both start and end - // angle will be == 0 - if( abs($sa - $ea) < 0.0001 ) { - $sa=2*M_PI; $ea=0; - } + // Special case when we have only one slice since then both start and end + // angle will be == 0 + if( abs($sa - $ea) < 0.0001 ) { + $sa=2*M_PI; $ea=0; + } - // Add inner circle first point - $xp = floor(($this->imidsize*$radius*cos($ea))+$xc); - $yp = floor($yc-($this->imidsize*$radius*sin($ea))); - $coords = "$xp, $yp"; - - //add coordinates every 0.25 radians - $a=$ea+0.25; + // Add inner circle first point + $xp = floor(($this->imidsize*$radius*cos($ea))+$xc); + $yp = floor($yc-($this->imidsize*$radius*sin($ea))); + $coords = "$xp, $yp"; - // If we cross the 360-limit with a slice we need to handle - // the fact that end angle is smaller than start - if( $sa < $ea ) { - while ($a <= 2*M_PI) { - $xp = floor($radius*cos($a)+$xc); - $yp = floor($yc-$radius*sin($a)); - $coords.= ", $xp, $yp"; - $a += 0.25; - } - $a -= 2*M_PI; - } + //add coordinates every 0.25 radians + $a=$ea+0.25; - while ($a < $sa) { - $xp = floor(($this->imidsize*$radius*cos($a)+$xc)); - $yp = floor($yc-($this->imidsize*$radius*sin($a))); - $coords.= ", $xp, $yp"; - $a += 0.25; - } + // If we cross the 360-limit with a slice we need to handle + // the fact that end angle is smaller than start + if( $sa < $ea ) { + while ($a <= 2*M_PI) { + $xp = floor($radius*cos($a)+$xc); + $yp = floor($yc-$radius*sin($a)); + $coords.= ", $xp, $yp"; + $a += 0.25; + } + $a -= 2*M_PI; + } - // Make sure we end at the last point - $xp = floor(($this->imidsize*$radius*cos($sa)+$xc)); - $yp = floor($yc-($this->imidsize*$radius*sin($sa))); - $coords.= ", $xp, $yp"; + while ($a < $sa) { + $xp = floor(($this->imidsize*$radius*cos($a)+$xc)); + $yp = floor($yc-($this->imidsize*$radius*sin($a))); + $coords.= ", $xp, $yp"; + $a += 0.25; + } - // Straight line to outer circle - $xp = floor($radius*cos($sa)+$xc); - $yp = floor($yc-$radius*sin($sa)); - $coords.= ", $xp, $yp"; + // Make sure we end at the last point + $xp = floor(($this->imidsize*$radius*cos($sa)+$xc)); + $yp = floor($yc-($this->imidsize*$radius*sin($sa))); + $coords.= ", $xp, $yp"; - //add coordinates every 0.25 radians - $a=$sa - 0.25; - while ($a > $ea) { - $xp = floor($radius*cos($a)+$xc); - $yp = floor($yc-$radius*sin($a)); - $coords.= ", $xp, $yp"; - $a -= 0.25; - } - - //Add the last point on the arc - $xp = floor($radius*cos($ea)+$xc); - $yp = floor($yc-$radius*sin($ea)); - $coords.= ", $xp, $yp"; + // Straight line to outer circle + $xp = floor($radius*cos($sa)+$xc); + $yp = floor($yc-$radius*sin($sa)); + $coords.= ", $xp, $yp"; - // Close the arc - $xp = floor(($this->imidsize*$radius*cos($ea))+$xc); - $yp = floor($yc-($this->imidsize*$radius*sin($ea))); - $coords .= ", $xp, $yp"; + //add coordinates every 0.25 radians + $a=$sa - 0.25; + while ($a > $ea) { + $xp = floor($radius*cos($a)+$xc); + $yp = floor($yc-$radius*sin($a)); + $coords.= ", $xp, $yp"; + $a -= 0.25; + } - if( !empty($this->csimtargets[$i]) ) { - $this->csimareas .= "csimtargets[$i]."\""; - if( !empty($this->csimwintargets[$i]) ) { - $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; - } - if( !empty($this->csimalts[$i]) ) { - $tmp=sprintf($this->csimalts[$i],$this->data[$i]); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; - } + //Add the last point on the arc + $xp = floor($radius*cos($ea)+$xc); + $yp = floor($yc-$radius*sin($ea)); + $coords.= ", $xp, $yp"; + + // Close the arc + $xp = floor(($this->imidsize*$radius*cos($ea))+$xc); + $yp = floor($yc-($this->imidsize*$radius*sin($ea))); + $coords .= ", $xp, $yp"; + + if( !empty($this->csimtargets[$i]) ) { + $this->csimareas .= "csimtargets[$i]."\""; + if( !empty($this->csimwintargets[$i]) ) { + $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; + } + if( !empty($this->csimalts[$i]) ) { + $tmp=sprintf($this->csimalts[$i],$this->data[$i]); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } } function Stroke($img,$aaoption=0) { - // Stroke the pie but don't stroke values - $tmp = $this->value->show; - $this->value->show = false; - parent::Stroke($img,$aaoption); - $this->value->show = $tmp; + // Stroke the pie but don't stroke values + $tmp = $this->value->show; + $this->value->show = false; + parent::Stroke($img,$aaoption); + $this->value->show = $tmp; - $xc = round($this->posx*$img->width); - $yc = round($this->posy*$img->height); + $xc = round($this->posx*$img->width); + $yc = round($this->posy*$img->height); - $radius = floor($this->radius * min($img->width,$img->height)) ; + $radius = floor($this->radius * min($img->width,$img->height)) ; - if( $this->imidsize > 0 && $aaoption !== 2 ) { + if( $this->imidsize > 0 && $aaoption !== 2 ) { - if( $this->ishadowcolor != "" ) { - $img->SetColor($this->ishadowcolor); - $img->FilledCircle($xc+$this->ishadowdrop,$yc+$this->ishadowdrop, - round($radius*$this->imidsize)); - } + if( $this->ishadowcolor != "" ) { + $img->SetColor($this->ishadowcolor); + $img->FilledCircle($xc+$this->ishadowdrop,$yc+$this->ishadowdrop, + round($radius*$this->imidsize)); + } - $img->SetColor($this->imidcolor); - $img->FilledCircle($xc,$yc,round($radius*$this->imidsize)); + $img->SetColor($this->imidcolor); + $img->FilledCircle($xc,$yc,round($radius*$this->imidsize)); - if( $this->pie_border && $aaoption === 0 ) { - $img->SetColor($this->color); - $img->Circle($xc,$yc,round($radius*$this->imidsize)); - } + if( $this->pie_border && $aaoption === 0 ) { + $img->SetColor($this->color); + $img->Circle($xc,$yc,round($radius*$this->imidsize)); + } - if( !empty($this->middlecsimtarget) ) - $this->AddMiddleCSIM($xc,$yc,round($radius*$this->imidsize)); + if( !empty($this->middlecsimtarget) ) + $this->AddMiddleCSIM($xc,$yc,round($radius*$this->imidsize)); - } + } - if( $this->value->show && $aaoption !== 1) { - $this->StrokeAllLabels($img,$xc,$yc,$radius); - $this->midtitle->SetPos($xc,$yc,'center','center'); - $this->midtitle->Stroke($img); - } + if( $this->value->show && $aaoption !== 1) { + $this->StrokeAllLabels($img,$xc,$yc,$radius); + $this->midtitle->SetPos($xc,$yc,'center','center'); + $this->midtitle->Stroke($img); + } } function AddMiddleCSIM($xc,$yc,$r) { - $xc=round($xc);$yc=round($yc);$r=round($r); - $this->csimareas .= "middlecsimtarget."\""; - if( !empty($this->middlecsimwintarget) ) { - $this->csimareas .= " target=\"".$this->middlecsimwintarget."\""; - } - if( !empty($this->middlecsimalt) ) { - $tmp = $this->middlecsimalt; - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; + $xc=round($xc);$yc=round($yc);$r=round($r); + $this->csimareas .= "middlecsimtarget."\""; + if( !empty($this->middlecsimwintarget) ) { + $this->csimareas .= " target=\"".$this->middlecsimwintarget."\""; + } + if( !empty($this->middlecsimalt) ) { + $tmp = $this->middlecsimalt; + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; } function StrokeLabel($label,$img,$xc,$yc,$a,$r) { - if( $this->ilabelposadj === 'auto' ) - $this->ilabelposadj = (1-$this->imidsize)/2+$this->imidsize; + if( $this->ilabelposadj === 'auto' ) + $this->ilabelposadj = (1-$this->imidsize)/2+$this->imidsize; - parent::StrokeLabel($label,$img,$xc,$yc,$a,$r); + parent::StrokeLabel($label,$img,$xc,$yc,$a,$r); } @@ -1204,234 +1205,241 @@ class PiePlotC extends PiePlot { //=================================================== // CLASS PieGraph -// Description: +// Description: //=================================================== class PieGraph extends Graph { - private $posx, $posy, $radius; - private $legends=array(); + private $posx, $posy, $radius; + private $legends=array(); public $plots=array(); public $pieaa = false ; -//--------------- -// CONSTRUCTOR - function PieGraph($width=300,$height=200,$cachedName="",$timeout=0,$inline=1) { - $this->Graph($width,$height,$cachedName,$timeout,$inline); - $this->posx=$width/2; - $this->posy=$height/2; - $this->SetColor(array(255,255,255)); + //--------------- + // CONSTRUCTOR + function __construct($width=300,$height=200,$cachedName="",$timeout=0,$inline=1) { + parent::__construct($width,$height,$cachedName,$timeout,$inline); + $this->posx=$width/2; + $this->posy=$height/2; + $this->SetColor(array(255,255,255)); } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function Add($aObj) { - if( is_array($aObj) && count($aObj) > 0 ) - $cl = $aObj[0]; - else - $cl = $aObj; + if( is_array($aObj) && count($aObj) > 0 ) + $cl = $aObj[0]; + else + $cl = $aObj; - if( $cl instanceof Text ) - $this->AddText($aObj); - elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) - $this->AddIcon($aObj); - else { - if( is_array($aObj) ) { - $n = count($aObj); - for($i=0; $i < $n; ++$i ) { - $this->plots[] = $aObj[$i]; - } - } - else { - $this->plots[] = $aObj; - } - } + if( $cl instanceof Text ) + $this->AddText($aObj); + elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) + $this->AddIcon($aObj); + else { + if( is_array($aObj) ) { + $n = count($aObj); + for($i=0; $i < $n; ++$i ) { + $this->plots[] = $aObj[$i]; + } + } + else { + $this->plots[] = $aObj; + } + } } function SetAntiAliasing($aFlg=true) { - $this->pieaa = $aFlg; + $this->pieaa = $aFlg; } - + function SetColor($c) { - $this->SetMarginColor($c); + $this->SetMarginColor($c); } function DisplayCSIMAreas() { - $csim=""; - foreach($this->plots as $p ) { - $csim .= $p->GetCSIMareas(); - } - //$csim.= $this->legend->GetCSIMareas(); - if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) { - $this->img->SetColor($this->csimcolor); - $n = count($coords[0]); - for ($i=0; $i < $n; $i++) { - if ($coords[1][$i]=="poly") { - preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts); - $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]); - $m = count($pts[0]); - for ($j=0; $j < $m; $j++) { - $this->img->LineTo($pts[1][$j],$pts[2][$j]); - } - } else if ($coords[1][$i]=="rect") { - $pts = preg_split('/,/', $coords[2][$i]); - $this->img->SetStartPoint($pts[0],$pts[1]); - $this->img->LineTo($pts[2],$pts[1]); - $this->img->LineTo($pts[2],$pts[3]); - $this->img->LineTo($pts[0],$pts[3]); - $this->img->LineTo($pts[0],$pts[1]); - - } - } - } + $csim=""; + foreach($this->plots as $p ) { + $csim .= $p->GetCSIMareas(); + } + //$csim.= $this->legend->GetCSIMareas(); + if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) { + $this->img->SetColor($this->csimcolor); + $n = count($coords[0]); + for ($i=0; $i < $n; $i++) { + if ($coords[1][$i]=="poly") { + preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts); + $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]); + $m = count($pts[0]); + for ($j=0; $j < $m; $j++) { + $this->img->LineTo($pts[1][$j],$pts[2][$j]); + } + } else if ($coords[1][$i]=="rect") { + $pts = preg_split('/,/', $coords[2][$i]); + $this->img->SetStartPoint($pts[0],$pts[1]); + $this->img->LineTo($pts[2],$pts[1]); + $this->img->LineTo($pts[2],$pts[3]); + $this->img->LineTo($pts[0],$pts[3]); + $this->img->LineTo($pts[0],$pts[1]); + + } + } + } } // Method description function Stroke($aStrokeFileName="") { - // If the filename is the predefined value = '_csim_special_' - // we assume that the call to stroke only needs to do enough - // to correctly generate the CSIM maps. - // We use this variable to skip things we don't strictly need - // to do to generate the image map to improve performance - // a best we can. Therefor you will see a lot of tests !$_csim in the - // code below. - $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE); + // If the filename is the predefined value = '_csim_special_' + // we assume that the call to stroke only needs to do enough + // to correctly generate the CSIM maps. + // We use this variable to skip things we don't strictly need + // to do to generate the image map to improve performance + // a best we can. Therefor you will see a lot of tests !$_csim in the + // code below. + $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE); - // We need to know if we have stroked the plot in the - // GetCSIMareas. Otherwise the CSIM hasn't been generated - // and in the case of GetCSIM called before stroke to generate - // CSIM without storing an image to disk GetCSIM must call Stroke. - $this->iHasStroked = true; + // If we are called the second time (perhaps the user has called GetHTMLImageMap() + // himself then the legends have alsready been populated once in order to get the + // CSIM coordinats. Since we do not want the legends to be populated a second time + // we clear the legends + $this->legend->Clear(); - $n = count($this->plots); + // We need to know if we have stroked the plot in the + // GetCSIMareas. Otherwise the CSIM hasn't been generated + // and in the case of GetCSIM called before stroke to generate + // CSIM without storing an image to disk GetCSIM must call Stroke. + $this->iHasStroked = true; - if( $this->pieaa ) { + $n = count($this->plots); - if( !$_csim ) { - if( $this->background_image != "" ) { - $this->StrokeFrameBackground(); - } - else { - $this->StrokeFrame(); - $this->StrokeBackgroundGrad(); - } - } + if( $this->pieaa ) { + + if( !$_csim ) { + if( $this->background_image != "" ) { + $this->StrokeFrameBackground(); + } + else { + $this->StrokeFrame(); + $this->StrokeBackgroundGrad(); + } + } - $w = $this->img->width; - $h = $this->img->height; - $oldimg = $this->img->img; + $w = $this->img->width; + $h = $this->img->height; + $oldimg = $this->img->img; - $this->img->CreateImgCanvas(2*$w,2*$h); - - $this->img->SetColor( $this->margin_color ); - $this->img->FilledRectangle(0,0,2*$w-1,2*$h-1); + $this->img->CreateImgCanvas(2*$w,2*$h); - // Make all icons *2 i size since we will be scaling down the - // imahe to do the anti aliasing - $ni = count($this->iIcons); - for($i=0; $i < $ni; ++$i) { - $this->iIcons[$i]->iScale *= 2 ; - if( $this->iIcons[$i]->iX > 1 ) - $this->iIcons[$i]->iX *= 2 ; - if( $this->iIcons[$i]->iY > 1 ) - $this->iIcons[$i]->iY *= 2 ; - } + $this->img->SetColor( $this->margin_color ); + $this->img->FilledRectangle(0,0,2*$w-1,2*$h-1); - $this->StrokeIcons(); + // Make all icons *2 i size since we will be scaling down the + // imahe to do the anti aliasing + $ni = count($this->iIcons); + for($i=0; $i < $ni; ++$i) { + $this->iIcons[$i]->iScale *= 2 ; + if( $this->iIcons[$i]->iX > 1 ) + $this->iIcons[$i]->iX *= 2 ; + if( $this->iIcons[$i]->iY > 1 ) + $this->iIcons[$i]->iY *= 2 ; + } - for($i=0; $i < $n; ++$i) { - if( $this->plots[$i]->posx > 1 ) - $this->plots[$i]->posx *= 2 ; - if( $this->plots[$i]->posy > 1 ) - $this->plots[$i]->posy *= 2 ; + $this->StrokeIcons(); - $this->plots[$i]->Stroke($this->img,1); + for($i=0; $i < $n; ++$i) { + if( $this->plots[$i]->posx > 1 ) + $this->plots[$i]->posx *= 2 ; + if( $this->plots[$i]->posy > 1 ) + $this->plots[$i]->posy *= 2 ; - if( $this->plots[$i]->posx > 1 ) - $this->plots[$i]->posx /= 2 ; - if( $this->plots[$i]->posy > 1 ) - $this->plots[$i]->posy /= 2 ; - } + $this->plots[$i]->Stroke($this->img,1); - $indent = $this->doframe ? ($this->frame_weight + ($this->doshadow ? $this->shadow_width : 0 )) : 0 ; - $indent += $this->framebevel ? $this->framebeveldepth + 1 : 0 ; - $this->img->CopyCanvasH($oldimg,$this->img->img,$indent,$indent,$indent,$indent, - $w-2*$indent,$h-2*$indent,2*($w-$indent),2*($h-$indent)); + if( $this->plots[$i]->posx > 1 ) + $this->plots[$i]->posx /= 2 ; + if( $this->plots[$i]->posy > 1 ) + $this->plots[$i]->posy /= 2 ; + } - $this->img->img = $oldimg ; - $this->img->width = $w ; - $this->img->height = $h ; + $indent = $this->doframe ? ($this->frame_weight + ($this->doshadow ? $this->shadow_width : 0 )) : 0 ; + $indent += $this->framebevel ? $this->framebeveldepth + 1 : 0 ; + $this->img->CopyCanvasH($oldimg,$this->img->img,$indent,$indent,$indent,$indent, + $w-2*$indent,$h-2*$indent,2*($w-$indent),2*($h-$indent)); - for($i=0; $i < $n; ++$i) { - $this->plots[$i]->Stroke($this->img,2); // Stroke labels - $this->plots[$i]->Legend($this); - } + $this->img->img = $oldimg ; + $this->img->width = $w ; + $this->img->height = $h ; - } - else { + for($i=0; $i < $n; ++$i) { + $this->plots[$i]->Stroke($this->img,2); // Stroke labels + $this->plots[$i]->Legend($this); + } - if( !$_csim ) { - if( $this->background_image != "" ) { - $this->StrokeFrameBackground(); - } - else { - $this->StrokeFrame(); - } - } + } + else { - $this->StrokeIcons(); + if( !$_csim ) { + if( $this->background_image != "" ) { + $this->StrokeFrameBackground(); + } + else { + $this->StrokeFrame(); + $this->StrokeBackgroundGrad(); + } + } - for($i=0; $i < $n; ++$i) { - $this->plots[$i]->Stroke($this->img); - $this->plots[$i]->Legend($this); - } - } + $this->StrokeIcons(); - $this->legend->Stroke($this->img); - $this->footer->Stroke($this->img); - $this->StrokeTitles(); + for($i=0; $i < $n; ++$i) { + $this->plots[$i]->Stroke($this->img); + $this->plots[$i]->Legend($this); + } + } - if( !$_csim ) { + $this->legend->Stroke($this->img); + $this->footer->Stroke($this->img); + $this->StrokeTitles(); - // Stroke texts - if( $this->texts != null ) { - $n = count($this->texts); - for($i=0; $i < $n; ++$i ) { - $this->texts[$i]->Stroke($this->img); - } - } + if( !$_csim ) { - if( _JPG_DEBUG ) { - $this->DisplayCSIMAreas(); - } + // Stroke texts + if( $this->texts != null ) { + $n = count($this->texts); + for($i=0; $i < $n; ++$i ) { + $this->texts[$i]->Stroke($this->img); + } + } - // Should we do any final image transformation - if( $this->iImgTrans ) { - if( !class_exists('ImgTrans',false) ) { - require_once('jpgraph_imgtrans.php'); - //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.'); - } - - $tform = new ImgTrans($this->img->img); - $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist, - $this->iImgTransDirection,$this->iImgTransHighQ, - $this->iImgTransMinSize,$this->iImgTransFillColor, - $this->iImgTransBorder); - } + if( _JPG_DEBUG ) { + $this->DisplayCSIMAreas(); + } + + // Should we do any final image transformation + if( $this->iImgTrans ) { + if( !class_exists('ImgTrans',false) ) { + require_once('jpgraph_imgtrans.php'); + //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.'); + } + + $tform = new ImgTrans($this->img->img); + $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist, + $this->iImgTransDirection,$this->iImgTransHighQ, + $this->iImgTransMinSize,$this->iImgTransFillColor, + $this->iImgTransBorder); + } - // If the filename is given as the special "__handle" - // then the image handler is returned and the image is NOT - // streamed back - if( $aStrokeFileName == _IMG_HANDLER ) { - return $this->img->img; - } - else { - // Finally stream the generated picture - $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline, - $aStrokeFileName); - } - } + // If the filename is given as the special "__handle" + // then the image handler is returned and the image is NOT + // streamed back + if( $aStrokeFileName == _IMG_HANDLER ) { + return $this->img->img; + } + else { + // Finally stream the generated picture + $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline, + $aStrokeFileName); + } + } } } // Class diff --git a/src/classes/jpgraph/jpgraph_pie3d.php b/src/classes/jpgraph/jpgraph_pie3d.php index 8b6c1f4..45cb2b2 100644 --- a/src/classes/jpgraph/jpgraph_pie3d.php +++ b/src/classes/jpgraph/jpgraph_pie3d.php @@ -1,922 +1,932 @@ radius = 0.5; - $this->data = $data; - $this->title = new Text(""); - $this->title->SetFont(FF_FONT1,FS_BOLD); - $this->value = new DisplayValue(); - $this->value->Show(); - $this->value->SetFormat('%.0f%%'); + + //--------------- + // CONSTRUCTOR + function __construct($data) { + $this->radius = 0.5; + $this->data = $data; + $this->title = new Text(""); + $this->title->SetFont(FF_FONT1,FS_BOLD); + $this->value = new DisplayValue(); + $this->value->Show(); + $this->value->SetFormat('%.0f%%'); } -//--------------- -// PUBLIC METHODS - + //--------------- + // PUBLIC METHODS + // Set label arrays function SetLegends($aLegend) { - $this->legends = array_reverse(array_slice($aLegend,0,count($this->data))); + $this->legends = array_reverse(array_slice($aLegend,0,count($this->data))); } function SetSliceColors($aColors) { - $this->setslicecolors = $aColors; + $this->setslicecolors = $aColors; } function Legend($aGraph) { - parent::Legend($aGraph); - $aGraph->legend->txtcol = array_reverse($aGraph->legend->txtcol); + parent::Legend($aGraph); + $aGraph->legend->txtcol = array_reverse($aGraph->legend->txtcol); } function SetCSIMTargets($aTargets,$aAlts='',$aWinTargets='') { - $this->csimtargets = $aTargets; - $this->csimwintargets = $aWinTargets; - $this->csimalts = $aAlts; + $this->csimtargets = $aTargets; + $this->csimwintargets = $aWinTargets; + $this->csimalts = $aAlts; } // Should the slices be separated by a line? If color is specified as "" no line // will be used to separate pie slices. function SetEdge($aColor='black',$aWeight=1) { - $this->edgecolor = $aColor; - $this->edgeweight = $aWeight; - } - - // Dummy function to make Pie3D behave in a similair way to 2D - function ShowBorder($exterior=true,$interior=true) { - JpGraphError::RaiseL(14001); -//('Pie3D::ShowBorder() . Deprecated function. Use Pie3D::SetEdge() to control the edges around slices.'); + $this->edgecolor = $aColor; + $this->edgeweight = $aWeight; } // Specify projection angle for 3D in degrees // Must be between 20 and 70 degrees function SetAngle($a) { - if( $a<5 || $a>90 ) - JpGraphError::RaiseL(14002); -//("PiePlot3D::SetAngle() 3D Pie projection angle must be between 5 and 85 degrees."); - else - $this->angle = $a; + if( $a<5 || $a>90 ) { + JpGraphError::RaiseL(14002); + //("PiePlot3D::SetAngle() 3D Pie projection angle must be between 5 and 85 degrees."); + } + else { + $this->angle = $a; + } } function Add3DSliceToCSIM($i,$xc,$yc,$height,$width,$thick,$sa,$ea) { //Slice number, ellipse centre (x,y), height, width, start angle, end angle - $sa *= M_PI/180; - $ea *= M_PI/180; + $sa *= M_PI/180; + $ea *= M_PI/180; - //add coordinates of the centre to the map - $coords = "$xc, $yc"; + //add coordinates of the centre to the map + $coords = "$xc, $yc"; - //add coordinates of the first point on the arc to the map - $xp = floor($width*cos($sa)/2+$xc); - $yp = floor($yc-$height*sin($sa)/2); - $coords.= ", $xp, $yp"; + //add coordinates of the first point on the arc to the map + $xp = floor($width*cos($sa)/2+$xc); + $yp = floor($yc-$height*sin($sa)/2); + $coords.= ", $xp, $yp"; - //If on the front half, add the thickness offset - if ($sa >= M_PI && $sa <= 2*M_PI*1.01) { - $yp = floor($yp+$thick); - $coords.= ", $xp, $yp"; - } - - //add coordinates every 0.2 radians - $a=$sa+0.2; - while ($a<$ea) { - $xp = floor($width*cos($a)/2+$xc); - if ($a >= M_PI && $a <= 2*M_PI*1.01) { - $yp = floor($yc-($height*sin($a)/2)+$thick); - } else { - $yp = floor($yc-$height*sin($a)/2); - } - $coords.= ", $xp, $yp"; - $a += 0.2; - } - - //Add the last point on the arc - $xp = floor($width*cos($ea)/2+$xc); - $yp = floor($yc-$height*sin($ea)/2); + //If on the front half, add the thickness offset + if ($sa >= M_PI && $sa <= 2*M_PI*1.01) { + $yp = floor($yp+$thick); + $coords.= ", $xp, $yp"; + } + + //add coordinates every 0.2 radians + $a=$sa+0.2; + while ($a<$ea) { + $xp = floor($width*cos($a)/2+$xc); + if ($a >= M_PI && $a <= 2*M_PI*1.01) { + $yp = floor($yc-($height*sin($a)/2)+$thick); + } else { + $yp = floor($yc-$height*sin($a)/2); + } + $coords.= ", $xp, $yp"; + $a += 0.2; + } + + //Add the last point on the arc + $xp = floor($width*cos($ea)/2+$xc); + $yp = floor($yc-$height*sin($ea)/2); - if ($ea >= M_PI && $ea <= 2*M_PI*1.01) { - $coords.= ", $xp, ".floor($yp+$thick); - } - $coords.= ", $xp, $yp"; - $alt=''; + if ($ea >= M_PI && $ea <= 2*M_PI*1.01) { + $coords.= ", $xp, ".floor($yp+$thick); + } + $coords.= ", $xp, $yp"; + $alt=''; - if( !empty($this->csimtargets[$i]) ) { - $this->csimareas .= "csimtargets[$i]."\""; - - if( !empty($this->csimwintargets[$i]) ) { - $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; - } - - if( !empty($this->csimalts[$i]) ) { - $tmp=sprintf($this->csimalts[$i],$this->data[$i]); - $this->csimareas .= "alt=\"$tmp\" title=\"$tmp\" "; - } - $this->csimareas .= " />\n"; - } + if( !empty($this->csimtargets[$i]) ) { + $this->csimareas .= "csimtargets[$i]."\""; + + if( !empty($this->csimwintargets[$i]) ) { + $this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" "; + } + + if( !empty($this->csimalts[$i]) ) { + $tmp=sprintf($this->csimalts[$i],$this->data[$i]); + $this->csimareas .= "alt=\"$tmp\" title=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } } function SetLabels($aLabels,$aLblPosAdj="auto") { - $this->labels = $aLabels; - $this->ilabelposadj=$aLblPosAdj; + $this->labels = $aLabels; + $this->ilabelposadj=$aLblPosAdj; } - + // Distance from the pie to the labels function SetLabelMargin($m) { - $this->value->SetMargin($m); + $this->value->SetMargin($m); } - + // Show a thin line from the pie to the label for a specific slice function ShowLabelHint($f=true) { - $this->showlabelhint=$f; + $this->showlabelhint=$f; } - + // Set color of hint line to label for each slice function SetLabelHintColor($c) { - $this->labelhintcolor=$c; + $this->labelhintcolor=$c; } function SetHeight($aHeight) { - $this->iThickness = $aHeight; + $this->iThickness = $aHeight; } -// Normalize Angle between 0-360 + // Normalize Angle between 0-360 function NormAngle($a) { - // Normalize anle to 0 to 2M_PI - // - if( $a > 0 ) { - while($a > 360) $a -= 360; - } - else { - while($a < 0) $a += 360; - } - if( $a < 0 ) - $a = 360 + $a; + // Normalize anle to 0 to 2M_PI + // + if( $a > 0 ) { + while($a > 360) $a -= 360; + } + else { + while($a < 0) $a += 360; + } + if( $a < 0 ) + $a = 360 + $a; - if( $a == 360 ) $a=0; - return $a; + if( $a == 360 ) $a=0; + return $a; } - -// Draw one 3D pie slice at position ($xc,$yc) with height $z + + // Draw one 3D pie slice at position ($xc,$yc) with height $z function Pie3DSlice($img,$xc,$yc,$w,$h,$sa,$ea,$z,$fillcolor,$shadow=0.65) { - - // Due to the way the 3D Pie algorithm works we are - // guaranteed that any slice we get into this method - // belongs to either the left or right side of the - // pie ellipse. Hence, no slice will cross 90 or 270 - // point. - if( ($sa < 90 && $ea > 90) || ( ($sa > 90 && $sa < 270) && $ea > 270) ) { - JpGraphError::RaiseL(14003);//('Internal assertion failed. Pie3D::Pie3DSlice'); - exit(1); - } - $p[] = array(); + // Due to the way the 3D Pie algorithm works we are + // guaranteed that any slice we get into this method + // belongs to either the left or right side of the + // pie ellipse. Hence, no slice will cross 90 or 270 + // point. + if( ($sa < 90 && $ea > 90) || ( ($sa > 90 && $sa < 270) && $ea > 270) ) { + JpGraphError::RaiseL(14003);//('Internal assertion failed. Pie3D::Pie3DSlice'); + exit(1); + } - // Setup pre-calculated values - $rsa = $sa/180*M_PI; // to Rad - $rea = $ea/180*M_PI; // to Rad - $sinsa = sin($rsa); - $cossa = cos($rsa); - $sinea = sin($rea); - $cosea = cos($rea); + $p[] = array(); - // p[] is the points for the overall slice and - // pt[] is the points for the top pie + // Setup pre-calculated values + $rsa = $sa/180*M_PI; // to Rad + $rea = $ea/180*M_PI; // to Rad + $sinsa = sin($rsa); + $cossa = cos($rsa); + $sinea = sin($rea); + $cosea = cos($rea); - // Angular step when approximating the arc with a polygon train. - $step = 0.05; + // p[] is the points for the overall slice and + // pt[] is the points for the top pie - if( $sa >= 270 ) { - if( $ea > 360 || ($ea > 0 && $ea <= 90) ) { - if( $ea > 0 && $ea <= 90 ) { - // Adjust angle to simplify conditions in loops - $rea += 2*M_PI; - } + // Angular step when approximating the arc with a polygon train. + $step = 0.05; - $p = array($xc,$yc,$xc,$yc+$z, - $xc+$w*$cossa,$z+$yc-$h*$sinsa); - $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); + if( $sa >= 270 ) { + if( $ea > 360 || ($ea > 0 && $ea <= 90) ) { + if( $ea > 0 && $ea <= 90 ) { + // Adjust angle to simplify conditions in loops + $rea += 2*M_PI; + } - for( $a=$rsa; $a < 2*M_PI; $a += $step ) { - $tca = cos($a); - $tsa = sin($a); - $p[] = $xc+$w*$tca; - $p[] = $z+$yc-$h*$tsa; - $pt[] = $xc+$w*$tca; - $pt[] = $yc-$h*$tsa; - } + $p = array($xc,$yc,$xc,$yc+$z, + $xc+$w*$cossa,$z+$yc-$h*$sinsa); + $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); - $pt[] = $xc+$w; - $pt[] = $yc; + for( $a=$rsa; $a < 2*M_PI; $a += $step ) { + $tca = cos($a); + $tsa = sin($a); + $p[] = $xc+$w*$tca; + $p[] = $z+$yc-$h*$tsa; + $pt[] = $xc+$w*$tca; + $pt[] = $yc-$h*$tsa; + } - $p[] = $xc+$w; - $p[] = $z+$yc; - $p[] = $xc+$w; - $p[] = $yc; - $p[] = $xc; - $p[] = $yc; + $pt[] = $xc+$w; + $pt[] = $yc; - for( $a=2*M_PI+$step; $a < $rea; $a += $step ) { - $pt[] = $xc + $w*cos($a); - $pt[] = $yc - $h*sin($a); - } - - $pt[] = $xc+$w*$cosea; - $pt[] = $yc-$h*$sinea; - $pt[] = $xc; - $pt[] = $yc; + $p[] = $xc+$w; + $p[] = $z+$yc; + $p[] = $xc+$w; + $p[] = $yc; + $p[] = $xc; + $p[] = $yc; - } - else { - $p = array($xc,$yc,$xc,$yc+$z, - $xc+$w*$cossa,$z+$yc-$h*$sinsa); - $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); - - $rea = $rea == 0.0 ? 2*M_PI : $rea; - for( $a=$rsa; $a < $rea; $a += $step ) { - $tca = cos($a); - $tsa = sin($a); - $p[] = $xc+$w*$tca; - $p[] = $z+$yc-$h*$tsa; - $pt[] = $xc+$w*$tca; - $pt[] = $yc-$h*$tsa; - } + for( $a=2*M_PI+$step; $a < $rea; $a += $step ) { + $pt[] = $xc + $w*cos($a); + $pt[] = $yc - $h*sin($a); + } - $pt[] = $xc+$w*$cosea; - $pt[] = $yc-$h*$sinea; - $pt[] = $xc; - $pt[] = $yc; - - $p[] = $xc+$w*$cosea; - $p[] = $z+$yc-$h*$sinea; - $p[] = $xc+$w*$cosea; - $p[] = $yc-$h*$sinea; - $p[] = $xc; - $p[] = $yc; - } - } - elseif( $sa >= 180 ) { - $p = array($xc,$yc,$xc,$yc+$z,$xc+$w*$cosea,$z+$yc-$h*$sinea); - $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); - - for( $a=$rea; $a>$rsa; $a -= $step ) { - $tca = cos($a); - $tsa = sin($a); - $p[] = $xc+$w*$tca; - $p[] = $z+$yc-$h*$tsa; - $pt[] = $xc+$w*$tca; - $pt[] = $yc-$h*$tsa; - } + $pt[] = $xc+$w*$cosea; + $pt[] = $yc-$h*$sinea; + $pt[] = $xc; + $pt[] = $yc; - $pt[] = $xc+$w*$cossa; - $pt[] = $yc-$h*$sinsa; - $pt[] = $xc; - $pt[] = $yc; - - $p[] = $xc+$w*$cossa; - $p[] = $z+$yc-$h*$sinsa; - $p[] = $xc+$w*$cossa; - $p[] = $yc-$h*$sinsa; - $p[] = $xc; - $p[] = $yc; - - } - elseif( $sa >= 90 ) { - if( $ea > 180 ) { - $p = array($xc,$yc,$xc,$yc+$z,$xc+$w*$cosea,$z+$yc-$h*$sinea); - $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); + } + else { + $p = array($xc,$yc,$xc,$yc+$z, + $xc+$w*$cossa,$z+$yc-$h*$sinsa); + $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); - for( $a=$rea; $a > M_PI; $a -= $step ) { - $tca = cos($a); - $tsa = sin($a); - $p[] = $xc+$w*$tca; - $p[] = $z + $yc - $h*$tsa; - $pt[] = $xc+$w*$tca; - $pt[] = $yc-$h*$tsa; - } + $rea = $rea == 0.0 ? 2*M_PI : $rea; + for( $a=$rsa; $a < $rea; $a += $step ) { + $tca = cos($a); + $tsa = sin($a); + $p[] = $xc+$w*$tca; + $p[] = $z+$yc-$h*$tsa; + $pt[] = $xc+$w*$tca; + $pt[] = $yc-$h*$tsa; + } - $p[] = $xc-$w; - $p[] = $z+$yc; - $p[] = $xc-$w; - $p[] = $yc; - $p[] = $xc; - $p[] = $yc; + $pt[] = $xc+$w*$cosea; + $pt[] = $yc-$h*$sinea; + $pt[] = $xc; + $pt[] = $yc; - $pt[] = $xc-$w; - $pt[] = $z+$yc; - $pt[] = $xc-$w; - $pt[] = $yc; + $p[] = $xc+$w*$cosea; + $p[] = $z+$yc-$h*$sinea; + $p[] = $xc+$w*$cosea; + $p[] = $yc-$h*$sinea; + $p[] = $xc; + $p[] = $yc; + } + } + elseif( $sa >= 180 ) { + $p = array($xc,$yc,$xc,$yc+$z,$xc+$w*$cosea,$z+$yc-$h*$sinea); + $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); - for( $a=M_PI-$step; $a > $rsa; $a -= $step ) { - $pt[] = $xc + $w*cos($a); - $pt[] = $yc - $h*sin($a); - } + for( $a=$rea; $a>$rsa; $a -= $step ) { + $tca = cos($a); + $tsa = sin($a); + $p[] = $xc+$w*$tca; + $p[] = $z+$yc-$h*$tsa; + $pt[] = $xc+$w*$tca; + $pt[] = $yc-$h*$tsa; + } - $pt[] = $xc+$w*$cossa; - $pt[] = $yc-$h*$sinsa; - $pt[] = $xc; - $pt[] = $yc; + $pt[] = $xc+$w*$cossa; + $pt[] = $yc-$h*$sinsa; + $pt[] = $xc; + $pt[] = $yc; - } - else { // $sa >= 90 && $ea <= 180 - $p = array($xc,$yc,$xc,$yc+$z, - $xc+$w*$cosea,$z+$yc-$h*$sinea, - $xc+$w*$cosea,$yc-$h*$sinea, - $xc,$yc); + $p[] = $xc+$w*$cossa; + $p[] = $z+$yc-$h*$sinsa; + $p[] = $xc+$w*$cossa; + $p[] = $yc-$h*$sinsa; + $p[] = $xc; + $p[] = $yc; - $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); + } + elseif( $sa >= 90 ) { + if( $ea > 180 ) { + $p = array($xc,$yc,$xc,$yc+$z,$xc+$w*$cosea,$z+$yc-$h*$sinea); + $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); - for( $a=$rea; $a>$rsa; $a -= $step ) { - $pt[] = $xc + $w*cos($a); - $pt[] = $yc - $h*sin($a); - } + for( $a=$rea; $a > M_PI; $a -= $step ) { + $tca = cos($a); + $tsa = sin($a); + $p[] = $xc+$w*$tca; + $p[] = $z + $yc - $h*$tsa; + $pt[] = $xc+$w*$tca; + $pt[] = $yc-$h*$tsa; + } - $pt[] = $xc+$w*$cossa; - $pt[] = $yc-$h*$sinsa; - $pt[] = $xc; - $pt[] = $yc; + $p[] = $xc-$w; + $p[] = $z+$yc; + $p[] = $xc-$w; + $p[] = $yc; + $p[] = $xc; + $p[] = $yc; - } - } - else { // sa > 0 && ea < 90 + $pt[] = $xc-$w; + $pt[] = $z+$yc; + $pt[] = $xc-$w; + $pt[] = $yc; - $p = array($xc,$yc,$xc,$yc+$z, - $xc+$w*$cossa,$z+$yc-$h*$sinsa, - $xc+$w*$cossa,$yc-$h*$sinsa, - $xc,$yc); + for( $a=M_PI-$step; $a > $rsa; $a -= $step ) { + $pt[] = $xc + $w*cos($a); + $pt[] = $yc - $h*sin($a); + } - $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); + $pt[] = $xc+$w*$cossa; + $pt[] = $yc-$h*$sinsa; + $pt[] = $xc; + $pt[] = $yc; - for( $a=$rsa; $a < $rea; $a += $step ) { - $pt[] = $xc + $w*cos($a); - $pt[] = $yc - $h*sin($a); - } + } + else { // $sa >= 90 && $ea <= 180 + $p = array($xc,$yc,$xc,$yc+$z, + $xc+$w*$cosea,$z+$yc-$h*$sinea, + $xc+$w*$cosea,$yc-$h*$sinea, + $xc,$yc); - $pt[] = $xc+$w*$cosea; - $pt[] = $yc-$h*$sinea; - $pt[] = $xc; - $pt[] = $yc; - } - - $img->PushColor($fillcolor.":".$shadow); - $img->FilledPolygon($p); - $img->PopColor(); + $pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea); - $img->PushColor($fillcolor); - $img->FilledPolygon($pt); - $img->PopColor(); + for( $a=$rea; $a>$rsa; $a -= $step ) { + $pt[] = $xc + $w*cos($a); + $pt[] = $yc - $h*sin($a); + } + + $pt[] = $xc+$w*$cossa; + $pt[] = $yc-$h*$sinsa; + $pt[] = $xc; + $pt[] = $yc; + + } + } + else { // sa > 0 && ea < 90 + + $p = array($xc,$yc,$xc,$yc+$z, + $xc+$w*$cossa,$z+$yc-$h*$sinsa, + $xc+$w*$cossa,$yc-$h*$sinsa, + $xc,$yc); + + $pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa); + + for( $a=$rsa; $a < $rea; $a += $step ) { + $pt[] = $xc + $w*cos($a); + $pt[] = $yc - $h*sin($a); + } + + $pt[] = $xc+$w*$cosea; + $pt[] = $yc-$h*$sinea; + $pt[] = $xc; + $pt[] = $yc; + } + + $img->PushColor($fillcolor.":".$shadow); + $img->FilledPolygon($p); + $img->PopColor(); + + $img->PushColor($fillcolor); + $img->FilledPolygon($pt); + $img->PopColor(); } function SetStartAngle($aStart) { - if( $aStart < 0 || $aStart > 360 ) { - JpGraphError::RaiseL(14004);//('Slice start angle must be between 0 and 360 degrees.'); - } - $this->startangle = $aStart; + if( $aStart < 0 || $aStart > 360 ) { + JpGraphError::RaiseL(14004);//('Slice start angle must be between 0 and 360 degrees.'); + } + $this->startangle = $aStart; } - -// Draw a 3D Pie + + // Draw a 3D Pie function Pie3D($aaoption,$img,$data,$colors,$xc,$yc,$d,$angle,$z, - $shadow=0.65,$startangle=0,$edgecolor="",$edgeweight=1) { + $shadow=0.65,$startangle=0,$edgecolor="",$edgeweight=1) { - //--------------------------------------------------------------------------- - // As usual the algorithm get more complicated than I originally - // envisioned. I believe that this is as simple as it is possible - // to do it with the features I want. It's a good exercise to start - // thinking on how to do this to convince your self that all this - // is really needed for the general case. - // - // The algorithm two draw 3D pies without "real 3D" is done in - // two steps. - // First imagine the pie cut in half through a thought line between - // 12'a clock and 6'a clock. It now easy to imagine that we can plot - // the individual slices for each half by starting with the topmost - // pie slice and continue down to 6'a clock. - // - // In the algortithm this is done in three principal steps - // Step 1. Do the knife cut to ensure by splitting slices that extends - // over the cut line. This is done by splitting the original slices into - // upto 3 subslices. - // Step 2. Find the top slice for each half - // Step 3. Draw the slices from top to bottom - // - // The thing that slightly complicates this scheme with all the - // angle comparisons below is that we can have an arbitrary start - // angle so we must take into account the different equivalence classes. - // For the same reason we must walk through the angle array in a - // modulo fashion. - // - // Limitations of algorithm: - // * A small exploded slice which crosses the 270 degree point - // will get slightly nagged close to the center due to the fact that - // we print the slices in Z-order and that the slice left part - // get printed first and might get slightly nagged by a larger - // slice on the right side just before the right part of the small - // slice. Not a major problem though. - //--------------------------------------------------------------------------- - - - // Determine the height of the ellippse which gives an - // indication of the inclination angle - $h = ($angle/90.0)*$d; - $sum = 0; - for($i=0; $ilabeltype == 2 ) { - $this->adjusted_data = $this->AdjPercentage($data); - } - - // Setup the start - $accsum = 0; - $a = $startangle; - $a = $this->NormAngle($a); - - // - // Step 1 . Split all slices that crosses 90 or 270 - // - $idx=0; - $adjexplode=array(); - $numcolors = count($colors); - for($i=0; $iexplode_radius[$i]) ) - $this->explode_radius[$i]=0; - - $expscale=1; - if( $aaoption == 1 ) - $expscale=2; - - $la = $a + $da/2; - $explode = array( $xc + $this->explode_radius[$i]*cos($la*M_PI/180)*$expscale, - $yc - $this->explode_radius[$i]*sin($la*M_PI/180) * ($h/$d) *$expscale ); - $adjexplode[$idx] = $explode; - $labeldata[$i] = array($la,$explode[0],$explode[1]); - $originalangles[$i] = array($a,$a+$da); - - $ne = $this->NormAngle($a+$da); - if( $da <= 180 ) { - // If the slice size is <= 90 it can at maximum cut across - // one boundary (either 90 or 270) where it needs to be split - $split=-1; // no split - if( ($da<=90 && ($a <= 90 && $ne > 90)) || - (($da <= 180 && $da >90) && (($a < 90 || $a >= 270) && $ne > 90)) ) { - $split = 90; - } - elseif( ($da<=90 && ($a <= 270 && $ne > 270)) || - (($da<=180 && $da>90) && ($a >= 90 && $a < 270 && ($a+$da) > 270 )) ) { - $split = 270; - } - if( $split > 0 ) { // split in two - $angles[$idx] = array($a,$split); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - $angles[++$idx] = array($split,$ne); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - } - else { // no split - $angles[$idx] = array($a,$ne); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - } - } - else { - // da>180 - // Slice may, depending on position, cross one or two - // bonudaries - - if( $a < 90 ) - $split = 90; - elseif( $a <= 270 ) - $split = 270; - else - $split = 90; - - $angles[$idx] = array($a,$split); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - //if( $a+$da > 360-$split ) { - // For slices larger than 270 degrees we might cross - // another boundary as well. This means that we must - // split the slice further. The comparison gets a little - // bit complicated since we must take into accound that - // a pie might have a startangle >0 and hence a slice might - // wrap around the 0 angle. - // Three cases: - // a) Slice starts before 90 and hence gets a split=90, but - // we must also check if we need to split at 270 - // b) Slice starts after 90 but before 270 and slices - // crosses 90 (after a wrap around of 0) - // c) If start is > 270 (hence the firstr split is at 90) - // and the slice is so large that it goes all the way - // around 270. - if( ($a < 90 && ($a+$da > 270)) || - ($a > 90 && $a<=270 && ($a+$da>360+90) ) || - ($a > 270 && $this->NormAngle($a+$da)>270) ) { - $angles[++$idx] = array($split,360-$split); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - $angles[++$idx] = array(360-$split,$ne); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - } - else { - // Just a simple split to the previous decided - // angle. - $angles[++$idx] = array($split,$ne); - $adjcolors[$idx] = $colors[$i % $numcolors]; - $adjexplode[$idx] = $explode; - } - } - $a += $da; - $a = $this->NormAngle($a); - } - - // Total number of slices - $n = count($angles); - - for($i=0; $i<$n; ++$i) { - list($dbgs,$dbge) = $angles[$i]; - } - - // - // Step 2. Find start index (first pie that starts in upper left quadrant) - // - $minval = $angles[0][0]; - $min = 0; - for( $i=0; $i<$n; ++$i ) { - if( $angles[$i][0] < $minval ) { - $minval = $angles[$i][0]; - $min = $i; - } - } - $j = $min; - $cnt = 0; - while( $angles[$j][1] <= 90 ) { - $j++; - if( $j>=$n) { - $j=0; - } - if( $cnt > $n ) { - JpGraphError::RaiseL(14005); -//("Pie3D Internal error (#1). Trying to wrap twice when looking for start index"); - } - ++$cnt; - } - $start = $j; - - // - // Step 3. Print slices in z-order - // - $cnt = 0; - - // First stroke all the slices between 90 and 270 (left half circle) - // counterclockwise - - while( $angles[$j][0] < 270 && $aaoption !== 2 ) { - - list($x,$y) = $adjexplode[$j]; - - $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], - $z,$adjcolors[$j],$shadow); - - $last = array($x,$y,$j); - - $j++; - if( $j >= $n ) $j=0; - if( $cnt > $n ) { - JpGraphError::RaiseL(14006); -//("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); - } - ++$cnt; - } - - $slice_left = $n-$cnt; - $j=$start-1; - if($j<0) $j=$n-1; - $cnt = 0; - - // The stroke all slices from 90 to -90 (right half circle) - // clockwise - while( $cnt < $slice_left && $aaoption !== 2 ) { - - list($x,$y) = $adjexplode[$j]; - - $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], - $z,$adjcolors[$j],$shadow); - $j--; - if( $cnt > $n ) { - JpGraphError::RaiseL(14006); -//("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); - } - if($j<0) $j=$n-1; - $cnt++; - } - - // Now do a special thing. Stroke the last slice on the left - // halfcircle one more time. This is needed in the case where - // the slice close to 270 have been exploded. In that case the - // part of the slice close to the center of the pie might be - // slightly nagged. - if( $aaoption !== 2 ) - $this->Pie3DSlice($img,$last[0],$last[1],$d,$h,$angles[$last[2]][0], - $angles[$last[2]][1],$z,$adjcolors[$last[2]],$shadow); + //--------------------------------------------------------------------------- + // As usual the algorithm get more complicated than I originally + // envisioned. I believe that this is as simple as it is possible + // to do it with the features I want. It's a good exercise to start + // thinking on how to do this to convince your self that all this + // is really needed for the general case. + // + // The algorithm two draw 3D pies without "real 3D" is done in + // two steps. + // First imagine the pie cut in half through a thought line between + // 12'a clock and 6'a clock. It now easy to imagine that we can plot + // the individual slices for each half by starting with the topmost + // pie slice and continue down to 6'a clock. + // + // In the algortithm this is done in three principal steps + // Step 1. Do the knife cut to ensure by splitting slices that extends + // over the cut line. This is done by splitting the original slices into + // upto 3 subslices. + // Step 2. Find the top slice for each half + // Step 3. Draw the slices from top to bottom + // + // The thing that slightly complicates this scheme with all the + // angle comparisons below is that we can have an arbitrary start + // angle so we must take into account the different equivalence classes. + // For the same reason we must walk through the angle array in a + // modulo fashion. + // + // Limitations of algorithm: + // * A small exploded slice which crosses the 270 degree point + // will get slightly nagged close to the center due to the fact that + // we print the slices in Z-order and that the slice left part + // get printed first and might get slightly nagged by a larger + // slice on the right side just before the right part of the small + // slice. Not a major problem though. + //--------------------------------------------------------------------------- - if( $aaoption !== 1 ) { - // Now print possible labels and add csim - $this->value->ApplyFont($img); - $margin = $img->GetFontHeight()/2 + $this->value->margin ; - for($i=0; $i < count($data); ++$i ) { - $la = $labeldata[$i][0]; - $x = $labeldata[$i][1] + cos($la*M_PI/180)*($d+$margin)*$this->ilabelposadj; - $y = $labeldata[$i][2] - sin($la*M_PI/180)*($h+$margin)*$this->ilabelposadj; - if( $this->ilabelposadj >= 1.0 ) { - if( $la > 180 && $la < 360 ) $y += $z; - } - if( $this->labeltype == 0 ) { - if( $sum > 0 ) - $l = 100*$data[$i]/$sum; - else - $l = 0; - } - elseif( $this->labeltype == 1 ) { - $l = $data[$i]; - } - else { - $l = $this->adjusted_data[$i]; - } - if( isset($this->labels[$i]) && is_string($this->labels[$i]) ) - $l=sprintf($this->labels[$i],$l); + // Determine the height of the ellippse which gives an + // indication of the inclination angle + $h = ($angle/90.0)*$d; + $sum = 0; + for($i=0; $iStrokeLabels($l,$img,$labeldata[$i][0]*M_PI/180,$x,$y,$z); - - $this->Add3DSliceToCSIM($i,$labeldata[$i][1],$labeldata[$i][2],$h*2,$d*2,$z, - $originalangles[$i][0],$originalangles[$i][1]); - } - } + // Special optimization + if( $sum==0 ) return; - // - // Finally add potential lines in pie - // + if( $this->labeltype == 2 ) { + $this->adjusted_data = $this->AdjPercentage($data); + } - if( $edgecolor=="" || $aaoption !== 0 ) return; + // Setup the start + $accsum = 0; + $a = $startangle; + $a = $this->NormAngle($a); - $accsum = 0; - $a = $startangle; - $a = $this->NormAngle($a); + // + // Step 1 . Split all slices that crosses 90 or 270 + // + $idx=0; + $adjexplode=array(); + $numcolors = count($colors); + for($i=0; $iexplode_radius[$i]) ) { + $this->explode_radius[$i]=0; + } - $idx=0; - $img->PushColor($edgecolor); - $img->SetLineWeight($edgeweight); - - $fulledge = true; - for($i=0; $i < count($data) && $fulledge; ++$i ) { - if( empty($this->explode_radius[$i]) ) - $this->explode_radius[$i]=0; - if( $this->explode_radius[$i] > 0 ) { - $fulledge = false; - } - } - + $expscale=1; + if( $aaoption == 1 ) { + $expscale=2; + } - for($i=0; $i < count($data); ++$i, ++$idx ) { + $la = $a + $da/2; + $explode = array( $xc + $this->explode_radius[$i]*cos($la*M_PI/180)*$expscale, + $yc - $this->explode_radius[$i]*sin($la*M_PI/180) * ($h/$d) *$expscale ); + $adjexplode[$idx] = $explode; + $labeldata[$i] = array($la,$explode[0],$explode[1]); + $originalangles[$i] = array($a,$a+$da); - $da = $data[$i]/$sum * 2*M_PI; - $this->StrokeFullSliceFrame($img,$xc,$yc,$a,$a+$da,$d,$h,$z,$edgecolor, - $this->explode_radius[$i],$fulledge); - $a += $da; - } - $img->PopColor(); + $ne = $this->NormAngle($a+$da); + if( $da <= 180 ) { + // If the slice size is <= 90 it can at maximum cut across + // one boundary (either 90 or 270) where it needs to be split + $split=-1; // no split + if( ($da<=90 && ($a <= 90 && $ne > 90)) || + (($da <= 180 && $da >90) && (($a < 90 || $a >= 270) && $ne > 90)) ) { + $split = 90; + } + elseif( ($da<=90 && ($a <= 270 && $ne > 270)) || + (($da<=180 && $da>90) && ($a >= 90 && $a < 270 && ($a+$da) > 270 )) ) { + $split = 270; + } + if( $split > 0 ) { // split in two + $angles[$idx] = array($a,$split); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + $angles[++$idx] = array($split,$ne); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + } + else { // no split + $angles[$idx] = array($a,$ne); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + } + } + else { + // da>180 + // Slice may, depending on position, cross one or two + // bonudaries + + if( $a < 90 ) $split = 90; + elseif( $a <= 270 ) $split = 270; + else $split = 90; + + $angles[$idx] = array($a,$split); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + //if( $a+$da > 360-$split ) { + // For slices larger than 270 degrees we might cross + // another boundary as well. This means that we must + // split the slice further. The comparison gets a little + // bit complicated since we must take into accound that + // a pie might have a startangle >0 and hence a slice might + // wrap around the 0 angle. + // Three cases: + // a) Slice starts before 90 and hence gets a split=90, but + // we must also check if we need to split at 270 + // b) Slice starts after 90 but before 270 and slices + // crosses 90 (after a wrap around of 0) + // c) If start is > 270 (hence the firstr split is at 90) + // and the slice is so large that it goes all the way + // around 270. + if( ($a < 90 && ($a+$da > 270)) || ($a > 90 && $a<=270 && ($a+$da>360+90) ) || ($a > 270 && $this->NormAngle($a+$da)>270) ) { + $angles[++$idx] = array($split,360-$split); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + $angles[++$idx] = array(360-$split,$ne); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + } + else { + // Just a simple split to the previous decided + // angle. + $angles[++$idx] = array($split,$ne); + $adjcolors[$idx] = $colors[$i % $numcolors]; + $adjexplode[$idx] = $explode; + } + } + $a += $da; + $a = $this->NormAngle($a); + } + + // Total number of slices + $n = count($angles); + + for($i=0; $i<$n; ++$i) { + list($dbgs,$dbge) = $angles[$i]; + } + + // + // Step 2. Find start index (first pie that starts in upper left quadrant) + // + $minval = $angles[0][0]; + $min = 0; + for( $i=0; $i<$n; ++$i ) { + if( $angles[$i][0] < $minval ) { + $minval = $angles[$i][0]; + $min = $i; + } + } + $j = $min; + $cnt = 0; + while( $angles[$j][1] <= 90 ) { + $j++; + if( $j>=$n) { + $j=0; + } + if( $cnt > $n ) { + JpGraphError::RaiseL(14005); + //("Pie3D Internal error (#1). Trying to wrap twice when looking for start index"); + } + ++$cnt; + } + $start = $j; + + // + // Step 3. Print slices in z-order + // + $cnt = 0; + + // First stroke all the slices between 90 and 270 (left half circle) + // counterclockwise + + while( $angles[$j][0] < 270 && $aaoption !== 2 ) { + + list($x,$y) = $adjexplode[$j]; + + $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], + $z,$adjcolors[$j],$shadow); + + $last = array($x,$y,$j); + + $j++; + if( $j >= $n ) $j=0; + if( $cnt > $n ) { + JpGraphError::RaiseL(14006); + //("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); + } + ++$cnt; + } + + $slice_left = $n-$cnt; + $j=$start-1; + if($j<0) $j=$n-1; + $cnt = 0; + + // The stroke all slices from 90 to -90 (right half circle) + // clockwise + while( $cnt < $slice_left && $aaoption !== 2 ) { + + list($x,$y) = $adjexplode[$j]; + + $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], + $z,$adjcolors[$j],$shadow); + $j--; + if( $cnt > $n ) { + JpGraphError::RaiseL(14006); + //("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); + } + if($j<0) $j=$n-1; + $cnt++; + } + + // Now do a special thing. Stroke the last slice on the left + // halfcircle one more time. This is needed in the case where + // the slice close to 270 have been exploded. In that case the + // part of the slice close to the center of the pie might be + // slightly nagged. + if( $aaoption !== 2 ) + $this->Pie3DSlice($img,$last[0],$last[1],$d,$h,$angles[$last[2]][0], + $angles[$last[2]][1],$z,$adjcolors[$last[2]],$shadow); + + + if( $aaoption !== 1 ) { + // Now print possible labels and add csim + $this->value->ApplyFont($img); + $margin = $img->GetFontHeight()/2 + $this->value->margin ; + for($i=0; $i < count($data); ++$i ) { + $la = $labeldata[$i][0]; + $x = $labeldata[$i][1] + cos($la*M_PI/180)*($d+$margin)*$this->ilabelposadj; + $y = $labeldata[$i][2] - sin($la*M_PI/180)*($h+$margin)*$this->ilabelposadj; + if( $this->ilabelposadj >= 1.0 ) { + if( $la > 180 && $la < 360 ) $y += $z; + } + if( $this->labeltype == 0 ) { + if( $sum > 0 ) $l = 100*$data[$i]/$sum; + else $l = 0; + } + elseif( $this->labeltype == 1 ) { + $l = $data[$i]; + } + else { + $l = $this->adjusted_data[$i]; + } + if( isset($this->labels[$i]) && is_string($this->labels[$i]) ) { + $l=sprintf($this->labels[$i],$l); + } + + $this->StrokeLabels($l,$img,$labeldata[$i][0]*M_PI/180,$x,$y,$z); + + $this->Add3DSliceToCSIM($i,$labeldata[$i][1],$labeldata[$i][2],$h*2,$d*2,$z, + $originalangles[$i][0],$originalangles[$i][1]); + } + } + + // + // Finally add potential lines in pie + // + + if( $edgecolor=="" || $aaoption !== 0 ) return; + + $accsum = 0; + $a = $startangle; + $a = $this->NormAngle($a); + + $a *= M_PI/180.0; + + $idx=0; + $img->PushColor($edgecolor); + $img->SetLineWeight($edgeweight); + + $fulledge = true; + for($i=0; $i < count($data) && $fulledge; ++$i ) { + if( empty($this->explode_radius[$i]) ) { + $this->explode_radius[$i]=0; + } + if( $this->explode_radius[$i] > 0 ) { + $fulledge = false; + } + } + + + for($i=0; $i < count($data); ++$i, ++$idx ) { + + $da = $data[$i]/$sum * 2*M_PI; + $this->StrokeFullSliceFrame($img,$xc,$yc,$a,$a+$da,$d,$h,$z,$edgecolor, + $this->explode_radius[$i],$fulledge); + $a += $da; + } + $img->PopColor(); } function StrokeFullSliceFrame($img,$xc,$yc,$sa,$ea,$w,$h,$z,$edgecolor,$exploderadius,$fulledge) { - $step = 0.02; + $step = 0.02; - if( $exploderadius > 0 ) { - $la = ($sa+$ea)/2; - $xc += $exploderadius*cos($la); - $yc -= $exploderadius*sin($la) * ($h/$w) ; - - } + if( $exploderadius > 0 ) { + $la = ($sa+$ea)/2; + $xc += $exploderadius*cos($la); + $yc -= $exploderadius*sin($la) * ($h/$w) ; + + } - $p = array($xc,$yc,$xc+$w*cos($sa),$yc-$h*sin($sa)); + $p = array($xc,$yc,$xc+$w*cos($sa),$yc-$h*sin($sa)); - for($a=$sa; $a < $ea; $a += $step ) { - $p[] = $xc + $w*cos($a); - $p[] = $yc - $h*sin($a); - } + for($a=$sa; $a < $ea; $a += $step ) { + $p[] = $xc + $w*cos($a); + $p[] = $yc - $h*sin($a); + } - $p[] = $xc+$w*cos($ea); - $p[] = $yc-$h*sin($ea); - $p[] = $xc; - $p[] = $yc; + $p[] = $xc+$w*cos($ea); + $p[] = $yc-$h*sin($ea); + $p[] = $xc; + $p[] = $yc; - $img->SetColor($edgecolor); - $img->Polygon($p); + $img->SetColor($edgecolor); + $img->Polygon($p); - // Unfortunately we can't really draw the full edge around the whole of - // of the slice if any of the slices are exploded. The reason is that - // this algorithm is to simply. There are cases where the edges will - // "overwrite" other slices when they have been exploded. - // Doing the full, proper 3D hidden lines stiff is actually quite - // tricky. So for exploded pies we only draw the top edge. Not perfect - // but the "real" solution is much more complicated. - if( $fulledge && !( $sa > 0 && $sa < M_PI && $ea < M_PI) ) { + // Unfortunately we can't really draw the full edge around the whole of + // of the slice if any of the slices are exploded. The reason is that + // this algorithm is to simply. There are cases where the edges will + // "overwrite" other slices when they have been exploded. + // Doing the full, proper 3D hidden lines stiff is actually quite + // tricky. So for exploded pies we only draw the top edge. Not perfect + // but the "real" solution is much more complicated. + if( $fulledge && !( $sa > 0 && $sa < M_PI && $ea < M_PI) ) { - if($sa < M_PI && $ea > M_PI) - $sa = M_PI; - - if($sa < 2*M_PI && (($ea >= 2*M_PI) || ($ea > 0 && $ea < $sa ) ) ) - $ea = 2*M_PI; + if($sa < M_PI && $ea > M_PI) { + $sa = M_PI; + } - if( $sa >= M_PI && $ea <= 2*M_PI ) { - $p = array($xc + $w*cos($sa),$yc - $h*sin($sa), - $xc + $w*cos($sa),$z + $yc - $h*sin($sa)); - - for($a=$sa+$step; $a < $ea; $a += $step ) { - $p[] = $xc + $w*cos($a); - $p[] = $z + $yc - $h*sin($a); - } - $p[] = $xc + $w*cos($ea); - $p[] = $z + $yc - $h*sin($ea); - $p[] = $xc + $w*cos($ea); - $p[] = $yc - $h*sin($ea); - $img->SetColor($edgecolor); - $img->Polygon($p); - } - } + if($sa < 2*M_PI && (($ea >= 2*M_PI) || ($ea > 0 && $ea < $sa ) ) ) { + $ea = 2*M_PI; + } + + if( $sa >= M_PI && $ea <= 2*M_PI ) { + $p = array($xc + $w*cos($sa),$yc - $h*sin($sa), + $xc + $w*cos($sa),$z + $yc - $h*sin($sa)); + + for($a=$sa+$step; $a < $ea; $a += $step ) { + $p[] = $xc + $w*cos($a); + $p[] = $z + $yc - $h*sin($a); + } + $p[] = $xc + $w*cos($ea); + $p[] = $z + $yc - $h*sin($ea); + $p[] = $xc + $w*cos($ea); + $p[] = $yc - $h*sin($ea); + $img->SetColor($edgecolor); + $img->Polygon($p); + } + } } function Stroke($img,$aaoption=0) { - $n = count($this->data); + $n = count($this->data); - // If user hasn't set the colors use the theme array - if( $this->setslicecolors==null ) { - $colors = array_keys($img->rgb->rgb_table); - sort($colors); - $idx_a=$this->themearr[$this->theme]; - $ca = array(); - $m = count($idx_a); - for($i=0; $i < $m; ++$i) - $ca[$i] = $colors[$idx_a[$i]]; - $ca = array_reverse(array_slice($ca,0,$n)); - } - else { - $ca = $this->setslicecolors; - } - + // If user hasn't set the colors use the theme array + if( $this->setslicecolors==null ) { + $colors = array_keys($img->rgb->rgb_table); + sort($colors); + $idx_a=$this->themearr[$this->theme]; + $ca = array(); + $m = count($idx_a); + for($i=0; $i < $m; ++$i) { + $ca[$i] = $colors[$idx_a[$i]]; + } + $ca = array_reverse(array_slice($ca,0,$n)); + } + else { + $ca = $this->setslicecolors; + } - if( $this->posx <= 1 && $this->posx > 0 ) - $xc = round($this->posx*$img->width); - else - $xc = $this->posx ; - - if( $this->posy <= 1 && $this->posy > 0 ) - $yc = round($this->posy*$img->height); - else - $yc = $this->posy ; - - if( $this->radius <= 1 ) { - $width = floor($this->radius*min($img->width,$img->height)); - // Make sure that the pie doesn't overflow the image border - // The 0.9 factor is simply an extra margin to leave some space - // between the pie an the border of the image. - $width = min($width,min($xc*0.9,($yc*90/$this->angle-$width/4)*0.9)); - } - else { - $width = $this->radius * ($aaoption === 1 ? 2 : 1 ) ; - } - // Add a sanity check for width - if( $width < 1 ) { - JpGraphError::RaiseL(14007);//("Width for 3D Pie is 0. Specify a size > 0"); - } + if( $this->posx <= 1 && $this->posx > 0 ) { + $xc = round($this->posx*$img->width); + } + else { + $xc = $this->posx ; + } - // Establish a thickness. By default the thickness is a fifth of the - // pie slice width (=pie radius) but since the perspective depends - // on the inclination angle we use some heuristics to make the edge - // slightly thicker the less the angle. - - // Has user specified an absolute thickness? In that case use - // that instead + if( $this->posy <= 1 && $this->posy > 0 ) { + $yc = round($this->posy*$img->height); + } + else { + $yc = $this->posy ; + } - if( $this->iThickness ) { - $thick = $this->iThickness; - $thick *= ($aaoption === 1 ? 2 : 1 ); - } - else - $thick = $width/12; - $a = $this->angle; - if( $a <= 30 ) $thick *= 1.6; - elseif( $a <= 40 ) $thick *= 1.4; - elseif( $a <= 50 ) $thick *= 1.2; - elseif( $a <= 60 ) $thick *= 1.0; - elseif( $a <= 70 ) $thick *= 0.8; - elseif( $a <= 80 ) $thick *= 0.7; - else $thick *= 0.6; + if( $this->radius <= 1 ) { + $width = floor($this->radius*min($img->width,$img->height)); + // Make sure that the pie doesn't overflow the image border + // The 0.9 factor is simply an extra margin to leave some space + // between the pie an the border of the image. + $width = min($width,min($xc*0.9,($yc*90/$this->angle-$width/4)*0.9)); + } + else { + $width = $this->radius * ($aaoption === 1 ? 2 : 1 ) ; + } - $thick = floor($thick); + // Add a sanity check for width + if( $width < 1 ) { + JpGraphError::RaiseL(14007);//("Width for 3D Pie is 0. Specify a size > 0"); + } - if( $this->explode_all ) - for($i=0; $i < $n; ++$i) - $this->explode_radius[$i]=$this->explode_r; + // Establish a thickness. By default the thickness is a fifth of the + // pie slice width (=pie radius) but since the perspective depends + // on the inclination angle we use some heuristics to make the edge + // slightly thicker the less the angle. - $this->Pie3D($aaoption,$img,$this->data, $ca, $xc, $yc, $width, $this->angle, - $thick, 0.65, $this->startangle, $this->edgecolor, $this->edgeweight); + // Has user specified an absolute thickness? In that case use + // that instead - // Adjust title position - if( $aaoption != 1 ) { - $this->title->SetPos($xc,$yc-$this->title->GetFontHeight($img)-$width/2-$this->title->margin, "center","bottom"); - $this->title->Stroke($img); - } + if( $this->iThickness ) { + $thick = $this->iThickness; + $thick *= ($aaoption === 1 ? 2 : 1 ); + } + else { + $thick = $width/12; + } + $a = $this->angle; + + if( $a <= 30 ) $thick *= 1.6; + elseif( $a <= 40 ) $thick *= 1.4; + elseif( $a <= 50 ) $thick *= 1.2; + elseif( $a <= 60 ) $thick *= 1.0; + elseif( $a <= 70 ) $thick *= 0.8; + elseif( $a <= 80 ) $thick *= 0.7; + else $thick *= 0.6; + + $thick = floor($thick); + + if( $this->explode_all ) { + for($i=0; $i < $n; ++$i) + $this->explode_radius[$i]=$this->explode_r; + } + + $this->Pie3D($aaoption,$img,$this->data, $ca, $xc, $yc, $width, $this->angle, + $thick, 0.65, $this->startangle, $this->edgecolor, $this->edgeweight); + + // Adjust title position + if( $aaoption != 1 ) { + $this->title->SetPos($xc,$yc-$this->title->GetFontHeight($img)-$width/2-$this->title->margin, "center","bottom"); + $this->title->Stroke($img); + } } -//--------------- -// PRIVATE METHODS + //--------------- + // PRIVATE METHODS // Position the labels of each slice function StrokeLabels($label,$img,$a,$xp,$yp,$z) { - $this->value->halign="left"; - $this->value->valign="top"; + $this->value->halign="left"; + $this->value->valign="top"; - // Position the axis title. - // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text - // that intersects with the extension of the corresponding axis. The code looks a little - // bit messy but this is really the only way of having a reasonable position of the - // axis titles. - $this->value->ApplyFont($img); - $h=$img->GetTextHeight($label); - // For numeric values the format of the display value - // must be taken into account - if( is_numeric($label) ) { - if( $label >= 0 ) - $w=$img->GetTextWidth(sprintf($this->value->format,$label)); - else - $w=$img->GetTextWidth(sprintf($this->value->negformat,$label)); - } - else - $w=$img->GetTextWidth($label); - while( $a > 2*M_PI ) $a -= 2*M_PI; - if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0; - if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI; - if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1; - if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI); - - if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI; - if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI); - if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1; - if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI); - if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0; - - $x = round($xp-$dx*$w); - $y = round($yp-$dy*$h); + // Position the axis title. + // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text + // that intersects with the extension of the corresponding axis. The code looks a little + // bit messy but this is really the only way of having a reasonable position of the + // axis titles. + $this->value->ApplyFont($img); + $h=$img->GetTextHeight($label); + // For numeric values the format of the display value + // must be taken into account + if( is_numeric($label) ) { + if( $label >= 0 ) { + $w=$img->GetTextWidth(sprintf($this->value->format,$label)); + } + else { + $w=$img->GetTextWidth(sprintf($this->value->negformat,$label)); + } + } + else { + $w=$img->GetTextWidth($label); + } + + while( $a > 2*M_PI ) { + $a -= 2*M_PI; + } + + if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0; + if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI; + if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1; + if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI); - - // Mark anchor point for debugging - /* - $img->SetColor('red'); - $img->Line($xp-10,$yp,$xp+10,$yp); - $img->Line($xp,$yp-10,$xp,$yp+10); - */ - $oldmargin = $this->value->margin; - $this->value->margin=0; - $this->value->Stroke($img,$label,$x,$y); - $this->value->margin=$oldmargin; + if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI; + if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI); + if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1; + if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI); + if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0; - } + $x = round($xp-$dx*$w); + $y = round($yp-$dy*$h); + + // Mark anchor point for debugging + /* + $img->SetColor('red'); + $img->Line($xp-10,$yp,$xp+10,$yp); + $img->Line($xp,$yp-10,$xp,$yp+10); + */ + + $oldmargin = $this->value->margin; + $this->value->margin=0; + $this->value->Stroke($img,$label,$x,$y); + $this->value->margin=$oldmargin; + + } } // Class /* EOF */ diff --git a/src/classes/jpgraph/jpgraph_plotband.php b/src/classes/jpgraph/jpgraph_plotband.php index 5c6fc29..1c78d33 100644 --- a/src/classes/jpgraph/jpgraph_plotband.php +++ b/src/classes/jpgraph/jpgraph_plotband.php @@ -1,35 +1,35 @@ x=$aX; - $this->y=$aY; - $this->w=$aWidth; - $this->h=$aHeight; - $this->xe=$aX+$aWidth-1; - $this->ye=$aY+$aHeight-1; + function __construct($aX,$aY,$aWidth,$aHeight) { + $this->x=$aX; + $this->y=$aY; + $this->w=$aWidth; + $this->h=$aHeight; + $this->xe=$aX+$aWidth-1; + $this->ye=$aY+$aHeight-1; } } @@ -45,55 +45,55 @@ class RectPattern { protected $weight; protected $rect=null; protected $doframe=true; - protected $linespacing; // Line spacing in pixels + protected $linespacing; // Line spacing in pixels protected $iBackgroundColor=-1; // Default is no background fill - - function RectPattern($aColor,$aWeight=1) { - $this->color = $aColor; - $this->weight = $aWeight; + + function __construct($aColor,$aWeight=1) { + $this->color = $aColor; + $this->weight = $aWeight; } function SetBackground($aBackgroundColor) { - $this->iBackgroundColor=$aBackgroundColor; + $this->iBackgroundColor=$aBackgroundColor; } function SetPos($aRect) { - $this->rect = $aRect; + $this->rect = $aRect; } - + function ShowFrame($aShow=true) { - $this->doframe=$aShow; + $this->doframe=$aShow; } function SetDensity($aDens) { - if( $aDens < 1 || $aDens > 100 ) - JpGraphError::RaiseL(16001,$aDens); -//(" Desity for pattern must be between 1 and 100. (You tried $aDens)"); - // 1% corresponds to linespacing=50 - // 100 % corresponds to linespacing 1 - $this->linespacing = floor(((100-$aDens)/100.0)*50)+1; + if( $aDens < 1 || $aDens > 100 ) + JpGraphError::RaiseL(16001,$aDens); + //(" Desity for pattern must be between 1 and 100. (You tried $aDens)"); + // 1% corresponds to linespacing=50 + // 100 % corresponds to linespacing 1 + $this->linespacing = floor(((100-$aDens)/100.0)*50)+1; } function Stroke($aImg) { - if( $this->rect == null ) - JpGraphError::RaiseL(16002); -//(" No positions specified for pattern."); + if( $this->rect == null ) + JpGraphError::RaiseL(16002); + //(" No positions specified for pattern."); - if( !(is_numeric($this->iBackgroundColor) && $this->iBackgroundColor==-1) ) { - $aImg->SetColor($this->iBackgroundColor); - $aImg->FilledRectangle($this->rect->x,$this->rect->y,$this->rect->xe,$this->rect->ye); - } + if( !(is_numeric($this->iBackgroundColor) && $this->iBackgroundColor==-1) ) { + $aImg->SetColor($this->iBackgroundColor); + $aImg->FilledRectangle($this->rect->x,$this->rect->y,$this->rect->xe,$this->rect->ye); + } - $aImg->SetColor($this->color); - $aImg->SetLineWeight($this->weight); + $aImg->SetColor($this->color); + $aImg->SetLineWeight($this->weight); - // Virtual function implemented by subclass - $this->DoPattern($aImg); + // Virtual function implemented by subclass + $this->DoPattern($aImg); - // Frame around the pattern area - if( $this->doframe ) - $aImg->Rectangle($this->rect->x,$this->rect->y,$this->rect->xe,$this->rect->ye); + // Frame around the pattern area + if( $this->doframe ) + $aImg->Rectangle($this->rect->x,$this->rect->y,$this->rect->xe,$this->rect->ye); } } @@ -105,14 +105,14 @@ class RectPattern { //===================================================================== class RectPatternSolid extends RectPattern { - function RectPatternSolid($aColor="black",$aWeight=1) { - parent::RectPattern($aColor,$aWeight); + function __construct($aColor="black",$aWeight=1) { + parent::__construct($aColor,$aWeight); } function DoPattern($aImg) { - $aImg->SetColor($this->color); - $aImg->FilledRectangle($this->rect->x,$this->rect->y, - $this->rect->xe,$this->rect->ye); + $aImg->SetColor($this->color); + $aImg->FilledRectangle($this->rect->x,$this->rect->y, + $this->rect->xe,$this->rect->ye); } } @@ -121,20 +121,20 @@ class RectPatternSolid extends RectPattern { // Implements horizontal line pattern //===================================================================== class RectPatternHor extends RectPattern { - - function RectPatternHor($aColor="black",$aWeight=1,$aLineSpacing=7) { - parent::RectPattern($aColor,$aWeight); - $this->linespacing = $aLineSpacing; + + function __construct($aColor="black",$aWeight=1,$aLineSpacing=7) { + parent::__construct($aColor,$aWeight); + $this->linespacing = $aLineSpacing; } - + function DoPattern($aImg) { - $x0 = $this->rect->x; - $x1 = $this->rect->xe; - $y = $this->rect->y; - while( $y < $this->rect->ye ) { - $aImg->Line($x0,$y,$x1,$y); - $y += $this->linespacing; - } + $x0 = $this->rect->x; + $x1 = $this->rect->xe; + $y = $this->rect->y; + while( $y < $this->rect->ye ) { + $aImg->Line($x0,$y,$x1,$y); + $y += $this->linespacing; + } } } @@ -143,23 +143,23 @@ class RectPatternHor extends RectPattern { // Implements vertical line pattern //===================================================================== class RectPatternVert extends RectPattern { - - function RectPatternVert($aColor="black",$aWeight=1,$aLineSpacing=7) { - parent::RectPattern($aColor,$aWeight); - $this->linespacing = $aLineSpacing; + + function __construct($aColor="black",$aWeight=1,$aLineSpacing=7) { + parent::__construct($aColor,$aWeight); + $this->linespacing = $aLineSpacing; } //-------------------- // Private methods // function DoPattern($aImg) { - $x = $this->rect->x; - $y0 = $this->rect->y; - $y1 = $this->rect->ye; - while( $x < $this->rect->xe ) { - $aImg->Line($x,$y0,$x,$y1); - $x += $this->linespacing; - } + $x = $this->rect->x; + $y0 = $this->rect->y; + $y1 = $this->rect->ye; + while( $x < $this->rect->xe ) { + $aImg->Line($x,$y0,$x,$y1); + $x += $this->linespacing; + } } } @@ -169,131 +169,131 @@ class RectPatternVert extends RectPattern { // Implements right diagonal pattern //===================================================================== class RectPatternRDiag extends RectPattern { - - function RectPatternRDiag($aColor="black",$aWeight=1,$aLineSpacing=12) { - parent::RectPattern($aColor,$aWeight); - $this->linespacing = $aLineSpacing; + + function __construct($aColor="black",$aWeight=1,$aLineSpacing=12) { + parent::__construct($aColor,$aWeight); + $this->linespacing = $aLineSpacing; } function DoPattern($aImg) { - // -------------------- - // | / / / / /| - // |/ / / / / | - // | / / / / | - // -------------------- - $xe = $this->rect->xe; - $ye = $this->rect->ye; - $x0 = $this->rect->x + round($this->linespacing/2); - $y0 = $this->rect->y; - $x1 = $this->rect->x; - $y1 = $this->rect->y + round($this->linespacing/2); + // -------------------- + // | / / / / /| + // |/ / / / / | + // | / / / / | + // -------------------- + $xe = $this->rect->xe; + $ye = $this->rect->ye; + $x0 = $this->rect->x + round($this->linespacing/2); + $y0 = $this->rect->y; + $x1 = $this->rect->x; + $y1 = $this->rect->y + round($this->linespacing/2); - while($x0<=$xe && $y1<=$ye) { - $aImg->Line($x0,$y0,$x1,$y1); - $x0 += $this->linespacing; - $y1 += $this->linespacing; - } + while($x0<=$xe && $y1<=$ye) { + $aImg->Line($x0,$y0,$x1,$y1); + $x0 += $this->linespacing; + $y1 += $this->linespacing; + } - if( $xe-$x1 > $ye-$y0 ) { - // Width larger than height - $x1 = $this->rect->x + ($y1-$ye); - $y1 = $ye; - $y0 = $this->rect->y; - while( $x0 <= $xe ) { - $aImg->Line($x0,$y0,$x1,$y1); - $x0 += $this->linespacing; - $x1 += $this->linespacing; - } - - $y0=$this->rect->y + ($x0-$xe); - $x0=$xe; - } - else { - // Height larger than width - $diff = $x0-$xe; - $y0 = $diff+$this->rect->y; - $x0 = $xe; - $x1 = $this->rect->x; - while( $y1 <= $ye ) { - $aImg->Line($x0,$y0,$x1,$y1); - $y1 += $this->linespacing; - $y0 += $this->linespacing; - } - - $diff = $y1-$ye; - $y1 = $ye; - $x1 = $diff + $this->rect->x; - } + if( $xe-$x1 > $ye-$y0 ) { + // Width larger than height + $x1 = $this->rect->x + ($y1-$ye); + $y1 = $ye; + $y0 = $this->rect->y; + while( $x0 <= $xe ) { + $aImg->Line($x0,$y0,$x1,$y1); + $x0 += $this->linespacing; + $x1 += $this->linespacing; + } + + $y0=$this->rect->y + ($x0-$xe); + $x0=$xe; + } + else { + // Height larger than width + $diff = $x0-$xe; + $y0 = $diff+$this->rect->y; + $x0 = $xe; + $x1 = $this->rect->x; + while( $y1 <= $ye ) { + $aImg->Line($x0,$y0,$x1,$y1); + $y1 += $this->linespacing; + $y0 += $this->linespacing; + } + + $diff = $y1-$ye; + $y1 = $ye; + $x1 = $diff + $this->rect->x; + } - while( $y0 <= $ye ) { - $aImg->Line($x0,$y0,$x1,$y1); - $y0 += $this->linespacing; - $x1 += $this->linespacing; - } + while( $y0 <= $ye ) { + $aImg->Line($x0,$y0,$x1,$y1); + $y0 += $this->linespacing; + $x1 += $this->linespacing; + } } } - + //===================================================================== // Class RectPatternLDiag // Implements left diagonal pattern //===================================================================== class RectPatternLDiag extends RectPattern { - - function RectPatternLDiag($aColor="black",$aWeight=1,$aLineSpacing=12) { - $this->linespacing = $aLineSpacing; - parent::RectPattern($aColor,$aWeight); + + function __construct($aColor="black",$aWeight=1,$aLineSpacing=12) { + $this->linespacing = $aLineSpacing; + parent::__construct($aColor,$aWeight); } function DoPattern($aImg) { - // -------------------- - // |\ \ \ \ \ | - // | \ \ \ \ \| - // | \ \ \ \ | - // |------------------| - $xe = $this->rect->xe; - $ye = $this->rect->ye; - $x0 = $this->rect->x + round($this->linespacing/2); - $y0 = $this->rect->ye; - $x1 = $this->rect->x; - $y1 = $this->rect->ye - round($this->linespacing/2); + // -------------------- + // |\ \ \ \ \ | + // | \ \ \ \ \| + // | \ \ \ \ | + // |------------------| + $xe = $this->rect->xe; + $ye = $this->rect->ye; + $x0 = $this->rect->x + round($this->linespacing/2); + $y0 = $this->rect->ye; + $x1 = $this->rect->x; + $y1 = $this->rect->ye - round($this->linespacing/2); - while($x0<=$xe && $y1>=$this->rect->y) { - $aImg->Line($x0,$y0,$x1,$y1); - $x0 += $this->linespacing; - $y1 -= $this->linespacing; - } - if( $xe-$x1 > $ye-$this->rect->y ) { - // Width larger than height - $x1 = $this->rect->x + ($this->rect->y-$y1); - $y0=$ye; $y1=$this->rect->y; - while( $x0 <= $xe ) { - $aImg->Line($x0,$y0,$x1,$y1); - $x0 += $this->linespacing; - $x1 += $this->linespacing; - } - - $y0=$this->rect->ye - ($x0-$xe); - $x0=$xe; - } - else { - // Height larger than width - $diff = $x0-$xe; - $y0 = $ye-$diff; - $x0 = $xe; - while( $y1 >= $this->rect->y ) { - $aImg->Line($x0,$y0,$x1,$y1); - $y0 -= $this->linespacing; - $y1 -= $this->linespacing; - } - $diff = $this->rect->y - $y1; - $x1 = $this->rect->x + $diff; - $y1 = $this->rect->y; - } - while( $y0 >= $this->rect->y ) { - $aImg->Line($x0,$y0,$x1,$y1); - $y0 -= $this->linespacing; - $x1 += $this->linespacing; - } + while($x0<=$xe && $y1>=$this->rect->y) { + $aImg->Line($x0,$y0,$x1,$y1); + $x0 += $this->linespacing; + $y1 -= $this->linespacing; + } + if( $xe-$x1 > $ye-$this->rect->y ) { + // Width larger than height + $x1 = $this->rect->x + ($this->rect->y-$y1); + $y0=$ye; $y1=$this->rect->y; + while( $x0 <= $xe ) { + $aImg->Line($x0,$y0,$x1,$y1); + $x0 += $this->linespacing; + $x1 += $this->linespacing; + } + + $y0=$this->rect->ye - ($x0-$xe); + $x0=$xe; + } + else { + // Height larger than width + $diff = $x0-$xe; + $y0 = $ye-$diff; + $x0 = $xe; + while( $y1 >= $this->rect->y ) { + $aImg->Line($x0,$y0,$x1,$y1); + $y0 -= $this->linespacing; + $y1 -= $this->linespacing; + } + $diff = $this->rect->y - $y1; + $x1 = $this->rect->x + $diff; + $y1 = $this->rect->y; + } + while( $y0 >= $this->rect->y ) { + $aImg->Line($x0,$y0,$x1,$y1); + $y0 -= $this->linespacing; + $x1 += $this->linespacing; + } } } @@ -307,110 +307,110 @@ class RectPattern3DPlane extends RectPattern { // top of the band. Specifies how fast the lines // converge. - function RectPattern3DPlane($aColor="black",$aWeight=1) { - parent::RectPattern($aColor,$aWeight); - $this->SetDensity(10); // Slightly larger default + function __construct($aColor="black",$aWeight=1) { + parent::__construct($aColor,$aWeight); + $this->SetDensity(10); // Slightly larger default } function SetHorizon($aHorizon) { - $this->alpha=$aHorizon; + $this->alpha=$aHorizon; } - + function DoPattern($aImg) { - // "Fake" a nice 3D grid-effect. - $x0 = $this->rect->x + $this->rect->w/2; - $y0 = $this->rect->y; - $x1 = $x0; - $y1 = $this->rect->ye; - $x0_right = $x0; - $x1_right = $x1; + // "Fake" a nice 3D grid-effect. + $x0 = $this->rect->x + $this->rect->w/2; + $y0 = $this->rect->y; + $x1 = $x0; + $y1 = $this->rect->ye; + $x0_right = $x0; + $x1_right = $x1; - // BTW "apa" means monkey in Swedish but is really a shortform for - // "alpha+a" which was the labels I used on paper when I derived the - // geometric to get the 3D perspective right. - // $apa is the height of the bounding rectangle plus the distance to the - // artifical horizon (alpha) - $apa = $this->rect->h + $this->alpha; + // BTW "apa" means monkey in Swedish but is really a shortform for + // "alpha+a" which was the labels I used on paper when I derived the + // geometric to get the 3D perspective right. + // $apa is the height of the bounding rectangle plus the distance to the + // artifical horizon (alpha) + $apa = $this->rect->h + $this->alpha; - // Three cases and three loops - // 1) The endpoint of the line ends on the bottom line - // 2) The endpoint ends on the side - // 3) Horizontal lines + // Three cases and three loops + // 1) The endpoint of the line ends on the bottom line + // 2) The endpoint ends on the side + // 3) Horizontal lines - // Endpoint falls on bottom line - $middle=$this->rect->x + $this->rect->w/2; - $dist=$this->linespacing; - $factor=$this->alpha /($apa); - while($x1>$this->rect->x) { - $aImg->Line($x0,$y0,$x1,$y1); - $aImg->Line($x0_right,$y0,$x1_right,$y1); - $x1 = $middle - $dist; - $x0 = $middle - $dist * $factor; - $x1_right = $middle + $dist; - $x0_right = $middle + $dist * $factor; - $dist += $this->linespacing; - } + // Endpoint falls on bottom line + $middle=$this->rect->x + $this->rect->w/2; + $dist=$this->linespacing; + $factor=$this->alpha /($apa); + while($x1>$this->rect->x) { + $aImg->Line($x0,$y0,$x1,$y1); + $aImg->Line($x0_right,$y0,$x1_right,$y1); + $x1 = $middle - $dist; + $x0 = $middle - $dist * $factor; + $x1_right = $middle + $dist; + $x0_right = $middle + $dist * $factor; + $dist += $this->linespacing; + } - // Endpoint falls on sides - $dist -= $this->linespacing; - $d=$this->rect->w/2; - $c = $apa - $d*$apa/$dist; - while( $x0>$this->rect->x ) { - $aImg->Line($x0,$y0,$this->rect->x,$this->rect->ye-$c); - $aImg->Line($x0_right,$y0,$this->rect->xe,$this->rect->ye-$c); - $dist += $this->linespacing; - $x0 = $middle - $dist * $factor; - $x1 = $middle - $dist; - $x0_right = $middle + $dist * $factor; - $c = $apa - $d*$apa/$dist; - } - - // Horizontal lines - // They need some serious consideration since they are a function - // of perspective depth (alpha) and density (linespacing) - $x0=$this->rect->x; - $x1=$this->rect->xe; - $y=$this->rect->ye; - - // The first line is drawn directly. Makes the loop below slightly - // more readable. - $aImg->Line($x0,$y,$x1,$y); - $hls = $this->linespacing; - - // A correction factor for vertical "brick" line spacing to account for - // a) the difference in number of pixels hor vs vert - // b) visual apperance to make the first layer of "bricks" look more - // square. - $vls = $this->linespacing*0.6; - - $ds = $hls*($apa-$vls)/$apa; - // Get the slope for the "perspective line" going from bottom right - // corner to top left corner of the "first" brick. - - // Uncomment the following lines if you want to get a visual understanding - // of what this helpline does. BTW this mimics the way you would get the - // perspective right when drawing on paper. - /* - $x0 = $middle; - $y0 = $this->rect->ye; - $len=floor(($this->rect->ye-$this->rect->y)/$vls); - $x1 = $middle+round($len*$ds); - $y1 = $this->rect->ye-$len*$vls; - $aImg->PushColor("red"); - $aImg->Line($x0,$y0,$x1,$y1); - $aImg->PopColor(); - */ - - $y -= $vls; - $k=($this->rect->ye-($this->rect->ye-$vls))/($middle-($middle-$ds)); - $dist = $hls; - while( $y>$this->rect->y ) { - $aImg->Line($this->rect->x,$y,$this->rect->xe,$y); - $adj = $k*$dist/(1+$dist*$k/$apa); - if( $adj < 2 ) $adj=1; - $y = $this->rect->ye - round($adj); - $dist += $hls; - } + // Endpoint falls on sides + $dist -= $this->linespacing; + $d=$this->rect->w/2; + $c = $apa - $d*$apa/$dist; + while( $x0>$this->rect->x ) { + $aImg->Line($x0,$y0,$this->rect->x,$this->rect->ye-$c); + $aImg->Line($x0_right,$y0,$this->rect->xe,$this->rect->ye-$c); + $dist += $this->linespacing; + $x0 = $middle - $dist * $factor; + $x1 = $middle - $dist; + $x0_right = $middle + $dist * $factor; + $c = $apa - $d*$apa/$dist; + } + + // Horizontal lines + // They need some serious consideration since they are a function + // of perspective depth (alpha) and density (linespacing) + $x0=$this->rect->x; + $x1=$this->rect->xe; + $y=$this->rect->ye; + + // The first line is drawn directly. Makes the loop below slightly + // more readable. + $aImg->Line($x0,$y,$x1,$y); + $hls = $this->linespacing; + + // A correction factor for vertical "brick" line spacing to account for + // a) the difference in number of pixels hor vs vert + // b) visual apperance to make the first layer of "bricks" look more + // square. + $vls = $this->linespacing*0.6; + + $ds = $hls*($apa-$vls)/$apa; + // Get the slope for the "perspective line" going from bottom right + // corner to top left corner of the "first" brick. + + // Uncomment the following lines if you want to get a visual understanding + // of what this helpline does. BTW this mimics the way you would get the + // perspective right when drawing on paper. + /* + $x0 = $middle; + $y0 = $this->rect->ye; + $len=floor(($this->rect->ye-$this->rect->y)/$vls); + $x1 = $middle+round($len*$ds); + $y1 = $this->rect->ye-$len*$vls; + $aImg->PushColor("red"); + $aImg->Line($x0,$y0,$x1,$y1); + $aImg->PopColor(); + */ + + $y -= $vls; + $k=($this->rect->ye-($this->rect->ye-$vls))/($middle-($middle-$ds)); + $dist = $hls; + while( $y>$this->rect->y ) { + $aImg->Line($this->rect->x,$y,$this->rect->xe,$y); + $adj = $k*$dist/(1+$dist*$k/$apa); + if( $adj < 2 ) $adj=1; + $y = $this->rect->ye - round($adj); + $dist += $hls; + } } } @@ -421,31 +421,31 @@ class RectPattern3DPlane extends RectPattern { class RectPatternCross extends RectPattern { private $vert=null; private $hor=null; - function RectPatternCross($aColor="black",$aWeight=1) { - parent::RectPattern($aColor,$aWeight); - $this->vert = new RectPatternVert($aColor,$aWeight); - $this->hor = new RectPatternHor($aColor,$aWeight); + function __construct($aColor="black",$aWeight=1) { + parent::__construct($aColor,$aWeight); + $this->vert = new RectPatternVert($aColor,$aWeight); + $this->hor = new RectPatternHor($aColor,$aWeight); } function SetOrder($aDepth) { - $this->vert->SetOrder($aDepth); - $this->hor->SetOrder($aDepth); + $this->vert->SetOrder($aDepth); + $this->hor->SetOrder($aDepth); } function SetPos($aRect) { - parent::SetPos($aRect); - $this->vert->SetPos($aRect); - $this->hor->SetPos($aRect); + parent::SetPos($aRect); + $this->vert->SetPos($aRect); + $this->hor->SetPos($aRect); } function SetDensity($aDens) { - $this->vert->SetDensity($aDens); - $this->hor->SetDensity($aDens); + $this->vert->SetDensity($aDens); + $this->hor->SetDensity($aDens); } function DoPattern($aImg) { - $this->vert->DoPattern($aImg); - $this->hor->DoPattern($aImg); + $this->vert->DoPattern($aImg); + $this->hor->DoPattern($aImg); } } @@ -457,74 +457,74 @@ class RectPatternCross extends RectPattern { class RectPatternDiagCross extends RectPattern { private $left=null; private $right=null; - function RectPatternDiagCross($aColor="black",$aWeight=1) { - parent::RectPattern($aColor,$aWeight); - $this->right = new RectPatternRDiag($aColor,$aWeight); - $this->left = new RectPatternLDiag($aColor,$aWeight); + function __construct($aColor="black",$aWeight=1) { + parent::__construct($aColor,$aWeight); + $this->right = new RectPatternRDiag($aColor,$aWeight); + $this->left = new RectPatternLDiag($aColor,$aWeight); } function SetOrder($aDepth) { - $this->left->SetOrder($aDepth); - $this->right->SetOrder($aDepth); + $this->left->SetOrder($aDepth); + $this->right->SetOrder($aDepth); } function SetPos($aRect) { - parent::SetPos($aRect); - $this->left->SetPos($aRect); - $this->right->SetPos($aRect); + parent::SetPos($aRect); + $this->left->SetPos($aRect); + $this->right->SetPos($aRect); } function SetDensity($aDens) { - $this->left->SetDensity($aDens); - $this->right->SetDensity($aDens); + $this->left->SetDensity($aDens); + $this->right->SetDensity($aDens); } function DoPattern($aImg) { - $this->left->DoPattern($aImg); - $this->right->DoPattern($aImg); + $this->left->DoPattern($aImg); + $this->right->DoPattern($aImg); } } //===================================================================== // Class RectPatternFactory -// Factory class for rectangular pattern +// Factory class for rectangular pattern //===================================================================== class RectPatternFactory { - function RectPatternFactory() { - // Empty + function __construct() { + // Empty } function Create($aPattern,$aColor,$aWeight=1) { - switch($aPattern) { - case BAND_RDIAG: - $obj = new RectPatternRDiag($aColor,$aWeight); - break; - case BAND_LDIAG: - $obj = new RectPatternLDiag($aColor,$aWeight); - break; - case BAND_SOLID: - $obj = new RectPatternSolid($aColor,$aWeight); - break; - case BAND_VLINE: - $obj = new RectPatternVert($aColor,$aWeight); - break; - case BAND_HLINE: - $obj = new RectPatternHor($aColor,$aWeight); - break; - case BAND_3DPLANE: - $obj = new RectPattern3DPlane($aColor,$aWeight); - break; - case BAND_HVCROSS: - $obj = new RectPatternCross($aColor,$aWeight); - break; - case BAND_DIAGCROSS: - $obj = new RectPatternDiagCross($aColor,$aWeight); - break; - default: - JpGraphError::RaiseL(16003,$aPattern); -//(" Unknown pattern specification ($aPattern)"); - } - return $obj; + switch($aPattern) { + case BAND_RDIAG: + $obj = new RectPatternRDiag($aColor,$aWeight); + break; + case BAND_LDIAG: + $obj = new RectPatternLDiag($aColor,$aWeight); + break; + case BAND_SOLID: + $obj = new RectPatternSolid($aColor,$aWeight); + break; + case BAND_VLINE: + $obj = new RectPatternVert($aColor,$aWeight); + break; + case BAND_HLINE: + $obj = new RectPatternHor($aColor,$aWeight); + break; + case BAND_3DPLANE: + $obj = new RectPattern3DPlane($aColor,$aWeight); + break; + case BAND_HVCROSS: + $obj = new RectPatternCross($aColor,$aWeight); + break; + case BAND_DIAGCROSS: + $obj = new RectPatternDiagCross($aColor,$aWeight); + break; + default: + JpGraphError::RaiseL(16003,$aPattern); + //(" Unknown pattern specification ($aPattern)"); + } + return $obj; } } @@ -540,94 +540,94 @@ class PlotBand { private $prect=null; private $dir, $min, $max; - function PlotBand($aDir,$aPattern,$aMin,$aMax,$aColor="black",$aWeight=1,$aDepth=DEPTH_BACK) { - $f = new RectPatternFactory(); - $this->prect = $f->Create($aPattern,$aColor,$aWeight); - if( is_numeric($aMin) && is_numeric($aMax) && ($aMin > $aMax) ) - JpGraphError::RaiseL(16004); -//('Min value for plotband is larger than specified max value. Please correct.'); - $this->dir = $aDir; - $this->min = $aMin; - $this->max = $aMax; - $this->depth=$aDepth; + function __construct($aDir,$aPattern,$aMin,$aMax,$aColor="black",$aWeight=1,$aDepth=DEPTH_BACK) { + $f = new RectPatternFactory(); + $this->prect = $f->Create($aPattern,$aColor,$aWeight); + if( is_numeric($aMin) && is_numeric($aMax) && ($aMin > $aMax) ) + JpGraphError::RaiseL(16004); + //('Min value for plotband is larger than specified max value. Please correct.'); + $this->dir = $aDir; + $this->min = $aMin; + $this->max = $aMax; + $this->depth=$aDepth; } - + // Set position. aRect contains absolute image coordinates function SetPos($aRect) { - assert( $this->prect != null ) ; - $this->prect->SetPos($aRect); + assert( $this->prect != null ) ; + $this->prect->SetPos($aRect); } - + function ShowFrame($aFlag=true) { - $this->prect->ShowFrame($aFlag); + $this->prect->ShowFrame($aFlag); } // Set z-order. In front of pplot or in the back function SetOrder($aDepth) { - $this->depth=$aDepth; + $this->depth=$aDepth; } - + function SetDensity($aDens) { - $this->prect->SetDensity($aDens); + $this->prect->SetDensity($aDens); } - + function GetDir() { - return $this->dir; + return $this->dir; } - + function GetMin() { - return $this->min; + return $this->min; } - + function GetMax() { - return $this->max; + return $this->max; } function PreStrokeAdjust($aGraph) { - // Nothing to do + // Nothing to do } - + // Display band function Stroke($aImg,$aXScale,$aYScale) { - assert( $this->prect != null ) ; - if( $this->dir == HORIZONTAL ) { - if( $this->min === 'min' ) $this->min = $aYScale->GetMinVal(); - if( $this->max === 'max' ) $this->max = $aYScale->GetMaxVal(); + assert( $this->prect != null ) ; + if( $this->dir == HORIZONTAL ) { + if( $this->min === 'min' ) $this->min = $aYScale->GetMinVal(); + if( $this->max === 'max' ) $this->max = $aYScale->GetMaxVal(); // Only draw the bar if it actually appears in the range if ($this->min < $aYScale->GetMaxVal() && $this->max > $aYScale->GetMinVal()) { - - // Trucate to limit of axis - $this->min = max($this->min, $aYScale->GetMinVal()); - $this->max = min($this->max, $aYScale->GetMaxVal()); + + // Trucate to limit of axis + $this->min = max($this->min, $aYScale->GetMinVal()); + $this->max = min($this->max, $aYScale->GetMaxVal()); - $x=$aXScale->scale_abs[0]; - $y=$aYScale->Translate($this->max); - $width=$aXScale->scale_abs[1]-$aXScale->scale_abs[0]+1; - $height=abs($y-$aYScale->Translate($this->min))+1; - $this->prect->SetPos(new Rectangle($x,$y,$width,$height)); - $this->prect->Stroke($aImg); + $x=$aXScale->scale_abs[0]; + $y=$aYScale->Translate($this->max); + $width=$aXScale->scale_abs[1]-$aXScale->scale_abs[0]+1; + $height=abs($y-$aYScale->Translate($this->min))+1; + $this->prect->SetPos(new Rectangle($x,$y,$width,$height)); + $this->prect->Stroke($aImg); } - } - else { // VERTICAL - if( $this->min === 'min' ) $this->min = $aXScale->GetMinVal(); - if( $this->max === 'max' ) $this->max = $aXScale->GetMaxVal(); - + } + else { // VERTICAL + if( $this->min === 'min' ) $this->min = $aXScale->GetMinVal(); + if( $this->max === 'max' ) $this->max = $aXScale->GetMaxVal(); + // Only draw the bar if it actually appears in the range - if ($this->min < $aXScale->GetMaxVal() && $this->max > $aXScale->GetMinVal()) { - - // Trucate to limit of axis - $this->min = max($this->min, $aXScale->GetMinVal()); - $this->max = min($this->max, $aXScale->GetMaxVal()); + if ($this->min < $aXScale->GetMaxVal() && $this->max > $aXScale->GetMinVal()) { + + // Trucate to limit of axis + $this->min = max($this->min, $aXScale->GetMinVal()); + $this->max = min($this->max, $aXScale->GetMaxVal()); - $y=$aYScale->scale_abs[1]; - $x=$aXScale->Translate($this->min); - $height=abs($aYScale->scale_abs[1]-$aYScale->scale_abs[0]); - $width=abs($x-$aXScale->Translate($this->max)); - $this->prect->SetPos(new Rectangle($x,$y,$width,$height)); - $this->prect->Stroke($aImg); + $y=$aYScale->scale_abs[1]; + $x=$aXScale->Translate($this->min); + $height=abs($aYScale->scale_abs[1]-$aYScale->scale_abs[0]); + $width=abs($x-$aXScale->Translate($this->max)); + $this->prect->SetPos(new Rectangle($x,$y,$width,$height)); + $this->prect->Stroke($aImg); } - } + } } } diff --git a/src/classes/jpgraph/jpgraph_plotmark.inc.php b/src/classes/jpgraph/jpgraph_plotmark.inc.php index c8a381a..78a08cf 100644 --- a/src/classes/jpgraph/jpgraph_plotmark.inc.php +++ b/src/classes/jpgraph/jpgraph_plotmark.inc.php @@ -1,9 +1,9 @@ title = new Text(); - $this->title->Hide(); - $this->csimareas = ''; - $this->type=-1; + //-------------- + // CONSTRUCTOR + function __construct() { + $this->title = new Text(); + $this->title->Hide(); + $this->csimareas = ''; + $this->type=-1; } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS function SetType($aType,$aFileName='',$aScale=1.0) { - $this->type = $aType; - if( $aType == MARK_IMG && $aFileName=='' ) { - JpGraphError::RaiseL(23003);//('A filename must be specified if you set the mark type to MARK_IMG.'); - } - $this->iFileName = $aFileName; - $this->iScale = $aScale; + $this->type = $aType; + if( $aType == MARK_IMG && $aFileName=='' ) { + JpGraphError::RaiseL(23003);//('A filename must be specified if you set the mark type to MARK_IMG.'); + } + $this->iFileName = $aFileName; + $this->iScale = $aScale; } - + function SetCallback($aFunc) { - $this->iFormatCallback = $aFunc; + $this->iFormatCallback = $aFunc; } function SetCallbackYX($aFunc) { - $this->iFormatCallback2 = $aFunc; + $this->iFormatCallback2 = $aFunc; } - + function GetType() { - return $this->type; + return $this->type; } - + function SetColor($aColor) { - $this->color=$aColor; + $this->color=$aColor; } - + function SetFillColor($aFillColor) { - $this->fill_color = $aFillColor; + $this->fill_color = $aFillColor; } function SetWeight($aWeight) { - $this->weight = $aWeight; + $this->weight = $aWeight; } // Synonym for SetWidth() function SetSize($aWidth) { - $this->width=$aWidth; + $this->width=$aWidth; } - + function SetWidth($aWidth) { - $this->width=$aWidth; + $this->width=$aWidth; } function SetDefaultWidth() { - switch( $this->type ) { - case MARK_CIRCLE: - case MARK_FILLEDCIRCLE: - $this->width=4; - break; - default: - $this->width=7; - } + switch( $this->type ) { + case MARK_CIRCLE: + case MARK_FILLEDCIRCLE: + $this->width=4; + break; + default: + $this->width=7; + } } - + function GetWidth() { - return $this->width; + return $this->width; } - + function Hide($aHide=true) { - $this->show = !$aHide; + $this->show = !$aHide; } - + function Show($aShow=true) { - $this->show = $aShow; + $this->show = $aShow; } function SetCSIMAltVal($aY,$aX='') { - $this->yvalue=$aY; - $this->xvalue=$aX; + $this->yvalue=$aY; + $this->xvalue=$aX; } - + function SetCSIMTarget($aTarget,$aWinTarget='') { $this->csimtarget=$aTarget; $this->csimwintarget=$aWinTarget; } - + function SetCSIMAlt($aAlt) { $this->csimalt=$aAlt; } - + function GetCSIMAreas(){ return $this->csimareas; } - + function AddCSIMPoly($aPts) { $coords = round($aPts[0]).", ".round($aPts[1]); $n = count($aPts)/2; for( $i=1; $i < $n; ++$i){ $coords .= ", ".round($aPts[2*$i]).", ".round($aPts[2*$i+1]); } - $this->csimareas=""; + $this->csimareas=""; if( !empty($this->csimtarget) ) { - $this->csimareas .= "csimtarget)."\""; + $this->csimareas .= "csimtarget)."\""; - if( !empty($this->csimwintarget) ) { - $this->csimareas .= " target=\"".$this->csimwintarget."\" "; - } + if( !empty($this->csimwintarget) ) { + $this->csimareas .= " target=\"".$this->csimwintarget."\" "; + } - if( !empty($this->csimalt) ) { - $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\""; - } - $this->csimareas .= " />\n"; - } - } - - function AddCSIMCircle($x,$y,$r) { - $x = round($x); $y=round($y); $r=round($r); - $this->csimareas=""; - if( !empty($this->csimtarget) ) { - $this->csimareas .= "csimtarget)."\""; - - if( !empty($this->csimwintarget) ) { - $this->csimareas .= " target=\"".$this->csimwintarget."\" "; - } - - if( !empty($this->csimalt) ) { - $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; + if( !empty($this->csimalt) ) { + $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\""; + } + $this->csimareas .= " />\n"; } } - + + function AddCSIMCircle($x,$y,$r) { + $x = round($x); $y=round($y); $r=round($r); + $this->csimareas=""; + if( !empty($this->csimtarget) ) { + $this->csimareas .= "csimtarget)."\""; + + if( !empty($this->csimwintarget) ) { + $this->csimareas .= " target=\"".$this->csimwintarget."\" "; + } + + if( !empty($this->csimalt) ) { + $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } + } + function Stroke($img,$x,$y) { - if( !$this->show ) return; + if( !$this->show ) return; - if( $this->iFormatCallback != '' || $this->iFormatCallback2 != '' ) { + if( $this->iFormatCallback != '' || $this->iFormatCallback2 != '' ) { - if( $this->iFormatCallback != '' ) { - $f = $this->iFormatCallback; - list($width,$color,$fcolor) = call_user_func($f,$this->yvalue); - $filename = $this->iFileName; - $imgscale = $this->iScale; - } - else { - $f = $this->iFormatCallback2; - list($width,$color,$fcolor,$filename,$imgscale) = call_user_func($f,$this->yvalue,$this->xvalue); - if( $filename=="" ) $filename = $this->iFileName; - if( $imgscale=="" ) $imgscale = $this->iScale; - } + if( $this->iFormatCallback != '' ) { + $f = $this->iFormatCallback; + list($width,$color,$fcolor) = call_user_func($f,$this->yvalue); + $filename = $this->iFileName; + $imgscale = $this->iScale; + } + else { + $f = $this->iFormatCallback2; + list($width,$color,$fcolor,$filename,$imgscale) = call_user_func($f,$this->yvalue,$this->xvalue); + if( $filename=="" ) $filename = $this->iFileName; + if( $imgscale=="" ) $imgscale = $this->iScale; + } - if( $width=="" ) $width = $this->width; - if( $color=="" ) $color = $this->color; - if( $fcolor=="" ) $fcolor = $this->fill_color; + if( $width=="" ) $width = $this->width; + if( $color=="" ) $color = $this->color; + if( $fcolor=="" ) $fcolor = $this->fill_color; - } - else { - $fcolor = $this->fill_color; - $color = $this->color; - $width = $this->width; - $filename = $this->iFileName; - $imgscale = $this->iScale; - } + } + else { + $fcolor = $this->fill_color; + $color = $this->color; + $width = $this->width; + $filename = $this->iFileName; + $imgscale = $this->iScale; + } - if( $this->type == MARK_IMG || - ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4 ) || - $this->type >= MARK_IMG_PUSHPIN ) { + if( $this->type == MARK_IMG || + ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4 ) || + $this->type >= MARK_IMG_PUSHPIN ) { - // Note: For the builtin images we use the "filename" parameter - // to denote the color - $anchor_x = 0.5; - $anchor_y = 0.5; - switch( $this->type ) { - case MARK_FLAG1: - case MARK_FLAG2: - case MARK_FLAG3: - case MARK_FLAG4: - $this->markimg = FlagCache::GetFlagImgByName($this->type-MARK_FLAG1+1,$filename); - break; + // Note: For the builtin images we use the "filename" parameter + // to denote the color + $anchor_x = 0.5; + $anchor_y = 0.5; + switch( $this->type ) { + case MARK_FLAG1: + case MARK_FLAG2: + case MARK_FLAG3: + case MARK_FLAG4: + $this->markimg = FlagCache::GetFlagImgByName($this->type-MARK_FLAG1+1,$filename); + break; - case MARK_IMG : - // Load an image and use that as a marker - // Small optimization, if we have already read an image don't - // waste time reading it again. - if( $this->markimg == '' || !($this->oldfilename === $filename) ) { - $this->markimg = Graph::LoadBkgImage('',$filename); - $this->oldfilename = $filename ; - } - break; + case MARK_IMG : + // Load an image and use that as a marker + // Small optimization, if we have already read an image don't + // waste time reading it again. + if( $this->markimg == '' || !($this->oldfilename === $filename) ) { + $this->markimg = Graph::LoadBkgImage('',$filename); + $this->oldfilename = $filename ; + } + break; - case MARK_IMG_PUSHPIN: - case MARK_IMG_SPUSHPIN: - case MARK_IMG_LPUSHPIN: - if( $this->imgdata_pushpins == null ) { - require_once 'imgdata_pushpins.inc.php'; - $this->imgdata_pushpins = new ImgData_PushPins(); - } - $this->markimg = $this->imgdata_pushpins->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_pushpins->GetAnchor(); - break; + case MARK_IMG_PUSHPIN: + case MARK_IMG_SPUSHPIN: + case MARK_IMG_LPUSHPIN: + if( $this->imgdata_pushpins == null ) { + require_once 'imgdata_pushpins.inc.php'; + $this->imgdata_pushpins = new ImgData_PushPins(); + } + $this->markimg = $this->imgdata_pushpins->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_pushpins->GetAnchor(); + break; - case MARK_IMG_SQUARE: - if( $this->imgdata_squares == null ) { - require_once 'imgdata_squares.inc.php'; - $this->imgdata_squares = new ImgData_Squares(); - } - $this->markimg = $this->imgdata_squares->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_squares->GetAnchor(); - break; + case MARK_IMG_SQUARE: + if( $this->imgdata_squares == null ) { + require_once 'imgdata_squares.inc.php'; + $this->imgdata_squares = new ImgData_Squares(); + } + $this->markimg = $this->imgdata_squares->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_squares->GetAnchor(); + break; - case MARK_IMG_STAR: - if( $this->imgdata_stars == null ) { - require_once 'imgdata_stars.inc.php'; - $this->imgdata_stars = new ImgData_Stars(); - } - $this->markimg = $this->imgdata_stars->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_stars->GetAnchor(); - break; + case MARK_IMG_STAR: + if( $this->imgdata_stars == null ) { + require_once 'imgdata_stars.inc.php'; + $this->imgdata_stars = new ImgData_Stars(); + } + $this->markimg = $this->imgdata_stars->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_stars->GetAnchor(); + break; - case MARK_IMG_BEVEL: - if( $this->imgdata_bevels == null ) { - require_once 'imgdata_bevels.inc.php'; - $this->imgdata_bevels = new ImgData_Bevels(); - } - $this->markimg = $this->imgdata_bevels->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_bevels->GetAnchor(); - break; + case MARK_IMG_BEVEL: + if( $this->imgdata_bevels == null ) { + require_once 'imgdata_bevels.inc.php'; + $this->imgdata_bevels = new ImgData_Bevels(); + } + $this->markimg = $this->imgdata_bevels->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_bevels->GetAnchor(); + break; - case MARK_IMG_DIAMOND: - if( $this->imgdata_diamonds == null ) { - require_once 'imgdata_diamonds.inc.php'; - $this->imgdata_diamonds = new ImgData_Diamonds(); - } - $this->markimg = $this->imgdata_diamonds->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_diamonds->GetAnchor(); - break; + case MARK_IMG_DIAMOND: + if( $this->imgdata_diamonds == null ) { + require_once 'imgdata_diamonds.inc.php'; + $this->imgdata_diamonds = new ImgData_Diamonds(); + } + $this->markimg = $this->imgdata_diamonds->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_diamonds->GetAnchor(); + break; - case MARK_IMG_BALL: - case MARK_IMG_SBALL: - case MARK_IMG_MBALL: - case MARK_IMG_LBALL: - if( $this->imgdata_balls == null ) { - require_once 'imgdata_balls.inc.php'; - $this->imgdata_balls = new ImgData_Balls(); - } - $this->markimg = $this->imgdata_balls->GetImg($this->type,$filename); - list($anchor_x,$anchor_y) = $this->imgdata_balls->GetAnchor(); - break; - } + case MARK_IMG_BALL: + case MARK_IMG_SBALL: + case MARK_IMG_MBALL: + case MARK_IMG_LBALL: + if( $this->imgdata_balls == null ) { + require_once 'imgdata_balls.inc.php'; + $this->imgdata_balls = new ImgData_Balls(); + } + $this->markimg = $this->imgdata_balls->GetImg($this->type,$filename); + list($anchor_x,$anchor_y) = $this->imgdata_balls->GetAnchor(); + break; + } - $w = $img->GetWidth($this->markimg); - $h = $img->GetHeight($this->markimg); - - $dw = round($imgscale * $w ); - $dh = round($imgscale * $h ); + $w = $img->GetWidth($this->markimg); + $h = $img->GetHeight($this->markimg); + + $dw = round($imgscale * $w ); + $dh = round($imgscale * $h ); - // Do potential rotation - list($x,$y) = $img->Rotate($x,$y); + // Do potential rotation + list($x,$y) = $img->Rotate($x,$y); - $dx = round($x-$dw*$anchor_x); - $dy = round($y-$dh*$anchor_y); - - $this->width = max($dx,$dy); - - $img->Copy($this->markimg,$dx,$dy,0,0,$dw,$dh,$w,$h); - if( !empty($this->csimtarget) ) { - $this->csimareas = "csimtarget)."\""; - - if( !empty($this->csimwintarget) ) { - $this->csimareas .= " target=\"".$this->csimwintarget."\" "; - } + $dx = round($x-$dw*$anchor_x); + $dy = round($y-$dh*$anchor_y); + + $this->width = max($dx,$dy); + + $img->Copy($this->markimg,$dx,$dy,0,0,$dw,$dh,$w,$h); + if( !empty($this->csimtarget) ) { + $this->csimareas = "csimtarget)."\""; - if( !empty($this->csimalt) ) { - $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); - $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; - } - $this->csimareas .= " />\n"; - } - - // Stroke title - $this->title->Align("center","top"); - $this->title->Stroke($img,$x,$y+round($dh/2)); - return; - } + if( !empty($this->csimwintarget) ) { + $this->csimareas .= " target=\"".$this->csimwintarget."\" "; + } - $weight = $this->weight; - $dx=round($width/2,0); - $dy=round($width/2,0); - $pts=0; + if( !empty($this->csimalt) ) { + $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); + $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; + } + $this->csimareas .= " />\n"; + } + + // Stroke title + $this->title->Align("center","top"); + $this->title->Stroke($img,$x,$y+round($dh/2)); + return; + } - switch( $this->type ) { - case MARK_SQUARE: - $c[]=$x-$dx;$c[]=$y-$dy; - $c[]=$x+$dx;$c[]=$y-$dy; - $c[]=$x+$dx;$c[]=$y+$dy; - $c[]=$x-$dx;$c[]=$y+$dy; - $c[]=$x-$dx;$c[]=$y-$dy; - $pts=5; - break; - case MARK_UTRIANGLE: - ++$dx;++$dy; - $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx - $c[]=$x;$c[]=$y-0.87*$dy; - $c[]=$x+$dx;$c[]=$y+0.87*$dy; - $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx - $pts=4; - break; - case MARK_DTRIANGLE: - ++$dx;++$dy; - $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx - $c[]=$x-$dx;$c[]=$y-0.87*$dy; - $c[]=$x+$dx;$c[]=$y-0.87*$dy; - $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx - $pts=4; - break; - case MARK_DIAMOND: - $c[]=$x;$c[]=$y+$dy; - $c[]=$x-$dx;$c[]=$y; - $c[]=$x;$c[]=$y-$dy; - $c[]=$x+$dx;$c[]=$y; - $c[]=$x;$c[]=$y+$dy; - $pts=5; - break; - case MARK_LEFTTRIANGLE: - $c[]=$x;$c[]=$y; - $c[]=$x;$c[]=$y+2*$dy; - $c[]=$x+$dx*2;$c[]=$y; - $c[]=$x;$c[]=$y; - $pts=4; - break; - case MARK_RIGHTTRIANGLE: - $c[]=$x-$dx*2;$c[]=$y; - $c[]=$x;$c[]=$y+2*$dy; - $c[]=$x;$c[]=$y; - $c[]=$x-$dx*2;$c[]=$y; - $pts=4; - break; - case MARK_FLASH: - $dy *= 2; - $c[]=$x+$dx/2; $c[]=$y-$dy; - $c[]=$x-$dx+$dx/2; $c[]=$y+$dy*0.7-$dy; - $c[]=$x+$dx/2; $c[]=$y+$dy*1.3-$dy; - $c[]=$x-$dx+$dx/2; $c[]=$y+2*$dy-$dy; - $img->SetLineWeight($weight); - $img->SetColor($color); - $img->Polygon($c); - $img->SetLineWeight(1); - $this->AddCSIMPoly($c); - break; - } + $weight = $this->weight; + $dx=round($width/2,0); + $dy=round($width/2,0); + $pts=0; - if( $pts>0 ) { - $this->AddCSIMPoly($c); - $img->SetLineWeight($weight); - $img->SetColor($fcolor); - $img->FilledPolygon($c); - $img->SetColor($color); - $img->Polygon($c); - $img->SetLineWeight(1); - } - elseif( $this->type==MARK_CIRCLE ) { - $img->SetColor($color); - $img->Circle($x,$y,$width); - $this->AddCSIMCircle($x,$y,$width); - } - elseif( $this->type==MARK_FILLEDCIRCLE ) { - $img->SetColor($fcolor); - $img->FilledCircle($x,$y,$width); - $img->SetColor($color); - $img->Circle($x,$y,$width); - $this->AddCSIMCircle($x,$y,$width); - } - elseif( $this->type==MARK_CROSS ) { - // Oversize by a pixel to match the X - $img->SetColor($color); - $img->SetLineWeight($weight); - $img->Line($x,$y+$dy+1,$x,$y-$dy-1); - $img->Line($x-$dx-1,$y,$x+$dx+1,$y); - $this->AddCSIMCircle($x,$y,$dx); - } - elseif( $this->type==MARK_X ) { - $img->SetColor($color); - $img->SetLineWeight($weight); - $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); - $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); - $this->AddCSIMCircle($x,$y,$dx+$dy); - } - elseif( $this->type==MARK_STAR ) { - $img->SetColor($color); - $img->SetLineWeight($weight); - $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); - $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); - // Oversize by a pixel to match the X - $img->Line($x,$y+$dy+1,$x,$y-$dy-1); - $img->Line($x-$dx-1,$y,$x+$dx+1,$y); - $this->AddCSIMCircle($x,$y,$dx+$dy); - } - - // Stroke title - $this->title->Align("center","center"); - $this->title->Stroke($img,$x,$y); + switch( $this->type ) { + case MARK_SQUARE: + $c[]=$x-$dx;$c[]=$y-$dy; + $c[]=$x+$dx;$c[]=$y-$dy; + $c[]=$x+$dx;$c[]=$y+$dy; + $c[]=$x-$dx;$c[]=$y+$dy; + $c[]=$x-$dx;$c[]=$y-$dy; + $pts=5; + break; + case MARK_UTRIANGLE: + ++$dx;++$dy; + $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx + $c[]=$x;$c[]=$y-0.87*$dy; + $c[]=$x+$dx;$c[]=$y+0.87*$dy; + $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx + $pts=4; + break; + case MARK_DTRIANGLE: + ++$dx;++$dy; + $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx + $c[]=$x-$dx;$c[]=$y-0.87*$dy; + $c[]=$x+$dx;$c[]=$y-0.87*$dy; + $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx + $pts=4; + break; + case MARK_DIAMOND: + $c[]=$x;$c[]=$y+$dy; + $c[]=$x-$dx;$c[]=$y; + $c[]=$x;$c[]=$y-$dy; + $c[]=$x+$dx;$c[]=$y; + $c[]=$x;$c[]=$y+$dy; + $pts=5; + break; + case MARK_LEFTTRIANGLE: + $c[]=$x;$c[]=$y; + $c[]=$x;$c[]=$y+2*$dy; + $c[]=$x+$dx*2;$c[]=$y; + $c[]=$x;$c[]=$y; + $pts=4; + break; + case MARK_RIGHTTRIANGLE: + $c[]=$x-$dx*2;$c[]=$y; + $c[]=$x;$c[]=$y+2*$dy; + $c[]=$x;$c[]=$y; + $c[]=$x-$dx*2;$c[]=$y; + $pts=4; + break; + case MARK_FLASH: + $dy *= 2; + $c[]=$x+$dx/2; $c[]=$y-$dy; + $c[]=$x-$dx+$dx/2; $c[]=$y+$dy*0.7-$dy; + $c[]=$x+$dx/2; $c[]=$y+$dy*1.3-$dy; + $c[]=$x-$dx+$dx/2; $c[]=$y+2*$dy-$dy; + $img->SetLineWeight($weight); + $img->SetColor($color); + $img->Polygon($c); + $img->SetLineWeight(1); + $this->AddCSIMPoly($c); + break; + } + + if( $pts>0 ) { + $this->AddCSIMPoly($c); + $img->SetLineWeight($weight); + $img->SetColor($fcolor); + $img->FilledPolygon($c); + $img->SetColor($color); + $img->Polygon($c); + $img->SetLineWeight(1); + } + elseif( $this->type==MARK_CIRCLE ) { + $img->SetColor($color); + $img->Circle($x,$y,$width); + $this->AddCSIMCircle($x,$y,$width); + } + elseif( $this->type==MARK_FILLEDCIRCLE ) { + $img->SetColor($fcolor); + $img->FilledCircle($x,$y,$width); + $img->SetColor($color); + $img->Circle($x,$y,$width); + $this->AddCSIMCircle($x,$y,$width); + } + elseif( $this->type==MARK_CROSS ) { + // Oversize by a pixel to match the X + $img->SetColor($color); + $img->SetLineWeight($weight); + $img->Line($x,$y+$dy+1,$x,$y-$dy-1); + $img->Line($x-$dx-1,$y,$x+$dx+1,$y); + $this->AddCSIMCircle($x,$y,$dx); + } + elseif( $this->type==MARK_X ) { + $img->SetColor($color); + $img->SetLineWeight($weight); + $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); + $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); + $this->AddCSIMCircle($x,$y,$dx+$dy); + } + elseif( $this->type==MARK_STAR ) { + $img->SetColor($color); + $img->SetLineWeight($weight); + $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); + $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); + // Oversize by a pixel to match the X + $img->Line($x,$y+$dy+1,$x,$y-$dy-1); + $img->Line($x-$dx-1,$y,$x+$dx+1,$y); + $this->AddCSIMCircle($x,$y,$dx+$dy); + } + + // Stroke title + $this->title->Align("center","center"); + $this->title->Stroke($img,$x,$y); } } // Class @@ -440,57 +440,64 @@ class PlotMark { //======================================================================== // CLASS ImgData -// Description: Base class for all image data classes that contains the +// Description: Base class for all image data classes that contains the // real image data. //======================================================================== class ImgData { - protected $name = ''; // Each subclass gives a name - protected $an = array(); // Data array names - protected $colors = array(); // Available colors - protected $index = array(); // Index for colors - protected $maxidx = 0 ; // Max color index + protected $name = ''; // Each subclass gives a name + protected $an = array(); // Data array names + protected $colors = array(); // Available colors + protected $index = array(); // Index for colors + protected $maxidx = 0 ; // Max color index protected $anchor_x=0.5, $anchor_y=0.5 ; // Where is the center of the image + + function __construct() { + // Empty + } + // Create a GD image from the data and return a GD handle function GetImg($aMark,$aIdx) { - $n = $this->an[$aMark]; - if( is_string($aIdx) ) { - if( !in_array($aIdx,$this->colors) ) { - JpGraphError::RaiseL(23001,$this->name,$aIdx);//('This marker "'.($this->name).'" does not exist in color: '.$aIdx); - } - $idx = $this->index[$aIdx]; - } - elseif( !is_integer($aIdx) || - (is_integer($aIdx) && $aIdx > $this->maxidx ) ) { - JpGraphError::RaiseL(23002,$this->name);//('Mark color index too large for marker "'.($this->name).'"'); - } - else - $idx = $aIdx ; - return Image::CreateFromString(base64_decode($this->{$n}[$idx][1])); + $n = $this->an[$aMark]; + if( is_string($aIdx) ) { + if( !in_array($aIdx,$this->colors) ) { + JpGraphError::RaiseL(23001,$this->name,$aIdx);//('This marker "'.($this->name).'" does not exist in color: '.$aIdx); + } + $idx = $this->index[$aIdx]; + } + elseif( !is_integer($aIdx) || + (is_integer($aIdx) && $aIdx > $this->maxidx ) ) { + JpGraphError::RaiseL(23002,$this->name);//('Mark color index too large for marker "'.($this->name).'"'); + } + else + $idx = $aIdx ; + return Image::CreateFromString(base64_decode($this->{$n}[$idx][1])); } + function GetAnchor() { - return array($this->anchor_x,$this->anchor_y); + return array($this->anchor_x,$this->anchor_y); } } // Keep a global flag cache to reduce memory usage $_gFlagCache=array( - 1 => null, - 2 => null, - 3 => null, - 4 => null, +1 => null, +2 => null, +3 => null, +4 => null, ); // Only supposed to b called as statics class FlagCache { + static function GetFlagImgByName($aSize,$aName) { - global $_gFlagCache; - require_once('jpgraph_flags.php'); - if( $_gFlagCache[$aSize] === null ) { - $_gFlagCache[$aSize] = new FlagImages($aSize); - } - $f = $_gFlagCache[$aSize]; - $idx = $f->GetIdxByName($aName,$aFullName); - return $f->GetImgByIdx($idx); + global $_gFlagCache; + require_once('jpgraph_flags.php'); + if( $_gFlagCache[$aSize] === null ) { + $_gFlagCache[$aSize] = new FlagImages($aSize); + } + $f = $_gFlagCache[$aSize]; + $idx = $f->GetIdxByName($aName,$aFullName); + return $f->GetImgByIdx($idx); } } diff --git a/src/classes/jpgraph/jpgraph_rgb.inc.php b/src/classes/jpgraph/jpgraph_rgb.inc.php new file mode 100644 index 0000000..6464bc1 --- /dev/null +++ b/src/classes/jpgraph/jpgraph_rgb.inc.php @@ -0,0 +1,628 @@ +img = $aImg; + + // Conversion array between color names and RGB + $this->rgb_table = array( + 'aqua'=> array(0,255,255), + 'lime'=> array(0,255,0), + 'teal'=> array(0,128,128), + 'whitesmoke'=>array(245,245,245), + 'gainsboro'=>array(220,220,220), + 'oldlace'=>array(253,245,230), + 'linen'=>array(250,240,230), + 'antiquewhite'=>array(250,235,215), + 'papayawhip'=>array(255,239,213), + 'blanchedalmond'=>array(255,235,205), + 'bisque'=>array(255,228,196), + 'peachpuff'=>array(255,218,185), + 'navajowhite'=>array(255,222,173), + 'moccasin'=>array(255,228,181), + 'cornsilk'=>array(255,248,220), + 'ivory'=>array(255,255,240), + 'lemonchiffon'=>array(255,250,205), + 'seashell'=>array(255,245,238), + 'mintcream'=>array(245,255,250), + 'azure'=>array(240,255,255), + 'aliceblue'=>array(240,248,255), + 'lavender'=>array(230,230,250), + 'lavenderblush'=>array(255,240,245), + 'mistyrose'=>array(255,228,225), + 'white'=>array(255,255,255), + 'black'=>array(0,0,0), + 'darkslategray'=>array(47,79,79), + 'dimgray'=>array(105,105,105), + 'slategray'=>array(112,128,144), + 'lightslategray'=>array(119,136,153), + 'gray'=>array(190,190,190), + 'lightgray'=>array(211,211,211), + 'midnightblue'=>array(25,25,112), + 'navy'=>array(0,0,128), + 'indigo'=>array(75,0,130), + 'electricindigo'=>array(102,0,255), + 'deepindigo'=>array(138,43,226), + 'pigmentindigo'=>array(75,0,130), + 'indigodye'=>array(0,65,106), + 'cornflowerblue'=>array(100,149,237), + 'darkslateblue'=>array(72,61,139), + 'slateblue'=>array(106,90,205), + 'mediumslateblue'=>array(123,104,238), + 'lightslateblue'=>array(132,112,255), + 'mediumblue'=>array(0,0,205), + 'royalblue'=>array(65,105,225), + 'blue'=>array(0,0,255), + 'dodgerblue'=>array(30,144,255), + 'deepskyblue'=>array(0,191,255), + 'skyblue'=>array(135,206,235), + 'lightskyblue'=>array(135,206,250), + 'steelblue'=>array(70,130,180), + 'lightred'=>array(211,167,168), + 'lightsteelblue'=>array(176,196,222), + 'lightblue'=>array(173,216,230), + 'powderblue'=>array(176,224,230), + 'paleturquoise'=>array(175,238,238), + 'darkturquoise'=>array(0,206,209), + 'mediumturquoise'=>array(72,209,204), + 'turquoise'=>array(64,224,208), + 'cyan'=>array(0,255,255), + 'lightcyan'=>array(224,255,255), + 'cadetblue'=>array(95,158,160), + 'mediumaquamarine'=>array(102,205,170), + 'aquamarine'=>array(127,255,212), + 'darkgreen'=>array(0,100,0), + 'darkolivegreen'=>array(85,107,47), + 'darkseagreen'=>array(143,188,143), + 'seagreen'=>array(46,139,87), + 'mediumseagreen'=>array(60,179,113), + 'lightseagreen'=>array(32,178,170), + 'palegreen'=>array(152,251,152), + 'springgreen'=>array(0,255,127), + 'lawngreen'=>array(124,252,0), + 'green'=>array(0,255,0), + 'chartreuse'=>array(127,255,0), + 'mediumspringgreen'=>array(0,250,154), + 'greenyellow'=>array(173,255,47), + 'limegreen'=>array(50,205,50), + 'yellowgreen'=>array(154,205,50), + 'forestgreen'=>array(34,139,34), + 'olivedrab'=>array(107,142,35), + 'darkkhaki'=>array(189,183,107), + 'khaki'=>array(240,230,140), + 'palegoldenrod'=>array(238,232,170), + 'lightgoldenrodyellow'=>array(250,250,210), + 'lightyellow'=>array(255,255,200), + 'yellow'=>array(255,255,0), + 'gold'=>array(255,215,0), + 'lightgoldenrod'=>array(238,221,130), + 'goldenrod'=>array(218,165,32), + 'darkgoldenrod'=>array(184,134,11), + 'rosybrown'=>array(188,143,143), + 'indianred'=>array(205,92,92), + 'saddlebrown'=>array(139,69,19), + 'sienna'=>array(160,82,45), + 'peru'=>array(205,133,63), + 'burlywood'=>array(222,184,135), + 'beige'=>array(245,245,220), + 'wheat'=>array(245,222,179), + 'sandybrown'=>array(244,164,96), + 'tan'=>array(210,180,140), + 'chocolate'=>array(210,105,30), + 'firebrick'=>array(178,34,34), + 'brown'=>array(165,42,42), + 'darksalmon'=>array(233,150,122), + 'salmon'=>array(250,128,114), + 'lightsalmon'=>array(255,160,122), + 'orange'=>array(255,165,0), + 'darkorange'=>array(255,140,0), + 'coral'=>array(255,127,80), + 'lightcoral'=>array(240,128,128), + 'tomato'=>array(255,99,71), + 'orangered'=>array(255,69,0), + 'red'=>array(255,0,0), + 'hotpink'=>array(255,105,180), + 'deeppink'=>array(255,20,147), + 'pink'=>array(255,192,203), + 'lightpink'=>array(255,182,193), + 'palevioletred'=>array(219,112,147), + 'maroon'=>array(176,48,96), + 'mediumvioletred'=>array(199,21,133), + 'violetred'=>array(208,32,144), + 'magenta'=>array(255,0,255), + 'violet'=>array(238,130,238), + 'plum'=>array(221,160,221), + 'orchid'=>array(218,112,214), + 'mediumorchid'=>array(186,85,211), + 'darkorchid'=>array(153,50,204), + 'darkviolet'=>array(148,0,211), + 'blueviolet'=>array(138,43,226), + 'purple'=>array(160,32,240), + 'mediumpurple'=>array(147,112,219), + 'thistle'=>array(216,191,216), + 'snow1'=>array(255,250,250), + 'snow2'=>array(238,233,233), + 'snow3'=>array(205,201,201), + 'snow4'=>array(139,137,137), + 'seashell1'=>array(255,245,238), + 'seashell2'=>array(238,229,222), + 'seashell3'=>array(205,197,191), + 'seashell4'=>array(139,134,130), + 'AntiqueWhite1'=>array(255,239,219), + 'AntiqueWhite2'=>array(238,223,204), + 'AntiqueWhite3'=>array(205,192,176), + 'AntiqueWhite4'=>array(139,131,120), + 'bisque1'=>array(255,228,196), + 'bisque2'=>array(238,213,183), + 'bisque3'=>array(205,183,158), + 'bisque4'=>array(139,125,107), + 'peachPuff1'=>array(255,218,185), + 'peachpuff2'=>array(238,203,173), + 'peachpuff3'=>array(205,175,149), + 'peachpuff4'=>array(139,119,101), + 'navajowhite1'=>array(255,222,173), + 'navajowhite2'=>array(238,207,161), + 'navajowhite3'=>array(205,179,139), + 'navajowhite4'=>array(139,121,94), + 'lemonchiffon1'=>array(255,250,205), + 'lemonchiffon2'=>array(238,233,191), + 'lemonchiffon3'=>array(205,201,165), + 'lemonchiffon4'=>array(139,137,112), + 'ivory1'=>array(255,255,240), + 'ivory2'=>array(238,238,224), + 'ivory3'=>array(205,205,193), + 'ivory4'=>array(139,139,131), + 'honeydew'=>array(193,205,193), + 'lavenderblush1'=>array(255,240,245), + 'lavenderblush2'=>array(238,224,229), + 'lavenderblush3'=>array(205,193,197), + 'lavenderblush4'=>array(139,131,134), + 'mistyrose1'=>array(255,228,225), + 'mistyrose2'=>array(238,213,210), + 'mistyrose3'=>array(205,183,181), + 'mistyrose4'=>array(139,125,123), + 'azure1'=>array(240,255,255), + 'azure2'=>array(224,238,238), + 'azure3'=>array(193,205,205), + 'azure4'=>array(131,139,139), + 'slateblue1'=>array(131,111,255), + 'slateblue2'=>array(122,103,238), + 'slateblue3'=>array(105,89,205), + 'slateblue4'=>array(71,60,139), + 'royalblue1'=>array(72,118,255), + 'royalblue2'=>array(67,110,238), + 'royalblue3'=>array(58,95,205), + 'royalblue4'=>array(39,64,139), + 'dodgerblue1'=>array(30,144,255), + 'dodgerblue2'=>array(28,134,238), + 'dodgerblue3'=>array(24,116,205), + 'dodgerblue4'=>array(16,78,139), + 'steelblue1'=>array(99,184,255), + 'steelblue2'=>array(92,172,238), + 'steelblue3'=>array(79,148,205), + 'steelblue4'=>array(54,100,139), + 'deepskyblue1'=>array(0,191,255), + 'deepskyblue2'=>array(0,178,238), + 'deepskyblue3'=>array(0,154,205), + 'deepskyblue4'=>array(0,104,139), + 'skyblue1'=>array(135,206,255), + 'skyblue2'=>array(126,192,238), + 'skyblue3'=>array(108,166,205), + 'skyblue4'=>array(74,112,139), + 'lightskyblue1'=>array(176,226,255), + 'lightskyblue2'=>array(164,211,238), + 'lightskyblue3'=>array(141,182,205), + 'lightskyblue4'=>array(96,123,139), + 'slategray1'=>array(198,226,255), + 'slategray2'=>array(185,211,238), + 'slategray3'=>array(159,182,205), + 'slategray4'=>array(108,123,139), + 'lightsteelblue1'=>array(202,225,255), + 'lightsteelblue2'=>array(188,210,238), + 'lightsteelblue3'=>array(162,181,205), + 'lightsteelblue4'=>array(110,123,139), + 'lightblue1'=>array(191,239,255), + 'lightblue2'=>array(178,223,238), + 'lightblue3'=>array(154,192,205), + 'lightblue4'=>array(104,131,139), + 'lightcyan1'=>array(224,255,255), + 'lightcyan2'=>array(209,238,238), + 'lightcyan3'=>array(180,205,205), + 'lightcyan4'=>array(122,139,139), + 'paleturquoise1'=>array(187,255,255), + 'paleturquoise2'=>array(174,238,238), + 'paleturquoise3'=>array(150,205,205), + 'paleturquoise4'=>array(102,139,139), + 'cadetblue1'=>array(152,245,255), + 'cadetblue2'=>array(142,229,238), + 'cadetblue3'=>array(122,197,205), + 'cadetblue4'=>array(83,134,139), + 'turquoise1'=>array(0,245,255), + 'turquoise2'=>array(0,229,238), + 'turquoise3'=>array(0,197,205), + 'turquoise4'=>array(0,134,139), + 'cyan1'=>array(0,255,255), + 'cyan2'=>array(0,238,238), + 'cyan3'=>array(0,205,205), + 'cyan4'=>array(0,139,139), + 'darkslategray1'=>array(151,255,255), + 'darkslategray2'=>array(141,238,238), + 'darkslategray3'=>array(121,205,205), + 'darkslategray4'=>array(82,139,139), + 'aquamarine1'=>array(127,255,212), + 'aquamarine2'=>array(118,238,198), + 'aquamarine3'=>array(102,205,170), + 'aquamarine4'=>array(69,139,116), + 'darkseagreen1'=>array(193,255,193), + 'darkseagreen2'=>array(180,238,180), + 'darkseagreen3'=>array(155,205,155), + 'darkseagreen4'=>array(105,139,105), + 'seagreen1'=>array(84,255,159), + 'seagreen2'=>array(78,238,148), + 'seagreen3'=>array(67,205,128), + 'seagreen4'=>array(46,139,87), + 'palegreen1'=>array(154,255,154), + 'palegreen2'=>array(144,238,144), + 'palegreen3'=>array(124,205,124), + 'palegreen4'=>array(84,139,84), + 'springgreen1'=>array(0,255,127), + 'springgreen2'=>array(0,238,118), + 'springgreen3'=>array(0,205,102), + 'springgreen4'=>array(0,139,69), + 'chartreuse1'=>array(127,255,0), + 'chartreuse2'=>array(118,238,0), + 'chartreuse3'=>array(102,205,0), + 'chartreuse4'=>array(69,139,0), + 'olivedrab1'=>array(192,255,62), + 'olivedrab2'=>array(179,238,58), + 'olivedrab3'=>array(154,205,50), + 'olivedrab4'=>array(105,139,34), + 'darkolivegreen1'=>array(202,255,112), + 'darkolivegreen2'=>array(188,238,104), + 'darkolivegreen3'=>array(162,205,90), + 'darkolivegreen4'=>array(110,139,61), + 'khaki1'=>array(255,246,143), + 'khaki2'=>array(238,230,133), + 'khaki3'=>array(205,198,115), + 'khaki4'=>array(139,134,78), + 'lightgoldenrod1'=>array(255,236,139), + 'lightgoldenrod2'=>array(238,220,130), + 'lightgoldenrod3'=>array(205,190,112), + 'lightgoldenrod4'=>array(139,129,76), + 'yellow1'=>array(255,255,0), + 'yellow2'=>array(238,238,0), + 'yellow3'=>array(205,205,0), + 'yellow4'=>array(139,139,0), + 'gold1'=>array(255,215,0), + 'gold2'=>array(238,201,0), + 'gold3'=>array(205,173,0), + 'gold4'=>array(139,117,0), + 'goldenrod1'=>array(255,193,37), + 'goldenrod2'=>array(238,180,34), + 'goldenrod3'=>array(205,155,29), + 'goldenrod4'=>array(139,105,20), + 'darkgoldenrod1'=>array(255,185,15), + 'darkgoldenrod2'=>array(238,173,14), + 'darkgoldenrod3'=>array(205,149,12), + 'darkgoldenrod4'=>array(139,101,8), + 'rosybrown1'=>array(255,193,193), + 'rosybrown2'=>array(238,180,180), + 'rosybrown3'=>array(205,155,155), + 'rosybrown4'=>array(139,105,105), + 'indianred1'=>array(255,106,106), + 'indianred2'=>array(238,99,99), + 'indianred3'=>array(205,85,85), + 'indianred4'=>array(139,58,58), + 'sienna1'=>array(255,130,71), + 'sienna2'=>array(238,121,66), + 'sienna3'=>array(205,104,57), + 'sienna4'=>array(139,71,38), + 'burlywood1'=>array(255,211,155), + 'burlywood2'=>array(238,197,145), + 'burlywood3'=>array(205,170,125), + 'burlywood4'=>array(139,115,85), + 'wheat1'=>array(255,231,186), + 'wheat2'=>array(238,216,174), + 'wheat3'=>array(205,186,150), + 'wheat4'=>array(139,126,102), + 'tan1'=>array(255,165,79), + 'tan2'=>array(238,154,73), + 'tan3'=>array(205,133,63), + 'tan4'=>array(139,90,43), + 'chocolate1'=>array(255,127,36), + 'chocolate2'=>array(238,118,33), + 'chocolate3'=>array(205,102,29), + 'chocolate4'=>array(139,69,19), + 'firebrick1'=>array(255,48,48), + 'firebrick2'=>array(238,44,44), + 'firebrick3'=>array(205,38,38), + 'firebrick4'=>array(139,26,26), + 'brown1'=>array(255,64,64), + 'brown2'=>array(238,59,59), + 'brown3'=>array(205,51,51), + 'brown4'=>array(139,35,35), + 'salmon1'=>array(255,140,105), + 'salmon2'=>array(238,130,98), + 'salmon3'=>array(205,112,84), + 'salmon4'=>array(139,76,57), + 'lightsalmon1'=>array(255,160,122), + 'lightsalmon2'=>array(238,149,114), + 'lightsalmon3'=>array(205,129,98), + 'lightsalmon4'=>array(139,87,66), + 'orange1'=>array(255,165,0), + 'orange2'=>array(238,154,0), + 'orange3'=>array(205,133,0), + 'orange4'=>array(139,90,0), + 'darkorange1'=>array(255,127,0), + 'darkorange2'=>array(238,118,0), + 'darkorange3'=>array(205,102,0), + 'darkorange4'=>array(139,69,0), + 'coral1'=>array(255,114,86), + 'coral2'=>array(238,106,80), + 'coral3'=>array(205,91,69), + 'coral4'=>array(139,62,47), + 'tomato1'=>array(255,99,71), + 'tomato2'=>array(238,92,66), + 'tomato3'=>array(205,79,57), + 'tomato4'=>array(139,54,38), + 'orangered1'=>array(255,69,0), + 'orangered2'=>array(238,64,0), + 'orangered3'=>array(205,55,0), + 'orangered4'=>array(139,37,0), + 'deeppink1'=>array(255,20,147), + 'deeppink2'=>array(238,18,137), + 'deeppink3'=>array(205,16,118), + 'deeppink4'=>array(139,10,80), + 'hotpink1'=>array(255,110,180), + 'hotpink2'=>array(238,106,167), + 'hotpink3'=>array(205,96,144), + 'hotpink4'=>array(139,58,98), + 'pink1'=>array(255,181,197), + 'pink2'=>array(238,169,184), + 'pink3'=>array(205,145,158), + 'pink4'=>array(139,99,108), + 'lightpink1'=>array(255,174,185), + 'lightpink2'=>array(238,162,173), + 'lightpink3'=>array(205,140,149), + 'lightpink4'=>array(139,95,101), + 'palevioletred1'=>array(255,130,171), + 'palevioletred2'=>array(238,121,159), + 'palevioletred3'=>array(205,104,137), + 'palevioletred4'=>array(139,71,93), + 'maroon1'=>array(255,52,179), + 'maroon2'=>array(238,48,167), + 'maroon3'=>array(205,41,144), + 'maroon4'=>array(139,28,98), + 'violetred1'=>array(255,62,150), + 'violetred2'=>array(238,58,140), + 'violetred3'=>array(205,50,120), + 'violetred4'=>array(139,34,82), + 'magenta1'=>array(255,0,255), + 'magenta2'=>array(238,0,238), + 'magenta3'=>array(205,0,205), + 'magenta4'=>array(139,0,139), + 'mediumred'=>array(140,34,34), + 'orchid1'=>array(255,131,250), + 'orchid2'=>array(238,122,233), + 'orchid3'=>array(205,105,201), + 'orchid4'=>array(139,71,137), + 'plum1'=>array(255,187,255), + 'plum2'=>array(238,174,238), + 'plum3'=>array(205,150,205), + 'plum4'=>array(139,102,139), + 'mediumorchid1'=>array(224,102,255), + 'mediumorchid2'=>array(209,95,238), + 'mediumorchid3'=>array(180,82,205), + 'mediumorchid4'=>array(122,55,139), + 'darkorchid1'=>array(191,62,255), + 'darkorchid2'=>array(178,58,238), + 'darkorchid3'=>array(154,50,205), + 'darkorchid4'=>array(104,34,139), + 'purple1'=>array(155,48,255), + 'purple2'=>array(145,44,238), + 'purple3'=>array(125,38,205), + 'purple4'=>array(85,26,139), + 'mediumpurple1'=>array(171,130,255), + 'mediumpurple2'=>array(159,121,238), + 'mediumpurple3'=>array(137,104,205), + 'mediumpurple4'=>array(93,71,139), + 'thistle1'=>array(255,225,255), + 'thistle2'=>array(238,210,238), + 'thistle3'=>array(205,181,205), + 'thistle4'=>array(139,123,139), + 'gray1'=>array(10,10,10), + 'gray2'=>array(40,40,30), + 'gray3'=>array(70,70,70), + 'gray4'=>array(100,100,100), + 'gray5'=>array(130,130,130), + 'gray6'=>array(160,160,160), + 'gray7'=>array(190,190,190), + 'gray8'=>array(210,210,210), + 'gray9'=>array(240,240,240), + 'darkgray'=>array(100,100,100), + 'darkblue'=>array(0,0,139), + 'darkcyan'=>array(0,139,139), + 'darkmagenta'=>array(139,0,139), + 'darkred'=>array(139,0,0), + 'silver'=>array(192, 192, 192), + 'eggplant'=>array(144,176,168), + 'lightgreen'=>array(144,238,144)); + } + //---------------- + // PUBLIC METHODS + // Colors can be specified as either + // 1. #xxxxxx HTML style + // 2. "colorname" as a named color + // 3. array(r,g,b) RGB triple + // This function translates this to a native RGB format and returns an + // RGB triple. + function Color($aColor) { + if (is_string($aColor)) { + // Strip of any alpha factor + $pos = strpos($aColor,'@'); + if( $pos === false ) { + $alpha = 0; + } + else { + $pos2 = strpos($aColor,':'); + if( $pos2===false ) + $pos2 = $pos-1; // Sentinel + if( $pos > $pos2 ) { + $alpha = str_replace(',','.',substr($aColor,$pos+1)); + $aColor = substr($aColor,0,$pos); + } + else { + $alpha = substr($aColor,$pos+1,$pos2-$pos-1); + $aColor = substr($aColor,0,$pos).substr($aColor,$pos2); + } + } + + // Extract potential adjustment figure at end of color + // specification + $pos = strpos($aColor,":"); + if( $pos === false ) { + $adj = 1.0; + } + else { + $adj = 0.0 + str_replace(',','.',substr($aColor,$pos+1)); + $aColor = substr($aColor,0,$pos); + } + if( $adj < 0 ) { + JpGraphError::RaiseL(25077);//('Adjustment factor for color must be > 0'); + } + + if (substr($aColor, 0, 1) == "#") { + $r = hexdec(substr($aColor, 1, 2)); + $g = hexdec(substr($aColor, 3, 2)); + $b = hexdec(substr($aColor, 5, 2)); + } else { + if(!isset($this->rgb_table[$aColor]) ) { + JpGraphError::RaiseL(25078,$aColor);//(" Unknown color: $aColor"); + } + $tmp=$this->rgb_table[$aColor]; + $r = $tmp[0]; + $g = $tmp[1]; + $b = $tmp[2]; + } + // Scale adj so that an adj=2 always + // makes the color 100% white (i.e. 255,255,255. + // and adj=1 neutral and adj=0 black. + if( $adj > 1 ) { + $m = ($adj-1.0)*(255-min(255,min($r,min($g,$b)))); + return array(min(255,$r+$m), min(255,$g+$m), min(255,$b+$m),$alpha); + } + elseif( $adj < 1 ) { + $m = ($adj-1.0)*max(255,max($r,max($g,$b))); + return array(max(0,$r+$m), max(0,$g+$m), max(0,$b+$m),$alpha); + } + else { + return array($r,$g,$b,$alpha); + } + + } elseif( is_array($aColor) ) { + if( count($aColor)==3 ) { + $aColor[3]=0; + return $aColor; + } + else + return $aColor; + } + else { + JpGraphError::RaiseL(25079,$aColor,count($aColor));//(" Unknown color specification: $aColor , size=".count($aColor)); + } + } + + // Compare two colors + // return true if equal + function Equal($aCol1,$aCol2) { + $c1 = $this->Color($aCol1); + $c2 = $this->Color($aCol2); + if( $c1[0]==$c2[0] && $c1[1]==$c2[1] && $c1[2]==$c2[2] ) { + return true; + } + else { + return false; + } + } + + // Allocate a new color in the current image + // Return new color index, -1 if no more colors could be allocated + function Allocate($aColor,$aAlpha=0.0) { + list ($r, $g, $b, $a) = $this->color($aColor); + // If alpha is specified in the color string then this + // takes precedence over the second argument + if( $a > 0 ) { + $aAlpha = $a; + } + if( $aAlpha < 0 || $aAlpha > 1 ) { + JpGraphError::RaiseL(25080);//('Alpha parameter for color must be between 0.0 and 1.0'); + } + return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); + } + + static function tryHexConversion($aColor) { + if( is_array( $aColor ) ) { + if( count( $aColor ) == 3 ) { + if( is_numeric($aColor[0]) &&is_numeric($aColor[1]) && is_numeric($aColor[2]) ) { + if( ($aColor[0] >= 0 && $aColor[0] <= 255) && + ($aColor[1] >= 0 && $aColor[1] <= 255) && + ($aColor[2] >= 0 && $aColor[2] <= 255) ) { + return sprintf('#%02x%02x%02x',$aColor[0],$aColor[1],$aColor[2]); + } + } + } + } + return $aColor; + } + + + // Return a RGB tripple corresponding to a position in the normal light spectrum + // The argumen values is in the range [0, 1] where a value of 0 correponds to blue and + // a value of 1 corresponds to red. Values in betwen is mapped to a linear interpolation + // of the constituting colors in the visible color spectra. + // The $aDynamicRange specified how much of the dynamic range we shold use + // a value of 1.0 give the full dyanmic range and a lower value give more dark + // colors. In the extreme of 0.0 then all colors will be black. + static function GetSpectrum($aVal,$aDynamicRange=1.0) { + if( $aVal < 0 || $aVal > 1.0001 ) { + return array(0,0,0); // Invalid case - just return black + } + + $sat = round(255*$aDynamicRange); + $a = 0.25; + if( $aVal <= 0.25 ) { + return array(0, round($sat*$aVal/$a), $sat); + } + elseif( $aVal <= 0.5 ) { + return array(0, $sat, round($sat-$sat*($aVal-0.25)/$a)); + } + elseif( $aVal <= 0.75 ) { + return array(round($sat*($aVal-0.5)/$a), $sat, 0); + } + else { + return array($sat, round($sat-$sat*($aVal-0.75)/$a), 0); + } + } + + } // Class + +?> diff --git a/src/classes/jpgraph/jpgraph_text.inc.php b/src/classes/jpgraph/jpgraph_text.inc.php new file mode 100644 index 0000000..f47508e --- /dev/null +++ b/src/classes/jpgraph/jpgraph_text.inc.php @@ -0,0 +1,272 @@ +t = $aTxt; + $this->x = round($aXAbsPos); + $this->y = round($aYAbsPos); + $this->margin = 0; + } + //--------------- + // PUBLIC METHODS + // Set the string in the text object + function Set($aTxt) { + $this->t = $aTxt; + } + + // Alias for Pos() + function SetPos($aXAbsPos=0,$aYAbsPos=0,$aHAlign="left",$aVAlign="top") { + //$this->Pos($aXAbsPos,$aYAbsPos,$aHAlign,$aVAlign); + $this->x = $aXAbsPos; + $this->y = $aYAbsPos; + $this->halign = $aHAlign; + $this->valign = $aVAlign; + } + + function SetScalePos($aX,$aY) { + $this->iScalePosX = $aX; + $this->iScalePosY = $aY; + } + + // Specify alignment for the text + function Align($aHAlign,$aVAlign="top",$aParagraphAlign="") { + $this->halign = $aHAlign; + $this->valign = $aVAlign; + if( $aParagraphAlign != "" ) + $this->paragraph_align = $aParagraphAlign; + } + + // Alias + function SetAlign($aHAlign,$aVAlign="top",$aParagraphAlign="") { + $this->Align($aHAlign,$aVAlign,$aParagraphAlign); + } + + // Specifies the alignment for a multi line text + function ParagraphAlign($aAlign) { + $this->paragraph_align = $aAlign; + } + + // Specifies the alignment for a multi line text + function SetParagraphAlign($aAlign) { + $this->paragraph_align = $aAlign; + } + + function SetShadow($aShadowColor='gray',$aShadowWidth=3) { + $this->ishadowwidth=$aShadowWidth; + $this->shadow=$aShadowColor; + $this->boxed=true; + } + + function SetWordWrap($aCol) { + $this->iWordwrap = $aCol ; + } + + // Specify that the text should be boxed. fcolor=frame color, bcolor=border color, + // $shadow=drop shadow should be added around the text. + function SetBox($aFrameColor=array(255,255,255),$aBorderColor=array(0,0,0),$aShadowColor=false,$aCornerRadius=4,$aShadowWidth=3) { + if( $aFrameColor==false ) + $this->boxed=false; + else + $this->boxed=true; + $this->fcolor=$aFrameColor; + $this->bcolor=$aBorderColor; + // For backwards compatibility when shadow was just true or false + if( $aShadowColor === true ) + $aShadowColor = 'gray'; + $this->shadow=$aShadowColor; + $this->icornerradius=$aCornerRadius; + $this->ishadowwidth=$aShadowWidth; + } + + // Hide the text + function Hide($aHide=true) { + $this->hide=$aHide; + } + + // This looks ugly since it's not a very orthogonal design + // but I added this "inverse" of Hide() to harmonize + // with some classes which I designed more recently (especially) + // jpgraph_gantt + function Show($aShow=true) { + $this->hide=!$aShow; + } + + // Specify font + function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) { + $this->font_family=$aFamily; + $this->font_style=$aStyle; + $this->font_size=$aSize; + } + + // Center the text between $left and $right coordinates + function Center($aLeft,$aRight,$aYAbsPos=false) { + $this->x = $aLeft + ($aRight-$aLeft )/2; + $this->halign = "center"; + if( is_numeric($aYAbsPos) ) + $this->y = $aYAbsPos; + } + + // Set text color + function SetColor($aColor) { + $this->color = $aColor; + } + + function SetAngle($aAngle) { + $this->SetOrientation($aAngle); + } + + // Orientation of text. Note only TTF fonts can have an arbitrary angle + function SetOrientation($aDirection=0) { + if( is_numeric($aDirection) ) + $this->dir=$aDirection; + elseif( $aDirection=="h" ) + $this->dir = 0; + elseif( $aDirection=="v" ) + $this->dir = 90; + else JpGraphError::RaiseL(25051);//(" Invalid direction specified for text."); + } + + // Total width of text + function GetWidth($aImg) { + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $w = $aImg->GetTextWidth($this->t,$this->dir); + return $w; + } + + // Hight of font + function GetFontHeight($aImg) { + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $h = $aImg->GetFontHeight(); + return $h; + + } + + function GetTextHeight($aImg) { + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $h = $aImg->GetTextHeight($this->t,$this->dir); + return $h; + } + + function GetHeight($aImg) { + // Synonym for GetTextHeight() + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $h = $aImg->GetTextHeight($this->t,$this->dir); + return $h; + } + + // Set the margin which will be interpretated differently depending + // on the context. + function SetMargin($aMarg) { + $this->margin = $aMarg; + } + + function StrokeWithScale($aImg,$axscale,$ayscale) { + if( $this->iScalePosX === null || $this->iScalePosY === null ) { + $this->Stroke($aImg); + } + else { + $this->Stroke($aImg, + round($axscale->Translate($this->iScalePosX)), + round($ayscale->Translate($this->iScalePosY))); + } + } + + function SetCSIMTarget($aURITarget,$aAlt='',$aWinTarget='') { + $this->iCSIMtarget = $aURITarget; + $this->iCSIMalt = $aAlt; + $this->iCSIMWinTarget = $aWinTarget; + } + + function GetCSIMareas() { + if( $this->iCSIMtarget !== '' ) + return $this->iCSIMarea; + else + return ''; + } + + // Display text in image + function Stroke($aImg,$x=null,$y=null) { + + if( !empty($x) ) $this->x = round($x); + if( !empty($y) ) $this->y = round($y); + + // Insert newlines + if( $this->iWordwrap > 0 ) { + $this->t = wordwrap($this->t,$this->iWordwrap,"\n"); + } + + // If position been given as a fraction of the image size + // calculate the absolute position + if( $this->x < 1 && $this->x > 0 ) $this->x *= $aImg->width; + if( $this->y < 1 && $this->y > 0 ) $this->y *= $aImg->height; + + $aImg->PushColor($this->color); + $aImg->SetFont($this->font_family,$this->font_style,$this->font_size); + $aImg->SetTextAlign($this->halign,$this->valign); + if( $this->boxed ) { + if( $this->fcolor=="nofill" ) + $this->fcolor=false; + $oldweight=$aImg->SetLineWeight(1); + $bbox = $aImg->StrokeBoxedText($this->x,$this->y,$this->t, + $this->dir,$this->fcolor,$this->bcolor,$this->shadow, + $this->paragraph_align,5,5,$this->icornerradius, + $this->ishadowwidth); + + $aImg->SetLineWeight($oldweight); + } + else { + $bbox = $aImg->StrokeText($this->x,$this->y,$this->t,$this->dir,$this->paragraph_align); + } + + // Create CSIM targets + $coords = $bbox[0].','.$bbox[1].','.$bbox[2].','.$bbox[3].','.$bbox[4].','.$bbox[5].','.$bbox[6].','.$bbox[7]; + $this->iCSIMarea = "iCSIMtarget)."\" "; + if( trim($this->iCSIMalt) != '' ) { + $this->iCSIMarea .= " alt=\"".$this->iCSIMalt."\" "; + $this->iCSIMarea .= " title=\"".$this->iCSIMalt."\" "; + } + if( trim($this->iCSIMWinTarget) != '' ) { + $this->iCSIMarea .= " target=\"".$this->iCSIMWinTarget."\" "; + } + $this->iCSIMarea .= " />\n"; + + $aImg->PopColor($this->color); + + } +} // Class + + +?> diff --git a/src/classes/jpgraph/jpgraph_ttf.inc.php b/src/classes/jpgraph/jpgraph_ttf.inc.php index 02050ee..ae66e66 100644 --- a/src/classes/jpgraph/jpgraph_ttf.inc.php +++ b/src/classes/jpgraph/jpgraph_ttf.inc.php @@ -1,73 +1,152 @@ g2312 == null ) { - include_once 'jpgraph_gb2312.php' ; - $this->g2312 = new GB2312toUTF8(); - } - return $this->g2312->gb2utf8($aTxt); - } - elseif( $aFF === FF_CHINESE ) { - if( !function_exists('iconv') ) { - JpGraphError::RaiseL(25006); -//('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).'); - } - return iconv('BIG5','UTF-8',$aTxt); - } - elseif( ASSUME_EUCJP_ENCODING && - ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) { - if( !function_exists('mb_convert_encoding') ) { - JpGraphError::RaiseL(25127); - } - return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP'); - } - elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) { - return LanguageConv::heb_iso2uni($aTxt); - } - else - return $aTxt; + if( LANGUAGE_GREEK ) { + if( GREEK_FROM_WINDOWS ) { + $unistring = LanguageConv::gr_win2uni($aTxt); + } else { + $unistring = LanguageConv::gr_iso2uni($aTxt); + } + return $unistring; + } elseif( LANGUAGE_CYRILLIC ) { + if( CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251')) ) { + $aTxt = convert_cyr_string($aTxt, "w", "k"); + } + if( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) { + $isostring = convert_cyr_string($aTxt, "k", "i"); + $unistring = LanguageConv::iso2uni($isostring); + } + else { + $unistring = $aTxt; + } + return $unistring; + } + elseif( $aFF === FF_SIMSUN ) { + // Do Chinese conversion + if( $this->g2312 == null ) { + include_once 'jpgraph_gb2312.php' ; + $this->g2312 = new GB2312toUTF8(); + } + return $this->g2312->gb2utf8($aTxt); + } + elseif( $aFF === FF_BIG5 ) { + if( !function_exists('iconv') ) { + JpGraphError::RaiseL(25006); + //('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).'); + } + return iconv('BIG5','UTF-8',$aTxt); + } + elseif( ASSUME_EUCJP_ENCODING && + ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) { + if( !function_exists('mb_convert_encoding') ) { + JpGraphError::RaiseL(25127); + } + return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP'); + } + elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) { + return LanguageConv::heb_iso2uni($aTxt); + } + else + return $aTxt; } // Translate iso encoding to unicode public static function iso2uni ($isoline){ - $uniline=''; - for ($i=0; $i < strlen($isoline); $i++){ - $thischar=substr($isoline,$i,1); - $charcode=ord($thischar); - $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar; - } - return $uniline; + $uniline=''; + for ($i=0; $i < strlen($isoline); $i++){ + $thischar=substr($isoline,$i,1); + $charcode=ord($thischar); + $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar; + } + return $uniline; } // Translate greek iso encoding to unicode public static function gr_iso2uni ($isoline) { - $uniline=''; - for ($i=0; $i < strlen($isoline); $i++) { - $thischar=substr($isoline,$i,1); - $charcode=ord($thischar); - $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar; - } - return $uniline; + $uniline=''; + for ($i=0; $i < strlen($isoline); $i++) { + $thischar=substr($isoline,$i,1); + $charcode=ord($thischar); + $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar; + } + return $uniline; } // Translate greek win encoding to unicode public static function gr_win2uni ($winline) { - $uniline=''; - for ($i=0; $i < strlen($winline); $i++) { - $thischar=substr($winline,$i,1); - $charcode=ord($thischar); - if ($charcode==161 || $charcode==162) { - $uniline.="&#" . (740+$charcode). ";"; - } - else { - $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar; - } - } - return $uniline; + $uniline=''; + for ($i=0; $i < strlen($winline); $i++) { + $thischar=substr($winline,$i,1); + $charcode=ord($thischar); + if ($charcode==161 || $charcode==162) { + $uniline.="&#" . (740+$charcode). ";"; + } + else { + $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar; + } + } + return $uniline; } public static function heb_iso2uni($isoline) { - $isoline = hebrev($isoline); - $o = ''; + $isoline = hebrev($isoline); + $o = ''; - $n = strlen($isoline); - for($i=0; $i < $n; $i++) { - $c=ord( substr($isoline,$i,1) ); - $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c); - } - return utf8_encode($o); + $n = strlen($isoline); + for($i=0; $i < $n; $i++) { + $c=ord( substr($isoline,$i,1) ); + $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c); + } + return utf8_encode($o); } } //============================================================= // CLASS TTF -// Description: Handle TTF font names and mapping and loading of +// Description: Handle TTF font names and mapping and loading of // font files //============================================================= class TTF { private $font_files,$style_names; -//--------------- -// CONSTRUCTOR - function TTF() { + function __construct() { - // String names for font styles to be used in error messages - $this->style_names=array(FS_NORMAL =>'normal', - FS_BOLD =>'bold', - FS_ITALIC =>'italic', - FS_BOLDITALIC =>'bolditalic'); + // String names for font styles to be used in error messages + $this->style_names=array( + FS_NORMAL =>'normal', + FS_BOLD =>'bold', + FS_ITALIC =>'italic', + FS_BOLDITALIC =>'bolditalic'); - // File names for available fonts - $this->font_files=array( - FF_COURIER => array(FS_NORMAL =>'cour.ttf', - FS_BOLD =>'courbd.ttf', - FS_ITALIC =>'couri.ttf', - FS_BOLDITALIC =>'courbi.ttf' ), - FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf', - FS_BOLD =>'georgiab.ttf', - FS_ITALIC =>'georgiai.ttf', - FS_BOLDITALIC =>'' ), - FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf', - FS_BOLD =>'trebucbd.ttf', - FS_ITALIC =>'trebucit.ttf', - FS_BOLDITALIC =>'trebucbi.ttf' ), - FF_VERDANA => array(FS_NORMAL =>'verdana.ttf', - FS_BOLD =>'verdanab.ttf', - FS_ITALIC =>'verdanai.ttf', - FS_BOLDITALIC =>'' ), - FF_TIMES => array(FS_NORMAL =>'times.ttf', - FS_BOLD =>'timesbd.ttf', - FS_ITALIC =>'timesi.ttf', - FS_BOLDITALIC =>'timesbi.ttf' ), - FF_COMIC => array(FS_NORMAL =>'comic.ttf', - FS_BOLD =>'comicbd.ttf', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_ARIAL => array(FS_NORMAL =>'arial.ttf', - FS_BOLD =>'arialbd.ttf', - FS_ITALIC =>'ariali.ttf', - FS_BOLDITALIC =>'arialbi.ttf' ) , - FF_VERA => array(FS_NORMAL =>'Vera.ttf', - FS_BOLD =>'VeraBd.ttf', - FS_ITALIC =>'VeraIt.ttf', - FS_BOLDITALIC =>'VeraBI.ttf' ), - FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf', - FS_BOLD =>'VeraMoBd.ttf', - FS_ITALIC =>'VeraMoIt.ttf', - FS_BOLDITALIC =>'VeraMoBI.ttf' ), - FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf', - FS_BOLD =>'VeraSeBd.ttf', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ) , + // File names for available fonts + $this->font_files=array( + FF_COURIER => array(FS_NORMAL =>'cour.ttf', + FS_BOLD =>'courbd.ttf', + FS_ITALIC =>'couri.ttf', + FS_BOLDITALIC =>'courbi.ttf' ), + FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf', + FS_BOLD =>'georgiab.ttf', + FS_ITALIC =>'georgiai.ttf', + FS_BOLDITALIC =>'' ), + FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf', + FS_BOLD =>'trebucbd.ttf', + FS_ITALIC =>'trebucit.ttf', + FS_BOLDITALIC =>'trebucbi.ttf' ), + FF_VERDANA => array(FS_NORMAL =>'verdana.ttf', + FS_BOLD =>'verdanab.ttf', + FS_ITALIC =>'verdanai.ttf', + FS_BOLDITALIC =>'' ), + FF_TIMES => array(FS_NORMAL =>'times.ttf', + FS_BOLD =>'timesbd.ttf', + FS_ITALIC =>'timesi.ttf', + FS_BOLDITALIC =>'timesbi.ttf' ), + FF_COMIC => array(FS_NORMAL =>'comic.ttf', + FS_BOLD =>'comicbd.ttf', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + FF_ARIAL => array(FS_NORMAL =>'arial.ttf', + FS_BOLD =>'arialbd.ttf', + FS_ITALIC =>'ariali.ttf', + FS_BOLDITALIC =>'arialbi.ttf' ) , + FF_VERA => array(FS_NORMAL =>'Vera.ttf', + FS_BOLD =>'VeraBd.ttf', + FS_ITALIC =>'VeraIt.ttf', + FS_BOLDITALIC =>'VeraBI.ttf' ), + FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf', + FS_BOLD =>'VeraMoBd.ttf', + FS_ITALIC =>'VeraMoIt.ttf', + FS_BOLDITALIC =>'VeraMoBI.ttf' ), + FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf', + FS_BOLD =>'VeraSeBd.ttf', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ) , /* Chinese fonts */ - FF_SIMSUN => array(FS_NORMAL =>'simsun.ttc', - FS_BOLD =>'simhei.ttf', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_CHINESE => array(FS_NORMAL =>CHINESE_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), + FF_SIMSUN => array( + FS_NORMAL =>'simsun.ttc', + FS_BOLD =>'simhei.ttf', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + FF_CHINESE => array( + FS_NORMAL =>CHINESE_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + FF_BIG5 => array( + FS_NORMAL =>CHINESE_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), /* Japanese fonts */ - FF_MINCHO => array(FS_NORMAL =>MINCHO_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_PMINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_GOTHIC => array(FS_NORMAL =>GOTHIC_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_PGOTHIC => array(FS_NORMAL =>PGOTHIC_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_MINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT, - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), + FF_MINCHO => array( + FS_NORMAL =>MINCHO_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_PMINCHO => array( + FS_NORMAL =>PMINCHO_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_GOTHIC => array( + FS_NORMAL =>GOTHIC_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_PGOTHIC => array( + FS_NORMAL =>PGOTHIC_TTF_FONT, + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), /* Hebrew fonts */ - FF_DAVID => array(FS_NORMAL =>'DAVIDNEW.TTF', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), + FF_DAVID => array( + FS_NORMAL =>'DAVIDNEW.TTF', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), - FF_MIRIAM => array(FS_NORMAL =>'MRIAMY.TTF', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), + FF_MIRIAM => array( + FS_NORMAL =>'MRIAMY.TTF', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), - FF_AHRON => array(FS_NORMAL =>'ahronbd.ttf', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), + FF_AHRON => array( + FS_NORMAL =>'ahronbd.ttf', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), /* Misc fonts */ - FF_DIGITAL => array(FS_NORMAL =>'DIGIRU__.TTF', - FS_BOLD =>'Digirtu_.ttf', - FS_ITALIC =>'Digir___.ttf', - FS_BOLDITALIC =>'DIGIRT__.TTF' ), - FF_SPEEDO => array(FS_NORMAL =>'Speedo.ttf', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_COMPUTER => array(FS_NORMAL =>'COMPUTER.TTF', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - FF_CALCULATOR => array(FS_NORMAL =>'Triad_xs.ttf', - FS_BOLD =>'', - FS_ITALIC =>'', - FS_BOLDITALIC =>'' ), - ); + FF_DIGITAL => array( + FS_NORMAL =>'DIGIRU__.TTF', + FS_BOLD =>'Digirtu_.ttf', + FS_ITALIC =>'Digir___.ttf', + FS_BOLDITALIC =>'DIGIRT__.TTF' ), + + /* This is an experimental font for the speedometer development + FF_SPEEDO => array( + FS_NORMAL =>'Speedo.ttf', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + */ + + FF_COMPUTER => array( + FS_NORMAL =>'COMPUTER.TTF', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_CALCULATOR => array( + FS_NORMAL =>'Triad_xs.ttf', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + /* Dejavu fonts */ + FF_DV_SANSSERIF => array( + FS_NORMAL =>array('DejaVuSans.ttf'), + FS_BOLD =>array('DejaVuSans-Bold.ttf','DejaVuSansBold.ttf'), + FS_ITALIC =>array('DejaVuSans-Oblique.ttf','DejaVuSansOblique.ttf'), + FS_BOLDITALIC =>array('DejaVuSans-BoldOblique.ttf','DejaVuSansBoldOblique.ttf') ), + + FF_DV_SANSSERIFMONO => array( + FS_NORMAL =>array('DejaVuSansMono.ttf','DejaVuMonoSans.ttf'), + FS_BOLD =>array('DejaVuSansMono-Bold.ttf','DejaVuMonoSansBold.ttf'), + FS_ITALIC =>array('DejaVuSansMono-Oblique.ttf','DejaVuMonoSansOblique.ttf'), + FS_BOLDITALIC =>array('DejaVuSansMono-BoldOblique.ttf','DejaVuMonoSansBoldOblique.ttf') ), + + FF_DV_SANSSERIFCOND => array( + FS_NORMAL =>array('DejaVuSansCondensed.ttf','DejaVuCondensedSans.ttf'), + FS_BOLD =>array('DejaVuSansCondensed-Bold.ttf','DejaVuCondensedSansBold.ttf'), + FS_ITALIC =>array('DejaVuSansCondensed-Oblique.ttf','DejaVuCondensedSansOblique.ttf'), + FS_BOLDITALIC =>array('DejaVuSansCondensed-BoldOblique.ttf','DejaVuCondensedSansBoldOblique.ttf') ), + + FF_DV_SERIF => array( + FS_NORMAL =>array('DejaVuSerif.ttf'), + FS_BOLD =>array('DejaVuSerif-Bold.ttf','DejaVuSerifBold.ttf'), + FS_ITALIC =>array('DejaVuSerif-Italic.ttf','DejaVuSerifItalic.ttf'), + FS_BOLDITALIC =>array('DejaVuSerif-BoldItalic.ttf','DejaVuSerifBoldItalic.ttf') ), + + FF_DV_SERIFCOND => array( + FS_NORMAL =>array('DejaVuSerifCondensed.ttf','DejaVuCondensedSerif.ttf'), + FS_BOLD =>array('DejaVuSerifCondensed-Bold.ttf','DejaVuCondensedSerifBold.ttf'), + FS_ITALIC =>array('DejaVuSerifCondensed-Italic.ttf','DejaVuCondensedSerifItalic.ttf'), + FS_BOLDITALIC =>array('DejaVuSerifCondensed-BoldItalic.ttf','DejaVuCondensedSerifBoldItalic.ttf') ), + + + /* Placeholders for defined fonts */ + FF_USERFONT1 => array( + FS_NORMAL =>'', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_USERFONT2 => array( + FS_NORMAL =>'', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + FF_USERFONT3 => array( + FS_NORMAL =>'', + FS_BOLD =>'', + FS_ITALIC =>'', + FS_BOLDITALIC =>'' ), + + ); } -//--------------- -// PUBLIC METHODS + //--------------- + // PUBLIC METHODS // Create the TTF file from the font specification function File($family,$style=FS_NORMAL) { - $fam = @$this->font_files[$family]; - if( !$fam ) { - JpGraphError::RaiseL(25046,$family);//("Specified TTF font family (id=$family) is unknown or does not exist. Please note that TTF fonts are not distributed with JpGraph for copyright reasons. You can find the MS TTF WEB-fonts (arial, courier etc) for download at http://corefonts.sourceforge.net/"); - } - $f = @$fam[$style]; + $fam = @$this->font_files[$family]; + if( !$fam ) { + JpGraphError::RaiseL(25046,$family);//("Specified TTF font family (id=$family) is unknown or does not exist. Please note that TTF fonts are not distributed with JpGraph for copyright reasons. You can find the MS TTF WEB-fonts (arial, courier etc) for download at http://corefonts.sourceforge.net/"); + } + $ff = @$fam[$style]; - if( $f==='' ) - JpGraphError::RaiseL(25047,$this->style_names[$style],$this->font_files[$family][FS_NORMAL]);//('Style "'.$this->style_names[$style].'" is not available for font family '.$this->font_files[$family][FS_NORMAL].'.'); - if( !$f ) { - JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam]."); - } + if( is_array($ff) ) { + // There are several optional file names. They are tried in order + // and the first one found is used + $n = count($ff); + } else { + $n = 1; + $ff = array($ff); + } + $i = 0; + do { + $f = $ff[$i]; + // All font families are guaranteed to have the normal style - if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) { - $f = MBTTF_DIR.$f; - } else { - $f = TTF_DIR.$f; - } + if( $f==='' ) + JpGraphError::RaiseL(25047,$this->style_names[$style],$this->font_files[$family][FS_NORMAL]);//('Style "'.$this->style_names[$style].'" is not available for font family '.$this->font_files[$family][FS_NORMAL].'.'); + if( !$f ) { + JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam]."); + } - if( file_exists($f) === false || is_readable($f) === false ) { - JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist."); - } - return $f; + if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) { + $f = MBTTF_DIR.$f; + } else { + $f = TTF_DIR.$f; + } + ++$i; + } while( $i < $n && (file_exists($f) === false || is_readable($f) === false) ); + + if( !file_exists($f) ) { + JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist."); + } + return $f; } + + function SetUserFont($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->font_files[FF_USERFONT] = + array(FS_NORMAL => $aNormal, + FS_BOLD => $aBold, + FS_ITALIC => $aItalic, + FS_BOLDITALIC => $aBoldIt ) ; + } + + function SetUserFont1($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->font_files[FF_USERFONT1] = + array(FS_NORMAL => $aNormal, + FS_BOLD => $aBold, + FS_ITALIC => $aItalic, + FS_BOLDITALIC => $aBoldIt ) ; + } + + function SetUserFont2($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->font_files[FF_USERFONT2] = + array(FS_NORMAL => $aNormal, + FS_BOLD => $aBold, + FS_ITALIC => $aItalic, + FS_BOLDITALIC => $aBoldIt ) ; + } + + function SetUserFont3($aNormal,$aBold='',$aItalic='',$aBoldIt='') { + $this->font_files[FF_USERFONT3] = + array(FS_NORMAL => $aNormal, + FS_BOLD => $aBold, + FS_ITALIC => $aItalic, + FS_BOLDITALIC => $aBoldIt ) ; + } + } // Class +//============================================================================= +// CLASS SymChar +// Description: Code values for some commonly used characters that +// normally isn't available directly on the keyboard, for example +// mathematical and greek symbols. +//============================================================================= +class SymChar { + static function Get($aSymb,$aCapital=FALSE) { + $iSymbols = array( + /* Greek */ + array('alpha','03B1','0391'), + array('beta','03B2','0392'), + array('gamma','03B3','0393'), + array('delta','03B4','0394'), + array('epsilon','03B5','0395'), + array('zeta','03B6','0396'), + array('ny','03B7','0397'), + array('eta','03B8','0398'), + array('theta','03B8','0398'), + array('iota','03B9','0399'), + array('kappa','03BA','039A'), + array('lambda','03BB','039B'), + array('mu','03BC','039C'), + array('nu','03BD','039D'), + array('xi','03BE','039E'), + array('omicron','03BF','039F'), + array('pi','03C0','03A0'), + array('rho','03C1','03A1'), + array('sigma','03C3','03A3'), + array('tau','03C4','03A4'), + array('upsilon','03C5','03A5'), + array('phi','03C6','03A6'), + array('chi','03C7','03A7'), + array('psi','03C8','03A8'), + array('omega','03C9','03A9'), + /* Money */ + array('euro','20AC'), + array('yen','00A5'), + array('pound','20A4'), + /* Math */ + array('approx','2248'), + array('neq','2260'), + array('not','2310'), + array('def','2261'), + array('inf','221E'), + array('sqrt','221A'), + array('int','222B'), + /* Misc */ + array('copy','00A9'), + array('para','00A7'), + array('tm','2122'), /* Trademark symbol */ + array('rtm','00AE'), /* Registered trademark */ + array('degree','00b0') + + ); + + $n = count($iSymbols); + $i=0; + $found = false; + $aSymb = strtolower($aSymb); + while( $i < $n && !$found ) { + $found = $aSymb === $iSymbols[$i++][0]; + } + if( $found ) { + $ca = $iSymbols[--$i]; + if( $aCapital && count($ca)==3 ) + $s = $ca[2]; + else + $s = $ca[1]; + return sprintf('&#%04d;',hexdec($s)); + } + else + return ''; + } +} + ?> diff --git a/src/classes/jpgraph/lang/de.inc.php b/src/classes/jpgraph/lang/de.inc.php index 04725f7..a81457c 100644 --- a/src/classes/jpgraph/lang/de.inc.php +++ b/src/classes/jpgraph/lang/de.inc.php @@ -1,10 +1,11 @@ array('
JpGraph Fehler: -HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zeile %d.
Erklärung:
HTTP header wurden bereits zum Browser gesendet, wobei die Daten als Text gekennzeichnet wurden, bevor die Bibliothek die Chance hatte, seinen Bild-HTTP-Header zum Browser zu schicken. Dies verhindert, dass die Bibliothek Bilddaten zum Browser schicken kann (weil sie vom Browser als Text interpretiert würden und daher nur Mist dargestellt würde).

Wahrscheinlich steht Text im Skript bevor Graph::Stroke() aufgerufen wird. Wenn dieser Text zum Browser gesendet wird, nimmt dieser an, dass die gesamten Daten aus Text bestehen. Such nach irgendwelchem Text, auch nach Leerzeichen und Zeilenumbrüchen, die eventuell bereits zum Browser gesendet wurden.

Zum Beispiel ist ein oft auftretender Fehler, eine Leerzeile am Anfang der Datei oder vor Graph::Stroke() zu lassen."<?php".

',2), +HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zeile %d.Erklärung:
HTTP header wurden bereits zum Browser gesendet, wobei die Daten als Text gekennzeichnet wurden, bevor die Bibliothek die Chance hatte, seinen Bild-HTTP-Header zum Browser zu schicken. Dies verhindert, dass die Bibliothek Bilddaten zum Browser schicken kann (weil sie vom Browser als Text interpretiert würden und daher nur Mist dargestellt würde).

Wahrscheinlich steht Text im Skript bevor Graph::Stroke() aufgerufen wird. Wenn dieser Text zum Browser gesendet wird, nimmt dieser an, dass die gesamten Daten aus Text bestehen. Such nach irgendwelchem Text, auch nach Leerzeichen und Zeilenumbrüchen, die eventuell bereits zum Browser gesendet wurden.

Zum Beispiel ist ein oft auftretender Fehler, eine Leerzeile am Anfang der Datei oder vor Graph::Stroke() zu lassen."<?php".',2), /* ** Setup Fehler */ -11 => array('Es wurde kein Pfad für CACHE_DIR angegeben. Bitte gib einen Pfad CACHE_DIR in der Datei jpg-config.inc an.',0), -12 => array('Es wurde kein Pfad für TTF_DIR angegeben und der Pfad kann nicht automatisch ermittelt werden. Bitte gib den Pfad in der Datei jpg-config.inc an.',0), +11 => array('Es wurde kein Pfad für CACHE_DIR angegeben. Bitte gib einen Pfad CACHE_DIR in der Datei jpg-config.inc an.',0), +12 => array('Es wurde kein Pfad für TTF_DIR angegeben und der Pfad kann nicht automatisch ermittelt werden. Bitte gib den Pfad in der Datei jpg-config.inc an.',0), 13 => array('The installed PHP version (%s) is not compatible with this release of the library. The library requires at least PHP version %s',2), /* @@ -33,24 +34,25 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei 2001 => array('Die Anzahl der Farben ist nicht gleich der Anzahl der Vorlagen in BarPlot::SetPattern().',0), 2002 => array('Unbekannte Vorlage im Aufruf von BarPlot::SetPattern().',0), 2003 => array('Anzahl der X- und Y-Koordinaten sind nicht identisch. Anzahl der X-Koordinaten: %d; Anzahl der Y-Koordinaten: %d.',2), -2004 => array('Alle Werte für ein Balkendiagramm (barplot) müssen numerisch sein. Du hast den Wert nr [%d] == %s angegeben.',2), -2005 => array('Du hast einen leeren Vektor für die Schattierungsfarben im Balkendiagramm (barplot) angegeben.',0), -2006 => array('Unbekannte Position für die Werte der Balken: %s.',1), +2004 => array('Alle Werte für ein Balkendiagramm (barplot) müssen numerisch sein. Du hast den Wert nr [%d] == %s angegeben.',2), +2005 => array('Du hast einen leeren Vektor für die Schattierungsfarben im Balkendiagramm (barplot) angegeben.',0), +2006 => array('Unbekannte Position für die Werte der Balken: %s.',1), 2007 => array('Kann GroupBarPlot nicht aus einem leeren Vektor erzeugen.',0), 2008 => array('GroupBarPlot Element nbr %d wurde nicht definiert oder ist leer.',0), 2009 => array('Eins der Objekte, das an GroupBar weitergegeben wurde ist kein Balkendiagramm (BarPlot). Versichere Dich, dass Du den GroupBarPlot aus einem Vektor von Balkendiagrammen (barplot) oder AccBarPlot-Objekten erzeugst. (Class = %s)',1), 2010 => array('Kann AccBarPlot nicht aus einem leeren Vektor erzeugen.',0), 2011 => array('AccBarPlot-Element nbr %d wurde nicht definiert oder ist leer.',1), 2012 => array('Eins der Objekte, das an AccBar weitergegeben wurde ist kein Balkendiagramm (barplot). Versichere Dich, dass Du den AccBar-Plot aus einem Vektor von Balkendiagrammen (barplot) erzeugst. (Class=%s)',1), -2013 => array('Du hast einen leeren Vektor für die Schattierungsfarben im Balkendiagramm (barplot) angegeben.',0), +2013 => array('Du hast einen leeren Vektor für die Schattierungsfarben im Balkendiagramm (barplot) angegeben.',0), 2014 => array('Die Anzahl der Datenpunkte jeder Datenreihe in AccBarPlot muss gleich sein.',0), +2015 => array('Individual bar plots in an AccBarPlot or GroupBarPlot can not have specified X-coordinates',0), /* ** jpgraph_date */ -3001 => array('Es ist nur möglich, entweder SetDateAlign() oder SetTimeAlign() zu benutzen, nicht beides!',0), +3001 => array('Es ist nur möglich, entweder SetDateAlign() oder SetTimeAlign() zu benutzen, nicht beides!',0), /* ** jpgraph_error @@ -62,9 +64,9 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph_flags */ -5001 => array('Unbekannte Flaggen-Größe (%d).',1), +5001 => array('Unbekannte Flaggen-Größe (%d).',1), 5002 => array('Der Flaggen-Index %s existiert nicht.',1), -5003 => array('Es wurde eine ungültige Ordnungszahl (%d) für den Flaggen-Index angegeben.',1), +5003 => array('Es wurde eine ungültige Ordnungszahl (%d) für den Flaggen-Index angegeben.',1), 5004 => array('Der Landesname %s hat kein korrespondierendes Flaggenbild. Die Flagge mag existieren, abr eventuell unter einem anderen Namen, z.B. versuche "united states" statt "usa".',1), @@ -72,35 +74,35 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph_gantt */ -6001 => array('Interner Fehler. Die Höhe für ActivityTitles ist < 0.',0), -6002 => array('Es dürfen keine negativen Werte für die Gantt-Diagramm-Dimensionen angegeben werden. Verwende 0, wenn die Dimensionen automatisch ermittelt werden sollen.',0), -6003 => array('Ungültiges Format für den Bedingungs-Parameter bei Index=%d in CreateSimple(). Der Parameter muss bei index 0 starten und Vektoren in der Form (Row,Constrain-To,Constrain-Type) enthalten.',1), -6004 => array('Ungültiges Format für den Fortschritts-Parameter bei Index=%d in CreateSimple(). Der Parameter muss bei Index 0 starten und Vektoren in der Form (Row,Progress) enthalten.',1), +6001 => array('Interner Fehler. Die Höhe für ActivityTitles ist < 0.',0), +6002 => array('Es dürfen keine negativen Werte für die Gantt-Diagramm-Dimensionen angegeben werden. Verwende 0, wenn die Dimensionen automatisch ermittelt werden sollen.',0), +6003 => array('Ungültiges Format für den Bedingungs-Parameter bei Index=%d in CreateSimple(). Der Parameter muss bei index 0 starten und Vektoren in der Form (Row,Constrain-To,Constrain-Type) enthalten.',1), +6004 => array('Ungültiges Format für den Fortschritts-Parameter bei Index=%d in CreateSimple(). Der Parameter muss bei Index 0 starten und Vektoren in der Form (Row,Progress) enthalten.',1), 6005 => array('SetScale() ist nicht sinnvoll bei Gantt-Diagrammen.',0), -6006 => array('Das Gantt-Diagramm kann nicht automatisch skaliert werden. Es existieren keine Aktivitäten mit Termin. [GetBarMinMax() start >= n]',0), -6007 => array('Plausibiltätsprüfung für die automatische Gantt-Diagramm-Größe schlug fehl. Entweder die Breite (=%d) oder die Höhe (=%d) ist größer als MAX_GANTTIMG_SIZE. Dies kann möglicherweise durch einen falschen Wert bei einer Aktivität hervorgerufen worden sein.',2), -6008 => array('Du hast eine Bedingung angegeben von Reihe=%d bis Reihe=%d, die keine Aktivität hat.',2), +6006 => array('Das Gantt-Diagramm kann nicht automatisch skaliert werden. Es existieren keine Aktivitäten mit Termin. [GetBarMinMax() start >= n]',0), +6007 => array('Plausibiltätsprüfung für die automatische Gantt-Diagramm-Größe schlug fehl. Entweder die Breite (=%d) oder die Höhe (=%d) ist größer als MAX_GANTTIMG_SIZE. Dies kann möglicherweise durch einen falschen Wert bei einer Aktivität hervorgerufen worden sein.',2), +6008 => array('Du hast eine Bedingung angegeben von Reihe=%d bis Reihe=%d, die keine Aktivität hat.',2), 6009 => array('Unbekannter Bedingungstyp von Reihe=%d bis Reihe=%d',2), -6010 => array('Ungültiger Icon-Index für das eingebaute Gantt-Icon [%d]',1), -6011 => array('Argument für IconImage muss entweder ein String oder ein Integer sein.',0), +6010 => array('Ungültiger Icon-Index für das eingebaute Gantt-Icon [%d]',1), +6011 => array('Argument für IconImage muss entweder ein String oder ein Integer sein.',0), 6012 => array('Unbekannter Typ bei der Gantt-Objekt-Title-Definition.',0), -6015 => array('Ungültige vertikale Position %d',1), -6016 => array('Der eingegebene Datums-String (%s) für eine Gantt-Aktivität kann nicht interpretiert werden. Versichere Dich, dass es ein gültiger Datumsstring ist, z.B. 2005-04-23 13:30',1), +6015 => array('Ungültige vertikale Position %d',1), +6016 => array('Der eingegebene Datums-String (%s) für eine Gantt-Aktivität kann nicht interpretiert werden. Versichere Dich, dass es ein gültiger Datumsstring ist, z.B. 2005-04-23 13:30',1), 6017 => array('Unbekannter Datumstyp in GanttScale (%s).',1), -6018 => array('Intervall für Minuten muss ein gerader Teiler einer Stunde sein, z.B. 1,5,10,12,15,20,30, etc. Du hast ein Intervall von %d Minuten angegeben.',1), -6019 => array('Die vorhandene Breite (%d) für die Minuten ist zu klein, um angezeigt zu werden. Bitte benutze die automatische Größenermittlung oder vergrößere die Breite des Diagramms.',1), -6020 => array('Das Intervall für die Stunden muss ein gerader Teiler eines Tages sein, z.B. 0:30, 1:00, 1:30, 4:00, etc. Du hast ein Intervall von %d eingegeben.',1), -6021 => array('Unbekanntes Format für die Woche.',0), +6018 => array('Intervall für Minuten muss ein gerader Teiler einer Stunde sein, z.B. 1,5,10,12,15,20,30, etc. Du hast ein Intervall von %d Minuten angegeben.',1), +6019 => array('Die vorhandene Breite (%d) für die Minuten ist zu klein, um angezeigt zu werden. Bitte benutze die automatische Größenermittlung oder vergrößere die Breite des Diagramms.',1), +6020 => array('Das Intervall für die Stunden muss ein gerader Teiler eines Tages sein, z.B. 0:30, 1:00, 1:30, 4:00, etc. Du hast ein Intervall von %d eingegeben.',1), +6021 => array('Unbekanntes Format für die Woche.',0), 6022 => array('Die Gantt-Skala wurde nicht eingegeben.',0), 6023 => array('Wenn Du sowohl Stunden als auch Minuten anzeigen lassen willst, muss das Stunden-Interval gleich 1 sein (anderenfalls ist es nicht sinnvoll, Minuten anzeigen zu lassen).',0), 6024 => array('Das CSIM-Ziel muss als String angegeben werden. Der Start des Ziels ist: %d',1), 6025 => array('Der CSIM-Alt-Text muss als String angegeben werden. Der Beginn des Alt-Textes ist: %d',1), 6027 => array('Der Fortschrittswert muss im Bereich [0, 1] liegen.',0), -6028 => array('Die eingegebene Höhe (%d) für GanttBar ist nicht im zulässigen Bereich.',1), -6029 => array('Der Offset für die vertikale Linie muss im Bereich [0,1] sein.',0), -6030 => array('Unbekannte Pfeilrichtung für eine Verbindung.',0), -6031 => array('Unbekannter Pfeiltyp für eine Verbindung.',0), -6032 => array('Interner Fehler: Unbekannter Pfadtyp (=%d) für eine Verbindung.',1), +6028 => array('Die eingegebene Höhe (%d) für GanttBar ist nicht im zulässigen Bereich.',1), +6029 => array('Der Offset für die vertikale Linie muss im Bereich [0,1] sein.',0), +6030 => array('Unbekannte Pfeilrichtung für eine Verbindung.',0), +6031 => array('Unbekannter Pfeiltyp für eine Verbindung.',0), +6032 => array('Interner Fehler: Unbekannter Pfadtyp (=%d) für eine Verbindung.',1), /* ** jpgraph_gradient @@ -112,107 +114,107 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph_iconplot */ -8001 => array('Der Mix-Wert für das Icon muss zwischen 0 und 100 sein.',0), -8002 => array('Die Ankerposition für Icons muss entweder "top", "bottom", "left", "right" oder "center" sein.',0), -8003 => array('Es ist nicht möglich, gleichzeitig ein Bild und eine Landesflagge für dasselbe Icon zu definieren',0), -8004 => array('Wenn Du Landesflaggen benutzen willst, musst Du die Datei "jpgraph_flags.php" hinzufügen (per include).',0), +8001 => array('Der Mix-Wert für das Icon muss zwischen 0 und 100 sein.',0), +8002 => array('Die Ankerposition für Icons muss entweder "top", "bottom", "left", "right" oder "center" sein.',0), +8003 => array('Es ist nicht möglich, gleichzeitig ein Bild und eine Landesflagge für dasselbe Icon zu definieren',0), +8004 => array('Wenn Du Landesflaggen benutzen willst, musst Du die Datei "jpgraph_flags.php" hinzufügen (per include).',0), /* ** jpgraph_imgtrans */ -9001 => array('Der Wert für die Bildtransformation ist außerhalb des zulässigen Bereichs. Der verschwindende Punkt am Horizont muss als Wert zwischen 0 und 1 angegeben werden.',0), +9001 => array('Der Wert für die Bildtransformation ist außerhalb des zulässigen Bereichs. Der verschwindende Punkt am Horizont muss als Wert zwischen 0 und 1 angegeben werden.',0), /* ** jpgraph_lineplot */ 10001 => array('Die Methode LinePlot::SetFilled() sollte nicht mehr benutzt werden. Benutze lieber SetFillColor()',0), -10002 => array('Der Plot ist zu kompliziert für FastLineStroke. Benutze lieber den StandardStroke()',0), +10002 => array('Der Plot ist zu kompliziert für FastLineStroke. Benutze lieber den StandardStroke()',0), 10003 => array('Each plot in an accumulated lineplot must have the same number of data points.',0), /* ** jpgraph_log */ 11001 => array('Deine Daten enthalten nicht-numerische Werte.',0), -11002 => array('Negative Werte können nicht für logarithmische Achsen verwendet werden.',0), +11002 => array('Negative Werte können nicht für logarithmische Achsen verwendet werden.',0), 11003 => array('Deine Daten enthalten nicht-numerische Werte.',0), -11004 => array('Skalierungsfehler für die logarithmische Achse. Es gibt ein Problem mit den Daten der Achse. Der größte Wert muss größer sein als Null. Es ist mathematisch nicht möglich, einen Wert gleich Null in der Skala zu haben.',0), -11005 => array('Das Tick-Intervall für die logarithmische Achse ist nicht definiert. Lösche jeden Aufruf von SetTextLabelStart() oder SetTextTickInterval() bei der logarithmischen Achse.',0), +11004 => array('Skalierungsfehler für die logarithmische Achse. Es gibt ein Problem mit den Daten der Achse. Der größte Wert muss größer sein als Null. Es ist mathematisch nicht möglich, einen Wert gleich Null in der Skala zu haben.',0), +11005 => array('Das Tick-Intervall für die logarithmische Achse ist nicht definiert. Lösche jeden Aufruf von SetTextLabelStart() oder SetTextTickInterval() bei der logarithmischen Achse.',0), /* ** jpgraph_mgraph */ -12001 => array("Du benutzt GD 2.x und versuchst ein Nicht-Truecolor-Bild als Hintergrundbild zu benutzen. Um Hintergrundbilder mit GD 2.x zu benutzen, ist es notwendig Truecolor zu aktivieren, indem die USE_TRUECOLOR-Konstante auf TRUE gesetzt wird. Wegen eines Bugs in GD 2.0.1 ist die Qualität der Truetype-Schriften sehr schlecht, wenn man Truetype-Schriften mit Truecolor-Bildern verwendet.",0), -12002 => array('Ungültiger Dateiname für MGraph::SetBackgroundImage() : %s. Die Datei muss eine gültige Dateierweiterung haben (jpg,gif,png), wenn die automatische Typerkennung verwendet wird.',1), -12003 => array('Unbekannte Dateierweiterung (%s) in MGraph::SetBackgroundImage() für Dateiname: %s',2), -12004 => array('Das Bildformat des Hintergrundbildes (%s) wird von Deiner System-Konfiguration nicht unterstützt. ',1), +12001 => array("Du benutzt GD 2.x und versuchst ein Nicht-Truecolor-Bild als Hintergrundbild zu benutzen. Um Hintergrundbilder mit GD 2.x zu benutzen, ist es notwendig Truecolor zu aktivieren, indem die USE_TRUECOLOR-Konstante auf TRUE gesetzt wird. Wegen eines Bugs in GD 2.0.1 ist die Qualität der Truetype-Schriften sehr schlecht, wenn man Truetype-Schriften mit Truecolor-Bildern verwendet.",0), +12002 => array('Ungültiger Dateiname für MGraph::SetBackgroundImage() : %s. Die Datei muss eine gültige Dateierweiterung haben (jpg,gif,png), wenn die automatische Typerkennung verwendet wird.',1), +12003 => array('Unbekannte Dateierweiterung (%s) in MGraph::SetBackgroundImage() für Dateiname: %s',2), +12004 => array('Das Bildformat des Hintergrundbildes (%s) wird von Deiner System-Konfiguration nicht unterstützt. ',1), 12005 => array('Das Hintergrundbild kann nicht gelesen werden: %s',1), -12006 => array('Es wurden ungültige Größen für Breite oder Höhe beim Erstellen des Bildes angegeben, (Breite=%d, Höhe=%d)',2), -12007 => array('Das Argument für MGraph::Add() ist nicht gültig für GD.',0), -12008 => array('Deine PHP- (und GD-lib-) Installation scheint keine bekannten Bildformate zu unterstützen.',0), -12009 => array('Deine PHP-Installation unterstützt das gewählte Bildformat nicht: %s',1), -12010 => array('Es konnte kein Bild als Datei %s erzeugt werden. Überprüfe, ob Du die entsprechenden Schreibrechte im aktuellen Verzeichnis hast.',1), -12011 => array('Es konnte kein Truecolor-Bild erzeugt werden. Überprüfe, ob Du wirklich die GD2-Bibliothek installiert hast.',0), -12012 => array('Es konnte kein Bild erzeugt werden. Überprüfe, ob Du wirklich die GD2-Bibliothek installiert hast.',0), +12006 => array('Es wurden ungültige Größen für Breite oder Höhe beim Erstellen des Bildes angegeben, (Breite=%d, Höhe=%d)',2), +12007 => array('Das Argument für MGraph::Add() ist nicht gültig für GD.',0), +12008 => array('Deine PHP- (und GD-lib-) Installation scheint keine bekannten Bildformate zu unterstützen.',0), +12009 => array('Deine PHP-Installation unterstützt das gewählte Bildformat nicht: %s',1), +12010 => array('Es konnte kein Bild als Datei %s erzeugt werden. Überprüfe, ob Du die entsprechenden Schreibrechte im aktuellen Verzeichnis hast.',1), +12011 => array('Es konnte kein Truecolor-Bild erzeugt werden. Überprüfe, ob Du wirklich die GD2-Bibliothek installiert hast.',0), +12012 => array('Es konnte kein Bild erzeugt werden. Überprüfe, ob Du wirklich die GD2-Bibliothek installiert hast.',0), /* ** jpgraph_pie3d */ -14001 => array('Pie3D::ShowBorder(). Missbilligte Funktion. Benutze Pie3D::SetEdge(), um die Ecken der Tortenstücke zu kontrollieren.',0), +14001 => array('Pie3D::ShowBorder(). Missbilligte Funktion. Benutze Pie3D::SetEdge(), um die Ecken der Tortenstücke zu kontrollieren.',0), 14002 => array('PiePlot3D::SetAngle() 3D-Torten-Projektionswinkel muss zwischen 5 und 85 Grad sein.',0), 14003 => array('Interne Festlegung schlug fehl. Pie3D::Pie3DSlice',0), -14004 => array('Tortenstück-Startwinkel muss zwischen 0 und 360 Grad sein.',0), -14005 => array('Pie3D Interner Fehler: Versuch, zweimal zu umhüllen bei der Suche nach dem Startindex.',0,), -14006 => array('Pie3D Interner Fehler: Z-Sortier-Algorithmus für 3D-Tortendiagramme funktioniert nicht einwandfrei (2). Versuch, zweimal zu umhüllen beim Erstellen des Bildes.',0), -14007 => array('Die Breite für das 3D-Tortendiagramm ist 0. Gib eine Breite > 0 an.',0), +14004 => array('Tortenstück-Startwinkel muss zwischen 0 und 360 Grad sein.',0), +14005 => array('Pie3D Interner Fehler: Versuch, zweimal zu umhüllen bei der Suche nach dem Startindex.',0,), +14006 => array('Pie3D Interner Fehler: Z-Sortier-Algorithmus für 3D-Tortendiagramme funktioniert nicht einwandfrei (2). Versuch, zweimal zu umhüllen beim Erstellen des Bildes.',0), +14007 => array('Die Breite für das 3D-Tortendiagramm ist 0. Gib eine Breite > 0 an.',0), /* ** jpgraph_pie */ 15001 => array('PiePLot::SetTheme() Unbekannter Stil: %s',1), -15002 => array('Argument für PiePlot::ExplodeSlice() muss ein Integer-Wert sein',0), -15003 => array('Argument für PiePlot::Explode() muss ein Vektor mit Integer-Werten sein.',0), -15004 => array('Tortenstück-Startwinkel muss zwischen 0 und 360 Grad sein.',0), +15002 => array('Argument für PiePlot::ExplodeSlice() muss ein Integer-Wert sein',0), +15003 => array('Argument für PiePlot::Explode() muss ein Vektor mit Integer-Werten sein.',0), +15004 => array('Tortenstück-Startwinkel muss zwischen 0 und 360 Grad sein.',0), 15005 => array('PiePlot::SetFont() sollte nicht mehr verwendet werden. Benutze stattdessen PiePlot->value->SetFont().',0), -15006 => array('PiePlot::SetSize() Radius für Tortendiagramm muss entweder als Bruch [0, 0.5] der Bildgröße oder als Absoluwert in Pixel im Bereich [10, 1000] angegeben werden.',0), +15006 => array('PiePlot::SetSize() Radius für Tortendiagramm muss entweder als Bruch [0, 0.5] der Bildgröße oder als Absoluwert in Pixel im Bereich [10, 1000] angegeben werden.',0), 15007 => array('PiePlot::SetFontColor() sollte nicht mehr verwendet werden. Benutze stattdessen PiePlot->value->SetColor()..',0), -15008 => array('PiePlot::SetLabelType() der Typ für Tortendiagramme muss entweder 0 or 1 sein (nicht %d).',1), -15009 => array('Ungültiges Tortendiagramm. Die Summe aller Daten ist Null.',0), +15008 => array('PiePlot::SetLabelType() der Typ für Tortendiagramme muss entweder 0 or 1 sein (nicht %d).',1), +15009 => array('Ungültiges Tortendiagramm. Die Summe aller Daten ist Null.',0), 15010 => array('Die Summe aller Daten ist Null.',0), -15011 => array('Um Bildtransformationen benutzen zu können, muss die Datei jpgraph_imgtrans.php eingefügt werden (per include).',0), +15011 => array('Um Bildtransformationen benutzen zu können, muss die Datei jpgraph_imgtrans.php eingefügt werden (per include).',0), /* ** jpgraph_plotband */ -16001 => array('Die Dichte für das Pattern muss zwischen 1 und 100 sein. (Du hast %f eingegeben)',1), -16002 => array('Es wurde keine Position für das Pattern angegeben.',0), +16001 => array('Die Dichte für das Pattern muss zwischen 1 und 100 sein. (Du hast %f eingegeben)',1), +16002 => array('Es wurde keine Position für das Pattern angegeben.',0), 16003 => array('Unbekannte Pattern-Definition (%d)',0), -16004 => array('Der Mindeswert für das PlotBand ist größer als der Maximalwert. Bitte korrigiere dies!',0), +16004 => array('Der Mindeswert für das PlotBand ist größer als der Maximalwert. Bitte korrigiere dies!',0), /* ** jpgraph_polar */ -17001 => array('PolarPlots müssen eine gerade Anzahl von Datenpunkten haben. Jeder Datenpunkt ist ein Tupel (Winkel, Radius).',0), -17002 => array('Unbekannte Ausrichtung für X-Achsen-Titel. (%s)',1), -//17003 => array('Set90AndMargin() wird für PolarGraph nicht unterstützt.',0), -17004 => array('Unbekannter Achsentyp für PolarGraph. Er muss entweder \'lin\' oder \'log\' sein.',0), +17001 => array('PolarPlots müssen eine gerade Anzahl von Datenpunkten haben. Jeder Datenpunkt ist ein Tupel (Winkel, Radius).',0), +17002 => array('Unbekannte Ausrichtung für X-Achsen-Titel. (%s)',1), +//17003 => array('Set90AndMargin() wird für PolarGraph nicht unterstützt.',0), +17004 => array('Unbekannter Achsentyp für PolarGraph. Er muss entweder \'lin\' oder \'log\' sein.',0), /* ** jpgraph_radar */ -18001 => array('ClientSideImageMaps werden für RadarPlots nicht unterstützt.',0), +18001 => array('ClientSideImageMaps werden für RadarPlots nicht unterstützt.',0), 18002 => array('RadarGraph::SupressTickMarks() sollte nicht mehr verwendet werden. Benutze stattdessen HideTickMarks().',0), -18003 => array('Ungültiger Achsentyp für RadarPlot (%s). Er muss entweder \'lin\' oder \'log\' sein.',1), -18004 => array('Die RadarPlot-Größe muss zwischen 0.1 und 1 sein. (Dein Wert=%f)',1), -18005 => array('RadarPlot: nicht unterstützte Tick-Dichte: %d',1), +18003 => array('Ungültiger Achsentyp für RadarPlot (%s). Er muss entweder \'lin\' oder \'log\' sein.',1), +18004 => array('Die RadarPlot-Größe muss zwischen 0.1 und 1 sein. (Dein Wert=%f)',1), +18005 => array('RadarPlot: nicht unterstützte Tick-Dichte: %d',1), 18006 => array('Minimum Daten %f (RadarPlots sollten nur verwendet werden, wenn alle Datenpunkte einen Wert > 0 haben).',1), 18007 => array('Die Anzahl der Titel entspricht nicht der Anzahl der Datenpunkte.',0), 18008 => array('Jeder RadarPlot muss die gleiche Anzahl von Datenpunkten haben.',0), @@ -222,29 +224,29 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei */ 19001 => array('Spline: Anzahl der X- und Y-Koordinaten muss gleich sein.',0), -19002 => array('Ungültige Dateneingabe für Spline. Zwei oder mehr aufeinanderfolgende X-Werte sind identisch. Jeder eigegebene X-Wert muss unterschiedlich sein, weil vom mathematischen Standpunkt ein Eins-zu-Eins-Mapping vorliegen muss, d.h. jeder X-Wert korrespondiert mit exakt einem Y-Wert.',0), +19002 => array('Ungültige Dateneingabe für Spline. Zwei oder mehr aufeinanderfolgende X-Werte sind identisch. Jeder eigegebene X-Wert muss unterschiedlich sein, weil vom mathematischen Standpunkt ein Eins-zu-Eins-Mapping vorliegen muss, d.h. jeder X-Wert korrespondiert mit exakt einem Y-Wert.',0), 19003 => array('Bezier: Anzahl der X- und Y-Koordinaten muss gleich sein.',0), /* ** jpgraph_scatter */ -20001 => array('Fieldplots müssen die gleiche Anzahl von X und Y Datenpunkten haben.',0), -20002 => array('Bei Fieldplots muss ein Winkel für jeden X und Y Datenpunkt angegeben werden.',0), -20003 => array('Scatterplots müssen die gleiche Anzahl von X- und Y-Datenpunkten haben.',0), +20001 => array('Fieldplots müssen die gleiche Anzahl von X und Y Datenpunkten haben.',0), +20002 => array('Bei Fieldplots muss ein Winkel für jeden X und Y Datenpunkt angegeben werden.',0), +20003 => array('Scatterplots müssen die gleiche Anzahl von X- und Y-Datenpunkten haben.',0), /* ** jpgraph_stock */ -21001 => array('Die Anzahl der Datenwerte für Stock-Charts müssen ein Mehrfaches von %d Datenpunkten sein.',1), +21001 => array('Die Anzahl der Datenwerte für Stock-Charts müssen ein Mehrfaches von %d Datenpunkten sein.',1), /* ** jpgraph_plotmark */ 23001 => array('Der Marker "%s" existiert nicht in der Farbe: %d',2), -23002 => array('Der Farb-Index ist zu hoch für den Marker "%s"',1), +23002 => array('Der Farb-Index ist zu hoch für den Marker "%s"',1), 23003 => array('Ein Dateiname muss angegeben werden, wenn Du den Marker-Typ auf MARK_IMG setzt.',0), /* @@ -259,64 +261,64 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph */ -25001 => array('Diese PHP-Installation ist nicht mit der GD-Bibliothek kompiliert. Bitte kompiliere PHP mit GD-Unterstützung neu, damit JpGraph funktioniert. (Weder die Funktion imagetypes() noch imagecreatefromstring() existiert!)',0), -25002 => array('Diese PHP-Installation scheint nicht die benötigte GD-Bibliothek zu unterstützen. Bitte schau in der PHP-Dokumentation nach, wie man die GD-Bibliothek installiert und aktiviert.',0), +25001 => array('Diese PHP-Installation ist nicht mit der GD-Bibliothek kompiliert. Bitte kompiliere PHP mit GD-Unterstützung neu, damit JpGraph funktioniert. (Weder die Funktion imagetypes() noch imagecreatefromstring() existiert!)',0), +25002 => array('Diese PHP-Installation scheint nicht die benötigte GD-Bibliothek zu unterstützen. Bitte schau in der PHP-Dokumentation nach, wie man die GD-Bibliothek installiert und aktiviert.',0), 25003 => array('Genereller PHP Fehler : Bei %s:%d : %s',3), 25004 => array('Genereller PHP Fehler : %s ',1), 25005 => array('PHP_SELF, die PHP-Global-Variable kann nicht ermittelt werden. PHP kann nicht von der Kommandozeile gestartet werden, wenn der Cache oder die Bilddateien automatisch benannt werden sollen.',0), -25006 => array('Die Benutzung der FF_CHINESE (FF_BIG5) Schriftfamilie benötigt die iconv() Funktion in Deiner PHP-Konfiguration. Dies wird nicht defaultmäßig in PHP kompiliert (benötigt "--width-iconv" bei der Konfiguration).',0), -25007 => array('Du versuchst das lokale (%s) zu verwenden, was von Deiner PHP-Installation nicht unterstützt wird. Hinweis: Benutze \'\', um das defaultmäßige Lokale für diese geographische Region festzulegen.',1), -25008 => array('Die Bild-Breite und Höhe in Graph::Graph() müssen numerisch sein',0), +25006 => array('Die Benutzung der FF_CHINESE (FF_BIG5) Schriftfamilie benötigt die iconv() Funktion in Deiner PHP-Konfiguration. Dies wird nicht defaultmäßig in PHP kompiliert (benötigt "--width-iconv" bei der Konfiguration).',0), +25007 => array('Du versuchst das lokale (%s) zu verwenden, was von Deiner PHP-Installation nicht unterstützt wird. Hinweis: Benutze \'\', um das defaultmäßige Lokale für diese geographische Region festzulegen.',1), +25008 => array('Die Bild-Breite und Höhe in Graph::Graph() müssen numerisch sein',0), 25009 => array('Die Skalierung der Achsen muss angegeben werden mit Graph::SetScale()',0), -25010 => array('Graph::Add() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), -25011 => array('Graph::AddY2() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), -25012 => array('Graph::AddYN() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), -25013 => array('Es können nur Standard-Plots zu multiplen Y-Achsen hinzugefügt werden',0), -25014 => array('Graph::AddText() Du hast versucht, einen leeren Text zum Graph hinzuzufügen.',0), -25015 => array('Graph::AddLine() Du hast versucht, eine leere Linie zum Graph hinzuzufügen.',0), -25016 => array('Graph::AddBand() Du hast versucht, ein leeres Band zum Graph hinzuzufügen.',0), -25017 => array('Du benutzt GD 2.x und versuchst, ein Hintergrundbild in einem Truecolor-Bild zu verwenden. Um Hintergrundbilder mit GD 2.x zu verwenden, ist es notwendig, Truecolor zu aktivieren, indem die USE_TRUECOLOR-Konstante auf TRUE gesetzt wird. Wegen eines Bugs in GD 2.0.1 ist die Qualität der Schrift sehr schlecht, wenn Truetype-Schrift in Truecolor-Bildern verwendet werden.',0), -25018 => array('Falscher Dateiname für Graph::SetBackgroundImage() : "%s" muss eine gültige Dateinamenerweiterung (jpg,gif,png) haben, wenn die automatische Dateityperkennung verwenndet werden soll.',1), -25019 => array('Unbekannte Dateinamenerweiterung (%s) in Graph::SetBackgroundImage() für Dateiname: "%s"',2), +25010 => array('Graph::Add() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), +25011 => array('Graph::AddY2() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), +25012 => array('Graph::AddYN() Du hast versucht, einen leeren Plot zum Graph hinzuzufügen.',0), +25013 => array('Es können nur Standard-Plots zu multiplen Y-Achsen hinzugefügt werden',0), +25014 => array('Graph::AddText() Du hast versucht, einen leeren Text zum Graph hinzuzufügen.',0), +25015 => array('Graph::AddLine() Du hast versucht, eine leere Linie zum Graph hinzuzufügen.',0), +25016 => array('Graph::AddBand() Du hast versucht, ein leeres Band zum Graph hinzuzufügen.',0), +25017 => array('Du benutzt GD 2.x und versuchst, ein Hintergrundbild in einem Truecolor-Bild zu verwenden. Um Hintergrundbilder mit GD 2.x zu verwenden, ist es notwendig, Truecolor zu aktivieren, indem die USE_TRUECOLOR-Konstante auf TRUE gesetzt wird. Wegen eines Bugs in GD 2.0.1 ist die Qualität der Schrift sehr schlecht, wenn Truetype-Schrift in Truecolor-Bildern verwendet werden.',0), +25018 => array('Falscher Dateiname für Graph::SetBackgroundImage() : "%s" muss eine gültige Dateinamenerweiterung (jpg,gif,png) haben, wenn die automatische Dateityperkennung verwenndet werden soll.',1), +25019 => array('Unbekannte Dateinamenerweiterung (%s) in Graph::SetBackgroundImage() für Dateiname: "%s"',2), -25020 => array('Graph::SetScale(): Dar Maximalwert muss größer sein als der Mindestwert.',0), -25021 => array('Unbekannte Achsendefinition für die Y-Achse. (%s)',1), -25022 => array('Unbekannte Achsendefinition für die X-Achse. (%s)',1), -25023 => array('Nicht unterstützter Y2-Achsentyp: "%s" muss einer von (lin,log,int) sein.',1), -25024 => array('Nicht unterstützter X-Achsentyp: "%s" muss einer von (lin,log,int) sein.',1), -25025 => array('Nicht unterstützte Tick-Dichte: %d',1), -25026 => array('Nicht unterstützter Typ der nicht angegebenen Y-Achse. Du hast entweder: 1. einen Y-Achsentyp für automatisches Skalieren definiert, aber keine Plots angegeben. 2. eine Achse direkt definiert, aber vergessen, die Tick-Dichte zu festzulegen.',0), -25027 => array('Kann cached CSIM "%s" zum Lesen nicht öffnen.',1), -25028 => array('Apache/PHP hat keine Schreibrechte, in das CSIM-Cache-Verzeichnis (%s) zu schreiben. Überprüfe die Rechte.',1), -25029 => array('Kann nicht in das CSIM "%s" schreiben. Überprüfe die Schreibrechte und den freien Speicherplatz.',1), +25020 => array('Graph::SetScale(): Dar Maximalwert muss größer sein als der Mindestwert.',0), +25021 => array('Unbekannte Achsendefinition für die Y-Achse. (%s)',1), +25022 => array('Unbekannte Achsendefinition für die X-Achse. (%s)',1), +25023 => array('Nicht unterstützter Y2-Achsentyp: "%s" muss einer von (lin,log,int) sein.',1), +25024 => array('Nicht unterstützter X-Achsentyp: "%s" muss einer von (lin,log,int) sein.',1), +25025 => array('Nicht unterstützte Tick-Dichte: %d',1), +25026 => array('Nicht unterstützter Typ der nicht angegebenen Y-Achse. Du hast entweder: 1. einen Y-Achsentyp für automatisches Skalieren definiert, aber keine Plots angegeben. 2. eine Achse direkt definiert, aber vergessen, die Tick-Dichte zu festzulegen.',0), +25027 => array('Kann cached CSIM "%s" zum Lesen nicht öffnen.',1), +25028 => array('Apache/PHP hat keine Schreibrechte, in das CSIM-Cache-Verzeichnis (%s) zu schreiben. Überprüfe die Rechte.',1), +25029 => array('Kann nicht in das CSIM "%s" schreiben. Überprüfe die Schreibrechte und den freien Speicherplatz.',1), -25030 => array('Fehlender Skriptname für StrokeCSIM(). Der Name des aktuellen Skriptes muss als erster Parameter von StrokeCSIM() angegeben werden.',0), +25030 => array('Fehlender Skriptname für StrokeCSIM(). Der Name des aktuellen Skriptes muss als erster Parameter von StrokeCSIM() angegeben werden.',0), 25031 => array('Der Achsentyp muss mittels Graph::SetScale() angegeben werden.',0), -25032 => array('Es existieren keine Plots für die Y-Achse nbr:%d',1), +25032 => array('Es existieren keine Plots für die Y-Achse nbr:%d',1), 25033 => array('',0), 25034 => array('Undefinierte X-Achse kann nicht gezeichnet werden. Es wurden keine Plots definiert.',0), -25035 => array('Du hast Clipping aktiviert. Clipping wird nur für Diagramme mit 0 oder 90 Grad Rotation unterstützt. Bitte verändere Deinen Rotationswinkel (=%d Grad) dementsprechend oder deaktiviere Clipping.',1), +25035 => array('Du hast Clipping aktiviert. Clipping wird nur für Diagramme mit 0 oder 90 Grad Rotation unterstützt. Bitte verändere Deinen Rotationswinkel (=%d Grad) dementsprechend oder deaktiviere Clipping.',1), 25036 => array('Unbekannter Achsentyp AxisStyle() : %s',1), -25037 => array('Das Bildformat Deines Hintergrundbildes (%s) wird von Deiner System-Konfiguration nicht unterstützt. ',1), +25037 => array('Das Bildformat Deines Hintergrundbildes (%s) wird von Deiner System-Konfiguration nicht unterstützt. ',1), 25038 => array('Das Hintergrundbild scheint von einem anderen Typ (unterschiedliche Dateierweiterung) zu sein als der angegebene Typ. Angegebenen: %s; Datei: %s',2), 25039 => array('Hintergrundbild kann nicht gelesen werden: "%s"',1), -25040 => array('Es ist nicht möglich, sowohl ein Hintergrundbild als auch eine Hintergrund-Landesflagge anzugeben.',0), -25041 => array('Um Landesflaggen als Hintergrund benutzen zu können, muss die Datei "jpgraph_flags.php" eingefügt werden (per include).',0), +25040 => array('Es ist nicht möglich, sowohl ein Hintergrundbild als auch eine Hintergrund-Landesflagge anzugeben.',0), +25041 => array('Um Landesflaggen als Hintergrund benutzen zu können, muss die Datei "jpgraph_flags.php" eingefügt werden (per include).',0), 25042 => array('Unbekanntes Hintergrundbild-Layout',0), 25043 => array('Unbekannter Titelhintergrund-Stil.',0), -25044 => array('Automatisches Skalieren kann nicht verwendet werden, weil es unmöglich ist, einen gültigen min/max Wert für die Y-Achse zu ermitteln (nur Null-Werte).',0), -25045 => array('Die Schriftfamilien FF_HANDWRT und FF_BOOK sind wegen Copyright-Problemen nicht mehr verfügbar. Diese Schriften können nicht mehr mit JpGraph verteilt werden. Bitte lade Dir Schriften von http://corefonts.sourceforge.net/ herunter.',0), +25044 => array('Automatisches Skalieren kann nicht verwendet werden, weil es unmöglich ist, einen gültigen min/max Wert für die Y-Achse zu ermitteln (nur Null-Werte).',0), +25045 => array('Die Schriftfamilien FF_HANDWRT und FF_BOOK sind wegen Copyright-Problemen nicht mehr verfügbar. Diese Schriften können nicht mehr mit JpGraph verteilt werden. Bitte lade Dir Schriften von http://corefonts.sourceforge.net/ herunter.',0), 25046 => array('Angegebene TTF-Schriftfamilie (id=%d) ist unbekannt oder existiert nicht. Bitte merke Dir, dass TTF-Schriften wegen Copyright-Problemen nicht mit JpGraph mitgeliefert werden. Du findest MS-TTF-Internetschriften (arial, courier, etc.) zum Herunterladen unter http://corefonts.sourceforge.net/',1), -25047 => array('Stil %s ist nicht verfügbar für Schriftfamilie %s',2), +25047 => array('Stil %s ist nicht verfügbar für Schriftfamilie %s',2), 25048 => array('Unbekannte Schriftstildefinition [%s].',1), 25049 => array('Schriftdatei "%s" ist nicht lesbar oder existiert nicht.',1), -25050 => array('Erstes Argument für Text::Text() muss ein String sein.',0), -25051 => array('Ungültige Richtung angegeben für Text.',0), -25052 => array('PANIK: Interner Fehler in SuperScript::Stroke(). Unbekannte vertikale Ausrichtung für Text.',0), -25053 => array('PANIK: Interner Fehler in SuperScript::Stroke(). Unbekannte horizontale Ausrichtung für Text.',0), +25050 => array('Erstes Argument für Text::Text() muss ein String sein.',0), +25051 => array('Ungültige Richtung angegeben für Text.',0), +25052 => array('PANIK: Interner Fehler in SuperScript::Stroke(). Unbekannte vertikale Ausrichtung für Text.',0), +25053 => array('PANIK: Interner Fehler in SuperScript::Stroke(). Unbekannte horizontale Ausrichtung für Text.',0), 25054 => array('Interner Fehler: Unbekannte Grid-Achse %s',1), 25055 => array('Axis::SetTickDirection() sollte nicht mehr verwendet werden. Benutze stattdessen Axis::SetTickSide().',0), 25056 => array('SetTickLabelMargin() sollte nicht mehr verwendet werden. Benutze stattdessen Axis::SetLabelMargin().',0), @@ -324,81 +326,91 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei 25058 => array('TextLabelIntevall >= 1 muss angegeben werden.',0), 25059 => array('SetLabelPos() sollte nicht mehr verwendet werden. Benutze stattdessen Axis::SetLabelSide().',0), -25060 => array('Unbekannte Ausrichtung angegeben für X-Achsentitel (%s).',1), -25061 => array('Unbekannte Ausrichtung angegeben für Y-Achsentitel (%s).',1), -25062 => array('Label unter einem Winkel werden für die Y-Achse nicht unterstützt.',0), +25060 => array('Unbekannte Ausrichtung angegeben für X-Achsentitel (%s).',1), +25061 => array('Unbekannte Ausrichtung angegeben für Y-Achsentitel (%s).',1), +25062 => array('Label unter einem Winkel werden für die Y-Achse nicht unterstützt.',0), 25063 => array('Ticks::SetPrecision() sollte nicht mehr verwendet werden. Benutze stattdessen Ticks::SetLabelFormat() (oder Ticks::SetFormatCallback()).',0), -25064 => array('Kleinere oder größere Schrittgröße ist 0. Überprüfe, ob Du fälschlicherweise SetTextTicks(0) in Deinem Skript hast. Wenn dies nicht der Fall ist, bist Du eventuell über einen Bug in JpGraph gestolpert. Bitte sende einen Report und füge den Code an, der den Fehler verursacht hat.',0), -25065 => array('Tick-Positionen müssen als array() angegeben werden',0), +25064 => array('Kleinere oder größere Schrittgröße ist 0. Überprüfe, ob Du fälschlicherweise SetTextTicks(0) in Deinem Skript hast. Wenn dies nicht der Fall ist, bist Du eventuell über einen Bug in JpGraph gestolpert. Bitte sende einen Report und füge den Code an, der den Fehler verursacht hat.',0), +25065 => array('Tick-Positionen müssen als array() angegeben werden',0), 25066 => array('Wenn die Tick-Positionen und -Label von Hand eingegeben werden, muss die Anzahl der Ticks und der Label gleich sein.',0), -25067 => array('Deine von Hand eingegebene Achse und Ticks sind nicht korrekt. Die Skala scheint zu klein zu sein für den Tickabstand.',0), -25068 => array('Ein Plot hat eine ungültige Achse. Dies kann beispielsweise der Fall sein, wenn Du automatisches Text-Skalieren verwendest, um ein Liniendiagramm zu zeichnen mit nur einem Datenpunkt, oder wenn die Bildfläche zu klein ist. Es kann auch der Fall sein, dass kein Datenpunkt einen numerischen Wert hat (vielleicht nur \'-\' oder \'x\').',0), -25069 => array('Grace muss größer sein als 0',0), +25067 => array('Deine von Hand eingegebene Achse und Ticks sind nicht korrekt. Die Skala scheint zu klein zu sein für den Tickabstand.',0), +25068 => array('Ein Plot hat eine ungültige Achse. Dies kann beispielsweise der Fall sein, wenn Du automatisches Text-Skalieren verwendest, um ein Liniendiagramm zu zeichnen mit nur einem Datenpunkt, oder wenn die Bildfläche zu klein ist. Es kann auch der Fall sein, dass kein Datenpunkt einen numerischen Wert hat (vielleicht nur \'-\' oder \'x\').',0), +25069 => array('Grace muss größer sein als 0',0), 25070 => array('Deine Daten enthalten nicht-numerische Werte.',0), -25071 => array('Du hast mit SetAutoMin() einen Mindestwert angegeben, der größer ist als der Maximalwert für die Achse. Dies ist nicht möglich.',0), -25072 => array('Du hast mit SetAutoMax() einen Maximalwert angegeben, der kleiner ist als der Minimalwert der Achse. Dies ist nicht möglich.',0), -25073 => array('Interner Fehler. Der Integer-Skalierungs-Algorithmus-Vergleich ist außerhalb der Grenzen (r=%f).',1), -25074 => array('Interner Fehler. Der Skalierungsbereich ist negativ (%f) [für %s Achse]. Dieses Problem könnte verursacht werden durch den Versuch, \'ungültige\' Werte in die Daten-Vektoren einzugeben (z.B. nur String- oder NULL-Werte), was beim automatischen Skalieren einen Fehler erzeugt.',2), -25075 => array('Die automatischen Ticks können nicht gesetzt werden, weil min==max.',0), -25077 => array('Einstellfaktor für die Farbe muss größer sein als 0',0), +25071 => array('Du hast mit SetAutoMin() einen Mindestwert angegeben, der größer ist als der Maximalwert für die Achse. Dies ist nicht möglich.',0), +25072 => array('Du hast mit SetAutoMax() einen Maximalwert angegeben, der kleiner ist als der Minimalwert der Achse. Dies ist nicht möglich.',0), +25073 => array('Interner Fehler. Der Integer-Skalierungs-Algorithmus-Vergleich ist außerhalb der Grenzen (r=%f).',1), +25074 => array('Interner Fehler. Der Skalierungsbereich ist negativ (%f) [für %s Achse]. Dieses Problem könnte verursacht werden durch den Versuch, \'ungültige\' Werte in die Daten-Vektoren einzugeben (z.B. nur String- oder NULL-Werte), was beim automatischen Skalieren einen Fehler erzeugt.',2), +25075 => array('Die automatischen Ticks können nicht gesetzt werden, weil min==max.',0), +25077 => array('Einstellfaktor für die Farbe muss größer sein als 0',0), 25078 => array('Unbekannte Farbe: %s',1), -25079 => array('Unbekannte Farbdefinition: %s, Größe=%d',2), +25079 => array('Unbekannte Farbdefinition: %s, Größe=%d',2), -25080 => array('Der Alpha-Parameter für Farben muss zwischen 0.0 und 1.0 liegen.',0), -25081 => array('Das ausgewählte Grafikformat wird entweder nicht unterstützt oder ist unbekannt [%s]',1), -25082 => array('Es wurden ungültige Größen für Breite und Höhe beim Erstellen des Bildes definiert (Breite=%d, Höhe=%d).',2), -25083 => array('Es wurde eine ungültige Größe beim Kopieren des Bildes angegeben. Die Größe für das kopierte Bild wurde auf 1 Pixel oder weniger gesetzt.',0), -25084 => array('Fehler beim Erstellen eines temporären GD-Canvas. Möglicherweise liegt ein Arbeitsspeicherproblem vor.',0), -25085 => array('Ein Bild kann nicht aus dem angegebenen String erzeugt werden. Er ist entweder in einem nicht unterstützen Format oder er represäntiert ein kaputtes Bild.',0), -25086 => array('Du scheinst nur GD 1.x installiert zu haben. Um Alphablending zu aktivieren, ist GD 2.x oder höher notwendig. Bitte installiere GD 2.x oder versichere Dich, dass die Konstante USE_GD2 richtig gesetzt ist. Standardmäßig wird die installierte GD-Version automatisch erkannt. Ganz selten wird GD2 erkannt, obwohl nur GD1 installiert ist. Die Konstante USE_GD2 muss dann zu "false" gesetzt werden.',0), -25087 => array('Diese PHP-Version wurde ohne TTF-Unterstützung konfiguriert. PHP muss mit TTF-Unterstützung neu kompiliert und installiert werden.',0), -25088 => array('Die GD-Schriftunterstützung wurde falsch konfiguriert. Der Aufruf von imagefontwidth() ist fehlerhaft.',0), -25089 => array('Die GD-Schriftunterstützung wurde falsch konfiguriert. Der Aufruf von imagefontheight() ist fehlerhaft.',0), +25080 => array('Der Alpha-Parameter für Farben muss zwischen 0.0 und 1.0 liegen.',0), +25081 => array('Das ausgewählte Grafikformat wird entweder nicht unterstützt oder ist unbekannt [%s]',1), +25082 => array('Es wurden ungültige Größen für Breite und Höhe beim Erstellen des Bildes definiert (Breite=%d, Höhe=%d).',2), +25083 => array('Es wurde eine ungültige Größe beim Kopieren des Bildes angegeben. Die Größe für das kopierte Bild wurde auf 1 Pixel oder weniger gesetzt.',0), +25084 => array('Fehler beim Erstellen eines temporären GD-Canvas. Möglicherweise liegt ein Arbeitsspeicherproblem vor.',0), +25085 => array('Ein Bild kann nicht aus dem angegebenen String erzeugt werden. Er ist entweder in einem nicht unterstützen Format oder er represäntiert ein kaputtes Bild.',0), +25086 => array('Du scheinst nur GD 1.x installiert zu haben. Um Alphablending zu aktivieren, ist GD 2.x oder höher notwendig. Bitte installiere GD 2.x oder versichere Dich, dass die Konstante USE_GD2 richtig gesetzt ist. Standardmäßig wird die installierte GD-Version automatisch erkannt. Ganz selten wird GD2 erkannt, obwohl nur GD1 installiert ist. Die Konstante USE_GD2 muss dann zu "false" gesetzt werden.',0), +25087 => array('Diese PHP-Version wurde ohne TTF-Unterstützung konfiguriert. PHP muss mit TTF-Unterstützung neu kompiliert und installiert werden.',0), +25088 => array('Die GD-Schriftunterstützung wurde falsch konfiguriert. Der Aufruf von imagefontwidth() ist fehlerhaft.',0), +25089 => array('Die GD-Schriftunterstützung wurde falsch konfiguriert. Der Aufruf von imagefontheight() ist fehlerhaft.',0), 25090 => array('Unbekannte Richtung angegeben im Aufruf von StrokeBoxedText() [%s].',1), -25091 => array('Die interne Schrift untestützt das Schreiben von Text in einem beliebigen Winkel nicht. Benutze stattdessen TTF-Schriften.',0), -25092 => array('Es liegt entweder ein Konfigurationsproblem mit TrueType oder ein Problem beim Lesen der Schriftdatei "%s" vor. Versichere Dich, dass die Datei existiert und Leserechte und -pfad vergeben sind. (wenn \'basedir\' restriction in PHP aktiviert ist, muss die Schriftdatei im Dokumentwurzelverzeichnis abgelegt werden). Möglicherweise ist die FreeType-Bibliothek falsch installiert. Versuche, mindestens zur FreeType-Version 2.1.13 zu aktualisieren und kompiliere GD mit einem korrekten Setup neu, damit die FreeType-Bibliothek gefunden werden kann.',1), +25091 => array('Die interne Schrift untestützt das Schreiben von Text in einem beliebigen Winkel nicht. Benutze stattdessen TTF-Schriften.',0), +25092 => array('Es liegt entweder ein Konfigurationsproblem mit TrueType oder ein Problem beim Lesen der Schriftdatei "%s" vor. Versichere Dich, dass die Datei existiert und Leserechte und -pfad vergeben sind. (wenn \'basedir\' restriction in PHP aktiviert ist, muss die Schriftdatei im Dokumentwurzelverzeichnis abgelegt werden). Möglicherweise ist die FreeType-Bibliothek falsch installiert. Versuche, mindestens zur FreeType-Version 2.1.13 zu aktualisieren und kompiliere GD mit einem korrekten Setup neu, damit die FreeType-Bibliothek gefunden werden kann.',1), 25093 => array('Die Schriftdatei "%s" kann nicht gelesen werden beim Aufruf von Image::GetBBoxTTF. Bitte versichere Dich, dass die Schrift gesetzt wurde, bevor diese Methode aufgerufen wird, und dass die Schrift im TTF-Verzeichnis installiert ist.',1), 25094 => array('Die Textrichtung muss in einem Winkel zwischen 0 und 90 engegeben werden.',0), 25095 => array('Unbekannte Schriftfamilien-Definition. ',0), -25096 => array('Der Farbpalette können keine weiteren Farben zugewiesen werden. Dem Bild wurde bereits die größtmögliche Anzahl von Farben (%d) zugewiesen und die Palette ist voll. Verwende stattdessen ein TrueColor-Bild',0), +25096 => array('Der Farbpalette können keine weiteren Farben zugewiesen werden. Dem Bild wurde bereits die größtmögliche Anzahl von Farben (%d) zugewiesen und die Palette ist voll. Verwende stattdessen ein TrueColor-Bild',0), 25097 => array('Eine Farbe wurde als leerer String im Aufruf von PushColor() angegegeben.',0), 25098 => array('Negativer Farbindex. Unpassender Aufruf von PopColor().',0), -25099 => array('Die Parameter für Helligkeit und Kontrast sind außerhalb des zulässigen Bereichs [-1,1]',0), +25099 => array('Die Parameter für Helligkeit und Kontrast sind außerhalb des zulässigen Bereichs [-1,1]',0), 25100 => array('Es liegt ein Problem mit der Farbpalette und dem GD-Setup vor. Bitte deaktiviere anti-aliasing oder verwende GD2 mit TrueColor. Wenn die GD2-Bibliothek installiert ist, versichere Dich, dass die Konstante USE_GD2 auf "true" gesetzt und TrueColor aktiviert ist.',0), -25101 => array('Ungültiges numerisches Argument für SetLineStyle(): (%d)',1), -25102 => array('Ungültiges String-Argument für SetLineStyle(): %s',1), -25103 => array('Ungültiges Argument für SetLineStyle %s',1), +25101 => array('Ungültiges numerisches Argument für SetLineStyle(): (%d)',1), +25102 => array('Ungültiges String-Argument für SetLineStyle(): %s',1), +25103 => array('Ungültiges Argument für SetLineStyle %s',1), 25104 => array('Unbekannter Linientyp: %s',1), -25105 => array('Es wurden NULL-Daten für ein gefülltes Polygon angegeben. Sorge dafür, dass keine NULL-Daten angegeben werden.',0), -25106 => array('Image::FillToBorder : es können keine weiteren Farben zugewiesen werden.',0), -25107 => array('In Datei "%s" kann nicht geschrieben werden. Überprüfe die aktuellen Schreibrechte.',1), -25108 => array('Das Bild kann nicht gestreamt werden. Möglicherweise liegt ein Fehler im PHP/GD-Setup vor. Kompiliere PHP neu und verwende die eingebaute GD-Bibliothek, die mit PHP angeboten wird.',0), -25109 => array('Deine PHP- (und GD-lib-) Installation scheint keine bekannten Grafikformate zu unterstützen. Sorge zunächst dafür, dass GD als PHP-Modul kompiliert ist. Wenn Du außerdem JPEG-Bilder verwenden willst, musst Du die JPEG-Bibliothek installieren. Weitere Details sind in der PHP-Dokumentation zu finden.',0), +25105 => array('Es wurden NULL-Daten für ein gefülltes Polygon angegeben. Sorge dafür, dass keine NULL-Daten angegeben werden.',0), +25106 => array('Image::FillToBorder : es können keine weiteren Farben zugewiesen werden.',0), +25107 => array('In Datei "%s" kann nicht geschrieben werden. Überprüfe die aktuellen Schreibrechte.',1), +25108 => array('Das Bild kann nicht gestreamt werden. Möglicherweise liegt ein Fehler im PHP/GD-Setup vor. Kompiliere PHP neu und verwende die eingebaute GD-Bibliothek, die mit PHP angeboten wird.',0), +25109 => array('Deine PHP- (und GD-lib-) Installation scheint keine bekannten Grafikformate zu unterstützen. Sorge zunächst dafür, dass GD als PHP-Modul kompiliert ist. Wenn Du außerdem JPEG-Bilder verwenden willst, musst Du die JPEG-Bibliothek installieren. Weitere Details sind in der PHP-Dokumentation zu finden.',0), -25110 => array('Dein PHP-Installation unterstützt das gewählte Grafikformat nicht: %s',1), -25111 => array('Das gecachete Bild %s kann nicht gelöscht werden. Problem mit den Rechten?',1), +25110 => array('Dein PHP-Installation unterstützt das gewählte Grafikformat nicht: %s',1), +25111 => array('Das gecachete Bild %s kann nicht gelöscht werden. Problem mit den Rechten?',1), 25112 => array('Das Datum der gecacheten Datei (%s) liegt in der Zukunft.',1), -25113 => array('Das gecachete Bild %s kann nicht gelöscht werden. Problem mit den Rechten?',1), -25114 => array('PHP hat nicht die erforderlichen Rechte, um in die Cache-Datei %s zu schreiben. Bitte versichere Dich, dass der Benutzer, der PHP anwendet, die entsprechenden Schreibrechte für die Datei hat, wenn Du das Cache-System in JPGraph verwenden willst.',1), -25115 => array('Berechtigung für gecachetes Bild %s kann nicht gesetzt werden. Problem mit den Rechten?',1), -25116 => array('Datei kann nicht aus dem Cache %s geöffnet werden',1), -25117 => array('Gecachetes Bild %s kann nicht zum Lesen geöffnet werden.',1), +25113 => array('Das gecachete Bild %s kann nicht gelöscht werden. Problem mit den Rechten?',1), +25114 => array('PHP hat nicht die erforderlichen Rechte, um in die Cache-Datei %s zu schreiben. Bitte versichere Dich, dass der Benutzer, der PHP anwendet, die entsprechenden Schreibrechte für die Datei hat, wenn Du das Cache-System in JPGraph verwenden willst.',1), +25115 => array('Berechtigung für gecachetes Bild %s kann nicht gesetzt werden. Problem mit den Rechten?',1), +25116 => array('Datei kann nicht aus dem Cache %s geöffnet werden',1), +25117 => array('Gecachetes Bild %s kann nicht zum Lesen geöffnet werden.',1), 25118 => array('Verzeichnis %s kann nicht angelegt werden. Versichere Dich, dass PHP die Schreibrechte in diesem Verzeichnis hat.',1), -25119 => array('Rechte für Datei %s können nicht gesetzt werden. Problem mit den Rechten?',1), +25119 => array('Rechte für Datei %s können nicht gesetzt werden. Problem mit den Rechten?',1), -25120 => array('Die Position für die Legende muss als Prozentwert im Bereich 0-1 angegeben werden.',0), -25121 => array('Eine leerer Datenvektor wurde für den Plot eingegeben. Es muss wenigstens ein Datenpunkt vorliegen.',0), +25120 => array('Die Position für die Legende muss als Prozentwert im Bereich 0-1 angegeben werden.',0), +25121 => array('Eine leerer Datenvektor wurde für den Plot eingegeben. Es muss wenigstens ein Datenpunkt vorliegen.',0), 25122 => array('Stroke() muss als Subklasse der Klasse Plot definiert sein.',0), 25123 => array('Du kannst keine Text-X-Achse mit X-Koordinaten verwenden. Benutze stattdessen eine "int" oder "lin" Achse.',0), -25124 => array('Der Eingabedatenvektor mus aufeinanderfolgende Werte von 0 aufwärts beinhalten. Der angegebene Y-Vektor beginnt mit leeren Werten (NULL).',0), -25125 => array('Ungültige Richtung für statische Linie.',0), -25126 => array('Es kann kein TrueColor-Bild erzeugt werden. Überprüfe, ob die GD2-Bibliothek und PHP korrekt aufgesetzt wurden.',0), +25124 => array('Der Eingabedatenvektor mus aufeinanderfolgende Werte von 0 aufwärts beinhalten. Der angegebene Y-Vektor beginnt mit leeren Werten (NULL).',0), +25125 => array('Ungültige Richtung für statische Linie.',0), +25126 => array('Es kann kein TrueColor-Bild erzeugt werden. Überprüfe, ob die GD2-Bibliothek und PHP korrekt aufgesetzt wurden.',0), 25127 => array('The library has been configured for automatic encoding conversion of Japanese fonts. This requires that PHP has the mb_convert_encoding() function. Your PHP installation lacks this function (PHP needs the "--enable-mbstring" when compiled).',0), 25128 => array('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.',0), 25129 => array('Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines.',0), +25130 => array('Too small plot area. (%d x %d). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins.',2), + + +/* +** jpgraph_led +*/ + +25500 => array('Multibyte strings must be enabled in the PHP installation in order to run the LED module so that the function mb_strlen() is available. See PHP documentation for more information.',0), + + /* **--------------------------------------------------------------------------------------------- ** Pro-version strings @@ -409,19 +421,19 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph_table */ -27001 => array('GTextTable: Ungültiges Argument für Set(). Das Array-Argument muss 2-- dimensional sein.',0), -27002 => array('GTextTable: Ungültiges Argument für Set()',0), -27003 => array('GTextTable: Falsche Anzahl von Argumenten für GTextTable::SetColor()',0), -27004 => array('GTextTable: Angegebener Zellenbereich, der verschmolzen werden soll, ist ungültig.',0), -27005 => array('GTextTable: Bereits verschmolzene Zellen im Bereich (%d,%d) bis (%d,%d) können nicht ein weiteres Mal verschmolzen werden.',4), -27006 => array('GTextTable: Spalten-Argument = %d liegt außerhalb der festgelegten Tabellengröße.',1), -27007 => array('GTextTable: Zeilen-Argument = %d liegt außerhalb der festgelegten Tabellengröße.',1), -27008 => array('GTextTable: Spalten- und Zeilengröße müssen zu den Dimensionen der Tabelle passen.',0), +27001 => array('GTextTable: Ungültiges Argument für Set(). Das Array-Argument muss 2-- dimensional sein.',0), +27002 => array('GTextTable: Ungültiges Argument für Set()',0), +27003 => array('GTextTable: Falsche Anzahl von Argumenten für GTextTable::SetColor()',0), +27004 => array('GTextTable: Angegebener Zellenbereich, der verschmolzen werden soll, ist ungültig.',0), +27005 => array('GTextTable: Bereits verschmolzene Zellen im Bereich (%d,%d) bis (%d,%d) können nicht ein weiteres Mal verschmolzen werden.',4), +27006 => array('GTextTable: Spalten-Argument = %d liegt außerhalb der festgelegten Tabellengröße.',1), +27007 => array('GTextTable: Zeilen-Argument = %d liegt außerhalb der festgelegten Tabellengröße.',1), +27008 => array('GTextTable: Spalten- und Zeilengröße müssen zu den Dimensionen der Tabelle passen.',0), 27009 => array('GTextTable: Die Anzahl der Tabellenspalten oder -zeilen ist 0. Versichere Dich, dass die Methoden Init() oder Set() aufgerufen werden.',0), 27010 => array('GTextTable: Es wurde keine Ausrichtung beim Aufruf von SetAlign() angegeben.',0), 27011 => array('GTextTable: Es wurde eine unbekannte Ausrichtung beim Aufruf von SetAlign() abgegeben. Horizontal=%s, Vertikal=%s',2), -27012 => array('GTextTable: Interner Fehler. Es wurde ein ungültiges Argument festgeleget %s',1), -27013 => array('GTextTable: Das Argument für FormatNumber() muss ein String sein.',0), +27012 => array('GTextTable: Interner Fehler. Es wurde ein ungültiges Argument festgeleget %s',1), +27013 => array('GTextTable: Das Argument für FormatNumber() muss ein String sein.',0), 27014 => array('GTextTable: Die Tabelle wurde weder mit einem Aufruf von Set() noch von Init() initialisiert.',0), 27015 => array('GTextTable: Der Zellenbildbedingungstyp muss entweder TIMG_WIDTH oder TIMG_HEIGHT sein.',0), @@ -429,25 +441,25 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei ** jpgraph_windrose */ -22001 => array('Die Gesamtsumme der prozentualen Anteile aller Windrosenarme darf 100%% nicht überschreiten!\n(Aktuell max: %d)',1), -22002 => array('Das Bild ist zu klein für eine Skala. Bitte vergrößere das Bild.',0), -22004 => array('Die Etikettendefinition für Windrosenrichtungen müssen 16 Werte haben (eine für jede Kompassrichtung).',0), -22005 => array('Der Linientyp für radiale Linien muss einer von ("solid","dotted","dashed","longdashed") sein.',0), -22006 => array('Es wurde ein ungültiger Windrosentyp angegeben.',0), -22007 => array('Es wurden zu wenig Werte für die Bereichslegende angegeben.',0), +22001 => array('Die Gesamtsumme der prozentualen Anteile aller Windrosenarme darf 100%% nicht überschreiten!\n(Aktuell max: %d)',1), +22002 => array('Das Bild ist zu klein für eine Skala. Bitte vergrößere das Bild.',0), +22004 => array('Die Etikettendefinition für Windrosenrichtungen müssen 16 Werte haben (eine für jede Kompassrichtung).',0), +22005 => array('Der Linientyp für radiale Linien muss einer von ("solid","dotted","dashed","longdashed") sein.',0), +22006 => array('Es wurde ein ungültiger Windrosentyp angegeben.',0), +22007 => array('Es wurden zu wenig Werte für die Bereichslegende angegeben.',0), 22008 => array('Interner Fehler: Versuch, eine freie Windrose zu plotten, obwohl der Typ keine freie Windrose ist.',0), 22009 => array('Du hast die gleiche Richtung zweimal angegeben, einmal mit einem Winkel und einmal mit einer Kompassrichtung (%f Grad).',0), 22010 => array('Die Richtung muss entweder ein numerischer Wert sein oder eine der 16 Kompassrichtungen',0), 22011 => array('Der Windrosenindex muss ein numerischer oder Richtungswert sein. Du hast angegeben Index=%d',1), -22012 => array('Die radiale Achsendefinition für die Windrose enthält eine nicht aktivierte Richtung.',0), -22013 => array('Du hast dasselbe Look&Feel für die gleiche Kompassrichtung zweimal engegeben, einmal mit Text und einmal mit einem Index (Index=%d)',1), -22014 => array('Der Index für eine Kompassrichtung muss zwischen 0 und 15 sein.',0), +22012 => array('Die radiale Achsendefinition für die Windrose enthält eine nicht aktivierte Richtung.',0), +22013 => array('Du hast dasselbe Look&Feel für die gleiche Kompassrichtung zweimal engegeben, einmal mit Text und einmal mit einem Index (Index=%d)',1), +22014 => array('Der Index für eine Kompassrichtung muss zwischen 0 und 15 sein.',0), 22015 => array('Du hast einen unbekannten Windrosenplottyp angegeben.',0), 22016 => array('Der Windrosenarmindex muss ein numerischer oder ein Richtungswert sein.',0), 22017 => array('Die Windrosendaten enthalten eine Richtung, die nicht aktiviert ist. Bitte berichtige, welche Label angezeigt werden sollen.',0), -22018 => array('Du hast für dieselbe Kompassrichtung zweimal Daten angegeben, einmal mit Text und einmal mit einem Index (Index=%d)',1), -22019 => array('Der Index für eine Richtung muss zwischen 0 und 15 sein. Winkel dürfen nicht für einen regelmäßigen Windplot angegeben werden, sondern entweder ein Index oder eine Kompassrichtung.',0), -22020 => array('Der Windrosenplot ist zu groß für die angegebene Bildgröße. Benutze entweder WindrosePlot::SetSize(), um den Plot kleiner zu machen oder vergrößere das Bild im ursprünglichen Aufruf von WindroseGraph().',0), +22018 => array('Du hast für dieselbe Kompassrichtung zweimal Daten angegeben, einmal mit Text und einmal mit einem Index (Index=%d)',1), +22019 => array('Der Index für eine Richtung muss zwischen 0 und 15 sein. Winkel dürfen nicht für einen regelmäßigen Windplot angegeben werden, sondern entweder ein Index oder eine Kompassrichtung.',0), +22020 => array('Der Windrosenplot ist zu groß für die angegebene Bildgröße. Benutze entweder WindrosePlot::SetSize(), um den Plot kleiner zu machen oder vergrößere das Bild im ursprünglichen Aufruf von WindroseGraph().',0), 22021 => array('It is only possible to add Text, IconPlot or WindrosePlot to a Windrose Graph',0), /* @@ -455,7 +467,7 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei */ 13001 => array('Unbekannter Nadeltypstil (%d).',1), -13002 => array('Ein Wert für das Odometer (%f) ist außerhalb des angegebenen Bereichs [%f,%f]',3), +13002 => array('Ein Wert für das Odometer (%f) ist außerhalb des angegebenen Bereichs [%f,%f]',3), /* ** jpgraph_barcode @@ -463,38 +475,63 @@ HTTP header wurden bereits gesendet.
Fehler in der Datei %s in der Zei 1001 => array('Unbekannte Kodier-Specifikation: %s',1), 1002 => array('datenvalidierung schlug fehl. [%s] kann nicht mittels der Kodierung "%s" kodiert werden',2), -1003 => array('Interner Kodierfehler. Kodieren von %s ist nicht möglich in Code 128',1), +1003 => array('Interner Kodierfehler. Kodieren von %s ist nicht möglich in Code 128',1), 1004 => array('Interner barcode Fehler. Unbekannter UPC-E Kodiertyp: %s',1), 1005 => array('Interner Fehler. Das Textzeichen-Tupel (%s, %s) kann nicht im Code-128 Zeichensatz C kodiert werden.',2), -1006 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, CTRL in CHARSET != A zu kodieren.',0), -1007 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, DEL in CHARSET != B zu kodieren.',0), -1008 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, kleine Buchstaben in CHARSET != B zu kodieren.',0), -1009 => array('Kodieren mittels CODE 93 wird noch nicht unterstützt.',0), -1010 => array('Kodieren mittels POSTNET wird noch nicht unterstützt.',0), -1011 => array('Nicht untrstütztes Barcode-Backend für den Typ %s',1), +1006 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, CTRL in CHARSET != A zu kodieren.',0), +1007 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, DEL in CHARSET != B zu kodieren.',0), +1008 => array('Interner Kodierfehler für CODE 128. Es wurde versucht, kleine Buchstaben in CHARSET != B zu kodieren.',0), +1009 => array('Kodieren mittels CODE 93 wird noch nicht unterstützt.',0), +1010 => array('Kodieren mittels POSTNET wird noch nicht unterstützt.',0), +1011 => array('Nicht untrstütztes Barcode-Backend für den Typ %s',1), /* ** PDF417 */ +26000 => array('PDF417: The PDF417 module requires that the PHP installation must support the function bcmod(). This is normally enabled at compile time. See documentation for more information.',0), 26001 => array('PDF417: Die Anzahl der Spalten muss zwischen 1 und 30 sein.',0), 26002 => array('PDF417: Der Fehler-Level muss zwischen 0 und 8 sein.',0), -26003 => array('PDF417: Ungültiges Format für Eingabedaten, um sie mit PDF417 zu kodieren.',0), -26004 => array('PDF417: die eigebenen Daten können nicht mit Fehler-Level %d und %d spalten kodiert werden, weil daraus zu viele Symbole oder mehr als 90 Zeilen resultieren.',2), -26005 => array('PDF417: Die Datei "%s" kann nicht zum Schreiben geöffnet werden.',1), -26006 => array('PDF417: Interner Fehler. Die Eingabedatendatei für PDF417-Cluster %d ist fehlerhaft.',1), -26007 => array('PDF417: Interner Fehler. GetPattern: Ungültiger Code-Wert %d (Zeile %d)',2), +26003 => array('PDF417: Ungültiges Format für Eingabedaten, um sie mit PDF417 zu kodieren.',0), +26004 => array('PDF417: die eigebenen Daten können nicht mit Fehler-Level %d und %d spalten kodiert werden, weil daraus zu viele Symbole oder mehr als 90 Zeilen resultieren.',2), +26005 => array('PDF417: Die Datei "%s" kann nicht zum Schreiben geöffnet werden.',1), +26006 => array('PDF417: Interner Fehler. Die Eingabedatendatei für PDF417-Cluster %d ist fehlerhaft.',1), +26007 => array('PDF417: Interner Fehler. GetPattern: Ungültiger Code-Wert %d (Zeile %d)',2), 26008 => array('PDF417: Interner Fehler. Modus wurde nicht in der Modusliste!! Modus %d',1), -26009 => array('PDF417: Kodierfehler: Ungültiges Zeichen. Zeichen kann nicht mit ASCII-Code %d kodiert werden.',1), +26009 => array('PDF417: Kodierfehler: Ungültiges Zeichen. Zeichen kann nicht mit ASCII-Code %d kodiert werden.',1), 26010 => array('PDF417: Interner Fehler: Keine Eingabedaten beim Dekodieren.',0), -26011 => array('PDF417: Kodierfehler. Numerisches Kodieren bei nicht-numerischen Daten nicht möglich.',0), -26012 => array('PDF417: Interner Fehler. Es wurden für den Binary-Kompressor keine Daten zum Dekodieren eingegeben.',0), +26011 => array('PDF417: Kodierfehler. Numerisches Kodieren bei nicht-numerischen Daten nicht möglich.',0), +26012 => array('PDF417: Interner Fehler. Es wurden für den Binary-Kompressor keine Daten zum Dekodieren eingegeben.',0), 26013 => array('PDF417: Interner Fehler. Checksum Fehler. Koeffiziententabellen sind fehlerhaft.',0), -26014 => array('PDF417: Interner Fehler. Es wurden keine Daten zum Berechnen von Kodewörtern eingegeben.',0), -26015 => array('PDF417: Interner Fehler. Ein Eintrag 0 in die Statusübertragungstabellen ist nicht NULL. Eintrag 1 = (%s)',1), -26016 => array('PDF417: Interner Fehler: Nichtregistrierter Statusübertragungsmodus beim Dekodieren.',0), +26014 => array('PDF417: Interner Fehler. Es wurden keine Daten zum Berechnen von Kodewörtern eingegeben.',0), +26015 => array('PDF417: Interner Fehler. Ein Eintrag 0 in die Statusübertragungstabellen ist nicht NULL. Eintrag 1 = (%s)',1), +26016 => array('PDF417: Interner Fehler: Nichtregistrierter Statusübertragungsmodus beim Dekodieren.',0), +/* +** jpgraph_contour +*/ + +28001 => array('Dritten parameter fur Contour muss ein vector der fargen sind.',0), +28002 => array('Die anzahlen der farges jeder isobar linien muss gleich sein.',0), +28003 => array('ContourPlot Interner Fehler: isobarHCrossing: Spalten index ist zu hoch (%d)',1), +28004 => array('ContourPlot Interner Fehler: isobarHCrossing: Reihe index ist zu hoch (%d)',1), +28005 => array('ContourPlot Interner Fehler: isobarVCrossing: Reihe index ist zu hoch (%d)',1), +28006 => array('ContourPlot Interner Fehler: isobarVCrossing: Spalten index ist zu hoch (%d)',1), +28007 => array('ContourPlot. Interpolation faktor ist zu hoch (>5)',0), + + +/* + * jpgraph_matrix and colormap +*/ +29201 => array('Min range value must be less or equal to max range value for colormaps'), +29202 => array('The distance between min and max value is too small for numerical precision'), +29203 => array('Number of color quantification level must be at least %d',1), +29204 => array('Number of colors (%d) is invalid for this colormap. It must be a number that can be written as: %d + k*%d',3), +29205 => array('Colormap specification out of range. Must be an integer in range [0,%d]',1), +29206 => array('Invalid object added to MatrixGraph'), +29207 => array('Empty input data specified for MatrixPlot'), + ); ?> diff --git a/src/classes/jpgraph/lang/en.inc.php b/src/classes/jpgraph/lang/en.inc.php index e61080e..cb57030 100644 --- a/src/classes/jpgraph/lang/en.inc.php +++ b/src/classes/jpgraph/lang/en.inc.php @@ -1,9 +1,9 @@ array('
JpGraph Error: +10 => array('
JpGraph Error: HTTP headers have already been sent.
Caused by output from file %s at line %d.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it\'s image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).

Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

For example it is a common mistake to leave a blank line before the opening "<?php".

',2), /* @@ -44,6 +44,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 2012 => array('One of the objects submitted to AccBar is not a BarPlot. Make sure that you create the AccBar plot from an array of BarPlot objects. (Class=%s)',1), 2013 => array('You have specified an empty array for shadow colors in the bar plot.',0), 2014 => array('Number of datapoints for each data set in accbarplot must be the same',0), +2015 => array('Individual bar plots in an AccBarPlot or GroupBarPlot can not have specified X-coordinates',0), /* @@ -74,8 +75,8 @@ HTTP headers have already been sent.
Caused by output from file %s at 6001 => array('Internal error. Height for ActivityTitles is < 0',0), 6002 => array('You can\'t specify negative sizes for Gantt graph dimensions. Use 0 to indicate that you want the library to automatically determine a dimension.',0), -6003 => array('Invalid format for Constrain parameter at index=%d in CreateSimple(). Parameter must start with index 0 and contain arrays of (Row,Constrain-To,Constrain-Type)',1), -6004 => array('Invalid format for Progress parameter at index=%d in CreateSimple(). Parameter must start with index 0 and contain arrays of (Row,Progress)',1), +6003 => array('Invalid format for Constrain parameter at index=%d in CreateSimple(). Parameter must start with index 0 and contain arrays of (Row,Constrain-To,Constrain-Type)',1), +6004 => array('Invalid format for Progress parameter at index=%d in CreateSimple(). Parameter must start with index 0 and contain arrays of (Row,Progress)',1), 6005 => array('SetScale() is not meaningful with Gantt charts.',0), 6006 => array('Cannot autoscale Gantt chart. No dated activities exist. [GetBarMinMax() start >= n]',0), 6007 => array('Sanity check for automatic Gantt chart size failed. Either the width (=%d) or height (=%d) is larger than MAX_GANTTIMG_SIZE. This could potentially be caused by a wrong date in one of the activities.',2), @@ -270,11 +271,11 @@ HTTP headers have already been sent.
Caused by output from file %s at 25009 => array('You must specify what scale to use with a call to Graph::SetScale()',0), 25010 => array('Graph::Add() You tried to add a null plot to the graph.',0), -25011 => array('Graph::AddY2() You tried to add a null plot to the graph.',0), -25012 => array('Graph::AddYN() You tried to add a null plot to the graph.',0), +25011 => array('Graph::AddY2() You tried to add a null plot to the graph.',0), +25012 => array('Graph::AddYN() You tried to add a null plot to the graph.',0), 25013 => array('You can only add standard plots to multiple Y-axis',0), -25014 => array('Graph::AddText() You tried to add a null text to the graph.',0), -25015 => array('Graph::AddLine() You tried to add a null line to the graph.',0), +25014 => array('Graph::AddText() You tried to add a null text to the graph.',0), +25015 => array('Graph::AddLine() You tried to add a null line to the graph.',0), 25016 => array('Graph::AddBand() You tried to add a null band to the graph.',0), 25017 => array('You are using GD 2.x and are trying to use a background images on a non truecolor image. To use background images with GD 2.x it is necessary to enable truecolor by setting the USE_TRUECOLOR constant to TRUE. Due to a bug in GD 2.0.1 using any truetype fonts with truecolor images will result in very poor quality fonts.',0), 25018 => array('Incorrect file name for Graph::SetBackgroundImage() : "%s" Must have a valid image extension (jpg,gif,png) when using auto detection of image type',1), @@ -300,7 +301,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 25036 => array('Unknown AxisStyle() : %s',1), 25037 => array('The image format of your background image (%s) is not supported in your system configuration. ',1), 25038 => array('Background image seems to be of different type (has different file extension) than specified imagetype. Specified: %s File: %s',2), -25039 => array('Can\'t read background image: "%s"',1), +25039 => array('Can\'t read background image: "%s"',1), 25040 => array('It is not possible to specify both a background image and a background country flag.',0), 25041 => array('In order to use Country flags as backgrounds you must include the "jpgraph_flags.php" file.',0), @@ -320,7 +321,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 25054 => array('Internal error: Unknown grid axis %s',1), 25055 => array('Axis::SetTickDirection() is deprecated. Use Axis::SetTickSide() instead',0), 25056 => array('SetTickLabelMargin() is deprecated. Use Axis::SetLabelMargin() instead.',0), -25057 => array('SetTextTicks() is deprecated. Use SetTextTickInterval() instead.',0), +25057 => array('SetTextTicks() is deprecated. Use SetTextTickInterval() instead.',0), 25058 => array('Text label interval must be specified >= 1.',0), 25059 => array('SetLabelPos() is deprecated. Use Axis::SetLabelSide() instead.',0), @@ -364,7 +365,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 25096 => array('Can\'t allocate any more colors in palette image. Image has already allocated maximum of %d colors and the palette is now full. Change to a truecolor image instead',0), 25097 => array('Color specified as empty string in PushColor().',0), 25098 => array('Negative Color stack index. Unmatched call to PopColor()',0), -25099 => array('Parameters for brightness and Contrast out of range [-1,1]',0), +25099 => array('Parameters for brightness and Contrast out of range [-1,1]',0), 25100 => array('Problem with color palette and your GD setup. Please disable anti-aliasing or use GD2 with true-color. If you have GD2 library installed please make sure that you have set the USE_GD2 constant to true and truecolor is enabled.',0), 25101 => array('Illegal numeric argument to SetLineStyle(): (%d)',1), @@ -383,7 +384,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 25113 => array('Can\'t delete cached image "%s". Permission problem?',1), 25114 => array('PHP has not enough permissions to write to the cache file "%s". Please make sure that the user running PHP has write permission for this file if you wan to use the cache system with JpGraph.',1), 25115 => array('Can\'t set permission for cached image "%s". Permission problem?',1), -25116 => array('Cant open file from cache "%s"',1), +25116 => array('Cant open file from cache "%s"',1), 25117 => array('Can\'t open cached image "%s" for reading.',1), 25118 => array('Can\'t create directory "%s". Make sure PHP has write permission to this directory.',1), 25119 => array('Can\'t set permissions for "%s". Permission problems?',1), @@ -398,7 +399,13 @@ HTTP headers have already been sent.
Caused by output from file %s at 25127 => array('The library has been configured for automatic encoding conversion of Japanese fonts. This requires that PHP has the mb_convert_encoding() function. Your PHP installation lacks this function (PHP needs the "--enable-mbstring" when compiled).',0), 25128 => array('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.',0), 25129 => array('Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines.',0), +25130 => array('Too small plot area. (%d x %d). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins.',2), +/* +** jpgraph_led +*/ + +25500 => array('Multibyte strings must be enabled in the PHP installation in order to run the LED module so that the function mb_strlen() is available. See PHP documentation for more information.',0), /* **--------------------------------------------------------------------------------------------- @@ -407,7 +414,7 @@ HTTP headers have already been sent.
Caused by output from file %s at */ /* -** jpgraph_table +** jpgraph_table */ 27001 => array('GTextTable: Invalid argument to Set(). Array argument must be 2 dimensional',0), @@ -476,7 +483,7 @@ HTTP headers have already been sent.
Caused by output from file %s at /* ** PDF417 */ - +26000 => array('PDF417: The PDF417 module requires that the PHP installation must support the function bcmod(). This is normally enabled at compile time. See documentation for more information.',0), 26001 => array('PDF417: Number of Columns must be >= 1 and <= 30',0), 26002 => array('PDF417: Error level must be between 0 and 8',0), 26003 => array('PDF417: Invalid format for input data to encode with PDF417',0), @@ -494,6 +501,29 @@ HTTP headers have already been sent.
Caused by output from file %s at 26015 => array('PDF417: Internal error. State transition table entry 0 is NULL. Entry 1 = (%s)',1), 26016 => array('PDF417: Internal error: Unrecognized state transition mode in decode.',0), +/* +** jpgraph_contour +*/ + +28001 => array('Third argument to Contour must be an array of colors.',0), +28002 => array('Number of colors must equal the number of isobar lines specified',0), +28003 => array('ContourPlot Internal Error: isobarHCrossing: Coloumn index too large (%d)',1), +28004 => array('ContourPlot Internal Error: isobarHCrossing: Row index too large (%d)',1), +28005 => array('ContourPlot Internal Error: isobarVCrossing: Row index too large (%d)',1), +28006 => array('ContourPlot Internal Error: isobarVCrossing: Col index too large (%d)',1), +28007 => array('ContourPlot interpolation factor is too large (>5)',0), + +/* + * jpgraph_matrix and colormap +*/ +29201 => array('Min range value must be less or equal to max range value for colormaps'), +29202 => array('The distance between min and max value is too small for numerical precision'), +29203 => array('Number of color quantification level must be at least %d',1), +29204 => array('Number of colors (%d) is invalid for this colormap. It must be a number that can be written as: %d + k*%d',3), +29205 => array('Colormap specification out of range. Must be an integer in range [0,%d]',1), +29206 => array('Invalid object added to MatrixGraph'), +29207 => array('Empty input data specified for MatrixPlot'), + ); diff --git a/src/classes/jpgraph/lang/prod.inc.php b/src/classes/jpgraph/lang/prod.inc.php index f04e30d..03cf285 100644 --- a/src/classes/jpgraph/lang/prod.inc.php +++ b/src/classes/jpgraph/lang/prod.inc.php @@ -1,10 +1,10 @@ array('
JpGraph Error: +10 => array('
JpGraph Error: HTTP headers have already been sent.
Caused by output from file %s at line %d.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it\'s image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).

Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

For example it is a common mistake to leave a blank line before the opening "<?php".

',2), @@ -275,6 +275,8 @@ HTTP headers have already been sent.
Caused by output from file %s at 25127 => array(DEFAULT_ERROR_MESSAGE.'25127',0), 25128 => array(DEFAULT_ERROR_MESSAGE.'25128',0), 25129 => array(DEFAULT_ERROR_MESSAGE.'25129',0), +25130 => array(DEFAULT_ERROR_MESSAGE.'25130',0), +25500 => array(DEFAULT_ERROR_MESSAGE.'25500',0), 24003 => array(DEFAULT_ERROR_MESSAGE.'24003',0), 24004 => array(DEFAULT_ERROR_MESSAGE.'24004',0), 24005 => array(DEFAULT_ERROR_MESSAGE.'24005',0), @@ -320,6 +322,7 @@ HTTP headers have already been sent.
Caused by output from file %s at 1009 => array(DEFAULT_ERROR_MESSAGE.'1009',0), 1010 => array(DEFAULT_ERROR_MESSAGE.'1010',0), 1011 => array(DEFAULT_ERROR_MESSAGE.'1011',0), +26000 => array(DEFAULT_ERROR_MESSAGE.'26000',0), 26001 => array(DEFAULT_ERROR_MESSAGE.'26001',0), 26002 => array(DEFAULT_ERROR_MESSAGE.'26002',0), 26003 => array(DEFAULT_ERROR_MESSAGE.'26003',0), @@ -352,6 +355,23 @@ HTTP headers have already been sent.
Caused by output from file %s at 27013 => array(DEFAULT_ERROR_MESSAGE.'27013',0), 27014 => array(DEFAULT_ERROR_MESSAGE.'27014',0), 27015 => array(DEFAULT_ERROR_MESSAGE.'27015',0), + +28001 => array(DEFAULT_ERROR_MESSAGE.'28001',0), +28002 => array(DEFAULT_ERROR_MESSAGE.'28002',0), +28003 => array(DEFAULT_ERROR_MESSAGE.'28003',0), +28004 => array(DEFAULT_ERROR_MESSAGE.'28004',0), +28005 => array(DEFAULT_ERROR_MESSAGE.'28005',0), +28006 => array(DEFAULT_ERROR_MESSAGE.'28006',0), +28007 => array(DEFAULT_ERROR_MESSAGE.'28007',0), + +29201 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29202 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29203 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29204 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29205 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29206 => array(DEFAULT_ERROR_MESSAGE.'28007',0), +29207 => array(DEFAULT_ERROR_MESSAGE.'28007',0), + ); ?>