function pChart::drawRadarAxis in Visitors 7.0
Same name and namespace in other branches
- 8 pchart/pChart.inc \pChart::drawRadarAxis()
File
- pchart/
pChart.inc, line 1475
Class
Code
function drawRadarAxis(&$Data, &$DataDescription, $Mosaic = TRUE, $BorderOffset = 10, $A_R = 60, $A_G = 60, $A_B = 60, $S_R = 200, $S_G = 200, $S_B = 200, $MaxValue = -1) {
/* Validate the Data and DataDescription array */
$this
->validateDataDescription("drawRadarAxis", $DataDescription);
$this
->validateData("drawRadarAxis", $Data);
$C_TextColor = imagecolorallocate($this->Picture, $A_R, $A_G, $A_B);
/* Draw radar axis */
$Points = count($Data);
$Radius = ($this->GArea_Y2 - $this->GArea_Y1) / 2 - $BorderOffset;
$XCenter = ($this->GArea_X2 - $this->GArea_X1) / 2 + $this->GArea_X1;
$YCenter = ($this->GArea_Y2 - $this->GArea_Y1) / 2 + $this->GArea_Y1;
/* Search for the max value */
if ($MaxValue == -1) {
foreach ($DataDescription["Values"] as $Key2 => $ColName) {
foreach ($Data as $Key => $Values) {
if (isset($Data[$Key][$ColName])) {
if ($Data[$Key][$ColName] > $MaxValue) {
$MaxValue = $Data[$Key][$ColName];
}
}
}
}
}
/* Draw the mosaic */
if ($Mosaic) {
$RadiusScale = $Radius / $MaxValue;
for ($t = 1; $t <= $MaxValue - 1; $t++) {
$TRadius = $RadiusScale * $t;
$LastX1 = -1;
for ($i = 0; $i <= $Points; $i++) {
$Angle = -90 + $i * 360 / $Points;
$X1 = cos($Angle * 3.1418 / 180) * $TRadius + $XCenter;
$Y1 = sin($Angle * 3.1418 / 180) * $TRadius + $YCenter;
$X2 = cos($Angle * 3.1418 / 180) * ($TRadius + $RadiusScale) + $XCenter;
$Y2 = sin($Angle * 3.1418 / 180) * ($TRadius + $RadiusScale) + $YCenter;
if ($t % 2 == 1 && $LastX1 != -1) {
$Plots = "";
$Plots[] = $X1;
$Plots[] = $Y1;
$Plots[] = $X2;
$Plots[] = $Y2;
$Plots[] = $LastX2;
$Plots[] = $LastY2;
$Plots[] = $LastX1;
$Plots[] = $LastY1;
$C_Graph = imagecolorallocate($this->Picture, 250, 250, 250);
imagefilledpolygon($this->Picture, $Plots, (count($Plots) + 1) / 2, $C_Graph);
}
$LastX1 = $X1;
$LastY1 = $Y1;
$LastX2 = $X2;
$LastY2 = $Y2;
}
}
}
/* Draw the spider web */
for ($t = 1; $t <= $MaxValue; $t++) {
$TRadius = $Radius / $MaxValue * $t;
$LastX = -1;
for ($i = 0; $i <= $Points; $i++) {
$Angle = -90 + $i * 360 / $Points;
$X = cos($Angle * 3.1418 / 180) * $TRadius + $XCenter;
$Y = sin($Angle * 3.1418 / 180) * $TRadius + $YCenter;
if ($LastX != -1) {
$this
->drawDottedLine($LastX, $LastY, $X, $Y, 4, $S_R, $S_G, $S_B);
}
$LastX = $X;
$LastY = $Y;
}
}
/* Draw the axis */
for ($i = 0; $i <= $Points; $i++) {
$Angle = -90 + $i * 360 / $Points;
$X = cos($Angle * 3.1418 / 180) * $Radius + $XCenter;
$Y = sin($Angle * 3.1418 / 180) * $Radius + $YCenter;
$this
->drawLine($XCenter, $YCenter, $X, $Y, $A_R, $A_G, $A_B);
$XOffset = 0;
$YOffset = 0;
if (isset($Data[$i][$DataDescription["Position"]])) {
$Label = $Data[$i][$DataDescription["Position"]];
$Positions = imagettfbbox($this->FontSize, 0, $this->FontName, $Label);
$Width = $Positions[2] - $Positions[6];
$Height = $Positions[3] - $Positions[7];
if ($Angle >= 0 && $Angle <= 90) {
$YOffset = $Height;
}
if ($Angle > 90 && $Angle <= 180) {
$YOffset = $Height;
$XOffset = -$Width;
}
if ($Angle > 180 && $Angle <= 270) {
$XOffset = -$Width;
}
imagettftext($this->Picture, $this->FontSize, 0, $X + $XOffset, $Y + $YOffset, $C_TextColor, $this->FontName, $Label);
}
}
/* Write the values */
for ($t = 1; $t <= $MaxValue; $t++) {
$TRadius = $Radius / $MaxValue * $t;
$Angle = -90 + 360 / $Points;
$X1 = $XCenter;
$Y1 = $YCenter - $TRadius;
$X2 = cos($Angle * 3.1418 / 180) * $TRadius + $XCenter;
$Y2 = sin($Angle * 3.1418 / 180) * $TRadius + $YCenter;
$XPos = floor(($X2 - $X1) / 2) + $X1;
$YPos = floor(($Y2 - $Y1) / 2) + $Y1;
$Positions = imagettfbbox($this->FontSize, 0, $this->FontName, $t);
$X = $XPos - ($X + $Positions[2] - $X + $Positions[6]) / 2;
$Y = $YPos + $this->FontSize;
$this
->drawFilledRoundedRectangle($X + $Positions[6] - 2, $Y + $Positions[7] - 1, $X + $Positions[2] + 4, $Y + $Positions[3] + 1, 2, 240, 240, 240);
$this
->drawRoundedRectangle($X + $Positions[6] - 2, $Y + $Positions[7] - 1, $X + $Positions[2] + 4, $Y + $Positions[3] + 1, 2, 220, 220, 220);
imagettftext($this->Picture, $this->FontSize, 0, $X, $Y, $C_TextColor, $this->FontName, $t);
}
}