Draw a Scatter threshold
@param mixed $Value
@param array $Format
@return array
349947
public function drawScatterThreshold($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"] : 3;
        $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;

        $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;
        }

        $Data = $this->pDataObject->getData();

        if (!isset($Data["Axis"][$AxisID])) {
            return -1;
        }

        if ($Data["Axis"][$AxisID]["Identity"] == AXIS_Y) {
            $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
            $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
            $Y = $this->getPosArray($Value, $AxisID);

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

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

            if ($WriteCaption) {
                if ($CaptionAlign == CAPTION_LEFT_TOP) {
                    $X = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
                } else {
                    $X = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
                }
                $this->pChartObject->drawText($X, $Y, $Caption, $CaptionSettings);
            }

            return ["Y" => $Y];
        } elseif ($Data["Axis"][$AxisID]["Identity"] == AXIS_X) {
            $X = $this->getPosArray($Value, $AxisID);
            $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
            $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];

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

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

            if ($WriteCaption) {
                if ($CaptionAlign == CAPTION_LEFT_TOP) {
                    $Y = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
                } else {
                    $Y = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset;
                    $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
                }

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

            return ["X" => $X];
        }
    }
1260058
static function format($value,$format)
    {
        $f = Utility::get($format, "format", true);
        if ($f===false) {
            return $value;
        }
        
        $type = Utility::get($format, "type", "unknown");
        switch($type)
        {
        case "number":
            $decimals = Utility::get($format, "decimals", 0);
            $dec_point = Utility::get(
                $format,
                "decPoint",
                Utility::get(
                    $format,
                    "decimalPoint",
                    Utility::get(
                        $format,
                        "dec_point",
                        "."
                    )
                )
            );

            $thousand_sep = Utility::get(
                $format,
                "thousandSep",
                Utility::get(
                    $format,
                    "thousandSeparator",
                    Utility::get(
                        $format,
                        "thousand_sep",
                        ","
                    )
                )
            );
            $prefix = Utility::get($format, "prefix", "");
            $suffix = Utility::get($format, "suffix", "");
            return $prefix
                .number_format($value, $decimals, $dec_point, $thousand_sep)
                .$suffix;
            break;
        case "string":
            $prefix = Utility::get($format, "prefix", "");
            $suffix = Utility::get($format, "suffix", "");
            return $prefix.$value.$suffix;
            break;
        case "datetime":
            $dateFormat = Utility::get($format, "format", "Y-m-d H:i:s");
        case "date":
            $dateFormat = isset($dateFormat)
                ?$dateFormat
                :Utility::get($format, "format", "Y-m-d");
        case "time":
            $dateFormat = isset($dateFormat)
                ?$dateFormat
                :Utility::get($format, "format", "H:i:s");
            $displayFormat = Utility::get($format, "displayFormat");
            if ($displayFormat && $value) {
                if ($fvalue = \DateTime::createFromFormat($dateFormat, $value)) {
                    return $fvalue->format($displayFormat);
                }
            }
            break;
        }
        return $value;
    }
1068175
public static function format($value)
    {
        if (isset($value['priority'])) {
            $value['priority'] = QuantityFormatter::format($value['priority']);
        }
        if (isset($value['ttl'])) {
            $value['ttl'] = QuantityFormatter::format($value['ttl']);
        }
        return $value;
    }
605847
public function draw($target, $format)
    {
        /** @var ClassMetadata[] $mds */
        $mds = $this->em->getMetadataFactory()->getAllMetadata();

        // Create graph
        $g = new Graph();

        // Create all boxes
        foreach ($mds as $m) {
            $g->addBox($m->getReflectionClass()->getName());
        }

        // Add all data
        foreach ($mds as $m) {
            $ref = $m->getReflectionClass();

            // Define this entity
            $box = $g->getBox($ref->getName());

            // Class extension
            if (false !== $parent = $ref->getParentClass()) {
                $box->addExtends($parent->getName());
            }

            // Fields
            foreach ($m->getFieldNames() as $field) {
                $property = $this->findProperty($ref, $field);
                $visibility = $property->isPrivate() ? Box::VISIBILITY_PRIVATE : ($property->isProtected() ? Box::VISIBILITY_PROTECTED : Box::VISIBILITY_PUBLIC);
                $isNullable = $m->isNullable($field);
                $box->addParameter($field, $m->getTypeOfField($field), $visibility, !$isNullable);
            }

            // Associations
            foreach ($m->getAssociationNames() as $field) {
                $mapping = $m->getAssociationMapping($field);
                switch ($mapping['type']) {
                    case ClassMetadataInfo::MANY_TO_MANY:
                        if ($mapping['isOwningSide']) {
                            $box->addManyToMany(
                                $mapping['targetEntity'],
                                $mapping['fieldName']
                            );
                        }
                        break;
                    case ClassMetadataInfo::MANY_TO_ONE:
                        if ($mapping['isOwningSide']) {
                            $box->addManyToOne(
                                $mapping['targetEntity'],
                                $mapping['fieldName']
                            );
                        }
                        break;
                    case ClassMetadataInfo::ONE_TO_MANY:
                        if ($mapping['isOwningSide']) {
                            $box->addOneToMany(
                                $mapping['targetEntity'],
                                $mapping['fieldName']
                            );
                        }
                        break;
                    case ClassMetadataInfo::ONE_TO_ONE:
                        if ($mapping['isOwningSide']) {
                            $box->addOneToOne(
                                $mapping['targetEntity'],
                                $mapping['fieldName']
                            );
                        }
                        break;
                    default:
                        break;
                }
            }
        }

        return $this->plantUML->dump($g, $target, $format);
    }
1021430
public function drawStackedAreaChart(array $Format = [])
    {
        $DrawLine = isset($Format["DrawLine"]) ? $Format["DrawLine"] : false;
        $LineSurrounding = isset($Format["LineSurrounding"]) ? $Format["LineSurrounding"] : null;
        $LineR = isset($Format["LineR"]) ? $Format["LineR"] : VOID;
        $LineG = isset($Format["LineG"]) ? $Format["LineG"] : VOID;
        $LineB = isset($Format["LineB"]) ? $Format["LineB"] : VOID;
        $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
        $DrawPlot = isset($Format["DrawPlot"]) ? $Format["DrawPlot"] : false;
        $PlotRadius = isset($Format["PlotRadius"]) ? $Format["PlotRadius"] : 2;
        $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : 1;
        $PlotBorderSurrounding = isset($Format["PlotBorderSurrounding"]) ? $Format["PlotBorderSurrounding"] : null;
        $PlotBorderR = isset($Format["PlotBorderR"]) ? $Format["PlotBorderR"] : 0;
        $PlotBorderG = isset($Format["PlotBorderG"]) ? $Format["PlotBorderG"] : 0;
        $PlotBorderB = isset($Format["PlotBorderB"]) ? $Format["PlotBorderB"] : 0;
        $PlotBorderAlpha = isset($Format["PlotBorderAlpha"]) ? $Format["PlotBorderAlpha"] : 50;
        $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : null;

        $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;

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

        $RestoreShadow = $this->Shadow;
        $this->Shadow = false;

        /* Build the offset data series */
        $OverallOffset = [];
        $SerieOrder = [];
        foreach ($Data["Series"] as $SerieName => $Serie) {
            if ($Serie["isDrawable"] == true && $SerieName != $Data["Abscissa"]) {
                $SerieOrder[] = $SerieName;

                foreach ($Serie["Data"] as $Key => $Value) {
                    if ($Value == VOID) {
                        $Value = 0;
                    }
                    if ($Value >= 0) {
                        $Sign = "+";
                    } else {
                        $Sign = "-";
                    }
                    if (!isset($OverallOffset[$Key]) || !isset($OverallOffset[$Key][$Sign])) {
                        $OverallOffset[$Key][$Sign] = 0;
                    }

                    if ($Sign == "+") {
                        $Data["Series"][$SerieName]["Data"][$Key] = $Value + $OverallOffset[$Key][$Sign];
                    } else {
                        $Data["Series"][$SerieName]["Data"][$Key] = $Value - $OverallOffset[$Key][$Sign];
                    }

                    $OverallOffset[$Key][$Sign] = $OverallOffset[$Key][$Sign] + abs($Value);
                }
            }
        }
        $SerieOrder = array_reverse($SerieOrder);

        foreach ($SerieOrder as $Key => $SerieName) {
            $Serie = $Data["Series"][$SerieName];
            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 ($ForceTransparency != null) {
                    $Alpha = $ForceTransparency;
                }

                $Color = ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha];
                if ($LineSurrounding != null) {
                    $LineColor = [
                        "R" => $R + $LineSurrounding,
                        "G" => $G + $LineSurrounding,
                        "B" => $B + $LineSurrounding,
                        "Alpha" => $Alpha
                    ];
                } elseif ($LineR != VOID) {
                    $LineColor = [
                        "R" => $LineR,
                        "G" => $LineG,
                        "B" => $LineB,
                        "Alpha" => $LineAlpha
                    ];
                } else {
                    $LineColor = $Color;
                }
                if ($PlotBorderSurrounding != null) {
                    $PlotBorderColor = [
                        "R" => $R + $PlotBorderSurrounding,
                        "G" => $G + $PlotBorderSurrounding,
                        "B" => $B + $PlotBorderSurrounding,
                        "Alpha" => $PlotBorderAlpha
                    ];
                } else {
                    $PlotBorderColor = [
                        "R" => $PlotBorderR,
                        "G" => $PlotBorderG,
                        "B" => $PlotBorderB,
                        "Alpha" => $PlotBorderAlpha
                    ];
                }
                $AxisID = $Serie["Axis"];
                $Format = $Data["Axis"][$AxisID]["Format"];

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

                $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

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

                    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;
                    }

                    $Plots = [];
                    $Plots[] = $X;
                    $Plots[] = $YZero;
                    foreach ($PosArray as $Key => $Height) {
                        if ($Height != VOID) {
                            $Plots[] = $X;
                            $Plots[] = $YZero - $Height;
                        }
                        $X = $X + $XStep;
                    }
                    $Plots[] = $X - $XStep;
                    $Plots[] = $YZero;

                    $this->drawPolygon($Plots, $Color);

                    $this->Shadow = $RestoreShadow;
                    if ($DrawLine) {
                        for ($i = 2; $i <= count($Plots) - 6; $i = $i + 2) {
                            $this->drawLine(
                                $Plots[$i],
                                $Plots[$i + 1],
                                $Plots[$i + 2],
                                $Plots[$i + 3],
                                $LineColor
                            );
                        }
                    }
                    if ($DrawPlot) {
                        for ($i = 2; $i <= count($Plots) - 4; $i = $i + 2) {
                            if ($PlotBorder != 0) {
                                $this->drawFilledCircle(
                                    $Plots[$i],
                                    $Plots[$i + 1],
                                    $PlotRadius + $PlotBorder,
                                    $PlotBorderColor
                                );
                            }
                            $this->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius, $Color);
                        }
                    }
                    $this->Shadow = false;
                } elseif ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
                    if ($YZero < $this->GraphAreaX1 + 1) {
                        $YZero = $this->GraphAreaX1 + 1;
                    }
                    if ($YZero > $this->GraphAreaX2 - 1) {
                        $YZero = $this->GraphAreaX2 - 1;
                    }

                    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;
                    }

                    $Plots = [];
                    $Plots[] = $YZero;
                    $Plots[] = $Y;
                    foreach ($PosArray as $Key => $Height) {
                        if ($Height != VOID) {
                            $Plots[] = $YZero + $Height;
                            $Plots[] = $Y;
                        }
                        $Y = $Y + $YStep;
                    }
                    $Plots[] = $YZero;
                    $Plots[] = $Y - $YStep;

                    $this->drawPolygon($Plots, $Color);

                    $this->Shadow = $RestoreShadow;
                    if ($DrawLine) {
                        for ($i = 2; $i <= count($Plots) - 6; $i = $i + 2) {
                            $this->drawLine(
                                $Plots[$i],
                                $Plots[$i + 1],
                                $Plots[$i + 2],
                                $Plots[$i + 3],
                                $LineColor
                            );
                        }
                    }
                    if ($DrawPlot) {
                        for ($i = 2; $i <= count($Plots) - 4; $i = $i + 2) {
                            if ($PlotBorder != 0) {
                                $this->drawFilledCircle(
                                    $Plots[$i],
                                    $Plots[$i + 1],
                                    $PlotRadius + $PlotBorder,
                                    $PlotBorderColor
                                );
                            }

                            $this->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius, $Color);
                        }
                    }
                    $this->Shadow = false;
                }
            }
        }
        $this->Shadow = $RestoreShadow;
    }
215105
protected function getDateTimeWithOptionalFormat( $format, $value )
	{
		$date = DateTime::createFromFormat( $format, $value );

		if ( $date )
		{
			return $date;
		}

		try
		{
			return new DateTime( $value );
		}
		catch ( Exception $e )
		{
			//
		}
	}
1143741
public function process($value, $format = '%b %e, %Y', $default = null)
    {
        if (!empty($value)) {
            // convert if it's not a valid unix timestamp
            if (preg_match('#^-?\d{1,10}$#', $value) === 0) {
                $value = strtotime($value);
            }
        } elseif (!empty($default)) {
            // convert if it's not a valid unix timestamp
            if (preg_match('#^-?\d{1,10}$#', $default) === 0) {
                $value = strtotime($default);
            } else {
                $value = $default;
            }
        } else {
            return '';
        }

        // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
        if (DIRECTORY_SEPARATOR == '\\') {
            $_win_from = array(
                '%D',
                '%h',
                '%n',
                '%r',
                '%R',
                '%t',
                '%T'
            );
            $_win_to   = array(
                '%m/%d/%y',
                '%b',
                "\n",
                '%I:%M:%S %p',
                '%H:%M',
                "\t",
                '%H:%M:%S'
            );
            if (strpos($format, '%e') !== false) {
                $_win_from[] = '%e';
                $_win_to[]   = sprintf('%\' 2d', date('j', $value));
            }
            if (strpos($format, '%l') !== false) {
                $_win_from[] = '%l';
                $_win_to[]   = sprintf('%\' 2d', date('h', $value));
            }
            $format = str_replace($_win_from, $_win_to, $format);
        }

        return strftime($format, $value);
    }
5809
public static function formatAccountside($value) {
        if ($value === StaticEb::$accountsideDebitSign) {
            return \Yii::t('common/staticeb', 'Debit');
        } else if ($value === StaticEb::$accountsideCreditSign) {
            return \Yii::t('common/staticeb', 'Credit');
        } else {
            throw new Exception(\Yii::t('common/staticeb', '{value} is not a accounside. Valid values: ' . StaticEb::$accountsideDebitSign . ',' . StaticEb::$accountsideCreditSign, [ 'value' => $value]
            ));
        }
    }
828446
public function drawAreaChart(array $Format = [])
    {
        $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : false;
        $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
        $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
        $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
        $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
        $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
        $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 25;
        $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : true;
        $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : null;

        $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;

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

        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;
                }

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

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

                if ($Threshold != null) {
                    foreach ($Threshold as $Key => $Params) {
                        $Threshold[$Key]["MinX"] = $this->scaleComputeY(
                            $Params["Min"],
                            ["AxisID" => $Serie["Axis"]]
                        );
                        $Threshold[$Key]["MaxX"] = $this->scaleComputeY(
                            $Params["Max"],
                            ["AxisID" => $Serie["Axis"]]
                        );
                    }
                }

                $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

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

                    $Areas = [];
                    $AreaID = 0;
                    $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
                    if ($AroundZero) {
                        $Areas[$AreaID][] = $YZero;
                    } else {
                        $Areas[$AreaID][] = $this->GraphAreaY2 - 1;
                    }

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

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    foreach ($PosArray as $Key => $Y) {
                        if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
                            if ($Serie["Data"][$Key] > 0) {
                                $Align = TEXT_ALIGN_BOTTOMMIDDLE;
                                $Offset = $DisplayOffset;
                            } else {
                                $Align = TEXT_ALIGN_TOPMIDDLE;
                                $Offset = -$DisplayOffset;
                            }
                            $this->drawText(
                                $X,
                                $Y - $Offset,
                                $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit),
                                ["R" => $DisplayR, "G" => $DisplayG, "B" => $DisplayB, "Align" => $Align]
                            );
                        }

                        if ($Y == VOID && isset($Areas[$AreaID])) {
                            if ($LastX == null) {
                                $Areas[$AreaID][] = $X;
                            } else {
                                $Areas[$AreaID][] = $LastX;
                            }

                            if ($AroundZero) {
                                $Areas[$AreaID][] = $YZero;
                            } else {
                                $Areas[$AreaID][] = $this->GraphAreaY2 - 1;
                            }
                            $AreaID++;
                        } elseif ($Y != VOID) {
                            if (!isset($Areas[$AreaID])) {
                                $Areas[$AreaID][] = $X;
                                if ($AroundZero) {
                                    $Areas[$AreaID][] = $YZero;
                                } else {
                                    $Areas[$AreaID][] = $this->GraphAreaY2 - 1;
                                }
                            }

                            $Areas[$AreaID][] = $X;
                            $Areas[$AreaID][] = $Y;
                        }

                        $LastX = $X;
                        $X = $X + $XStep;
                    }
                    $Areas[$AreaID][] = $LastX;
                    if ($AroundZero) {
                        $Areas[$AreaID][] = $YZero;
                    } else {
                        $Areas[$AreaID][] = $this->GraphAreaY2 - 1;
                    }

                    /* Handle shadows in the areas */
                    if ($this->Shadow) {
                        $ShadowArea = [];
                        foreach ($Areas as $Key => $Points) {
                            $ShadowArea[$Key] = [];
                            foreach ($Points as $Key2 => $Value) {
                                if ($Key2 % 2 == 0) {
                                    $ShadowArea[$Key][] = $Value + $this->ShadowX;
                                } else {
                                    $ShadowArea[$Key][] = $Value + $this->ShadowY;
                                }
                            }
                        }

                        foreach ($ShadowArea as $Key => $Points) {
                            $this->drawPolygonChart(
                                $Points,
                                [
                                    "R" => $this->ShadowR,
                                    "G" => $this->ShadowG,
                                    "B" => $this->ShadowB,
                                    "Alpha" => $this->Shadowa
                                ]
                            );
                        }
                    }

                    $Alpha = $ForceTransparency != null ? $ForceTransparency : $Alpha;
                    $Color = [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Threshold" => $Threshold
                    ];

                    foreach ($Areas as $Key => $Points) {
                        $this->drawPolygonChart($Points, $Color);
                    }
                } else {
                    if ($YZero < $this->GraphAreaX1 + 1) {
                        $YZero = $this->GraphAreaX1 + 1;
                    }
                    if ($YZero > $this->GraphAreaX2 - 1) {
                        $YZero = $this->GraphAreaX2 - 1;
                    }

                    $Areas = [];
                    $AreaID = 0;
                    if ($AroundZero) {
                        $Areas[$AreaID][] = $YZero;
                    } else {
                        $Areas[$AreaID][] = $this->GraphAreaX1 + 1;
                    }
                    $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;

                    if ($XDivs == 0) {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
                    } else {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
                    }
                    $Y = $this->GraphAreaY1 + $XMargin;
                    $LastX = null;
                    $LastY = null;

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    foreach ($PosArray as $Key => $X) {
                        if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
                            if ($Serie["Data"][$Key] > 0) {
                                $Align = TEXT_ALIGN_BOTTOMMIDDLE;
                                $Offset = $DisplayOffset;
                            } else {
                                $Align = TEXT_ALIGN_TOPMIDDLE;
                                $Offset = -$DisplayOffset;
                            }
                            $this->drawText(
                                $X + $Offset,
                                $Y,
                                $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit),
                                [
                                    "Angle" => 270,
                                    "R" => $DisplayR,
                                    "G" => $DisplayG,
                                    "B" => $DisplayB,
                                    "Align" => $Align
                                ]
                            );
                        }

                        if ($X == VOID && isset($Areas[$AreaID])) {
                            if ($AroundZero) {
                                $Areas[$AreaID][] = $YZero;
                            } else {
                                $Areas[$AreaID][] = $this->GraphAreaX1 + 1;
                            }

                            if ($LastY == null) {
                                $Areas[$AreaID][] = $Y;
                            } else {
                                $Areas[$AreaID][] = $LastY;
                            }

                            $AreaID++;
                        } elseif ($X != VOID) {
                            if (!isset($Areas[$AreaID])) {
                                if ($AroundZero) {
                                    $Areas[$AreaID][] = $YZero;
                                } else {
                                    $Areas[$AreaID][] = $this->GraphAreaX1 + 1;
                                }
                                $Areas[$AreaID][] = $Y;
                            }

                            $Areas[$AreaID][] = $X;
                            $Areas[$AreaID][] = $Y;
                        }

                        $LastX = $X;
                        $LastY = $Y;
                        $Y = $Y + $YStep;
                    }
                    if ($AroundZero) {
                        $Areas[$AreaID][] = $YZero;
                    } else {
                        $Areas[$AreaID][] = $this->GraphAreaX1 + 1;
                    }
                    $Areas[$AreaID][] = $LastY;

                    /* Handle shadows in the areas */
                    if ($this->Shadow) {
                        $ShadowArea = [];
                        foreach ($Areas as $Key => $Points) {
                            $ShadowArea[$Key] = [];
                            foreach ($Points as $Key2 => $Value) {
                                if ($Key2 % 2 == 0) {
                                    $ShadowArea[$Key][] = $Value + $this->ShadowX;
                                } else {
                                    $ShadowArea[$Key][] = $Value + $this->ShadowY;
                                }
                            }
                        }

                        foreach ($ShadowArea as $Key => $Points) {
                            $this->drawPolygonChart(
                                $Points,
                                [
                                    "R" => $this->ShadowR,
                                    "G" => $this->ShadowG,
                                    "B" => $this->ShadowB,
                                    "Alpha" => $this->Shadowa
                                ]
                            );
                        }
                    }

                    $Alpha = $ForceTransparency != null ? $ForceTransparency : $Alpha;
                    $Color = ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "Threshold" => $Threshold];

                    foreach ($Areas as $Key => $Points) {
                        $this->drawPolygonChart($Points, $Color);
                    }
                }
            }
        }
    }
1368535
protected function formatValue($value, $format, $row = null)
    {
        $formatValue = Utility::get($format, "formatValue", null);

        if (is_string($formatValue)) {
            eval('$fv="' . str_replace('@value', '$value', $formatValue) . '";');
            return $fv;
        } else if (is_callable($formatValue)) {
            return $formatValue($value, $row);
        } else {
            return Utility::format($value, $format);
        }
    }
1014719
protected function date($name, $value, $format){
        //Si no se completo no se valida
        if(! $this->isComplete($value)){
            return TRUE;
        }
        $separator_type= array(
            "/",
            "-",
            "."
        );        
        $separator_used= NULL;
        foreach ($separator_type as $separator) {
            $find= stripos($value, $separator);
            if($find <> FALSE){
                $separator_used= $separator;
            }
        }        
        if($separator_used != NULL){      
            $dato_array= explode($separator_used, $value);
            $valid= FALSE;
            switch ($format){
                case 'Y-m-d':
                    if($separator_used == '-'){
                        $valid= checkdate($dato_array[1], $dato_array[2], $dato_array[0]);
                    }
                    break;
                case 'd-m-Y':
                    if($separator_used == '-'){
                        $valid= checkdate($dato_array[1], $dato_array[0], $dato_array[2]);
                    }
                    break;
                case 'd/m/Y':
                    if($separator_used == '/'){
                        $valid= checkdate($dato_array[1], $dato_array[0], $dato_array[2]);
                    }
                    break;
                case 'Y/m/d':
                    if($separator_used == '/'){
                        $valid= checkdate($dato_array[1], $dato_array[2], $dato_array[0]);
                    }
                    break;
                case 'Y.m.d':
                    if($separator_used == '.'){
                        $valid= checkdate($dato_array[1], $dato_array[2], $dato_array[0]);
                    }
                    break;
                case 'd.m.Y':
                    if($separator_used == '.'){
                        $valid= checkdate($dato_array[1], $dato_array[0], $dato_array[2]);
                    }
                    break;
                default :
                    if($separator_used == '-'){
                        $valid= checkdate($dato_array[1], $dato_array[2], $dato_array[0]);
                    }
                    break;          
            }
        }else{
            $valid= false;
        }
        
        if($valid){
            return TRUE;
        }else{
            $this->add_message($name, 'date', array('format' => $format));
            return FALSE;
        }        
    }
375390
public function draw2DPie($X, $Y, array $Format = [])
    {
        $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60;
        $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0;
        $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0;
        $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0;
        $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : true;
        $Border = isset($Format["Border"]) ? $Format["Border"] : false;
        $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
        $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
        $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
        $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : false;
        $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : false;
        $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : false;
        $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL;
        $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0;
        $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0;
        $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0;
        $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100;
        $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : null;
        $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE;
        $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15;
        $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : "";
        $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255;
        $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255;
        $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255;
        $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100;
        $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false;

        $Data = $this->pDataObject->getData();
        $Palette = $this->pDataObject->getPalette();

        /* Do we have an abscissa serie defined? */
        if ($Data["Abscissa"] == "") {
            return PIE_NO_ABSCISSA;
        }

        /* Try to find the data serie */
        $DataSerie = null;
        foreach (array_keys($Data["Series"]) as $SerieName) {
            if ($SerieName != $Data["Abscissa"]) {
                $DataSerie = $SerieName;
            }
        }

        /* Do we have data to compute? */
        if (!$DataSerie) {
            return PIE_NO_DATASERIE;
        }

        /* Remove unused data */
        list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]);

        /* Compute the pie sum */
        $SerieSum = $this->pDataObject->getSum($DataSerie);

        /* Do we have data to draw? */
        if ($SerieSum == 0) {
            return PIE_SUMISNULL;
        }

        /* Dump the real number of data to draw */
        $Values = [];
        foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) {
            if ($Value != 0) {
                $Values[] = $Value;
            }
        }

        /* Compute the wasted angular space between series */
        if (count($Values) == 1) {
            $WastedAngular = 0;
        } else {
            $WastedAngular = count($Values) * $DataGapAngle;
        }

        /* Compute the scale */
        $ScaleFactor = (360 - $WastedAngular) / $SerieSum;

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

            $ShadowFormat = $Format;
            $ShadowFormat["Shadow"] = true;
            $this->draw2DPie(
                $X + $this->pChartObject->ShadowX,
                $Y + $this->pChartObject->ShadowY,
                $ShadowFormat
            );
        }

        /* Draw the polygon pie elements */
        $Step = 360 / (2 * PI * $Radius);
        $Offset = 0;
        $ID = 0;
        foreach ($Values as $Key => $Value) {
            if ($Shadow) {
                $Settings = [
                    "R" => $this->pChartObject->ShadowR,
                    "G" => $this->pChartObject->ShadowG,
                    "B" => $this->pChartObject->ShadowB,
                    "Alpha" => $this->pChartObject->Shadowa
                ];
            } else {
                if (!isset($Palette[$ID]["R"])) {
                    $Color = $this->pChartObject->getRandomColor();
                    $Palette[$ID] = $Color;
                    $this->pDataObject->savePalette($ID, $Color);
                }
                $Settings = [
                    "R" => $Palette[$ID]["R"],
                    "G" => $Palette[$ID]["G"],
                    "B" => $Palette[$ID]["B"],
                    "Alpha" => $Palette[$ID]["Alpha"]
                ];
            }

            if (!$SecondPass && !$Shadow) {
                if (!$Border) {
                    $Settings["Surrounding"] = 10;
                } else {
                    $Settings["BorderR"] = $BorderR;
                    $Settings["BorderG"] = $BorderG;
                    $Settings["BorderB"] = $BorderB;
                }
            }

            $EndAngle = $Offset + ($Value * $ScaleFactor);
            if ($EndAngle > 360) {
                $EndAngle = 360;
            }

            $Angle = ($EndAngle - $Offset) / 2 + $Offset;
            if ($DataGapAngle == 0) {
                $X0 = $X;
                $Y0 = $Y;
            } else {
                $X0 = cos(($Angle - 90) * PI / 180) * $DataGapRadius + $X;
                $Y0 = sin(($Angle - 90) * PI / 180) * $DataGapRadius + $Y;
            }

            $Plots = [$X0, $Y0];

            for ($i = $Offset; $i <= $EndAngle; $i = $i + $Step) {
                $Xc = cos(($i - 90) * PI / 180) * $Radius + $X;
                $Yc = sin(($i - 90) * PI / 180) * $Radius + $Y;

                if ($SecondPass && ($i < 90)) {
                    $Yc++;
                }
                if ($SecondPass && ($i > 180 && $i < 270)) {
                    $Xc++;
                }
                if ($SecondPass && ($i >= 270)) {
                    $Xc++;
                    $Yc++;
                }

                $Plots[] = $Xc;
                $Plots[] = $Yc;
            }

            $this->pChartObject->drawPolygon($Plots, $Settings);
            if ($RecordImageMap && !$Shadow) {
                $this->pChartObject->addToImageMap(
                    "POLY",
                    $this->arraySerialize($Plots),
                    $this->pChartObject->toHTMLColor(
                        $Palette[$ID]["R"],
                        $Palette[$ID]["G"],
                        $Palette[$ID]["B"]
                    ),
                    $Data["Series"][$Data["Abscissa"]]["Data"][$Key],
                    $Value
                );
            }

            if ($DrawLabels && !$Shadow && !$SecondPass) {
                if ($LabelColor == PIE_LABEL_COLOR_AUTO) {
                    $Settings = [
                        "FillR" => $Palette[$ID]["R"],
                        "FillG" => $Palette[$ID]["G"],
                        "FillB" => $Palette[$ID]["B"],
                        "Alpha" => $Palette[$ID]["Alpha"]
                    ];
                } else {
                    $Settings = [
                        "FillR" => $LabelR,
                        "FillG" => $LabelG,
                        "FillB" => $LabelB,
                        "Alpha" => $LabelAlpha
                    ];
                }

                $Angle = ($EndAngle - $Offset) / 2 + $Offset;
                $Xc = cos(($Angle - 90) * PI / 180) * $Radius + $X;
                $Yc = sin(($Angle - 90) * PI / 180) * $Radius + $Y;

                $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key];

                if ($LabelStacked) {
                    $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, true, $X, $Y, $Radius);
                } else {
                    $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, false);
                }
            }

            $Offset = $i + $DataGapAngle;
            $ID++;
        }

        /* Second pass to smooth the angles */
        if ($SecondPass) {
            $Step = 360 / (2 * PI * $Radius);
            $Offset = 0;
            $ID = 0;
            foreach ($Values as $Key => $Value) {
                $FirstPoint = true;
                if ($Shadow) {
                    $Settings = [
                        "R" => $this->pChartObject->ShadowR,
                        "G" => $this->pChartObject->ShadowG,
                        "B" => $this->pChartObject->ShadowB,
                        "Alpha" => $this->pChartObject->Shadowa
                    ];
                } else {
                    if ($Border) {
                        $Settings = ["R" => $BorderR, "G" => $BorderG, "B" => $BorderB];
                    } else {
                        $Settings = [
                            "R" => $Palette[$ID]["R"],
                            "G" => $Palette[$ID]["G"],
                            "B" => $Palette[$ID]["B"],
                            "Alpha" => $Palette[$ID]["Alpha"]
                        ];
                    }
                }

                $EndAngle = $Offset + ($Value * $ScaleFactor);
                if ($EndAngle > 360) {
                    $EndAngle = 360;
                }

                if ($DataGapAngle == 0) {
                    $X0 = $X;
                    $Y0 = $Y;
                } else {
                    $Angle = ($EndAngle - $Offset) / 2 + $Offset;
                    $X0 = cos(($Angle - 90) * PI / 180) * $DataGapRadius + $X;
                    $Y0 = sin(($Angle - 90) * PI / 180) * $DataGapRadius + $Y;
                }
                $Plots[] = $X0;
                $Plots[] = $Y0;

                for ($i = $Offset; $i <= $EndAngle; $i = $i + $Step) {
                    $Xc = cos(($i - 90) * PI / 180) * $Radius + $X;
                    $Yc = sin(($i - 90) * PI / 180) * $Radius + $Y;

                    if ($FirstPoint) {
                        $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings);
                        $FirstPoint = false;
                    }

                    $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings);
                }
                $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings);

                if ($DrawLabels && !$Shadow) {
                    if ($LabelColor == PIE_LABEL_COLOR_AUTO) {
                        $Settings = [
                            "FillR" => $Palette[$ID]["R"],
                            "FillG" => $Palette[$ID]["G"],
                            "FillB" => $Palette[$ID]["B"],
                            "Alpha" => $Palette[$ID]["Alpha"]
                        ];
                    } else {
                        $Settings = [
                            "FillR" => $LabelR,
                            "FillG" => $LabelG,
                            "FillB" => $LabelB,
                            "Alpha" => $LabelAlpha
                        ];
                    }

                    $Angle = ($EndAngle - $Offset) / 2 + $Offset;
                    $Xc = cos(($Angle - 90) * PI / 180) * $Radius + $X;
                    $Yc = sin(($Angle - 90) * PI / 180) * $Radius + $Y;

                    $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key];

                    if ($LabelStacked) {
                        $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, true, $X, $Y, $Radius);
                    } else {
                        $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, false);
                    }
                }

                $Offset = $i + $DataGapAngle;
                $ID++;
            }
        }

        if ($WriteValues != null && !$Shadow) {
            $Step = 360 / (2 * PI * $Radius);
            $Offset = 0;
            $ID = count($Values) - 1;
            $Settings = [
                "Align" => TEXT_ALIGN_MIDDLEMIDDLE,
                "R" => $ValueR,
                "G" => $ValueG,
                "B" => $ValueB,
                "Alpha" => $ValueAlpha
            ];
            foreach ($Values as $Key => $Value) {
                $EndAngle = ($Value * $ScaleFactor) + $Offset;
                if ((int) $EndAngle > 360) {
                    $EndAngle = 0;
                }
                $Angle = ($EndAngle - $Offset) / 2 + $Offset;

                if ($ValuePosition == PIE_VALUE_OUTSIDE) {
                    $Xc = cos(($Angle - 90) * PI / 180) * ($Radius + $ValuePadding) + $X;
                    $Yc = sin(($Angle - 90) * PI / 180) * ($Radius + $ValuePadding) + $Y;
                } else {
                    $Xc = cos(($Angle - 90) * PI / 180) * ($Radius) / 2 + $X;
                    $Yc = sin(($Angle - 90) * PI / 180) * ($Radius) / 2 + $Y;
                }

                if ($WriteValues == PIE_VALUE_PERCENTAGE) {
                    $Display = round((100 / $SerieSum) * $Value, $Precision) . "%";
                } elseif ($WriteValues == PIE_VALUE_NATURAL) {
                    $Display = $Value . $ValueSuffix;
                }
                $this->pChartObject->drawText($Xc, $Yc, $Display, $Settings);

                $Offset = $EndAngle + $DataGapAngle;
                $ID--;
            }
        }

        if ($DrawLabels && $LabelStacked) {
            $this->writeShiftedLabels();
        }

        $this->pChartObject->Shadow = $RestoreShadow;

        return PIE_RENDERED;
    }
102629
public function scaleFormat($Value, $Mode = null, $Format = null, $Unit = null)
    {
        if ($Value == VOID) {
            return "";
        }

        if ($Mode == AXIS_FORMAT_TRAFFIC) {
            if ($Value == 0) {
                return "0B";
            }
            $Units = ["B", "KB", "MB", "GB", "TB", "PB"];
            $Sign = "";
            if ($Value < 0) {
                $Value = abs($Value);
                $Sign = "-";
            }

            $Value = number_format($Value / pow(1024, ($Scale = floor(log($Value, 1024)))), 2, ",", ".");
            return $Sign . $Value . " " . $Units[$Scale];
        }

        if ($Mode == AXIS_FORMAT_CUSTOM) {
            if (is_callable($Format)) {
                return call_user_func($Format, $Value);
            }
        }

        if ($Mode == AXIS_FORMAT_DATE) {
            $Pattern = "d/m/Y";
            if ($Format !== null) {
                $Pattern = $Format;
            }

            return gmdate($Pattern, $Value);
        }

        if ($Mode == AXIS_FORMAT_TIME) {
            $Pattern = "H:i:s";
            if ($Format !== null) {
                $Pattern = $Format;
            }

            return gmdate($Pattern, $Value);
        }

        if ($Mode == AXIS_FORMAT_CURRENCY) {
            return $Format . number_format($Value, 2);
        }

        if ($Mode == AXIS_FORMAT_METRIC) {
            if (abs($Value) > 1000000000) {
                return round($Value / 1000000000, $Format) . "g" . $Unit;
            }
            if (abs($Value) > 1000000) {
                return round($Value / 1000000, $Format) . "m" . $Unit;
            } elseif (abs($Value) >= 1000) {
                return round($Value / 1000, $Format) . "k" . $Unit;
            }
        }
        return $Value . $Unit;
    }
1290149
public static function fromString($value, array $formats = [])
	{
		$formats = array_merge($formats, [
			'Y-m-d H:i:s.u',
			'Y-m-d H:i:s',
			'Y-m-d',
			'j. n. Y G:i:s',
			'j. n. Y G:i',
			'j. n. Y',
			'U',
		]);

		if ($value instanceof \DateTime) {
			return $value;
		}

		if ($value instanceof \DateTimeImmutable) {
			$date = new \DateTime('now', $value->getTimezone());
			$date->setTimestamp($value->getTimestamp());

			return $date;
		}

		foreach ($formats as $format) {
			if (!is_string($format) || !$date = \DateTime::createFromFormat($format, $value)) {
				continue;
			}

			return $date;
		}

		$timestamp = strtotime($value);

		if ($timestamp !== false) {
			$date = new \DateTime;
			$date->setTimestamp($timestamp);

			return $date;
		}

		throw new DataGridDateTimeHelperException;
	}
1151908
protected function validateBeforeWithFormat($format, $value, $parameters)
    {
        $param = $this->getValue($parameters[0]) ?: $parameters[0];

        return $this->checkDateTimeOrder($format, $value, $param);
    }
926752
public function drawSplineChart(array $Format = [])
    {
        $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : true;
        $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
        $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : null; // 234
        $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : null; // 55
        $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : null; // 26
        $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : false;
        $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
        $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
        $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
        $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
        $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
        $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false;
        $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;

        $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;

        $Data = $this->DataSet->getData();
        list($XMargin, $XDivs) = $this->scaleGetXSettings();
        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"];
                $Weight = $Serie["Weight"];

                if ($BreakR == null) {
                    $BreakSettings = [
                        "R" => $R,
                        "G" => $G,
                        "B" => $B,
                        "Alpha" => $Alpha,
                        "Ticks" => $VoidTicks
                    ];
                } else {
                    $BreakSettings = [
                        "R" => $BreakR,
                        "G" => $BreakG,
                        "B" => $BreakB,
                        "Alpha" => $Alpha,
                        "Ticks" => $VoidTicks,
                        "Weight" => $Weight
                    ];
                }
                if ($DisplayColor == DISPLAY_AUTO) {
                    $DisplayR = $R;
                    $DisplayG = $G;
                    $DisplayB = $B;
                }

                $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"]]
                );

                $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

                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;
                    $WayPoints = [];
                    $Force = $XStep / 5;

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    $LastGoodY = null;
                    $LastGoodX = null;
                    $LastX = 1;
                    $LastY = 1;
                    foreach ($PosArray as $Key => $Y) {
                        if ($DisplayValues) {
                            $this->drawText(
                                $X,
                                $Y - $DisplayOffset,
                                $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit),
                                [
                                    "R" => $DisplayR,
                                    "G" => $DisplayG,
                                    "B" => $DisplayB,
                                    "Align" => TEXT_ALIGN_BOTTOMMIDDLE
                                ]
                            );
                        }
                        if ($RecordImageMap && $Y != VOID) {
                            $this->addToImageMap(
                                "CIRCLE",
                                floor($X) . "," . floor($Y) . "," . $ImageMapPlotSize,
                                $this->toHTMLColor($R, $G, $B),
                                $SerieDescription,
                                $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                            );
                        }

                        if ($Y == VOID && $LastY != null) {
                            $this->drawSpline(
                                $WayPoints,
                                [
                                    "Force" => $Force,
                                    "R" => $R,
                                    "G" => $G,
                                    "B" => $B,
                                    "Alpha" => $Alpha,
                                    "Ticks" => $Ticks,
                                    "Weight" => $Weight
                                ]
                            );
                            $WayPoints = [];
                        }

                        if ($Y != VOID && $LastY == null && $LastGoodY != null && !$BreakVoid) {
                            $this->drawLine($LastGoodX, $LastGoodY, $X, $Y, $BreakSettings);
                        }

                        if ($Y != VOID) {
                            $WayPoints[] = [$X, $Y];
                        }
                        if ($Y != VOID) {
                            $LastGoodY = $Y;
                            $LastGoodX = $X;
                        }
                        if ($Y == VOID) {
                            $Y = null;
                        }

                        $LastX = $X;
                        $LastY = $Y;
                        $X = $X + $XStep;
                    }
                    $this->drawSpline(
                        $WayPoints,
                        [
                            "Force" => $Force,
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha,
                            "Ticks" => $Ticks,
                            "Weight" => $Weight
                        ]
                    );
                } else {
                    if ($XDivs == 0) {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
                    } else {
                        $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
                    }
                    $Y = $this->GraphAreaY1 + $XMargin;
                    $WayPoints = [];
                    $Force = $YStep / 5;

                    if (!is_array($PosArray)) {
                        $Value = $PosArray;
                        $PosArray = [];
                        $PosArray[0] = $Value;
                    }
                    $LastGoodY = null;
                    $LastGoodX = null;
                    $LastX = 1;
                    $LastY = 1;
                    foreach ($PosArray as $Key => $X) {
                        if ($DisplayValues) {
                            $this->drawText(
                                $X + $DisplayOffset,
                                $Y,
                                $this->scaleFormat(
                                    $Serie["Data"][$Key],
                                    $Mode,
                                    $Format,
                                    $Unit
                                ),
                                [
                                    "Angle" => 270,
                                    "R" => $DisplayR,
                                    "G" => $DisplayG,
                                    "B" => $DisplayB,
                                    "Align" => TEXT_ALIGN_BOTTOMMIDDLE
                                ]
                            );
                        }
                        if ($RecordImageMap && $X != VOID) {
                            $this->addToImageMap(
                                "CIRCLE",
                                floor($X) . "," . floor($Y) . "," . $ImageMapPlotSize,
                                $this->toHTMLColor($R, $G, $B),
                                $SerieDescription,
                                $this->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit)
                            );
                        }

                        if ($X == VOID && $LastX != null) {
                            $this->drawSpline(
                                $WayPoints,
                                [
                                    "Force" => $Force,
                                    "R" => $R,
                                    "G" => $G,
                                    "B" => $B,
                                    "Alpha" => $Alpha,
                                    "Ticks" => $Ticks,
                                    "Weight" => $Weight
                                ]
                            );
                            $WayPoints = [];
                        }

                        if ($X != VOID && $LastX == null && $LastGoodX != null && !$BreakVoid) {
                            $this->drawLine($LastGoodX, $LastGoodY, $X, $Y, $BreakSettings);
                        }

                        if ($X != VOID) {
                            $WayPoints[] = [$X, $Y];
                        }
                        if ($X != VOID) {
                            $LastGoodX = $X;
                            $LastGoodY = $Y;
                        }
                        if ($X == VOID) {
                            $X = null;
                        }

                        $LastX = $X;
                        $LastY = $Y;
                        $Y = $Y + $YStep;
                    }
                    $this->drawSpline(
                        $WayPoints,
                        [
                            "Force" => $Force,
                            "R" => $R,
                            "G" => $G,
                            "B" => $B,
                            "Alpha" => $Alpha,
                            "Ticks" => $Ticks,
                            "Weight" => $Weight
                        ]
                    );
                }
            }
        }
    }
668252
public function drawScatterLineChart($Format = null)
    {
        $Data = $this->pDataObject->getData();
        $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : false;
        $ImageMapTitle = isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : null;
        $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 10;

        /* Parse all the series to draw */
        foreach ($Data["ScatterSeries"] as $Key => $Series) {
            if ($Series["isDrawable"] == true) {
                $SerieX = $Series["X"];
                $SerieValuesX = $Data["Series"][$SerieX]["Data"];
                $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
                $SerieY = $Series["Y"];
                $SerieValuesY = $Data["Series"][$SerieY]["Data"];
                $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
                $Ticks = $Series["Ticks"];
                $Weight = $Series["Weight"];

                if ($ImageMapTitle == null) {
                    $Description = sprintf(
                        "%s / %s",
                        $Data["Series"][$Series["X"]]["Description"],
                        $Data["Series"][$Series["Y"]]["Description"]
                    );
                } else {
                    $Description = $ImageMapTitle;
                }

                $PosArrayX = $this->getPosArray($SerieValuesX, $SerieXAxis);
                if (!is_array($PosArrayX)) {
                    $Value = $PosArrayX;
                    $PosArrayX = [];
                    $PosArrayX[0] = $Value;
                }
                $PosArrayY = $this->getPosArray($SerieValuesY, $SerieYAxis);
                if (!is_array($PosArrayY)) {
                    $Value = $PosArrayY;
                    $PosArrayY = [];
                    $PosArrayY[0] = $Value;
                }

                $Color = [
                    "R" => $Series["Color"]["R"],
                    "G" => $Series["Color"]["G"],
                    "B" => $Series["Color"]["B"],
                    "Alpha" => $Series["Color"]["Alpha"]
                ];
                if ($Ticks != 0) {
                    $Color["Ticks"] = $Ticks;
                }
                if ($Weight != 0) {
                    $Color["Weight"] = $Weight;
                }

                $LastX = VOID;
                $LastY = VOID;
                foreach ($PosArrayX as $Key => $Value) {
                    $X = $Value;
                    $Y = $PosArrayY[$Key];

                    if ($X != VOID && $Y != VOID) {
                        $RealValue = sprintf(
                            "%s / %s",
                            round($Data["Series"][$Series["X"]]["Data"][$Key], 2),
                            round($Data["Series"][$Series["Y"]]["Data"][$Key], 2)
                        );
                        if ($RecordImageMap) {
                            $this->pChartObject->addToImageMap(
                                "CIRCLE",
                                sprintf("%s,%s,%s", floor($X), floor($Y), $ImageMapPlotSize),
                                $this->pChartObject->toHTMLColor(
                                    $Series["Color"]["R"],
                                    $Series["Color"]["G"],
                                    $Series["Color"]["B"]
                                ),
                                $Description,
                                $RealValue
                            );
                        }
                    }

                    if ($X != VOID && $Y != VOID && $LastX != VOID && $LastY != VOID) {
                        $this->pChartObject->drawLine($LastX, $LastY, $X, $Y, $Color);
                    }
                    $LastX = $X;
                    $LastY = $Y;
                }
            }
        }
    }