Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 aurelien 1
<?php
2
//=======================================================================
3
// File:	JPGRAPH_ICONPLOT.PHP
4
// Description:	PHP4 Graph Plotting library. Extension module.
5
// Created: 	2004-02-18
6
// Ver:		$Id: jpgraph_iconplot.php 838 2007-01-22 21:01:22Z ljp $
7
//
8
// Copyright (c) Aditus Consulting. All rights reserved.
9
//========================================================================
10
 
11
 
12
//===================================================
13
// CLASS IconPlot
14
// Description: Make it possible to add a (small) image
15
// to the graph
16
//===================================================
17
class IconPlot {
18
    var $iHorAnchor='left',$iVertAnchor='top';
19
    var $iX=0,$iY=0;
20
    var $iFile='';
21
    var $iScale=1.0,$iMix=100;
22
    var $iAnchors = array('left','right','top','bottom','center');
23
    var $iCountryFlag='',$iCountryStdSize=3;
24
    var $iScalePosY=null,$iScalePosX=null;
25
    var $iImgString='';
26
 
27
    function IconPlot($aFile="",$aX=0,$aY=0,$aScale=1.0,$aMix=100) {
28
	$this->iFile = $aFile;
29
	$this->iX=$aX;
30
	$this->iY=$aY;
31
	$this->iScale= $aScale;
32
	if( $aMix < 0 || $aMix > 100 ) {
33
	    JpGraphError::RaiseL(8001); //('Mix value for icon must be between 0 and 100.');
34
	}
35
	$this->iMix = $aMix ;
36
    }
37
 
38
    function CreateFromString($aStr) {
39
	$this->iImgString = $aStr;
40
    }
41
 
42
    function SetCountryFlag($aFlag,$aX=0,$aY=0,$aScale=1.0,$aMix=100,$aStdSize=3) {
43
	$this->iCountryFlag = $aFlag;
44
	$this->iX=$aX;
45
	$this->iY=$aY;
46
	$this->iScale= $aScale;
47
	if( $aMix < 0 || $aMix > 100 ) {
48
	    JpGraphError::RaiseL(8001);//'Mix value for icon must be between 0 and 100.');
49
	}
50
	$this->iMix = $aMix;
51
	$this->iCountryStdSize = $aStdSize;
52
    }
53
 
54
    function SetPos($aX,$aY) {
55
	$this->iX=$aX;
56
	$this->iY=$aY;
57
    }
58
 
59
    function SetScalePos($aX,$aY) {
60
	$this->iScalePosX = $aX;
61
	$this->iScalePosY = $aY;
62
    }
63
 
64
    function SetScale($aScale) {
65
	$this->iScale = $aScale;
66
    }
67
 
68
    function SetMix($aMix) {
69
	if( $aMix < 0 || $aMix > 100 ) {
70
	    JpGraphError::RaiseL(8001);//('Mix value for icon must be between 0 and 100.');
71
	}
72
	$this->iMix = $aMix ;
73
    }
74
 
75
    function SetAnchor($aXAnchor='left',$aYAnchor='center') {
76
	if( !in_array($aXAnchor,$this->iAnchors) ||
77
	    !in_array($aYAnchor,$this->iAnchors) ) {
78
	    JpGraphError::RaiseL(8002);//("Anchor position for icons must be one of 'top', 'bottom', 'left', 'right' or 'center'");
79
	}
80
	$this->iHorAnchor=$aXAnchor;
81
	$this->iVertAnchor=$aYAnchor;
82
    }
83
 
84
    function PreStrokeAdjust($aGraph) {
85
	// Nothing to do ...
86
    }
87
 
88
    function DoLegend($aGraph) {
89
	// Nothing to do ...
90
    }
91
 
92
    function Max() {
93
	return array(false,false);
94
    }
95
 
96
 
97
    // The next four function are framework function tht gets called
98
    // from Gantt and is not menaiungfull in the context of Icons but
99
    // they must be implemented to avoid errors.
100
    function GetMaxDate() { return false;   }
101
    function GetMinDate() { return false;   }
102
    function GetLineNbr() { return 0;   }
103
    function GetAbsHeight() {return 0;  }
104
 
105
 
106
    function Min() {
107
	return array(false,false);
108
    }
109
 
110
    function StrokeMargin(&$aImg) {
111
	return true;
112
    }
113
 
114
    function Stroke(&$aImg,&$axscale,&$ayscale) {
115
	$this->StrokeWithScale($aImg,$axscale,$ayscale);
116
    }
117
 
118
    function StrokeWithScale(&$aImg,&$axscale,&$ayscale) {
119
	if( $this->iScalePosX === null ||
120
	    $this->iScalePosY === null ) {
121
	    $this->_Stroke($aImg);
122
	}
123
	else {
124
	    $this->_Stroke($aImg,
125
			  round($axscale->Translate($this->iScalePosX)),
126
			  round($ayscale->Translate($this->iScalePosY)));
127
	}
128
    }
129
 
130
    function GetWidthHeight() {
131
	$dummy=0;
132
	return $this->_Stroke($dummy,null,null,true);
133
    }
134
 
135
    function _Stroke(&$aImg,$x=null,$y=null,$aReturnWidthHeight=false) {
136
	if( $this->iFile != '' && $this->iCountryFlag != '' ) {
137
	    JpGraphError::RaiseL(8003);//('It is not possible to specify both an image file and a country flag for the same icon.');
138
	}
139
	if( $this->iFile != '' ) {
140
	    $gdimg = Graph::LoadBkgImage('',$this->iFile);
141
	}
142
	elseif( $this->iImgString != '') {
143
	    $gdimg = Image::CreateFromString($this->iImgString);
144
	}
145
	else {
146
	    if( ! class_exists('FlagImages') ) {
147
		JpGraphError::RaiseL(8004);//('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.');
148
	    }
149
	    $fobj = new FlagImages($this->iCountryStdSize);
150
	    $dummy='';
151
	    $gdimg = $fobj->GetImgByName($this->iCountryFlag,$dummy);
152
	}
153
 
154
	$iconw = imagesx($gdimg);
155
	$iconh = imagesy($gdimg);
156
 
157
	if( $aReturnWidthHeight ) {
158
	    return array(round($iconw*$this->iScale),round($iconh*$this->iScale));
159
	}
160
 
161
	if( $x !== null && $y !== null ) {
162
	    $this->iX = $x; $this->iY = $y;
163
	}
164
	if( $this->iX >= 0  && $this->iX <= 1.0 ) {
165
	    $w = imagesx($aImg->img);
166
	    $this->iX = round($w*$this->iX);
167
	}
168
	if( $this->iY >= 0  && $this->iY <= 1.0 ) {
169
	    $h = imagesy($aImg->img);
170
	    $this->iY = round($h*$this->iY);
171
	}
172
 
173
	if( $this->iHorAnchor == 'center' )
174
	    $this->iX -= round($iconw*$this->iScale/2);
175
	if( $this->iHorAnchor == 'right' )
176
	    $this->iX -= round($iconw*$this->iScale);
177
	if( $this->iVertAnchor == 'center' )
178
	    $this->iY -= round($iconh*$this->iScale/2);
179
	if( $this->iVertAnchor == 'bottom' )
180
	    $this->iY -= round($iconh*$this->iScale);
181
 
182
	$aImg->CopyMerge($gdimg,$this->iX,$this->iY,0,0,
183
			 round($iconw*$this->iScale),round($iconh*$this->iScale),
184
			 $iconw,$iconh,
185
			 $this->iMix);
186
    }
187
}
188
 
189
?>