function request() { $this->query = "SELECT news.id AS id, title, text, view, DATE_FORMAT(news.date,'%d.%m.%Y') AS date,author,users.login AS authorLogin FROM news JOIN users ON news.author = users.id WHERE type = 1 OR type = 2 ORDER BY id DESC"; $getData = parent::getData(); $result = self::requestData($getData, $this->db); $this->dataCount = count($result); return $result; }
function getLastItems() { $this->query = "SELECT id,title FROM data ORDER BY date DESC, id DESC LIMIT 5"; $getData = parent::getData(); if (!$getData) { throw new DataException("Ошибка базы данных", "Запрос на выборку данных из базы не прошел. Напишите об этом администратору, Klymstalker@yandex.ua"); } $result = self::requestData($getData, $this->db); return $result; }
/** * Draw a radar chart * @param Image $Object * @param Data $Values * @param array $Format */ public function drawPolar(Image $Object, Data $Values, array $Format = array()) { $this->pChartObject = $Object; $FixedMax = isset($Format["FixedMax"]) ? $Format["FixedMax"] : VOID; $AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60; $AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60; $AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60; $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50; $AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90; $DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : true; $TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2; $DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : true; $AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : true; $AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; $AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : false; $WriteValuesInBubble = isset($Format["WriteValuesInBubble"]) ? $Format["WriteValuesInBubble"] : true; $ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName; $ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize; $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 4; $OuterBubbleRadius = isset($Format["OuterBubbleRadius"]) ? $Format["OuterBubbleRadius"] : 2; $OuterBubbleR = isset($Format["OuterBubbleR"]) ? $Format["OuterBubbleR"] : VOID; $OuterBubbleG = isset($Format["OuterBubbleG"]) ? $Format["OuterBubbleG"] : VOID; $OuterBubbleB = isset($Format["OuterBubbleB"]) ? $Format["OuterBubbleB"] : VOID; $OuterBubbleAlpha = isset($Format["OuterBubbleAlpha"]) ? $Format["OuterBubbleAlpha"] : 100; $InnerBubbleR = isset($Format["InnerBubbleR"]) ? $Format["InnerBubbleR"] : 255; $InnerBubbleG = isset($Format["InnerBubbleG"]) ? $Format["InnerBubbleG"] : 255; $InnerBubbleB = isset($Format["InnerBubbleB"]) ? $Format["InnerBubbleB"] : 255; $InnerBubbleAlpha = isset($Format["InnerBubbleAlpha"]) ? $Format["InnerBubbleAlpha"] : 100; $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : true; $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255; $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255; $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255; $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50; $BackgroundGradient = isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : null; $AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20; $SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO; $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4; $WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : true; $LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : true; $LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255; $LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255; $LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255; $LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50; $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED; $LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4; $DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : true; $PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4; $PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30; $DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : true; $LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : false; $DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : false; $PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : null; $FontSize = $Object->FontSize; $X1 = $Object->GraphAreaX1; $Y1 = $Object->GraphAreaY1; $X2 = $Object->GraphAreaX2; $Y2 = $Object->GraphAreaY2; $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false; if ($AxisBoxRounded) { $DrawAxisValues = true; } /* Cancel default tick length if ticks not enabled */ if ($DrawTicks == false) { $TicksLength = 0; } /* Data Processing */ $Data = $Values->getData(); $Palette = $Values->getPalette(); /* Catch the number of required axis */ $LabelSerie = $Data["Abscissa"]; if ($LabelSerie) { $Points = count($Data["Series"][$LabelSerie]["Data"]); } else { $Points = 0; foreach ($Data["Series"] as $SerieName => $DataArray) { if (count($DataArray["Data"]) > $Points) { $Points = count($DataArray["Data"]); } } } /* Draw the axis */ $CenterX = ($X2 - $X1) / 2 + $X1; $CenterY = ($Y2 - $Y1) / 2 + $Y1; $EdgeHeight = min(($X2 - $X1) / 2, ($Y2 - $Y1) / 2); if ($WriteLabels) { $EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength; } /* Determine the scale if set to automatic */ if ($SegmentHeight == SEGMENT_HEIGHT_AUTO) { if ($FixedMax != VOID) { $Max = $FixedMax; } else { $Max = 0; foreach ($Data["Series"] as $SerieName => $DataArray) { if ($SerieName != $LabelSerie) { if (max($DataArray["Data"]) > $Max) { $Max = max($DataArray["Data"]); } } } } $MaxSegments = $EdgeHeight / 20; $Scale = $Object->computeScale(0, $Max, $MaxSegments, array(1, 2, 5)); $Segments = $Scale["Rows"]; $SegmentHeight = $Scale["RowHeight"]; } /* Background processing */ if ($DrawBackground) { $RestoreShadow = $Object->Shadow; $Object->Shadow = false; if ($BackgroundGradient == null) { $Color = array("R" => $BackgroundR, "G" => $BackgroundG, "B" => $BackgroundB, "Alpha" => $BackgroundAlpha); $Object->drawFilledCircle($CenterX, $CenterY, $EdgeHeight, $Color); } else { $GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments; $GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments; $GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments; $GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments; for ($j = $Segments; $j >= 1; $j--) { $Color = array("R" => $BackgroundGradient["StartR"] + $GradientROffset * $j, "G" => $BackgroundGradient["StartG"] + $GradientGOffset * $j, "B" => $BackgroundGradient["StartB"] + $GradientBOffset * $j, "Alpha" => $BackgroundGradient["StartAlpha"] + $GradientAlphaOffset * $j); $Object->drawFilledCircle($CenterX, $CenterY, $EdgeHeight / $Segments * $j, $Color); } } $Object->Shadow = $RestoreShadow; } /* Axis to axis lines */ $Color = array("R" => $AxisR, "G" => $AxisG, "B" => $AxisB, "Alpha" => $AxisAlpha); for ($j = 1; $j <= $Segments; $j++) { $Radius = $EdgeHeight / $Segments * $j; $Object->drawCircle($CenterX, $CenterY, $Radius, $Radius, $Color); } if ($DrawAxisValues) { if ($LabelsBackground) { $Options = array("DrawBox" => true, "Align" => TEXT_ALIGN_MIDDLEMIDDLE, "BoxR" => $LabelsBGR, "BoxG" => $LabelsBGG, "BoxB" => $LabelsBGB, "BoxAlpha" => $LabelsBGAlpha); } else { $Options = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE); } if ($AxisBoxRounded) { $Options["BoxRounded"] = true; } $Options["FontName"] = $AxisFontName; $Options["FontSize"] = $AxisFontSize; $Angle = 360 / ($Points * 2); for ($j = 1; $j <= $Segments; $j++) { $EdgeX1 = cos(deg2rad($Angle + $AxisRotation)) * ($EdgeHeight / $Segments) * $j + $CenterX; $EdgeY1 = sin(deg2rad($Angle + $AxisRotation)) * ($EdgeHeight / $Segments) * $j + $CenterY; $Label = $j * $SegmentHeight; $Object->drawText($EdgeX1, $EdgeY1, $Label, $Options); } } /* Axis lines */ $ID = 0; for ($i = 0; $i <= 359; $i = $i + $AxisSteps) { $EdgeX = cos(deg2rad($i + $AxisRotation)) * ($EdgeHeight + $TicksLength) + $CenterX; $EdgeY = sin(deg2rad($i + $AxisRotation)) * ($EdgeHeight + $TicksLength) + $CenterY; $Object->drawLine($CenterX, $CenterY, $EdgeX, $EdgeY, $Color); if ($WriteLabels) { $LabelX = cos(deg2rad($i + $AxisRotation)) * ($EdgeHeight + $LabelPadding + $TicksLength) + $CenterX; $LabelY = sin(deg2rad($i + $AxisRotation)) * ($EdgeHeight + $LabelPadding + $TicksLength) + $CenterY; $Label = $i . "°"; if ($LabelPos == RADAR_LABELS_ROTATED) { $Object->drawText($LabelX, $LabelY, $Label, array("Angle" => 360 - $i, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); } else { if (floor($LabelX) == floor($CenterX) && floor($LabelY) < floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_BOTTOMMIDDLE)); } if (floor($LabelX) > floor($CenterX) && floor($LabelY) < floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_BOTTOMLEFT)); } if (floor($LabelX) > floor($CenterX) && floor($LabelY) == floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_MIDDLELEFT)); } if (floor($LabelX) > floor($CenterX) && floor($LabelY) > floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_TOPLEFT)); } if (floor($LabelX) < floor($CenterX) && floor($LabelY) < floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_BOTTOMRIGHT)); } if (floor($LabelX) < floor($CenterX) && floor($LabelY) == floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_MIDDLERIGHT)); } if (floor($LabelX) < floor($CenterX) && floor($LabelY) > floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_TOPRIGHT)); } if (floor($LabelX) == floor($CenterX) && floor($LabelY) > floor($CenterY)) { $Object->drawText($LabelX, $LabelY, $Label, array("Align" => TEXT_ALIGN_TOPMIDDLE)); } } } $ID++; } /* Compute the plots position */ $ID = 0; $Plot = array(); foreach ($Data["Series"] as $SerieName => $DataSet) { if ($SerieName != $LabelSerie) { $Color = array("R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"], "Alpha" => $Palette[$ID]["Alpha"], "Surrounding" => $PointSurrounding); foreach ($DataSet["Data"] as $Key => $Value) { $Angle = $Data["Series"][$LabelSerie]["Data"][$Key]; $Length = $EdgeHeight / ($Segments * $SegmentHeight) * $Value; $X = cos(deg2rad($Angle + $AxisRotation)) * $Length + $CenterX; $Y = sin(deg2rad($Angle + $AxisRotation)) * $Length + $CenterY; if ($RecordImageMap) { $this->pChartObject->addToImageMap("CIRCLE", sprintf("%s,%s,%s", floor($X), floor($Y), floor($PointRadius)), $this->pChartObject->toHTMLColor($Palette[$ID]["R"], $Palette[$ID]["G"], $Palette[$ID]["B"]), $DataSet["Description"], $Data["Series"][$LabelSerie]["Data"][$Key] . "° = " . $Value); } $Plot[$ID][] = array($X, $Y, $Value); } $ID++; } } /* Draw all that stuff! */ foreach ($Plot as $ID => $Points) { $Color = array("R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"], "Alpha" => $Palette[$ID]["Alpha"], "Surrounding" => $PointSurrounding); /* Draw the polygons */ if ($DrawPoly) { if ($PolyAlpha != null) { $Color = array("R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"], "Alpha" => $PolyAlpha, "Surrounding" => $PointSurrounding); } $PointsArray = array(); for ($i = 0; $i < count($Points); $i++) { $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; } $Object->drawPolygon($PointsArray, $Color); } $Color = array("R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"], "Alpha" => $Palette[$ID]["Alpha"], "Surrounding" => $PointSurrounding); /* Bubble and labels settings */ $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "FontName" => $ValueFontName, "FontSize" => $ValueFontSize, "R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"]); $InnerColor = array("R" => $InnerBubbleR, "G" => $InnerBubbleG, "B" => $InnerBubbleB, "Alpha" => $InnerBubbleAlpha); if ($OuterBubbleR != VOID) { $OuterColor = array("R" => $OuterBubbleR, "G" => $OuterBubbleG, "B" => $OuterBubbleB, "Alpha" => $OuterBubbleAlpha); } else { $OuterColor = array("R" => $Palette[$ID]["R"] + 20, "G" => $Palette[$ID]["G"] + 20, "B" => $Palette[$ID]["B"] + 20, "Alpha" => $Palette[$ID]["Alpha"]); } /* Loop to the starting points if asked */ if ($LineLoopStart && $DrawLines) { $Object->drawLine($Points[count($Points) - 1][0], $Points[count($Points) - 1][1], $Points[0][0], $Points[0][1], $Color); } /* Draw the lines & points */ for ($i = 0; $i < count($Points); $i++) { if ($DrawLines && $i < count($Points) - 1) { $Object->drawLine($Points[$i][0], $Points[$i][1], $Points[$i + 1][0], $Points[$i + 1][1], $Color); } if ($DrawPoints) { $Object->drawFilledCircle($Points[$i][0], $Points[$i][1], $PointRadius, $Color); } if ($WriteValuesInBubble && $WriteValues) { $TxtPos = $this->pChartObject->getTextBox($Points[$i][0], $Points[$i][1], $ValueFontName, $ValueFontSize, 0, $Points[$i][2]); $Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $ValuePadding * 2) / 2); $this->pChartObject->drawFilledCircle($Points[$i][0], $Points[$i][1], $Radius + $OuterBubbleRadius, $OuterColor); $this->pChartObject->drawFilledCircle($Points[$i][0], $Points[$i][1], $Radius, $InnerColor); } if ($WriteValues) { $this->pChartObject->drawText($Points[$i][0] - 1, $Points[$i][1] - 1, $Points[$i][2], $TextSettings); } } } }
/** * Draw a 3D ring chart * @param int $X * @param int $Y * @param array $Format * @return int */ public function draw3DRing($X, $Y, array $Format = array()) { $OuterRadius = isset($Format["OuterRadius"]) ? $Format["OuterRadius"] : 100; $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; $InnerRadius = isset($Format["InnerRadius"]) ? $Format["InnerRadius"] : 30; $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : 0.6; $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 10; $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 10; $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 10; $Border = isset($Format["Border"]) ? $Format["Border"] : false; $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : false; $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : false; $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : false; $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; $Cf = isset($Format["Cf"]) ? $Format["Cf"] : 20; $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : PIE_VALUE_NATURAL; $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : $SliceHeight + 15; $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false; /* Error correction for overlaying rounded corners */ if ($SkewFactor < 0.5) { $SkewFactor = 0.5; } /* Data Processing */ $Data = $this->pDataObject->getData(); $Palette = $this->pDataObject->getPalette(); /* Do we have an abscissa serie defined? */ if ($Data["Abscissa"] == "") { return PIE_NO_ABSCISSA; } /* Try to find the data serie */ $DataSerie = null; foreach ($Data["Series"] as $SerieName => $SerieData) { if ($SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } /* Do we have data to compute? */ if (!$DataSerie) { return PIE_NO_DATASERIE; } /* Remove unused data */ list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]); /* Compute the pie sum */ $SerieSum = $this->pDataObject->getSum($DataSerie); /* Do we have data to draw? */ if ($SerieSum == 0) { return PIE_SUMISNULL; } /* Dump the real number of data to draw */ $Values = array(); foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) { if ($Value != 0) { $Values[] = $Value; } } /* Compute the wasted angular space between series */ if (count($Values) == 1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } /* Compute the scale */ $ScaleFactor = (360 - $WastedAngular) / $SerieSum; $RestoreShadow = $this->pChartObject->Shadow; if ($this->pChartObject->Shadow) { $this->pChartObject->Shadow = false; } /* Draw the polygon ring elements */ $Offset = 360; $ID = count($Values) - 1; $Values = array_reverse($Values); $Slice = 0; $Slices = array(); $SliceColors = array(); $Visible = array(); $SliceAngle = array(); foreach ($Values as $Key => $Value) { if (!isset($Palette[$ID]["R"])) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID, $Color); } $Settings = array("R" => $Palette[$ID]["R"], "G" => $Palette[$ID]["G"], "B" => $Palette[$ID]["B"], "Alpha" => $Palette[$ID]["Alpha"]); $SliceColors[$Slice] = $Settings; $StartAngle = $Offset; $EndAngle = $Offset - $Value * $ScaleFactor; if ($EndAngle < 0) { $EndAngle = 0; } if ($StartAngle > 180) { $Visible[$Slice]["Start"] = true; } else { $Visible[$Slice]["Start"] = true; } if ($EndAngle < 180) { $Visible[$Slice]["End"] = false; } else { $Visible[$Slice]["End"] = true; } $Step = 360 / (2 * PI * $OuterRadius) / 2; $OutX1 = VOID; $OutY1 = VOID; for ($i = $Offset; $i >= $EndAngle; $i = $i - $Step) { $Xc = cos(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius - 2) + $X; $Yc = sin(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius - 2) * $SkewFactor + $Y; $Slices[$Slice]["AA"][] = array($Xc, $Yc); $Xc = cos(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius - 1) + $X; $Yc = sin(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius - 1) * $SkewFactor + $Y; $Slices[$Slice]["AA"][] = array($Xc, $Yc); $Xc = cos(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius) + $X; $Yc = sin(($i - 90) * PI / 180) * ($OuterRadius + $DataGapRadius) * $SkewFactor + $Y; $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings); if ($OutX1 == VOID) { $OutX1 = $Xc; $OutY1 = $Yc; } if ($i < 90) { $Yc++; } if ($i > 90 && $i < 180) { $Xc++; } if ($i > 180 && $i < 270) { $Xc++; } if ($i >= 270) { $Xc++; $Yc++; } $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc) - $SliceHeight; $Slices[$Slice]["Angle"][] = $i; } $OutX2 = $Xc; $OutY2 = $Yc; $Slices[$Slice]["Angle"][] = VOID; $Lasti = $i; $Step = 360 / (2 * PI * $InnerRadius) / 2; $InX1 = VOID; $InY1 = VOID; for ($i = $EndAngle; $i <= $Offset; $i = $i + $Step) { $Xc = cos(($i - 90) * PI / 180) * ($InnerRadius + $DataGapRadius - 1) + $X; $Yc = sin(($i - 90) * PI / 180) * ($InnerRadius + $DataGapRadius - 1) * $SkewFactor + $Y; $Slices[$Slice]["AA"][] = array($Xc, $Yc); $Xc = cos(($i - 90) * PI / 180) * ($InnerRadius + $DataGapRadius) + $X; $Yc = sin(($i - 90) * PI / 180) * ($InnerRadius + $DataGapRadius) * $SkewFactor + $Y; $Slices[$Slice]["AA"][] = array($Xc, $Yc); if ($InX1 == VOID) { $InX1 = $Xc; $InY1 = $Yc; } if ($i < 90) { $Yc++; } if ($i > 90 && $i < 180) { $Xc++; } if ($i > 180 && $i < 270) { $Xc++; } if ($i >= 270) { $Xc++; $Yc++; } $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc) - $SliceHeight; $Slices[$Slice]["Angle"][] = $i; } $InX2 = $Xc; $InY2 = $Yc; $Slices[$Slice]["InX1"] = $InX1; $Slices[$Slice]["InY1"] = $InY1; $Slices[$Slice]["InX2"] = $InX2; $Slices[$Slice]["InY2"] = $InY2; $Slices[$Slice]["OutX1"] = $OutX1; $Slices[$Slice]["OutY1"] = $OutY1; $Slices[$Slice]["OutX2"] = $OutX2; $Slices[$Slice]["OutY2"] = $OutY2; $Offset = $Lasti - $DataGapAngle; $ID--; $Slice++; } /* Draw the bottom pie splice */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $this->pChartObject->drawPolygon($Plots["BottomPoly"], $Settings); foreach ($Plots["AA"] as $Key => $Pos) { $this->pChartObject->drawAntialiasPixel($Pos[0], $Pos[1], $Settings); } $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"], $Plots["OutX2"], $Plots["OutY2"], $Settings); $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"], $Plots["OutX1"], $Plots["OutY1"], $Settings); } $Slices = array_reverse($Slices); $SliceColors = array_reverse($SliceColors); /* Draw the vertical edges (semi-visible) */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; $StartAngle = $Plots["Angle"][0]; foreach ($Plots["Angle"] as $Key => $Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } if ($StartAngle >= 270 || $StartAngle <= 90) { $this->pChartObject->drawLine($Plots["OutX1"], $Plots["OutY1"], $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); } if ($StartAngle >= 270 || $StartAngle <= 90) { $this->pChartObject->drawLine($Plots["OutX2"], $Plots["OutY2"], $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); } $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"], $Plots["InX1"], $Plots["InY1"] - $SliceHeight, $Settings); $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"], $Plots["InX2"], $Plots["InY2"] - $SliceHeight, $Settings); } /* Draw the inner vertical slices */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; $Outer = true; $Inner = false; $InnerPlotsA = array(); $InnerPlotsB = array(); foreach ($Plots["Angle"] as $ID => $Angle) { if ($Angle == VOID) { $Outer = false; $Inner = true; } elseif ($Inner && ($Angle < 90 || $Angle > 270) && isset($Plots["BottomPoly"][$ID * 2])) { $Xo = $Plots["BottomPoly"][$ID * 2]; $Yo = $Plots["BottomPoly"][$ID * 2 + 1]; $InnerPlotsA[] = $Xo; $InnerPlotsA[] = $Yo; $InnerPlotsB[] = $Xo; $InnerPlotsB[] = $Yo - $SliceHeight; } } if (count($InnerPlotsA)) { $InnerPlots = array_merge($InnerPlotsA, $this->arrayReverse($InnerPlotsB)); $this->pChartObject->drawPolygon($InnerPlots, $Settings); } } /* Draw the splice top and left poly */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf * 1.5; $Settings["G"] = $Settings["G"] + $Cf * 1.5; $Settings["B"] = $Settings["B"] + $Cf * 1.5; $StartAngle = $Plots["Angle"][0]; foreach ($Plots["Angle"] as $Key => $Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } if ($StartAngle < 180) { $Points = array(); $Points[] = $Plots["InX2"]; $Points[] = $Plots["InY2"]; $Points[] = $Plots["InX2"]; $Points[] = $Plots["InY2"] - $SliceHeight; $Points[] = $Plots["OutX1"]; $Points[] = $Plots["OutY1"] - $SliceHeight; $Points[] = $Plots["OutX1"]; $Points[] = $Plots["OutY1"]; $this->pChartObject->drawPolygon($Points, $Settings); } if ($EndAngle > 180) { $Points = array(); $Points[] = $Plots["InX1"]; $Points[] = $Plots["InY1"]; $Points[] = $Plots["InX1"]; $Points[] = $Plots["InY1"] - $SliceHeight; $Points[] = $Plots["OutX2"]; $Points[] = $Plots["OutY2"] - $SliceHeight; $Points[] = $Plots["OutX2"]; $Points[] = $Plots["OutY2"]; $this->pChartObject->drawPolygon($Points, $Settings); } } /* Draw the vertical edges (visible) */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; $StartAngle = $Plots["Angle"][0]; foreach ($Plots["Angle"] as $Key => $Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } if ($StartAngle <= 270 && $StartAngle >= 90) { $this->pChartObject->drawLine($Plots["OutX1"], $Plots["OutY1"], $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); } if ($EndAngle <= 270 && $EndAngle >= 90) { $this->pChartObject->drawLine($Plots["OutX2"], $Plots["OutY2"], $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); } } /* Draw the outer vertical slices */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; $Outer = true; $Inner = false; $OuterPlotsA = array(); $OuterPlotsB = array(); $InnerPlotsA = array(); $InnerPlotsB = array(); foreach ($Plots["Angle"] as $ID => $Angle) { if ($Angle == VOID) { $Outer = false; $Inner = true; } elseif ($Outer && ($Angle > 90 && $Angle < 270) && isset($Plots["BottomPoly"][$ID * 2])) { $Xo = $Plots["BottomPoly"][$ID * 2]; $Yo = $Plots["BottomPoly"][$ID * 2 + 1]; $OuterPlotsA[] = $Xo; $OuterPlotsA[] = $Yo; $OuterPlotsB[] = $Xo; $OuterPlotsB[] = $Yo - $SliceHeight; } } if (count($OuterPlotsA)) { $OuterPlots = array_merge($OuterPlotsA, $this->arrayReverse($OuterPlotsB)); $this->pChartObject->drawPolygon($OuterPlots, $Settings); } } $Slices = array_reverse($Slices); $SliceColors = array_reverse($SliceColors); /* Draw the top pie splice */ foreach ($Slices as $SliceID => $Plots) { $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = true; $Settings["R"] = $Settings["R"] + $Cf * 2; $Settings["G"] = $Settings["G"] + $Cf * 2; $Settings["B"] = $Settings["B"] + $Cf * 2; $this->pChartObject->drawPolygon($Plots["TopPoly"], $Settings); if ($RecordImageMap) { $this->pChartObject->addToImageMap("POLY", $this->arraySerialize($Plots["TopPoly"]), $this->pChartObject->toHTMLColor($Settings["R"], $Settings["G"], $Settings["B"]), $Data["Series"][$Data["Abscissa"]]["Data"][$SliceID], $Data["Series"][$DataSerie]["Data"][count($Slices) - $SliceID - 1]); } foreach ($Plots["AA"] as $Key => $Pos) { $this->pChartObject->drawAntialiasPixel($Pos[0], $Pos[1] - $SliceHeight, $Settings); } $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"] - $SliceHeight, $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"] - $SliceHeight, $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); } if ($DrawLabels) { $Offset = 360; foreach ($Values as $Key => $Value) { $StartAngle = $Offset; $EndAngle = $Offset - $Value * $ScaleFactor; if ($EndAngle < 0) { $EndAngle = 0; } if ($LabelColor == PIE_LABEL_COLOR_AUTO) { $Settings = array("FillR" => $Palette[$ID]["R"], "FillG" => $Palette[$ID]["G"], "FillB" => $Palette[$ID]["B"], "Alpha" => $Palette[$ID]["Alpha"]); } else { $Settings = array("FillR" => $LabelR, "FillG" => $LabelG, "FillB" => $LabelB, "Alpha" => $LabelAlpha); } $Angle = ($EndAngle - $Offset) / 2 + $Offset; $Xc = cos(($Angle - 90) * PI / 180) * ($OuterRadius + $DataGapRadius) + $X; $Yc = sin(($Angle - 90) * PI / 180) * ($OuterRadius + $DataGapRadius) * $SkewFactor + $Y; $Label = ""; if ($WriteValues == PIE_VALUE_PERCENTAGE) { $Label = $Display = round(100 / $SerieSum * $Value, $Precision) . "%"; } elseif ($WriteValues == PIE_VALUE_NATURAL) { $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; } if ($LabelStacked) { $this->writePieLabel($Xc, $Yc - $SliceHeight, $Label, $Angle, $Settings, true, $X, $Y, $OuterRadius); } else { $this->writePieLabel($Xc, $Yc - $SliceHeight, $Label, $Angle, $Settings, false); } $Offset = $EndAngle - $DataGapAngle; $ID--; $Slice++; } } if ($DrawLabels && $LabelStacked) { $this->writeShiftedLabels(); } $this->pChartObject->Shadow = $RestoreShadow; return PIE_RENDERED; }
<?php header('Content-type: application/json'); require_once 'Data.php'; require_once 'setHttpCode.php'; try { // Instantiate Data class $data = new Data(); // $_GET superglobal is only used to read // input parameters. It is not modified by // Data.php and extraneous parameters will // be ignored. All necessary parameters are // validated before being used by the system. $chartData = $data->getData($_GET); echo json_encode($chartData); } catch (Exception $e) { $message = (string) $e->getMessage(); $code = (int) $e->getCode(); $header = setHttpCode($code); // Set Header header($header); // Return JSON with display data die(json_encode(array('message' => $message))); }
function request() { $this->query = "SELECT * FROM categories"; return self::requestData(parent::getData()); }
/** * Get data. * * @param null|array $blocks Array of blocks (optional) * @return array */ public function getData(array $blocks = null) { return $this->Data->getData($blocks); }
/** * Get data. * * @param null|array $blocks Array of blocks (optional) * @param string $vargaKey Varga key (optional) * @return array */ public function getData(array $blocks = null, $vargaKey = Varga::KEY_D1) { return $this->Data->getData($blocks, $vargaKey); }
/** * Write labels * @param string $SeriesName * @param array $Indexes * @param array $Format */ public function writeLabel($SeriesName, $Indexes, array $Format = array()) { $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : null; $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : null; $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX; $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : false; $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0; $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0; $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0; $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40; $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2; $Data = $this->DataSet->getData(); list($XMargin, $XDivs) = $this->scaleGetXSettings(); if (!is_array($Indexes)) { $Index = $Indexes; $Indexes = array(); $Indexes[] = $Index; } if (!is_array($SeriesName)) { $SerieName = $SeriesName; $SeriesName = array(); $SeriesName[] = $SerieName; } if ($ForceLabels != null && !is_array($ForceLabels)) { $ForceLabel = $ForceLabels; $ForceLabels = array(); $ForceLabels[] = $ForceLabel; } foreach ($Indexes as $Key => $Index) { $Series = array(); if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) { if ($XDivs == 0) { $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1) / 4; } else { $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XMargin * 2) / $XDivs; } $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep; if ($DrawVerticalLine) { $this->drawLine($X, $this->GraphAreaY1 + $Data["YMargin"], $X, $this->GraphAreaY2 - $Data["YMargin"], array("R" => $VerticalLineR, "G" => $VerticalLineG, "B" => $VerticalLineB, "Alpha" => $VerticalLineAlpha, "Ticks" => $VerticalLineTicks)); } $MinY = $this->GraphAreaY2; foreach ($SeriesName as $iKey => $SerieName) { if (isset($Data["Series"][$SerieName]["Data"][$Index])) { $AxisID = $Data["Series"][$SerieName]["Axis"]; $XAxisMode = $Data["XAxisDisplay"]; $XAxisFormat = $Data["XAxisFormat"]; $XAxisUnit = $Data["XAxisUnit"]; $AxisMode = $Data["Axis"][$AxisID]["Display"]; $AxisFormat = $Data["Axis"][$AxisID]["Format"]; $AxisUnit = $Data["Axis"][$AxisID]["Unit"]; if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) { $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index], $XAxisMode, $XAxisFormat, $XAxisUnit); } else { $XLabel = ""; } if ($OverrideTitle != null) { $Description = $OverrideTitle; } elseif (count($SeriesName) == 1) { $Description = $Data["Series"][$SerieName]["Description"] . " - " . $XLabel; } elseif (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) { $Description = $XLabel; } $Serie = ""; $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"]; $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"]; $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"]; $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"]; if (count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"])) { $SerieOffset = $Data["Series"][$SerieName]["XOffset"]; } else { $SerieOffset = 0; } $Value = $Data["Series"][$SerieName]["Data"][$Index]; if ($Value == VOID) { $Value = "NaN"; } if ($ForceLabels != null) { $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set"; } else { $Caption = $this->scaleFormat($Value, $AxisMode, $AxisFormat, $AxisUnit); } if ($this->LastChartLayout == CHART_LAST_LAYOUT_STACKED) { if ($Value >= 0) { $LookFor = "+"; } else { $LookFor = "-"; } $Value = 0; $Done = false; foreach ($Data["Series"] as $Name => $SerieLookup) { if ($SerieLookup["isDrawable"] == true && $Name != $Data["Abscissa"] && !$Done) { if (isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID) { if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+") { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; } if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-") { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; } if ($Name == $SerieName) { $Done = true; } } } } } $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset); $Y = floor($this->scaleComputeY($Value, array("AxisID" => $AxisID))); if ($Y < $MinY) { $MinY = $Y; } if ($DrawPoint == LABEL_POINT_CIRCLE) { $this->drawFilledCircle($X, $Y, 3, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } elseif ($DrawPoint == LABEL_POINT_BOX) { $this->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } $Series[] = array("Format" => $Serie, "Caption" => $Caption); } } $this->drawLabelBox($X, $MinY - 3, $Description, $Series, $Format); } else { if ($XDivs == 0) { $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4; } else { $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs; } $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep; if ($DrawVerticalLine) { $this->drawLine($this->GraphAreaX1 + $Data["YMargin"], $Y, $this->GraphAreaX2 - $Data["YMargin"], $Y, array("R" => $VerticalLineR, "G" => $VerticalLineG, "B" => $VerticalLineB, "Alpha" => $VerticalLineAlpha, "Ticks" => $VerticalLineTicks)); } $MinX = $this->GraphAreaX2; foreach ($SeriesName as $Key => $SerieName) { if (isset($Data["Series"][$SerieName]["Data"][$Index])) { $AxisID = $Data["Series"][$SerieName]["Axis"]; $XAxisMode = $Data["XAxisDisplay"]; $XAxisFormat = $Data["XAxisFormat"]; $XAxisUnit = $Data["XAxisUnit"]; $AxisMode = $Data["Axis"][$AxisID]["Display"]; $AxisFormat = $Data["Axis"][$AxisID]["Format"]; $AxisUnit = $Data["Axis"][$AxisID]["Unit"]; if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) { $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index], $XAxisMode, $XAxisFormat, $XAxisUnit); } else { $XLabel = ""; } if ($OverrideTitle != null) { $Description = $OverrideTitle; } elseif (count($SeriesName) == 1) { if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) { $Description = $Data["Series"][$SerieName]["Description"] . " - " . $XLabel; } } elseif (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) { $Description = $XLabel; } $Serie = ""; if (isset($Data["Extended"]["Palette"][$Index])) { $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"]; $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"]; $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"]; $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"]; } else { $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"]; $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"]; $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"]; $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"]; } if (count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"])) { $SerieOffset = $Data["Series"][$SerieName]["XOffset"]; } else { $SerieOffset = 0; } $Value = $Data["Series"][$SerieName]["Data"][$Index]; if ($ForceLabels != null) { $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set"; } else { $Caption = $this->scaleFormat($Value, $AxisMode, $AxisFormat, $AxisUnit); } if ($Value == VOID) { $Value = "NaN"; } if ($this->LastChartLayout == CHART_LAST_LAYOUT_STACKED) { if ($Value >= 0) { $LookFor = "+"; } else { $LookFor = "-"; } $Value = 0; $Done = false; foreach ($Data["Series"] as $Name => $SerieLookup) { if ($SerieLookup["isDrawable"] == true && $Name != $Data["Abscissa"] && !$Done) { if (isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID) { if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+") { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; } if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-") { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; } if ($Name == $SerieName) { $Done = true; } } } } } $X = floor($this->scaleComputeY($Value, array("AxisID" => $AxisID))); $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset); if ($X < $MinX) { $MinX = $X; } if ($DrawPoint == LABEL_POINT_CIRCLE) { $this->drawFilledCircle($X, $Y, 3, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } elseif ($DrawPoint == LABEL_POINT_BOX) { $this->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } $Series[] = array("Format" => $Serie, "Caption" => $Caption); } } $this->drawLabelBox($MinX, $Y - 3, $Description, $Series, $Format); } } }
/** * Create the encoded string * @param Image $Object * @param Data $Values * @param array $Format */ public function drawSplitPath(Image $Object, Data $Values, array $Format = array()) { $this->pChartObject = $Object; $Spacing = isset($Format["Spacing"]) ? $Format["Spacing"] : 20; $TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 2; $TextPos = isset($Format["TextPos"]) ? $Format["TextPos"] : TEXT_POS_TOP; $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null; $Force = isset($Format["Force"]) ? $Format["Force"] : 70; $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 15; $X1 = $Object->GraphAreaX1; $Y1 = $Object->GraphAreaY1; $X2 = $Object->GraphAreaX2; $Y2 = $Object->GraphAreaY2; /* Data Processing */ $Data = $Values->getData(); $Palette = $Values->getPalette(); $LabelSerie = $Data["Abscissa"]; $DataSerie = array(); foreach ($Data["Series"] as $SerieName => $Value) { if ($SerieName != $LabelSerie && $DataSerie == "") { $DataSerie = $SerieName; } } $DataSerieSum = array_sum($Data["Series"][$DataSerie]["Data"]); $DataSerieCount = count($Data["Series"][$DataSerie]["Data"]); /* Scale Processing */ if ($TextPos == TEXT_POS_RIGHT) { $YScale = ($Y2 - $Y1 - ($DataSerieCount + 1) * $Spacing) / $DataSerieSum; } else { $YScale = ($Y2 - $Y1 - $DataSerieCount * $Spacing) / $DataSerieSum; } $LeftHeight = $DataSerieSum * $YScale; /* Re-compute graph width depending of the text mode choosen */ if ($TextPos == TEXT_POS_RIGHT) { $MaxWidth = 0; foreach ($Data["Series"][$LabelSerie]["Data"] as $Key => $Label) { $Boundardies = $Object->getTextBox(0, 0, $Object->FontName, $Object->FontSize, 0, $Label); if ($Boundardies[1]["X"] > $MaxWidth) { $MaxWidth = $Boundardies[1]["X"] + $TextPadding * 2; } } $X2 = $X2 - $MaxWidth; } /* Drawing */ $LeftY = ($Y2 - $Y1) / 2 + $Y1 - $LeftHeight / 2; $RightY = $Y1; foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) { if (isset($Data["Series"][$LabelSerie]["Data"][$Key])) { $Label = $Data["Series"][$LabelSerie]["Data"][$Key]; } else { $Label = "-"; } $LeftY1 = $LeftY; $LeftY2 = $LeftY + $Value * $YScale; $RightY1 = $RightY + $Spacing; $RightY2 = $RightY + $Spacing + $Value * $YScale; $Settings = array("R" => $Palette[$Key]["R"], "G" => $Palette[$Key]["G"], "B" => $Palette[$Key]["B"], "Alpha" => $Palette[$Key]["Alpha"], "NoDraw" => true, "Segments" => $Segments, "Surrounding" => $Surrounding); $PolyGon = ""; $Angle = $Object->getAngle($X2, $RightY1, $X1, $LeftY1); $VectorX1 = cos(deg2rad($Angle + 90)) * $Force + ($X2 - $X1) / 2 + $X1; $VectorY1 = sin(deg2rad($Angle + 90)) * $Force + ($RightY1 - $LeftY1) / 2 + $LeftY1; $VectorX2 = cos(deg2rad($Angle - 90)) * $Force + ($X2 - $X1) / 2 + $X1; $VectorY2 = sin(deg2rad($Angle - 90)) * $Force + ($RightY1 - $LeftY1) / 2 + $LeftY1; $Points = $Object->drawBezier($X1, $LeftY1, $X2, $RightY1, $VectorX1, $VectorY1, $VectorX2, $VectorY2, $Settings); foreach ($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; } $Angle = $Object->getAngle($X2, $RightY2, $X1, $LeftY2); $VectorX1 = cos(deg2rad($Angle + 90)) * $Force + ($X2 - $X1) / 2 + $X1; $VectorY1 = sin(deg2rad($Angle + 90)) * $Force + ($RightY2 - $LeftY2) / 2 + $LeftY2; $VectorX2 = cos(deg2rad($Angle - 90)) * $Force + ($X2 - $X1) / 2 + $X1; $VectorY2 = sin(deg2rad($Angle - 90)) * $Force + ($RightY2 - $LeftY2) / 2 + $LeftY2; $Points = $Object->drawBezier($X1, $LeftY2, $X2, $RightY2, $VectorX1, $VectorY1, $VectorX2, $VectorY2, $Settings); $Points = array_reverse($Points); foreach ($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; } $Object->drawPolygon($PolyGon, $Settings); if ($TextPos == TEXT_POS_RIGHT) { $Object->drawText($X2 + $TextPadding, ($RightY2 - $RightY1) / 2 + $RightY1, $Label, array("Align" => TEXT_ALIGN_MIDDLELEFT)); } else { $Object->drawText($X2, $RightY1 - $TextPadding, $Label, array("Align" => TEXT_ALIGN_BOTTOMRIGHT)); } $LeftY = $LeftY2; $RightY = $RightY2; } }
public function writeBubbleLabel($SerieName, $SerieWeightName, $Points, $Format = "") { $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX; if (!is_array($Points)) { $Point = $Points; $Points = array(); $Points[] = $Point; } $Data = $this->pDataObject->getData(); if (!isset($Data["Series"][$SerieName]) || !isset($Data["Series"][$SerieWeightName])) { return 0; } list($XMargin, $XDivs) = $this->pChartObject->scaleGetXSettings(); $AxisID = $Data["Series"][$SerieName]["Axis"]; $AxisMode = $Data["Axis"][$AxisID]["Display"]; $AxisFormat = $Data["Axis"][$AxisID]["Format"]; $AxisUnit = $Data["Axis"][$AxisID]["Unit"]; $XStep = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1 - $XMargin * 2) / $XDivs; $X = $InitialX = $this->pChartObject->GraphAreaX1 + $XMargin; $Y = $InitialY = $this->pChartObject->GraphAreaY1 + $XMargin; $Color = array("R" => $Data["Series"][$SerieName]["Color"]["R"], "G" => $Data["Series"][$SerieName]["Color"]["G"], "B" => $Data["Series"][$SerieName]["Color"]["B"], "Alpha" => $Data["Series"][$SerieName]["Color"]["Alpha"]); foreach ($Points as $Key => $Point) { $Value = $Data["Series"][$SerieName]["Data"][$Point]; $PosArray = $this->pChartObject->scaleComputeY($Value, array("AxisID" => $AxisID)); if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Point])) { $Abscissa = $Data["Series"][$Data["Abscissa"]]["Data"][$Point] . " : "; } else { $Abscissa = ""; } $Value = $this->pChartObject->scaleFormat($Value, $AxisMode, $AxisFormat, $AxisUnit); $Weight = $Data["Series"][$SerieWeightName]["Data"][$Point]; $Caption = $Abscissa . $Value . " / " . $Weight; if (isset($Data["Series"][$SerieName]["Description"])) { $Description = $Data["Series"][$SerieName]["Description"]; } else { $Description = "No description"; } $Series = ""; $Series[] = array("Format" => $Color, "Caption" => $Caption); if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) { if ($XDivs == 0) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1 - $XMargin * 2) / $XDivs; } $X = floor($InitialX + $Point * $XStep); $Y = floor($PosArray); } else { if ($XDivs == 0) { $YStep = 0; } else { $YStep = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1 - $XMargin * 2) / $XDivs; } $X = floor($PosArray); $Y = floor($InitialY + $Point * $YStep); } if ($DrawPoint == LABEL_POINT_CIRCLE) { $this->pChartObject->drawFilledCircle($X, $Y, 3, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } elseif ($DrawPoint == LABEL_POINT_BOX) { $this->pChartObject->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array("R" => 255, "G" => 255, "B" => 255, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); } $this->pChartObject->drawLabelBox($X, $Y - 3, $Description, $Series, $Format); } }
public function testGetData() { $wrappedData = new Data(array('wrapped' => array('sampleData' => $this->getSampleData()))); $data = $wrappedData->getData('wrapped.sampleData'); $this->runSampleDataTests($data); $this->setExpectedException('RuntimeException'); $data = $wrappedData->getData('wrapped.sampleData.a'); }
/** * Get environment. * * @return array */ public function getEnvironment() { return $this->Data->getData(); }
<table> <? foreach(Data::getData('students') as $student) { ?> <tr> <td><?php echo $student['FirstName']; ?> </td> <td><?php echo $student['LastName']; ?> </td> <td><?php echo $student['BirthDate']; ?> </td> <td> <a href="students.php?del_id=<?php echo $student['StudentId']; ?> ">X</a> </td> </tr> <? } ?> </table>