Merge branch '138-toggle-free-look-with-hotkey' into 'main/atys-live'
[ryzomcore.git] / web / public_php / admin / jpgraph / jpgraph_iconplot.php
blob4e25b55dee7bb5f93efb2b3a652abbb1a4a1e780
1 <?php
2 //=======================================================================
3 // File: JPGRAPH_ICONPLOT.PHP
4 // Description: PHP4 Graph Plotting library. Extension module.
5 // Created: 2004-02-18
6 // Author: Johan Persson (johanp@aditus.nu)
7 // Ver: $Id: jpgraph_iconplot.php,v 1.1 2006/07/07 13:37:14 powles Exp $
8 //
9 // Copyright (c) Aditus Consulting. All rights reserved.
10 //========================================================================
13 //===================================================
14 // CLASS IconPlot
15 // Description: Make it possible to add a (small) image
16 // to the graph
17 //===================================================
18 class IconPlot {
19 var $iHorAnchor='left',$iVertAnchor='top';
20 var $iX=0,$iY=0;
21 var $iFile='';
22 var $iScale=1.0,$iMix=100;
23 var $iAnchors = array('left','right','top','bottom','center');
24 var $iCountryFlag='',$iCountryStdSize=3;
25 var $iScalePosY=null,$iScalePosX=null;
26 var $iImgString='';
28 function IconPlot($aFile="",$aX=0,$aY=0,$aScale=1.0,$aMix=100) {
29 $this->iFile = $aFile;
30 $this->iX=$aX;
31 $this->iY=$aY;
32 $this->iScale= $aScale;
33 if( $aMix < 0 || $aMix > 100 ) {
34 JpGraphError::RaiseL(8001); //('Mix value for icon must be between 0 and 100.');
36 $this->iMix = $aMix ;
39 function CreateFromString($aStr) {
40 $this->iImgString = $aStr;
43 function SetCountryFlag($aFlag,$aX=0,$aY=0,$aScale=1.0,$aMix=100,$aStdSize=3) {
44 $this->iCountryFlag = $aFlag;
45 $this->iX=$aX;
46 $this->iY=$aY;
47 $this->iScale= $aScale;
48 if( $aMix < 0 || $aMix > 100 ) {
49 JpGraphError::RaiseL(8001);//'Mix value for icon must be between 0 and 100.');
51 $this->iMix = $aMix;
52 $this->iCountryStdSize = $aStdSize;
55 function SetPos($aX,$aY) {
56 $this->iX=$aX;
57 $this->iY=$aY;
60 function SetScalePos($aX,$aY) {
61 $this->iScalePosX = $aX;
62 $this->iScalePosY = $aY;
65 function SetScale($aScale) {
66 $this->iScale = $aScale;
69 function SetMix($aMix) {
70 if( $aMix < 0 || $aMix > 100 ) {
71 JpGraphError::RaiseL(8001);//('Mix value for icon must be between 0 and 100.');
73 $this->iMix = $aMix ;
76 function SetAnchor($aXAnchor='left',$aYAnchor='center') {
77 if( !in_array($aXAnchor,$this->iAnchors) ||
78 !in_array($aYAnchor,$this->iAnchors) ) {
79 JpGraphError::RaiseL(8002);//("Anchor position for icons must be one of 'top', 'bottom', 'left', 'right' or 'center'");
81 $this->iHorAnchor=$aXAnchor;
82 $this->iVertAnchor=$aYAnchor;
85 function PreStrokeAdjust($aGraph) {
86 // Nothing to do ...
89 function DoLegend($aGraph) {
90 // Nothing to do ...
93 function Max() {
94 return array(false,false);
98 // The next four function are framework function tht gets called
99 // from Gantt and is not menaiungfull in the context of Icons but
100 // they must be implemented to avoid errors.
101 function GetMaxDate() { return false; }
102 function GetMinDate() { return false; }
103 function GetLineNbr() { return 0; }
104 function GetAbsHeight() {return 0; }
107 function Min() {
108 return array(false,false);
111 function StrokeMargin(&$aImg) {
112 return true;
115 function Stroke(&$aImg,$axscale,$ayscale) {
116 $this->StrokeWithScale($aImg,$axscale,$ayscale);
119 function StrokeWithScale(&$aImg,$axscale,$ayscale) {
120 if( $this->iScalePosX === null ||
121 $this->iScalePosY === null ) {
122 $this->_Stroke($aImg);
124 else {
125 $this->_Stroke($aImg,
126 round($axscale->Translate($this->iScalePosX)),
127 round($ayscale->Translate($this->iScalePosY)));
131 function GetWidthHeight() {
132 $dummy=0;
133 return $this->_Stroke($dummy,null,null,true);
136 function _Stroke(&$aImg,$x=null,$y=null,$aReturnWidthHeight=false) {
137 if( $this->iFile != '' && $this->iCountryFlag != '' ) {
138 JpGraphError::RaiseL(8003);//('It is not possible to specify both an image file and a country flag for the same icon.');
140 if( $this->iFile != '' ) {
141 $gdimg = Graph::LoadBkgImage('',$this->iFile);
143 elseif( $this->iImgString != '') {
144 $gdimg = Image::CreateFromString($this->iImgString);
146 else {
147 if( ! class_exists('FlagImages') ) {
148 JpGraphError::RaiseL(8004);//('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.');
150 $fobj = new FlagImages($this->iCountryStdSize);
151 $dummy='';
152 $gdimg = $fobj->GetImgByName($this->iCountryFlag,$dummy);
155 $iconw = imagesx($gdimg);
156 $iconh = imagesy($gdimg);
158 if( $aReturnWidthHeight ) {
159 return array(round($iconw*$this->iScale),round($iconh*$this->iScale));
162 if( $x !== null && $y !== null ) {
163 $this->iX = $x; $this->iY = $y;
165 if( $this->iX >= 0 && $this->iX <= 1.0 ) {
166 $w = imagesx($aImg->img);
167 $this->iX = round($w*$this->iX);
169 if( $this->iY >= 0 && $this->iY <= 1.0 ) {
170 $h = imagesy($aImg->img);
171 $this->iY = round($h*$this->iY);
174 if( $this->iHorAnchor == 'center' )
175 $this->iX -= round($iconw*$this->iScale/2);
176 if( $this->iHorAnchor == 'right' )
177 $this->iX -= round($iconw*$this->iScale);
178 if( $this->iVertAnchor == 'center' )
179 $this->iY -= round($iconh*$this->iScale/2);
180 if( $this->iVertAnchor == 'bottom' )
181 $this->iY -= round($iconh*$this->iScale);
183 $aImg->CopyMerge($gdimg,$this->iX,$this->iY,0,0,
184 round($iconw*$this->iScale),round($iconh*$this->iScale),
185 $iconw,$iconh,
186 $this->iMix);