Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
<?php
2
/*=======================================================================
3
// File: 	JPGRAPH_POLAR.PHP
4
// Description:	Polar plot extension for JpGraph
5
// Created: 	2003-02-02
6
// Ver:		$Id: jpgraph_polar.php 781 2006-10-08 08:07:47Z ljp $
7
//
8
// Copyright (c) Aditus Consulting. All rights reserved.
9
//========================================================================
10
*/
11
 
12
require_once ('jpgraph_plotmark.inc.php');
13
 
14
 
15
require_once "jpgraph_log.php";
16
 
17
 
18
DEFINE('POLAR_360',1);
19
DEFINE('POLAR_180',2);
20
 
21
//
22
// Note. Don't attempt to make sense of this code.
23
// In order not to have to be able to inherit the scaling code
24
// from the main graph package we have had to make some "tricks" since
25
// the original scaling and axis was not designed to do what is
26
// required here.
27
// There were two option. 1: Re-implement everything and get a clean design
28
// and 2: do some "small" trickery and be able to inherit most of
29
// the functionlity from the main graph package.
30
// We choose 2: here in order to save some time.
31
//
32
 
33
//--------------------------------------------------------------------------
34
// class PolarPlot
35
//--------------------------------------------------------------------------
36
class PolarPlot {
37
    public $line_style='solid',$mark;
38
    public $legendcsimtarget='';
39
    public $legendcsimalt='';
40
    public $legend="";
41
    public $csimtargets=array();	// Array of targets for CSIM
42
    public $csimareas="";			// Resultant CSIM area tags
43
    public $csimalts=null;			// ALT:s for corresponding target
44
    public $scale=null;
45
    private $numpoints=0;
46
    private $iColor='navy',$iFillColor='';
47
    private $iLineWeight=1;
48
    private $coord=null;
49
 
50
    function PolarPlot($aData) {
51
	$n = count($aData);
52
	if( $n & 1 ) {
53
	    JpGraphError::RaiseL(17001);
54
//('Polar plots must have an even number of data point. Each data point is a tuple (angle,radius).');
55
	}
56
	$this->numpoints = $n/2;
57
	$this->coord = $aData;
58
	$this->mark = new PlotMark();
59
    }
60
 
61
    function SetWeight($aWeight) {
62
	$this->iLineWeight = $aWeight;
63
    }
64
 
65
    function SetColor($aColor){
66
	$this->iColor = $aColor;
67
    }
68
 
69
    function SetFillColor($aColor){
70
	$this->iFillColor = $aColor;
71
    }
72
 
73
    function Max() {
74
	$m = $this->coord[1];
75
	$i=1;
76
	while( $i < $this->numpoints ) {
77
	    $m = max($m,$this->coord[2*$i+1]);
78
	    ++$i;
79
	}
80
	return $m;
81
    }
82
    // Set href targets for CSIM
83
    function SetCSIMTargets($aTargets,$aAlts=null) {
84
	$this->csimtargets=$aTargets;
85
	$this->csimalts=$aAlts;
86
    }
87
 
88
    // Get all created areas
89
    function GetCSIMareas() {
90
	return $this->csimareas;
91
    }
92
 
93
    function SetLegend($aLegend,$aCSIM="",$aCSIMAlt="") {
94
	$this->legend = $aLegend;
95
	$this->legendcsimtarget = $aCSIM;
96
	$this->legendcsimalt = $aCSIMAlt;
97
    }
98
 
99
    // Private methods
100
 
101
    function Legend($aGraph) {
102
	$color = $this->iColor ;
103
	if( $this->legend != "" ) {
104
	    if( $this->iFillColor!='' ) {
105
		$color = $this->iFillColor;
106
		$aGraph->legend->Add($this->legend,$color,$this->mark,0,
107
				     $this->legendcsimtarget,$this->legendcsimalt);
108
	    }
109
	    else {
110
		$aGraph->legend->Add($this->legend,$color,$this->mark,$this->line_style,
111
				     $this->legendcsimtarget,$this->legendcsimalt);
112
	    }
113
	}
114
    }
115
 
116
    function Stroke($img,$scale) {
117
 
118
	$i=0;
119
	$p=array();
120
	$this->csimareas='';
121
	while($i < $this->numpoints) {
122
	    list($x1,$y1) = $scale->PTranslate($this->coord[2*$i],$this->coord[2*$i+1]);
123
	    $p[2*$i] = $x1;
124
	    $p[2*$i+1] = $y1;
125
 
126
	    if( isset($this->csimtargets[$i]) ) {
127
	        $this->mark->SetCSIMTarget($this->csimtargets[$i]);
128
	        $this->mark->SetCSIMAlt($this->csimalts[$i]);
129
		$this->mark->SetCSIMAltVal($this->coord[2*$i], $this->coord[2*$i+1]);
130
		$this->mark->Stroke($img,$x1,$y1);
131
		$this->csimareas .= $this->mark->GetCSIMAreas();
132
	    }
133
	    else
134
		$this->mark->Stroke($img,$x1,$y1);
135
 
136
	    ++$i;
137
	}
138
 
139
	if( $this->iFillColor != '' ) {
140
	    $img->SetColor($this->iFillColor);
141
	    $img->FilledPolygon($p);
142
	}
143
	$img->SetLineWeight($this->iLineWeight);
144
	$img->SetColor($this->iColor);
145
	$img->Polygon($p,$this->iFillColor!='');
146
    }
147
}
148
 
149
//--------------------------------------------------------------------------
150
// class PolarAxis
151
//--------------------------------------------------------------------------
152
class PolarAxis extends Axis {
153
    private $angle_step=15,$angle_color='lightgray',$angle_label_color='black';
154
    private $angle_fontfam=FF_FONT1,$angle_fontstyle=FS_NORMAL,$angle_fontsize=10;
155
    private $angle_fontcolor = 'navy';
156
    private $gridminor_color='lightgray',$gridmajor_color='lightgray';
157
    private $show_minor_grid = false, $show_major_grid = true ;
158
    private $show_angle_mark=true, $show_angle_grid=true, $show_angle_label=true;
159
    private $angle_tick_len=3, $angle_tick_len2=3, $angle_tick_color='black';
160
    private $show_angle_tick=true;
161
    private $radius_tick_color='black';
162
 
163
    function PolarAxis($img,$aScale) {
164
	parent::Axis($img,$aScale);
165
    }
166
 
167
    function ShowAngleDegreeMark($aFlg=true) {
168
	$this->show_angle_mark = $aFlg;
169
    }
170
 
171
    function SetAngleStep($aStep) {
172
	$this->angle_step=$aStep;
173
    }
174
 
175
    function HideTicks($aFlg=true,$aAngleFlg=true) {
176
	parent::HideTicks($aFlg,$aFlg);
177
	$this->show_angle_tick = !$aAngleFlg;
178
    }
179
 
180
    function ShowAngleLabel($aFlg=true) {
181
	$this->show_angle_label = $aFlg;
182
    }
183
 
184
    function ShowGrid($aMajor=true,$aMinor=false,$aAngle=true) {
185
	$this->show_minor_grid = $aMinor;
186
	$this->show_major_grid = $aMajor;
187
	$this->show_angle_grid = $aAngle ;
188
    }
189
 
190
    function SetAngleFont($aFontFam,$aFontStyle=FS_NORMAL,$aFontSize=10) {
191
	$this->angle_fontfam = $aFontFam;
192
	$this->angle_fontstyle = $aFontStyle;
193
	$this->angle_fontsize = $aFontSize;
194
    }
195
 
196
    function SetColor($aColor,$aRadColor='',$aAngleColor='') {
197
	if( $aAngleColor == '' )
198
	    $aAngleColor=$aColor;
199
	parent::SetColor($aColor,$aRadColor);
200
	$this->angle_fontcolor = $aAngleColor;
201
    }
202
 
203
    function SetGridColor($aMajorColor,$aMinorColor='',$aAngleColor='') {
204
	if( $aMinorColor == '' )
205
	    $aMinorColor = $aMajorColor;
206
	if( $aAngleColor == '' )
207
	    $aAngleColor = $aMajorColor;
208
 
209
	$this->gridminor_color = $aMinorColor;
210
	$this->gridmajor_color = $aMajorColor;
211
	$this->angle_color = $aAngleColor;
212
    }
213
 
214
    function SetTickColors($aRadColor,$aAngleColor='') {
215
	$this->radius_tick_color = $aRadColor;
216
	$this->angle_tick_color = $aAngleColor;
217
    }
218
 
219
    // Private methods
220
    function StrokeGrid($pos) {
221
	$x = round($this->img->left_margin + $this->img->plotwidth/2);
222
	$this->scale->ticks->Stroke($this->img,$this->scale,$pos);
223
 
224
	// Stroke the minor arcs
225
	$pmin = array();
226
	$p = $this->scale->ticks->ticks_pos;
227
	$n = count($p);
228
	$i = 0;
229
	$this->img->SetColor($this->gridminor_color);
230
	while( $i < $n ) {
231
	    $r = $p[$i]-$x+1;
232
	    $pmin[]=$r;
233
	    if( $this->show_minor_grid ) {
234
		$this->img->Circle($x,$pos,$r);
235
	    }
236
	    $i++;
237
	}
238
 
239
	$limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
240
	while( $r < $limit ) {
241
	    $off = $r;
242
	    $i=1;
243
	    $r = $off + round($p[$i]-$x+1);
244
	    while( $r < $limit && $i < $n ) {
245
		$r = $off+$p[$i]-$x;
246
		$pmin[]=$r;
247
		if( $this->show_minor_grid ) {
248
		    $this->img->Circle($x,$pos,$r);
249
		}
250
		$i++;
251
	    }
252
	}
253
 
254
	// Stroke the major arcs
255
	if( $this->show_major_grid ) {
256
	    // First determine how many minor step on
257
	    // every major step. We have recorded the minor radius
258
	    // in pmin and use these values. This is done in order
259
	    // to avoid rounding errors if we were to recalculate the
260
	    // different major radius.
261
	    $pmaj = $this->scale->ticks->maj_ticks_pos;
262
	    $p = $this->scale->ticks->ticks_pos;
263
	    if( $this->scale->name == 'lin' ) {
264
		$step=round(($pmaj[1] - $pmaj[0])/($p[1] - $p[0]));
265
	    }
266
	    else {
267
		$step=9;
268
	    }
269
	    $n = round(count($pmin)/$step);
270
	    $i = 0;
271
	    $this->img->SetColor($this->gridmajor_color);
272
	    $limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
273
	    $off = $r;
274
	    $i=0;
275
	    $r = $pmin[$i*$step];
276
	    while( $r < $limit && $i < $n ) {
277
		$r = $pmin[$i*$step];
278
		$this->img->Circle($x,$pos,$r);
279
		$i++;
280
	    }
281
	}
282
 
283
	// Draw angles
284
	if( $this->show_angle_grid ) {
285
	    $this->img->SetColor($this->angle_color);
286
	    $d = max($this->img->plotheight,$this->img->plotwidth)*1.4 ;
287
	    $a = 0;
288
	    $p = $this->scale->ticks->ticks_pos;
289
	    $start_radius = $p[1]-$x;
290
	    while( $a < 360 ) {
291
		if( $a == 90 || $a == 270 ) {
292
		    // Make sure there are no rounding problem with
293
		    // exactly vertical lines
294
		    $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
295
				     $pos-$start_radius*sin($a/180*M_PI),
296
				     $x+$start_radius*cos($a/180*M_PI)+1,
297
				     $pos-$d*sin($a/180*M_PI));
298
 
299
		}
300
		else {
301
		    $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
302
				     $pos-$start_radius*sin($a/180*M_PI),
303
				     $x+$d*cos($a/180*M_PI),
304
				     $pos-$d*sin($a/180*M_PI));
305
		}
306
		$a += $this->angle_step;
307
	    }
308
	}
309
    }
310
 
311
    function StrokeAngleLabels($pos,$type) {
312
 
313
	if( !$this->show_angle_label )
314
	    return;
315
 
316
	$x0 = round($this->img->left_margin+$this->img->plotwidth/2)+1;
317
 
318
	$d = max($this->img->plotwidth,$this->img->plotheight)*1.42;
319
	$a = $this->angle_step;
320
	$t = new Text();
321
	$t->SetColor($this->angle_fontcolor);
322
	$t->SetFont($this->angle_fontfam,$this->angle_fontstyle,$this->angle_fontsize);
323
	$xright = $this->img->width - $this->img->right_margin;
324
	$ytop = $this->img->top_margin;
325
	$xleft = $this->img->left_margin;
326
	$ybottom = $this->img->height - $this->img->bottom_margin;
327
	$ha = 'left';
328
	$va = 'center';
329
	$w = $this->img->plotwidth/2;
330
	$h = $this->img->plotheight/2;
331
	$xt = $x0; $yt = $pos;
332
	$margin=5;
333
 
334
	$tl  = $this->angle_tick_len ; // Outer len
335
	$tl2 = $this->angle_tick_len2 ; // Interior len
336
 
337
	$this->img->SetColor($this->angle_tick_color);
338
	$rot90 = $this->img->a == 90 ;
339
 
340
	if( $type == POLAR_360 ) {
341
	    $ca1 = atan($h/$w)/M_PI*180;
342
	    $ca2 = 180-$ca1;
343
	    $ca3 = $ca1+180;
344
	    $ca4 = 360-$ca1;
345
	    $end = 360;
346
	    while( $a < $end ) {
347
		$ca = cos($a/180*M_PI);
348
		$sa = sin($a/180*M_PI);
349
		$x = $d*$ca;
350
		$y = $d*$sa;
351
		$xt=1000;$yt=1000;
352
		if( $a <= $ca1 || $a >= $ca4 ) {
353
		    $yt = $pos - $w * $y/$x;
354
		    $xt = $xright + $margin;
355
 		    if( $rot90 ) {
356
			$ha = 'center';
357
			$va = 'top';
358
		    }
359
		    else {
360
			$ha = 'left';
361
			$va = 'center';
362
		    }
363
		    $x1=$xright-$tl2; $x2=$xright+$tl;
364
		    $y1=$y2=$yt;
365
		}
366
		elseif( $a > $ca1 && $a < $ca2 ) {
367
		    $xt = $x0 + $h * $x/$y;
368
		    $yt = $ytop - $margin;
369
 		    if( $rot90 ) {
370
			$ha = 'left';
371
			$va = 'center';
372
		    }
373
		    else {
374
			$ha = 'center';
375
			$va = 'bottom';
376
		    }
377
		    $y1=$ytop+$tl2;$y2=$ytop-$tl;
378
		    $x1=$x2=$xt;
379
		}
380
		elseif( $a >= $ca2 && $a <= $ca3 ) {
381
		    $yt = $pos + $w * $y/$x;
382
		    $xt = $xleft - $margin;
383
 		    if( $rot90 ) {
384
			$ha = 'center';
385
			$va = 'bottom';
386
		    }
387
		    else {
388
			$ha = 'right';
389
			$va = 'center';
390
		    }
391
		    $x1=$xleft+$tl2;$x2=$xleft-$tl;
392
		    $y1=$y2=$yt;
393
		}
394
		else {
395
		    $xt = $x0 - $h * $x/$y;
396
		    $yt = $ybottom + $margin;
397
 		    if( $rot90 ) {
398
			$ha = 'right';
399
			$va = 'center';
400
		    }
401
		    else {
402
			$ha = 'center';
403
			$va = 'top';
404
		    }
405
		    $y1=$ybottom-$tl2;$y2=$ybottom+$tl;
406
		    $x1=$x2=$xt;
407
		}
408
		if( $a != 0 && $a != 180 ) {
409
		    $t->Align($ha,$va);
410
		    if( $this->show_angle_mark )
411
			$a .= '°';
412
		    $t->Set($a);
413
		    $t->Stroke($this->img,$xt,$yt);
414
		    if( $this->show_angle_tick )
415
			$this->img->Line($x1,$y1,$x2,$y2);
416
		}
417
		$a += $this->angle_step;
418
	    }
419
	}
420
	else {
421
	    // POLAR_HALF
422
	    $ca1 = atan($h/$w*2)/M_PI*180;
423
	    $ca2 = 180-$ca1;
424
	    $end = 180;
425
	    while( $a < $end ) {
426
		$ca = cos($a/180*M_PI);
427
		$sa = sin($a/180*M_PI);
428
		$x = $d*$ca;
429
		$y = $d*$sa;
430
		if( $a <= $ca1 ) {
431
		    $yt = $pos - $w * $y/$x;
432
		    $xt = $xright + $margin;
433
 		    if( $rot90 ) {
434
			$ha = 'center';
435
			$va = 'top';
436
		    }
437
		    else {
438
			$ha = 'left';
439
			$va = 'center';
440
		    }
441
		    $x1=$xright-$tl2; $x2=$xright+$tl;
442
		    $y1=$y2=$yt;
443
		}
444
		elseif( $a > $ca1 && $a < $ca2 ) {
445
		    $xt = $x0 + 2*$h * $x/$y;
446
		    $yt = $ytop - $margin;
447
 		    if( $rot90 ) {
448
			$ha = 'left';
449
			$va = 'center';
450
		    }
451
		    else {
452
			$ha = 'center';
453
			$va = 'bottom';
454
		    }
455
		    $y1=$ytop+$tl2;$y2=$ytop-$tl;
456
		    $x1=$x2=$xt;
457
		}
458
		elseif( $a >= $ca2 ) {
459
		    $yt = $pos + $w * $y/$x;
460
		    $xt = $xleft - $margin;
461
 		    if( $rot90 ) {
462
			$ha = 'center';
463
			$va = 'bottom';
464
		    }
465
		    else {
466
			$ha = 'right';
467
			$va = 'center';
468
		    }
469
		    $x1=$xleft+$tl2;$x2=$xleft-$tl;
470
		    $y1=$y2=$yt;
471
		}
472
		$t->Align($ha,$va);
473
		if( $this->show_angle_mark )
474
		    $a .= '°';
475
		$t->Set($a);
476
		$t->Stroke($this->img,$xt,$yt);
477
		if( $this->show_angle_tick )
478
		    $this->img->Line($x1,$y1,$x2,$y2);
479
		$a += $this->angle_step;
480
	    }
481
	}
482
    }
483
 
484
    function Stroke($pos,$dummy=true) {
485
 
486
	$this->img->SetLineWeight($this->weight);
487
	$this->img->SetColor($this->color);
488
	$this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
489
	if( !$this->hide_line )
490
	    $this->img->FilledRectangle($this->img->left_margin,$pos,
491
		     $this->img->width-$this->img->right_margin,$pos+$this->weight-1);
492
	$y=$pos+$this->img->GetFontHeight()+$this->title_margin+$this->title->margin;
493
	if( $this->title_adjust=="high" )
494
	    $this->title->SetPos($this->img->width-$this->img->right_margin,$y,"right","top");
495
	elseif( $this->title_adjust=="middle" || $this->title_adjust=="center" )
496
	    $this->title->SetPos(($this->img->width-$this->img->left_margin-
497
			       $this->img->right_margin)/2+$this->img->left_margin,
498
			      $y,"center","top");
499
	elseif($this->title_adjust=="low")
500
	    $this->title->SetPos($this->img->left_margin,$y,"left","top");
501
	else {
502
	    JpGraphError::RaiseL(17002,$this->title_adjust);
503
//('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')');
504
	}
505
 
506
 
507
	if (!$this->hide_labels) {
508
	    $this->StrokeLabels($pos,false);
509
	}
510
	$this->img->SetColor($this->radius_tick_color);
511
	$this->scale->ticks->Stroke($this->img,$this->scale,$pos);
512
 
513
	//
514
	// Mirror the positions for the left side of the scale
515
        //
516
	$mid = 2*($this->img->left_margin+$this->img->plotwidth/2);
517
	$n = count($this->scale->ticks->ticks_pos);
518
	$i=0;
519
	while( $i < $n ) {
520
	    $this->scale->ticks->ticks_pos[$i] =
521
		$mid-$this->scale->ticks->ticks_pos[$i] ;
522
	    ++$i;
523
	}
524
 
525
	$n = count($this->scale->ticks->maj_ticks_pos);
526
	$i=0;
527
	while( $i < $n ) {
528
	    $this->scale->ticks->maj_ticks_pos[$i] =
529
		$mid-$this->scale->ticks->maj_ticks_pos[$i] ;
530
	    ++$i;
531
	}
532
 
533
	$n = count($this->scale->ticks->maj_ticklabels_pos);
534
	$i=1;
535
	while( $i < $n ) {
536
	    $this->scale->ticks->maj_ticklabels_pos[$i] =
537
		$mid-$this->scale->ticks->maj_ticklabels_pos[$i] ;
538
	    ++$i;
539
	}
540
 
541
	// Draw the left side of the scale
542
	$n = count($this->scale->ticks->ticks_pos);
543
	$yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMinTickAbsSize();
544
 
545
 
546
	// Minor ticks
547
	if( ! $this->scale->ticks->supress_minor_tickmarks ) {
548
	    $i=1;
549
	    while( $i < $n/2 ) {
550
		$x = round($this->scale->ticks->ticks_pos[$i]) ;
551
		$this->img->Line($x,$pos,$x,$yu);
552
		++$i;
553
	    }
554
	}
555
 
556
	$n = count($this->scale->ticks->maj_ticks_pos);
557
	$yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMajTickAbsSize();
558
 
559
 
560
	// Major ticks
561
	if( ! $this->scale->ticks->supress_tickmarks ) {
562
	    $i=1;
563
	    while( $i < $n/2 ) {
564
		$x = round($this->scale->ticks->maj_ticks_pos[$i]) ;
565
		$this->img->Line($x,$pos,$x,$yu);
566
		++$i;
567
	    }
568
	}
569
	if (!$this->hide_labels) {
570
	    $this->StrokeLabels($pos,false);
571
	}
572
	$this->title->Stroke($this->img);
573
    }
574
}
575
 
576
class PolarScale extends LinearScale {
577
    private $graph;
578
 
579
    function PolarScale($aMax=0,$graph) {
580
	parent::LinearScale(0,$aMax,'x');
581
	$this->graph = $graph;
582
    }
583
 
584
    function _Translate($v) {
585
	return parent::Translate($v);
586
    }
587
 
588
    function PTranslate($aAngle,$aRad) {
589
 
590
	$m = $this->scale[1];
591
	$w = $this->graph->img->plotwidth/2;
592
	$aRad = $aRad/$m*$w;
593
 
594
	$x = cos( $aAngle/180 * M_PI ) * $aRad;
595
	$y = sin( $aAngle/180 * M_PI ) * $aRad;
596
 
597
	$x += $this->_Translate(0);
598
 
599
	if( $this->graph->iType == POLAR_360 ) {
600
	    $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
601
	}
602
	else {
603
	    $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
604
	}
605
	return array($x,$y);
606
    }
607
}
608
 
609
class PolarLogScale extends LogScale {
610
    private $graph;
611
    function PolarLogScale($aMax=1,$graph) {
612
	parent::LogScale(0,$aMax,'x');
613
	$this->graph = $graph;
614
	$this->ticks->SetLabelLogType(LOGLABELS_MAGNITUDE);
615
 
616
    }
617
 
618
    function PTranslate($aAngle,$aRad) {
619
 
620
	if( $aRad == 0 )
621
	    $aRad = 1;
622
	$aRad = log10($aRad);
623
	$m = $this->scale[1];
624
	$w = $this->graph->img->plotwidth/2;
625
	$aRad = $aRad/$m*$w;
626
 
627
	$x = cos( $aAngle/180 * M_PI ) * $aRad;
628
	$y = sin( $aAngle/180 * M_PI ) * $aRad;
629
 
630
	$x += $w+$this->graph->img->left_margin;//$this->_Translate(0);
631
	if( $this->graph->iType == POLAR_360 ) {
632
	    $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
633
	}
634
	else {
635
	    $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
636
	}
637
	return array($x,$y);
638
    }
639
}
640
 
641
class PolarGraph extends Graph {
642
    public $scale;
643
    public $axis;
644
    public $iType=POLAR_360;
645
 
646
    function PolarGraph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {
647
	parent::Graph($aWidth,$aHeight,$aCachedName,$aTimeOut,$aInline) ;
648
	$this->SetDensity(TICKD_DENSE);
649
	$this->SetBox();
650
	$this->SetMarginColor('white');
651
    }
652
 
653
    function SetDensity($aDense) {
654
	$this->SetTickDensity(TICKD_NORMAL,$aDense);
655
    }
656
 
657
    function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) {
658
	$adj = ($this->img->height - $this->img->width)/2;
659
	$this->SetAngle(90);
660
	$this->img->SetMargin($lm-$adj,$rm-$adj,$tm+$adj,$bm+$adj);
661
	$this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2));
662
	$this->axis->SetLabelAlign('right','center');
663
	//JpGraphError::Raise('Set90AndMargin() is not supported for polar graphs.');
664
    }
665
 
666
    function SetScale($aScale,$rmax=0,$dummy1=1,$dummy2=1,$dummy3=1) {
667
	if( $aScale == 'lin' )
668
	    $this->scale = new PolarScale($rmax,$this);
669
	elseif( $aScale == 'log' ) {
670
	    $this->scale = new PolarLogScale($rmax,$this);
671
	}
672
	else {
673
	    JpGraphError::RaiseL(17004);//('Unknown scale type for polar graph. Must be "lin" or "log"');
674
	}
675
 
676
	$this->axis = new PolarAxis($this->img,$this->scale);
677
	$this->SetMargin(40,40,50,40);
678
    }
679
 
680
    function SetType($aType) {
681
	$this->iType = $aType;
682
    }
683
 
684
    function SetPlotSize($w,$h) {
685
	$this->SetMargin(($this->img->width-$w)/2,($this->img->width-$w)/2,
686
			 ($this->img->height-$h)/2,($this->img->height-$h)/2);
687
    }
688
 
689
    // Private methods
690
    function GetPlotsMax() {
691
	$n = count($this->plots);
692
	$m = $this->plots[0]->Max();
693
	$i=1;
694
	while($i < $n) {
695
	    $m = max($this->plots[$i]->Max(),$m);
696
	    ++$i;
697
	}
698
	return $m;
699
    }
700
 
701
    function Stroke($aStrokeFileName="") {
702
 
703
	// Start by adjusting the margin so that potential titles will fit.
704
	$this->AdjustMarginsForTitles();
705
 
706
	// If the filename is the predefined value = '_csim_special_'
707
	// we assume that the call to stroke only needs to do enough
708
	// to correctly generate the CSIM maps.
709
	// We use this variable to skip things we don't strictly need
710
	// to do to generate the image map to improve performance
711
	// a best we can. Therefor you will see a lot of tests !$_csim in the
712
	// code below.
713
	$_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);
714
 
715
	// We need to know if we have stroked the plot in the
716
	// GetCSIMareas. Otherwise the CSIM hasn't been generated
717
	// and in the case of GetCSIM called before stroke to generate
718
	// CSIM without storing an image to disk GetCSIM must call Stroke.
719
	$this->iHasStroked = true;
720
 
721
	//Check if we should autoscale axis
722
	if( !$this->scale->IsSpecified() && count($this->plots)>0 ) {
723
	    $max = $this->GetPlotsMax();
724
	    $t1 = $this->img->plotwidth;
725
	    $this->img->plotwidth /= 2;
726
	    $t2 = $this->img->left_margin;
727
	    $this->img->left_margin += $this->img->plotwidth+1;
728
	    $this->scale->AutoScale($this->img,0,$max,
729
				     $this->img->plotwidth/$this->xtick_factor/2);
730
	    $this->img->plotwidth = $t1;
731
	    $this->img->left_margin = $t2;
732
	}
733
	else {
734
	    // The tick calculation will use the user suplied min/max values to determine
735
	    // the ticks. If auto_ticks is false the exact user specifed min and max
736
	    // values will be used for the scale.
737
	    // If auto_ticks is true then the scale might be slightly adjusted
738
	    // so that the min and max values falls on an even major step.
739
	    //$min = 0;
740
	    $max = $this->scale->scale[1];
741
	    $t1 = $this->img->plotwidth;
742
	    $this->img->plotwidth /= 2;
743
	    $t2 = $this->img->left_margin;
744
	    $this->img->left_margin += $this->img->plotwidth+1;
745
	    $this->scale->AutoScale($this->img,0,$max,
746
				     $this->img->plotwidth/$this->xtick_factor/2);
747
	    $this->img->plotwidth = $t1;
748
	    $this->img->left_margin = $t2;
749
	}
750
 
751
	if( $this->iType ==  POLAR_180 )
752
	    $pos = $this->img->height - $this->img->bottom_margin;
753
	else
754
	    $pos = $this->img->plotheight/2 + $this->img->top_margin;
755
 
756
 
757
	if( !$_csim ) {
758
	    $this->StrokePlotArea();
759
	}
760
 
761
	$this->iDoClipping = true;
762
 
763
	if( $this->iDoClipping ) {
764
	    $oldimage = $this->img->CloneCanvasH();
765
	}
766
 
767
	if( !$_csim ) {
768
	    $this->axis->StrokeGrid($pos);
769
	}
770
 
771
	// Stroke all plots for Y1 axis
772
	for($i=0; $i < count($this->plots); ++$i) {
773
	    $this->plots[$i]->Stroke($this->img,$this->scale);
774
	}
775
 
776
 
777
	if( $this->iDoClipping ) {
778
	    // Clipping only supports graphs at 0 and 90 degrees
779
	    if( $this->img->a == 0  ) {
780
		$this->img->CopyCanvasH($oldimage,$this->img->img,
781
					$this->img->left_margin,$this->img->top_margin,
782
					$this->img->left_margin,$this->img->top_margin,
783
					$this->img->plotwidth+1,$this->img->plotheight+1);
784
	    }
785
	    elseif( $this->img->a == 90 ) {
786
		$adj = round(($this->img->height - $this->img->width)/2);
787
		$this->img->CopyCanvasH($oldimage,$this->img->img,
788
					$this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
789
					$this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
790
					$this->img->plotheight,$this->img->plotwidth);
791
	    }
792
	    $this->img->Destroy();
793
	    $this->img->SetCanvasH($oldimage);
794
	}
795
 
796
	if( !$_csim ) {
797
	    $this->axis->Stroke($pos);
798
	    $this->axis->StrokeAngleLabels($pos,$this->iType);
799
	}
800
 
801
	if( !$_csim ) {
802
	    $this->StrokePlotBox();
803
	    $this->footer->Stroke($this->img);
804
 
805
	    // The titles and legends never gets rotated so make sure
806
	    // that the angle is 0 before stroking them
807
	    $aa = $this->img->SetAngle(0);
808
	    $this->StrokeTitles();
809
	}
810
 
811
	for($i=0; $i < count($this->plots) ; ++$i ) {
812
	    $this->plots[$i]->Legend($this);
813
	}
814
 
815
	$this->legend->Stroke($this->img);
816
 
817
	if( !$_csim ) {
818
 
819
	    $this->StrokeTexts();
820
	    $this->img->SetAngle($aa);
821
 
822
	    // Draw an outline around the image map
823
	    if(_JPG_DEBUG)
824
		$this->DisplayClientSideaImageMapAreas();
825
 
826
	    // Adjust the appearance of the image
827
	    $this->AdjustSaturationBrightnessContrast();
828
 
829
	    // If the filename is given as the special "__handle"
830
	    // then the image handler is returned and the image is NOT
831
	    // streamed back
832
	    if( $aStrokeFileName == _IMG_HANDLER ) {
833
		return $this->img->img;
834
	    }
835
	    else {
836
		// Finally stream the generated picture
837
		$this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,
838
					   $aStrokeFileName);
839
	    }
840
	}
841
    }
842
}
843
 
844
 
845
 
846
?>