/** * 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); } } }
/** * Draw a Scatter threshold area * @param int | float $Value1 * @param int | float $Value2 * @param array $Format * @return type */ public function drawScatterThresholdArea($Value1, $Value2, array $Format = array()) { $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0; $R = isset($Format["R"]) ? $Format["R"] : 255; $G = isset($Format["G"]) ? $Format["G"] : 0; $B = isset($Format["B"]) ? $Format["B"] : 0; $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20; $Border = isset($Format["Border"]) ? $Format["Border"] : true; $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R; $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G; $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B; $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20; $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2; $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : "La ouate de phoque"; //null; $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO; $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255; $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255; $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255; $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100; $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : true; if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); } $RestoreShadow = $this->pChartObject->Shadow; if ($DisableShadowOnArea && $this->pChartObject->Shadow) { $this->pChartObject->Shadow = false; } if ($BorderAlpha > 100) { $BorderAlpha = 100; } $Data = $this->pDataObject->getData(); if (!isset($Data["Axis"][$AxisID])) { return -1; } if ($Data["Axis"][$AxisID]["Identity"] == AXIS_X) { $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"]; $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"]; $X1 = $this->getPosArray($Value1, $AxisID); $X2 = $this->getPosArray($Value2, $AxisID); if ($X1 <= $this->pChartObject->GraphAreaX1) { $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"]; } if ($X2 >= $this->pChartObject->GraphAreaX2) { $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"]; } $this->pChartObject->drawFilledRectangle($X1, $Y1, $X2, $Y2, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha)); if ($Border) { $this->pChartObject->drawLine($X1, $Y1, $X1, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks)); $this->pChartObject->drawLine($X2, $Y1, $X2, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks)); } if ($AreaName != null) { $XPos = ($X2 - $X1) / 2 + $X1; $YPos = ($Y2 - $Y1) / 2 + $Y1; if ($NameAngle == ZONE_NAME_ANGLE_AUTO) { $TxtPos = $this->pChartObject->getTextBox($XPos, $YPos, $this->pChartObject->FontName, $this->pChartObject->FontSize, 0, $AreaName); $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"]; if (abs($X2 - $X1) > $TxtWidth) { $NameAngle = 0; } else { $NameAngle = 90; } } $this->pChartObject->Shadow = $RestoreShadow; $this->pChartObject->drawText($XPos, $YPos, $AreaName, array("R" => $NameR, "G" => $NameG, "B" => $NameB, "Alpha" => $NameAlpha, "Angle" => $NameAngle, "Align" => TEXT_ALIGN_MIDDLEMIDDLE)); if ($DisableShadowOnArea) { $this->pChartObject->Shadow = false; } } $this->pChartObject->Shadow = $RestoreShadow; return array("X1" => $X1, "X2" => $X2); } elseif ($Data["Axis"][$AxisID]["Identity"] == AXIS_Y) { $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"]; $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"]; $Y1 = $this->getPosArray($Value1, $AxisID); $Y2 = $this->getPosArray($Value2, $AxisID); if ($Y1 >= $this->pChartObject->GraphAreaY2) { $Y1 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"]; } if ($Y2 <= $this->pChartObject->GraphAreaY1) { $Y2 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"]; } $this->pChartObject->drawFilledRectangle($X1, $Y1, $X2, $Y2, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha)); if ($Border) { $this->pChartObject->drawLine($X1, $Y1, $X2, $Y1, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks)); $this->pChartObject->drawLine($X1, $Y2, $X2, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks)); } if ($AreaName != null) { $XPos = ($X2 - $X1) / 2 + $X1; $YPos = ($Y2 - $Y1) / 2 + $Y1; $this->pChartObject->Shadow = $RestoreShadow; $this->pChartObject->drawText($YPos, $XPos, $AreaName, array("R" => $NameR, "G" => $NameG, "B" => $NameB, "Alpha" => $NameAlpha, "Angle" => 0, "Align" => TEXT_ALIGN_MIDDLEMIDDLE)); if ($DisableShadowOnArea) { $this->Shadow = false; } } $this->pChartObject->Shadow = $RestoreShadow; return array("Y1" => $Y1, "Y2" => $Y2); } }