source: trunk/client/modules/Elezioni/grafici/jpgraph_radar.php@ 2

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

importo il progetto

File size: 21.1 KB
Line 
1<?php
2/*=======================================================================
3// File: JPGRAPH_RADAR.PHP
4// Description: Radar plot extension for JpGraph
5// Created: 2001-02-04
6// Ver: $Id: jpgraph_radar.php 1044 2008-07-31 18:34:55Z ljp $
7//
8// Copyright (c) Aditus Consulting. All rights reserved.
9//========================================================================
10*/
11
12require_once('jpgraph_plotmark.inc.php');
13
14class RadarLogTicks extends Ticks {
15//---------------
16// CONSTRUCTOR
17 function RadarLogTicks() {
18 }
19//---------------
20// PUBLIC METHODS
21
22 // TODO: Add Argument grid
23 function Stroke($aImg,&$grid,$aPos,$aAxisAngle,$aScale,&$aMajPos,&$aMajLabel) {
24 $start = $aScale->GetMinVal();
25 $limit = $aScale->GetMaxVal();
26 $nextMajor = 10*$start;
27 $step = $nextMajor / 10.0;
28 $count=1;
29
30 $ticklen_maj=5;
31 $dx_maj=round(sin($aAxisAngle)*$ticklen_maj);
32 $dy_maj=round(cos($aAxisAngle)*$ticklen_maj);
33 $ticklen_min=3;
34 $dx_min=round(sin($aAxisAngle)*$ticklen_min);
35 $dy_min=round(cos($aAxisAngle)*$ticklen_min);
36
37 $aMajPos=array();
38 $aMajLabel=array();
39
40 if( $this->supress_first )
41 $aMajLabel[]="";
42 else
43 $aMajLabel[]=$start;
44 $yr=$aScale->RelTranslate($start);
45 $xt=round($yr*cos($aAxisAngle))+$aScale->scale_abs[0];
46 $yt=$aPos-round($yr*sin($aAxisAngle));
47 $aMajPos[]=$xt+2*$dx_maj;
48 $aMajPos[]=$yt-$aImg->GetFontheight()/2;
49 $grid[]=$xt;
50 $grid[]=$yt;
51
52 $aImg->SetLineWeight($this->weight);
53
54 for($y=$start; $y<=$limit; $y+=$step,++$count ) {
55 $yr=$aScale->RelTranslate($y);
56 $xt=round($yr*cos($aAxisAngle))+$aScale->scale_abs[0];
57 $yt=$aPos-round($yr*sin($aAxisAngle));
58 if( $count % 10 == 0 ) {
59 $grid[]=$xt;
60 $grid[]=$yt;
61 $aMajPos[]=$xt+2*$dx_maj;
62 $aMajPos[]=$yt-$aImg->GetFontheight()/2;
63 if( !$this->supress_tickmarks ) {
64 if( $this->majcolor!="" ) $aImg->PushColor($this->majcolor);
65 $aImg->Line($xt+$dx_maj,$yt+$dy_maj,$xt-$dx_maj,$yt-$dy_maj);
66 if( $this->majcolor!="" ) $aImg->PopColor();
67 }
68 if( $this->label_formfunc != "" ) {
69 $f=$this->label_formfunc;
70 $l = call_user_func($f,$nextMajor);
71 }
72 else
73 $l = $nextMajor;
74
75 $aMajLabel[]=$l;
76 $nextMajor *= 10;
77 $step *= 10;
78 $count=1;
79 }
80 else
81 if( !$this->supress_minor_tickmarks ) {
82 if( $this->mincolor!="" ) $aImg->PushColor($this->mincolor);
83 $aImg->Line($xt+$dx_min,$yt+$dy_min,$xt-$dx_min,$yt-$dy_min);
84 if( $this->mincolor!="" ) $aImg->PopColor();
85 }
86 }
87 }
88}
89
90class RadarLinearTicks extends Ticks {
91
92 private $minor_step=1, $major_step=2;
93 private $xlabel_offset=0,$xtick_offset=0;
94
95//---------------
96// CONSTRUCTOR
97 function RadarLinearTicks() {
98 // Empty
99 }
100
101//---------------
102// PUBLIC METHODS
103
104
105 // Return major step size in world coordinates
106 function GetMajor() {
107 return $this->major_step;
108 }
109
110 // Return minor step size in world coordinates
111 function GetMinor() {
112 return $this->minor_step;
113 }
114
115 // Set Minor and Major ticks (in world coordinates)
116 function Set($aMajStep,$aMinStep=false) {
117 if( $aMinStep==false )
118 $aMinStep=$aMajStep;
119
120 if( $aMajStep <= 0 || $aMinStep <= 0 ) {
121 JpGraphError::Raise(" Minor or major step size is 0. Check that you haven't
122 got an accidental SetTextTicks(0) in your code.<p>
123 If this is not the case you might have stumbled upon a bug in JpGraph.
124 Please report this and if possible include the data that caused the
125 problem.");
126 }
127
128 $this->major_step=$aMajStep;
129 $this->minor_step=$aMinStep;
130 $this->is_set = true;
131 }
132
133 function Stroke($aImg,&$grid,$aPos,$aAxisAngle,$aScale,&$aMajPos,&$aMajLabel) {
134 // Prepare to draw linear ticks
135 $maj_step_abs = abs($aScale->scale_factor*$this->major_step);
136 $min_step_abs = abs($aScale->scale_factor*$this->minor_step);
137 $nbrmaj = floor(($aScale->world_abs_size)/$maj_step_abs);
138 $nbrmin = floor(($aScale->world_abs_size)/$min_step_abs);
139 $skip = round($nbrmin/$nbrmaj); // Don't draw minor ontop of major
140
141 // Draw major ticks
142 $ticklen2=$this->major_abs_size;
143 $dx=round(sin($aAxisAngle)*$ticklen2);
144 $dy=round(cos($aAxisAngle)*$ticklen2);
145 $label=$aScale->scale[0]+$this->major_step;
146
147 $aImg->SetLineWeight($this->weight);
148 // NEW
149 $aMajPos = array();
150 $aMajLabel = array();
151 for($i=1; $i<=$nbrmaj; ++$i) {
152 $xt=round($i*$maj_step_abs*cos($aAxisAngle))+$aScale->scale_abs[0];
153 $yt=$aPos-round($i*$maj_step_abs*sin($aAxisAngle));
154
155 if( $this->label_formfunc != "" ) {
156 $f=$this->label_formfunc;
157 $l = call_user_func($f,$label);
158 }
159 else
160 $l = $label;
161
162 $aMajLabel[]=$l;
163 $label += $this->major_step;
164 $grid[]=$xt;
165 $grid[]=$yt;
166 $aMajPos[($i-1)*2]=$xt+2*$dx;
167 $aMajPos[($i-1)*2+1]=$yt-$aImg->GetFontheight()/2;
168 if( !$this->supress_tickmarks ) {
169 if( $this->majcolor!="" ) $aImg->PushColor($this->majcolor);
170 $aImg->Line($xt+$dx,$yt+$dy,$xt-$dx,$yt-$dy);
171 if( $this->majcolor!="" ) $aImg->PopColor();
172 }
173 }
174
175 // Draw minor ticks
176 $ticklen2=$this->minor_abs_size;
177 $dx=round(sin($aAxisAngle)*$ticklen2);
178 $dy=round(cos($aAxisAngle)*$ticklen2);
179 if( !$this->supress_tickmarks && !$this->supress_minor_tickmarks) {
180 if( $this->mincolor!="" ) $aImg->PushColor($this->mincolor);
181 for($i=1; $i<=$nbrmin; ++$i) {
182 if( ($i % $skip) == 0 ) continue;
183 $xt=round($i*$min_step_abs*cos($aAxisAngle))+$aScale->scale_abs[0];
184 $yt=$aPos-round($i*$min_step_abs*sin($aAxisAngle));
185 $aImg->Line($xt+$dx,$yt+$dy,$xt-$dx,$yt-$dy);
186 }
187 if( $this->mincolor!="" ) $aImg->PopColor();
188 }
189 }
190}
191
192
193
194//===================================================
195// CLASS RadarAxis
196// Description: Implements axis for the radar graph
197//===================================================
198class RadarAxis extends AxisPrototype {
199 public $title=null;
200 private $title_color="navy";
201 private $len=0;
202//---------------
203// CONSTRUCTOR
204 function RadarAxis($img,$aScale,$color=array(0,0,0)) {
205 parent::Axis($img,$aScale,$color);
206 $this->len=$img->plotheight;
207 $this->title = new Text();
208 $this->title->SetFont(FF_FONT1,FS_BOLD);
209 $this->color = array(0,0,0);
210 }
211//---------------
212// PUBLIC METHODS
213 function SetTickLabels($aLabelArray,$aLabelColorArray=null) {
214 $this->ticks_label = $aLabelArray;
215 $this->ticks_label_colors = $aLabelColorArray;
216 }
217
218
219 // Stroke the axis
220 // $pos = Vertical position of axis
221 // $aAxisAngle = Axis angle
222 // $grid = Returns an array with positions used to draw the grid
223 // $lf = Label flag, TRUE if the axis should have labels
224 function Stroke($pos,$aAxisAngle,&$grid,$title,$lf) {
225 $this->img->SetColor($this->color);
226
227 // Determine end points for the axis
228 $x=round($this->scale->world_abs_size*cos($aAxisAngle)+$this->scale->scale_abs[0]);
229 $y=round($pos-$this->scale->world_abs_size*sin($aAxisAngle));
230
231 // Draw axis
232 $this->img->SetColor($this->color);
233 $this->img->SetLineWeight($this->weight);
234 if( !$this->hide )
235 $this->img->Line($this->scale->scale_abs[0],$pos,$x,$y);
236
237 $this->scale->ticks->Stroke($this->img,$grid,$pos,$aAxisAngle,$this->scale,$majpos,$majlabel);
238 $ncolor=0;
239 if( isset($this->ticks_label_colors) )
240 $ncolor=count($this->ticks_label_colors);
241
242 // Draw labels
243 if( $lf && !$this->hide ) {
244 $this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
245 $this->img->SetTextAlign("left","top");
246 $this->img->SetColor($this->label_color);
247
248 // majpos contains (x,y) coordinates for labels
249 if( ! $this->hide_labels ) {
250 $n = floor(count($majpos)/2);
251 for($i=0; $i < $n; ++$i) {
252 // Set specific label color if specified
253 if( $ncolor > 0 )
254 $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]);
255
256 if( $this->ticks_label != null && isset($this->ticks_label[$i]) )
257 $this->img->StrokeText($majpos[$i*2],$majpos[$i*2+1],$this->ticks_label[$i]);
258 else
259 $this->img->StrokeText($majpos[$i*2],$majpos[$i*2+1],$majlabel[$i]);
260 }
261 }
262 }
263 $this->_StrokeAxisTitle($pos,$aAxisAngle,$title);
264 }
265//---------------
266// PRIVATE METHODS
267
268 function _StrokeAxisTitle($pos,$aAxisAngle,$title) {
269 $this->title->Set($title);
270 $marg=6+$this->title->margin;
271 $xt=round(($this->scale->world_abs_size+$marg)*cos($aAxisAngle)+$this->scale->scale_abs[0]);
272 $yt=round($pos-($this->scale->world_abs_size+$marg)*sin($aAxisAngle));
273
274 // Position the axis title.
275 // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text
276 // that intersects with the extension of the corresponding axis. The code looks a little
277 // bit messy but this is really the only way of having a reasonable position of the
278 // axis titles.
279 if( $this->title->iWordwrap > 0 ) {
280 $title = wordwrap($title,$this->title->iWordwrap,"\n");
281 }
282
283 $h=$this->img->GetTextHeight($title)*1.2;
284 $w=$this->img->GetTextWidth($title)*1.2;
285
286 while( $aAxisAngle > 2*M_PI ) $aAxisAngle -= 2*M_PI;
287
288 // Around 3 a'clock
289 if( $aAxisAngle>=7*M_PI/4 || $aAxisAngle <= M_PI/4 ) $dx=-0.15; // Small trimming to make the dist to the axis more even
290 // Around 12 a'clock
291 if( $aAxisAngle>=M_PI/4 && $aAxisAngle <= 3*M_PI/4 ) $dx=($aAxisAngle-M_PI/4)*2/M_PI;
292 // Around 9 a'clock
293 if( $aAxisAngle>=3*M_PI/4 && $aAxisAngle <= 5*M_PI/4 ) $dx=1;
294 // Around 6 a'clock
295 if( $aAxisAngle>=5*M_PI/4 && $aAxisAngle <= 7*M_PI/4 ) $dx=(1-($aAxisAngle-M_PI*5/4)*2/M_PI);
296
297 if( $aAxisAngle>=7*M_PI/4 ) $dy=(($aAxisAngle-M_PI)-3*M_PI/4)*2/M_PI;
298 if( $aAxisAngle<=M_PI/12 ) $dy=(0.5-$aAxisAngle*2/M_PI);
299 if( $aAxisAngle<=M_PI/4 && $aAxisAngle > M_PI/12) $dy=(1-$aAxisAngle*2/M_PI);
300 if( $aAxisAngle>=M_PI/4 && $aAxisAngle <= 3*M_PI/4 ) $dy=1;
301 if( $aAxisAngle>=3*M_PI/4 && $aAxisAngle <= 5*M_PI/4 ) $dy=(1-($aAxisAngle-3*M_PI/4)*2/M_PI);
302 if( $aAxisAngle>=5*M_PI/4 && $aAxisAngle <= 7*M_PI/4 ) $dy=0;
303
304 if( !$this->hide ) {
305 $this->title->Stroke($this->img,$xt-$dx*$w,$yt-$dy*$h,$title);
306 }
307 }
308
309
310} // Class
311
312
313//===================================================
314// CLASS RadarGrid
315// Description: Draws grid for the radar graph
316//===================================================
317class RadarGrid { //extends Grid {
318 private $type='solid';
319 private $grid_color='#DDDDDD';
320 private $show=false, $weight=1;
321
322//------------
323// CONSTRUCTOR
324 function RadarGrid() {
325 }
326
327// PUBLIC METHODS
328 function SetColor($aMajColor) {
329 $this->grid_color = $aMajColor;
330 }
331
332 function SetWeight($aWeight) {
333 $this->weight=$aWeight;
334 }
335
336 // Specify if grid should be dashed, dotted or solid
337 function SetLineStyle($aType) {
338 $this->type = $aType;
339 }
340
341 // Decide if both major and minor grid should be displayed
342 function Show($aShowMajor=true) {
343 $this->show=$aShowMajor;
344 }
345
346//----------------
347// PRIVATE METHODS
348 function Stroke($img,$grid) {
349 if( !$this->show ) return;
350 $nbrticks = count($grid[0])/2;
351 $nbrpnts = count($grid);
352 $img->SetColor($this->grid_color);
353 $img->SetLineWeight($this->weight);
354 for($i=0; $i<$nbrticks; ++$i) {
355 for($j=0; $j<$nbrpnts; ++$j) {
356 $pnts[$j*2]=$grid[$j][$i*2];
357 $pnts[$j*2+1]=$grid[$j][$i*2+1];
358 }
359 for($k=0; $k<$nbrpnts; ++$k ){
360 $l=($k+1)%$nbrpnts;
361 if( $this->type == "solid" )
362 $img->Line($pnts[$k*2],$pnts[$k*2+1],$pnts[$l*2],$pnts[$l*2+1]);
363 elseif( $this->type == "dotted" )
364 $img->DashedLine($pnts[$k*2],$pnts[$k*2+1],$pnts[$l*2],$pnts[$l*2+1],1,6);
365 elseif( $this->type == "dashed" )
366 $img->DashedLine($pnts[$k*2],$pnts[$k*2+1],$pnts[$l*2],$pnts[$l*2+1],2,4);
367 elseif( $this->type == "longdashed" )
368 $img->DashedLine($pnts[$k*2],$pnts[$k*2+1],$pnts[$l*2],$pnts[$l*2+1],8,6);
369 }
370 $pnts=array();
371 }
372 }
373} // Class
374
375
376//===================================================
377// CLASS RadarPlot
378// Description: Plot a radarplot
379//===================================================
380class RadarPlot {
381 public $mark=null;
382 public $legend="";
383 private $data=array();
384 private $fill=false, $fill_color=array(200,170,180);
385 private $color=array(0,0,0);
386 private $weight=1;
387 private $linestyle='solid';
388//---------------
389// CONSTRUCTOR
390 function RadarPlot($data) {
391 $this->data = $data;
392 $this->mark = new PlotMark();
393 }
394
395//---------------
396// PUBLIC METHODS
397 function Min() {
398 return Min($this->data);
399 }
400
401 function Max() {
402 return Max($this->data);
403 }
404
405 function SetLegend($legend) {
406 $this->legend=$legend;
407 }
408
409 function SetLineStyle($aStyle) {
410 $this->linestyle=$aStyle;
411 }
412
413 function SetLineWeight($w) {
414 $this->weight=$w;
415 }
416
417 function SetFillColor($aColor) {
418 $this->fill_color = $aColor;
419 $this->fill = true;
420 }
421
422 function SetFill($f=true) {
423 $this->fill = $f;
424 }
425
426 function SetColor($aColor,$aFillColor=false) {
427 $this->color = $aColor;
428 if( $aFillColor ) {
429 $this->SetFillColor($aFillColor);
430 $this->fill = true;
431 }
432 }
433
434 function GetCSIMareas() {
435 JpGraphError::RaiseL(18001);
436//("Client side image maps not supported for RadarPlots.");
437 }
438
439 function Stroke($img, $pos, $scale, $startangle) {
440 $nbrpnts = count($this->data);
441 $astep=2*M_PI/$nbrpnts;
442 $a=$startangle;
443
444 $nulls=0;
445 for($i=0; $i<$nbrpnts; ++$i) {
446 if(!is_null($this->data[$i])) {
447 // Rotate each non null point to the correct axis-angle
448 $cs=$scale->RelTranslate($this->data[$i]);
449 $x=round($cs*cos($a)+$scale->scale_abs[0]);
450 $y=round($pos-$cs*sin($a));
451 /*
452 // TODO: Update for proper LogScale
453 $c=log10($c);
454 $x=round(($c-$scale->scale[0])*$scale->scale_factor*cos($a)+$scale->scale_abs[0]);
455 $y=round($pos-($c-$scale->scale[0])*$scale->scale_factor*sin($a));
456 */
457 $pnts[($i-$nulls)*2]=$x;
458 $pnts[($i-$nulls)*2+1]=$y;
459 }
460 else {
461 ++$nulls;
462 }
463 $a += $astep;
464 }
465
466 if( $this->fill ) {
467 $img->SetColor($this->fill_color);
468 $img->FilledPolygon($pnts);
469 }
470 $img->SetLineWeight($this->weight);
471 $img->SetColor($this->color);
472 $img->SetLineStyle($this->linestyle);
473 $pnts[]=$pnts[0];
474 $pnts[]=$pnts[1];
475 $img->Polygon($pnts);
476 $img->SetLineStyle('solid'); // Reset line style to default
477
478 // Add plotmarks on top
479 if( $this->mark->show ) {
480 for($i=0; $i < $nbrpnts; ++$i) {
481 $this->mark->Stroke($img,$pnts[$i*2],$pnts[$i*2+1]);
482 }
483 }
484
485 }
486
487//---------------
488// PRIVATE METHODS
489 function GetCount() {
490 return count($this->data);
491 }
492
493 function Legend($graph) {
494 if( $this->legend=="" ) return;
495 if( $this->fill )
496 $graph->legend->Add($this->legend,$this->fill_color,$this->mark);
497 else
498 $graph->legend->Add($this->legend,$this->color,$this->mark);
499 }
500
501} // Class
502
503//===================================================
504// CLASS RadarGraph
505// Description: Main container for a radar graph
506//===================================================
507class RadarGraph extends Graph {
508 public $grid,$axis=null;
509 private $posx,$posy;
510 private $len;
511 private $axis_title=null;
512//---------------
513// CONSTRUCTOR
514 function RadarGraph($width=300,$height=200,$cachedName="",$timeout=0,$inline=1) {
515 $this->Graph($width,$height,$cachedName,$timeout,$inline);
516 $this->posx=$width/2;
517 $this->posy=$height/2;
518 $this->len=min($width,$height)*0.35;
519 $this->SetColor(array(255,255,255));
520 $this->SetTickDensity(TICKD_NORMAL);
521 $this->SetScale("lin");
522 $this->SetGridDepth(DEPTH_FRONT);
523
524 }
525
526//---------------
527// PUBLIC METHODS
528 function SupressTickMarks($f=true) {
529 if( ERR_DEPRECATED )
530 JpGraphError::RaiseL(18002);
531//('RadarGraph::SupressTickMarks() is deprecated. Use HideTickMarks() instead.');
532 $this->axis->scale->ticks->SupressTickMarks($f);
533 }
534
535 function HideTickMarks($aFlag=true) {
536 $this->axis->scale->ticks->SupressTickMarks($aFlag);
537 }
538
539 function ShowMinorTickmarks($aFlag=true) {
540 $this->yscale->ticks->SupressMinorTickMarks(!$aFlag);
541 }
542
543 function SetScale($axtype,$ymin=1,$ymax=1,$dummy1=null,$dumy2=null) {
544 if( $axtype != "lin" && $axtype != "log" ) {
545 JpGraphError::RaiseL(18003,$axtype);
546//("Illegal scale for radarplot ($axtype). Must be \"lin\" or \"log\"");
547 }
548 if( $axtype=="lin" ) {
549 $this->yscale = new LinearScale($ymin,$ymax);
550 $this->yscale->ticks = new RadarLinearTicks();
551 $this->yscale->ticks->SupressMinorTickMarks();
552 }
553 elseif( $axtype=="log" ) {
554 $this->yscale = new LogScale($ymin,$ymax);
555 $this->yscale->ticks = new RadarLogTicks();
556 }
557
558 $this->axis = new RadarAxis($this->img,$this->yscale);
559 $this->grid = new RadarGrid();
560 }
561
562 function SetSize($aSize) {
563 if( $aSize < 0.1 || $aSize>1 )
564 JpGraphError::RaiseL(18004,$aSize);
565//("Radar Plot size must be between 0.1 and 1. (Your value=$s)");
566 $this->len=min($this->img->width,$this->img->height)*$aSize/2;
567 }
568
569 function SetPlotSize($aSize) {
570 $this->SetSize($aSize);
571 }
572
573 function SetTickDensity($densy=TICKD_NORMAL,$dummy1=null) {
574 $this->ytick_factor=25;
575 switch( $densy ) {
576 case TICKD_DENSE:
577 $this->ytick_factor=12;
578 break;
579 case TICKD_NORMAL:
580 $this->ytick_factor=25;
581 break;
582 case TICKD_SPARSE:
583 $this->ytick_factor=40;
584 break;
585 case TICKD_VERYSPARSE:
586 $this->ytick_factor=70;
587 break;
588 default:
589 JpGraphError::RaiseL(18005,$densy);
590//("RadarPlot Unsupported Tick density: $densy");
591 }
592 }
593
594 function SetPos($px,$py=0.5) {
595 $this->SetCenter($px,$py);
596 }
597
598 function SetCenter($px,$py=0.5) {
599 assert($px > 0 && $py > 0 );
600 $this->posx=$this->img->width*$px;
601 $this->posy=$this->img->height*$py;
602 }
603
604 function SetColor($c) {
605 $this->SetMarginColor($c);
606 }
607
608 function SetTitles($title) {
609 $this->axis_title = $title;
610 }
611
612 function Add($splot) {
613 $this->plots[]=$splot;
614 }
615
616 function GetPlotsYMinMax($aPlots) {
617 $min=$aPlots[0]->Min();
618 $max=$aPlots[0]->Max();
619 foreach( $this->plots as $p ) {
620 $max=max($max,$p->Max());
621 $min=min($min,$p->Min());
622 }
623 if( $min < 0 )
624 JpGraphError::RaiseL(18006,$min);
625//("Minimum data $min (Radar plots should only be used when all data points > 0)");
626 return array($min,$max);
627 }
628
629 // Stroke the Radar graph
630 function Stroke($aStrokeFileName="") {
631 $n = count($this->plots);
632 // Set Y-scale
633 if( !$this->yscale->IsSpecified() && count($this->plots)>0 ) {
634 list($min,$max) = $this->GetPlotsYMinMax($this->plots);
635 $this->yscale->AutoScale($this->img,0,$max,$this->len/$this->ytick_factor);
636 }
637 elseif( $this->yscale->IsSpecified() &&
638 ( $this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified()) ) {
639 // The tick calculation will use the user suplied min/max values to determine
640 // the ticks. If auto_ticks is false the exact user specifed min and max
641 // values will be used for the scale.
642 // If auto_ticks is true then the scale might be slightly adjusted
643 // so that the min and max values falls on an even major step.
644 $min = $this->yscale->scale[0];
645 $max = $this->yscale->scale[1];
646 $this->yscale->AutoScale($this->img,$min,$max,
647 $this->len/$this->ytick_factor,
648 $this->yscale->auto_ticks);
649 }
650
651 // Set start position end length of scale (in absolute pixels)
652 $this->yscale->SetConstants($this->posx,$this->len);
653
654 // We need as many axis as there are data points
655 $nbrpnts=$this->plots[0]->GetCount();
656
657 // If we have no titles just number the axis 1,2,3,...
658 if( $this->axis_title==null ) {
659 for($i=0; $i < $nbrpnts; ++$i )
660 $this->axis_title[$i] = $i+1;
661 }
662 elseif(count($this->axis_title)<$nbrpnts)
663 JpGraphError::RaiseL(18007);
664//("Number of titles does not match number of points in plot.");
665 for($i=0; $i < $n; ++$i )
666 if( $nbrpnts != $this->plots[$i]->GetCount() )
667 JpGraphError::RaiseL(18008);
668//("Each radar plot must have the same number of data points.");
669
670 if( $this->background_image != "" ) {
671 $this->StrokeFrameBackground();
672 }
673 else {
674 $this->StrokeFrame();
675 }
676 $astep=2*M_PI/$nbrpnts;
677
678 // Prepare legends
679 for($i=0; $i < $n; ++$i)
680 $this->plots[$i]->Legend($this);
681 $this->legend->Stroke($this->img);
682 $this->footer->Stroke($this->img);
683
684 if( $this->grid_depth == DEPTH_BACK ) {
685 // Draw axis and grid
686 for( $i=0,$a=M_PI/2; $i < $nbrpnts; ++$i, $a += $astep ) {
687 $this->axis->Stroke($this->posy,$a,$grid[$i],$this->axis_title[$i],$i==0);
688 }
689 }
690
691 // Plot points
692 $a=M_PI/2;
693 for($i=0; $i < $n; ++$i )
694 $this->plots[$i]->Stroke($this->img, $this->posy, $this->yscale, $a);
695
696 if( $this->grid_depth != DEPTH_BACK ) {
697 // Draw axis and grid
698 for( $i=0,$a=M_PI/2; $i < $nbrpnts; ++$i, $a += $astep ) {
699 $this->axis->Stroke($this->posy,$a,$grid[$i],$this->axis_title[$i],$i==0);
700 }
701 }
702 $this->grid->Stroke($this->img,$grid);
703 $this->StrokeTitles();
704
705 // Stroke texts
706 if( $this->texts != null ) {
707 foreach( $this->texts as $t)
708 $t->Stroke($this->img);
709 }
710
711 // Should we do any final image transformation
712 if( $this->iImgTrans ) {
713 if( !class_exists('ImgTrans',false) ) {
714 require_once('jpgraph_imgtrans.php');
715 }
716
717 $tform = new ImgTrans($this->img->img);
718 $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist,
719 $this->iImgTransDirection,$this->iImgTransHighQ,
720 $this->iImgTransMinSize,$this->iImgTransFillColor,
721 $this->iImgTransBorder);
722 }
723
724 // If the filename is given as the special "__handle"
725 // then the image handler is returned and the image is NOT
726 // streamed back
727 if( $aStrokeFileName == _IMG_HANDLER ) {
728 return $this->img->img;
729 }
730 else {
731 // Finally stream the generated picture
732 $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,
733 $aStrokeFileName);
734 }
735 }
736} // Class
737
738/* EOF */
739?>
Note: See TracBrowser for help on using the repository browser.