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