Ignore:
Timestamp:
Apr 13, 2019, 8:05:15 PM (5 years ago)
Author:
roby
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/modules/Elezioni/grafici/jpgraph_polar.php

    r2 r265  
    11<?php
    22/*=======================================================================
    3 // File:        JPGRAPH_POLAR.PHP
    4 // Description: Polar plot extension for JpGraph
    5 // Created:     2003-02-02
    6 // Ver:         $Id: jpgraph_polar.php 1091 2009-01-18 22:57:40Z ljp $
    7 //
    8 // Copyright (c) Aditus Consulting. All rights reserved.
    9 //========================================================================
    10 */
     3 // File:        JPGRAPH_POLAR.PHP
     4 // Description: Polar plot extension for JpGraph
     5 // Created:     2003-02-02
     6 // Ver:         $Id: jpgraph_polar.php 1796 2009-09-07 09:37:19Z ljp $
     7 //
     8 // Copyright (c) Asial Corporation. All rights reserved.
     9 //========================================================================
     10 */
    1111
    1212require_once ('jpgraph_plotmark.inc.php');
     
    2525// There were two option. 1: Re-implement everything and get a clean design
    2626// and 2: do some "small" trickery and be able to inherit most of
    27 // the functionlity from the main graph package. 
     27// the functionlity from the main graph package.
    2828// We choose 2: here in order to save some time.
    29 // 
     29//
    3030
    3131//--------------------------------------------------------------------------
     
    3737    public $legendcsimalt='';
    3838    public $legend="";
    39     public $csimtargets=array();        // Array of targets for CSIM
    40     public $csimareas="";                       // Resultant CSIM area tags     
    41     public $csimalts=null;                      // ALT:s for corresponding target
     39    public $csimtargets=array(); // Array of targets for CSIM
     40    public $csimareas="";   // Resultant CSIM area tags
     41    public $csimalts=null;   // ALT:s for corresponding target
    4242    public $scale=null;
    4343    private $numpoints=0;
     
    4646    private $coord=null;
    4747
    48     function PolarPlot($aData) {
    49         $n = count($aData);
    50         if( $n & 1 ) {
    51             JpGraphError::RaiseL(17001);
    52 //('Polar plots must have an even number of data point. Each data point is a tuple (angle,radius).');
    53         }
    54         $this->numpoints = $n/2;
    55         $this->coord = $aData;
    56         $this->mark = new PlotMark();
     48    function __construct($aData) {
     49        $n = count($aData);
     50        if( $n & 1 ) {
     51            JpGraphError::RaiseL(17001);
     52            //('Polar plots must have an even number of data point. Each data point is a tuple (angle,radius).');
     53        }
     54        $this->numpoints = $n/2;
     55        $this->coord = $aData;
     56        $this->mark = new PlotMark();
    5757    }
    5858
    5959    function SetWeight($aWeight) {
    60         $this->iLineWeight = $aWeight;
     60        $this->iLineWeight = $aWeight;
    6161    }
    6262
    6363    function SetColor($aColor){
    64         $this->iColor = $aColor;
     64        $this->iColor = $aColor;
    6565    }
    6666
    6767    function SetFillColor($aColor){
    68         $this->iFillColor = $aColor;
     68        $this->iFillColor = $aColor;
    6969    }
    7070
    7171    function Max() {
    72         $m = $this->coord[1];
    73         $i=1;
    74         while( $i < $this->numpoints ) {
    75             $m = max($m,$this->coord[2*$i+1]); 
    76             ++$i;
    77         }
    78         return $m;
    79     }
    80     // Set href targets for CSIM       
     72        $m = $this->coord[1];
     73        $i=1;
     74        while( $i < $this->numpoints ) {
     75            $m = max($m,$this->coord[2*$i+1]);
     76            ++$i;
     77        }
     78        return $m;
     79    }
     80    // Set href targets for CSIM
    8181    function SetCSIMTargets($aTargets,$aAlts=null) {
    82         $this->csimtargets=$aTargets;
    83         $this->csimalts=$aAlts;         
    84     }
    85        
     82        $this->csimtargets=$aTargets;
     83        $this->csimalts=$aAlts;
     84    }
     85
    8686    // Get all created areas
    8787    function GetCSIMareas() {
    88         return $this->csimareas;
    89     }   
    90        
     88        return $this->csimareas;
     89    }
     90
    9191    function SetLegend($aLegend,$aCSIM="",$aCSIMAlt="") {
    92         $this->legend = $aLegend;
    93         $this->legendcsimtarget = $aCSIM;
    94         $this->legendcsimalt = $aCSIMAlt;
     92        $this->legend = $aLegend;
     93        $this->legendcsimtarget = $aCSIM;
     94        $this->legendcsimalt = $aCSIMAlt;
    9595    }
    9696
     
    9898
    9999    function Legend($aGraph) {
    100         $color = $this->iColor ;
    101         if( $this->legend != "" ) {
    102             if( $this->iFillColor!='' ) {
    103                 $color = $this->iFillColor;
    104                 $aGraph->legend->Add($this->legend,$color,$this->mark,0,
    105                                      $this->legendcsimtarget,$this->legendcsimalt);   
    106             }
    107             else {
    108                 $aGraph->legend->Add($this->legend,$color,$this->mark,$this->line_style,
    109                                      $this->legendcsimtarget,$this->legendcsimalt);   
    110             }
    111         }
     100        $color = $this->iColor ;
     101        if( $this->legend != "" ) {
     102            if( $this->iFillColor!='' ) {
     103                $color = $this->iFillColor;
     104                $aGraph->legend->Add($this->legend,$color,$this->mark,0,
     105                $this->legendcsimtarget,$this->legendcsimalt);
     106            }
     107            else {
     108                $aGraph->legend->Add($this->legend,$color,$this->mark,$this->line_style,
     109                $this->legendcsimtarget,$this->legendcsimalt);
     110            }
     111        }
    112112    }
    113113
    114114    function Stroke($img,$scale) {
    115115
    116         $i=0;
    117         $p=array();
    118         $this->csimareas='';
    119         while($i < $this->numpoints) {
    120             list($x1,$y1) = $scale->PTranslate($this->coord[2*$i],$this->coord[2*$i+1]);
    121             $p[2*$i] = $x1;
    122             $p[2*$i+1] = $y1;
    123        
    124             if( isset($this->csimtargets[$i]) ) {
    125                 $this->mark->SetCSIMTarget($this->csimtargets[$i]);
    126                 $this->mark->SetCSIMAlt($this->csimalts[$i]);
    127                 $this->mark->SetCSIMAltVal($this->coord[2*$i], $this->coord[2*$i+1]);
    128                 $this->mark->Stroke($img,$x1,$y1);
    129                 $this->csimareas .= $this->mark->GetCSIMAreas();
    130             }
    131             else
    132                 $this->mark->Stroke($img,$x1,$y1);
    133 
    134             ++$i;
    135         }
    136 
    137         if( $this->iFillColor != '' ) {
    138             $img->SetColor($this->iFillColor);
    139             $img->FilledPolygon($p);
    140         }
    141         $img->SetLineWeight($this->iLineWeight);
    142         $img->SetColor($this->iColor);
    143         $img->Polygon($p,$this->iFillColor!='');
     116        $i=0;
     117        $p=array();
     118        $this->csimareas='';
     119        while($i < $this->numpoints) {
     120            list($x1,$y1) = $scale->PTranslate($this->coord[2*$i],$this->coord[2*$i+1]);
     121            $p[2*$i] = $x1;
     122            $p[2*$i+1] = $y1;
     123
     124            if( isset($this->csimtargets[$i]) ) {
     125                $this->mark->SetCSIMTarget($this->csimtargets[$i]);
     126                $this->mark->SetCSIMAlt($this->csimalts[$i]);
     127                $this->mark->SetCSIMAltVal($this->coord[2*$i], $this->coord[2*$i+1]);
     128                $this->mark->Stroke($img,$x1,$y1);
     129                $this->csimareas .= $this->mark->GetCSIMAreas();
     130            }
     131            else {
     132                $this->mark->Stroke($img,$x1,$y1);
     133            }
     134
     135            ++$i;
     136        }
     137
     138        if( $this->iFillColor != '' ) {
     139            $img->SetColor($this->iFillColor);
     140            $img->FilledPolygon($p);
     141        }
     142        $img->SetLineWeight($this->iLineWeight);
     143        $img->SetColor($this->iColor);
     144        $img->Polygon($p,$this->iFillColor!='');
    144145    }
    145146}
     
    159160    private $radius_tick_color='black';
    160161
    161     function PolarAxis($img,$aScale) {
    162         parent::Axis($img,$aScale);
     162    function __construct($img,$aScale) {
     163        parent::__construct($img,$aScale);
    163164    }
    164165
    165166    function ShowAngleDegreeMark($aFlg=true) {
    166         $this->show_angle_mark = $aFlg;
     167        $this->show_angle_mark = $aFlg;
    167168    }
    168169
    169170    function SetAngleStep($aStep) {
    170         $this->angle_step=$aStep;
     171        $this->angle_step=$aStep;
    171172    }
    172173
    173174    function HideTicks($aFlg=true,$aAngleFlg=true) {
    174         parent::HideTicks($aFlg,$aFlg);
    175         $this->show_angle_tick = !$aAngleFlg;
     175        parent::HideTicks($aFlg,$aFlg);
     176        $this->show_angle_tick = !$aAngleFlg;
    176177    }
    177178
    178179    function ShowAngleLabel($aFlg=true) {
    179         $this->show_angle_label = $aFlg;
     180        $this->show_angle_label = $aFlg;
    180181    }
    181182
    182183    function ShowGrid($aMajor=true,$aMinor=false,$aAngle=true) {
    183         $this->show_minor_grid = $aMinor;
    184         $this->show_major_grid = $aMajor;
    185         $this->show_angle_grid = $aAngle ;
     184        $this->show_minor_grid = $aMinor;
     185        $this->show_major_grid = $aMajor;
     186        $this->show_angle_grid = $aAngle ;
    186187    }
    187188
    188189    function SetAngleFont($aFontFam,$aFontStyle=FS_NORMAL,$aFontSize=10) {
    189         $this->angle_fontfam = $aFontFam;
    190         $this->angle_fontstyle = $aFontStyle;
    191         $this->angle_fontsize = $aFontSize;
     190        $this->angle_fontfam = $aFontFam;
     191        $this->angle_fontstyle = $aFontStyle;
     192        $this->angle_fontsize = $aFontSize;
    192193    }
    193194
    194195    function SetColor($aColor,$aRadColor='',$aAngleColor='') {
    195         if( $aAngleColor == '' )
    196             $aAngleColor=$aColor;
    197         parent::SetColor($aColor,$aRadColor);
    198         $this->angle_fontcolor = $aAngleColor;
     196        if( $aAngleColor == '' )
     197        $aAngleColor=$aColor;
     198        parent::SetColor($aColor,$aRadColor);
     199        $this->angle_fontcolor = $aAngleColor;
    199200    }
    200201
    201202    function SetGridColor($aMajorColor,$aMinorColor='',$aAngleColor='') {
    202         if( $aMinorColor == '' )
    203             $aMinorColor = $aMajorColor;
    204         if( $aAngleColor == '' )
    205             $aAngleColor = $aMajorColor;
    206 
    207         $this->gridminor_color = $aMinorColor;
    208         $this->gridmajor_color = $aMajorColor;
    209         $this->angle_color = $aAngleColor;
     203        if( $aMinorColor == '' )
     204        $aMinorColor = $aMajorColor;
     205        if( $aAngleColor == '' )
     206        $aAngleColor = $aMajorColor;
     207
     208        $this->gridminor_color = $aMinorColor;
     209        $this->gridmajor_color = $aMajorColor;
     210        $this->angle_color = $aAngleColor;
    210211    }
    211212
    212213    function SetTickColors($aRadColor,$aAngleColor='') {
    213         $this->radius_tick_color = $aRadColor;
    214         $this->angle_tick_color = $aAngleColor;
    215     }
    216    
     214        $this->radius_tick_color = $aRadColor;
     215        $this->angle_tick_color = $aAngleColor;
     216    }
     217
    217218    // Private methods
    218219    function StrokeGrid($pos) {
    219         $x = round($this->img->left_margin + $this->img->plotwidth/2);
    220         $this->scale->ticks->Stroke($this->img,$this->scale,$pos);
    221 
    222         // Stroke the minor arcs
    223         $pmin = array();
    224         $p = $this->scale->ticks->ticks_pos;
    225         $n = count($p);
    226         $i = 0;
    227         $this->img->SetColor($this->gridminor_color);
    228         while( $i < $n ) {
    229             $r = $p[$i]-$x+1;
    230             $pmin[]=$r;
    231             if( $this->show_minor_grid ) {
    232                 $this->img->Circle($x,$pos,$r);
    233             }
    234             $i++;
    235         }
    236        
    237         $limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
    238         while( $r < $limit ) {
    239             $off = $r;
    240             $i=1;
    241             $r = $off + round($p[$i]-$x+1);
    242             while( $r < $limit && $i < $n ) {
    243                 $r = $off+$p[$i]-$x;
    244                 $pmin[]=$r;
    245                 if( $this->show_minor_grid ) {
    246                     $this->img->Circle($x,$pos,$r);
    247                 }
    248                 $i++;
    249             }
    250         }
    251 
    252         // Stroke the major arcs
    253         if( $this->show_major_grid ) {
    254             // First determine how many minor step on
    255             // every major step. We have recorded the minor radius
    256             // in pmin and use these values. This is done in order
    257             // to avoid rounding errors if we were to recalculate the
    258             // different major radius.
    259             $pmaj = $this->scale->ticks->maj_ticks_pos;
    260             $p = $this->scale->ticks->ticks_pos;
    261             if( $this->scale->name == 'lin' ) {
    262                 $step=round(($pmaj[1] - $pmaj[0])/($p[1] - $p[0]));
    263             }
    264             else {
    265                 $step=9;
    266             }
    267             $n = round(count($pmin)/$step);
    268             $i = 0;
    269             $this->img->SetColor($this->gridmajor_color);
    270             $limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
    271             $off = $r;
    272             $i=0;
    273             $r = $pmin[$i*$step];
    274             while( $r < $limit && $i < $n ) {
    275                 $r = $pmin[$i*$step];
    276                 $this->img->Circle($x,$pos,$r);
    277                 $i++;
    278             }
    279         }
    280 
    281         // Draw angles
    282         if( $this->show_angle_grid ) {
    283             $this->img->SetColor($this->angle_color);
    284             $d = max($this->img->plotheight,$this->img->plotwidth)*1.4 ;
    285             $a = 0;
    286             $p = $this->scale->ticks->ticks_pos;
    287             $start_radius = $p[1]-$x;
    288             while( $a < 360 ) {
    289                 if( $a == 90 || $a == 270 ) {
    290                     // Make sure there are no rounding problem with
    291                     // exactly vertical lines
    292                     $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
    293                                      $pos-$start_radius*sin($a/180*M_PI),
    294                                      $x+$start_radius*cos($a/180*M_PI)+1,
    295                                      $pos-$d*sin($a/180*M_PI));
    296                    
    297                 }
    298                 else {
    299                     $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
    300                                      $pos-$start_radius*sin($a/180*M_PI),
    301                                      $x+$d*cos($a/180*M_PI),
    302                                      $pos-$d*sin($a/180*M_PI));
    303                 }
    304                 $a += $this->angle_step;
    305             }
    306         }
     220        $x = round($this->img->left_margin + $this->img->plotwidth/2);
     221        $this->scale->ticks->Stroke($this->img,$this->scale,$pos);
     222
     223        // Stroke the minor arcs
     224        $pmin = array();
     225        $p = $this->scale->ticks->ticks_pos;
     226        $n = count($p);
     227        $i = 0;
     228        $this->img->SetColor($this->gridminor_color);
     229        while( $i < $n ) {
     230            $r = $p[$i]-$x+1;
     231            $pmin[]=$r;
     232            if( $this->show_minor_grid ) {
     233                $this->img->Circle($x,$pos,$r);
     234            }
     235            $i++;
     236        }
     237
     238        $limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
     239        while( $r < $limit ) {
     240            $off = $r;
     241            $i=1;
     242            $r = $off + round($p[$i]-$x+1);
     243            while( $r < $limit && $i < $n ) {
     244                $r = $off+$p[$i]-$x;
     245                $pmin[]=$r;
     246                if( $this->show_minor_grid ) {
     247                    $this->img->Circle($x,$pos,$r);
     248                }
     249                $i++;
     250            }
     251        }
     252
     253        // Stroke the major arcs
     254        if( $this->show_major_grid ) {
     255            // First determine how many minor step on
     256            // every major step. We have recorded the minor radius
     257            // in pmin and use these values. This is done in order
     258            // to avoid rounding errors if we were to recalculate the
     259            // different major radius.
     260            $pmaj = $this->scale->ticks->maj_ticks_pos;
     261            $p = $this->scale->ticks->ticks_pos;
     262            if( $this->scale->name == 'lin' ) {
     263                $step=round(($pmaj[1] - $pmaj[0])/($p[1] - $p[0]));
     264            }
     265            else {
     266                $step=9;
     267            }
     268            $n = round(count($pmin)/$step);
     269            $i = 0;
     270            $this->img->SetColor($this->gridmajor_color);
     271            $limit = max($this->img->plotwidth,$this->img->plotheight)*1.4 ;
     272            $off = $r;
     273            $i=0;
     274            $r = $pmin[$i*$step];
     275            while( $r < $limit && $i < $n ) {
     276                $r = $pmin[$i*$step];
     277                $this->img->Circle($x,$pos,$r);
     278                $i++;
     279            }
     280        }
     281
     282        // Draw angles
     283        if( $this->show_angle_grid ) {
     284            $this->img->SetColor($this->angle_color);
     285            $d = max($this->img->plotheight,$this->img->plotwidth)*1.4 ;
     286            $a = 0;
     287            $p = $this->scale->ticks->ticks_pos;
     288            $start_radius = $p[1]-$x;
     289            while( $a < 360 ) {
     290                if( $a == 90 || $a == 270 ) {
     291                    // Make sure there are no rounding problem with
     292                    // exactly vertical lines
     293                    $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
     294                                     $pos-$start_radius*sin($a/180*M_PI),
     295                                     $x+$start_radius*cos($a/180*M_PI)+1,
     296                                     $pos-$d*sin($a/180*M_PI));
     297
     298                }
     299                else {
     300                    $this->img->Line($x+$start_radius*cos($a/180*M_PI)+1,
     301                                     $pos-$start_radius*sin($a/180*M_PI),
     302                                     $x+$d*cos($a/180*M_PI),
     303                                     $pos-$d*sin($a/180*M_PI));
     304                }
     305                $a += $this->angle_step;
     306            }
     307        }
    307308    }
    308309
    309310    function StrokeAngleLabels($pos,$type) {
    310311
    311         if( !$this->show_angle_label )
    312             return;
    313        
    314         $x0 = round($this->img->left_margin+$this->img->plotwidth/2)+1;
    315 
    316         $d = max($this->img->plotwidth,$this->img->plotheight)*1.42;
    317         $a = $this->angle_step;
    318         $t = new Text();
    319         $t->SetColor($this->angle_fontcolor);
    320         $t->SetFont($this->angle_fontfam,$this->angle_fontstyle,$this->angle_fontsize);
    321         $xright = $this->img->width - $this->img->right_margin;
    322         $ytop = $this->img->top_margin;
    323         $xleft = $this->img->left_margin;
    324         $ybottom = $this->img->height - $this->img->bottom_margin;
    325         $ha = 'left';
    326         $va = 'center';
    327         $w = $this->img->plotwidth/2;
    328         $h = $this->img->plotheight/2;
    329         $xt = $x0; $yt = $pos;
    330         $margin=5;
    331 
    332         $tl  = $this->angle_tick_len ; // Outer len
    333         $tl2 = $this->angle_tick_len2 ; // Interior len
    334 
    335         $this->img->SetColor($this->angle_tick_color);
    336         $rot90 = $this->img->a == 90 ;
    337 
    338         if( $type == POLAR_360 ) {
    339             $ca1 = atan($h/$w)/M_PI*180;
    340             $ca2 = 180-$ca1;
    341             $ca3 = $ca1+180;
    342             $ca4 = 360-$ca1;
    343             $end = 360;
    344             while( $a < $end ) {
    345                 $ca = cos($a/180*M_PI);
    346                 $sa = sin($a/180*M_PI);
    347                 $x = $d*$ca;
    348                 $y = $d*$sa;
    349                 $xt=1000;$yt=1000;
    350                 if( $a <= $ca1 || $a >= $ca4 ) {
    351                     $yt = $pos - $w * $y/$x;
    352                     $xt = $xright + $margin;
    353                     if( $rot90 ) {
    354                         $ha = 'center';
    355                         $va = 'top';
    356                     }
    357                     else {
    358                         $ha = 'left';
    359                         $va = 'center';
    360                     }
    361                     $x1=$xright-$tl2; $x2=$xright+$tl;
    362                     $y1=$y2=$yt;
    363                 }
    364                 elseif( $a > $ca1 && $a < $ca2 ) {
    365                     $xt = $x0 + $h * $x/$y;
    366                     $yt = $ytop - $margin;
    367                     if( $rot90 ) {
    368                         $ha = 'left';
    369                         $va = 'center';
    370                     }
    371                     else {
    372                         $ha = 'center';
    373                         $va = 'bottom';
    374                     }
    375                     $y1=$ytop+$tl2;$y2=$ytop-$tl;
    376                     $x1=$x2=$xt;
    377                 }
    378                 elseif( $a >= $ca2 && $a <= $ca3 ) {
    379                     $yt = $pos + $w * $y/$x;
    380                     $xt = $xleft - $margin;
    381                     if( $rot90 ) {
    382                         $ha = 'center';
    383                         $va = 'bottom';
    384                     }
    385                     else {
    386                         $ha = 'right';
    387                         $va = 'center';
    388                     }
    389                     $x1=$xleft+$tl2;$x2=$xleft-$tl;
    390                     $y1=$y2=$yt;
    391                 }
    392                 else {
    393                     $xt = $x0 - $h * $x/$y;
    394                     $yt = $ybottom + $margin;
    395                     if( $rot90 ) {
    396                         $ha = 'right';
    397                         $va = 'center';
    398                     }
    399                     else {
    400                         $ha = 'center';
    401                         $va = 'top';
    402                     }
    403                     $y1=$ybottom-$tl2;$y2=$ybottom+$tl;
    404                     $x1=$x2=$xt;
    405                 }
    406                 if( $a != 0 && $a != 180 ) {
    407                     $t->Align($ha,$va);
    408                     if( $this->show_angle_mark )
    409                         $a .= '°';
    410                     $t->Set($a);
    411                     $t->Stroke($this->img,$xt,$yt);   
    412                     if( $this->show_angle_tick )
    413                         $this->img->Line($x1,$y1,$x2,$y2);
    414                 }
    415                 $a += $this->angle_step;
    416             }
    417         }
    418         else {
    419             // POLAR_HALF
    420             $ca1 = atan($h/$w*2)/M_PI*180;
    421             $ca2 = 180-$ca1;
    422             $end = 180;     
    423             while( $a < $end ) {
    424                 $ca = cos($a/180*M_PI);
    425                 $sa = sin($a/180*M_PI);
    426                 $x = $d*$ca;
    427                 $y = $d*$sa;
    428                 if( $a <= $ca1 ) {
    429                     $yt = $pos - $w * $y/$x;
    430                     $xt = $xright + $margin;
    431                     if( $rot90 ) {
    432                         $ha = 'center';
    433                         $va = 'top';
    434                     }
    435                     else {
    436                         $ha = 'left';
    437                         $va = 'center';
    438                     }
    439                     $x1=$xright-$tl2; $x2=$xright+$tl;
    440                     $y1=$y2=$yt;
    441                 }
    442                 elseif( $a > $ca1 && $a < $ca2 ) {
    443                     $xt = $x0 + 2*$h * $x/$y;
    444                     $yt = $ytop - $margin;
    445                     if( $rot90 ) {
    446                         $ha = 'left';
    447                         $va = 'center';
    448                     }
    449                     else {
    450                         $ha = 'center';
    451                         $va = 'bottom';
    452                     }
    453                     $y1=$ytop+$tl2;$y2=$ytop-$tl;
    454                     $x1=$x2=$xt;
    455                 }
    456                 elseif( $a >= $ca2 ) {
    457                     $yt = $pos + $w * $y/$x;
    458                     $xt = $xleft - $margin;
    459                     if( $rot90 ) {
    460                         $ha = 'center';
    461                         $va = 'bottom';
    462                     }
    463                     else {
    464                         $ha = 'right';
    465                         $va = 'center';
    466                     }
    467                     $x1=$xleft+$tl2;$x2=$xleft-$tl;
    468                     $y1=$y2=$yt;
    469                 }
    470                 $t->Align($ha,$va);
    471                 if( $this->show_angle_mark )
    472                     $a .= '°';
    473                 $t->Set($a);
    474                 $t->Stroke($this->img,$xt,$yt); 
    475                 if( $this->show_angle_tick )
    476                     $this->img->Line($x1,$y1,$x2,$y2); 
    477                 $a += $this->angle_step;
    478             }
    479         }
     312        if( !$this->show_angle_label )
     313            return;
     314
     315        $x0 = round($this->img->left_margin+$this->img->plotwidth/2)+1;
     316
     317        $d = max($this->img->plotwidth,$this->img->plotheight)*1.42;
     318        $a = $this->angle_step;
     319        $t = new Text();
     320        $t->SetColor($this->angle_fontcolor);
     321        $t->SetFont($this->angle_fontfam,$this->angle_fontstyle,$this->angle_fontsize);
     322        $xright = $this->img->width - $this->img->right_margin;
     323        $ytop = $this->img->top_margin;
     324        $xleft = $this->img->left_margin;
     325        $ybottom = $this->img->height - $this->img->bottom_margin;
     326        $ha = 'left';
     327        $va = 'center';
     328        $w = $this->img->plotwidth/2;
     329        $h = $this->img->plotheight/2;
     330        $xt = $x0; $yt = $pos;
     331        $margin=5;
     332
     333        $tl  = $this->angle_tick_len ; // Outer len
     334        $tl2 = $this->angle_tick_len2 ; // Interior len
     335
     336        $this->img->SetColor($this->angle_tick_color);
     337        $rot90 = $this->img->a == 90 ;
     338
     339        if( $type == POLAR_360 ) {
     340
     341            // Corner angles of the four corners
     342            $ca1 = atan($h/$w)/M_PI*180;
     343            $ca2 = 180-$ca1;
     344            $ca3 = $ca1+180;
     345            $ca4 = 360-$ca1;
     346            $end = 360;
     347
     348            while( $a < $end ) {
     349                $ca = cos($a/180*M_PI);
     350                $sa = sin($a/180*M_PI);
     351                $x = $d*$ca;
     352                $y = $d*$sa;
     353                $xt=1000;$yt=1000;
     354                if( $a <= $ca1 || $a >= $ca4 ) {
     355                    $yt = $pos - $w * $y/$x;
     356                    $xt = $xright + $margin;
     357                    if( $rot90 ) {
     358                        $ha = 'center';
     359                        $va = 'top';
     360                    }
     361                    else {
     362                        $ha = 'left';
     363                        $va = 'center';
     364                    }
     365                    $x1=$xright-$tl2; $x2=$xright+$tl;
     366                    $y1=$y2=$yt;
     367                }
     368                elseif( $a > $ca1 && $a < $ca2 ) {
     369                    $xt = $x0 + $h * $x/$y;
     370                    $yt = $ytop - $margin;
     371                    if( $rot90 ) {
     372                        $ha = 'left';
     373                        $va = 'center';
     374                    }
     375                    else {
     376                        $ha = 'center';
     377                        $va = 'bottom';
     378                    }
     379                    $y1=$ytop+$tl2;$y2=$ytop-$tl;
     380                    $x1=$x2=$xt;
     381                }
     382                elseif( $a >= $ca2 && $a <= $ca3 ) {
     383                    $yt = $pos + $w * $y/$x;
     384                    $xt = $xleft - $margin;
     385                    if( $rot90 ) {
     386                        $ha = 'center';
     387                        $va = 'bottom';
     388                    }
     389                    else {
     390                        $ha = 'right';
     391                        $va = 'center';
     392                    }
     393                    $x1=$xleft+$tl2;$x2=$xleft-$tl;
     394                    $y1=$y2=$yt;
     395                }
     396                else {
     397                    $xt = $x0 - $h * $x/$y;
     398                    $yt = $ybottom + $margin;
     399                    if( $rot90 ) {
     400                        $ha = 'right';
     401                        $va = 'center';
     402                    }
     403                    else {
     404                        $ha = 'center';
     405                        $va = 'top';
     406                    }
     407                    $y1=$ybottom-$tl2;$y2=$ybottom+$tl;
     408                    $x1=$x2=$xt;
     409                }
     410                if( $a != 0 && $a != 180 ) {
     411                    $t->Align($ha,$va);
     412                    if( $this->scale->clockwise ) {
     413                        $t->Set(360-$a);
     414                    }
     415                    else {
     416                        $t->Set($a);
     417                    }
     418                    if( $this->show_angle_mark && $t->font_family > 4 ) {
     419                        $a .= SymChar::Get('degree');
     420                    }
     421                    $t->Stroke($this->img,$xt,$yt);
     422                    if( $this->show_angle_tick ) {
     423                        $this->img->Line($x1,$y1,$x2,$y2);
     424                    }
     425                }
     426                $a = (int) $a;
     427                $a += $this->angle_step;
     428            }
     429        }
     430        else {
     431            // POLAR_HALF
     432            $ca1 = atan($h/$w*2)/M_PI*180;
     433            $ca2 = 180-$ca1;
     434            $end = 180;
     435            while( $a < $end ) {
     436                $ca = cos($a/180*M_PI);
     437                $sa = sin($a/180*M_PI);
     438                $x = $d*$ca;
     439                $y = $d*$sa;
     440                if( $a <= $ca1 ) {
     441                    $yt = $pos - $w * $y/$x;
     442                    $xt = $xright + $margin;
     443                    if( $rot90 ) {
     444                        $ha = 'center';
     445                        $va = 'top';
     446                    }
     447                    else {
     448                        $ha = 'left';
     449                        $va = 'center';
     450                    }
     451                    $x1=$xright-$tl2; $x2=$xright+$tl;
     452                    $y1=$y2=$yt;
     453                }
     454                elseif( $a > $ca1 && $a < $ca2 ) {
     455                    $xt = $x0 + 2*$h * $x/$y;
     456                    $yt = $ytop - $margin;
     457                    if( $rot90 ) {
     458                        $ha = 'left';
     459                        $va = 'center';
     460                    }
     461                    else {
     462                        $ha = 'center';
     463                        $va = 'bottom';
     464                    }
     465                    $y1=$ytop+$tl2;$y2=$ytop-$tl;
     466                    $x1=$x2=$xt;
     467                }
     468                elseif( $a >= $ca2 ) {
     469                    $yt = $pos + $w * $y/$x;
     470                    $xt = $xleft - $margin;
     471                    if( $rot90 ) {
     472                        $ha = 'center';
     473                        $va = 'bottom';
     474                    }
     475                    else {
     476                        $ha = 'right';
     477                        $va = 'center';
     478                    }
     479                    $x1=$xleft+$tl2;$x2=$xleft-$tl;
     480                    $y1=$y2=$yt;
     481                }
     482                $t->Align($ha,$va);
     483                if( $this->show_angle_mark && $t->font_family > 4 ) {
     484                        $a .= SymChar::Get('degree');
     485                }
     486                $t->Set($a);
     487                $t->Stroke($this->img,$xt,$yt);
     488                if( $this->show_angle_tick ) {
     489                    $this->img->Line($x1,$y1,$x2,$y2);
     490                }
     491                $a = (int) $a;
     492                $a += $this->angle_step;
     493            }
     494        }
    480495    }
    481496
    482497    function Stroke($pos,$dummy=true) {
    483498
    484         $this->img->SetLineWeight($this->weight);
    485         $this->img->SetColor($this->color);             
    486         $this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
    487         if( !$this->hide_line )
    488             $this->img->FilledRectangle($this->img->left_margin,$pos,
    489                      $this->img->width-$this->img->right_margin,$pos+$this->weight-1);
    490         $y=$pos+$this->img->GetFontHeight()+$this->title_margin+$this->title->margin;
    491         if( $this->title_adjust=="high" )
    492             $this->title->SetPos($this->img->width-$this->img->right_margin,$y,"right","top");
    493         elseif( $this->title_adjust=="middle" || $this->title_adjust=="center" )
    494             $this->title->SetPos(($this->img->width-$this->img->left_margin-
    495                                $this->img->right_margin)/2+$this->img->left_margin,
    496                               $y,"center","top");
    497         elseif($this->title_adjust=="low")
    498             $this->title->SetPos($this->img->left_margin,$y,"left","top");
    499         else { 
    500             JpGraphError::RaiseL(17002,$this->title_adjust);
    501 //('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')');
    502         }
    503 
    504        
    505         if (!$this->hide_labels) {
    506             $this->StrokeLabels($pos,false);
    507         }
    508         $this->img->SetColor($this->radius_tick_color);
    509         $this->scale->ticks->Stroke($this->img,$this->scale,$pos);
    510 
    511         //
    512         // Mirror the positions for the left side of the scale
     499        $this->img->SetLineWeight($this->weight);
     500        $this->img->SetColor($this->color);
     501        $this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
     502        if( !$this->hide_line ) {
     503            $this->img->FilledRectangle($this->img->left_margin,$pos,
     504                                        $this->img->width-$this->img->right_margin,
     505                                        $pos+$this->weight-1);
     506        }
     507        $y=$pos+$this->img->GetFontHeight()+$this->title_margin+$this->title->margin;
     508        if( $this->title_adjust=="high" ) {
     509            $this->title->SetPos($this->img->width-$this->img->right_margin,$y,"right","top");
     510        }
     511        elseif( $this->title_adjust=="middle" || $this->title_adjust=="center" ) {
     512            $this->title->SetPos(($this->img->width-$this->img->left_margin-$this->img->right_margin)/2+$this->img->left_margin,
     513                                $y,"center","top");
     514        }
     515        elseif($this->title_adjust=="low") {
     516            $this->title->SetPos($this->img->left_margin,$y,"left","top");
     517        }
     518        else {
     519            JpGraphError::RaiseL(17002,$this->title_adjust);
     520            //('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')');
     521        }
     522
     523
     524        if (!$this->hide_labels) {
     525            $this->StrokeLabels($pos,false);
     526        }
     527        $this->img->SetColor($this->radius_tick_color);
     528        $this->scale->ticks->Stroke($this->img,$this->scale,$pos);
     529
    513530        //
    514         $mid = 2*($this->img->left_margin+$this->img->plotwidth/2);
    515         $n = count($this->scale->ticks->ticks_pos);
    516         $i=0;
    517         while( $i < $n ) {
    518             $this->scale->ticks->ticks_pos[$i] =
    519                 $mid-$this->scale->ticks->ticks_pos[$i] ;
    520             ++$i;
    521         }
    522 
    523         $n = count($this->scale->ticks->maj_ticks_pos);
    524         $i=0;
    525         while( $i < $n ) {
    526             $this->scale->ticks->maj_ticks_pos[$i] =
    527                 $mid-$this->scale->ticks->maj_ticks_pos[$i] ;
    528             ++$i;
    529         }
    530        
    531         $n = count($this->scale->ticks->maj_ticklabels_pos);
    532         $i=1;
    533         while( $i < $n ) {
    534             $this->scale->ticks->maj_ticklabels_pos[$i] =
    535                 $mid-$this->scale->ticks->maj_ticklabels_pos[$i] ;
    536             ++$i;
    537         }
    538 
    539         // Draw the left side of the scale
    540         $n = count($this->scale->ticks->ticks_pos);
    541         $yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMinTickAbsSize();
    542 
    543 
    544         // Minor ticks
    545         if( ! $this->scale->ticks->supress_minor_tickmarks ) {
    546             $i=1;
    547             while( $i < $n/2 ) {
    548                 $x = round($this->scale->ticks->ticks_pos[$i]) ;
    549                 $this->img->Line($x,$pos,$x,$yu);
    550                 ++$i;
    551             }
    552         }
    553 
    554         $n = count($this->scale->ticks->maj_ticks_pos);
    555         $yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMajTickAbsSize();
    556 
    557 
    558         // Major ticks
    559         if( ! $this->scale->ticks->supress_tickmarks ) {
    560             $i=1;
    561             while( $i < $n/2 ) {
    562                 $x = round($this->scale->ticks->maj_ticks_pos[$i]) ;
    563                 $this->img->Line($x,$pos,$x,$yu);
    564                 ++$i;
    565             }
    566         }
    567         if (!$this->hide_labels) {
    568             $this->StrokeLabels($pos,false);
    569         }
    570         $this->title->Stroke($this->img);       
     531        // Mirror the positions for the left side of the scale
     532        //
     533        $mid = 2*($this->img->left_margin+$this->img->plotwidth/2);
     534        $n = count($this->scale->ticks->ticks_pos);
     535        $i=0;
     536        while( $i < $n ) {
     537            $this->scale->ticks->ticks_pos[$i] =
     538            $mid-$this->scale->ticks->ticks_pos[$i] ;
     539            ++$i;
     540        }
     541
     542        $n = count($this->scale->ticks->maj_ticks_pos);
     543        $i=0;
     544        while( $i < $n ) {
     545            $this->scale->ticks->maj_ticks_pos[$i] =
     546            $mid-$this->scale->ticks->maj_ticks_pos[$i] ;
     547            ++$i;
     548        }
     549
     550        $n = count($this->scale->ticks->maj_ticklabels_pos);
     551        $i=1;
     552        while( $i < $n ) {
     553            $this->scale->ticks->maj_ticklabels_pos[$i] =
     554            $mid-$this->scale->ticks->maj_ticklabels_pos[$i] ;
     555            ++$i;
     556        }
     557
     558        // Draw the left side of the scale
     559        $n = count($this->scale->ticks->ticks_pos);
     560        $yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMinTickAbsSize();
     561
     562
     563        // Minor ticks
     564        if( ! $this->scale->ticks->supress_minor_tickmarks ) {
     565            $i=1;
     566            while( $i < $n/2 ) {
     567                $x = round($this->scale->ticks->ticks_pos[$i]) ;
     568                $this->img->Line($x,$pos,$x,$yu);
     569                ++$i;
     570            }
     571        }
     572
     573        $n = count($this->scale->ticks->maj_ticks_pos);
     574        $yu = $pos - $this->scale->ticks->direction*$this->scale->ticks->GetMajTickAbsSize();
     575
     576
     577        // Major ticks
     578        if( ! $this->scale->ticks->supress_tickmarks ) {
     579            $i=1;
     580            while( $i < $n/2 ) {
     581                $x = round($this->scale->ticks->maj_ticks_pos[$i]) ;
     582                $this->img->Line($x,$pos,$x,$yu);
     583                ++$i;
     584            }
     585        }
     586        if (!$this->hide_labels) {
     587            $this->StrokeLabels($pos,false);
     588        }
     589        $this->title->Stroke($this->img);
    571590    }
    572591}
     
    574593class PolarScale extends LinearScale {
    575594    private $graph;
    576 
    577     function PolarScale($aMax=0,$graph) {
    578         parent::LinearScale(0,$aMax,'x');
    579         $this->graph = $graph;
     595    public $clockwise=false;
     596
     597    function __construct($aMax,$graph,$aClockwise) {
     598        parent::__construct(0,$aMax,'x');
     599        $this->graph = $graph;
     600        $this->clockwise = $aClockwise;
     601    }
     602
     603    function SetClockwise($aFlg) {
     604        $this->clockwise = $aFlg;
    580605    }
    581606
    582607    function _Translate($v) {
    583         return parent::Translate($v);
     608        return parent::Translate($v);
    584609    }
    585610
    586611    function PTranslate($aAngle,$aRad) {
    587        
    588         $m = $this->scale[1];
    589         $w = $this->graph->img->plotwidth/2;
    590         $aRad = $aRad/$m*$w;
    591 
    592         $x = cos( $aAngle/180 * M_PI ) * $aRad;
    593         $y = sin( $aAngle/180 * M_PI ) * $aRad;
    594 
    595         $x += $this->_Translate(0);
    596 
    597         if( $this->graph->iType == POLAR_360 ) {
    598             $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
    599         }
    600         else {
    601             $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
    602         }
    603         return array($x,$y);
     612
     613        $m = $this->scale[1];
     614        $w = $this->graph->img->plotwidth/2;
     615        $aRad = $aRad/$m*$w;
     616
     617        $a = $aAngle/180 * M_PI;
     618        if( $this->clockwise ) {
     619            $a = 2*M_PI-$a;
     620        }
     621
     622        $x = cos($a) * $aRad;
     623        $y = sin($a) * $aRad;
     624
     625        $x += $this->_Translate(0);
     626
     627        if( $this->graph->iType == POLAR_360 ) {
     628            $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
     629        }
     630        else {
     631            $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
     632        }
     633        return array($x,$y);
    604634    }
    605635}
     
    607637class PolarLogScale extends LogScale {
    608638    private $graph;
    609     function PolarLogScale($aMax=1,$graph) {
    610         parent::LogScale(0,$aMax,'x');
    611         $this->graph = $graph;
    612         $this->ticks->SetLabelLogType(LOGLABELS_MAGNITUDE);
    613 
     639    public $clockwise=false;
     640
     641    function __construct($aMax,$graph,$aClockwise=false) {
     642        parent::__construct(0,$aMax,'x');
     643        $this->graph = $graph;
     644        $this->ticks->SetLabelLogType(LOGLABELS_MAGNITUDE);
     645        $this->clockwise = $aClockwise;
     646
     647    }
     648
     649    function SetClockwise($aFlg) {
     650        $this->clockwise = $aFlg;
    614651    }
    615652
    616653    function PTranslate($aAngle,$aRad) {
    617654
    618         if( $aRad == 0 )
    619             $aRad = 1;
    620         $aRad = log10($aRad);
    621         $m = $this->scale[1];
    622         $w = $this->graph->img->plotwidth/2;
    623         $aRad = $aRad/$m*$w;
    624 
    625         $x = cos( $aAngle/180 * M_PI ) * $aRad;
    626         $y = sin( $aAngle/180 * M_PI ) * $aRad;
    627 
    628         $x += $w+$this->graph->img->left_margin;//$this->_Translate(0);
    629         if( $this->graph->iType == POLAR_360 ) {
    630             $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
    631         }
    632         else {
    633             $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
    634         }
    635         return array($x,$y);
     655        if( $aRad == 0 )
     656        $aRad = 1;
     657        $aRad = log10($aRad);
     658        $m = $this->scale[1];
     659        $w = $this->graph->img->plotwidth/2;
     660        $aRad = $aRad/$m*$w;
     661
     662        $a = $aAngle/180 * M_PI;
     663        if( $this->clockwise ) {
     664            $a = 2*M_PI-$a;
     665        }
     666
     667        $x = cos( $a ) * $aRad;
     668        $y = sin( $a ) * $aRad;
     669
     670        $x += $w+$this->graph->img->left_margin;//$this->_Translate(0);
     671        if( $this->graph->iType == POLAR_360 ) {
     672            $y = ($this->graph->img->top_margin + $this->graph->img->plotheight/2) - $y;
     673        }
     674        else {
     675            $y = ($this->graph->img->top_margin + $this->graph->img->plotheight) - $y;
     676        }
     677        return array($x,$y);
    636678    }
    637679}
     
    641683    public $axis;
    642684    public $iType=POLAR_360;
    643    
    644     function PolarGraph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {
    645         parent::Graph($aWidth,$aHeight,$aCachedName,$aTimeOut,$aInline) ;
    646         $this->SetDensity(TICKD_DENSE);
    647         $this->SetBox();
    648         $this->SetMarginColor('white');
     685    private $iClockwise=false;
     686
     687    function __construct($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {
     688        parent::__construct($aWidth,$aHeight,$aCachedName,$aTimeOut,$aInline) ;
     689        $this->SetDensity(TICKD_DENSE);
     690        $this->SetBox();
     691        $this->SetMarginColor('white');
    649692    }
    650693
    651694    function SetDensity($aDense) {
    652         $this->SetTickDensity(TICKD_NORMAL,$aDense);
     695        $this->SetTickDensity(TICKD_NORMAL,$aDense);
     696    }
     697
     698    function SetClockwise($aFlg) {
     699        $this->scale->SetClockwise($aFlg);
    653700    }
    654701
    655702    function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) {
    656         $adj = ($this->img->height - $this->img->width)/2;
    657         $this->SetAngle(90);
    658         $this->img->SetMargin($lm-$adj,$rm-$adj,$tm+$adj,$bm+$adj);
    659         $this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2));
    660         $this->axis->SetLabelAlign('right','center');
    661         //JpGraphError::Raise('Set90AndMargin() is not supported for polar graphs.');
     703        $adj = ($this->img->height - $this->img->width)/2;
     704        $this->SetAngle(90);
     705        $lm2 = -$adj + ($lm-$rm+$tm+$bm)/2;
     706        $rm2 = -$adj + (-$lm+$rm+$tm+$bm)/2;
     707        $tm2 = $adj + ($tm-$bm+$lm+$rm)/2;
     708        $bm2 = $adj + (-$tm+$bm+$lm+$rm)/2;
     709        $this->SetMargin($lm2, $rm2, $tm2, $bm2);
     710        $this->axis->SetLabelAlign('right','center');
    662711    }
    663712
    664713    function SetScale($aScale,$rmax=0,$dummy1=1,$dummy2=1,$dummy3=1) {
    665         if( $aScale == 'lin' )
    666             $this->scale = new PolarScale($rmax,$this);
    667         elseif( $aScale == 'log' ) {
    668             $this->scale = new PolarLogScale($rmax,$this);
    669         }
    670         else {
    671             JpGraphError::RaiseL(17004);//('Unknown scale type for polar graph. Must be "lin" or "log"');
    672         }
    673 
    674         $this->axis = new PolarAxis($this->img,$this->scale);
    675         $this->SetMargin(40,40,50,40);
     714        if( $aScale == 'lin' ) {
     715            $this->scale = new PolarScale($rmax,$this,$this->iClockwise);
     716        }
     717        elseif( $aScale == 'log' ) {
     718            $this->scale = new PolarLogScale($rmax,$this,$this->iClockwise);
     719        }
     720        else {
     721            JpGraphError::RaiseL(17004);//('Unknown scale type for polar graph. Must be "lin" or "log"');
     722        }
     723
     724        $this->axis = new PolarAxis($this->img,$this->scale);
     725        $this->SetMargin(40,40,50,40);
    676726    }
    677727
    678728    function SetType($aType) {
    679         $this->iType = $aType;
     729        $this->iType = $aType;
    680730    }
    681731
    682732    function SetPlotSize($w,$h) {
    683         $this->SetMargin(($this->img->width-$w)/2,($this->img->width-$w)/2,
    684                         ($this->img->height-$h)/2,($this->img->height-$h)/2);
     733        $this->SetMargin(($this->img->width-$w)/2,($this->img->width-$w)/2,
     734                        ($this->img->height-$h)/2,($this->img->height-$h)/2);
    685735    }
    686736
    687737    // Private methods
    688738    function GetPlotsMax() {
    689         $n = count($this->plots);
    690         $m = $this->plots[0]->Max();
    691         $i=1;
    692         while($i < $n) {
    693             $m = max($this->plots[$i]->Max(),$m);
    694             ++$i;
    695         }
    696         return $m;
     739        $n = count($this->plots);
     740        $m = $this->plots[0]->Max();
     741        $i=1;
     742        while($i < $n) {
     743            $m = max($this->plots[$i]->Max(),$m);
     744            ++$i;
     745        }
     746        return $m;
    697747    }
    698748
    699749    function Stroke($aStrokeFileName="") {
    700750
    701         // Start by adjusting the margin so that potential titles will fit.
    702         $this->AdjustMarginsForTitles();
    703            
    704         // If the filename is the predefined value = '_csim_special_'
    705         // we assume that the call to stroke only needs to do enough
    706         // to correctly generate the CSIM maps.
    707         // We use this variable to skip things we don't strictly need
    708         // to do to generate the image map to improve performance
    709         // a best we can. Therefor you will see a lot of tests !$_csim in the
    710         // code below.
    711         $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);
    712 
    713         // We need to know if we have stroked the plot in the
    714         // GetCSIMareas. Otherwise the CSIM hasn't been generated
    715         // and in the case of GetCSIM called before stroke to generate
    716         // CSIM without storing an image to disk GetCSIM must call Stroke.
    717         $this->iHasStroked = true;
    718 
    719         //Check if we should autoscale axis
    720         if( !$this->scale->IsSpecified() && count($this->plots)>0 ) {
    721             $max = $this->GetPlotsMax();
    722             $t1 = $this->img->plotwidth;
    723             $this->img->plotwidth /= 2;
    724             $t2 = $this->img->left_margin;
    725             $this->img->left_margin += $this->img->plotwidth+1;
    726             $this->scale->AutoScale($this->img,0,$max,
    727                                      $this->img->plotwidth/$this->xtick_factor/2);
    728             $this->img->plotwidth = $t1;
    729             $this->img->left_margin = $t2;
    730         }
    731         else {
    732             // The tick calculation will use the user suplied min/max values to determine
    733             // the ticks. If auto_ticks is false the exact user specifed min and max
    734             // values will be used for the scale.
    735             // If auto_ticks is true then the scale might be slightly adjusted
    736             // so that the min and max values falls on an even major step.
    737             //$min = 0;
    738             $max = $this->scale->scale[1];
    739             $t1 = $this->img->plotwidth;
    740             $this->img->plotwidth /= 2;
    741             $t2 = $this->img->left_margin;
    742             $this->img->left_margin += $this->img->plotwidth+1;
    743             $this->scale->AutoScale($this->img,0,$max,
    744                                      $this->img->plotwidth/$this->xtick_factor/2);
    745             $this->img->plotwidth = $t1;
    746             $this->img->left_margin = $t2;
    747         }
    748 
    749         if( $this->iType ==  POLAR_180 )
    750             $pos = $this->img->height - $this->img->bottom_margin;
    751         else
    752             $pos = $this->img->plotheight/2 + $this->img->top_margin;
    753 
    754 
    755         if( !$_csim ) {
    756             $this->StrokePlotArea();
    757         }
    758 
    759         $this->iDoClipping = true;
    760 
    761         if( $this->iDoClipping ) {
    762             $oldimage = $this->img->CloneCanvasH();
    763         }
    764 
    765         if( !$_csim ) {
    766             $this->axis->StrokeGrid($pos);
    767         }
    768 
    769         // Stroke all plots for Y1 axis
    770         for($i=0; $i < count($this->plots); ++$i) {
    771             $this->plots[$i]->Stroke($this->img,$this->scale);
    772         }                                               
    773 
    774 
    775         if( $this->iDoClipping ) {
    776             // Clipping only supports graphs at 0 and 90 degrees
    777             if( $this->img->a == 0  ) {
    778                 $this->img->CopyCanvasH($oldimage,$this->img->img,
    779                                         $this->img->left_margin,$this->img->top_margin,
    780                                         $this->img->left_margin,$this->img->top_margin,
    781                                         $this->img->plotwidth+1,$this->img->plotheight+1);
    782             }
    783             elseif( $this->img->a == 90 ) {
    784                 $adj = round(($this->img->height - $this->img->width)/2);
    785                 $this->img->CopyCanvasH($oldimage,$this->img->img,
    786                                         $this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
    787                                         $this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
    788                                         $this->img->plotheight,$this->img->plotwidth);
    789             }
    790             $this->img->Destroy();
    791             $this->img->SetCanvasH($oldimage);
    792         }
    793 
    794         if( !$_csim ) {
    795             $this->axis->Stroke($pos);
    796             $this->axis->StrokeAngleLabels($pos,$this->iType);
    797         }
    798 
    799         if( !$_csim ) {
    800             $this->StrokePlotBox();
    801             $this->footer->Stroke($this->img);
    802 
    803             // The titles and legends never gets rotated so make sure
    804             // that the angle is 0 before stroking them                         
    805             $aa = $this->img->SetAngle(0);
    806             $this->StrokeTitles();
    807         }
    808 
    809         for($i=0; $i < count($this->plots) ; ++$i ) {
    810             $this->plots[$i]->Legend($this);
    811         }
    812 
    813         $this->legend->Stroke($this->img);             
    814 
    815         if( !$_csim ) {
    816 
    817             $this->StrokeTexts();       
    818             $this->img->SetAngle($aa); 
    819                        
    820             // Draw an outline around the image map     
    821             if(_JPG_DEBUG)
    822                 $this->DisplayClientSideaImageMapAreas();               
    823            
    824             // If the filename is given as the special "__handle"
    825             // then the image handler is returned and the image is NOT
    826             // streamed back
    827             if( $aStrokeFileName == _IMG_HANDLER ) {
    828                 return $this->img->img;
    829             }
    830             else {
    831                 // Finally stream the generated picture                                 
    832                 $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,
    833                                            $aStrokeFileName);           
    834             }
    835         }
     751        // Start by adjusting the margin so that potential titles will fit.
     752        $this->AdjustMarginsForTitles();
     753
     754        // If the filename is the predefined value = '_csim_special_'
     755        // we assume that the call to stroke only needs to do enough
     756        // to correctly generate the CSIM maps.
     757        // We use this variable to skip things we don't strictly need
     758        // to do to generate the image map to improve performance
     759        // a best we can. Therefor you will see a lot of tests !$_csim in the
     760        // code below.
     761        $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);
     762
     763        // We need to know if we have stroked the plot in the
     764        // GetCSIMareas. Otherwise the CSIM hasn't been generated
     765        // and in the case of GetCSIM called before stroke to generate
     766        // CSIM without storing an image to disk GetCSIM must call Stroke.
     767        $this->iHasStroked = true;
     768
     769        //Check if we should autoscale axis
     770        if( !$this->scale->IsSpecified() && count($this->plots)>0 ) {
     771            $max = $this->GetPlotsMax();
     772            $t1 = $this->img->plotwidth;
     773            $this->img->plotwidth /= 2;
     774            $t2 = $this->img->left_margin;
     775            $this->img->left_margin += $this->img->plotwidth+1;
     776            $this->scale->AutoScale($this->img,0,$max,
     777            $this->img->plotwidth/$this->xtick_factor/2);
     778            $this->img->plotwidth = $t1;
     779            $this->img->left_margin = $t2;
     780        }
     781        else {
     782            // The tick calculation will use the user suplied min/max values to determine
     783            // the ticks. If auto_ticks is false the exact user specifed min and max
     784            // values will be used for the scale.
     785            // If auto_ticks is true then the scale might be slightly adjusted
     786            // so that the min and max values falls on an even major step.
     787            //$min = 0;
     788            $max = $this->scale->scale[1];
     789            $t1 = $this->img->plotwidth;
     790            $this->img->plotwidth /= 2;
     791            $t2 = $this->img->left_margin;
     792            $this->img->left_margin += $this->img->plotwidth+1;
     793            $this->scale->AutoScale($this->img,0,$max,
     794            $this->img->plotwidth/$this->xtick_factor/2);
     795            $this->img->plotwidth = $t1;
     796            $this->img->left_margin = $t2;
     797        }
     798
     799        if( $this->iType ==  POLAR_180 ) {
     800                $pos = $this->img->height - $this->img->bottom_margin;
     801        }
     802        else {
     803                $pos = $this->img->plotheight/2 + $this->img->top_margin;
     804        }
     805
     806        if( !$_csim ) {
     807            $this->StrokePlotArea();
     808        }
     809
     810        $this->iDoClipping = true;
     811
     812        if( $this->iDoClipping ) {
     813            $oldimage = $this->img->CloneCanvasH();
     814        }
     815
     816        if( !$_csim ) {
     817            $this->axis->StrokeGrid($pos);
     818        }
     819
     820        // Stroke all plots for Y1 axis
     821        for($i=0; $i < count($this->plots); ++$i) {
     822            $this->plots[$i]->Stroke($this->img,$this->scale);
     823        }
     824
     825
     826        if( $this->iDoClipping ) {
     827            // Clipping only supports graphs at 0 and 90 degrees
     828            if( $this->img->a == 0  ) {
     829                $this->img->CopyCanvasH($oldimage,$this->img->img,
     830                                        $this->img->left_margin,$this->img->top_margin,
     831                                        $this->img->left_margin,$this->img->top_margin,
     832                                        $this->img->plotwidth+1,$this->img->plotheight+1);
     833            }
     834            elseif( $this->img->a == 90 ) {
     835                $adj1 = round(($this->img->height - $this->img->width)/2);
     836                $adj2 = round(($this->img->width - $this->img->height)/2);
     837                $lm = $this->img->left_margin;
     838                $rm = $this->img->right_margin;
     839                $tm = $this->img->top_margin;
     840                $bm = $this->img->bottom_margin;
     841                $this->img->CopyCanvasH($oldimage,$this->img->img,
     842                                        $adj2 + round(($lm-$rm+$tm+$bm)/2),
     843                                        $adj1 + round(($tm-$bm+$lm+$rm)/2),
     844                                        $adj2 + round(($lm-$rm+$tm+$bm)/2),
     845                                        $adj1 + round(($tm-$bm+$lm+$rm)/2),
     846                                        $this->img->plotheight+1,
     847                                        $this->img->plotwidth+1);
     848            }
     849            $this->img->Destroy();
     850            $this->img->SetCanvasH($oldimage);
     851        }
     852
     853        if( !$_csim ) {
     854            $this->axis->Stroke($pos);
     855            $this->axis->StrokeAngleLabels($pos,$this->iType);
     856        }
     857
     858        if( !$_csim ) {
     859            $this->StrokePlotBox();
     860            $this->footer->Stroke($this->img);
     861
     862            // The titles and legends never gets rotated so make sure
     863            // that the angle is 0 before stroking them
     864            $aa = $this->img->SetAngle(0);
     865            $this->StrokeTitles();
     866        }
     867
     868        for($i=0; $i < count($this->plots) ; ++$i ) {
     869            $this->plots[$i]->Legend($this);
     870        }
     871
     872        $this->legend->Stroke($this->img);
     873
     874        if( !$_csim ) {
     875
     876            $this->StrokeTexts();
     877            $this->img->SetAngle($aa);
     878
     879            // Draw an outline around the image map
     880            if(_JPG_DEBUG)
     881                $this->DisplayClientSideaImageMapAreas();
     882
     883            // If the filename is given as the special "__handle"
     884            // then the image handler is returned and the image is NOT
     885            // streamed back
     886            if( $aStrokeFileName == _IMG_HANDLER ) {
     887                return $this->img->img;
     888            }
     889            else {
     890                // Finally stream the generated picture
     891                $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,$aStrokeFileName);
     892            }
     893        }
    836894    }
    837895}
Note: See TracChangeset for help on using the changeset viewer.