Bubble.php
1 year ago
Indicator.php
1 year ago
Pie.php
1 year ago
Radar.php
1 year ago
Scatter.php
1 year ago
Split.php
1 year ago
Spring.php
1 year ago
Stock.php
1 year ago
Surface.php
1 year ago
Split.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CpChart\Chart; |
| 4 | |
| 5 | use CpChart\Data; |
| 6 | use CpChart\Image; |
| 7 | /** |
| 8 | * Split - class to draw spline splitted charts |
| 9 | * |
| 10 | * Version : 2.1.4 |
| 11 | * Made by : Jean-Damien POGOLOTTI |
| 12 | * Last Update : 19/01/2014 |
| 13 | * |
| 14 | * This file can be distributed under the license you can find at : |
| 15 | * |
| 16 | * http://www.pchart.net/license |
| 17 | * |
| 18 | * You can find the whole class documentation on the pChart web site. |
| 19 | */ |
| 20 | class Split |
| 21 | { |
| 22 | /** |
| 23 | * @var Image |
| 24 | */ |
| 25 | public $pChartObject; |
| 26 | /** |
| 27 | * Create the encoded string |
| 28 | * @param Image $Object |
| 29 | * @param Data $Values |
| 30 | * @param array $Format |
| 31 | */ |
| 32 | public function drawSplitPath(Image $Object, Data $Values, array $Format = []) |
| 33 | { |
| 34 | $this->pChartObject = $Object; |
| 35 | $Spacing = isset($Format["Spacing"]) ? $Format["Spacing"] : 20; |
| 36 | $TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 2; |
| 37 | $TextPos = isset($Format["TextPos"]) ? $Format["TextPos"] : TEXT_POS_TOP; |
| 38 | $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null; |
| 39 | $Force = isset($Format["Force"]) ? $Format["Force"] : 70; |
| 40 | $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 15; |
| 41 | $X1 = $Object->GraphAreaX1; |
| 42 | $Y1 = $Object->GraphAreaY1; |
| 43 | $X2 = $Object->GraphAreaX2; |
| 44 | $Y2 = $Object->GraphAreaY2; |
| 45 | /* Data Processing */ |
| 46 | $Data = $Values->getData(); |
| 47 | $Palette = $Values->getPalette(); |
| 48 | $LabelSerie = $Data["Abscissa"]; |
| 49 | $DataSerie = []; |
| 50 | foreach ($Data["Series"] as $SerieName => $Value) { |
| 51 | if ($SerieName != $LabelSerie && empty($DataSerie)) { |
| 52 | $DataSerie = $SerieName; |
| 53 | } |
| 54 | } |
| 55 | $DataSerieSum = array_sum($Data["Series"][$DataSerie]["Data"]); |
| 56 | $DataSerieCount = count($Data["Series"][$DataSerie]["Data"]); |
| 57 | /* Scale Processing */ |
| 58 | if ($TextPos == TEXT_POS_RIGHT) { |
| 59 | $YScale = ($Y2 - $Y1 - ($DataSerieCount + 1) * $Spacing) / $DataSerieSum; |
| 60 | } else { |
| 61 | $YScale = ($Y2 - $Y1 - $DataSerieCount * $Spacing) / $DataSerieSum; |
| 62 | } |
| 63 | $LeftHeight = $DataSerieSum * $YScale; |
| 64 | /* Re-compute graph width depending of the text mode choosen */ |
| 65 | if ($TextPos == TEXT_POS_RIGHT) { |
| 66 | $MaxWidth = 0; |
| 67 | foreach ($Data["Series"][$LabelSerie]["Data"] as $Key => $Label) { |
| 68 | $Boundardies = $Object->getTextBox(0, 0, $Object->FontName, $Object->FontSize, 0, $Label); |
| 69 | if ($Boundardies[1]["X"] > $MaxWidth) { |
| 70 | $MaxWidth = $Boundardies[1]["X"] + $TextPadding * 2; |
| 71 | } |
| 72 | } |
| 73 | $X2 = $X2 - $MaxWidth; |
| 74 | } |
| 75 | /* Drawing */ |
| 76 | $LeftY = ($Y2 - $Y1) / 2 + $Y1 - $LeftHeight / 2; |
| 77 | $RightY = $Y1; |
| 78 | foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) { |
| 79 | if (isset($Data["Series"][$LabelSerie]["Data"][$Key])) { |
| 80 | $Label = $Data["Series"][$LabelSerie]["Data"][$Key]; |
| 81 | } else { |
| 82 | $Label = "-"; |
| 83 | } |
| 84 | $LeftY1 = $LeftY; |
| 85 | $LeftY2 = $LeftY + $Value * $YScale; |
| 86 | $RightY1 = $RightY + $Spacing; |
| 87 | $RightY2 = $RightY + $Spacing + $Value * $YScale; |
| 88 | $Settings = ["R" => $Palette[$Key]["R"], "G" => $Palette[$Key]["G"], "B" => $Palette[$Key]["B"], "Alpha" => $Palette[$Key]["Alpha"], "NoDraw" => \true, "Segments" => $Segments, "Surrounding" => $Surrounding]; |
| 89 | $Angle = $Object->getAngle($X2, $RightY1, $X1, $LeftY1); |
| 90 | $VectorX1 = cos(deg2rad($Angle + 90)) * $Force + ($X2 - $X1) / 2 + $X1; |
| 91 | $VectorY1 = sin(deg2rad($Angle + 90)) * $Force + ($RightY1 - $LeftY1) / 2 + $LeftY1; |
| 92 | $VectorX2 = cos(deg2rad($Angle - 90)) * $Force + ($X2 - $X1) / 2 + $X1; |
| 93 | $VectorY2 = sin(deg2rad($Angle - 90)) * $Force + ($RightY1 - $LeftY1) / 2 + $LeftY1; |
| 94 | $Points = $Object->drawBezier($X1, $LeftY1, $X2, $RightY1, $VectorX1, $VectorY1, $VectorX2, $VectorY2, $Settings); |
| 95 | $PolyGon = []; |
| 96 | foreach ($Points as $Key => $Pos) { |
| 97 | $PolyGon[] = $Pos["X"]; |
| 98 | $PolyGon[] = $Pos["Y"]; |
| 99 | } |
| 100 | $Angle = $Object->getAngle($X2, $RightY2, $X1, $LeftY2); |
| 101 | $VectorX1 = cos(deg2rad($Angle + 90)) * $Force + ($X2 - $X1) / 2 + $X1; |
| 102 | $VectorY1 = sin(deg2rad($Angle + 90)) * $Force + ($RightY2 - $LeftY2) / 2 + $LeftY2; |
| 103 | $VectorX2 = cos(deg2rad($Angle - 90)) * $Force + ($X2 - $X1) / 2 + $X1; |
| 104 | $VectorY2 = sin(deg2rad($Angle - 90)) * $Force + ($RightY2 - $LeftY2) / 2 + $LeftY2; |
| 105 | $Points = $Object->drawBezier($X1, $LeftY2, $X2, $RightY2, $VectorX1, $VectorY1, $VectorX2, $VectorY2, $Settings); |
| 106 | $Points = array_reverse($Points); |
| 107 | foreach ($Points as $Key => $Pos) { |
| 108 | $PolyGon[] = $Pos["X"]; |
| 109 | $PolyGon[] = $Pos["Y"]; |
| 110 | } |
| 111 | $Object->drawPolygon($PolyGon, $Settings); |
| 112 | if ($TextPos == TEXT_POS_RIGHT) { |
| 113 | $Object->drawText($X2 + $TextPadding, ($RightY2 - $RightY1) / 2 + $RightY1, $Label, ["Align" => TEXT_ALIGN_MIDDLELEFT]); |
| 114 | } else { |
| 115 | $Object->drawText($X2, $RightY1 - $TextPadding, $Label, ["Align" => TEXT_ALIGN_BOTTOMRIGHT]); |
| 116 | } |
| 117 | $LeftY = $LeftY2; |
| 118 | $RightY = $RightY2; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 |