Draw a label with associated arrow
@param int $X1
@param int $Y1
@param string $Text
@param array $Format
963715
public function drawArrowLabel($X1, $Y1, $Text, array $Format = [])
    {
        $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
        $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
        $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
        $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
        $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
        $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
        $FontName = isset($Format["FontName"]) ? $this->loadFont($Format["FontName"], 'fonts') : $this->FontName;
        $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
        $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
        $Length = isset($Format["Length"]) ? $Format["Length"] : 50;
        $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 315;
        $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
        $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
        $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : false;
        $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : null;

        $Angle = $Angle % 360;

        $X2 = sin(($Angle + 180) * PI / 180) * $Length + $X1;
        $Y2 = cos(($Angle + 180) * PI / 180) * $Length + $Y1;

        if ($RoundPos && $Angle > 0 && $Angle < 180) {
            $Y2 = ceil($Y2);
        }
        if ($RoundPos && $Angle > 180) {
            $Y2 = floor($Y2);
        }

        $this->drawArrow($X2, $Y2, $X1, $Y1, $Format);

        $Size = imagettfbbox($FontSize, 0, $FontName, $Text);
        $TxtWidth = max(abs($Size[2] - $Size[0]), abs($Size[0] - $Size[6]));

        if ($Angle > 0 && $Angle < 180) {
            $this->drawLine(
                $X2,
                $Y2,
                $X2 - $TxtWidth,
                $Y2,
                ["R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks]
            );
            if ($Position == POSITION_TOP) {
                $this->drawText(
                    $X2,
                    $Y2 - 2,
                    $Text,
                    [
                        "R" => $BorderR,
                        "G" => $BorderG,
                        "B" => $BorderB,
                        "Alpha" => $Alpha,
                        "Align" => TEXT_ALIGN_BOTTOMRIGHT
                    ]
                );
            } else {
                $this->drawText(
                    $X2,
                    $Y2 + 4,
                    $Text,
                    [
                        "R" => $BorderR,
                        "G" => $BorderG,
                        "B" => $BorderB,
                        "Alpha" => $Alpha,
                        "Align" => TEXT_ALIGN_TOPRIGHT
                    ]
                );
            }
        } else {
            $this->drawLine(
                $X2,
                $Y2,
                $X2 + $TxtWidth,
                $Y2,
                ["R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks]
            );
            if ($Position == POSITION_TOP) {
                $this->drawText(
                    $X2,
                    $Y2 - 2,
                    $Text,
                    ["R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha]
                );
            } else {
                $this->drawText(
                    $X2,
                    $Y2 + 4,
                    $Text,
                    [
                        "R" => $BorderR,
                        "G" => $BorderG,
                        "B" => $BorderB,
                        "Alpha" => $Alpha,
                        "Align" => TEXT_ALIGN_TOPLEFT
                    ]
                );
            }
        }
    }
795021
private function text($text, $size, $x, $y, $color = 'black', $font = 'swiss_normal', $angle = 0)
    {
        imagettftext($this->image, $size, $angle, $x, $y, $this->colors[$color], $this->fonts[$font], $text);
    }
826012
public function format($text = '', string $style = 'none')
    {
        return $this->getStartMark($style) . $text . $this->getClearMark();
    }
583941
public function drawBarChart(array $Format = [])
    {
        $Floating0Serie = isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : null;
        $Floating0Value = isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : null;
        $Draw0Line = isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : false;
        $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : false;
        $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
        $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
        $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
        $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
        $DisplayPos = isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
        $DisplayShadow = isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : true;
        $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
        $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
        $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
        $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : true;
        $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
        $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : false;
        $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
        $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null;
        $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
        $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
        $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
        $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : false;
        $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
        $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
        $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
        $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
        $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
        $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
        $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
        $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
        $TxtMargin = isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
        $OverrideColors = isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : null;
        $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
        $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : null;
        $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
        $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
        $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
        $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false;

        $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;

        $Data = $this->DataSet->getData();
        list($XMargin, $XDivs) = $this->scaleGetXSettings();

        if ($OverrideColors != null) {
            $OverrideColors = $this->validatePalette($OverrideColors, $OverrideSurrounding);
            $this->DataSet->saveExtendedData("Palette", $OverrideColors);
        }

        $RestoreShadow = $this->Shadow;

        $SeriesCount = $this->countDrawableSeries();
        $CurrentSerie = 0;
        foreach ($Data["Series"] as $SerieName => $Serie) {
            if ($Serie["isDrawable"] == true && $SerieName != $Data["Abscissa"]) {
                $R = $Serie["Color"]["R"];
                $G = $Serie["Color"]["G"];
                $B = $Serie["Color"]["B"];
                $Alpha = $Serie["Color"]["Alpha"];
                $Ticks = $Serie["Ticks"];
                if ($DisplayColor == DISPLAY_AUTO) {
                    $DisplayR = $R;
                    $DisplayG = $G;
                    $DisplayB = $B;
                }
                if ($Surrounding != null) {
                    $BorderR = $R + $Surrounding;
                    $BorderG = $G + $Surrounding;
                    $BorderB = $B + $Surrounding;
                }
                if ($InnerSurrounding != null) {
                    $InnerBorderR = $R + $InnerSurrounding;
                    $InnerBorderG = $G + $InnerSurrounding;
                    $InnerBorderB = $B + $InnerSurrounding;
                }
                if ($InnerBorderR == -1) {
                    $InnerColor = null;
                } else {
                    $InnerColor = [
                        "R" => $InnerBorderR,
                        "G" => $InnerBorderG,
                        "B" => $InnerBorderB
                    ];
                }
                $Color = [
                    "R" => $R,
                    "G" => $G,
                    "B" => $B,
                    "Alpha" => $Alpha,
                    "BorderR" => $BorderR,
                    "BorderG" => $BorderG,
                    "BorderB" => $BorderB
                ];

                $AxisID = $Serie["Axis"];
                $Mode = $Data["Axis"][$AxisID]["Display"];
                $Format = $Data["Axis"][$AxisID]["Format"];
                $Unit = $Data["Axis"][$AxisID]["Unit"];

                if (isset($Serie["Description"])) {
                    $SerieDescription = $Serie["Description"];
                } else {
                    $SerieDescription = $SerieName;
                }

                $PosArray = $this->scaleComputeY(
                    $Serie["Data"],
                    ["AxisID" => $Serie["Axis"]]
                );

                if ($Floating0Value != null) {
                    $YZero = $this->scaleComputeY(
                        $Floating0Value,
                        ["AxisID" => $Serie["Axis"]]
                    );
                } else {
                    $YZero = $this->scaleComputeY(0, ["AxisID" => $Serie["Axis"]]);
                }

                if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
                    if ($YZero > $this->GraphAreaY2 - 1) {
                        $YZero = $this->GraphAreaY2 - 1;
                    }
                    if ($YZero < $this->GraphAreaY1 + 1) {
                        $YZero = $this->GraphAreaY1 + 1;
                    }

                    if ($XDivs == 0) {
                        $XStep = 0;
                    } else {
                        $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XMargin * 2) / $XDivs;
                    }
                    $X = $this->GraphAreaX1 + $XMargin;

                    if ($AroundZero) {
                        $Y1 = $YZero;
                    } else {
                        $Y1 = $this->GraphAreaY2 - 1;
                    }
                    if ($XDivs == 0) {
                        $XSize = ($this->GraphAreaX2 - $this->GraphAreaX1) / ($SeriesCount + $Interleave);
                    } else {
                        $XSize = ($XStep / ($SeriesCount + $Interleave));
                    }

                    $XOffset = -($XSize * $SeriesCount) / 2 + $CurrentSerie * $XSize;
                    if ($X + $XOffset <= $this->GraphAreaX1) {
                        $XOffset = $this->GraphAreaX1 - $X + 1;
                    }

                    $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;

                    if ($Rounded || $BorderR != -1) {
                        $XSpace = 1;
                    } else {
                        $XSpace = 0;
                    }

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }

                    $ID = 0;
                    foreach ($PosArray as $Key => $Y2) {
                        if ($Floating0Serie != null) {
                            if (isset($Data["Series"][$Floating0Serie]["Data"][$Key])) {
                                $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
                            } else {
                                $Value = 0;
                            }

                            $YZero = $this->scaleComputeY($Value, ["AxisID" => $Serie["Axis"]]);
                            if ($YZero > $this->GraphAreaY2 - 1) {
                                $YZero = $this->GraphAreaY2 - 1;
                            }
                            if ($YZero < $this->GraphAreaY1 + 1) {
                                $YZero = $this->GraphAreaY1 + 1;
                            }

                            if ($AroundZero) {
                                $Y1 = $YZero;
                            } else {
                                $Y1 = $this->GraphAreaY2 - 1;
                            }
                        }

                        if ($OverrideColors != null) {
                            if (isset($OverrideColors[$ID])) {
                                $Color = [
                                    "R" => $OverrideColors[$ID]["R"],
                                    "G" => $OverrideColors[$ID]["G"],
                                    "B" => $OverrideColors[$ID]["B"],
                                    "Alpha" => $OverrideColors[$ID]["Alpha"],
                                    "BorderR" => $OverrideColors[$ID]["BorderR"],
                                    "BorderG" => $OverrideColors[$ID]["BorderG"],
                                    "BorderB" => $OverrideColors[$ID]["BorderB"]
                                ];
                            } else {
                                $Color = $this->getRandomColor();
                            }
                        }

                        if ($Y2 != VOID) {
                            $BarHeight = $Y1 - $Y2;

                            if ($Serie["Data"][$Key] == 0) {
                                $this->drawLine(
                                    $X + $XOffset + $XSpace,
                                    $Y1,
                                    $X + $XOffset + $XSize - $XSpace,
                                    $Y1,
                                    $Color
                                );
                                if ($RecordImageMap) {
                                    $this->addToImageMap(
                                        "RECT",
                                        sprintf(
                                            "%s,%s,%s,%s",
                                            floor($X + $XOffset + $XSpace),
                                            floor($Y1 - 1),
                                            floor($X + $XOffset + $XSize - $XSpace),
                                            floor($Y1 + 1)
                                        ),
                                        $this->toHTMLColor($R, $G, $B),
                                        $SerieDescription,
                                        $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                                    );
                                }
                            } else {
                                if ($RecordImageMap) {
                                    $this->addToImageMap(
                                        "RECT",
                                        sprintf(
                                            "%s,%s,%s,%s,%s",
                                            floor($X + $XOffset + $XSpace),
                                            floor($Y1),
                                            floor($X + $XOffset + $XSize - $XSpace),
                                            floor($Y2),
                                            $this->toHTMLColor($R, $G, $B)
                                        ),
                                        $SerieDescription,
                                        $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                                    );
                                }

                                if ($Rounded) {
                                    $this->drawRoundedFilledRectangle(
                                        $X + $XOffset + $XSpace,
                                        $Y1,
                                        $X + $XOffset + $XSize - $XSpace,
                                        $Y2,
                                        $RoundRadius,
                                        $Color
                                    );
                                } else {
                                    $this->drawFilledRectangle(
                                        $X + $XOffset + $XSpace,
                                        $Y1,
                                        $X + $XOffset + $XSize - $XSpace,
                                        $Y2,
                                        $Color
                                    );

                                    if ($InnerColor != null) {
                                        $this->drawRectangle(
                                            $X + $XOffset + $XSpace + 1,
                                            min($Y1, $Y2) + 1,
                                            $X + $XOffset + $XSize - $XSpace - 1,
                                            max($Y1, $Y2) - 1,
                                            $InnerColor
                                        );
                                    }

                                    if ($Gradient) {
                                        $this->Shadow = false;

                                        if ($GradientMode == GRADIENT_SIMPLE) {
                                            if ($Serie["Data"][$Key] >= 0) {
                                                $GradienColor = [
                                                    "StartR" => $GradientStartR,
                                                    "StartG" => $GradientStartG,
                                                    "StartB" => $GradientStartB,
                                                    "EndR" => $GradientEndR,
                                                    "EndG" => $GradientEndG,
                                                    "EndB" => $GradientEndB,
                                                    "Alpha" => $GradientAlpha
                                                ];
                                            } else {
                                                $GradienColor = [
                                                    "StartR" => $GradientEndR,
                                                    "StartG" => $GradientEndG,
                                                    "StartB" => $GradientEndB,
                                                    "EndR" => $GradientStartR,
                                                    "EndG" => $GradientStartG,
                                                    "EndB" => $GradientStartB,
                                                    "Alpha" => $GradientAlpha
                                                ];
                                            }
                                            $this->drawGradientArea(
                                                $X + $XOffset + $XSpace,
                                                $Y1,
                                                $X + $XOffset + $XSize - $XSpace,
                                                $Y2,
                                                DIRECTION_VERTICAL,
                                                $GradienColor
                                            );
                                        } elseif ($GradientMode == GRADIENT_EFFECT_CAN) {
                                            $GradienColor1 = [
                                                "StartR" => $GradientEndR,
                                                "StartG" => $GradientEndG,
                                                "StartB" => $GradientEndB,
                                                "EndR" => $GradientStartR,
                                                "EndG" => $GradientStartG,
                                                "EndB" => $GradientStartB,
                                                "Alpha" => $GradientAlpha
                                            ];
                                            $GradienColor2 = [
                                                "StartR" => $GradientStartR,
                                                "StartG" => $GradientStartG,
                                                "StartB" => $GradientStartB,
                                                "EndR" => $GradientEndR,
                                                "EndG" => $GradientEndG,
                                                "EndB" => $GradientEndB,
                                                "Alpha" => $GradientAlpha
                                            ];
                                            $XSpan = floor($XSize / 3);

                                            $this->drawGradientArea(
                                                $X + $XOffset + $XSpace,
                                                $Y1,
                                                $X + $XOffset + $XSpan - $XSpace,
                                                $Y2,
                                                DIRECTION_HORIZONTAL,
                                                $GradienColor1
                                            );
                                            $this->drawGradientArea(
                                                $X + $XOffset + $XSpan + $XSpace,
                                                $Y1,
                                                $X + $XOffset + $XSize - $XSpace,
                                                $Y2,
                                                DIRECTION_HORIZONTAL,
                                                $GradienColor2
                                            );
                                        }
                                        $this->Shadow = $RestoreShadow;
                                    }
                                }

                                if ($Draw0Line) {
                                    $Line0Color = ["R" => 0, "G" => 0, "B" => 0, "Alpha" => 20];

                                    if (abs($Y1 - $Y2) > 3) {
                                        $Line0Width = 3;
                                    } else {
                                        $Line0Width = 1;
                                    }
                                    if ($Y1 - $Y2 < 0) {
                                        $Line0Width = -$Line0Width;
                                    }

                                    $this->drawFilledRectangle(
                                        $X + $XOffset + $XSpace,
                                        floor($Y1),
                                        $X + $XOffset + $XSize - $XSpace,
                                        floor($Y1) - $Line0Width,
                                        $Line0Color
                                    );
                                    $this->drawLine(
                                        $X + $XOffset + $XSpace,
                                        floor($Y1),
                                        $X + $XOffset + $XSize - $XSpace,
                                        floor($Y1),
                                        $Line0Color
                                    );
                                }
                            }

                            if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
                                if ($DisplayShadow) {
                                    $this->Shadow = true;
                                }

                                $Caption = $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit);
                                $TxtPos = $this->getTextBox(0, 0, $DisplayFont, $DisplaySize, 90, $Caption);
                                $TxtHeight = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;

                                if ($DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight)) {
                                    $CenterX = (($X + $XOffset + $XSize - $XSpace) - ($X + $XOffset + $XSpace))
                                        / 2 + $X + $XOffset + $XSpace
                                    ;
                                    $CenterY = ($Y2 - $Y1) / 2 + $Y1;

                                    $this->drawText(
                                        $CenterX,
                                        $CenterY,
                                        $Caption,
                                        [
                                            "R" => $DisplayR,
                                            "G" => $DisplayG,
                                            "B" => $DisplayB,
                                            "Align" => TEXT_ALIGN_MIDDLEMIDDLE,
                                            "FontSize" => $DisplaySize,
                                            "Angle" => 90
                                        ]
                                    );
                                } else {
                                    if ($Serie["Data"][$Key] >= 0) {
                                        $Align = TEXT_ALIGN_BOTTOMMIDDLE;
                                        $Offset = $DisplayOffset;
                                    } else {
                                        $Align = TEXT_ALIGN_TOPMIDDLE;
                                        $Offset = -$DisplayOffset;
                                    }
                                    $this->drawText(
                                        $X + $XOffset + $XSize / 2,
                                        $Y2 - $Offset,
                                        $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit),
                                        [
                                            "R" => $DisplayR,
                                            "G" => $DisplayG,
                                            "B" => $DisplayB,
                                            "Align" => $Align,
                                            "FontSize" => $DisplaySize
                                        ]
                                    );
                                }

                                $this->Shadow = $RestoreShadow;
                            }
                        }

                        $X = $X + $XStep;
                        $ID++;
                    }
                } else {
                    if ($YZero < $this->GraphAreaX1 + 1) {
                        $YZero = $this->GraphAreaX1 + 1;
                    }
                    if ($YZero > $this->GraphAreaX2 - 1) {
                        $YZero = $this->GraphAreaX2 - 1;
                    }

                    if ($XDivs == 0) {
                        $YStep = 0;
                    } else {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
                    }

                    $Y = $this->GraphAreaY1 + $XMargin;

                    if ($AroundZero) {
                        $X1 = $YZero;
                    } else {
                        $X1 = $this->GraphAreaX1 + 1;
                    }
                    if ($XDivs == 0) {
                        $YSize = ($this->GraphAreaY2 - $this->GraphAreaY1) / ($SeriesCount + $Interleave);
                    } else {
                        $YSize = ($YStep / ($SeriesCount + $Interleave));
                    }

                    $YOffset = -($YSize * $SeriesCount) / 2 + $CurrentSerie * $YSize;
                    if ($Y + $YOffset <= $this->GraphAreaY1) {
                        $YOffset = $this->GraphAreaY1 - $Y + 1;
                    }

                    $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;

                    if ($Rounded || $BorderR != -1) {
                        $YSpace = 1;
                    } else {
                        $YSpace = 0;
                    }

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }

                    $ID = 0;
                    foreach ($PosArray as $Key => $X2) {
                        if ($Floating0Serie != null) {
                            if (isset($Data["Series"][$Floating0Serie]["Data"][$Key])) {
                                $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
                            } else {
                                $Value = 0;
                            }

                            $YZero = $this->scaleComputeY($Value, ["AxisID" => $Serie["Axis"]]);
                            if ($YZero < $this->GraphAreaX1 + 1) {
                                $YZero = $this->GraphAreaX1 + 1;
                            }
                            if ($YZero > $this->GraphAreaX2 - 1) {
                                $YZero = $this->GraphAreaX2 - 1;
                            }
                            if ($AroundZero) {
                                $X1 = $YZero;
                            } else {
                                $X1 = $this->GraphAreaX1 + 1;
                            }
                        }

                        if ($OverrideColors != null) {
                            if (isset($OverrideColors[$ID])) {
                                $Color = [
                                    "R" => $OverrideColors[$ID]["R"],
                                    "G" => $OverrideColors[$ID]["G"],
                                    "B" => $OverrideColors[$ID]["B"],
                                    "Alpha" => $OverrideColors[$ID]["Alpha"],
                                    "BorderR" => $OverrideColors[$ID]["BorderR"],
                                    "BorderG" => $OverrideColors[$ID]["BorderG"],
                                    "BorderB" => $OverrideColors[$ID]["BorderB"]
                                ];
                            } else {
                                $Color = $this->getRandomColor();
                            }
                        }

                        if ($X2 != VOID) {
                            $BarWidth = $X2 - $X1;
                            if ($Serie["Data"][$Key] == 0) {
                                $this->drawLine(
                                    $X1,
                                    $Y + $YOffset + $YSpace,
                                    $X1,
                                    $Y + $YOffset + $YSize - $YSpace,
                                    $Color
                                );
                                if ($RecordImageMap) {
                                    $this->addToImageMap(
                                        "RECT",
                                        sprintf(
                                            "%s,%s,%s,%s",
                                            floor($X1 - 1),
                                            floor($Y + $YOffset + $YSpace),
                                            floor($X1 + 1),
                                            floor($Y + $YOffset + $YSize - $YSpace)
                                        ),
                                        $this->toHTMLColor($R, $G, $B),
                                        $SerieDescription,
                                        $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                                    );
                                }
                            } else {
                                if ($RecordImageMap) {
                                    $this->addToImageMap(
                                        "RECT",
                                        sprintf(
                                            "%s,%s,%s,%s",
                                            floor($X1),
                                            floor($Y + $YOffset + $YSpace),
                                            floor($X2),
                                            floor($Y + $YOffset + $YSize - $YSpace)
                                        ),
                                        $this->toHTMLColor($R, $G, $B),
                                        $SerieDescription,
                                        $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                                    );
                                }

                                if ($Rounded) {
                                    $this->drawRoundedFilledRectangle(
                                        $X1 + 1,
                                        $Y + $YOffset + $YSpace,
                                        $X2,
                                        $Y + $YOffset + $YSize - $YSpace,
                                        $RoundRadius,
                                        $Color
                                    );
                                } else {
                                    $this->drawFilledRectangle(
                                        $X1,
                                        $Y + $YOffset + $YSpace,
                                        $X2,
                                        $Y + $YOffset + $YSize - $YSpace,
                                        $Color
                                    );

                                    if ($InnerColor != null) {
                                        $this->drawRectangle(
                                            min($X1, $X2) + 1,
                                            $Y + $YOffset + $YSpace + 1,
                                            max($X1, $X2) - 1,
                                            $Y + $YOffset + $YSize - $YSpace - 1,
                                            $InnerColor
                                        );
                                    }

                                    if ($Gradient) {
                                        $this->Shadow = false;

                                        if ($GradientMode == GRADIENT_SIMPLE) {
                                            if ($Serie["Data"][$Key] >= 0) {
                                                $GradienColor = [
                                                    "StartR" => $GradientStartR,
                                                    "StartG" => $GradientStartG,
                                                    "StartB" => $GradientStartB,
                                                    "EndR" => $GradientEndR,
                                                    "EndG" => $GradientEndG,
                                                    "EndB" => $GradientEndB,
                                                    "Alpha" => $GradientAlpha
                                                ];
                                            } else {
                                                $GradienColor = [
                                                    "StartR" => $GradientEndR,
                                                    "StartG" => $GradientEndG,
                                                    "StartB" => $GradientEndB,
                                                    "EndR" => $GradientStartR,
                                                    "EndG" => $GradientStartG,
                                                    "EndB" => $GradientStartB,
                                                    "Alpha" => $GradientAlpha
                                                ];
                                            }
                                            $this->drawGradientArea(
                                                $X1,
                                                $Y + $YOffset + $YSpace,
                                                $X2,
                                                $Y + $YOffset + $YSize - $YSpace,
                                                DIRECTION_HORIZONTAL,
                                                $GradienColor
                                            );
                                        } elseif ($GradientMode == GRADIENT_EFFECT_CAN) {
                                            $GradienColor1 = [
                                                "StartR" => $GradientEndR,
                                                "StartG" => $GradientEndG,
                                                "StartB" => $GradientEndB,
                                                "EndR" => $GradientStartR,
                                                "EndG" => $GradientStartG,
                                                "EndB" => $GradientStartB,
                                                "Alpha" => $GradientAlpha
                                            ];
                                            $GradienColor2 = [
                                                "StartR" => $GradientStartR,
                                                "StartG" => $GradientStartG,
                                                "StartB" => $GradientStartB,
                                                "EndR" => $GradientEndR,
                                                "EndG" => $GradientEndG,
                                                "EndB" => $GradientEndB,
                                                "Alpha" => $GradientAlpha
                                            ];
                                            $YSpan = floor($YSize / 3);

                                            $this->drawGradientArea(
                                                $X1,
                                                $Y + $YOffset + $YSpace,
                                                $X2,
                                                $Y + $YOffset + $YSpan - $YSpace,
                                                DIRECTION_VERTICAL,
                                                $GradienColor1
                                            );
                                            $this->drawGradientArea(
                                                $X1,
                                                $Y + $YOffset + $YSpan,
                                                $X2,
                                                $Y + $YOffset + $YSize - $YSpace,
                                                DIRECTION_VERTICAL,
                                                $GradienColor2
                                            );
                                        }
                                        $this->Shadow = $RestoreShadow;
                                    }
                                }

                                if ($Draw0Line) {
                                    $Line0Color = ["R" => 0, "G" => 0, "B" => 0, "Alpha" => 20];

                                    if (abs($X1 - $X2) > 3) {
                                        $Line0Width = 3;
                                    } else {
                                        $Line0Width = 1;
                                    }
                                    if ($X2 - $X1 < 0) {
                                        $Line0Width = -$Line0Width;
                                    }

                                    $this->drawFilledRectangle(
                                        floor($X1),
                                        $Y + $YOffset + $YSpace,
                                        floor($X1) + $Line0Width,
                                        $Y + $YOffset + $YSize - $YSpace,
                                        $Line0Color
                                    );
                                    $this->drawLine(
                                        floor($X1),
                                        $Y + $YOffset + $YSpace,
                                        floor($X1),
                                        $Y + $YOffset + $YSize - $YSpace,
                                        $Line0Color
                                    );
                                }
                            }

                            if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
                                if ($DisplayShadow) {
                                    $this->Shadow = true;
                                }

                                $Caption = $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit);
                                $TxtPos = $this->getTextBox(0, 0, $DisplayFont, $DisplaySize, 0, $Caption);
                                $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;

                                if ($DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth)) {
                                    $CenterX = ($X2 - $X1) / 2 + $X1;
                                    $CenterY = (($Y + $YOffset + $YSize - $YSpace)
                                        - ($Y + $YOffset + $YSpace)) / 2
                                        + ($Y + $YOffset + $YSpace)
                                    ;

                                    $this->drawText(
                                        $CenterX,
                                        $CenterY,
                                        $Caption,
                                        [
                                            "R" => $DisplayR,
                                            "G" => $DisplayG,
                                            "B" => $DisplayB,
                                            "Align" => TEXT_ALIGN_MIDDLEMIDDLE,
                                            "FontSize" => $DisplaySize
                                        ]
                                    );
                                } else {
                                    if ($Serie["Data"][$Key] >= 0) {
                                        $Align = TEXT_ALIGN_MIDDLELEFT;
                                        $Offset = $DisplayOffset;
                                    } else {
                                        $Align = TEXT_ALIGN_MIDDLERIGHT;
                                        $Offset = -$DisplayOffset;
                                    }
                                    $this->drawText(
                                        $X2 + $Offset,
                                        $Y + $YOffset + $YSize / 2,
                                        $Caption,
                                        [
                                            "R" => $DisplayR,
                                            "G" => $DisplayG,
                                            "B" => $DisplayB,
                                            "Align" => $Align,
                                            "FontSize" => $DisplaySize
                                        ]
                                    );
                                }

                                $this->Shadow = $RestoreShadow;
                            }
                        }
                        $Y = $Y + $YStep;
                        $ID++;
                    }
                }
                $CurrentSerie++;
            }
        }
    }
132075
private function drawText(Text $text, $canvas)
    {
        list($red, $green, $blue) = $text->getColor();
        $opacity = Utils::fixPNGOpacity($text->getOpacity());

        $color = imagecolorallocatealpha(
            $canvas,
            $red,
            $green,
            $blue,
            $opacity < 127 ? $opacity : null
        );

        $size = $text->getSize();
        $angle = $text->getAngle();
        $font = $text->getFontface();
        $lineHeight = $text->getLineHeight() * $text->getSize();

        list($x, $y) = $text->getCords();

        $lines = $text->wrappText();

        foreach ($lines as $i => $line) {
            $ny = $y + ($lineHeight * $i);
            imagealphablending($canvas, true);
            imagettftext($canvas, $size, $angle, $x, $ny, $color, $font, $line);
        }
    }
546878
function line($x1, $y1, $x2, $y2, $stroke = true)
    {
        $this->addContent(sprintf("\n%.3F %.3F m %.3F %.3F l", $x1, $y1, $x2, $y2));

        if ($stroke) {
            $this->addContent(' S');
        }
    }
566702
private function addTextToImage($text, $x, $y)
    {
        imagettftext($this->image, $this->get('font_size'), 0, $x, $y, $this->get('text_color'), $this->dir.'/instruction.ttf', $text);
    }
1028638
public function drawXThreshold($Value, array $Format = [])
    {
        $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"] : 50;
        $Weight = isset($Format["Weight"]) ? $Format["Weight"] : null;
        $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
        $Wide = isset($Format["Wide"]) ? $Format["Wide"] : false;
        $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
        $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : false;
        $Caption = isset($Format["Caption"]) ? $Format["Caption"] : null;
        $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
        $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 5;
        $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
        $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
        $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
        $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
        $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : true;
        $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : false;
        $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
        $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : true;
        $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
        $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
        $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
        $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
        $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
        $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
        $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
        $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
        $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
        $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
        $ValueIsLabel = isset($Format["ValueIsLabel"]) ? $Format["ValueIsLabel"] : false;

        $Data = $this->DataSet->getData();
        $AbscissaMargin = $this->getAbscissaMargin($Data);
        $XScale = $this->scaleGetXSettings();

        if (is_array($Value)) {
            foreach ($Value as $Key => $ID) {
                $this->drawXThreshold($ID, $Format);
            }
            return 0;
        }

        if ($ValueIsLabel) {
            $Format["ValueIsLabel"] = false;
            foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $SerieValue) {
                if ($SerieValue == $Value) {
                    $this->drawXThreshold($Key, $Format);
                }
            }
            return 0;
        }

        $CaptionSettings = [
            "DrawBox" => $DrawBox,
            "DrawBoxBorder" => $DrawBoxBorder,
            "BorderOffset" => $BorderOffset,
            "BoxRounded" => $BoxRounded,
            "RoundedRadius" => $RoundedRadius,
            "BoxR" => $BoxR,
            "BoxG" => $BoxG,
            "BoxB" => $BoxB,
            "BoxAlpha" => $BoxAlpha,
            "BoxSurrounding" => $BoxSurrounding,
            "BoxBorderR" => $BoxBorderR,
            "BoxBorderG" => $BoxBorderG,
            "BoxBorderB" => $BoxBorderB,
            "BoxBorderAlpha" => $BoxBorderAlpha,
            "R" => $CaptionR,
            "G" => $CaptionG,
            "B" => $CaptionB,
            "Alpha" => $CaptionAlpha
        ];

        if ($Caption == null) {
            $Caption = $Value;
            if (isset($Data["Abscissa"])
                && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Value])
            ) {
                $Caption = $Data["Series"][$Data["Abscissa"]]["Data"][$Value];
            }
        }

        if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
            $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] * 2) / $XScale[1];
            $XPos = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value;
            $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
            $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];

            if ($XPos >= $this->GraphAreaX1 + $AbscissaMargin
                && $XPos <= $this->GraphAreaX2 - $AbscissaMargin
            ) {
                $this->drawLine(
                    $XPos,
                    $YPos1,
                    $XPos,
                    $YPos2,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Ticks" => $Ticks,
                        "Weight" => $Weight
                    ]
                );

                if ($Wide) {
                    $this->drawLine(
                        $XPos - 1,
                        $YPos1,
                        $XPos - 1,
                        $YPos2,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                    $this->drawLine(
                        $XPos + 1,
                        $YPos1,
                        $XPos + 1,
                        $YPos2,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                }

                if ($WriteCaption) {
                    if ($CaptionAlign == CAPTION_LEFT_TOP) {
                        $Y = $YPos1 + $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                    } else {
                        $Y = $YPos2 - $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
                    }
                    $this->drawText($XPos, $Y, $Caption, $CaptionSettings);
                }

                return ["X" => $XPos];
            }
        } elseif ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
            $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] * 2) / $XScale[1];
            $XPos = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value;
            $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
            $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];

            if ($XPos >= $this->GraphAreaY1 + $AbscissaMargin
                && $XPos <= $this->GraphAreaY2 - $AbscissaMargin
            ) {
                $this->drawLine(
                    $YPos1,
                    $XPos,
                    $YPos2,
                    $XPos,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Ticks" => $Ticks,
                        "Weight" => $Weight
                    ]
                );

                if ($Wide) {
                    $this->drawLine(
                        $YPos1,
                        $XPos - 1,
                        $YPos2,
                        $XPos - 1,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                    $this->drawLine(
                        $YPos1,
                        $XPos + 1,
                        $YPos2,
                        $XPos + 1,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                }

                if ($WriteCaption) {
                    if ($CaptionAlign == CAPTION_LEFT_TOP) {
                        $Y = $YPos1 + $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
                    } else {
                        $Y = $YPos2 - $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
                    }

                    $this->drawText($Y, $XPos, $Caption, $CaptionSettings);
                }

                return ["X" => $XPos];
            }
        }
    }
1183317
public function drawPieLegend($X, $Y, array $Format = [])
    {
        $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
        $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
        $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
        $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
        $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
        $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
        $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
        $R = isset($Format["R"]) ? $Format["R"] : 200;
        $G = isset($Format["G"]) ? $Format["G"] : 200;
        $B = isset($Format["B"]) ? $Format["B"] : 200;
        $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
        $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
        $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
        $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
        $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null;
        $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
        $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;

        if ($Surrounding != null) {
            $BorderR = $R + $Surrounding;
            $BorderG = $G + $Surrounding;
            $BorderB = $B + $Surrounding;
        }

        $YStep = max($this->pChartObject->FontSize, $BoxSize) + 5;
        $XStep = $BoxSize + 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;
        }

        $Boundaries = [];
        $Boundaries["L"] = $X;
        $Boundaries["T"] = $Y;
        $Boundaries["R"] = 0;
        $Boundaries["B"] = 0;
        $vY = $Y;
        $vX = $X;
        foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) {
            $BoxArray = $this->pChartObject->getTextBox(
                $vX + $BoxSize + 4,
                $vY + $BoxSize / 2,
                $FontName,
                $FontSize,
                0,
                $Value
            );

            if ($Mode == LEGEND_VERTICAL) {
                if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize / 2) {
                    $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize / 2;
                }
                if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
                    $Boundaries["R"] = $BoxArray[1]["X"] + 2;
                }
                if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize / 2) {
                    $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize / 2;
                }
                $vY = $vY + $YStep;
            } elseif ($Mode == LEGEND_HORIZONTAL) {
                if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize / 2) {
                    $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize / 2;
                }
                if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
                    $Boundaries["R"] = $BoxArray[1]["X"] + 2;
                }
                if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize / 2) {
                    $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize / 2;
                }
                $vX = $Boundaries["R"] + $XStep;
            }
        }
        $vY = $vY - $YStep;
        $vX = $vX - $XStep;

        $TopOffset = $Y - $Boundaries["T"];
        if ($Boundaries["B"] - ($vY + $BoxSize) < $TopOffset) {
            $Boundaries["B"] = $vY + $BoxSize + $TopOffset;
        }

        if ($Style == LEGEND_ROUND) {
            $this->pChartObject->drawRoundedFilledRectangle(
                $Boundaries["L"] - $Margin,
                $Boundaries["T"] - $Margin,
                $Boundaries["R"] + $Margin,
                $Boundaries["B"] + $Margin,
                $Margin,
                [
                    "R" => $R,
                    "G" => $G,
                    "B" => $B,
                    "Alpha" => $Alpha,
                    "BorderR" => $BorderR,
                    "BorderG" => $BorderG,
                    "BorderB" => $BorderB
                ]
            );
        } elseif ($Style == LEGEND_BOX) {
            $this->pChartObject->drawFilledRectangle(
                $Boundaries["L"] - $Margin,
                $Boundaries["T"] - $Margin,
                $Boundaries["R"] + $Margin,
                $Boundaries["B"] + $Margin,
                [
                    "R" => $R,
                    "G" => $G,
                    "B" => $B,
                    "Alpha" => $Alpha,
                    "BorderR" => $BorderR,
                    "BorderG" => $BorderG,
                    "BorderB" => $BorderB
                ]
            );
        }
        $RestoreShadow = $this->pChartObject->Shadow;
        $this->pChartObject->Shadow = false;
        foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) {
            $R = $Palette[$Key]["R"];
            $G = $Palette[$Key]["G"];
            $B = $Palette[$Key]["B"];

            $this->pChartObject->drawFilledRectangle(
                $X + 1,
                $Y + 1,
                $X + $BoxSize + 1,
                $Y + $BoxSize + 1,
                ["R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]
            );
            $this->pChartObject->drawFilledRectangle(
                $X,
                $Y,
                $X + $BoxSize,
                $Y + $BoxSize,
                ["R" => $R, "G" => $G, "B" => $B, "Surrounding" => 20]
            );
            if ($Mode == LEGEND_VERTICAL) {
                $this->pChartObject->drawText(
                    $X + $BoxSize + 4,
                    $Y + $BoxSize / 2,
                    $Value,
                    [
                        "R" => $FontR,
                        "G" => $FontG,
                        "B" => $FontB,
                        "Align" => TEXT_ALIGN_MIDDLELEFT,
                        "FontName" => $FontName,
                        "FontSize" => $FontSize
                    ]
                );
                $Y = $Y + $YStep;
            } elseif ($Mode == LEGEND_HORIZONTAL) {
                $BoxArray = $this->pChartObject->drawText(
                    $X + $BoxSize + 4,
                    $Y + $BoxSize / 2,
                    $Value,
                    [
                        "R" => $FontR,
                        "G" => $FontG,
                        "B" => $FontB,
                        "Align" => TEXT_ALIGN_MIDDLELEFT,
                        "FontName" => $FontName,
                        "FontSize" => $FontSize
                    ]
                );
                $X = $BoxArray[1]["X"] + 2 + $XStep;
            }
        }

        $this->Shadow = $RestoreShadow;
    }
944101
function drawAxisLabels() {
            // If y-axis label is given, draw it
            if (yAxisLabel) {
                if (yAxisLabelEl) {
                    svg.selectAll('.y-axis-label-text').remove();
                }

                yAxisLabelEl = svg.select('.axis-labels-group')
                    .append('g')
                    .attr('class', 'y-axis-label')
                      .append('text')
                      .classed('y-axis-label-text', true)
                      .attr('x', -chartHeight / 2)
                      .attr('y', yAxisLabelOffset - xAxisPadding.left)
                      .attr('text-anchor', 'middle')
                      .attr('transform', 'rotate(270 0 0)')
                      .text(yAxisLabel)
            }

            // If x-axis label is given, draw it
            if (xAxisLabel) {
                if (xAxisLabelEl) {
                    svg.selectAll('.x-axis-label-text').remove();
                }

                xAxisLabelEl = svg.selectAll('.axis-labels-group')
                    .append('g')
                    .attr('class', 'x-axis-label')
                      .append('text')
                      .classed('x-axis-label-text', true)
                      .attr('x', chartWidth / 2)
                      .attr('y', chartHeight - xAxisLabelOffset)
                      .attr('text-anchor', 'middle')
                      .text(xAxisLabel);
            }
        }
320750
public function writeText($text, $point, $size, $angle, $font, $maxwidth = 0, $rgbAr = null, $textAlignment = 1)
    {
        if (!is_readable($font)) {
            throw new ImageUtilException('Error: The specified font not found');
        }

        if (!is_array($rgbAr)) {
            $rgbAr = [0, 0, 0];
        }

        $color = imagecolorallocate($this->image, $rgbAr[0], $rgbAr[1], $rgbAr[2]);

        // Determine the line break if required.
        if (($maxwidth > 0) && ($angle == 0)) {
            $words = explode(' ', $text);
            $lines = [$words[0]];
            $currentLine = 0;

            $numberOfWords = count($words);
            for ($i = 1; $i < $numberOfWords; $i++) {
                $lineSize = imagettfbbox($size, 0, $font, $lines[$currentLine] . ' ' . $words[$i]);
                if ($lineSize[2] - $lineSize[0] < $maxwidth) {
                    $lines[$currentLine] .= ' ' . $words[$i];
                } else {
                    $currentLine++;
                    $lines[$currentLine] = $words[$i];
                }
            }
        } else {
            $lines = [$text];
        }

        $curX = $point[0];
        $curY = $point[1];

        foreach ($lines as $text) {
            $bbox = imagettfbbox($size, $angle, $font, $text);

            switch ($textAlignment) {
                case TextAlignment::RIGHT:
                    $curX = $point[0] - abs($bbox[2] - $bbox[0]);
                    break;

                case TextAlignment::CENTER:
                    $curX = $point[0] - (abs($bbox[2] - $bbox[0]) / 2);
                    break;
            }

            imagettftext($this->image, $size, $angle, $curX, $curY, $color, $font, $text);

            $curY += ($size * 1.35);
        }
    }
237969
public function generateLabel(string $text) {
        $args = [
            'w'             => $this->width,
            'h'             => 0,
            'txt'           => $text,
            'border'        => 0,
            'align'         => 'L',
            'fill'          => 0,
            'ln'            => 0,
            'x'             => '',
            'y'             => '',
            'reseth'        => true,
            'stretch'       => 0,
            'ishtml'        => false,
            'autopadding'   => false,
            'maxh'          => $this->height,
        ];

        if (true === $args['ishtml']) {
            $this->writeHTMLCell($args['w'], $args['h'],
                $args['x'], $args['y'],
                $args['txt'], $args['border'],
                $args['ln'], $args['fill'],
                $args['reseth'], $args['align'],
                $args['autopadding']
            );
        } else {
            $this->multiCell($args['w'], $args['h'],
                $args['txt'], $args['border'],
                $args['align'], $args['fill'],
                $args['ln'], $args['x'],
                $args['y'], $args['reseth'],
                $args['stretch'], $args['ishtml'],
                $args['autopadding'], $args['maxh']
            );
        }
    }
997088
public function drawText($text, $x, $y, $charEncoding = 'WINDOWS-1252')
    {
        $this->convertCoordinatesFromUserSpace($x, $y);
        $y -= $this->getFontSize();
        return parent::drawText($text, $x, $y, $charEncoding);
    }
179250
public function mprint($A, $format='%01.2f', $width=2)
    {
        $spacing = '';
        $m = count($A);
        $n = count($A[0]);
        for ($i = 0; $i < $width; $i++) {
            $spacing .= '&nbsp;';
        }
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $formatted = sprintf($format, $A[$i][$j]);
                echo $formatted . $spacing;
            }
            echo '<br />';
        }
    }
597571
public function drawScatterThresholdArea($Value1, $Value2, array $Format = [])
    {
        $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) = [$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,
                ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha]
            );

            if ($Border) {
                $this->pChartObject->drawLine(
                    $X1,
                    $Y1,
                    $X1,
                    $Y2,
                    [
                        "R" => $BorderR,
                        "G" => $BorderG,
                        "B" => $BorderB,
                        "Alpha" => $BorderAlpha,
                        "Ticks" => $BorderTicks
                    ]
                );
                $this->pChartObject->drawLine(
                    $X2,
                    $Y1,
                    $X2,
                    $Y2,
                    [
                        "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,
                    [
                        "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 ["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,
                ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha]
            );

            if ($Border) {
                $this->pChartObject->drawLine(
                    $X1,
                    $Y1,
                    $X2,
                    $Y1,
                    [
                        "R" => $BorderR,
                        "G" => $BorderG,
                        "B" => $BorderB,
                        "Alpha" => $BorderAlpha,
                        "Ticks" => $BorderTicks
                    ]
                );
                $this->pChartObject->drawLine(
                    $X1,
                    $Y2,
                    $X2,
                    $Y2,
                    [
                        "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,
                    [
                        "R" => $NameR,
                        "G" => $NameG,
                        "B" => $NameB,
                        "Alpha" => $NameAlpha,
                        "Angle" => 0,
                        "Align" => TEXT_ALIGN_MIDDLEMIDDLE
                    ]
                );
                if ($DisableShadowOnArea) {
                    $this->Shadow = false;
                }
            }

            $this->pChartObject->Shadow = $RestoreShadow;
            return ["Y1" => $Y1, "Y2" => $Y2];
        }
    }
1183255
public function drawThreshold($Value, array $Format = [])
    {
        $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"] : 50;
        $Weight = isset($Format["Weight"]) ? $Format["Weight"] : null;
        $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
        $Wide = isset($Format["Wide"]) ? $Format["Wide"] : false;
        $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
        $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : false;
        $Caption = isset($Format["Caption"]) ? $Format["Caption"] : null;
        $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
        $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
        $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
        $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
        $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
        $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
        $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : true;
        $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : false;
        $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
        $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : true;
        $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
        $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
        $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
        $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
        $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
        $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
        $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
        $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
        $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
        $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
        $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : false;

        if (is_array($Value)) {
            foreach ($Value as $Key => $ID) {
                $this->drawThreshold($ID, $Format);
            }
            return 0;
        }

        $CaptionSettings = [
            "DrawBox" => $DrawBox,
            "DrawBoxBorder" => $DrawBoxBorder,
            "BorderOffset" => $BorderOffset,
            "BoxRounded" => $BoxRounded,
            "RoundedRadius" => $RoundedRadius,
            "BoxR" => $BoxR,
            "BoxG" => $BoxG,
            "BoxB" => $BoxB,
            "BoxAlpha" => $BoxAlpha,
            "BoxSurrounding" => $BoxSurrounding,
            "BoxBorderR" => $BoxBorderR,
            "BoxBorderG" => $BoxBorderG,
            "BoxBorderB" => $BoxBorderB,
            "BoxBorderAlpha" => $BoxBorderAlpha,
            "R" => $CaptionR,
            "G" => $CaptionG,
            "B" => $CaptionB,
            "Alpha" => $CaptionAlpha
        ];

        $Data = $this->DataSet->getData();
        $AbscissaMargin = $this->getAbscissaMargin($Data);

        if ($NoMargin) {
            $AbscissaMargin = 0;
        }
        if (!isset($Data["Axis"][$AxisID])) {
            return -1;
        }
        if ($Caption == null) {
            $Caption = $Value;
        }

        if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
            $YPos = $this->scaleComputeY($Value, ["AxisID" => $AxisID]);
            if ($YPos >= $this->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"]
                && $YPos <= $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"]
            ) {
                $X1 = $this->GraphAreaX1 + $AbscissaMargin;
                $X2 = $this->GraphAreaX2 - $AbscissaMargin;

                $this->drawLine(
                    $X1,
                    $YPos,
                    $X2,
                    $YPos,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Ticks" => $Ticks,
                        "Weight" => $Weight
                    ]
                );

                if ($Wide) {
                    $this->drawLine(
                        $X1,
                        $YPos - 1,
                        $X2,
                        $YPos - 1,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                    $this->drawLine(
                        $X1,
                        $YPos + 1,
                        $X2,
                        $YPos + 1,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                }

                if ($WriteCaption) {
                    if ($CaptionAlign == CAPTION_LEFT_TOP) {
                        $X = $X1 + $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
                    } else {
                        $X = $X2 - $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
                    }

                    $this->drawText($X, $YPos, $Caption, $CaptionSettings);
                }
            }

            return ["Y" => $YPos];
        }

        if ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
            $XPos = $this->scaleComputeY($Value, ["AxisID" => $AxisID]);
            if ($XPos >= $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"]
                    && $XPos <= $this->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"]
            ) {
                $Y1 = $this->GraphAreaY1 + $AbscissaMargin;
                $Y2 = $this->GraphAreaY2 - $AbscissaMargin;

                $this->drawLine(
                    $XPos,
                    $Y1,
                    $XPos,
                    $Y2,
                    [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Ticks" => $Ticks,
                        "Weight" => $Weight
                    ]
                );

                if ($Wide) {
                    $this->drawLine(
                        $XPos - 1,
                        $Y1,
                        $XPos - 1,
                        $Y2,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                    $this->drawLine(
                        $XPos + 1,
                        $Y1,
                        $XPos + 1,
                        $Y2,
                        [
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha / $WideFactor,
                            "Ticks" => $Ticks
                        ]
                    );
                }

                if ($WriteCaption) {
                    if ($CaptionAlign == CAPTION_LEFT_TOP) {
                        $Y = $Y1 + $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                    } else {
                        $Y = $Y2 - $CaptionOffset;
                        $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
                    }

                    $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                    $this->drawText($XPos, $Y, $Caption, $CaptionSettings);
                }
            }

            return ["Y" => $XPos];
        }
    }
1106579
public function drawBestFit(array $Format = [])
    {
        $OverrideTicks = isset($Format["Ticks"]) ? $Format["Ticks"] : null;
        $OverrideR = isset($Format["R"]) ? $Format["R"] : VOID;
        $OverrideG = isset($Format["G"]) ? $Format["G"] : VOID;
        $OverrideB = isset($Format["B"]) ? $Format["B"] : VOID;
        $OverrideAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;

        $Data = $this->DataSet->getData();
        list($XMargin, $XDivs) = $this->scaleGetXSettings();

        foreach ($Data["Series"] as $SerieName => $Serie) {
            if ($Serie["isDrawable"] == true && $SerieName != $Data["Abscissa"]) {
                if ($OverrideR != VOID && $OverrideG != VOID && $OverrideB != VOID) {
                    $R = $OverrideR;
                    $G = $OverrideG;
                    $B = $OverrideB;
                } else {
                    $R = $Serie["Color"]["R"];
                    $G = $Serie["Color"]["G"];
                    $B = $Serie["Color"]["B"];
                }
                if ($OverrideTicks == null) {
                    $Ticks = $Serie["Ticks"];
                } else {
                    $Ticks = $OverrideTicks;
                }
                if ($OverrideAlpha == VOID) {
                    $Alpha = $Serie["Color"]["Alpha"];
                } else {
                    $Alpha = $OverrideAlpha;
                }

                $Color = ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "Ticks" => $Ticks];

                $PosArray = $this->scaleComputeY(
                    $Serie["Data"],
                    ["AxisID" => $Serie["Axis"]]
                );

                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;

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    $Sxy = 0;
                    $Sx = 0;
                    $Sy = 0;
                    $Sxx = 0;
                    foreach ($PosArray as $Key => $Y) {
                        if ($Y != VOID) {
                            $Sxy = $Sxy + $X * $Y;
                            $Sx = $Sx + $X;
                            $Sy = $Sy + $Y;
                            $Sxx = $Sxx + $X * $X;
                        }

                        $X = $X + $XStep;
                    }
                    $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
                    $M = (($n * $Sxy) - ($Sx * $Sy)) / (($n * $Sxx) - ($Sx * $Sx));
                    $B = (($Sy) - ($M * $Sx)) / ($n);

                    $X1 = $this->GraphAreaX1 + $XMargin;
                    $Y1 = $M * $X1 + $B;
                    $X2 = $this->GraphAreaX2 - $XMargin;
                    $Y2 = $M * $X2 + $B;

                    if ($Y1 < $this->GraphAreaY1) {
                        $X1 = $X1 + ($this->GraphAreaY1 - $Y1);
                        $Y1 = $this->GraphAreaY1;
                    }
                    if ($Y1 > $this->GraphAreaY2) {
                        $X1 = $X1 + ($Y1 - $this->GraphAreaY2);
                        $Y1 = $this->GraphAreaY2;
                    }
                    if ($Y2 < $this->GraphAreaY1) {
                        $X2 = $X2 - ($this->GraphAreaY1 - $Y2);
                        $Y2 = $this->GraphAreaY1;
                    }
                    if ($Y2 > $this->GraphAreaY2) {
                        $X2 = $X2 - ($Y2 - $this->GraphAreaY2);
                        $Y2 = $this->GraphAreaY2;
                    }

                    $this->drawLine($X1, $Y1, $X2, $Y2, $Color);
                } else {
                    if ($XDivs == 0) {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
                    } else {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
                    }
                    $Y = $this->GraphAreaY1 + $XMargin;

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    $Sxy = 0;
                    $Sx = 0;
                    $Sy = 0;
                    $Sxx = 0;
                    foreach ($PosArray as $Key => $X) {
                        if ($X != VOID) {
                            $Sxy = $Sxy + $X * $Y;
                            $Sx = $Sx + $Y;
                            $Sy = $Sy + $X;
                            $Sxx = $Sxx + $Y * $Y;
                        }

                        $Y = $Y + $YStep;
                    }
                    $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
                    $M = (($n * $Sxy) - ($Sx * $Sy)) / (($n * $Sxx) - ($Sx * $Sx));
                    $B = (($Sy) - ($M * $Sx)) / ($n);

                    $Y1 = $this->GraphAreaY1 + $XMargin;
                    $X1 = $M * $Y1 + $B;
                    $Y2 = $this->GraphAreaY2 - $XMargin;
                    $X2 = $M * $Y2 + $B;

                    if ($X1 < $this->GraphAreaX1) {
                        $Y1 = $Y1 + ($this->GraphAreaX1 - $X1);
                        $X1 = $this->GraphAreaX1;
                    }
                    if ($X1 > $this->GraphAreaX2) {
                        $Y1 = $Y1 + ($X1 - $this->GraphAreaX2);
                        $X1 = $this->GraphAreaX2;
                    }
                    if ($X2 < $this->GraphAreaX1) {
                        $Y2 = $Y2 - ($this->GraphAreaY1 - $X2);
                        $X2 = $this->GraphAreaX1;
                    }
                    if ($X2 > $this->GraphAreaX2) {
                        $Y2 = $Y2 - ($X2 - $this->GraphAreaX2);
                        $X2 = $this->GraphAreaX2;
                    }

                    $this->drawLine($X1, $Y1, $X2, $Y2, $Color);
                }
            }
        }
    }