Fix checkRpItemsPosition
[ryzomcore.git] / web / public_php / admin / jpgraph / jpgraph_scatter.php
blob1a21fccfa5a8bbac052d7ae6a726595d68cc009e
1 <?php
2 /*=======================================================================
3 // File: JPGRAPH_SCATTER.PHP
4 // Description: Scatter (and impuls) plot extension for JpGraph
5 // Created: 2001-02-11
6 // Author: Johan Persson (johanp@aditus.nu)
7 // Ver: $Id: jpgraph_scatter.php,v 1.1 2006/07/07 13:37:14 powles Exp $
8 //
9 // Copyright (c) Aditus Consulting. All rights reserved.
10 //========================================================================
12 require_once ('jpgraph_plotmark.inc');
14 //===================================================
15 // CLASS FieldArrow
16 // Description: Draw an arrow at (x,y) with angle a
17 //===================================================
18 class FieldArrow {
19 var $iSize=10; // Length in pixels for arrow
20 var $iArrowSize = 2;
21 var $iColor='black';
22 var $isizespec = array(
23 array(2,1),array(3,2),array(4,3),array(6,4),array(7,4),array(8,5),array(10,6),array(12,7),array(16,8),array(20,10));
24 function FieldArrow() {
27 function SetSize($aSize,$aArrowSize=2) {
28 $this->iSize = $aSize;
29 $this->iArrowSize = $aArrowSize;
32 function SetColor($aColor) {
33 $this->iColor = $aColor;
36 function Stroke(&$aImg,$x,$y,$a) {
37 // First rotate the center coordinates
38 list($x,$y) = $aImg->Rotate($x,$y);
40 $old_origin = $aImg->SetCenter($x,$y);
41 $old_a = $aImg->a;
42 $aImg->SetAngle(-$a+$old_a);
44 $dx = round($this->iSize/2);
45 $c = array($x-$dx,$y,$x+$dx,$y);
46 $x += $dx;
48 list($dx,$dy) = $this->isizespec[$this->iArrowSize];
49 $ca = array($x,$y,$x-$dx,$y-$dy,$x-$dx,$y+$dy,$x,$y);
51 $aImg->SetColor($this->iColor);
52 $aImg->Polygon($c);
53 $aImg->FilledPolygon($ca);
55 $aImg->SetCenter($old_origin[0],$old_origin[1]);
56 $aImg->SetAngle($old_a);
60 //===================================================
61 // CLASS FieldPlot
62 // Description: Render a field plot
63 //===================================================
64 class FieldPlot extends Plot {
65 var $iAngles;
66 var $iCallback='';
67 function FieldPlot($datay,$datax,$angles) {
68 if( (count($datax) != count($datay)) )
69 JpGraphError::RaiseL(20001);//("Fieldplots must have equal number of X and Y points.");
70 if( (count($datax) != count($angles)) )
71 JpGraphError::RaiseL(20002);//("Fieldplots must have an angle specified for each X and Y points.");
73 $this->iAngles = $angles;
75 $this->Plot($datay,$datax);
76 $this->value->SetAlign('center','center');
77 $this->value->SetMargin(15);
79 $this->arrow = new FieldArrow();
82 function SetCallback($aFunc) {
83 $this->iCallback = $aFunc;
86 function Stroke(&$img,&$xscale,&$yscale) {
88 // Remeber base color and size
89 $bc = $this->arrow->iColor;
90 $bs = $this->arrow->iSize;
91 $bas = $this->arrow->iArrowSize;
93 for( $i=0; $i<$this->numpoints; ++$i ) {
94 // Skip null values
95 if( $this->coords[0][$i]==="" )
96 continue;
98 $f = $this->iCallback;
99 if( $f != "" ) {
100 list($cc,$cs,$cas) = call_user_func($f,$this->coords[1][$i],$this->coords[0][$i],$this->iAngles[$i]);
101 // Fall back on global data if the callback isn't set
102 if( $cc == "" ) $cc = $bc;
103 if( $cs == "" ) $cs = $bs;
104 if( $cas == "" ) $cas = $bas;
105 //echo "f=$f, cc=$cc, cs=$cs, cas=$cas<br>";
106 $this->arrow->SetColor($cc);
107 $this->arrow->SetSize($cs,$cas);
110 $xt = $xscale->Translate($this->coords[1][$i]);
111 $yt = $yscale->Translate($this->coords[0][$i]);
113 $this->arrow->Stroke($img,$xt,$yt,$this->iAngles[$i]);
114 $this->value->Stroke($img,$this->coords[0][$i],$xt,$yt);
118 // Framework function
119 function Legend(&$aGraph) {
120 if( $this->legend != "" ) {
121 $aGraph->legend->Add($this->legend,$this->mark->fill_color,$this->mark,0,
122 $this->legendcsimtarget,$this->legendcsimalt);
127 //===================================================
128 // CLASS ScatterPlot
129 // Description: Render X and Y plots
130 //===================================================
131 class ScatterPlot extends Plot {
132 var $impuls = false;
133 var $linkpoints = false, $linkpointweight=1, $linkpointcolor="black";
134 //---------------
135 // CONSTRUCTOR
136 function ScatterPlot($datay,$datax=false) {
137 if( (count($datax) != count($datay)) && is_array($datax))
138 JpGraphError::RaiseL(20003);//("Scatterplot must have equal number of X and Y points.");
139 $this->Plot($datay,$datax);
140 $this->mark = new PlotMark();
141 $this->mark->SetType(MARK_SQUARE);
142 $this->mark->SetColor($this->color);
143 $this->value->SetAlign('center','center');
144 $this->value->SetMargin(0);
147 //---------------
148 // PUBLIC METHODS
149 function SetImpuls($f=true) {
150 $this->impuls = $f;
153 // Combine the scatter plot points with a line
154 function SetLinkPoints($aFlag=true,$aColor="black",$aWeight=1) {
155 $this->linkpoints=$aFlag;
156 $this->linkpointcolor=$aColor;
157 $this->linkpointweight=$aWeight;
160 function Stroke(&$img,&$xscale,&$yscale) {
162 $ymin=$yscale->scale_abs[0];
163 if( $yscale->scale[0] < 0 )
164 $yzero=$yscale->Translate(0);
165 else
166 $yzero=$yscale->scale_abs[0];
168 $this->csimareas = '';
169 for( $i=0; $i<$this->numpoints; ++$i ) {
171 // Skip null values
172 if( $this->coords[0][$i]==="" || $this->coords[0][$i]==='-' || $this->coords[0][$i]==='x')
173 continue;
175 if( isset($this->coords[1]) )
176 $xt = $xscale->Translate($this->coords[1][$i]);
177 else
178 $xt = $xscale->Translate($i);
179 $yt = $yscale->Translate($this->coords[0][$i]);
182 if( $this->linkpoints && isset($yt_old) ) {
183 $img->SetColor($this->linkpointcolor);
184 $img->SetLineWeight($this->linkpointweight);
185 $img->Line($xt_old,$yt_old,$xt,$yt);
188 if( $this->impuls ) {
189 $img->SetColor($this->color);
190 $img->SetLineWeight($this->weight);
191 $img->Line($xt,$yzero,$xt,$yt);
194 if( !empty($this->csimtargets[$i]) ) {
195 $this->mark->SetCSIMTarget($this->csimtargets[$i]);
196 $this->mark->SetCSIMAlt($this->csimalts[$i]);
199 if( isset($this->coords[1]) ) {
200 $this->mark->SetCSIMAltVal($this->coords[0][$i],$this->coords[1][$i]);
202 else {
203 $this->mark->SetCSIMAltVal($this->coords[0][$i],$i);
206 $this->mark->Stroke($img,$xt,$yt);
208 $this->csimareas .= $this->mark->GetCSIMAreas();
209 $this->value->Stroke($img,$this->coords[0][$i],$xt,$yt);
211 $xt_old = $xt;
212 $yt_old = $yt;
216 // Framework function
217 function Legend(&$aGraph) {
218 if( $this->legend != "" ) {
219 $aGraph->legend->Add($this->legend,$this->mark->fill_color,$this->mark,0,
220 $this->legendcsimtarget,$this->legendcsimalt);
223 } // Class
224 /* EOF */