1<?php 2 /* 3 pRadar - class to draw radar charts 4 5 Version : 2.1.0 6 Made by : Jean-Damien POGOLOTTI 7 Last Update : 26/01/11 8 9 This file can be distributed under the license you can find at : 10 11 http://www.pchart.net/license 12 13 You can find the whole class documentation on the pChart web site. 14 */ 15 16 define("SEGMENT_HEIGHT_AUTO" , 690001); 17 18 define("RADAR_LAYOUT_STAR" , 690011); 19 define("RADAR_LAYOUT_CIRCLE" , 690012); 20 21 define("RADAR_LABELS_ROTATED" , 690021); 22 define("RADAR_LABELS_HORIZONTAL" , 690022); 23 24 /* pRadar class definition */ 25 class pRadar 26 { 27 var $pChartObject; 28 29 /* Class creator */ 30 function pRadar() 31 { } 32 33 /* Draw a radar chart */ 34 function drawRadar($Object,$Values,$Format="") 35 { 36 $this->pChartObject = $Object; 37 38 $AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60; 39 $AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60; 40 $AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60; 41 $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50; 42 $AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : 0; 43 $DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE; 44 $TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2; 45 $DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE; 46 $AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE; 47 $AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; 48 $AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; 49 $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE; 50 $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255; 51 $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255; 52 $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255; 53 $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50; 54 $BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL; 55 $Layout = isset($Format["Layout"]) ? $Format["Layout"] : RADAR_LAYOUT_STAR; 56 $SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO; 57 $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4; 58 $WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE; 59 $SkipLabels = isset($Format["SkipLabels"]) ? $Format["SkipLabels"] : 1; 60 $LabelMiddle = isset($Format["LabelMiddle"]) ? $Format["LabelMiddle"] : FALSE; 61 $LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE; 62 $LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255; 63 $LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255; 64 $LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255; 65 $LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50; 66 $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED; 67 $LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4; 68 $DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE; 69 $PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4; 70 $PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30; 71 $DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE; 72 $LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : TRUE; 73 $DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE; 74 $PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : 40; 75 $FontSize = $Object->FontSize; 76 $X1 = $Object->GraphAreaX1; 77 $Y1 = $Object->GraphAreaY1; 78 $X2 = $Object->GraphAreaX2; 79 $Y2 = $Object->GraphAreaY2; 80 81 // if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; } 82 83 /* Cancel default tick length if ticks not enabled */ 84 if ( $DrawTicks == FALSE ) { $TicksLength = 0; } 85 86 /* Data Processing */ 87 $Data = $Values->getData(); 88 $Palette = $Values->getPalette(); 89 90 /* Catch the number of required axis */ 91 $LabelSerie = $Data["Abscissa"]; 92 if ( $LabelSerie != "" ) 93 { $Points = count($Data["Series"][$LabelSerie]["Data"]); } 94 else 95 { 96 $Points = 0; 97 foreach($Data["Series"] as $SerieName => $DataArray) 98 { if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } } 99 } 100 101 /* Draw the axis */ 102 $CenterX = ($X2-$X1)/2 + $X1; 103 $CenterY = ($Y2-$Y1)/2 + $Y1; 104 105 $EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2); 106 if ( $WriteLabels ) 107 $EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength; 108 109 /* Determine the scale if set to automatic */ 110 if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO) 111 { 112 $Max = 0; 113 foreach($Data["Series"] as $SerieName => $DataArray) 114 { 115 if ( $SerieName != $LabelSerie ) 116 { 117 if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); } 118 } 119 } 120 $MaxSegments = $EdgeHeight/20; 121 $Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5)); 122 123 $Segments = $Scale["Rows"]; 124 $SegmentHeight = $Scale["RowHeight"]; 125 } 126 127 if ( $LabelMiddle && $SkipLabels == 1 ) 128 { $Axisoffset = (360/$Points)/2; } 129 elseif ( $LabelMiddle && $SkipLabels != 1 ) 130 { $Axisoffset = (360/($Points/$SkipLabels))/2; } 131 elseif ( !$LabelMiddle ) 132 { $Axisoffset = 0; } 133 134 /* Background processing */ 135 if ( $DrawBackground ) 136 { 137 $RestoreShadow = $Object->Shadow; 138 $Object->Shadow = FALSE; 139 140 if ($BackgroundGradient == NULL) 141 { 142 if ( $Layout == RADAR_LAYOUT_STAR ) 143 { 144 $Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha); 145 $PointArray = ""; 146 for($i=0;$i<=360;$i=$i+(360/$Points)) 147 { 148 $PointArray[] = cos(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterX; 149 $PointArray[] = sin(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterY; 150 } 151 $Object->drawPolygon($PointArray,$Color); 152 } 153 elseif ( $Layout == RADAR_LAYOUT_CIRCLE ) 154 { 155 $Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha); 156 $Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color); 157 } 158 } 159 else 160 { 161 $GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments; 162 $GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments; 163 $GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments; 164 $GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments; 165 166 if ( $Layout == RADAR_LAYOUT_STAR ) 167 { 168 for($j=$Segments;$j>=1;$j--) 169 { 170 $Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j); 171 $PointArray = ""; 172 173 for($i=0;$i<=360;$i=$i+(360/$Points)) 174 { 175 $PointArray[] = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 176 $PointArray[] = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 177 } 178 $Object->drawPolygon($PointArray,$Color); 179 } 180 } 181 elseif ( $Layout == RADAR_LAYOUT_CIRCLE ) 182 { 183 for($j=$Segments;$j>=1;$j--) 184 { 185 $Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j); 186 $Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color); 187 } 188 } 189 } 190 $Object->Shadow = $RestoreShadow; 191 } 192 193 /* Axis to axis lines */ 194 $Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha); 195 $ColorDotted = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha*.8, "Ticks"=>2); 196 if ( $Layout == RADAR_LAYOUT_STAR ) 197 { 198 for($j=1;$j<=$Segments;$j++) 199 { 200 for($i=0;$i<360;$i=$i+(360/$Points)) 201 { 202 $EdgeX1 = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 203 $EdgeY1 = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 204 $EdgeX2 = cos(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterX; 205 $EdgeY2 = sin(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterY; 206 207 $Object->drawLine($EdgeX1,$EdgeY1,$EdgeX2,$EdgeY2,$Color); 208 } 209 } 210 } 211 elseif ( $Layout == RADAR_LAYOUT_CIRCLE ) 212 { 213 for($j=1;$j<=$Segments;$j++) 214 { 215 $Radius = ($EdgeHeight/$Segments)*$j; 216 $Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color); 217 } 218 } 219 220 if ( $DrawAxisValues ) 221 { 222 if ( $LabelsBackground ) 223 $Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha); 224 else 225 $Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE); 226 227 if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; } 228 229 $Options["FontName"] = $AxisFontName; 230 $Options["FontSize"] = $AxisFontSize; 231 232 $Angle = 360 / ($Points*2); 233 for($j=1;$j<=$Segments;$j++) 234 { 235 $Label = $j * $SegmentHeight; 236 237 if ( $Layout == RADAR_LAYOUT_CIRCLE ) 238 { 239 $EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 240 $EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 241 } 242 elseif ( $Layout == RADAR_LAYOUT_STAR ) 243 { 244 $EdgeX1 = cos(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 245 $EdgeY1 = sin(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 246 $EdgeX2 = cos(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 247 $EdgeY2 = sin(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 248 249 $EdgeX1 = ($EdgeX2 - $EdgeX1)/2 + $EdgeX1; 250 $EdgeY1 = ($EdgeY2 - $EdgeY1)/2 + $EdgeY1; 251 } 252 253 $Object->drawText($EdgeX1,$EdgeY1,$Label,$Options); 254 } 255 } 256 257 /* Axis lines */ 258 $ID = 0; 259 for($i=0;$i<360;$i=$i+(360/$Points)) 260 { 261 $EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX; 262 $EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY; 263 264 if ($ID % $SkipLabels == 0) 265 { $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); } 266 else 267 { $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$ColorDotted); } 268 269 if ( $WriteLabels ) 270 { 271 $LabelX = cos(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX; 272 $LabelY = sin(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY; 273 274 if ( $LabelSerie != "" ) 275 { $Label = isset($Data["Series"][$LabelSerie]["Data"][$ID]) ? $Data["Series"][$LabelSerie]["Data"][$ID] : ""; } 276 else 277 $Label = $ID; 278 279 if ($ID % $SkipLabels == 0) 280 { 281 if ( $LabelPos == RADAR_LABELS_ROTATED ) 282 $Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-($i+$AxisRotation+$Axisoffset))-90,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); 283 else 284 { 285 if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); } 286 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); } 287 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); } 288 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); } 289 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); } 290 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); } 291 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); } 292 if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); } 293 } 294 } 295 } 296 $ID++; 297 } 298 299 /* Compute the plots position */ 300 $ID = 0; $Plot = ""; 301 foreach($Data["Series"] as $SerieName => $Data) 302 { 303 if ( $SerieName != $LabelSerie ) 304 { 305 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 306 foreach($Data["Data"] as $Key => $Value) 307 { 308 $Angle = (360/$Points) * $Key; 309 $Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value; 310 311 $X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX; 312 $Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY; 313 314 $Plot[$ID][] = array($X,$Y); 315 } 316 $ID++; 317 } 318 } 319 320 /* Draw all that stuff! */ 321 foreach($Plot as $ID => $Points) 322 { 323 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 324 325 /* Draw the polygons */ 326 if ( $DrawPoly ) 327 { 328 if ($PolyAlpha != NULL) 329 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding); 330 331 $PointsArray = ""; 332 for($i=0; $i<count($Points);$i++) 333 { $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; } 334 $Object->drawPolygon($PointsArray,$Color); 335 } 336 337 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 338 339 /* Draw the lines & points */ 340 for($i=0; $i<count($Points);$i++) 341 { 342 if ( $DrawLines && $i < count($Points)-1) 343 $Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color); 344 345 if ( $DrawPoints ) 346 $Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color); 347 } 348 349 /* Loop to the starting points if asked */ 350 if ( $LineLoopStart && $DrawLines ) 351 $Object->drawLine($Points[$i-1][0],$Points[$i-1][1],$Points[0][0],$Points[0][1],$Color); 352 353 } 354 } 355 356 357 358 /* Draw a radar chart */ 359 function drawPolar($Object,$Values,$Format="") 360 { 361 $this->pChartObject = $Object; 362 363 $AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60; 364 $AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60; 365 $AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60; 366 $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50; 367 $AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90; 368 $DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE; 369 $TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2; 370 $DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE; 371 $AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE; 372 $AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; 373 $AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; 374 $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE; 375 $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255; 376 $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255; 377 $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255; 378 $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50; 379 $BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL; 380 $AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20; 381 $SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO; 382 $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4; 383 $WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE; 384 $LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE; 385 $LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255; 386 $LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255; 387 $LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255; 388 $LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50; 389 $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED; 390 $LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4; 391 $DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE; 392 $PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4; 393 $PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30; 394 $DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE; 395 $LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : FALSE; 396 $DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE; 397 $PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : NULL; 398 $FontSize = $Object->FontSize; 399 $X1 = $Object->GraphAreaX1; 400 $Y1 = $Object->GraphAreaY1; 401 $X2 = $Object->GraphAreaX2; 402 $Y2 = $Object->GraphAreaY2; 403 404 if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; } 405 406 /* Cancel default tick length if ticks not enabled */ 407 if ( $DrawTicks == FALSE ) { $TicksLength = 0; } 408 409 /* Data Processing */ 410 $Data = $Values->getData(); 411 $Palette = $Values->getPalette(); 412 413 /* Catch the number of required axis */ 414 $LabelSerie = $Data["Abscissa"]; 415 if ( $LabelSerie != "" ) 416 { $Points = count($Data["Series"][$LabelSerie]["Data"]); } 417 else 418 { 419 $Points = 0; 420 foreach($Data["Series"] as $SerieName => $DataArray) 421 { if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } } 422 } 423 424 /* Draw the axis */ 425 $CenterX = ($X2-$X1)/2 + $X1; 426 $CenterY = ($Y2-$Y1)/2 + $Y1; 427 428 $EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2); 429 if ( $WriteLabels ) 430 $EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength; 431 432 /* Determine the scale if set to automatic */ 433 if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO) 434 { 435 $Max = 0; 436 foreach($Data["Series"] as $SerieName => $DataArray) 437 { 438 if ( $SerieName != $LabelSerie ) 439 { 440 if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); } 441 } 442 } 443 $MaxSegments = $EdgeHeight/20; 444 $Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5)); 445 446 $Segments = $Scale["Rows"]; 447 $SegmentHeight = $Scale["RowHeight"]; 448 } 449 450 451 /* Background processing */ 452 if ( $DrawBackground ) 453 { 454 $RestoreShadow = $Object->Shadow; 455 $Object->Shadow = FALSE; 456 457 if ($BackgroundGradient == NULL) 458 { 459 $Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha); 460 $Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color); 461 } 462 else 463 { 464 $GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments; 465 $GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments; 466 $GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments; 467 $GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments; 468 469 for($j=$Segments;$j>=1;$j--) 470 { 471 $Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j); 472 $Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color); 473 } 474 } 475 $Object->Shadow = $RestoreShadow; 476 } 477 478 /* Axis to axis lines */ 479 $Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha); 480 for($j=1;$j<=$Segments;$j++) 481 { 482 $Radius = ($EdgeHeight/$Segments)*$j; 483 $Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color); 484 } 485 486 if ( $DrawAxisValues ) 487 { 488 if ( $LabelsBackground ) 489 $Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha); 490 else 491 $Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE); 492 493 if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; } 494 495 $Options["FontName"] = $AxisFontName; 496 $Options["FontSize"] = $AxisFontSize; 497 498 $Angle = 360 / ($Points*2); 499 for($j=1;$j<=$Segments;$j++) 500 { 501 $EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; 502 $EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; 503 $Label = $j*$SegmentHeight; 504 505 $Object->drawText($EdgeX1,$EdgeY1,$Label,$Options); 506 } 507 } 508 509 /* Axis lines */ 510 $ID = 0; 511 for($i=0;$i<=359;$i=$i+$AxisSteps) 512 { 513 $EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX; 514 $EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY; 515 516 $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); 517 518 if ( $WriteLabels ) 519 { 520 $LabelX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX; 521 $LabelY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY; 522 $Label = $i."�"; 523 524 if ( $LabelPos == RADAR_LABELS_ROTATED ) 525 $Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-$i),"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); 526 else 527 { 528 if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); } 529 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); } 530 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); } 531 if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); } 532 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); } 533 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); } 534 if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); } 535 if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); } 536 } 537 } 538 $ID++; 539 } 540 541 /* Compute the plots position */ 542 $ID = 0; $Plot = ""; 543 foreach($Data["Series"] as $SerieName => $DataSet) 544 { 545 if ( $SerieName != $LabelSerie ) 546 { 547 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 548 foreach($DataSet["Data"] as $Key => $Value) 549 { 550 $Angle = $Data["Series"][$LabelSerie]["Data"][$Key]; 551 $Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value; 552 553 $X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX; 554 $Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY; 555 556 $Plot[$ID][] = array($X,$Y); 557 } 558 $ID++; 559 } 560 } 561 562 /* Draw all that stuff! */ 563 foreach($Plot as $ID => $Points) 564 { 565 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 566 567 /* Draw the polygons */ 568 if ( $DrawPoly ) 569 { 570 if ($PolyAlpha != NULL) 571 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding); 572 573 $PointsArray = ""; 574 for($i=0; $i<count($Points);$i++) 575 { $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; } 576 577 $Object->drawPolygon($PointsArray,$Color); 578 } 579 580 $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); 581 582 /* Draw the lines & points */ 583 for($i=0; $i<count($Points);$i++) 584 { 585 if ( $DrawLines && $i < count($Points)-1) 586 $Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color); 587 588 if ( $DrawPoints ) 589 $Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color); 590 } 591 592 /* Loop to the starting points if asked */ 593 if ( $LineLoopStart && $DrawLines ) 594 $Object->drawLine($Points[$i-1][0],$Points[$i-1][1],$Points[0][0],$Points[0][1],$Color); 595 } 596 } 597 } 598?>