public function __construct($aIcon, $aScale = 1) { global $_gPredefIcons; if (is_string($aIcon)) { $this->iGDImage = Graph::LoadBkgImage('', $aIcon); } elseif (is_integer($aIcon)) { // Builtin image $this->iGDImage = $_gPredefIcons->GetImg($aIcon); } else { Util\JpGraphError::RaiseL(6011); //('Argument to IconImage must be string or integer'); } $this->iScale = $aScale; $this->iWidth = Image::GetWidth($this->iGDImage); $this->iHeight = Image::GetHeight($this->iGDImage); }
function Stroke($aImg) { if ($this->iFile != '' && $this->iCountryFlag != '') { JpGraphError::Raise('It is not possible to specify both an image file and a country flag for the same icon.'); } if ($this->iFile != '') { $gdimg = Graph::LoadBkgImage('', $this->iFile); } else { if (!class_exists('FlagImages')) { JpGraphError::Raise('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.'); } $fobj = new FlagImages($this->iCountryStdSize); $dummy = ''; $gdimg = $fobj->GetImgByName($this->iCountryFlag, $dummy); } if ($this->iX >= 0 && $this->iX <= 1.0) { $w = imagesx($aImg->img); $this->iX = round($w * $this->iX); } if ($this->iY >= 0 && $this->iY <= 1.0) { $h = imagesy($aImg->img); $this->iY = round($h * $this->iY); } $iconw = imagesx($gdimg); $iconh = imagesy($gdimg); if ($this->iHorAnchor == 'center') { $this->iX -= round($iconw * $this->iScale / 2); } if ($this->iHorAnchor == 'right') { $this->iX -= round($iconw * $this->iScale); } if ($this->iVertAnchor == 'center') { $this->iY -= round($iconh * $this->iScale / 2); } if ($this->iVertAnchor == 'bottom') { $this->iY -= round($iconh * $this->iScale); } $aImg->CopyMerge($gdimg, $this->iX, $this->iY, 0, 0, round($iconw * $this->iScale), round($iconh * $this->iScale), $iconw, $iconh, $this->iMix); }
function _strokeBackgroundImage() { if ($this->background_image == '') { return; } $bkgimg = Graph::LoadBkgImage('', $this->background_image); // Background width & Heoght $bw = imagesx($bkgimg); $bh = imagesy($bkgimg); // Canvas width and height $cw = imagesx($this->img); $ch = imagesy($this->img); if ($this->doshadow) { $cw -= $this->shadow_width; $ch -= $this->shadow_width; } if ($this->background_image_x === NULL || $this->background_image_y === NULL) { if ($this->background_image_center) { // Center original image in the plot area $x = round($cw / 2 - $bw / 2); $y = round($ch / 2 - $bh / 2); } else { // Just copy the image from left corner, no resizing $x = 0; $y = 0; } } else { $x = $this->background_image_x; $y = $this->background_image_y; } imagecopymerge($this->img, $bkgimg, $x, $y, 0, 0, $bw, $bh, $this->background_image_mix); }
function Stroke($img, $x, $y) { if (!$this->show) { return; } 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 ($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; } 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; 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_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_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_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); // 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 = "<area shape=\"rect\" coords=\"" . $dx . ',' . $dy . ',' . round($dx + $dw) . ',' . round($dy + $dh) . '" ' . "href=\"" . htmlentities($this->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"; } // Stroke title $this->title->Align("center", "top"); $this->title->Stroke($img, $x, $y + round($dh / 2)); return; } $weight = $this->weight; $dx = round($width / 2, 0); $dy = round($width / 2, 0); $pts = 0; 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); }
function _Stroke($aImg, $x = null, $y = null, $aReturnWidthHeight = false) { if ($this->iFile != '' && $this->iCountryFlag != '') { JpGraphError::RaiseL(8003); //('It is not possible to specify both an image file and a country flag for the same icon.'); } if ($this->iFile != '') { $gdimg = Graph::LoadBkgImage('', $this->iFile); } elseif ($this->iImgString != '') { $gdimg = Image::CreateFromString($this->iImgString); } else { if (!class_exists('FlagImages', false)) { JpGraphError::RaiseL(8004); //('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.'); } $fobj = new FlagImages($this->iCountryStdSize); $dummy = ''; $gdimg = $fobj->GetImgByName($this->iCountryFlag, $dummy); } $iconw = imagesx($gdimg); $iconh = imagesy($gdimg); if ($aReturnWidthHeight) { return array(round($iconw * $this->iScale), round($iconh * $this->iScale)); } if ($x !== null && $y !== null) { $this->iX = $x; $this->iY = $y; } if ($this->iX >= 0 && $this->iX <= 1.0) { $w = imagesx($aImg->img); $this->iX = round($w * $this->iX); } if ($this->iY >= 0 && $this->iY <= 1.0) { $h = imagesy($aImg->img); $this->iY = round($h * $this->iY); } if ($this->iHorAnchor == 'center') { $this->iX -= round($iconw * $this->iScale / 2); } if ($this->iHorAnchor == 'right') { $this->iX -= round($iconw * $this->iScale); } if ($this->iVertAnchor == 'center') { $this->iY -= round($iconh * $this->iScale / 2); } if ($this->iVertAnchor == 'bottom') { $this->iY -= round($iconh * $this->iScale); } $aImg->CopyMerge($gdimg, $this->iX, $this->iY, 0, 0, round($iconw * $this->iScale), round($iconh * $this->iScale), $iconw, $iconh, $this->iMix); }
function IconImage($aIcon, $aScale = 1) { global $_gPredefIcons; if (is_string($aIcon)) { $this->iGDImage = Graph::LoadBkgImage('', $aIcon); } elseif (is_integer($aIcon)) { $this->iGDImage = $_gPredefIcons->GetImg($aIcon); } else { JpGraphError::RaiseL(6011); } $this->iScale = $aScale; $this->iWidth = Image::GetWidth($this->iGDImage); $this->iHeight = Image::GetHeight($this->iGDImage); }
function _Stroke(&$aImg, $x = null, $y = null, $aReturnWidthHeight = false) { if ($this->iFile != '' && $this->iCountryFlag != '') { JpGraphError::RaiseL(8003); } if ($this->iFile != '') { $gdimg = Graph::LoadBkgImage('', $this->iFile); } elseif ($this->iImgString != '') { $gdimg = Image::CreateFromString($this->iImgString); } else { if (!class_exists('FlagImages')) { JpGraphError::RaiseL(8004); } $fobj = new FlagImages($this->iCountryStdSize); $dummy = ''; $gdimg = $fobj->GetImgByName($this->iCountryFlag, $dummy); } $iconw = imagesx($gdimg); $iconh = imagesy($gdimg); if ($aReturnWidthHeight) { return array(round($iconw * $this->iScale), round($iconh * $this->iScale)); } if ($x !== null && $y !== null) { $this->iX = $x; $this->iY = $y; } if ($this->iX >= 0 && $this->iX <= 1.0) { $w = imagesx($aImg->img); $this->iX = round($w * $this->iX); } if ($this->iY >= 0 && $this->iY <= 1.0) { $h = imagesy($aImg->img); $this->iY = round($h * $this->iY); } if ($this->iHorAnchor == 'center') { $this->iX -= round($iconw * $this->iScale / 2); } if ($this->iHorAnchor == 'right') { $this->iX -= round($iconw * $this->iScale); } if ($this->iVertAnchor == 'center') { $this->iY -= round($iconh * $this->iScale / 2); } if ($this->iVertAnchor == 'bottom') { $this->iY -= round($iconh * $this->iScale); } $aImg->CopyMerge($gdimg, $this->iX, $this->iY, 0, 0, round($iconw * $this->iScale), round($iconh * $this->iScale), $iconw, $iconh, $this->iMix); }
function IconImage($aIcon,$aScale=1) { GLOBAL $_gPredefIcons ; if( is_string($aIcon) ) { $this->iGDImage = Graph::LoadBkgImage('',$aIcon); } elseif( is_integer($aIcon) ) { // Builtin image $this->iGDImage = $_gPredefIcons->GetImg($aIcon); } else { JpGraphError::Raise('Argument to IconImage must be string or integer'); } $this->iScale = $aScale; $this->iWidth = Image::GetWidth($this->iGDImage); $this->iHeight = Image::GetHeight($this->iGDImage); }