- Timestamp:
- Apr 13, 2019, 8:05:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/modules/Elezioni/grafici/jpgraph_plotmark.inc.php
r2 r265 1 1 <?php 2 2 //======================================================================= 3 // File: 4 // Description: 5 // Created: 6 // Ver: $Id: jpgraph_plotmark.inc.php 956 2007-11-17 13:19:20Z ljp $3 // File: JPGRAPH_PLOTMARK.PHP 4 // Description: Class file. Handles plotmarks 5 // Created: 2003-03-21 6 // Ver: $Id: jpgraph_plotmark.inc.php 1106 2009-02-22 20:16:35Z ljp $ 7 7 // 8 // Copyright (c) A ditus Consulting. All rights reserved.8 // Copyright (c) Asial Corporation. All rights reserved. 9 9 //======================================================================== 10 10 … … 31 31 private $imgdata_pushpins = null; 32 32 33 //--------------34 // CONSTRUCTOR35 function PlotMark() {36 37 38 39 40 } 41 //---------------42 // PUBLIC METHODS 33 //-------------- 34 // CONSTRUCTOR 35 function __construct() { 36 $this->title = new Text(); 37 $this->title->Hide(); 38 $this->csimareas = ''; 39 $this->type=-1; 40 } 41 //--------------- 42 // PUBLIC METHODS 43 43 function SetType($aType,$aFileName='',$aScale=1.0) { 44 45 46 47 48 49 50 } 51 44 $this->type = $aType; 45 if( $aType == MARK_IMG && $aFileName=='' ) { 46 JpGraphError::RaiseL(23003);//('A filename must be specified if you set the mark type to MARK_IMG.'); 47 } 48 $this->iFileName = $aFileName; 49 $this->iScale = $aScale; 50 } 51 52 52 function SetCallback($aFunc) { 53 53 $this->iFormatCallback = $aFunc; 54 54 } 55 55 56 56 function SetCallbackYX($aFunc) { 57 58 } 59 57 $this->iFormatCallback2 = $aFunc; 58 } 59 60 60 function GetType() { 61 62 } 63 61 return $this->type; 62 } 63 64 64 function SetColor($aColor) { 65 66 } 67 65 $this->color=$aColor; 66 } 67 68 68 function SetFillColor($aFillColor) { 69 69 $this->fill_color = $aFillColor; 70 70 } 71 71 72 72 function SetWeight($aWeight) { 73 73 $this->weight = $aWeight; 74 74 } 75 75 76 76 // Synonym for SetWidth() 77 77 function SetSize($aWidth) { 78 79 } 80 78 $this->width=$aWidth; 79 } 80 81 81 function SetWidth($aWidth) { 82 82 $this->width=$aWidth; 83 83 } 84 84 85 85 function SetDefaultWidth() { 86 87 case MARK_CIRCLE: 88 case MARK_FILLEDCIRCLE: 89 90 91 92 93 94 } 95 86 switch( $this->type ) { 87 case MARK_CIRCLE: 88 case MARK_FILLEDCIRCLE: 89 $this->width=4; 90 break; 91 default: 92 $this->width=7; 93 } 94 } 95 96 96 function GetWidth() { 97 98 } 99 97 return $this->width; 98 } 99 100 100 function Hide($aHide=true) { 101 102 } 103 101 $this->show = !$aHide; 102 } 103 104 104 function Show($aShow=true) { 105 105 $this->show = $aShow; 106 106 } 107 107 108 108 function SetCSIMAltVal($aY,$aX='') { 109 $this->yvalue=$aY; 110 $this->xvalue=$aX; 111 } 112 109 $this->yvalue=$aY; 110 $this->xvalue=$aX; 111 } 112 113 113 function SetCSIMTarget($aTarget,$aWinTarget='') { 114 114 $this->csimtarget=$aTarget; 115 115 $this->csimwintarget=$aWinTarget; 116 116 } 117 117 118 118 function SetCSIMAlt($aAlt) { 119 119 $this->csimalt=$aAlt; 120 120 } 121 121 122 122 function GetCSIMAreas(){ 123 123 return $this->csimareas; 124 124 } 125 125 126 126 function AddCSIMPoly($aPts) { 127 127 $coords = round($aPts[0]).", ".round($aPts[1]); … … 130 130 $coords .= ", ".round($aPts[2*$i]).", ".round($aPts[2*$i+1]); 131 131 } 132 $this->csimareas=""; 132 $this->csimareas=""; 133 133 if( !empty($this->csimtarget) ) { 134 135 136 137 138 139 140 if( !empty($this->csimalt) ) { 141 142 143 144 145 146 } 147 134 $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".htmlentities($this->csimtarget)."\""; 135 136 if( !empty($this->csimwintarget) ) { 137 $this->csimareas .= " target=\"".$this->csimwintarget."\" "; 138 } 139 140 if( !empty($this->csimalt) ) { 141 $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); 142 $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\""; 143 } 144 $this->csimareas .= " />\n"; 145 } 146 } 147 148 148 function AddCSIMCircle($x,$y,$r) { 149 150 $this->csimareas=""; 149 $x = round($x); $y=round($y); $r=round($r); 150 $this->csimareas=""; 151 151 if( !empty($this->csimtarget) ) { 152 153 154 155 156 157 158 if( !empty($this->csimalt) ) {159 160 161 162 163 } 164 } 165 152 $this->csimareas .= "<area shape=\"circle\" coords=\"$x,$y,$r\" href=\"".htmlentities($this->csimtarget)."\""; 153 154 if( !empty($this->csimwintarget) ) { 155 $this->csimareas .= " target=\"".$this->csimwintarget."\" "; 156 } 157 158 if( !empty($this->csimalt) ) { 159 $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); 160 $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; 161 } 162 $this->csimareas .= " />\n"; 163 } 164 } 165 166 166 function Stroke($img,$x,$y) { 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 $anchor_y = 0.5; 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 case MARK_IMG_BALL: 271 case MARK_IMG_SBALL: 272 case MARK_IMG_MBALL: 273 case MARK_IMG_LBALL: 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 $this->title->Stroke($img,$x,$y+round($dh/2)); 317 318 319 320 321 322 323 $pts=0; 324 325 326 327 328 329 330 331 332 333 334 335 336 $c[]=$x-$dx;$c[]=$y+0.87*$dy;// tan(60)/2*$dx337 338 339 $c[]=$x-$dx;$c[]=$y+0.87*$dy;// tan(60)/2*$dx340 341 342 343 ++$dx;++$dy; 344 $c[]=$x;$c[]=$y+0.87*$dy;// tan(60)/2*$dx345 346 347 $c[]=$x;$c[]=$y+0.87*$dy;// tan(60)/2*$dx348 349 break; 350 351 352 353 354 355 356 357 break; 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 $img->SetColor($color); 380 381 382 383 384 385 386 387 388 389 $img->SetColor($fcolor); 390 391 $img->SetColor($color); 392 393 394 395 396 $img->SetColor($color); 397 398 399 400 401 $img->SetColor($fcolor); 402 403 $img->SetColor($color); 404 405 406 407 408 409 410 411 412 413 $this->AddCSIMCircle($x,$y,$dx); 414 415 416 417 418 419 $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); 420 $this->AddCSIMCircle($x,$y,$dx+$dy); 421 } 422 423 424 425 426 427 // Oversize by a pixel to match the X 428 429 430 $this->AddCSIMCircle($x,$y,$dx+$dy); 431 432 433 434 435 $this->title->Stroke($img,$x,$y); 167 if( !$this->show ) return; 168 169 if( $this->iFormatCallback != '' || $this->iFormatCallback2 != '' ) { 170 171 if( $this->iFormatCallback != '' ) { 172 $f = $this->iFormatCallback; 173 list($width,$color,$fcolor) = call_user_func($f,$this->yvalue); 174 $filename = $this->iFileName; 175 $imgscale = $this->iScale; 176 } 177 else { 178 $f = $this->iFormatCallback2; 179 list($width,$color,$fcolor,$filename,$imgscale) = call_user_func($f,$this->yvalue,$this->xvalue); 180 if( $filename=="" ) $filename = $this->iFileName; 181 if( $imgscale=="" ) $imgscale = $this->iScale; 182 } 183 184 if( $width=="" ) $width = $this->width; 185 if( $color=="" ) $color = $this->color; 186 if( $fcolor=="" ) $fcolor = $this->fill_color; 187 188 } 189 else { 190 $fcolor = $this->fill_color; 191 $color = $this->color; 192 $width = $this->width; 193 $filename = $this->iFileName; 194 $imgscale = $this->iScale; 195 } 196 197 if( $this->type == MARK_IMG || 198 ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4 ) || 199 $this->type >= MARK_IMG_PUSHPIN ) { 200 201 // Note: For the builtin images we use the "filename" parameter 202 // to denote the color 203 $anchor_x = 0.5; 204 $anchor_y = 0.5; 205 switch( $this->type ) { 206 case MARK_FLAG1: 207 case MARK_FLAG2: 208 case MARK_FLAG3: 209 case MARK_FLAG4: 210 $this->markimg = FlagCache::GetFlagImgByName($this->type-MARK_FLAG1+1,$filename); 211 break; 212 213 case MARK_IMG : 214 // Load an image and use that as a marker 215 // Small optimization, if we have already read an image don't 216 // waste time reading it again. 217 if( $this->markimg == '' || !($this->oldfilename === $filename) ) { 218 $this->markimg = Graph::LoadBkgImage('',$filename); 219 $this->oldfilename = $filename ; 220 } 221 break; 222 223 case MARK_IMG_PUSHPIN: 224 case MARK_IMG_SPUSHPIN: 225 case MARK_IMG_LPUSHPIN: 226 if( $this->imgdata_pushpins == null ) { 227 require_once 'imgdata_pushpins.inc.php'; 228 $this->imgdata_pushpins = new ImgData_PushPins(); 229 } 230 $this->markimg = $this->imgdata_pushpins->GetImg($this->type,$filename); 231 list($anchor_x,$anchor_y) = $this->imgdata_pushpins->GetAnchor(); 232 break; 233 234 case MARK_IMG_SQUARE: 235 if( $this->imgdata_squares == null ) { 236 require_once 'imgdata_squares.inc.php'; 237 $this->imgdata_squares = new ImgData_Squares(); 238 } 239 $this->markimg = $this->imgdata_squares->GetImg($this->type,$filename); 240 list($anchor_x,$anchor_y) = $this->imgdata_squares->GetAnchor(); 241 break; 242 243 case MARK_IMG_STAR: 244 if( $this->imgdata_stars == null ) { 245 require_once 'imgdata_stars.inc.php'; 246 $this->imgdata_stars = new ImgData_Stars(); 247 } 248 $this->markimg = $this->imgdata_stars->GetImg($this->type,$filename); 249 list($anchor_x,$anchor_y) = $this->imgdata_stars->GetAnchor(); 250 break; 251 252 case MARK_IMG_BEVEL: 253 if( $this->imgdata_bevels == null ) { 254 require_once 'imgdata_bevels.inc.php'; 255 $this->imgdata_bevels = new ImgData_Bevels(); 256 } 257 $this->markimg = $this->imgdata_bevels->GetImg($this->type,$filename); 258 list($anchor_x,$anchor_y) = $this->imgdata_bevels->GetAnchor(); 259 break; 260 261 case MARK_IMG_DIAMOND: 262 if( $this->imgdata_diamonds == null ) { 263 require_once 'imgdata_diamonds.inc.php'; 264 $this->imgdata_diamonds = new ImgData_Diamonds(); 265 } 266 $this->markimg = $this->imgdata_diamonds->GetImg($this->type,$filename); 267 list($anchor_x,$anchor_y) = $this->imgdata_diamonds->GetAnchor(); 268 break; 269 270 case MARK_IMG_BALL: 271 case MARK_IMG_SBALL: 272 case MARK_IMG_MBALL: 273 case MARK_IMG_LBALL: 274 if( $this->imgdata_balls == null ) { 275 require_once 'imgdata_balls.inc.php'; 276 $this->imgdata_balls = new ImgData_Balls(); 277 } 278 $this->markimg = $this->imgdata_balls->GetImg($this->type,$filename); 279 list($anchor_x,$anchor_y) = $this->imgdata_balls->GetAnchor(); 280 break; 281 } 282 283 $w = $img->GetWidth($this->markimg); 284 $h = $img->GetHeight($this->markimg); 285 286 $dw = round($imgscale * $w ); 287 $dh = round($imgscale * $h ); 288 289 // Do potential rotation 290 list($x,$y) = $img->Rotate($x,$y); 291 292 $dx = round($x-$dw*$anchor_x); 293 $dy = round($y-$dh*$anchor_y); 294 295 $this->width = max($dx,$dy); 296 297 $img->Copy($this->markimg,$dx,$dy,0,0,$dw,$dh,$w,$h); 298 if( !empty($this->csimtarget) ) { 299 $this->csimareas = "<area shape=\"rect\" coords=\"". 300 $dx.','.$dy.','.round($dx+$dw).','.round($dy+$dh).'" '. 301 "href=\"".htmlentities($this->csimtarget)."\""; 302 303 if( !empty($this->csimwintarget) ) { 304 $this->csimareas .= " target=\"".$this->csimwintarget."\" "; 305 } 306 307 if( !empty($this->csimalt) ) { 308 $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue); 309 $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; 310 } 311 $this->csimareas .= " />\n"; 312 } 313 314 // Stroke title 315 $this->title->Align("center","top"); 316 $this->title->Stroke($img,$x,$y+round($dh/2)); 317 return; 318 } 319 320 $weight = $this->weight; 321 $dx=round($width/2,0); 322 $dy=round($width/2,0); 323 $pts=0; 324 325 switch( $this->type ) { 326 case MARK_SQUARE: 327 $c[]=$x-$dx;$c[]=$y-$dy; 328 $c[]=$x+$dx;$c[]=$y-$dy; 329 $c[]=$x+$dx;$c[]=$y+$dy; 330 $c[]=$x-$dx;$c[]=$y+$dy; 331 $c[]=$x-$dx;$c[]=$y-$dy; 332 $pts=5; 333 break; 334 case MARK_UTRIANGLE: 335 ++$dx;++$dy; 336 $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx 337 $c[]=$x;$c[]=$y-0.87*$dy; 338 $c[]=$x+$dx;$c[]=$y+0.87*$dy; 339 $c[]=$x-$dx;$c[]=$y+0.87*$dy; // tan(60)/2*$dx 340 $pts=4; 341 break; 342 case MARK_DTRIANGLE: 343 ++$dx;++$dy; 344 $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx 345 $c[]=$x-$dx;$c[]=$y-0.87*$dy; 346 $c[]=$x+$dx;$c[]=$y-0.87*$dy; 347 $c[]=$x;$c[]=$y+0.87*$dy; // tan(60)/2*$dx 348 $pts=4; 349 break; 350 case MARK_DIAMOND: 351 $c[]=$x;$c[]=$y+$dy; 352 $c[]=$x-$dx;$c[]=$y; 353 $c[]=$x;$c[]=$y-$dy; 354 $c[]=$x+$dx;$c[]=$y; 355 $c[]=$x;$c[]=$y+$dy; 356 $pts=5; 357 break; 358 case MARK_LEFTTRIANGLE: 359 $c[]=$x;$c[]=$y; 360 $c[]=$x;$c[]=$y+2*$dy; 361 $c[]=$x+$dx*2;$c[]=$y; 362 $c[]=$x;$c[]=$y; 363 $pts=4; 364 break; 365 case MARK_RIGHTTRIANGLE: 366 $c[]=$x-$dx*2;$c[]=$y; 367 $c[]=$x;$c[]=$y+2*$dy; 368 $c[]=$x;$c[]=$y; 369 $c[]=$x-$dx*2;$c[]=$y; 370 $pts=4; 371 break; 372 case MARK_FLASH: 373 $dy *= 2; 374 $c[]=$x+$dx/2; $c[]=$y-$dy; 375 $c[]=$x-$dx+$dx/2; $c[]=$y+$dy*0.7-$dy; 376 $c[]=$x+$dx/2; $c[]=$y+$dy*1.3-$dy; 377 $c[]=$x-$dx+$dx/2; $c[]=$y+2*$dy-$dy; 378 $img->SetLineWeight($weight); 379 $img->SetColor($color); 380 $img->Polygon($c); 381 $img->SetLineWeight(1); 382 $this->AddCSIMPoly($c); 383 break; 384 } 385 386 if( $pts>0 ) { 387 $this->AddCSIMPoly($c); 388 $img->SetLineWeight($weight); 389 $img->SetColor($fcolor); 390 $img->FilledPolygon($c); 391 $img->SetColor($color); 392 $img->Polygon($c); 393 $img->SetLineWeight(1); 394 } 395 elseif( $this->type==MARK_CIRCLE ) { 396 $img->SetColor($color); 397 $img->Circle($x,$y,$width); 398 $this->AddCSIMCircle($x,$y,$width); 399 } 400 elseif( $this->type==MARK_FILLEDCIRCLE ) { 401 $img->SetColor($fcolor); 402 $img->FilledCircle($x,$y,$width); 403 $img->SetColor($color); 404 $img->Circle($x,$y,$width); 405 $this->AddCSIMCircle($x,$y,$width); 406 } 407 elseif( $this->type==MARK_CROSS ) { 408 // Oversize by a pixel to match the X 409 $img->SetColor($color); 410 $img->SetLineWeight($weight); 411 $img->Line($x,$y+$dy+1,$x,$y-$dy-1); 412 $img->Line($x-$dx-1,$y,$x+$dx+1,$y); 413 $this->AddCSIMCircle($x,$y,$dx); 414 } 415 elseif( $this->type==MARK_X ) { 416 $img->SetColor($color); 417 $img->SetLineWeight($weight); 418 $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); 419 $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); 420 $this->AddCSIMCircle($x,$y,$dx+$dy); 421 } 422 elseif( $this->type==MARK_STAR ) { 423 $img->SetColor($color); 424 $img->SetLineWeight($weight); 425 $img->Line($x+$dx,$y+$dy,$x-$dx,$y-$dy); 426 $img->Line($x-$dx,$y+$dy,$x+$dx,$y-$dy); 427 // Oversize by a pixel to match the X 428 $img->Line($x,$y+$dy+1,$x,$y-$dy-1); 429 $img->Line($x-$dx-1,$y,$x+$dx+1,$y); 430 $this->AddCSIMCircle($x,$y,$dx+$dy); 431 } 432 433 // Stroke title 434 $this->title->Align("center","center"); 435 $this->title->Stroke($img,$x,$y); 436 436 } 437 437 } // Class … … 441 441 //======================================================================== 442 442 // CLASS ImgData 443 // Description: Base class for all image data classes that contains the 443 // Description: Base class for all image data classes that contains the 444 444 // real image data. 445 445 //======================================================================== 446 446 class ImgData { 447 protected $name = ''; 448 protected $an = array(); 449 protected $colors = array(); 450 protected $index = array(); 451 protected $maxidx = 0 ; 447 protected $name = ''; // Each subclass gives a name 448 protected $an = array(); // Data array names 449 protected $colors = array(); // Available colors 450 protected $index = array(); // Index for colors 451 protected $maxidx = 0 ; // Max color index 452 452 protected $anchor_x=0.5, $anchor_y=0.5 ; // Where is the center of the image 453 454 function __construct() { 455 // Empty 456 } 457 453 458 // Create a GD image from the data and return a GD handle 454 459 function GetImg($aMark,$aIdx) { 455 $n = $this->an[$aMark]; 456 if( is_string($aIdx) ) { 457 if( !in_array($aIdx,$this->colors) ) { 458 JpGraphError::RaiseL(23001,$this->name,$aIdx);//('This marker "'.($this->name).'" does not exist in color: '.$aIdx); 459 } 460 $idx = $this->index[$aIdx]; 461 } 462 elseif( !is_integer($aIdx) || 463 (is_integer($aIdx) && $aIdx > $this->maxidx ) ) { 464 JpGraphError::RaiseL(23002,$this->name);//('Mark color index too large for marker "'.($this->name).'"'); 465 } 466 else 467 $idx = $aIdx ; 468 return Image::CreateFromString(base64_decode($this->{$n}[$idx][1])); 469 } 460 $n = $this->an[$aMark]; 461 if( is_string($aIdx) ) { 462 if( !in_array($aIdx,$this->colors) ) { 463 JpGraphError::RaiseL(23001,$this->name,$aIdx);//('This marker "'.($this->name).'" does not exist in color: '.$aIdx); 464 } 465 $idx = $this->index[$aIdx]; 466 } 467 elseif( !is_integer($aIdx) || 468 (is_integer($aIdx) && $aIdx > $this->maxidx ) ) { 469 JpGraphError::RaiseL(23002,$this->name);//('Mark color index too large for marker "'.($this->name).'"'); 470 } 471 else 472 $idx = $aIdx ; 473 return Image::CreateFromString(base64_decode($this->{$n}[$idx][1])); 474 } 475 470 476 function GetAnchor() { 471 477 return array($this->anchor_x,$this->anchor_y); 472 478 } 473 479 } … … 476 482 // Keep a global flag cache to reduce memory usage 477 483 $_gFlagCache=array( 478 479 480 481 484 1 => null, 485 2 => null, 486 3 => null, 487 4 => null, 482 488 ); 483 489 // Only supposed to b called as statics 484 490 class FlagCache { 491 485 492 static function GetFlagImgByName($aSize,$aName) { 486 487 488 489 490 491 492 493 493 global $_gFlagCache; 494 require_once('jpgraph_flags.php'); 495 if( $_gFlagCache[$aSize] === null ) { 496 $_gFlagCache[$aSize] = new FlagImages($aSize); 497 } 498 $f = $_gFlagCache[$aSize]; 499 $idx = $f->GetIdxByName($aName,$aFullName); 500 return $f->GetImgByIdx($idx); 494 501 } 495 502 }
Note:
See TracChangeset
for help on using the changeset viewer.