Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

pScatter::drawScatterLegend()   F

Complexity

Conditions 55
Paths > 20000

Size

Total Lines 150
Code Lines 95

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 150
rs 2
cc 55
eloc 95
nc 429496.7295
nop 3

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
 /*
3
     pScatter - class to draw scatter 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
16
 define("SCATTER_MISSING_X_SERIE"	, 190001);
17
 define("SCATTER_MISSING_Y_SERIE"	, 190002);
18
19
 /* pScatter class definition */
20
 class pScatter
21
  {
22
   var $pChartObject;
23
   var $pDataObject;
24
25
   /* Class creator */
26
   function pScatter($pChartObject,$pDataObject)
27
    {
28
     $this->pChartObject = $pChartObject;
29
     $this->pDataObject  = $pDataObject;
30
    }
31
32
   /* Prepare the scale */
33
   function drawScatterScale($Format="")
34
    {
35
     $Mode		= isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
36
     $Floating		= isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
37
     $XLabelsRotation	= isset($Format["XLabelsRotation"]) ? $Format["XLabelsRotation"] : 90;
38
     $MinDivHeight	= isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
39
     $Factors		= isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
40
     $ManualScale	= isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
41
     $XMargin		= isset($Format["XMargin"]) ? $Format["XMargin"] : 0;
42
     $YMargin		= isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
43
     $ScaleSpacing	= isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
44
     $InnerTickWidth	= isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
45
     $OuterTickWidth	= isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
46
     $DrawXLines	= isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : ALL;
47
     $DrawYLines	= isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
48
     $GridTicks		= isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
49
     $GridR		= isset($Format["GridR"]) ? $Format["GridR"] : 255;
50
     $GridG		= isset($Format["GridG"]) ? $Format["GridG"] : 255;
51
     $GridB		= isset($Format["GridB"]) ? $Format["GridB"] : 255;
52
     $GridAlpha		= isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
53
     $AxisRo		= isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
54
     $AxisGo		= isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
55
     $AxisBo		= isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
56
     $AxisAlpha		= isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
57
     $TickRo		= isset($Format["TickR"]) ? $Format["TickR"] : 0;
58
     $TickGo		= isset($Format["TickG"]) ? $Format["TickG"] : 0;
59
     $TickBo		= isset($Format["TickB"]) ? $Format["TickB"] : 0;
60
     $TickAlpha		= isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
61
     $DrawSubTicks	= isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
62
     $InnerSubTickWidth	= isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
63
     $OuterSubTickWidth	= isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
64
     $SubTickR		= isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
65
     $SubTickG		= isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
66
     $SubTickB		= isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
67
     $SubTickAlpha	= isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
68
     $XReleasePercent	= isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
69
     $DrawArrows	= isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
70
     $ArrowSize         = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
71
     $CycleBackground	= isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
72
     $BackgroundR1	= isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
73
     $BackgroundG1	= isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
74
     $BackgroundB1	= isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
75
     $BackgroundAlpha1	= isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 10;
76
     $BackgroundR2	= isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
77
     $BackgroundG2	= isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
78
     $BackgroundB2	= isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
79
     $BackgroundAlpha2	= isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 10;
80
81
     /* Check if we have at least both one X and Y axis */
82
     $GotXAxis = FALSE; $GotYAxis = FALSE;
83
     foreach($this->pDataObject->Data["Axis"] as $AxisID => $AxisSettings)
84
      {
85
       if ( $AxisSettings["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
86
       if ( $AxisSettings["Identity"] == AXIS_Y ) { $GotYAxis = TRUE; }
87
      }
88
     if ( !$GotXAxis ) { return(SCATTER_MISSING_X_SERIE); }
89
     if ( !$GotYAxis ) { return(SCATTER_MISSING_Y_SERIE); }
90
91
     /* Skip a NOTICE event in case of an empty array */
92
     if ( $DrawYLines == NONE ) { $DrawYLines = array("zarma"=>"31"); }
93
94
     $Data = $this->pDataObject->getData();
95
96
     foreach($Data["Axis"] as $AxisID => $AxisSettings)
97
      {
98
       if ( $AxisSettings["Identity"] == AXIS_X)
99
        { $Width = $this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1 - $XMargin*2; }
100
       else
101
        { $Width = $this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1 - $YMargin*2; }
102
103
       $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
104
       if ( $Mode == SCALE_MODE_FLOATING )
105
        {
106
         foreach($Data["Series"] as $SerieID => $SerieParameter)
107
          {
108
           if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] )
109
            {
110
             $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
111
             $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
112
            }
113
          }
114
         $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
115
116
         $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
117
        }
118
       elseif ( $Mode == SCALE_MODE_MANUAL )
119
        {
120
         if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
121
          {
122
           $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
123
           $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
124
          }
125
         else
126
          { echo "Manual scale boundaries not set."; exit(); }
127
        }
128
129
       /* Full manual scale */
130
       if ( isset($ManualScale[$AxisID]["Rows"]) && isset($ManualScale[$AxisID]["RowHeight"]) )
131
        $Scale = array("Rows"=>$ManualScale[$AxisID]["Rows"],"RowHeight"=>$ManualScale[$AxisID]["RowHeight"],"XMin"=>$ManualScale[$AxisID]["Min"],"XMax"=>$ManualScale[$AxisID]["Max"]);
132
       else
133
        {
134
         $MaxDivs = floor($Width/$MinDivHeight);
135
         $Scale   = $this->pChartObject->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
136
        }
137
138
       $Data["Axis"][$AxisID]["Margin"]    = $AxisSettings["Identity"] == AXIS_X ? $XMargin : $YMargin;
139
       $Data["Axis"][$AxisID]["ScaleMin"]  = $Scale["XMin"];
140
       $Data["Axis"][$AxisID]["ScaleMax"]  = $Scale["XMax"];
141
       $Data["Axis"][$AxisID]["Rows"]      = $Scale["Rows"];
142
       $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
143
144
       if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
145
146
       if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
147
       if ( !isset($Data["Axis"][$AxisID]["Format"]) )  { $Data["Axis"][$AxisID]["Format"] = NULL; }
148
       if ( !isset($Data["Axis"][$AxisID]["Unit"]) )    { $Data["Axis"][$AxisID]["Unit"] = NULL; }
149
      }
150
151
     /* Get the default font color */
152
     $FontColorRo = $this->pChartObject->FontColorR; $FontColorGo = $this->pChartObject->FontColorG; $FontColorBo = $this->pChartObject->FontColorB;
153
154
     /* Set the original boundaries */
155
     $AxisPos["L"] = $this->pChartObject->GraphAreaX1; $AxisPos["R"] = $this->pChartObject->GraphAreaX2; $AxisPos["T"] = $this->pChartObject->GraphAreaY1; $AxisPos["B"] = $this->pChartObject->GraphAreaY2;
156
157
     foreach($Data["Axis"] as $AxisID => $AxisSettings)
158
      {
159
       if ( isset($AxisSettings["Color"]) )
160
        {
161
         $AxisR = $AxisSettings["Color"]["R"]; $AxisG = $AxisSettings["Color"]["G"]; $AxisB = $AxisSettings["Color"]["B"];
162
         $TickR = $AxisSettings["Color"]["R"]; $TickG = $AxisSettings["Color"]["G"]; $TickB = $AxisSettings["Color"]["B"];
163
         $this->pChartObject->setFontProperties(array("R"=>$AxisSettings["Color"]["R"],"G"=>$AxisSettings["Color"]["G"],"B"=>$AxisSettings["Color"]["B"]));
164
        }
165
       else
166
        {
167
         $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
168
         $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
169
         $this->pChartObject->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
170
        }
171
172
       $LastValue = "w00t"; $ID = 1;
173
       if ( $AxisSettings["Identity"] == AXIS_X )
174
        {
175
         if ( $AxisSettings["Position"] == AXIS_POSITION_BOTTOM )
176
          {
177
           if ( $XLabelsRotation == 0 )				   { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 2; }
178
           if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 )   { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
179
           if ( $XLabelsRotation == 180 )			   { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 5; }
180
           if ( $XLabelsRotation > 180 && $XLabelsRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
181
182
           if ( $Floating )
183
            { $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
184
           else
185
            { $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["B"],$this->pChartObject->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
186
187
           if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
188
189
           $Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
190
           $Step   = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
191
           $LastX  = NULL;
192
           for($i=0;$i<=$AxisSettings["Rows"];$i++)
193
            {
194
             $XPos  = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
195
             $YPos  = $AxisPos["B"];
196
             $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
197
198
             if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
199
             if ( $LastX != NULL && $CycleBackground  && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
200
201
             if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
202
             if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
203
              $this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$InnerSubTickWidth,$XPos+$SubTicksSize,$YPos+$OuterSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
204
205
             $this->pChartObject->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
206
             $Bounds    = $this->pChartObject->drawText($XPos,$YPos+$OuterTickWidth+$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
207
             $TxtBottom = $YPos+2+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
208
             $MaxBottom = max($MaxBottom,$TxtBottom);
209
210
             $LastX = $XPos;
211
            }
212
213
           if ( isset($AxisSettings["Name"]) )
214
            {
215
             $YPos   = $MaxBottom+2;
216
             $XPos   = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
217
             $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
218
             $MaxBottom = $Bounds[0]["Y"];
219
220
             $this->pDataObject->Data["GraphArea"]["Y2"] = $MaxBottom + $this->pChartObject->FontSize;
221
            }
222
223
           $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
224
          }
225
         elseif ( $AxisSettings["Position"] == AXIS_POSITION_TOP )
226
          {
227
           if ( $XLabelsRotation == 0 )					{ $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 2; }
228
           if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 )	{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
229
           if ( $XLabelsRotation == 180 )				{ $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 5; }
230
           if ( $XLabelsRotation > 180 && $SLabelxRotation < 360 )	{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
231
232
           if ( $Floating )
233
            { $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
234
           else
235
            { $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["T"],$this->pChartObject->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
236
237
           if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
238
239
           $Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
240
           $Step   = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
241
           $LastX  = NULL;
242
           for($i=0;$i<=$AxisSettings["Rows"];$i++)
243
            {
244
             $XPos  = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
245
             $YPos  = $AxisPos["T"];
246
             $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
247
248
             if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
249
             if ( $LastX != NULL && $CycleBackground  && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
250
251
             if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
252
253
             if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
254
              $this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
255
256
             $this->pChartObject->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
257
             $Bounds = $this->pChartObject->drawText($XPos,$YPos-$OuterTickWidth-$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
258
             $TxtBox = $YPos-$OuterTickWidth-4-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
259
             $MinTop = min($MinTop,$TxtBox);
260
261
             $LastX = $XPos;
262
            }
263
264
           if ( isset($AxisSettings["Name"]) )
265
            {
266
             $YPos   = $MinTop-2;
267
             $XPos   = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
268
             $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
269
             $MinTop = $Bounds[2]["Y"];
270
271
             $this->pDataObject->Data["GraphArea"]["Y1"] = $MinTop;
272
            }
273
274
           $AxisPos["T"] = $MinTop - $ScaleSpacing;
275
          }
276
        }
277
       elseif ( $AxisSettings["Identity"] == AXIS_Y )
278
        {
279
         if ( $AxisSettings["Position"] == AXIS_POSITION_LEFT )
280
          {
281
282
           if ( $Floating )
283
            { $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
284
           else
285
            { $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1,$AxisPos["L"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
286
287
           if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
288
289
           $Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
290
           $Step   = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
291
           $LastY  = NULL;
292
           for($i=0;$i<=$AxisSettings["Rows"];$i++)
293
            {
294
             $YPos  = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
295
             $XPos  = $AxisPos["L"];
296
             $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
297
298
             if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
299
             if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
300
301
             if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
302
303
             if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
304
              $this->pChartObject->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
305
306
             $this->pChartObject->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
307
             $Bounds  = $this->pChartObject->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
308
             $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
309
             $MinLeft = min($MinLeft,$TxtLeft);
310
311
             $LastY = $YPos;
312
            }
313
314
           if ( isset($AxisSettings["Name"]) )
315
            {
316
             $XPos    = $MinLeft-2;
317
             $YPos    = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
318
             $Bounds  = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
319
             $MinLeft = $Bounds[2]["X"];
320
321
             $this->pDataObject->Data["GraphArea"]["X1"] = $MinLeft;
322
            }
323
324
           $AxisPos["L"] = $MinLeft - $ScaleSpacing;
325
          }
326
         elseif ( $AxisSettings["Position"] == AXIS_POSITION_RIGHT )
327
          {
328
329
           if ( $Floating )
330
            { $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
331
           else
332
            { $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1,$AxisPos["R"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
333
334
           if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
335
336
           $Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
337
           $Step   = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
338
           $LastY  = NULL;
339
           for($i=0;$i<=$AxisSettings["Rows"];$i++)
340
            {
341
             $YPos  = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
342
             $XPos  = $AxisPos["R"];
343
             $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
344
345
             if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
346
             if ( $LastY != NULL && $CycleBackground  && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
347
348
             if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines)) ) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
349
350
             if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
351
              $this->pChartObject->drawLine($XPos-$InnerSubTickWidth,$YPos-$SubTicksSize,$XPos+$OuterSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
352
353
             $this->pChartObject->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
354
             $Bounds  = $this->pChartObject->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
355
             $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
356
             $MaxLeft = max($MaxLeft,$TxtLeft);
357
358
             $LastY = $YPos;
359
            }
360
361
           if ( isset($AxisSettings["Name"]) )
362
            {
363
             $XPos    = $MaxLeft+6;
364
             $YPos    = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
365
             $Bounds  = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
366
             $MaxLeft = $Bounds[2]["X"];
367
368
             $this->pDataObject->Data["GraphArea"]["X2"] = $MaxLeft + $this->pChartObject->FontSize;
369
            }
370
371
           $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
372
          }
373
        }
374
      }
375
376
     $this->pDataObject->saveAxisConfig($Data["Axis"]);
377
    }
378
379
   /* Draw a scatter plot chart */
380
   function drawScatterPlotChart($Format=NULL)
381
    {
382
     $PlotSize		= isset($Format["PlotSize"]) ? $Format["PlotSize"] : 3;
383
     $PlotBorder	= isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
384
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : 250;
385
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : 250;
386
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : 250;
387
     $BorderAlpha	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
388
     $BorderSize	= isset($Format["BorderSize"]) ? $Format["BorderSize"] : 1;
389
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
390
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
391
     $ImageMapTitle	= isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
392
     $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
393
394
     $Data    = $this->pDataObject->getData();
395
     $Palette = $this->pDataObject->getPalette();
396
397
     $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
398
399
     foreach($Data["ScatterSeries"] as $Key => $Series)
400
      {
401
       if ( $Series["isDrawable"] == TRUE )
402
        {
403
         $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
404
         $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
405
406
         if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
407
         
408
         if ( isset($Series["Picture"]) && $Series["Picture"] != "" )
409
          { $Picture = $Series["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->pChartObject->getPicInfo($Picture); }
410
         else
411
          { $Picture = NULL; }
412
413
         $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
414
         if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
415
         $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
416
         if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
417
418
         $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
419
420
         foreach($PosArrayX as $Key => $Value)
0 ignored issues
show
Bug introduced by
The expression $PosArrayX of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
421
          {
422
           $X = $Value; $Y = $PosArrayY[$Key];
423
424
           if ( $X != VOID && $Y != VOID )
425
            {
426
             $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
427
             if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($PlotSize+$BorderSize),$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
428
429
             if( isset($Series["Shape"]) )
430
              { $this->pChartObject->drawShape($X,$Y,$Series["Shape"],$PlotSize,$PlotBorder,$BorderSize,$Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"],$Series["Color"]["Alpha"],$BorderR,$BorderG,$BorderB,$BorderAlpha); }
431
             elseif ( $Picture == NULL )
432
              {
433
               if ( $PlotBorder ) { $this->pChartObject->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,$BorderColor); }
434
               $this->pChartObject->drawFilledCircle($X,$Y,$PlotSize,$Color);
435
              }
436
             else
437
              { $this->pChartObject->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
438
            }
439
          }
440
        }
441
      }
442
    }
443
444
   /* Draw a scatter line chart */
445
   function drawScatterLineChart($Format=NULL)
446
    {
447
     $Data		= $this->pDataObject->getData();
448
     $Palette		= $this->pDataObject->getPalette();
449
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
450
     $ImageMapTitle	= isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
451
     $ImageMapPlotSize	= isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 10;
452
     $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
453
454
     /* Parse all the series to draw */
455
     foreach($Data["ScatterSeries"] as $Key => $Series)
456
      {
457
       if ( $Series["isDrawable"] == TRUE )
458
        {
459
         $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
460
         $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
461
         $Ticks  = $Series["Ticks"];
462
         $Weight = $Series["Weight"];
463
464
         if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
465
466
         $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
467
         if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
468
         $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
469
         if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
470
471
         $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
472
         if ( $Ticks != 0 )  { $Color["Ticks"]  = $Ticks; }
473
         if ( $Weight != 0 ) { $Color["Weight"] = $Weight; }
474
475
         $LastX = VOID; $LastY = VOID;
476
         foreach($PosArrayX as $Key => $Value)
0 ignored issues
show
Bug introduced by
The expression $PosArrayX of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
477
          {
478
           $X = $Value; $Y = $PosArrayY[$Key];
479
480
           if ( $X != VOID && $Y != VOID )
481
            {
482
             $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
483
             if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
484
            }
485
486
           if ( $X != VOID && $Y != VOID && $LastX != VOID && $LastY != VOID)
487
            $this->pChartObject->drawLine($LastX,$LastY,$X,$Y,$Color);
488
489
           $LastX = $X; $LastY = $Y;
490
          }
491
        }
492
      }
493
    }
494
495
   /* Draw a scatter spline chart */
496
   function drawScatterSplineChart($Format=NULL)
497
    {
498
     $Data		= $this->pDataObject->getData();
499
     $Palette		= $this->pDataObject->getPalette();
500
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
501
     $ImageMapTitle	= isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
502
     $ImageMapPlotSize	= isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 10;
503
     $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
504
505
     foreach($Data["ScatterSeries"] as $Key => $Series)
506
      {
507
       if ( $Series["isDrawable"] == TRUE )
508
        {
509
         $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
510
         $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
511
         $Ticks  = $Series["Ticks"];
512
         $Weight = $Series["Weight"];
513
514
         if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
515
516
         $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
517
         if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
518
         $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
519
         if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
520
521
         $SplineSettings = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
522
         if ( $Ticks != 0 )  { $SplineSettings["Ticks"]  = $Ticks; }
523
         if ( $Weight != 0 ) { $SplineSettings["Weight"] = $Weight; }
524
525
         $LastX = VOID; $LastY = VOID; $WayPoints = ""; $Forces = "";
526
         foreach($PosArrayX as $Key => $Value)
0 ignored issues
show
Bug introduced by
The expression $PosArrayX of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
527
          {
528
           $X = $Value; $Y = $PosArrayY[$Key];
529
           $Force = $this->pChartObject->getLength($LastX,$LastY,$X,$Y)/5;
530
531
           if ( $X != VOID && $Y != VOID )
532
            {
533
             $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
534
             if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
535
            }
536
537
           if ( $X != VOID && $Y != VOID )
538
            { $WayPoints[] = array($X,$Y); $Forces[] = $Force; }
539
540
           if ( $Y == VOID || $X == VOID )
541
            { $SplineSettings["Forces"] = $Forces; $this->pChartObject->drawSpline($WayPoints,$SplineSettings); $WayPoints = ""; $Forces = "";}
542
543
           $LastX = $X; $LastY = $Y;
544
          }
545
         $SplineSettings["Forces"] = $Forces; 
546
         $this->pChartObject->drawSpline($WayPoints,$SplineSettings);
547
        }
548
      }
549
    }
550
551
   /* Return the scaled plot position */
552
   function getPosArray($Values,$AxisID)
553
    {
554
     $Data = $this->pDataObject->getData();
555
556
     if ( !is_array($Values) ) { $Values = array($Values); }
557
558
     if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
559
      {
560
       $Height      = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
561
       $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
562
       $Step        = $Height / $ScaleHeight;
563
564
       $Result = "";
565
       foreach($Values as $Key => $Value)
566
        {
567
         if ( $Value == VOID ) 
568
          $Result[] = VOID;
569
         else
570
          $Result[] = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
571
        }
572
573
       if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
574
      }
575
     else
576
      {
577
       $Height      = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
578
       $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
579
       $Step        = $Height / $ScaleHeight;
580
581
       $Result = "";
582
       foreach($Values as $Key => $Value)
583
        {
584
         if ( $Value == VOID ) 
585
          $Result[] = VOID;
586
         else
587
          $Result[] = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
588
        }
589
590
       if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
591
      }
592
    }
593
594
   /* Draw the legend of the active series */
595
   function drawScatterLegend($X,$Y,$Format="")
596
    {
597
     $Family		= isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
598
     $FontName		= isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
599
     $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
600
     $FontR		= isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
601
     $FontG		= isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
602
     $FontB		= isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
603
     $BoxWidth		= isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
604
     $BoxHeight		= isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
605
     $IconAreaWidth	= isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
606
     $IconAreaHeight	= isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
607
     $XSpacing		= isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
608
     $Margin		= isset($Format["Margin"]) ? $Format["Margin"] : 5;
609
     $R			= isset($Format["R"]) ? $Format["R"] : 200;
610
     $G			= isset($Format["G"]) ? $Format["G"] : 200;
611
     $B			= isset($Format["B"]) ? $Format["B"] : 200;
612
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
613
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
614
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
615
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
616
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
617
     $Style		= isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
618
     $Mode		= isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
619
620
     if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $Surrounding of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
621
622
     $Data = $this->pDataObject->getData();
623
624
     foreach($Data["ScatterSeries"] as $Key => $Series)
625
      {
626
       if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
627
        {
628
         list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
629
         if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
630
         if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
631
        }
632
      }
633
634
     $YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
635
     $XStep = $IconAreaWidth + 5;
636
     $XStep = $XSpacing;
637
638
     $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
639
     foreach($Data["ScatterSeries"] as $Key => $Series)
640
      {
641
       if ( $Series["isDrawable"] == TRUE )
642
        {
643
         if ( $Mode == LEGEND_VERTICAL )
644
          {
645
           $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
646
647
           if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
648
           if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
649
           if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
650
651
           $Lines = preg_split("/\n/",$Series["Description"]);
652
           $vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
653
          }
654
         elseif ( $Mode == LEGEND_HORIZONTAL )
655
          {
656
           $Lines = preg_split("/\n/",$Series["Description"]);
657
           $Width = "";
658
           foreach($Lines as $Key => $Value)
659
            {
660
             $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
661
662
             if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
663
             if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
664
             if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
665
666
             $Width[] = $BoxArray[1]["X"];
667
            }
668
669
           $vX=max($Width)+$XStep;
670
          }
671
        }
672
      }
673
     $vY=$vY-$YStep; $vX=$vX-$XStep;
674
675
     $TopOffset  = $Y - $Boundaries["T"];
676
     if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
677
678
     if ( $Style == LEGEND_ROUND )
679
      $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
680
     elseif ( $Style == LEGEND_BOX )
681
      $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
682
683
     $RestoreShadow = $this->pChartObject->Shadow; $this->Shadow = FALSE;
684
     foreach($Data["ScatterSeries"] as $Key => $Series)
685
      {
686
       if ( $Series["isDrawable"] == TRUE )
687
        {
688
         $R = $Series["Color"]["R"]; $G = $Series["Color"]["G"]; $B = $Series["Color"]["B"];
689
         $Ticks = $Series["Ticks"]; $Weight = $Series["Weight"];
690
691
         if ( isset($Series["Picture"]) )
692
          {
693
           $Picture = $Series["Picture"];
694
           list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Picture);
695
           $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2; 
696
697
           $this->pChartObject->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
698
          }
699
         else
700
          {
701
           if ( $Family == LEGEND_FAMILY_BOX )
702
            {
703
             if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
704
             if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
705
706
             $this->pChartObject->drawFilledRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
707
             $this->pChartObject->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
708
            }
709
           elseif ( $Family == LEGEND_FAMILY_CIRCLE )
710
            {
711
             $this->pChartObject->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
712
             $this->pChartObject->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
713
            }
714
           elseif ( $Family == LEGEND_FAMILY_LINE )
715
            {
716
             $this->pChartObject->drawLine($X+1,$Y+1+$IconAreaHeight/2,$X+1+$IconAreaWidth,$Y+1+$IconAreaHeight/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20,"Ticks"=>$Ticks,"Weight"=>$Weight));
717
             $this->pChartObject->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
718
            }
719
          }
720
721
         if ( $Mode == LEGEND_VERTICAL )
722
          {
723
           $Lines = preg_split("/\n/",$Series["Description"]);
724
           foreach($Lines as $Key => $Value)
725
            $this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
726
727
           $Y=$Y+max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
728
          }
729
         elseif ( $Mode == LEGEND_HORIZONTAL )
730
          {
731
           $Lines = preg_split("/\n/",$Series["Description"]);
732
           $Width = "";
733
           foreach($Lines as $Key => $Value)
734
            {
735
             $BoxArray = $this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
736
             $Width[] = $BoxArray[1]["X"];
737
            }
738
           $X=max($Width)+2+$XStep;
739
          }
740
        }
741
      }
742
743
     $this->Shadow = $RestoreShadow;
744
    }
745
746
   /* Get the legend box size */
747
   function getScatterLegendSize($Format="")
748
    {
749
     $FontName	= isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
750
     $FontSize	= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
751
     $BoxSize	= isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
752
     $Margin	= isset($Format["Margin"]) ? $Format["Margin"] : 5;
753
     $Style	= isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
754
     $Mode	= isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
755
756
     $YStep = max($this->pChartObject->FontSize,$BoxSize) + 5;
757
     $XStep = $BoxSize + 5;
758
759
     $X=100; $Y=100;
760
761
     $Data = $this->pDataObject->getData();
762
763
     foreach($Data["ScatterSeries"] as $Key => $Series)
764
      {
765
       if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
766
        {
767
         list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
768
         if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
769
         if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
770
        }
771
      }
772
773
     $YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
774
     $XStep = $IconAreaWidth + 5;
775
     $XStep = $XSpacing;
776
777
     $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
778
     foreach($Data["ScatterSeries"] as $Key => $Series)
779
      {
780
       if ( $Series["isDrawable"] == TRUE )
781
        {
782
         if ( $Mode == LEGEND_VERTICAL )
783
          {
784
           $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
785
786
           if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
787
           if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
788
           if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
789
790
           $Lines = preg_split("/\n/",$Series["Description"]);
791
           $vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
792
          }
793
         elseif ( $Mode == LEGEND_HORIZONTAL )
794
          {
795
           $Lines = preg_split("/\n/",$Series["Description"]);
796
           $Width = "";
797
           foreach($Lines as $Key => $Value)
798
            {
799
             $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
800
801
             if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
802
             if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
803
             if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
804
805
             $Width[] = $BoxArray[1]["X"];
806
            }
807
808
           $vX=max($Width)+$XStep;
809
          }
810
        }
811
      }
812
     $vY=$vY-$YStep; $vX=$vX-$XStep;
813
814
     $TopOffset  = $Y - $Boundaries["T"];
815
     if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; }
816
817
     $Width  = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
818
     $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
819
820
     return(array("Width"=>$Width,"Height"=>$Height));
821
    }
822
823
   /* Draw the line of best fit */
824
   function drawScatterBestFit($Format="")
825
    {
826
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : 0;
827
828
     $Data    = $this->pDataObject->getData();
829
830
     foreach($Data["ScatterSeries"] as $Key => $Series)
831
      {
832
       if ( $Series["isDrawable"] == TRUE )
833
        {
834
         $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
835
         $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
836
837
         $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
838
         $Color["Ticks"] = $Ticks;
839
840
         $PosArrayX = $Data["Series"][$Series["X"]]["Data"];
841
         $PosArrayY = $Data["Series"][$Series["Y"]]["Data"];
842
843
         $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
844
         foreach($PosArrayX as $Key => $Value)
845
          {
846
           $X = $Value; $Y = $PosArrayY[$Key];
847
848
           $Sxy = $Sxy + $X*$Y;
849
           $Sx  = $Sx + $X;
850
           $Sy  = $Sy + $Y;
851
           $Sxx = $Sxx + $X*$X;
852
          }
853
854
         $n = count($PosArrayX);
855
856
         if ((($n*$Sxx) == ($Sx*$Sx)))
857
          {
858
           $X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
859
           $X2 = $X1;
860
           $Y1 = $this->pChartObject->GraphAreaY1;
861
           $Y2 = $this->pChartObject->GraphAreaY2;
862
          }
863
         else
864
          {
865
           $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
866
           $B = (($Sy)-($M*$Sx))/($n);
867
868
           $X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
869
           $Y1 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMin"] + $B,$SerieYAxis);
870
           $X2 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMax"],$SerieXAxis);
871
           $Y2 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMax"] + $B,$SerieYAxis);
872
873
           $RealM = -($Y2-$Y1)/($X2-$X1);
874
875
           if ( $Y1 < $this->pChartObject->GraphAreaY1 ) { $X1 = $X1 + ($this->pChartObject->GraphAreaY1-$Y1/$RealM); $Y1 = $this->pChartObject->GraphAreaY1; }
876
           if ( $Y1 > $this->pChartObject->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->pChartObject->GraphAreaY2)/$RealM; $Y1 = $this->pChartObject->GraphAreaY2; }
877
           if ( $Y2 < $this->pChartObject->GraphAreaY1 ) { $X2 = $X2 - ($this->pChartObject->GraphAreaY1-$Y2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY1; }
878
           if ( $Y2 > $this->pChartObject->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->pChartObject->GraphAreaY2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY2; }
879
          }
880
881
         $this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Color);
882
        }
883
      }
884
    }
885
886
   function writeScatterLabel($ScatterSerieID,$Points,$Format="")
887
    {
888
     $OverrideTitle	= isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
889
     $DrawPoint		= isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
890
     $Decimals		= isset($Format["Decimals"]) ? $Format["Decimals"] : NULL;
891
892
     $Data    = $this->pDataObject->getData();
893
     $Palette = $this->pDataObject->getPalette();
894
895
     if ( !is_array($Points) ) { $Point = $Points; $Points = ""; $Points[0] = $Point; }
896
897
     if ( !isset($Data["ScatterSeries"][$ScatterSerieID]) ) 
898
      return(0);
899
900
     $Series = $Data["ScatterSeries"][$ScatterSerieID];
901
     $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
902
     $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
903
904
     $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
905
     if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
906
     $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
907
     if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
908
909
     foreach($Points as $Key => $Point)
0 ignored issues
show
Bug introduced by
The expression $Points of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
910
      {
911
       if ( isset($PosArrayX[$Point]) && isset($PosArrayY[$Point]) )
912
        {
913
         $X = floor($PosArrayX[$Point]);
914
         $Y = floor($PosArrayY[$Point]);
915
916
         if ( $DrawPoint == LABEL_POINT_CIRCLE )
917
          $this->pChartObject->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
918
         elseif ( $DrawPoint == LABEL_POINT_BOX )
919
          $this->pChartObject->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
920
921
         $Serie = "";
922
         $Serie["R"] = $Series["Color"]["R"];
923
         $Serie["G"] = $Series["Color"]["G"];
924
         $Serie["B"] = $Series["Color"]["B"];
925
         $Serie["Alpha"] = $Series["Color"]["Alpha"];
926
927
         $XAxisMode   = $Data["Axis"][$SerieXAxis]["Display"];
928
         $XAxisFormat = $Data["Axis"][$SerieXAxis]["Format"];
929
         $XAxisUnit   = $Data["Axis"][$SerieXAxis]["Unit"];
930
         if ( $Decimals == NULL ) { $XValue = $SerieValuesX[$Point]; } else { $XValue = round($SerieValuesX[$Point],$Decimals); }
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $Decimals of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
931
         $XValue      = $this->pChartObject->scaleFormat($XValue,$XAxisMode,$XAxisFormat,$XAxisUnit);
932
933
         $YAxisMode   = $Data["Axis"][$SerieYAxis]["Display"];
934
         $YAxisFormat = $Data["Axis"][$SerieYAxis]["Format"];
935
         $YAxisUnit   = $Data["Axis"][$SerieYAxis]["Unit"];
936
         if ( $Decimals == NULL ) { $YValue = $SerieValuesY[$Point]; } else { $YValue = round($SerieValuesY[$Point],$Decimals); }
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $Decimals of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
937
         $YValue      = $this->pChartObject->scaleFormat($YValue,$YAxisMode,$YAxisFormat,$YAxisUnit);
938
939
         $Caption = $XValue." / ".$YValue;
940
941
         if ( isset($Series["Description"]) )
942
          $Description = $Series["Description"];
943
         else
944
          $Description = "No description";
945
946
         $Series = "";
947
         $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
948
949
         $this->pChartObject->drawLabelBox($X,$Y-3,$Description,$Series,$Format);
950
        }
951
      }
952
    }
953
954
   /* Draw a Scatter threshold */
955
   function drawScatterThreshold($Value,$Format="")
956
    {
957
     $AxisID		= isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
958
     $R			= isset($Format["R"]) ? $Format["R"] : 255;
959
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
960
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
961
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
962
     $Weight		= isset($Format["Weight"]) ? $Format["Weight"] : NULL;
963
     $Ticks		= isset($Format["Ticks"]) ? $Format["Ticks"] : 3;
964
     $Wide		= isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
965
     $WideFactor	= isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
966
     $WriteCaption	= isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
967
     $Caption		= isset($Format["Caption"]) ? $Format["Caption"] : NULL;
968
     $CaptionAlign	= isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
969
     $CaptionOffset     = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
970
     $CaptionR		= isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
971
     $CaptionG		= isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
972
     $CaptionB		= isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
973
     $CaptionAlpha	= isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
974
     $DrawBox		= isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
975
     $DrawBoxBorder	= isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
976
     $BorderOffset	= isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
977
     $BoxRounded	= isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
978
     $RoundedRadius	= isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
979
     $BoxR		= isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
980
     $BoxG		= isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
981
     $BoxB		= isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
982
     $BoxAlpha		= isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
983
     $BoxSurrounding	= isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
984
     $BoxBorderR	= isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
985
     $BoxBorderG	= isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
986
     $BoxBorderB	= isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
987
     $BoxBorderAlpha	= isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
988
989
     $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
990
                              "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
991
                              "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
992
                              "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
993
994
     if ( $Caption == NULL ) { $Caption = $Value; }
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $Caption of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
995
996
     $Data = $this->pDataObject->getData();
997
998
     if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
999
 
1000
     if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_Y )
1001
      {
1002
       $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
1003
       $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
1004
       $Y  = $this->getPosArray($Value,$AxisID);
1005
1006
       $this->pChartObject->drawLine($X1,$Y,$X2,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
1007
1008
       if ( $Wide )
1009
        {
1010
         $this->pChartObject->drawLine($X1,$Y-1,$X2,$Y-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
1011
         $this->pChartObject->drawLine($X1,$Y+1,$X2,$Y+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
1012
        }
1013
1014
       if ( $WriteCaption )
1015
        {
1016
         if ( $CaptionAlign == CAPTION_LEFT_TOP )
1017
          { $X = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
1018
         else 
1019
          { $X = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
1020
1021
         $this->pChartObject->drawText($X,$Y,$Caption,$CaptionSettings);
1022
        }
1023
1024
       return(array("Y"=>$Y));
1025
      }
1026
     elseif ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
1027
      {
1028
       $X  = $this->getPosArray($Value,$AxisID);
1029
       $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
1030
       $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
1031
1032
       $this->pChartObject->drawLine($X,$Y1,$X,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
1033
1034
       if ( $Wide )
1035
        {
1036
         $this->pChartObject->drawLine($X-1,$Y1,$X-1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
1037
         $this->pChartObject->drawLine($X+1,$Y1,$X+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
1038
        }
1039
1040
       if ( $WriteCaption )
1041
        {
1042
         if ( $CaptionAlign == CAPTION_LEFT_TOP )
1043
          { $Y = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
1044
         else 
1045
          { $Y = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
1046
1047
         $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
1048
         $this->pChartObject->drawText($X,$Y,$Caption,$CaptionSettings);
1049
        }
1050
1051
       return(array("X"=>$X));
1052
      }
1053
    }
1054
1055
   /* Draw a Scatter threshold area */
1056
   function drawScatterThresholdArea($Value1,$Value2,$Format="")
1057
    {
1058
     $AxisID	= isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
1059
     $R		= isset($Format["R"]) ? $Format["R"] : 255;
1060
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
1061
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
1062
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
1063
     $Border    = isset($Format["Border"]) ? $Format["Border"] : TRUE;
1064
     $BorderR   = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
1065
     $BorderG   = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
1066
     $BorderB   = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
1067
     $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
1068
     $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
1069
     $AreaName 	= isset($Format["AreaName"]) ? $Format["AreaName"] : "La ouate de phoque"; //NULL;
1070
     $NameAngle	= isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
1071
     $NameR	= isset($Format["NameR"]) ? $Format["NameR"] : 255;
1072
     $NameG	= isset($Format["NameG"]) ? $Format["NameG"] : 255;
1073
     $NameB	= isset($Format["NameB"]) ? $Format["NameB"] : 255;
1074
     $NameAlpha	= isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
1075
     $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
1076
1077
     if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); }
1078
1079
     $RestoreShadow = $this->pChartObject->Shadow;
1080
     if ( $DisableShadowOnArea && $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; }
1081
1082
     if ($BorderAlpha >100) { $BorderAlpha = 100;}
1083
1084
     $Data = $this->pDataObject->getData();
1085
1086
     if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
1087
 
1088
     if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
1089
      {
1090
       $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
1091
       $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
1092
       $X1  = $this->getPosArray($Value1,$AxisID);
1093
       $X2  = $this->getPosArray($Value2,$AxisID);
1094
1095
       if ( $X1 <= $this->pChartObject->GraphAreaX1 ) { $X1 = $this->pChartObject->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
1096
       if ( $X2 >= $this->pChartObject->GraphAreaX2 ) { $X2 = $this->pChartObject->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
1097
1098
       $this->pChartObject->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
1099
1100
       if ( $Border )
1101
        {
1102
         $this->pChartObject->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
1103
         $this->pChartObject->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
1104
        }
1105
1106
       if ( $AreaName != NULL )
1107
        {
1108
         $XPos = ($X2-$X1)/2 + $X1;
1109
         $YPos = ($Y2-$Y1)/2 + $Y1;
1110
1111
         if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
1112
          {
1113
           $TxtPos   = $this->pChartObject->getTextBox($XPos,$YPos,$this->pChartObject->FontName,$this->pChartObject->FontSize,0,$AreaName);
1114
           $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
1115
           if ( abs($X2 - $X1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
1116
          }
1117
         $this->pChartObject->Shadow = $RestoreShadow;
1118
         $this->pChartObject->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
1119
         if ( $DisableShadowOnArea ) { $this->pChartObject->Shadow = FALSE; }
1120
        }
1121
1122
       $this->pChartObject->Shadow = $RestoreShadow;
1123
       return(array("X1"=>$X1,"X2"=>$X2));
1124
      }
1125
     elseif ( $Data["Axis"][$AxisID]["Identity"] == AXIS_Y )
1126
      {
1127
       $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
1128
       $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
1129
       $Y1 = $this->getPosArray($Value1,$AxisID);
1130
       $Y2 = $this->getPosArray($Value2,$AxisID);
1131
1132
       if ( $Y1 >= $this->pChartObject->GraphAreaY2 ) { $Y1 = $this->pChartObject->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
1133
       if ( $Y2 <= $this->pChartObject->GraphAreaY1 ) { $Y2 = $this->pChartObject->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
1134
1135
       $this->pChartObject->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
1136
1137
       if ( $Border )
1138
        {
1139
         $this->pChartObject->drawLine($X1,$Y1,$X2,$Y1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
1140
         $this->pChartObject->drawLine($X1,$Y2,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
1141
        }
1142
1143
       if ( $AreaName != NULL )
1144
        {
1145
         $XPos = ($X2-$X1)/2 + $X1;
1146
         $YPos = ($Y2-$Y1)/2 + $Y1;
1147
1148
         $this->pChartObject->Shadow = $RestoreShadow;
1149
         $this->pChartObject->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
1150
         if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
1151
        }
1152
1153
       $this->pChartObject->Shadow = $RestoreShadow;
1154
       return(array("Y1"=>$Y1,"Y2"=>$Y2));
1155
      }
1156
    }
1157
  }
1158
?>