]> git.llucax.com Git - mecon/meconlib.git/blob - lib/MECON/Graph/external/jpgraph/src/jpgraph_scatter.php
Se agrega una nueva mutacion (funcionalidad) a TablaDB. addRowsIcon ahora puede
[mecon/meconlib.git] / lib / MECON / Graph / external / jpgraph / src / jpgraph_scatter.php
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.31.2.1 2003/08/15 15:27:40 aditus Exp $
8 //
9 // License:     This code is released under QPL
10 // Copyright (C) 2001,2002 Johan Persson
11 //========================================================================
12 */
13
14
15 //===================================================
16 // CLASS FieldArrow
17 // Description: Draw an arrow at (x,y) with angle a
18 //===================================================
19 class FieldArrow {
20     var $iSize=10;  // Length in pixels for  arrow
21     var $iArrowSize = 2;
22     var $iColor='black';
23     var $isizespec = array(
24         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));
25     function FieldArrow() {
26     }
27
28     function SetSize($aSize,$aArrowSize=2) {
29         $this->iSize = $aSize;
30         $this->iArrowSize = $aArrowSize;
31     }
32
33     function SetColor($aColor) {
34         $this->iColor = $aColor;
35     }
36
37     function Stroke($aImg,$x,$y,$a) {
38         $old_origin = $aImg->SetCenter($x,$y);
39         $old_a = $aImg->SetAngle(-$a);
40
41         $dx = round($this->iSize/2);
42         $c = array($x-$dx,$y,$x+$dx,$y);
43         $x += $dx;
44
45         list($dx,$dy) = $this->isizespec[$this->iArrowSize];
46         $ca = array($x,$y,$x-$dx,$y-$dy,$x-$dx,$y+$dy,$x,$y);
47
48         $aImg->SetColor($this->iColor);
49         $aImg->Polygon($c);
50         $aImg->FilledPolygon($ca);
51
52         $aImg->SetCenter($old_origin[0],$old_origin[1]);
53         $aImg->SetAngle($old_a);
54     }
55 }
56
57 //===================================================
58 // CLASS FieldPlot
59 // Description: Render a field plot
60 //===================================================
61 class FieldPlot extends Plot {
62     var $iAngles;
63     var $iCallback='';
64     function FieldPlot($datay,$datax,$angles) {
65         if( (count($datax) != count($datay)) )
66             JpGraphError::Raise("Fieldplots must have equal number of X and Y points.");
67         if( (count($datax) != count($angles)) )
68             JpGraphError::Raise("Fieldplots must have an angle specified for each X and Y points.");
69         
70         $this->iAngles = $angles;
71
72         $this->Plot($datay,$datax);
73         $this->value->SetAlign('center','center');
74         $this->value->SetMargin(15);
75
76         $this->arrow = new FieldArrow();
77     }
78
79     function SetCallback($aFunc) {
80         $this->iCallback = $aFunc;
81     }
82
83     function Stroke(&$img,&$xscale,&$yscale) {
84
85         // Remeber base color and size
86         $bc = $this->arrow->iColor;
87         $bs = $this->arrow->iSize;
88         $bas = $this->arrow->iArrowSize;
89
90         for( $i=0; $i<$this->numpoints; ++$i ) {
91             // Skip null values
92             if( $this->coords[0][$i]==="" )
93                 continue;
94
95             $f = $this->iCallback;
96             if( $f != "" ) {
97                 list($cc,$cs,$cas) = call_user_func($f,$this->coords[1][$i],$this->coords[0][$i],$this->iAngles[$i]);
98                 // Fall back on global data if the callback isn't set
99                 if( $cc  == "" ) $cc = $bc;
100                 if( $cs  == "" ) $cs = $bs;
101                 if( $cas == "" ) $cas = $bas;
102                 //echo "f=$f, cc=$cc, cs=$cs, cas=$cas<br>";
103                 $this->arrow->SetColor($cc);        
104                 $this->arrow->SetSize($cs,$cas);
105             }
106
107             $xt = $xscale->Translate($this->coords[1][$i]);
108             $yt = $yscale->Translate($this->coords[0][$i]);     
109
110             $this->arrow->Stroke($img,$xt,$yt,$this->iAngles[$i]);
111             $this->value->Stroke($img,$this->coords[0][$i],$xt,$yt);
112         }
113     }
114         
115     // Framework function
116     function Legend(&$aGraph) {
117         if( $this->legend != "" ) {
118             $aGraph->legend->Add($this->legend,$this->mark->fill_color,$this->mark,0,
119                                  $this->legendcsimtarget,$this->legendcsimalt);
120         }
121     }   
122 }
123
124 //===================================================
125 // CLASS ScatterPlot
126 // Description: Render X and Y plots
127 //===================================================
128 class ScatterPlot extends Plot {
129     var $impuls = false;
130     var $linkpoints = false, $linkpointweight=1, $linkpointcolor="black";
131 //---------------
132 // CONSTRUCTOR
133     function ScatterPlot($datay,$datax=false) {
134         if( (count($datax) != count($datay)) && is_array($datax))
135             JpGraphError::Raise("Scatterplot must have equal number of X and Y points.");
136         $this->Plot($datay,$datax);
137         $this->mark = new PlotMark();
138         $this->mark->SetType(MARK_SQUARE);
139         $this->mark->SetColor($this->color);
140         $this->value->SetAlign('center','center');
141         $this->value->SetMargin(0);
142     }
143
144 //---------------
145 // PUBLIC METHODS       
146     function SetImpuls($f=true) {
147         $this->impuls = $f;
148     }   
149
150     // Combine the scatter plot points with a line
151     function SetLinkPoints($aFlag=true,$aColor="black",$aWeight=1) {
152         $this->linkpoints=$aFlag;
153         $this->linkpointcolor=$aColor;
154         $this->linkpointweight=$aWeight;
155     }
156
157     function Stroke(&$img,&$xscale,&$yscale) {
158
159         $ymin=$yscale->scale_abs[0];
160         if( $yscale->scale[0] < 0 )
161             $yzero=$yscale->Translate(0);
162         else
163             $yzero=$yscale->scale_abs[0];
164             
165         $this->csimareas = '';
166         for( $i=0; $i<$this->numpoints; ++$i ) {
167
168             // Skip null values
169             if( $this->coords[0][$i]==="" )
170                 continue;
171
172             if( isset($this->coords[1]) )
173                 $xt = $xscale->Translate($this->coords[1][$i]);
174             else
175                 $xt = $xscale->Translate($i);
176             $yt = $yscale->Translate($this->coords[0][$i]);     
177
178
179             if( $this->linkpoints && isset($yt_old) ) {
180                 $img->SetColor($this->linkpointcolor);
181                 $img->SetLineWeight($this->linkpointweight);
182                 $img->Line($xt_old,$yt_old,$xt,$yt);
183             }
184
185             if( $this->impuls ) {
186                 $img->SetColor($this->color);
187                 $img->SetLineWeight($this->weight);
188                 $img->Line($xt,$yzero,$xt,$yt);
189             }
190         
191             if( !empty($this->csimtargets[$i]) ) {
192                 $this->mark->SetCSIMTarget($this->csimtargets[$i]);
193                 $this->mark->SetCSIMAlt($this->csimalts[$i]);
194             }
195             
196             if( isset($this->coords[1]) ) {
197                 $this->mark->SetCSIMAltVal($this->coords[0][$i],$this->coords[1][$i]);
198             }
199             else {
200                 $this->mark->SetCSIMAltVal($this->coords[0][$i],$i);
201             }
202
203             $this->mark->Stroke($img,$xt,$yt);
204         
205             $this->csimareas .= $this->mark->GetCSIMAreas();
206             $this->value->Stroke($img,$this->coords[0][$i],$xt,$yt);
207
208             $xt_old = $xt;
209             $yt_old = $yt;
210         }
211     }
212         
213     // Framework function
214     function Legend(&$aGraph) {
215         if( $this->legend != "" ) {
216             $aGraph->legend->Add($this->legend,$this->mark->fill_color,$this->mark,0,
217                                  $this->legendcsimtarget,$this->legendcsimalt);
218         }
219     }   
220 } // Class
221 /* EOF */
222 ?>