add amendments metric
[contractdashboard.git] / lib / jpgraph / jpgraph_plotmark.inc.php
blob:a/lib/jpgraph/jpgraph_plotmark.inc.php -> blob:b/lib/jpgraph/jpgraph_plotmark.inc.php
<?php <?php
//======================================================================= //=======================================================================
// File: JPGRAPH_PLOTMARK.PHP // File: JPGRAPH_PLOTMARK.PHP
// Description: Class file. Handles plotmarks // Description: Class file. Handles plotmarks
// Created: 2003-03-21 // Created: 2003-03-21
// Ver: $Id: jpgraph_plotmark.inc.php 1106 2009-02-22 20:16:35Z ljp $ // Ver: $Id: jpgraph_plotmark.inc.php 1106 2009-02-22 20:16:35Z ljp $
// //
// Copyright (c) Aditus Consulting. All rights reserved. // Copyright (c) Aditus Consulting. All rights reserved.
//======================================================================== //========================================================================
   
   
//=================================================== //===================================================
// CLASS PlotMark // CLASS PlotMark
// Description: Handles the plot marks in graphs // Description: Handles the plot marks in graphs
//=================================================== //===================================================
   
class PlotMark { class PlotMark {
public $title, $show=true; public $title, $show=true;
public $type,$weight=1; public $type,$weight=1;
public $iFormatCallback="", $iFormatCallback2=""; public $iFormatCallback="", $iFormatCallback2="";
public $fill_color="blue"; public $fill_color="blue";
public $color="black", $width=4; public $color="black", $width=4;
private $yvalue,$xvalue='',$csimtarget,$csimwintarget='',$csimalt,$csimareas; private $yvalue,$xvalue='',$csimtarget,$csimwintarget='',$csimalt,$csimareas;
private $markimg='',$iScale=1.0; private $markimg='',$iScale=1.0;
private $oldfilename='',$iFileName=''; private $oldfilename='',$iFileName='';
private $imgdata_balls = null; private $imgdata_balls = null;
private $imgdata_diamonds = null; private $imgdata_diamonds = null;
private $imgdata_squares = null; private $imgdata_squares = null;
private $imgdata_bevels = null; private $imgdata_bevels = null;
private $imgdata_stars = null; private $imgdata_stars = null;
private $imgdata_pushpins = null; private $imgdata_pushpins = null;
   
//-------------- //--------------
// CONSTRUCTOR // CONSTRUCTOR
function __construct() { function __construct() {
$this->title = new Text(); $this->title = new Text();
$this->title->Hide(); $this->title->Hide();
$this->csimareas = ''; $this->csimareas = '';
$this->type=-1; $this->type=-1;
} }
//--------------- //---------------
// PUBLIC METHODS // PUBLIC METHODS
function SetType($aType,$aFileName='',$aScale=1.0) { function SetType($aType,$aFileName='',$aScale=1.0) {
$this->type = $aType; $this->type = $aType;
if( $aType == MARK_IMG && $aFileName=='' ) { if( $aType == MARK_IMG && $aFileName=='' ) {
JpGraphError::RaiseL(23003);//('A filename must be specified if you set the mark type to MARK_IMG.'); JpGraphError::RaiseL(23003);//('A filename must be specified if you set the mark type to MARK_IMG.');
} }
$this->iFileName = $aFileName; $this->iFileName = $aFileName;
$this->iScale = $aScale; $this->iScale = $aScale;
} }
   
function SetCallback($aFunc) { function SetCallback($aFunc) {
$this->iFormatCallback = $aFunc; $this->iFormatCallback = $aFunc;
} }
   
function SetCallbackYX($aFunc) { function SetCallbackYX($aFunc) {
$this->iFormatCallback2 = $aFunc; $this->iFormatCallback2 = $aFunc;
} }
   
function GetType() { function GetType() {
return $this->type; return $this->type;
} }
   
function SetColor($aColor) { function SetColor($aColor) {
$this->color=$aColor; $this->color=$aColor;
} }
   
function SetFillColor($aFillColor) { function SetFillColor($aFillColor) {
$this->fill_color = $aFillColor; $this->fill_color = $aFillColor;
} }
   
function SetWeight($aWeight) { function SetWeight($aWeight) {
$this->weight = $aWeight; $this->weight = $aWeight;
} }
   
// Synonym for SetWidth() // Synonym for SetWidth()
function SetSize($aWidth) { function SetSize($aWidth) {
$this->width=$aWidth; $this->width=$aWidth;
} }
   
function SetWidth($aWidth) { function SetWidth($aWidth) {
$this->width=$aWidth; $this->width=$aWidth;
} }
   
function SetDefaultWidth() { function SetDefaultWidth() {
switch( $this->type ) { switch( $this->type ) {
case MARK_CIRCLE: case MARK_CIRCLE:
case MARK_FILLEDCIRCLE: case MARK_FILLEDCIRCLE:
$this->width=4; $this->width=4;
break; break;
default: default:
$this->width=7; $this->width=7;
} }
} }
   
function GetWidth() { function GetWidth() {
return $this->width; return $this->width;
} }
   
function Hide($aHide=true) { function Hide($aHide=true) {
$this->show = !$aHide; $this->show = !$aHide;
} }
   
function Show($aShow=true) { function Show($aShow=true) {
$this->show = $aShow; $this->show = $aShow;
} }
   
function SetCSIMAltVal($aY,$aX='') { function SetCSIMAltVal($aY,$aX='') {
$this->yvalue=$aY; $this->yvalue=$aY;
$this->xvalue=$aX; $this->xvalue=$aX;
} }
   
function SetCSIMTarget($aTarget,$aWinTarget='') { function SetCSIMTarget($aTarget,$aWinTarget='') {
$this->csimtarget=$aTarget; $this->csimtarget=$aTarget;
$this->csimwintarget=$aWinTarget; $this->csimwintarget=$aWinTarget;
} }
   
function SetCSIMAlt($aAlt) { function SetCSIMAlt($aAlt) {
$this->csimalt=$aAlt; $this->csimalt=$aAlt;
} }
   
function GetCSIMAreas(){ function GetCSIMAreas(){
return $this->csimareas; return $this->csimareas;
} }
   
function AddCSIMPoly($aPts) { function AddCSIMPoly($aPts) {
$coords = round($aPts[0]).", ".round($aPts[1]); $coords = round($aPts[0]).", ".round($aPts[1]);
$n = count($aPts)/2; $n = count($aPts)/2;
for( $i=1; $i < $n; ++$i){ for( $i=1; $i < $n; ++$i){
$coords .= ", ".round($aPts[2*$i]).", ".round($aPts[2*$i+1]); $coords .= ", ".round($aPts[2*$i]).", ".round($aPts[2*$i+1]);
} }
$this->csimareas=""; $this->csimareas="";
if( !empty($this->csimtarget) ) { if( !empty($this->csimtarget) ) {
$this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".htmlentities($this->csimtarget)."\""; $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".htmlentities($this->csimtarget)."\"";
   
if( !empty($this->csimwintarget) ) { if( !empty($this->csimwintarget) ) {
$this->csimareas .= " target=\"".$this->csimwintarget."\" "; $this->csimareas .= " target=\"".$this->csimwintarget."\" ";
} }
   
if( !empty($this->csimalt) ) { if( !empty($this->csimalt) ) {
$tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue);
$this->csimareas .= " title=\"$tmp\" alt=\"$tmp\""; $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\"";
} }
$this->csimareas .= " />\n"; $this->csimareas .= " />\n";
} }
} }
   
function AddCSIMCircle($x,$y,$r) { function AddCSIMCircle($x,$y,$r) {
$x = round($x); $y=round($y); $r=round($r); $x = round($x); $y=round($y); $r=round($r);
$this->csimareas=""; $this->csimareas="";
if( !empty($this->csimtarget) ) { if( !empty($this->csimtarget) ) {
$this->csimareas .= "<area shape=\"circle\" coords=\"$x,$y,$r\" href=\"".htmlentities($this->csimtarget)."\""; $this->csimareas .= "<area shape=\"circle\" coords=\"$x,$y,$r\" href=\"".htmlentities($this->csimtarget)."\"";
   
if( !empty($this->csimwintarget) ) { if( !empty($this->csimwintarget) ) {
$this->csimareas .= " target=\"".$this->csimwintarget."\" "; $this->csimareas .= " target=\"".$this->csimwintarget."\" ";
} }
   
if( !empty($this->csimalt) ) { if( !empty($this->csimalt) ) {
$tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue);
$this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" ";
} }
$this->csimareas .= " />\n"; $this->csimareas .= " />\n";
} }
} }
function Stroke($img,$x,$y) { 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 != '' ) { if( $this->iFormatCallback != '' ) {
$f = $this->iFormatCallback; $f = $this->iFormatCallback;
list($width,$color,$fcolor) = call_user_func($f,$this->yvalue); list($width,$color,$fcolor) = call_user_func($f,$this->yvalue);
$filename = $this->iFileName; $filename = $this->iFileName;
$imgscale = $this->iScale; $imgscale = $this->iScale;
} }
else { else {
$f = $this->iFormatCallback2; $f = $this->iFormatCallback2;
list($width,$color,$fcolor,$filename,$imgscale) = call_user_func($f,$this->yvalue,$this->xvalue); list($width,$color,$fcolor,$filename,$imgscale) = call_user_func($f,$this->yvalue,$this->xvalue);
if( $filename=="" ) $filename = $this->iFileName; if( $filename=="" ) $filename = $this->iFileName;
if( $imgscale=="" ) $imgscale = $this->iScale; if( $imgscale=="" ) $imgscale = $this->iScale;
} }
   
if( $width=="" ) $width = $this->width; if( $width=="" ) $width = $this->width;
if( $color=="" ) $color = $this->color; if( $color=="" ) $color = $this->color;
if( $fcolor=="" ) $fcolor = $this->fill_color; if( $fcolor=="" ) $fcolor = $this->fill_color;
   
} }
else { else {
$fcolor = $this->fill_color; $fcolor = $this->fill_color;
$color = $this->color; $color = $this->color;
$width = $this->width; $width = $this->width;
$filename = $this->iFileName; $filename = $this->iFileName;
$imgscale = $this->iScale; $imgscale = $this->iScale;
} }
   
if( $this->type == MARK_IMG || if( $this->type == MARK_IMG ||
($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4 ) || ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4 ) ||
$this->type >= MARK_IMG_PUSHPIN ) { $this->type >= MARK_IMG_PUSHPIN ) {
   
// Note: For the builtin images we use the "filename" parameter // Note: For the builtin images we use the "filename" parameter
// to denote the color // to denote the color
$anchor_x = 0.5; $anchor_x = 0.5;
$anchor_y = 0.5; $anchor_y = 0.5;
switch( $this->type ) { switch( $this->type ) {
case MARK_FLAG1: case MARK_FLAG1:
case MARK_FLAG2: case MARK_FLAG2:
case MARK_FLAG3: case MARK_FLAG3:
case MARK_FLAG4: case MARK_FLAG4:
$this->markimg = FlagCache::GetFlagImgByName($this->type-MARK_FLAG1+1,$filename); $this->markimg = FlagCache::GetFlagImgByName($this->type-MARK_FLAG1+1,$filename);
break; break;
   
case MARK_IMG : case MARK_IMG :
// Load an image and use that as a marker // Load an image and use that as a marker
// Small optimization, if we have already read an image don't // Small optimization, if we have already read an image don't
// waste time reading it again. // waste time reading it again.
if( $this->markimg == '' || !($this->oldfilename === $filename) ) { if( $this->markimg == '' || !($this->oldfilename === $filename) ) {
$this->markimg = Graph::LoadBkgImage('',$filename); $this->markimg = Graph::LoadBkgImage('',$filename);
$this->oldfilename = $filename ; $this->oldfilename = $filename ;
} }
break; break;
   
case MARK_IMG_PUSHPIN: case MARK_IMG_PUSHPIN:
case MARK_IMG_SPUSHPIN: case MARK_IMG_SPUSHPIN:
case MARK_IMG_LPUSHPIN: case MARK_IMG_LPUSHPIN:
if( $this->imgdata_pushpins == null ) { if( $this->imgdata_pushpins == null ) {
require_once 'imgdata_pushpins.inc.php'; require_once 'imgdata_pushpins.inc.php';
$this->imgdata_pushpins = new ImgData_PushPins(); $this->imgdata_pushpins = new ImgData_PushPins();
} }
$this->markimg = $this->imgdata_pushpins->GetImg($this->type,$filename); $this->markimg = $this->imgdata_pushpins->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_pushpins->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_pushpins->GetAnchor();
break; break;
   
case MARK_IMG_SQUARE: case MARK_IMG_SQUARE:
if( $this->imgdata_squares == null ) { if( $this->imgdata_squares == null ) {
require_once 'imgdata_squares.inc.php'; require_once 'imgdata_squares.inc.php';
$this->imgdata_squares = new ImgData_Squares(); $this->imgdata_squares = new ImgData_Squares();
} }
$this->markimg = $this->imgdata_squares->GetImg($this->type,$filename); $this->markimg = $this->imgdata_squares->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_squares->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_squares->GetAnchor();
break; break;
   
case MARK_IMG_STAR: case MARK_IMG_STAR:
if( $this->imgdata_stars == null ) { if( $this->imgdata_stars == null ) {
require_once 'imgdata_stars.inc.php'; require_once 'imgdata_stars.inc.php';
$this->imgdata_stars = new ImgData_Stars(); $this->imgdata_stars = new ImgData_Stars();
} }
$this->markimg = $this->imgdata_stars->GetImg($this->type,$filename); $this->markimg = $this->imgdata_stars->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_stars->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_stars->GetAnchor();
break; break;
   
case MARK_IMG_BEVEL: case MARK_IMG_BEVEL:
if( $this->imgdata_bevels == null ) { if( $this->imgdata_bevels == null ) {
require_once 'imgdata_bevels.inc.php'; require_once 'imgdata_bevels.inc.php';
$this->imgdata_bevels = new ImgData_Bevels(); $this->imgdata_bevels = new ImgData_Bevels();
} }
$this->markimg = $this->imgdata_bevels->GetImg($this->type,$filename); $this->markimg = $this->imgdata_bevels->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_bevels->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_bevels->GetAnchor();
break; break;
   
case MARK_IMG_DIAMOND: case MARK_IMG_DIAMOND:
if( $this->imgdata_diamonds == null ) { if( $this->imgdata_diamonds == null ) {
require_once 'imgdata_diamonds.inc.php'; require_once 'imgdata_diamonds.inc.php';
$this->imgdata_diamonds = new ImgData_Diamonds(); $this->imgdata_diamonds = new ImgData_Diamonds();
} }
$this->markimg = $this->imgdata_diamonds->GetImg($this->type,$filename); $this->markimg = $this->imgdata_diamonds->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_diamonds->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_diamonds->GetAnchor();
break; break;
   
case MARK_IMG_BALL: case MARK_IMG_BALL:
case MARK_IMG_SBALL: case MARK_IMG_SBALL:
case MARK_IMG_MBALL: case MARK_IMG_MBALL:
case MARK_IMG_LBALL: case MARK_IMG_LBALL:
if( $this->imgdata_balls == null ) { if( $this->imgdata_balls == null ) {
require_once 'imgdata_balls.inc.php'; require_once 'imgdata_balls.inc.php';
$this->imgdata_balls = new ImgData_Balls(); $this->imgdata_balls = new ImgData_Balls();
} }
$this->markimg = $this->imgdata_balls->GetImg($this->type,$filename); $this->markimg = $this->imgdata_balls->GetImg($this->type,$filename);
list($anchor_x,$anchor_y) = $this->imgdata_balls->GetAnchor(); list($anchor_x,$anchor_y) = $this->imgdata_balls->GetAnchor();
break; break;
} }
   
$w = $img->GetWidth($this->markimg); $w = $img->GetWidth($this->markimg);
$h = $img->GetHeight($this->markimg); $h = $img->GetHeight($this->markimg);
$dw = round($imgscale * $w ); $dw = round($imgscale * $w );
$dh = round($imgscale * $h ); $dh = round($imgscale * $h );
   
// Do potential rotation // Do potential rotation
list($x,$y) = $img->Rotate($x,$y); list($x,$y) = $img->Rotate($x,$y);
   
$dx = round($x-$dw*$anchor_x); $dx = round($x-$dw*$anchor_x);
$dy = round($y-$dh*$anchor_y); $dy = round($y-$dh*$anchor_y);
$this->width = max($dx,$dy); $this->width = max($dx,$dy);
$img->Copy($this->markimg,$dx,$dy,0,0,$dw,$dh,$w,$h); $img->Copy($this->markimg,$dx,$dy,0,0,$dw,$dh,$w,$h);
if( !empty($this->csimtarget) ) { if( !empty($this->csimtarget) ) {
$this->csimareas = "<area shape=\"rect\" coords=\"". $this->csimareas = "<area shape=\"rect\" coords=\"".
$dx.','.$dy.','.round($dx+$dw).','.round($dy+$dh).'" '. $dx.','.$dy.','.round($dx+$dw).','.round($dy+$dh).'" '.
"href=\"".htmlentities($this->csimtarget)."\""; "href=\"".htmlentities($this->csimtarget)."\"";
   
if( !empty($this->csimwintarget) ) { if( !empty($this->csimwintarget) ) {
$this->csimareas .= " target=\"".$this->csimwintarget."\" "; $this->csimareas .= " target=\"".$this->csimwintarget."\" ";
} }
   
if( !empty($this->csimalt) ) { if( !empty($this->csimalt) ) {
$tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue);
$this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" ";
} }
$this->csimareas .= " />\n"; $this->csimareas .= " />\n";
} }
// Stroke title // Stroke title
$this->title->Align("center","top"); $this->title->Align("center","top");
$this->title->Stroke($img,$x,$y+round($dh/2)); $this->title->Stroke($img,$x,$y+round($dh/2));
return; return;
} }
   
$weight = $this->weight; $weight = $this->weight;
$dx=round($width/2,0); $dx=round($width/2,0);
$dy=round($width/2,0); $dy=round($width/2,0);
$pts=0; $pts=0;
   
switch( $this->type ) { switch( $this->type ) {
case MARK_SQUARE: 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; $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; $pts=5;
break; break;
case MARK_UTRIANGLE: case MARK_UTRIANGLE:
++$dx;++$dy; ++$dx;++$dy;
$c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx
$c[]=$x;$c[]=$y-0.87*$dy; $c[]=$x;$c[]=$y-0.87*$dy;
$c[]=$x+$dx;$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 $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx
$pts=4; $pts=4;
break; break;