source: trunk/client/modules/Elezioni/grafici/jpgraph_iconplot.php@ 250

Last change on this file since 250 was 2, checked in by root, 15 years ago

importo il progetto

File size: 5.2 KB
Line 
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 781 2006-10-08 08:07:47Z 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//===================================================
17class IconPlot {
18 public $iX=0,$iY=0,$iScale=1.0,$iMix=100;
19 private $iHorAnchor='left',$iVertAnchor='top';
20 private $iFile='';
21 private $iAnchors = array('left','right','top','bottom','center');
22 private $iCountryFlag='',$iCountryStdSize=3;
23 private $iScalePosY=null,$iScalePosX=null;
24 private $iImgString='';
25
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 SetCountryFlag($aFlag,$aX=0,$aY=0,$aScale=1.0,$aMix=100,$aStdSize=3) {
39 $this->iCountryFlag = $aFlag;
40 $this->iX=$aX;
41 $this->iY=$aY;
42 $this->iScale= $aScale;
43 if( $aMix < 0 || $aMix > 100 ) {
44 JpGraphError::RaiseL(8001);//'Mix value for icon must be between 0 and 100.');
45 }
46 $this->iMix = $aMix;
47 $this->iCountryStdSize = $aStdSize;
48 }
49
50 function SetPos($aX,$aY) {
51 $this->iX=$aX;
52 $this->iY=$aY;
53 }
54
55 function CreateFromString($aStr) {
56 $this->iImgString = $aStr;
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
146 else {
147 if( ! class_exists('FlagImages',false) ) {
148 JpGraphError::RaiseL(8004);//('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.');
149 }
150 $fobj = new FlagImages($this->iCountryStdSize);
151 $dummy='';
152 $gdimg = $fobj->GetImgByName($this->iCountryFlag,$dummy);
153 }
154
155 $iconw = imagesx($gdimg);
156 $iconh = imagesy($gdimg);
157
158 if( $aReturnWidthHeight ) {
159 return array(round($iconw*$this->iScale),round($iconh*$this->iScale));
160 }
161
162 if( $x !== null && $y !== null ) {
163 $this->iX = $x; $this->iY = $y;
164 }
165 if( $this->iX >= 0 && $this->iX <= 1.0 ) {
166 $w = imagesx($aImg->img);
167 $this->iX = round($w*$this->iX);
168 }
169 if( $this->iY >= 0 && $this->iY <= 1.0 ) {
170 $h = imagesy($aImg->img);
171 $this->iY = round($h*$this->iY);
172 }
173
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);
182
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);
187 }
188}
189
190?>
Note: See TracBrowser for help on using the repository browser.