Completed
Push — 23 ( 340196...de9e92 )
by Harald
08:30 queued 03:42
created

PHPlot::SetTickLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2003 osCommerce
9
10
  Released under the GNU General Public License
11
12
  PHPLOT 4.4.6 Copyright (c) 1998-2001 Afan Ottenheimer
13
*/
14
15
class PHPlot{
16
17
	var $is_inline = 0;			//0 = Sends headers, 1 = sends just raw image data
18
	var $browser_cache = '1';	// 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)
19
									// (only if is_inline = 0 also)
20
	var $session_set = '';		//Do not change
21
	var $scale_is_set = '';		//Do not change
22
	var $draw_plot_area_background = '';
23
24
	var $image_width;	//Total Width in Pixels
25
	var $image_height; 	//Total Height in Pixels
26
	var $image_border_type = ''; //raised, plain, ''
27
	var $x_left_margin;
28
	var $y_top_margin;
29
	var $x_right_margin;
30
	var $y_bot_margin;
31
	var $plot_area = array(5,5,600,400);
32
	var $x_axis_position = 0;	//Where to draw the X_axis (world coordinates)
33
	var $y_axis_position = '';  //Leave blank for Y axis at left of plot. (world coord.)
34
	var $xscale_type = 'linear';  //linear or log
35
	var $yscale_type = 'linear';
36
37
//Use for multiple plots per image
38
	var $print_image = 1;  //Used for multiple charts per image.
39
40
//Fonts
41
	var $use_ttf  = 0;		  //Use TTF fonts (1) or not (0)
42
	var $font_path = './';  //To be added
43
	var $font = './benjamingothic.ttf';
44
45
	///////////Fonts: Small/Generic
46
	var $small_ttffont_size = 12; //
47
	//non-ttf
48
	var $small_font = 2; // fonts = 1,2,3,4 or 5
49
	var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8)
50
	var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12)
51
52
	//////////   Fonts:Title
53
	var $title_ttffont = './benjamingothic.ttf';
54
	var $title_ttffont_size = 14;
55
	var $title_angle= 0;
56
	//non-ttf
57
	var $title_font = '4'; // fonts = 1,2,3,4,5
58
59
	//////////////  Fonts:Axis
60
	var $axis_ttffont = './benjamingothic.ttf';
61
	var $axis_ttffont_size = 8;
62
	var $x_datalabel_angle = 0;
63
	//non-ttf
64
	var $axis_font = 2;
65
66
	////////////////Fonts:Labels of Data
67
	var $datalabel_font = '2';
68
69
	//////////////// Fonts:Labels (Axis Titles)
70
	var $x_label_ttffont = './benjamingothic.ttf';
71
	var $x_label_ttffont_size = '12';
72
	var $x_label_angle = '0';
73
74
	var $y_label_ttffont = './benjamingothic.ttf';
75
	var $y_label_ttffont_size = '12';
76
	var $y_label_angle = 90;
77
	var $y_label_width = '';
78
79
//Formats
80
	var $file_format = 'png';
81
	var $file_name = '';  //For output to a file instead of stdout
82
83
//Plot Colors
84
	var $shading = 0;
85
	var $color_array = 1;	//1 = include small list
86
							//2 = include large list
87
							//array =  define your own color translation. See rgb.inc.php and SetRGBArray
88
	var $bg_color;
89
	var $plot_bg_color;
90
	var $grid_color;
91
	var $light_grid_color;
92
	var $tick_color;
93
	var $title_color;
94
	var $label_color;
95
	var $text_color;
96
	var $i_light = '';
97
98
//Data
99
	var $data_type = 'text-data'; //text-data, data-data-error, data-data
100
	var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline
101
	var $line_width = 2;
102
	var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines
103
104
	var $data_color = ''; //array('blue','green','yellow',array(0,0,0));
105
	var $data_border_color = '';
106
107
	var $label_scale_position = '.5';  //1 = top, 0 = bottom
108
	var $group_frac_width = '.7'; //value from 0 to 1 = width of bar
109
	var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0
110
111
	var $point_size = 10;
112
	var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline
113
	var $error_bar_shape = 'tee'; //tee, line
114
	var $error_bar_size = 5; //right left size of tee
115
	var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness
116
	var $error_bar_color = '';
117
	var $data_values;
118
119
	var $plot_border_type = 'full'; //left, none, full
120
	var $plot_area_width = '';
121
	var $number_x_points;
122
	var $plot_min_x; // Max and min of the plot area
123
	var $plot_max_x= ''; // Max and min of the plot area
124
	var $plot_min_y= ''; // Max and min of the plot area
125
	var $plot_max_y = ''; // Max and min of the plot area
126
	var $min_y = '';
127
	var $max_y = '';
128
	var $max_x = 10;  //Must not be = 0;
129
	var $y_precision = '1';
130
	var $x_precision = '1';
131
	var $si_units = '';
132
133
//Labels
134
	var $draw_data_labels = '0';
135
	var $legend = '';  //an array
136
	var $legend_x_pos = '';
137
	var $legend_y_pos = '';
138
	var $title_txt = "";
139
	var $y_label_txt = '';
140
	var $x_label_txt = "";
141
142
//DataAxis Labels (on each axis)
143
	var $y_grid_label_type = 'data';    //data, none, time, other
144
	var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both
145
	var $x_grid_label_type = 'data';    //data, title, none, time, other
146
	var $draw_x_data_labels = '';       // 0=false, 1=true, ""=let program decide
147
	var $x_time_format = "%H:%m:%s";    //See http://www.php.net/manual/html/function.strftime.html
148
	var $x_datalabel_maxlength = 10;
149
150
//Tick Formatting
151
	var $tick_length = '10';   //pixels: tick length from axis left/downward
152
	//tick_length2 to be implemented
153
	//var $tick_length2 = '';  //pixels: tick length from axis line rightward/upward
154
	var $draw_vert_ticks = 1;  //1 = draw ticks, 0 = don't draw ticks
155
	var $num_vert_ticks = '';
156
	var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both.
157
	var $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only),
158
								//both = (both left and right of plot), yaxis=(crosses y axis)
159
	var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both.
160
	var $num_horiz_ticks='';
161
	var $skip_top_tick = '0';
162
	var $skip_bottom_tick = '0';
163
164
//Grid Formatting
165
	var $draw_x_grid = 0;
166
	var $draw_y_grid = 1;
167
168
169
//BEGIN CODE
170
//////////////////////////////////////////////////////
171
	//Constructor: Setup Img pointer, Colors and Size of Image
172
	function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
173
174
		$this->SetRGBArray('2');
175
		$this->background_done = 0; //Set to 1 after background image first drawn
0 ignored issues
show
Bug introduced by
The property background_done does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
176
177
		if ($which_output_file != "") { $this->SetOutputFile($which_output_file);  };
178
179
		if ($which_input_file != "") {
180
			$this->SetInputFile($which_input_file) ;
181
		} else {
182
			$this->SetImageArea($which_width, $which_height);
183
			$this->InitImage();
184
		}
185
186
		if ( ($this->session_set == 1) && ($this->img == "") ) {  //For sessions
0 ignored issues
show
Bug introduced by
The property img does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
187
			//Do nothing
188
		} else {
189
			$this->SetDefaultColors();
190
		}
191
192
		$this->SetIndexColors();
193
194
	}
195
196
	//Set up the image and colors
197
	function InitImage() {
198
		//if ($this->img) {
199
		//	ImageDestroy($this->img);
200
		//}
201
		$this->img = ImageCreate($this->image_width, $this->image_height);
202
		return true;
203
	}
204
205
	function SetBrowserCache($which_browser_cache) {  //Submitted by Thiemo Nagel
206
		$this->browser_cache = $which_browser_cache;
207
		return true;
208
	}
209
210
	function SetPrintImage($which_pi) {
211
		$this->print_image = $which_pi;
212
		return true;
213
	}
214
215
	function SetIsInline($which_ii) {
216
		$this->is_inline = $which_ii;
217
		return true;
218
	}
219
220
	function SetUseTTF($which_ttf) {
221
		$this->use_ttf = $which_ttf;
222
		return true;
223
	}
224
225
	function SetTitleFontSize($which_tfs) {
226
		//TTF
227
		$this->title_ttffont_size = $which_tfs; //pt size
228
229
		//Non-TTF settings
230
		if (($which_tfs > 5) && (!$this->use_ttf)) {
231
			$this->DrawError('Non-TTF font size must be 1,2,3,4 or 5');
232
			return false;
233
		} else {
234
			$this->title_font = $which_tfs;
235
			//$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels
236
			//$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels
237
		}
238
		return true;
239
	}
240
241
	function SetLineStyles($which_sls){
242
		$this->line_style = $which_sls;
243
		return true;
244
	}
245
246
	function SetLegend($which_leg){
247
		if (is_array($which_leg)) {
248
			$this->legend = $which_leg;
0 ignored issues
show
Documentation Bug introduced by
It seems like $which_leg of type array is incompatible with the declared type string of property $legend.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
249
			return true;
250
		} else {
251
			$this->DrawError('Error: SetLegend argument must be an array');
252
			return false;
253
		}
254
	}
255
256
	function SetLegendPixels($which_x,$which_y,$which_type) {
0 ignored issues
show
Unused Code introduced by
The parameter $which_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
257
		//which_type not yet used
258
		$this->legend_x_pos = $which_x;
259
		$this->legend_y_pos = $which_y;
260
		return true;
261
	}
262
263
	function SetLegendWorld($which_x,$which_y,$which_type='') {
0 ignored issues
show
Unused Code introduced by
The parameter $which_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
264
		//which_type not yet used
265
		//Must be called after scales are set up.
266
		if ($this->scale_is_set != 1) { $this->SetTranslation(); };
267
		$this->legend_x_pos = $this->xtr($which_x);
0 ignored issues
show
Documentation Bug introduced by
The property $legend_x_pos was declared of type string, but $this->xtr($which_x) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
268
		$this->legend_y_pos = $this->ytr($which_y);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->ytr($which_y) of type integer or double is incompatible with the declared type string of property $legend_y_pos.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
269
		return true;
270
	}
271
/* ***************************************
272
	function SetFileFormat($which_file_format) { //Only works with PHP4
273
		$asked = strtolower($which_file_format);
274
		if( $asked =="jpg" || $asked =="png" || $asked =="gif" || $asked =="wbmp" ) {
275
			if( $asked=="jpg" && !(imagetypes() & IMG_JPG) )
276
				return false;
277
			elseif( $asked=="png" && !(imagetypes() & IMG_PNG) )
278
				return false;
279
			elseif( $asked=="gif" && !(imagetypes() & IMG_GIF) )
280
				return false;
281
			elseif( $asked=="wbmp" && !(imagetypes() & IMG_WBMP) )
282
				return false;
283
			else {
284
				$this->img_format=$asked;
285
				return true;
286
			}
287
		}
288
		else
289
			return false;
290
	}
291
292
*************************************** */
293
	function SetFileFormat($which_file_format) {
294
	//eventually test to see if that is supported - if not then return false
295
		$asked = strtolower(trim($which_file_format));
296
		if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) {
297
			$this->file_format = $asked;
298
			return true;
299
		} else {
300
			return false;
301
		}
302
	}
303
304
	function SetInputFile($which_input_file) {
305
		//$this->SetFileFormat($which_frmt);
306
		$size = GetImageSize($which_input_file);
307
		$input_type = $size[2];
308
309
		switch($input_type) {  //After SetFileFormat is in lower case
310
			case "1":
311
				$im = @ImageCreateFromGIF ($which_input_file);
312
				if (!$im) { // See if it failed
313
					$this->PrintError("Unable to open $which_input_file as a GIF");
314
					return false;
315
				}
316
			break;
317
			case "3":
318
				$im = @ImageCreateFromPNG ($which_input_file);
319
				if (!$im) { // See if it failed
320
					$this->PrintError("Unable to open $which_input_file as a PNG");
321
					return false;
322
				}
323
			break;
324
			case "2":
325
				$im = @ImageCreateFromJPEG ($which_input_file);
326
				if (!$im) { // See if it failed
327
					$this->PrintError("Unable to open $which_input_file as a JPG");
328
					return false;
329
				}
330
			break;
331
			default:
332
				$this->PrintError('Please select wbmp,gif,jpg, or png for image type!');
333
				return false;
334
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
335
		}
336
337
		//Get Width and Height of Image
338
		$this->SetImageArea($size[0],$size[1]);
339
340
		$this->img = $im;
341
342
		return true;
343
344
	}
345
346
	function SetOutputFile($which_output_file) {
347
		$this->output_file = $which_output_file;
0 ignored issues
show
Bug introduced by
The property output_file does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
348
		return true;
349
	}
350
351
	function SetImageArea($which_iw,$which_ih) {
352
		//Note this is now an Internal function - please set w/h via PHPlot()
353
		$this->image_width = $which_iw;
354
		$this->image_height = $which_ih;
355
356
		return true;
357
	}
358
359
360
	function SetYAxisPosition($which_pos) {
361
		$this->y_axis_position = $which_pos;
362
		return true;
363
	}
364
	function SetXAxisPosition($which_pos) {
365
		$this->x_axis_position = $which_pos;
366
		return true;
367
	}
368
	function SetXTimeFormat($which_xtf) {
369
		$this->x_time_format = $which_xtf;
370
		return true;
371
	}
372
	function SetXDataLabelMaxlength($which_xdlm) {
373
		if ($which_xdlm >0 ) {
374
			$this->x_datalabel_maxlength = $which_xdlm;
375
			return true;
376
		} else {
377
			return false;
378
		}
379
	}
380
	function SetXDataLabelAngle($which_xdla) {
381
		$this->x_datalabel_angle = $which_xdla;
382
		return true;
383
	}
384
	function SetXScaleType($which_xst) {
385
		$this->xscale_type = $which_xst;
386
		return true;
387
	}
388
	function SetYScaleType($which_yst) {
389
		$this->yscale_type = $which_yst;
390
		if ($this->x_axis_position <= 0) {
391
			$this->x_axis_position = 1;
392
		}
393
		return true;
394
	}
395
396
	function SetPrecisionX($which_prec) {
397
		$this->x_precision = $which_prec;
398
		return true;
399
	}
400
	function SetPrecisionY($which_prec) {
401
		$this->y_precision = $which_prec;
402
		return true;
403
	}
404
405
406
	function SetIndexColors() { //Internal Method called to set colors and preserve state
407
		//These are the colors of the image that are used. They are initialized
408
		//to work with sessions and PHP.
409
410
		$this->ndx_i_light = $this->SetIndexColor($this->i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
411
		$this->ndx_i_dark  = $this->SetIndexColor($this->i_dark);
0 ignored issues
show
Bug introduced by
The property ndx_i_dark does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property i_dark does not seem to exist. Did you mean ndx_i_dark?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
412
		$this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
0 ignored issues
show
Bug introduced by
The property ndx_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
413
		$this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
0 ignored issues
show
Bug introduced by
The property ndx_plot_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
414
415
		$this->ndx_title_color= $this->SetIndexColor($this->title_color);
0 ignored issues
show
Bug introduced by
The property ndx_title_color does not seem to exist. Did you mean title_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
416
		$this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
417
		$this->ndx_label_color= $this->SetIndexColor($this->label_color);
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
418
		$this->ndx_text_color= $this->SetIndexColor($this->text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
419
		$this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
420
		$this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
421
422
		unset($ndx_error_bar_color);
423
		$i = 0;
424
		foreach ($this->error_bar_color as $col) {
0 ignored issues
show
Bug introduced by
The expression $this->error_bar_color of type string is not traversable.
Loading history...
425
		  $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_error_bar_color does not seem to exist. Did you mean error_bar_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
426
			$i++;
427
		}
428
429
		unset($ndx_data_border_color);
430
		$i = 0;
431
		foreach ($this->data_border_color as $col) {
0 ignored issues
show
Bug introduced by
The expression $this->data_border_color of type string is not traversable.
Loading history...
432
			$this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_data_border_color does not seem to exist. Did you mean data_border_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
433
			$i++;
434
		}
435
436
		unset($ndx_data_color);
437
		$i = 0;
438
		foreach ($this->data_color as $col) {
0 ignored issues
show
Bug introduced by
The expression $this->data_color of type string is not traversable.
Loading history...
439
			$this->ndx_data_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
440
			$i++;
441
		}
442
443
		return true;
444
	}
445
446
447
	function SetDefaultColors() {
448
449
		$this->i_light = array(194,194,194);
0 ignored issues
show
Documentation Bug introduced by
It seems like array(194, 194, 194) of type array<integer,integer,{"...nteger","2":"integer"}> is incompatible with the declared type string of property $i_light.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
450
		$this->i_dark =  array(100,100,100);
0 ignored issues
show
Bug introduced by
The property i_dark does not seem to exist. Did you mean ndx_i_dark?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
451
		$this->SetPlotBgColor(array(222,222,222));
452
		$this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values
453
		$this->SetLabelColor('black');
454
		$this->SetTextColor('black');
455
		$this->SetGridColor('black');
456
		$this->SetLightGridColor(array(175,175,175));
457
		$this->SetTickColor('black');
458
		$this->SetTitleColor(array(0,0,0)); // Can be array or name
459
		$this->data_color = array('blue','green','yellow','red','orange');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('blue', 'green', 'yellow', 'red', 'orange') of type array<integer,string,{"0..."string","4":"string"}> is incompatible with the declared type string of property $data_color.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
460
		$this->error_bar_color = array('blue','green','yellow','red','orange');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('blue', 'green', 'yellow', 'red', 'orange') of type array<integer,string,{"0..."string","4":"string"}> is incompatible with the declared type string of property $error_bar_color.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
461
		$this->data_border_color = array('black');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('black') of type array<integer,string,{"0":"string"}> is incompatible with the declared type string of property $data_border_color.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
462
463
		$this->session_set = 1; //Mark it down for PHP session() usage.
0 ignored issues
show
Documentation Bug introduced by
The property $session_set was declared of type string, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
464
	}
465
466
	function PrintImage() {
467
468
		if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
469
			header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
470
			header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
471
			header('Cache-Control: no-cache, must-revalidate');
472
			header('Pragma: no-cache');
473
		}
474
475
		switch($this->file_format) {
476 View Code Duplication
			case "png":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
477
				if ($this->is_inline == 0) {
478
					Header('Content-type: image/png');
479
				}
480
				if ($this->is_inline == 1 && $this->output_file != "") {
481
					ImagePng($this->img,$this->output_file);
482
				} else {
483
					ImagePng($this->img);
484
				}
485
				break;
486 View Code Duplication
			case "jpg":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
487
				if ($this->is_inline == 0) {
488
					Header('Content-type: image/jpeg');
489
				}
490
				if ($this->is_inline == 1 && $this->output_file != "") {
491
					ImageJPEG($this->img,$this->output_file);
492
				} else {
493
					ImageJPEG($this->img);
494
				}
495
				break;
496 View Code Duplication
			case "gif":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
497
				if ($this->is_inline == 0) {
498
					Header('Content-type: image/gif');
499
				}
500
				if ($this->is_inline == 1 && $this->output_file != "") {
501
					ImageGIF($this->img,$this->output_file);
502
				} else {
503
					ImageGIF($this->img);
504
				}
505
506
				break;
507 View Code Duplication
			case "wbmp":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
508
				if ($this->is_inline == 0) {
509
					Header('Content-type: image/wbmp');
510
				}
511
				if ($this->is_inline == 1 && $this->output_file != "") {
512
					ImageWBMP($this->img,$this->output_file);
513
				} else {
514
					ImageWBMP($this->img);
515
				}
516
517
				break;
518
			default:
519
				$this->PrintError('Please select an image type!<br />');
520
				break;
521
		}
522
		ImageDestroy($this->img);
523
		return true;
524
	}
525
526
527
	function DrawBackground() {
528
		//if ($this->img == "") { $this->InitImage(); };
529
		if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image
530
			ImageFilledRectangle($this->img, 0, 0,
531
				$this->image_width, $this->image_height, $this->ndx_bg_color);
0 ignored issues
show
Bug introduced by
The property ndx_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
532
			$this->background_done = 1;
533
		}
534
		return true;
535
	}
536
537
	function DrawImageBorder() {
538
		switch ($this->image_border_type) {
539
			case "raised":
540
				ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
541
				ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
542
				ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
543
				ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
544
				ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
545
				ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
546
				ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
547
				ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
548
			break;
549
			case "plain":
550
				ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark);
551
				ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark);
552
				ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark);
553
				ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark);
554
			break;
555
			default:
556
			break;
557
		}
558
		return true;
559
	}
560
561
	function SetPlotBorderType($which_pbt) {
562
		$this->plot_border_type = $which_pbt; //left, none, anything else=full
563
	}
564
565
	function SetImageBorderType($which_sibt) {
566
		$this->image_border_type = $which_sibt; //raised, plain
567
	}
568
569
	function SetDrawPlotAreaBackground($which_dpab) {
570
		$this->draw_plot_area_background = $which_dpab;  // 1=true or anything else=false
571
	}
572
573
	function SetDrawDataLabels($which_ddl) {  //Draw next to datapoints
574
		$this->draw_data_labels = $which_ddl;  // 1=true or anything else=false
575
	}
576
577
	function SetDrawXDataLabels($which_dxdl) {  //Draw on X Axis
578
		$this->draw_x_data_labels = $which_dxdl;  // 1=true or anything else=false
579
	}
580
581
	function SetDrawYGrid($which_dyg) {
582
		$this->draw_y_grid = $which_dyg;  // 1=true or anything else=false
583
	}
584
585
	function SetDrawXGrid($which_dxg) {
586
		$this->draw_x_grid = $which_dxg;  // 1=true or anything else=false
587
	}
588
589
	function SetYGridLabelType($which_yglt) {
590
		$this->y_grid_label_type = $which_yglt;
591
		return true;
592
	}
593
594
	function SetXGridLabelType($which_xglt) {
595
		$this->x_grid_label_type = $which_xglt;
596
		return true;
597
	}
598
599
	function SetXLabel($xlbl) {
600
		$this->x_label_txt = $xlbl;
601
		return true;
602
	}
603
	function SetYLabel($ylbl) {
604
		$this->y_label_txt = $ylbl;
605
		return true;
606
	}
607
	function SetTitle($title) {
608
		$this->title_txt = $title;
609
		return true;
610
	}
611
612
	//function SetLabels($xlbl,$ylbl,$title) {
613
	//	$this->title_txt = $title;
614
	//	$this->x_label_txt = $xlbl;
615
	//	$this->y_label_txt = $ylbl;
616
	//}
617
618
	function DrawLabels() {
619
		$this->DrawTitle();
620
		$this->DrawXLabel();
621
		$this->DrawYLabel();
622
		return true;
623
	}
624
625
	function DrawXLabel() {
626
		if ($this->use_ttf == 1) {
627
			$xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ;
628
			$ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0;
0 ignored issues
show
Bug introduced by
The property x_label_height does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
629
			$this->DrawText($this->x_label_ttffont, $this->x_label_angle,
630
				$xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
631 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
632
			//$xpos = 0.0 - (ImageFontWidth($this->small_font)*strlen($this->x_label_txt)/2.0) + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
633
			$xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
634
			$ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
635
636
			$this->DrawText($this->small_font, $this->x_label_angle,
637
				$xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center');
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
638
639
		}
640
		return true;
641
	}
642
643
	function DrawYLabel() {
644
		if ($this->use_ttf == 1) {
645
			$size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt);
646
			$xpos = 8 + $size[0];
647
			$ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ;
648
			$this->DrawText($this->y_label_ttffont, 90,
649
				$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
650 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
651
			$xpos = 8;
652
			$ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) +
653
					$this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) );
654
			$this->DrawText($this->small_font, 90,
655
				$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
656
		}
657
		return true;
658
	}
659
660
	function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') {
661
662
		if ($this->use_ttf == 1 ) {
663
			$size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text);
664
			if ($which_valign == 'bottom') {
665
				$which_ypos = $which_ypos + ImageFontHeight($which_font);
666
			}
667
			if ($which_halign == 'center') {
668
				$which_xpos = $which_xpos - $size[0]/2;
669
			}
670
			ImageTTFText($this->img, $which_size, $which_angle,
671
				$which_xpos, $which_ypos, $which_color, $which_font, $which_text);
672
		} else {
673
			if ($which_valign == 'top') {
674
				$which_ypos = $which_ypos - ImageFontHeight((int)$which_font);
675
			}
676
			$which_text = preg_replace("/\r/","",$which_text);
677
			$str = explode("\n",$which_text); //multiple lines submitted by Remi Ricard
678
			$height = ImageFontHeight((int)$which_font);
679
			$width = ImageFontWidth((int)$which_font);
680
			if ($which_angle == 90) {  //Vertical Code Submitted by Marlin Viss
681
				for($i=0;$i<count($str);$i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
682
					ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color);
683
				}
684
			} else {
685
				for($i=0;$i<count($str);$i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
686
					if ($which_halign == 'center') {
687
                    	$xpos = $which_xpos - strlen($str[$i]) * $width/2;
688
 						ImageString($this->img, (int)$which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
689
					} else {
690
						ImageString($this->img, (int)$which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
691
					}
692
				}
693
			}
694
695
		}
696
		return true;
697
698
	}
699
	function DrawTitle() {
700
		if ($this->use_ttf == 1 ) {
701
			$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
702
			$ypos = $this->y_top_margin/2;
703
			$this->DrawText($this->title_ttffont, $this->title_angle,
704
				$xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center');
0 ignored issues
show
Bug introduced by
The property ndx_title_color does not seem to exist. Did you mean title_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
705
		} else {
706
			$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
707
			$ypos = ImageFontHeight($this->title_font);
708
			$this->DrawText($this->title_font, $this->title_angle,
709
				$xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center');
0 ignored issues
show
Bug introduced by
The property ndx_title_color does not seem to exist. Did you mean title_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
710
		}
711
		return true;
712
713
	}
714
715
	function DrawPlotAreaBackground() {
716
		ImageFilledRectangle($this->img,$this->plot_area[0],
717
			$this->plot_area[1],$this->plot_area[2],$this->plot_area[3],
718
			$this->ndx_plot_bg_color);
0 ignored issues
show
Bug introduced by
The property ndx_plot_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
719
	}
720
721
	function SetBackgroundColor($which_color) {
722
		$this->bg_color= $which_color;
723
		$this->ndx_bg_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
724
		return true;
725
	}
726
	function SetPlotBgColor($which_color) {
727
		$this->plot_bg_color= $which_color;
728
		$this->ndx_plot_bg_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_plot_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
729
		return true;
730
	}
731
732
	function SetShading($which_s) {
733
		$this->shading = $which_s;
734
		return true;
735
	}
736
737
	function SetTitleColor($which_color) {
738
		$this->title_color= $which_color;
739
		$this->ndx_title_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_title_color does not seem to exist. Did you mean title_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
740
		return true;
741
	}
742
743
	function SetTickColor ($which_color) {
744
		$this->tick_color= $which_color;
745
		$this->ndx_tick_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
746
		return true;
747
	}
748
749
	function SetLabelColor ($which_color) {
750
		$this->label_color= $which_color;
751
		$this->ndx_label_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
752
		return true;
753
	}
754
755
	function SetTextColor ($which_color) {
756
		$this->text_color= $which_color;
757
		$this->ndx_text_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
758
		return true;
759
	}
760
761
	function SetLightGridColor ($which_color) {
762
		$this->light_grid_color= $which_color;
763
		$this->ndx_light_grid_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
764
		return true;
765
	}
766
767
	function SetGridColor ($which_color) {
768
		$this->grid_color = $which_color;
769
		$this->ndx_grid_color= $this->SetIndexColor($which_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
770
		return true;
771
	}
772
773
	function SetCharacterHeight() {
774
		//to be set
775
		return true;
776
	}
777
778
	function SetPlotType($which_pt) {
779
		$accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
780
		$asked = trim($which_pt);
781
		if (preg_match('/' . $asked .'/i', $accepted)) {
782
			$this->plot_type = $which_pt;
783
			return true;
784
		} else {
785
			$this->DrawError('$which_pt not an acceptable plot type');
786
			return false;
787
		}
788
	}
789
790
	function FindDataLimits() {
791
		//Text-Data is different than data-data graphs. For them what
792
		// we have, instead of X values, is # of records equally spaced on data.
793
		//text-data is passed in as $data[] = (title,y1,y2,y3,y4,...)
794
		//data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...)
795
796
		$this->number_x_points = count($this->data_values);
797
798
		switch ($this->data_type) {
799
			case "text-data":
800
				$minx = 0; //valid for BAR TYPE GRAPHS ONLY
801
				$maxx = $this->number_x_points - 1 ;  //valid for BAR TYPE GRAPHS ONLY
802
				$miny = (double) $this->data_values[0][1];
803
				$maxy = $miny;
804
				if ($this->draw_x_data_labels == "") {
805
					$this->draw_x_data_labels = 1;  //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping
0 ignored issues
show
Documentation Bug introduced by
The property $draw_x_data_labels was declared of type string, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
806
				}
807
			break;
808
			default:  //Everything else: data-data, etc.
809
				$maxx = $this->data_values[0][1];
810
				$minx = $maxx;
811
				$miny = $this->data_values[0][2];
812
				$maxy = $miny;
0 ignored issues
show
Unused Code introduced by
$maxy is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
813
				$maxy = $miny;
814
			break;
815
		}
816
817
		$max_records_per_group = 0;
818
		$total_records = 0;
819
		$mine = 0; //Maximum value for the -error bar (assume error bars always > 0)
820
		$maxe = 0; //Maximum value for the +error bar (assume error bars always > 0)
821
822
		foreach ($this->data_values as $dat_key => $dat) {
823
			$tmp = 0;
824
			$total_records += count($dat) - 1; // -1 for label
825
826
			switch ($this->data_type) {
827
				case "text-data":
828
					//Find the relative Max and Min
829
830
					foreach ($dat as $key => $val) {
831
						if ($key != 0) {  //$dat[0] = label
832
							SetType($val,"double");
833
							if ($val > $maxy) {
834
								$maxy = $val ;
835
							}
836
							if ($val < $miny) {
837
								$miny = (double) $val ;
838
							}
839
						}
840
						$tmp++;
841
					}
842
				break;
843
				case "data-data":  //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
844
845
					foreach ($dat as $key => $val) {
846
						if ($key == 1) {  //$dat[0] = label
847
							SetType($val,"double");
848
							if ($val > $maxx) {
849
								$maxx = $val;
850
							} elseif ($val < $minx) {
851
								$minx = $val;
852
							}
853 View Code Duplication
						} elseif ($key > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
854
							SetType($val,"double");
855
							if ($val > $maxy) {
856
								$maxy = $val ;
857
							} elseif ($val < $miny) {
858
								$miny = $val ;
859
							}
860
						}
861
						$tmp++;
862
					}
863
					$tmp = $tmp - 1; //# records per group
864
				break;
865
				case "data-data-error":  //Assume 2-D for now, can go higher
866
				//Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-)
867
868
					foreach ($dat as $key => $val) {
869
						if ($key == 1) {  //$dat[0] = label
870
							SetType($val,'double');
871
							if ($val > $maxx) {
872
								$maxx = $val;
873
							} elseif ($val < $minx) {
874
								$minx = $val;
875
							}
876 View Code Duplication
						} elseif ($key%3 == 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
877
							SetType($val,'double');
878
							if ($val > $maxy) {
879
								$maxy = $val ;
880
							} elseif ($val < $miny) {
881
								$miny = $val ;
882
							}
883
						} elseif ($key%3 == 0) {
884
							SetType($val,'double');
885
							if ($val > $maxe) {
886
								$maxe = $val ;
887
							}
888
						} elseif ($key%3 == 1) {
889
							SetType($val,'double');
890
							if ($val > $mine) {
891
								$mine = $val ;
892
							}
893
						}
894
						$tmp++;
895
					}
896
					$maxy = $maxy + $maxe;
897
					$miny = $miny - $mine; //assume error bars are always > 0
898
899
				break;
900
				default:
901
					$this->PrintError('ERROR: unknown chart type');
902
				break;
903
			}
904
			if ($tmp > $max_records_per_group) {
905
				$max_records_per_group = $tmp;
906
			}
907
		}
908
909
910
		$this->min_x = $minx;
0 ignored issues
show
Bug introduced by
The property min_x does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
911
		$this->max_x = $maxx;
912
		$this->min_y = $miny;
913
		$this->max_y = $maxy;
914
915
916
		if ($max_records_per_group > 1) {
917
			$this->records_per_group = $max_records_per_group - 1;
0 ignored issues
show
Bug introduced by
The property records_per_group does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
918
		} else {
919
			$this->records_per_group = 1;
920
		}
921
922
923
		//$this->data_count = $total_records ;
924
	} // function FindDataLimits
925
926
	function SetMargins() {
927
		/////////////////////////////////////////////////////////////////
928
		// When the image is first created - set the margins
929
		// to be the standard viewport.
930
		// The standard viewport is the full area of the view surface (or panel),
931
		// less a margin of 4 character heights all round for labelling.
932
		// It thus depends on the current character size, set by SetCharacterHeight().
933
		/////////////////////////////////////////////////////////////////
934
935
		$str = explode("\n",$this->title_txt);
936
		$nbLines = count($str);
937
938
		if ($this->use_ttf == 1) {
939
			$title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array
940 View Code Duplication
			if ($nbLines == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
941
				$this->y_top_margin = $title_size[1] * 4;
942
			} else {
943
				$this->y_top_margin = $title_size[1] * ($nbLines+3);
944
			}
945
946
			//ajo working here
947
			//$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
948
949
			$this->y_bot_margin = $this->x_label_height ;
950
			$this->x_left_margin = $this->y_label_width * 2 + $this->tick_length;
951
			$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
952
		} else {
953
			$title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font));
954
			//$this->y_top_margin = ($title_size[1] * 4);
955 View Code Duplication
			if ($nbLines == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
956
				$this->y_top_margin = $title_size[1] * 4;
957
			} else {
958
				$this->y_top_margin = $title_size[1] * ($nbLines+3);
959
			}
960
			if ($this->x_datalabel_angle == 90) {
961
				$this->y_bot_margin = 76.0; // Must be integer
962
			} else {
963
				$this->y_bot_margin = 66.0; // Must be integer
964
			}
965
			$this->x_left_margin = 77.0; // distance between left and start of x axis in pixels
966
			$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
967
		}
968
969
//exit;
970
		$this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
0 ignored issues
show
Bug introduced by
The property x_tot_margin does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
971
		$this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
0 ignored issues
show
Bug introduced by
The property y_tot_margin does not seem to exist. Did you mean x_tot_margin?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
972
973
		if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation
974
			$this->SetTranslation();
975
		}
976
	}
977
978
	function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) {
979
		//Set the plot area using margins in pixels (left, right, top, bottom)
980
		$this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm));
981
		return true;
982
	}
983
984
	function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) {
985
		//Like in GD 0,0 is upper left set via pixel Coordinates
986
		$this->plot_area = array($x1,$y1,$x2,$y2);
987
		$this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->plot_area[2] - $this->plot_area[0] of type integer or double is incompatible with the declared type string of property $plot_area_width.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
988
		$this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
0 ignored issues
show
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
989
		$this->y_top_margin = $this->plot_area[1];
990
		if ($this->plot_max_x) {
991
			$this->SetTranslation();
992
		}
993
		return true;
994
	}
995
996
	function SetPlotAreaPixels($x1,$y1,$x2,$y2) {
997
		//Like in GD 0,0 is upper left
998
		if (!$this->x_tot_margin) {
999
			$this->SetMargins();
1000
		}
1001
		if ($x2 && $y2) {
1002
			$this->plot_area = array($x1,$y1,$x2,$y2);
1003
		} else {
1004
			$this->plot_area = array($this->x_left_margin, $this->y_top_margin,
1005
								$this->image_width - $this->x_right_margin,
1006
								$this->image_height - $this->y_bot_margin
1007
							);
1008
		}
1009
		$this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->plot_area[2] - $this->plot_area[0] of type integer or double is incompatible with the declared type string of property $plot_area_width.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1010
		$this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
0 ignored issues
show
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1011
1012
		return true;
1013
1014
	}
1015
1016
	function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) {
1017
		if (($xmin == "")  && ($xmax == "")) {
1018
			//For automatic setting of data we need $this->max_x
1019
				if (!$this->max_y) {
1020
					$this->FindDataLimits() ;
1021
				}
1022
				if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed.
1023
					$xmax = $this->max_x + 1 ;  //valid for BAR CHART TYPE GRAPHS ONLY
1024
					$xmin = 0 ; 				//valid for BAR CHART TYPE GRAPHS ONLY
1025
				} else {
1026
					$xmax = $this->max_x * 1.02;
1027
					$xmin = $this->min_x;
1028
				}
1029
1030
				$ymax = ceil($this->max_y * 1.2);
1031
				if ($this->min_y < 0) {
1032
					$ymin = floor($this->min_y * 1.2);
1033
				} else {
1034
					$ymin = 0;
1035
				}
1036
		}
1037
1038
		$this->plot_min_x = $xmin;
1039
		$this->plot_max_x = $xmax;
1040
1041
		if ($ymin == $ymax) {
1042
			$ymax += 1;
1043
		}
1044
		if ($this->yscale_type == "log") {
1045
			//extra error checking
1046
			if ($ymin <= 0) {
1047
				$ymin = 1;
1048
			}
1049
			if ($ymax <= 0) {
1050
				$this->PrintError('Log plots need data greater than 0');
1051
			}
1052
		}
1053
		$this->plot_min_y = $ymin;
1054
		$this->plot_max_y = $ymax;
1055
1056
		if ($ymax <= $ymin) {
1057
			$this->DrawError('Error in Data - max not gt min');
1058
		}
1059
1060
//Set the boundaries of the box for plotting in world coord
1061
//		if (!$this->x_tot_margin) { //We need to know the margins before we can calculate scale
1062
//			$this->SetMargins();
1063
//		}
1064
		//For this we have to reset the scale
1065
		if ($this->plot_area_width) {
1066
			$this->SetTranslation();
1067
		}
1068
1069
		return true;
1070
1071
	} //function SetPlotAreaWorld
1072
1073
1074
	function PrintError($error_message) {
1075
	// prints the error message to stdout and die
1076
		echo "<p><strong>Fatal error</strong>: $error_message<p>";
1077
		die;
1078
	}
1079
1080
	function DrawError($error_message) {
1081
	// prints the error message inline into
1082
	// the generated image
1083
1084
		if (($this->img) == "") { $this->InitImage(); } ;
1085
1086
		$ypos = $this->image_height/2;
1087
1088
		if ($this->use_ttf == 1) {
1089
			ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1090
			ImageTTFText($this->img, $this->small_ttffont_size, 0, $xpos, $ypos, ImageColorAllocate($this->img,0,0,0), $this->axis_ttffont, $error_message);
0 ignored issues
show
Bug introduced by
The variable $xpos does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1091
		} else {
1092
			ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1093
			ImageString($this->img, $this->small_font,1,$ypos,$error_message, ImageColorAllocate($this->img,0,0,0));
1094
		}
1095
1096
		$this->PrintImage();
1097
		return true;
1098
	}
1099
1100
	function TTFBBoxSize($size, $angle, $font, $string) {
1101
1102
		//Assume angle < 90
1103
		$arr = ImageTTFBBox($size, 0, $font, $string);
1104
		$flat_width  = $arr[0] - $arr[2];
1105
		$flat_height = abs($arr[3] - $arr[5]);
1106
1107
			// for 90deg:
1108
			//	$height = $arr[5] - $arr[7];
1109
			//	$width = $arr[2] - $arr[4];
1110
1111
		$angle = deg2rad($angle);
1112
		$width  = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer
1113
		$height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer
1114
1115
		return array($width, $height);
1116
	}
1117
1118
	function SetXLabelHeight() {
1119
1120
		if ($this->use_ttf == 1) {
1121
			//Space for the X Label
1122
			$size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
1123
			$tmp = $size[1];
1124
1125
			//$string = Str_Repeat('w', $this->x_datalabel_maxlength);
1126
			$i = 0;
1127
			$string = '';
1128
			while ($i < $this->x_datalabel_maxlength) {
1129
			  $string .= 'w';
1130
			  $i++;
1131
			}
1132
1133
			//Space for the axis data labels
1134
			$size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $string);
1135
1136
			$this->x_label_height = 2*$tmp + $size[1] + 4;
1137
1138
		} else {
1139
			//For Non-TTF fonts we can have only angles 0 or 90
1140
			if ($this->x_datalabel_angle == 90) {
1141
				$this->x_label_height = $this->x_datalabel_maxlength * ImageFontWidth($this->small_font) / 1.5;
1142
			} else {
1143
				$this->x_label_height = 5 * ImageFontHeight($this->small_font);
1144
			}
1145
		}
1146
1147
		$this->SetMargins();
1148
1149
		return true;
1150
	} //function SetXLabelHeight
1151
1152
	function SetYLabelWidth() {
1153
		//$ylab = sprintf("%6.1f %s",$i,$si_units[0]);  //use for PHP2 compatibility
1154
		//the "." is for space. It isn't actually printed
1155
		$ylab = number_format($this->max_y, $this->y_precision, ".", ",") . $this->si_units . ".";
1156
1157
		if ($this->use_ttf == 1) {
1158
			$size = $this->TTFBBoxSize($this->axis_ttffont_size, 0, $this->axis_ttffont, $ylab);
1159
		} else {
1160
			$size[0] = StrLen($ylab) * $this->small_font_width * .6;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$size was never initialized. Although not strictly required by PHP, it is generally a good practice to add $size = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1161
		}
1162
1163
		$this->y_label_width = $size[0] * 2;
0 ignored issues
show
Documentation Bug introduced by
The property $y_label_width was declared of type string, but $size[0] * 2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1164
//echo "SYLW: $this->y_label_width<br />";
1165
//exit;
1166
1167
		$this->SetMargins();
1168
		return true;
1169
	}
1170
1171
	function SetEqualXCoord() {
1172
		//for plots that have equally spaced x variables and multiple bars per x-point.
1173
1174
		$space = ($this->plot_area[2] - $this->plot_area[0]) / ($this->number_x_points * 2) * $this->group_frac_width;
1175
		$group_width = $space * 2;
1176
		$bar_width = $group_width / $this->records_per_group;
1177
  //I think that eventually this space variable will be replaced by just graphing x.
1178
		$this->data_group_space = $space;
0 ignored issues
show
Bug introduced by
The property data_group_space does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1179
		$this->record_bar_width = $bar_width;
0 ignored issues
show
Bug introduced by
The property record_bar_width does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1180
		return true;
1181
	}
1182
1183
	function SetLabelScalePosition($which_blp) {
1184
		//0 to 1
1185
		$this->label_scale_position = $which_blp;
1186
		return true;
1187
	}
1188
1189
	function SetErrorBarSize($which_ebs) {
1190
		//in pixels
1191
		$this->error_bar_size = $which_ebs;
1192
		return true;
1193
	}
1194
1195
	function SetErrorBarShape($which_ebs) {
1196
		//in pixels
1197
		$this->error_bar_shape = $which_ebs;
1198
		return true;
1199
	}
1200
1201
	function SetPointShape($which_pt) {
1202
		//in pixels
1203
		$this->point_shape = $which_pt;
1204
		return true;
1205
	}
1206
1207
	function SetPointSize($which_ps) {
1208
		//in pixels
1209
		SetType($which_ps,'integer');
1210
		$this->point_size = $which_ps;
1211
1212
		if ($this->point_shape == "diamond" or $this->point_shape == "triangle") {
1213
			if ($this->point_size % 2 != 0) {
1214
				$this->point_size++;
1215
			}
1216
		}
1217
		return true;
1218
	}
1219
1220
	function SetDataType($which_dt) {
1221
		//The next three lines are for past compatibility.
1222
		if ($which_dt == "text-linear") { $which_dt = "text-data"; };
1223
		if ($which_dt == "linear-linear") { $which_dt = "data-data"; };
1224
		if ($which_dt == "linear-linear-error") { $which_dt = "data-data-error"; };
1225
1226
		$this->data_type = $which_dt; //text-data, data-data, data-data-error
1227
		return true;
1228
	}
1229
1230
	function SetDataValues($which_dv) {
1231
		$this->data_values = $which_dv;
1232
//echo $this->data_values
1233
		return true;
1234
	}
1235
1236
//////////////COLORS
1237
	function SetRGBArray ($which_color_array) {
1238
		if ( is_array($which_color_array) ) {
1239
			//User Defined Array
1240
			$this->rgb_array = $which_color_array;
0 ignored issues
show
Bug introduced by
The property rgb_array does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1241
			return true;
1242
		} elseif ($which_color_array == 2) { //Use the small predefined color array
1243
		$this->rgb_array = array(
1244
			"white"			=> array(255, 255, 255),
1245
			"snow"			=> array(255, 250, 250),
1246
			"PeachPuff"		=> array(255, 218, 185),
1247
			"ivory"			=> array(255, 255, 240),
1248
			"lavender"		=> array(230, 230, 250),
1249
			"black"			=> array(  0,   0,   0),
1250
			"DimGrey"			=> array(105, 105, 105),
1251
			"gray"			=> array(190, 190, 190),
1252
			"grey"			=> array(190, 190, 190),
1253
			"navy"			=> array(  0,   0, 128),
1254
			"SlateBlue"			=> array(106,  90, 205),
1255
			"blue"			=> array(  0,   0, 255),
1256
			"SkyBlue"			=> array(135, 206, 235),
1257
			"cyan"			=> array(  0, 255, 255),
1258
			"DarkGreen"			=> array(  0, 100,   0),
1259
			"green"			=> array(  0, 255,   0),
1260
			"YellowGreen"			=> array(154, 205,  50),
1261
			"yellow"			=> array(255, 255,   0),
1262
			"orange"			=> array(255, 165,   0),
1263
			"gold"			=> array(255, 215,   0),
1264
			"peru"			=> array(205, 133,  63),
1265
			"beige"			=> array(245, 245, 220),
1266
			"wheat"			=> array(245, 222, 179),
1267
			"tan"			=> array(210, 180, 140),
1268
			"brown"			=> array(165,  42,  42),
1269
			"salmon"			=> array(250, 128, 114),
1270
			"red"			=> array(255,   0,   0),
1271
			"pink"			=> array(255, 192, 203),
1272
			"maroon"			=> array(176,  48,  96),
1273
			"magenta"			=> array(255,   0, 255),
1274
			"violet"			=> array(238, 130, 238),
1275
			"plum"			=> array(221, 160, 221),
1276
			"orchid"			=> array(218, 112, 214),
1277
			"purple"			=> array(160,  32, 240),
1278
			"azure1"			=> array(240, 255, 255),
1279
			"aquamarine1"		=> array(127, 255, 212)
1280
			);
1281
			return true;
1282
		} elseif ($which_color_array == 1)  {
1283
			include("./rgb.inc.php"); //Get large $ColorArray
1284
			$this->rgb_array = $RGBArray;
0 ignored issues
show
Bug introduced by
The variable $RGBArray does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1285
		} else {
1286
			$this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0));
1287
			exit;
1288
		}
1289
1290
		return true;
1291
	}
1292
1293
	function SetColor($which_color) {
1294
		//obsoleted by SetRGBColor
1295
		SetRgbColor($which_color);
1296
		return true;
1297
	}
1298
1299
	function SetIndexColor($which_color) { //Color is passed in as anything
1300
  		list ($r, $g, $b) = $this->SetRgbColor($which_color);  //Translate to RGB
1301
		$index = ImageColorExact($this->img, $r, $g, $b);
1302
		if ($index == -1) {
1303
	  			//return ImageColorAllocate($this->img, $r, $g, $b);
1304
	  			//return ImageColorClosest($this->img, $r, $g, $b);
1305
	  			return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later
1306
 		} else {
1307
	  			return $index;
1308
  		}
1309
	}
1310
1311
	function SetTransparentColor($which_color) {
1312
		ImageColorTransparent($this->img,$this->SetIndexColor($which_color));
1313
		return true;
1314
	}
1315
1316
	function SetRgbColor($color_asked) {
1317
		//Returns an array in R,G,B format 0-255
1318
		if ($color_asked == "") { $color_asked = array(0,0,0); };
1319
1320
		if ( count($color_asked) == 3 ) { //already array of 3 rgb
1321
	   		$ret_val =  $color_asked;
1322
		} else { // is asking for a color by string
1323
			if(substr($color_asked,0,1) == "#") {  //asking in #FFFFFF format.
1324
				$ret_val =  array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2)));
0 ignored issues
show
Bug introduced by
The variable $color does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1325
			} else {
1326
				$ret_val =  $this->rgb_array[$color_asked];
1327
			}
1328
		}
1329
		return $ret_val;
1330
	}
1331
1332
	function SetDataColors($which_data,$which_border) {
1333
		//Set the data to be displayed in a particular color
1334
		if (!$which_data) {
1335
			$which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange');
1336
			$which_border = array('black');
1337
		}
1338
1339
		$this->data_color = $which_data;  //an array
1340
		$this->data_border_color = $which_border;  //an array
1341
1342
		unset($this->ndx_data_color);
1343
		$i = 0;
1344
		foreach ($this->data_color as $col) {
1345
			$this->ndx_data_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1346
			$i++;
1347
		}
1348
1349
		// border_color
1350
		//If we are also going to put a border on the data (bars, dots, area, ...)
1351
		//	then lets also set a border color as well.
1352
		unset($this->ndx_data_border_color);
1353
		$i = 0;
1354
		foreach ($this->data_border_color as $col) {
1355
			$this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_data_border_color does not seem to exist. Did you mean data_border_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1356
			$i++;
1357
		}
1358
1359
		//Set color of the error bars to be that of data if not already set.
1360
		if (!$this->error_bar_color) {
1361
				reset($which_data);
1362
				$this->SetErrorBarColors($which_data);
1363
		}
1364
1365
		return true;
1366
1367
	} //function SetDataColors
1368
1369
	function SetErrorBarColors($which_data) {
1370
1371
	 //Set the data to be displayed in a particular color
1372
1373
	 if ($which_data) {
1374
		$this->error_bar_color = $which_data;  //an array
1375
		unset($this->ndx_error_bar_color);
1376
		$i = 0;
1377
		foreach ($this->error_bar_color as $col) {
1378
			$this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
0 ignored issues
show
Bug introduced by
The property ndx_error_bar_color does not seem to exist. Did you mean error_bar_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1379
			$i++;
1380
		}
1381
		return true;
1382
	  }
1383
	  return false;
1384
	} //function SetErrorBarColors
1385
1386
1387
	function DrawPlotBorder() {
1388
		switch ($this->plot_border_type) {
1389 View Code Duplication
			case "left" :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1390
				ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1391
					$this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1392
			break;
1393
			case "none":
1394
				//Draw No Border
1395
			break;
1396 View Code Duplication
			default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1397
				ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1398
					$this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1399
			break;
1400
		}
1401
		$this->DrawYAxis();
1402
		$this->DrawXAxis();
1403
		return true;
1404
	}
1405
1406
1407
	function SetHorizTickIncrement($which_ti) {
1408
		//Use either this or NumHorizTicks to set where to place x tick marks
1409
		if ($which_ti) {
1410
			$this->horiz_tick_increment = $which_ti;  //world coordinates
1411
		} else {
1412
			if (!$this->max_x) {
1413
				$this->FindDataLimits();  //Get maxima and minima for scaling
1414
			}
1415
			//$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10;
1416
			$this->horiz_tick_increment =  ($this->plot_max_x  - $this->plot_min_x  )/10;
0 ignored issues
show
Documentation Bug introduced by
It seems like ($this->plot_max_x - $this->plot_min_x) / 10 of type integer or double is incompatible with the declared type string of property $horiz_tick_increment.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1417
		}
1418
		$this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
1419
		return true;
1420
	}
1421
1422
	function SetDrawVertTicks($which_dvt) {
1423
		$this->draw_vert_ticks = $which_dvt;
1424
		return true;
1425
	}
1426
1427
	function SetVertTickIncrement($which_ti) {
1428
		//Use either this or NumVertTicks to set where to place y tick marks
1429
		if ($which_ti) {
1430
			$this->vert_tick_increment = $which_ti;  //world coordinates
1431
		} else {
1432
			if (!$this->max_y) {
1433
				$this->FindDataLimits();  //Get maxima and minima for scaling
1434
			}
1435
			//$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10;
1436
			$this->vert_tick_increment =  ($this->plot_max_y  - $this->plot_min_y  )/10;
0 ignored issues
show
Documentation Bug introduced by
It seems like ($this->plot_max_y - $this->plot_min_y) / 10 of type integer or double is incompatible with the declared type string of property $vert_tick_increment.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1437
		}
1438
		$this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
1439
		return true;
1440
	}
1441
1442
	function SetNumHorizTicks($which_nt) {
1443
		$this->num_horiz_ticks = $which_nt;
1444
		$this->horiz_tick_increment = '';  //either use num_horiz_ticks or horiz_tick_increment, not both
1445
		return true;
1446
	}
1447
1448
	function SetNumVertTicks($which_nt) {
1449
		$this->num_vert_ticks = $which_nt;
1450
		$this->vert_tick_increment = '';  //either use num_vert_ticks or vert_tick_increment, not both
1451
		return true;
1452
	}
1453
	function SetVertTickPosition($which_tp) {
1454
		$this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis
1455
		return true;
1456
	}
1457
	function SetSkipBottomTick($which_sbt) {
1458
		$this->skip_bottom_tick = $which_sbt;
1459
		return true;
1460
	}
1461
1462
	function SetTickLength($which_tl) {
1463
		$this->tick_length = $which_tl;
1464
		return true;
1465
	}
1466
1467
	function DrawYAxis() {
1468
		//Draw Line at left side or at this->y_axis_position
1469 View Code Duplication
		if ($this->y_axis_position != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1470
			$yaxis_x = $this->xtr($this->y_axis_position);
1471
		} else {
1472
			$yaxis_x = $this->plot_area[0];
1473
		}
1474
1475
		ImageLine($this->img, $yaxis_x, $this->plot_area[1],
1476
			$yaxis_x, $this->plot_area[3], $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1477
			//$yaxis_x, $this->plot_area[3], 9);
1478
1479
		if ($this->draw_vert_ticks == 1) {
1480
			$this->DrawVerticalTicks();
1481
		}
1482
1483
	} //function DrawYAxis
1484
1485
	function DrawXAxis() {
1486
		//Draw Tick and Label for Y axis
1487
		$ylab =$this->FormatYTickLabel($this->x_axis_position);
1488
		if ($this->skip_bottom_tick != 1) {
1489
			$this->DrawVerticalTick($ylab,$this->x_axis_position);
1490
		}
1491
1492
		//Draw X Axis at Y=$x_axis_postion
1493
		ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position),
1494
				$this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1495
1496
		//X Ticks and Labels
1497
		if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed.
1498
			$this->DrawHorizontalTicks();
1499
		}
1500
		return true;
1501
	}
1502
1503
	function DrawHorizontalTicks() {
1504
		//Ticks and lables are drawn on the left border of PlotArea.
1505
		//Left Bottom
1506
		ImageLine($this->img,$this->plot_area[0],
1507
				$this->plot_area[3]+$this->tick_length,
1508
				$this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1509
1510
		switch ($this->x_grid_label_type) {
1511
			case "title":
1512
				$xlab = $this->data_values[0][0];
1513
			break;
1514 View Code Duplication
			case "data":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1515
				$xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units";
1516
			break;
1517
			case "none":
1518
				$xlab = '';
1519
			break;
1520
			case "time":  //Time formatting suggested by Marlin Viss
1521
				$xlab = strftime($this->x_time_format,$this->plot_min_x);
1522
			break;
1523
			default:
1524
				//Unchanged from whatever format is passed in
1525
				$xlab = $this->plot_min_x;
1526
			break;
1527
		}
1528
1529
		if ($this->x_datalabel_angle == 90) {
1530
			$xpos =  $this->plot_area[0] - $this->small_font_height/2;
1531
			$ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height);
1532
			ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1533
		} else {
1534
			$xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ;
1535
			$ypos = $this->plot_area[3] + $this->small_font_height;
1536
			ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1537
		}
1538
1539
		//Will be changed to allow for TTF fonts in data as well.
1540
		//$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab);
1541
1542
		//Top
1543
1544
		if ($this->horiz_tick_increment) {
1545
			$delta_x = $this->horiz_tick_increment;
1546
		} elseif ($this->num_horiz_ticks) {
1547
			$delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks;
1548
		} else {
1549
			$delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ;
1550
		}
1551
1552
		$i = 0;
1553
		$x_tmp = $this->plot_min_x;
1554
		SetType($x_tmp,'double');
1555
1556
		while ($x_tmp <= $this->plot_max_x){
1557
			//$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]);  //PHP2 past compatibility
1558
			switch ($this->x_grid_label_type) {
1559
				case "title":
1560
					$xlab = $this->data_values[$x_tmp][0];
1561
				break;
1562 View Code Duplication
				case "data":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1563
					$xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units";
1564
				break;
1565
				case "none":
1566
					$xlab = '';
1567
				break;
1568
				case "time":  //Time formatting suggested by Marlin Viss
1569
					$xlab = strftime($this->x_time_format,$x_tmp);
1570
				break;
1571
				default:
1572
					//Unchanged from whatever format is passed in
1573
					$xlab = $x_tmp;
1574
				break;
1575
			}
1576
1577
			$x_pixels = $this->xtr($x_tmp);
1578
1579
			//Bottom Tick
1580
			ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length,
1581
				$x_pixels,$this->plot_area[3], $this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1582
			//Top Tick
1583
			//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
1584
			//	$y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color);
1585
1586 View Code Duplication
			if ($this->draw_x_grid == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1587
				ImageLine($this->img,$x_pixels,$this->plot_area[1],
1588
					$x_pixels,$this->plot_area[3], $this->ndx_light_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1589
			}
1590
1591
			if ($this->x_datalabel_angle == 90) {  //Vertical Code Submitted by Marlin Viss
1592
 			   ImageStringUp($this->img, $this->small_font,
1593
				( $x_pixels - $this->small_font_height/2),
1594
				( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1595
			} else {
1596
				ImageString($this->img, $this->small_font,
1597
					( $x_pixels - $this->small_font_width*strlen($xlab)/2) ,
1598
					( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1599
			}
1600
1601
			$i++;
1602
			$x_tmp += $delta_x;
1603
		}
1604
1605
	} // function DrawHorizontalTicks
1606
1607
	function FormatYTickLabel($which_ylab) {
1608
		switch ($this->y_grid_label_type) {
1609
			case "data":
1610
				$ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units";
1611
			break;
1612
			case "none":
1613
				$ylab = '';
1614
			break;
1615
			case "time":
1616
				$ylab = strftime($this->y_time_format,$which_ylab);
0 ignored issues
show
Bug introduced by
The property y_time_format does not seem to exist. Did you mean x_time_format?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1617
			break;
1618
			case "right":
1619
				//Make it right aligned
1620
				//$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only
1621
				$sstr = "%".strlen($this->plot_max_y)."s";
1622
				$ylab = sprintf($sstr,$which_ylab);
1623
			break;
1624
			default:
1625
				//Unchanged from whatever format is passed in
1626
				$ylab = $which_ylab;
1627
			break;
1628
		}
1629
1630
		return($ylab);
1631
1632
	} //function FormatYTickLabel
1633
1634
	function DrawVerticalTick($which_ylab,$which_ypos) {  //ylab in world coord.
1635
		//Draw Just one Tick, called from DrawVerticalTicks
1636
		//Ticks and datalables can be left of plot only, right of plot only,
1637
		//  both on the left and right of plot, or crossing a user defined Y-axis
1638
		//
1639
		//Its faster to draw both left and right ticks at same time
1640
		//  than first left and then right.
1641
1642 View Code Duplication
		if ($this->y_axis_position != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1643
			//Ticks and lables are drawn on the left border of yaxis
1644
			$yaxis_x = $this->xtr($this->y_axis_position);
1645
		} else {
1646
			//Ticks and lables are drawn on the left border of PlotArea.
1647
			$yaxis_x = $this->plot_area[0];
1648
		}
1649
1650
		$y_pixels = $this->ytr($which_ypos);
1651
1652
		//Lines Across the Plot Area
1653 View Code Duplication
		if ($this->draw_y_grid == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1654
			ImageLine($this->img,$this->plot_area[0]+1,$y_pixels,
1655
				$this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1656
		}
1657
1658
		//Ticks to the Left of the Plot Area
1659 View Code Duplication
		if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1660
			ImageLine($this->img,(-$this->tick_length+$yaxis_x),
1661
			$y_pixels,$yaxis_x,
1662
			$y_pixels, $this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1663
		}
1664
1665
		//Ticks to the Right of the Plot Area
1666
		if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) {
1667
			ImageLine($this->img,($this->plot_area[2]+$this->tick_length),
1668
			$y_pixels,$this->plot_area[2],
1669
			$y_pixels,$this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1670
		}
1671
1672
		//Ticks on the Y Axis
1673 View Code Duplication
		if (($this->vert_tick_position == "yaxis") ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1674
			ImageLine($this->img,($yaxis_x - $this->tick_length),
1675
			$y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color);
0 ignored issues
show
Bug introduced by
The property ndx_tick_color does not seem to exist. Did you mean tick_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1676
		}
1677
1678
		//DataLabel
1679
//ajo working
1680
		//$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2),
1681
		//		$y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab);
1682
		ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
1683
			( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1684
	}
1685
1686
	function DrawVerticalTicks() {
1687
1688
		if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top
1689
			//Left Top
1690
			//ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)),
1691
			//		$this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
1692
			//$ylab = $this->FormatYTickLabel($plot_max_y);
1693
1694
			//Right Top
1695
			//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
1696
			//		$this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
1697
1698
			//Draw Grid Line at Top
1699
			ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y),
1700
					$this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1701
1702
		}
1703
1704
		if ($this->skip_bottom_tick != 1) {
1705
			//Right Bottom
1706
			//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
1707
			//		$this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x),
1708
			//		$this->ytr($this->plot_min_y),$this->ndx_tick_color);
1709
1710
			//Draw Grid Line at Bottom of Plot
1711
			ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y),
1712
					$this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_light_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1713
		}
1714
1715
		// maxy is always > miny so delta_y is always positive
1716
		if ($this->vert_tick_increment) {
1717
			$delta_y = $this->vert_tick_increment;
1718
		} elseif ($this->num_vert_ticks) {
1719
			$delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
1720
		} else {
1721
			$delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
1722
		}
1723
1724
		$y_tmp = $this->plot_min_y;
1725
		SetType($y_tmp,'double');
1726
		if ($this->skip_bottom_tick == 1) {
1727
			$y_tmp += $delta_y;
1728
		}
1729
1730
		while ($y_tmp <= $this->plot_max_y){
1731
			//For log plots:
1732
			if (($this->yscale_type == "log") && ($this->plot_min_y == 1) &&
1733
				($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) {
1734
				$y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,...
1735
			}
1736
1737
			$ylab = $this->FormatYTickLabel($y_tmp);
1738
1739
			$this->DrawVerticalTick($ylab,$y_tmp);
1740
1741
			$y_tmp += $delta_y;
1742
		}
1743
1744
		return true;
1745
1746
	} // function DrawVerticalTicks
1747
1748
	function SetTranslation() {
1749
		if ($this->xscale_type == "log") {
1750
			$this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x));
0 ignored issues
show
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1751
		} else {
1752
			$this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x);
0 ignored issues
show
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1753
		}
1754
		if ($this->yscale_type == "log") {
1755
			$this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y));
0 ignored issues
show
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1756
		} else {
1757
			$this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y);
0 ignored issues
show
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1758
		}
1759
1760
		// GD defines x=0 at left and y=0 at TOP so -/+ respectively
1761
		if ($this->xscale_type == "log") {
1762
			$this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) );
0 ignored issues
show
Bug introduced by
The property plot_origin_x does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1763
		} else {
1764
			$this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x);
0 ignored issues
show
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1765
		}
1766
		if ($this->yscale_type == "log") {
1767
			$this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y));
0 ignored issues
show
Bug introduced by
The property plot_origin_y does not seem to exist. Did you mean plot_origin_x?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1768
		} else {
1769
			$this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y);
0 ignored issues
show
Bug introduced by
The property plot_origin_y does not seem to exist. Did you mean plot_origin_x?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1770
		}
1771
1772
		$this->scale_is_set = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $scale_is_set was declared of type string, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1773
	} // function SetTranslation
1774
1775
	function xtr($x_world) {
1776
	//Translate world coordinates into pixel coordinates
1777
	//The pixel coordinates are those of the ENTIRE image, not just the plot_area
1778
		//$x_pixels =  $this->x_left_margin + ($this->image_width - $this->x_tot_margin)*(($x_world - $this->plot_min_x) / ($this->plot_max_x - $this->plot_min_x)) ;
1779
		//which with a little bit of math reduces to ...
1780
		if ($this->xscale_type == "log") {
1781
			$x_pixels =  $this->plot_origin_x + log10($x_world) * $this->xscale ;
0 ignored issues
show
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1782
		} else {
1783
			$x_pixels =  $this->plot_origin_x + $x_world * $this->xscale ;
0 ignored issues
show
Bug introduced by
The property xscale does not seem to exist. Did you mean xscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1784
		}
1785
		return($x_pixels);
1786
	}
1787
1788
	function ytr($y_world) {
1789
		// translate y world coord into pixel coord
1790
		if ($this->yscale_type == "log") {
1791
			$y_pixels =  $this->plot_origin_y - log10($y_world) * $this->yscale ;  //minus because GD defines y=0 at top. doh!
0 ignored issues
show
Bug introduced by
The property plot_origin_y does not seem to exist. Did you mean plot_origin_x?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1792
		} else {
1793
			$y_pixels =  $this->plot_origin_y - $y_world * $this->yscale ;
0 ignored issues
show
Bug introduced by
The property plot_origin_y does not seem to exist. Did you mean plot_origin_x?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property yscale does not seem to exist. Did you mean yscale_type?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1794
		}
1795
		return ($y_pixels);
1796
	}
1797
1798
1799
	function DrawDataLabel($lab,$x_world,$y_world) {
1800
		//Depreciated. Use DrawText Instead.
1801
		//Data comes in in WORLD coordinates
1802
		//Draw data label near actual data point
1803
			//$y = $this->ytr($y_world) ;  //in pixels
1804
			//$x = $this->xtr($x_world) ;
1805
			//$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');
1806
			if ($this->use_ttf) {
1807
//ajjjo
1808
				$lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array
1809
				$y = $this->ytr($y_world) - $lab_size[1] ;  //in pixels
1810
				$x = $this->xtr($x_world) - $lab_size[0]/2;
1811
				ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1812
			} else {
1813
				$lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3);
0 ignored issues
show
Unused Code introduced by
$lab_size is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1814
				if ($this->x_datalabel_angle == 90) {
1815
					$y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels
1816
					$x = $this->xtr($x_world) - $this->small_font_height;
1817
					ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1818
				} else {
1819
					$y = $this->ytr($y_world) - $this->small_font_height; //in pixels
1820
					$x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2;
1821
					ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1822
				}
1823
			}
1824
1825
	}
1826
1827
	function DrawXDataLabel($xlab,$xpos) {
1828
		//xpos comes in in PIXELS not in world coordinates.
1829
		//Draw an x data label centered at xlab
1830
			if ($this->use_ttf) {
1831
				$xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size,
1832
					$this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array
1833
				$y = $this->plot_area[3] + $xlab_size[1] + 4;  //in pixels
1834
				$x = $xpos - $xlab_size[0]/2;
1835
				ImageTTFText($this->img, $this->axis_ttffont_size,
1836
					$this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1837
			} else {
1838
				$xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3);
0 ignored issues
show
Unused Code introduced by
$xlab_size is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1839
				if ($this->x_datalabel_angle == 90) {
1840
					$y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels
1841
					$x = $xpos - ($this->small_font_height);
1842
					ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1843
				} else {
1844
					$y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels
1845
					$x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2;
1846
					ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1847
				}
1848
			}
1849
1850
	}
1851
1852
	function DrawPieChart() {
1853
		//$pi = '3.14159265358979323846';
1854
		$xpos = $this->plot_area[0] + $this->plot_area_width/2;
1855
		$ypos = $this->plot_area[1] + $this->plot_area_height/2;
0 ignored issues
show
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1856
		$diameter = (min($this->plot_area_width, $this->plot_area_height)) ;
0 ignored issues
show
Bug introduced by
The property plot_area_height does not seem to exist. Did you mean plot_area?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1857
		$radius = $diameter/2;
1858
1859
		ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1860
1861
		$total = 0;
1862
		$tmp = $this->number_x_points - 1;
1863
		foreach ($this->data_values as $j => $row) {
1864
			//Get sum of each type
1865
			$color_index = 0;
0 ignored issues
show
Unused Code introduced by
$color_index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1866
			$i = 0;
1867
			foreach ($row as $k => $v) {
1868
				if ($k != 0) {
1869
					if ($j == 0) {
1870
						$sumarr[$i] = $v;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sumarr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sumarr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1871
					} elseif ($j < $tmp) {
1872
						$sumarr[$i] += $v;
0 ignored issues
show
Bug introduced by
The variable $sumarr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1873
					} else {
1874
						$sumarr[$i] += $v;
1875
					// NOTE!  sum > 0 to make pie charts
1876
						$sumarr[$i] = abs($sumarr[$i]);
1877
						$total += $sumarr[$i];
1878
					}
1879
				}
1880
			$i++;
1881
			}
1882
		}
1883
1884
		$color_index = 0;
1885
		$start_angle = 0;
0 ignored issues
show
Unused Code introduced by
$start_angle is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1886
1887
		$end_angle = 0;
1888
		foreach ($sumarr as $val) {
1889
			if ($color_index >= count($this->ndx_data_color)) $color_index=0;  //data_color = array
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1890
			$label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%";
1891
			$val = 360 * ($val / $total);
1892
1893
			$end_angle += $val;
1894
			$mid_angle = $end_angle - ($val / 2);
1895
1896
			$slicecol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1897
1898
//Need this again for FillToBorder
1899
			ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1900
1901
			$out_x = $radius * cos(deg2rad($end_angle));
1902
			$out_y = - $radius * sin(deg2rad($end_angle));
1903
1904
			$mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ;
1905
			$mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle)));
1906
1907
			$label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position;
1908
			$label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position;
1909
1910
			$out_x = $xpos + $out_x;
1911
			$out_y = $ypos + $out_y;
1912
1913
			ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1914
			//ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color);
1915
			ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1916
1917
			if ($this->use_ttf) {
1918
				ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1919
			} else {
1920
				ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1921
			}
1922
1923
			$start_angle = $val;
0 ignored issues
show
Unused Code introduced by
$start_angle is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1924
1925
			$color_index++;
1926
		}
1927
1928
	}
1929
1930
	function DrawLinesError() {
1931
		//Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
1932
		$start_lines = 0;
1933
1934
		foreach ($this->data_values as $row) {
1935
			$color_index = 0;
1936
			$i = 0;
1937
1938
			foreach ($row as $key => $val) {
1939
//echo "$key, $i, $val<br />";
1940
				if ($key == 0) {
1941
					$lab = $val;
1942
				} elseif ($key == 1) {
1943
					$x_now = $val;
1944
					$x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations.
1945
				} elseif ($key%3 == 2) {
1946
					$y_now = $val;
1947
					$y_now_pixels = $this->ytr($y_now);
1948
1949
					//Draw Data Label
1950
					if ( $this->draw_data_labels == 1) {
1951
						$this->DrawDataLabel($lab,$x_now,$y_now);
0 ignored issues
show
Bug introduced by
The variable $lab does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $x_now does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1952
					}
1953
1954
					if ($color_index >= count($this->ndx_data_color)) { $color_index=0;};
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1955
					$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1956
					$error_barcol = $this->ndx_error_bar_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_error_bar_color does not seem to exist. Did you mean error_bar_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1957
1958
//echo "start = $start_lines<br />";
1959
					if ($start_lines == 1) {
1960
						for ($width = 0; $width < $this->line_width; $width++) {
1961
							ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width,
0 ignored issues
show
Bug introduced by
The variable $x_now_pixels does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1962
								$lastx[$i], $lasty[$i] + $width, $barcol);
0 ignored issues
show
Bug introduced by
The variable $lastx does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $lasty does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1963
						}
1964
					}
1965
1966
					$lastx[$i] = $x_now_pixels;
1967
					$lasty[$i] = $y_now_pixels;
1968
					$color_index++;
1969
					$i++;
1970
					$start_lines = 1;
1971
				} elseif ($key%3 == 0) {
1972
					$this->DrawYErrorBar($x_now,$y_now,$val,$this->error_bar_shape,$error_barcol);
0 ignored issues
show
Bug introduced by
The variable $y_now does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $error_barcol does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1973
				} elseif ($key%3 == 1) {
1974
					$this->DrawYErrorBar($x_now,$y_now,-$val,$this->error_bar_shape,$error_barcol);
1975
				}
1976
			}
1977
		}
1978
	}
1979
1980
	function DrawDotsError() {
1981
		//Draw Dots - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
1982
		foreach ($this->data_values as $row) {
1983
			$color_index = 0;
1984
			foreach ($row as $key => $val) {
1985
				if ($key == 0) {
1986
				} elseif ($key == 1) {
1987
					$xpos = $val;
1988
				} elseif ($key%3 == 2) {
1989
					if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1990
					$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1991
					$error_barcol = $this->ndx_error_bar_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_error_bar_color does not seem to exist. Did you mean error_bar_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1992
					$ypos = $val;
1993
1994
					$color_index++;
1995
					$this->DrawDot($xpos,$ypos,$this->point_shape,$barcol);
0 ignored issues
show
Bug introduced by
The variable $xpos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1996
				} elseif ($key%3 == 0) {
1997
					$this->DrawYErrorBar($xpos,$ypos,$val,$this->error_bar_shape,$error_barcol);
0 ignored issues
show
Bug introduced by
The variable $ypos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $error_barcol does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1998
				} elseif ($key%3 == 1) {
1999
					$mine = $val ;
0 ignored issues
show
Unused Code introduced by
$mine is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2000
					$this->DrawYErrorBar($xpos,$ypos,-$val,$this->error_bar_shape,$error_barcol);
2001
				}
2002
			}
2003
		}
2004
2005
	}
2006
2007
	function DrawDots() {
2008
		//Draw Dots - data comes in as array("title",x,y1,y2,y3,...);
2009
		foreach ($this->data_values as $j => $row) {
2010
			$color_index = 0;
2011
			foreach ($row as $k => $v) {
2012
				if ($k == 0) {
2013
				} elseif (($k == 1) && ($this->data_type == "data-data"))  {
2014
					$xpos = $v;
2015
				} else {
2016
					if ($this->data_type == "text-data") {
2017
						$xpos = ($j+.5);
2018
					}
2019
					if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2020
					$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2021
2022
					//if (is_numeric($v))  //PHP4 only
2023
					if ((strval($v) != "") ) {   //Allow for missing Y data
2024
						$this->DrawDot($xpos,$v,$this->point_shape,$barcol);
0 ignored issues
show
Bug introduced by
The variable $xpos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2025
					}
2026
					$color_index++;
2027
				}
2028
			}
2029
		}
2030
2031
	} //function DrawDots
2032
2033
	function DrawDotSeries() {
2034
		//Depreciated: Use DrawDots
2035
		$this->DrawDots();
2036
	}
2037
2038
	function DrawThinBarLines() {
2039
		//A clean,fast routine for when you just want charts like stock volume charts
2040
		//Data must be text-data since I didn't see a graphing need for equally spaced thin lines.
2041
		//If you want it - then write to [email protected] and I might add it.
2042
2043
		if ($this->data_type != "data-data") { $this->DrawError('Data Type for ThinBarLines must be data-data'); };
2044
		$y1 = $this->ytr($this->x_axis_position);
2045
2046
		foreach ($this->data_values as $row) {
2047
			$color_index = 0;
2048
			foreach ($row as $k => $v) {
2049
				if ($k == 0) {
2050
						$xlab = $v;
2051
				} elseif ($k == 1) {
2052
					$xpos = $this->xtr($v);
2053
					if ( ($this->draw_x_data_labels == 1) )  { //See "labels_note1 above.
2054
						$this->DrawXDataLabel($xlab,$xpos);
0 ignored issues
show
Bug introduced by
The variable $xlab does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2055
					}
2056
				} else {
2057
					if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2058
					$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2059
2060
					ImageLine($this->img,$xpos,$y1,$xpos,$this->ytr($v),$barcol);
0 ignored issues
show
Bug introduced by
The variable $xpos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2061
					$color_index++;
2062
				}
2063
			}
2064
		}
2065
2066
	}  //function DrawThinBarLines
2067
2068
	function DrawYErrorBar($x_world,$y_world,$error_height,$error_bar_type,$color) {
2069
		$x1 = $this->xtr($x_world);
2070
		$y1 = $this->ytr($y_world);
2071
		$y2 = $this->ytr($y_world+$error_height) ;
2072
2073
		for ($width = 0; $width < $this->error_bar_line_width; $width++) {
2074
			ImageLine($this->img, $x1+$width, $y1 , $x1+$width, $y2, $color);
2075
			ImageLine($this->img, $x1-$width, $y1 , $x1-$width, $y2, $color);
2076
		}
2077
		switch ($error_bar_type) {
2078
			case "line":
2079
				break;
2080 View Code Duplication
			case "tee":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2081
				ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
2082
				break;
2083 View Code Duplication
			default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2084
				ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
2085
				break;
2086
		}
2087
		return true;
2088
	}
2089
2090
	function DrawDot($x_world,$y_world,$dot_type,$color) {
2091
		$half_point = $this->point_size / 2;
2092
		$x1 = $this->xtr($x_world) - $half_point;
2093
		$x2 = $this->xtr($x_world) + $half_point;
2094
		$y1 = $this->ytr($y_world) - $half_point;
2095
		$y2 = $this->ytr($y_world) + $half_point;
2096
2097
		switch ($dot_type) {
2098
			case "halfline":
2099
				ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color);
2100
				break;
2101
			case "line":
2102
				ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color);
2103
				break;
2104
			case "rect":
2105
				ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
2106
				break;
2107
			case "circle":
2108
				ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
2109
				break;
2110
			case "dot":
2111
				ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
2112
				ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color);
2113
				break;
2114
			case "diamond":
2115
2116
				$arrpoints = array(
2117
					$x1,$y1 + $half_point,
2118
					$x1 + $half_point, $y1,
2119
					$x2,$y1 + $half_point,
2120
					$x1 + $half_point, $y2
2121
				);
2122
2123
				ImageFilledPolygon($this->img, $arrpoints, 4, $color);
2124
				break;
2125
			case "triangle":
2126
				$arrpoints = array( $x1, $y1 + $half_point,
2127
					$x2, $y1 + $half_point,
2128
					$x1 + $half_point, $y2
2129
				);
2130
				ImageFilledPolygon($this->img, $arrpoints, 3, $color);
2131
				break;
2132
			default:
2133
				ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
2134
				break;
2135
		}
2136
		return true;
2137
	}
2138
2139
	function SetErrorBarLineWidth($which_seblw) {
2140
		$this->error_bar_line_width = $which_seblw;
2141
		return true;
2142
	}
2143
2144
2145
	function SetLineWidth($which_lw) {
2146
		$this->line_width = $which_lw;
2147
		if (!$this->error_bar_line_width) {
2148
			$this->error_bar_line_width = $which_lw;
2149
		}
2150
		return true;
2151
	}
2152
2153
	function DrawArea() {
2154
		//Data comes in as $data[]=("title",x,y,...);
2155
		//Set first and last datapoints of area
2156
		$i = 0;
2157 View Code Duplication
		while ($i < $this->records_per_group) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2158
			$posarr[$i][] =  $this->xtr($this->min_x);	//x initial
0 ignored issues
show
Coding Style Comprehensibility introduced by
$posarr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $posarr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2159
			$posarr[$i][] =  $this->ytr($this->x_axis_position); 	//y initial
0 ignored issues
show
Bug introduced by
The variable $posarr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2160
			$i++;
2161
		}
2162
2163
		foreach ($this->data_values as $j => $row) {
2164
			$color_index = 0;
2165
			foreach ($row as $k => $v) {
2166
				if ($k == 0) {
2167
					//Draw Data Labels
2168
					$xlab = SubStr($v,0,$this->x_datalabel_maxlength);
0 ignored issues
show
Unused Code introduced by
$xlab is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2169
				} elseif ($k == 1) {
2170
					$x = $this->xtr($v);
2171
					// DrawXDataLabel interferes with Numbers on x-axis
2172
					//$this->DrawXDataLabel($xlab,$x);
2173
				} else {
2174
					// Create Array of points for later
2175
2176
					$y = $this->ytr($v);
2177
					$posarr[$color_index][] = $x;
0 ignored issues
show
Bug introduced by
The variable $x does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2178
					$posarr[$color_index][] = $y;
2179
					$color_index++;
2180
				}
2181
			}
2182
		}
2183
2184
		//Final_points
2185 View Code Duplication
		for ($i = 0; $i < $this->records_per_group; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2186
			$posarr[$i][] =  $this->xtr($this->max_x);			//x final
2187
			$posarr[$i][] =  $this->ytr($this->x_axis_position); 	//y final
2188
	   	}
2189
2190
		$color_index=0;
2191
2192 View Code Duplication
		foreach ($posarr as $row) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2193
			if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2194
			$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2195
//echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br />";
2196
			ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
2197
			$color_index++;
2198
		}
2199
//exit;
2200
2201
	}
2202
2203
	function DrawAreaSeries() {
2204
2205
		//Set first and last datapoints of area
2206
		$i = 0;
2207 View Code Duplication
		while ($i < $this->records_per_group) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2208
			$posarr[$i][] =  $this->xtr(.5);			//x initial
0 ignored issues
show
Coding Style Comprehensibility introduced by
$posarr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $posarr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2209
			$posarr[$i][] =  $this->ytr($this->x_axis_position); 	//y initial
0 ignored issues
show
Bug introduced by
The variable $posarr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2210
			$i++;
2211
		}
2212
2213
		foreach ($this->data_values as $j => $row) {
2214
			$color_index = 0;
2215
			foreach ($row as $k => $v) {
2216
				if ($k == 0) {
2217
					//Draw Data Labels
2218
					$xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2219
					$this->DrawXDataLabel($xlab,$this->xtr($j + .5));
2220
				} else {
2221
					// Create Array of points for later
2222
2223
					$x = round($this->xtr($j + .5 ));
2224
					$y = round($this->ytr($v));
2225
					$posarr[$color_index][] = $x;
2226
					$posarr[$color_index][] = $y;
2227
					$color_index++;
2228
				}
2229
			}
2230
		}
2231
2232
		//Final_points
2233 View Code Duplication
		for ($i = 0; $i < $this->records_per_group; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2234
			$posarr[$i][] =  round($this->xtr($this->max_x + .5));	//x final
2235
			$posarr[$i][] =  $this->ytr($this->x_axis_position); 		//y final
2236
	   	}
2237
2238
		$color_index=0;
2239
2240 View Code Duplication
		foreach ($posarr as $row) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2241
			if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2242
			$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2243
//echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br />";
2244
			ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
2245
			$color_index++;
2246
		}
2247
2248
	}
2249
2250
	function DrawLines() {
2251
		//Data comes in as $data[]=("title",x,y,...);
2252
		$start_lines = 0;
2253
		if ($this->data_type == "text-data") {
2254
			$lastx[0] = $this->xtr(0);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$lastx was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lastx = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2255
			$lasty[0] = $this->xtr(0);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$lasty was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lasty = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2256
		}
2257
2258
		foreach ($this->data_values as $j => $row) {
2259
			$color_index = 0;
2260
			$i = 0;
2261
			foreach ($row as $k => $v) {
2262
				if ($k == 0) {
2263
					$xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2264
				} elseif (($k == 1) && ($this->data_type == "data-data"))  {
2265
						$x_now = $this->xtr($v);
2266
				} else {
2267
					//(double) $v;
2268
					// Draw Lines
2269
					if ($this->data_type == "text-data") {
2270
						$x_now = $this->xtr($j+.5);
2271
					}
2272
2273
					//if (is_numeric($v))  //PHP4 only
2274
					if ((strval($v) != "") ) {   //Allow for missing Y data
2275
						$y_now = $this->ytr($v);
2276
						if ($color_index >= count($this->ndx_data_color)) { $color_index=0;} ;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2277
						$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2278
2279
						if ($start_lines == 1) {
2280
							for ($width = 0; $width < $this->line_width; $width++) {
2281
								if ($this->line_style[$i] == "dashed") {
2282
									$this->DrawDashedLine($x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, 4,4, $barcol);
0 ignored issues
show
Bug introduced by
The variable $x_now does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $lastx does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $lasty does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2283
								} else {
2284
									ImageLine($this->img, $x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, $barcol);
2285
								}
2286
							}
2287
						}
2288
						$lastx[$i] = $x_now;
2289
					} else {
2290
						$y_now = $lasty[$i];
2291
						//Don't increment lastx[$i]
2292
					}
2293
					//$bordercol = $this->ndx_data_border_color[$colbarcount];
2294
2295
					$lasty[$i] = $y_now;
2296
					$color_index++;
2297
					$i++;
2298
				}
2299
				//Now we are assured an x_value
2300
				if ( ($this->draw_x_data_labels == 1) && ($k == 1) )  { //See "labels_note1 above.
2301
					$this->DrawXDataLabel($xlab,$x_now);
0 ignored issues
show
Bug introduced by
The variable $xlab does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2302
				}
2303
			} //while rows of data
2304
			$start_lines = 1;
2305
		}
2306
	}
2307
2308
		//Data comes in as $data[]=("title",x,y,e+,e-,y2,e2+,e2-,...);
2309
2310
	function DrawLineSeries() {
2311
		//This function is replaced by DrawLines
2312
		//Tests have shown not much improvement in speed by having separate routines for DrawLineSeries and DrawLines
2313
		//For ease of programming I have combined them
2314
		return false;
2315
	} //function DrawLineSeries
2316
2317
	function DrawDashedLine($x1pix,$y1pix,$x2pix,$y2pix,$dash_length,$dash_space,$color) {
2318
		//Code based on work by Ariel Garza and James Pine
2319
		//I've decided to have this be in pixels only as a replacement for ImageLine
2320
		//$x1pix = $this->xtr($x1);
2321
		//$y1pix = $this->ytr($y1);
2322
		//$x2pix = $this->xtr($x2);
2323
		//$y2pix = $this->ytr($y2);
2324
2325
		// Get the length of the line in pixels
2326
		$line_length = ceil (sqrt(pow(($x2pix - $x1pix),2) + pow(($y2pix - $y1pix),2)) );
2327
2328
		$dx = ($x2pix - $x1pix) / $line_length;
2329
		$dy = ($y2pix - $y1pix) / $line_length;
2330
		$lastx	= $x1pix;
2331
		$lasty	= $y1pix;
2332
2333
		// Draw the dashed line
2334
		for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
2335
			$xpix = ($dash_length * $dx) + $lastx;
2336
			$ypix = ($dash_length * $dy) + $lasty;
2337
2338
			ImageLine($this->img,$lastx,$lasty,$xpix,$ypix,$color);
2339
			$lastx = $xpix + ($dash_space * $dx);
2340
			$lasty = $ypix + ($dash_space * $dy);
2341
		}
2342
	} // function DrawDashedLine
2343
2344
	function DrawBars() {
2345
2346
		if ($this->data_type != "text-data") {
2347
			$this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")');
2348
		}
2349
2350
		$xadjust = ($this->records_per_group * $this->record_bar_width )/4;
0 ignored issues
show
Unused Code introduced by
$xadjust is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2351
2352
		foreach ($this->data_values as $j => $row) {
2353
			$color_index = 0;
2354
			$colbarcount = 0;
2355
			$x_now = $this->xtr($j+.5);
2356
2357
			foreach ($row as $k => $v) {
2358
				if ($k == 0) {
2359
					//Draw Data Labels
2360
					$xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2361
					$this->DrawXDataLabel($xlab,$x_now);
2362
				} else {
2363
					// Draw Bars ($v)
2364
					$x1 = $x_now - $this->data_group_space + ($k-1)*$this->record_bar_width;
2365
					$x2 = $x1 + $this->record_bar_width*$this->bar_width_adjust;
2366
2367
					if ($v < $this->x_axis_position) {
2368
						$y1 = $this->ytr($this->x_axis_position);
2369
						$y2 = $this->ytr($v);
2370
					} else {
2371
						$y1 = $this->ytr($v);
2372
						$y2 = $this->ytr($this->x_axis_position);
2373
					}
2374
2375
					if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2376
					if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_border_color does not seem to exist. Did you mean data_border_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2377
					$barcol = $this->ndx_data_color[$color_index];
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2378
					$bordercol = $this->ndx_data_border_color[$colbarcount];
0 ignored issues
show
Bug introduced by
The property ndx_data_border_color does not seem to exist. Did you mean data_border_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2379
2380
					if ((strval($v) != "") ) {   //Allow for missing Y data
2381
						if ($this->shading > 0) {
2382
							for($i=0;$i<($this->shading);$i++) {
2383
							//Shading set in SetDefaultColors
2384
							ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light);
0 ignored issues
show
Bug introduced by
The property ndx_i_light does not seem to exist. Did you mean i_light?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2385
							}
2386
						}
2387
2388
						ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol);
2389
						ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol);
2390
						if ($this->draw_data_labels == '1') {  //ajo
2391
							$y1 = $this->ytr($this->label_scale_position * $v);
2392
							//$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position);
2393
							$this->DrawText($this->x_label_ttffont, $this->x_label_angle,
2394
								$x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top');
0 ignored issues
show
Bug introduced by
The property ndx_label_color does not seem to exist. Did you mean label_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2395
						}
2396
					}
2397
2398
					$color_index++;
2399
					$colbarcount++;
2400
				}
2401
			}
2402
		}
2403
	} //function DrawBars
2404
2405
	function DrawLegend($which_x1,$which_y1,$which_boxtype) {
0 ignored issues
show
Unused Code introduced by
The parameter $which_boxtype is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2406
		//Base code submitted by Marlin Viss
2407
		$max_legend_length=0;
2408
		foreach ($this->legend as $leg) {
0 ignored issues
show
Bug introduced by
The expression $this->legend of type string is not traversable.
Loading history...
2409
			$len = strlen($leg);
2410
			if ($max_legend_length < $len) {
2411
				$max_legend_length = $len;
2412
			}
2413
		}
2414
2415
		$line_spacing = 1.25;
2416
		$vert_margin = $this->small_font_height/2 ;
2417
		$dot_height = $this->small_font_height*$line_spacing - 1;
2418
2419
	//Upper Left
2420
		if ((!$which_x1) || (!$which_y1) ) {
2421
			$box_start_x = $this->plot_area[2] - $this->small_font_width*($max_legend_length+4);
2422
			$box_start_y = $this->plot_area[1] + 4;
2423
		} else {
2424
			$box_start_x = $which_x1;
2425
			$box_start_y = $which_y1;
2426
		}
2427
2428
	//Lower Right
2429
		$box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin;
2430
		//$box_end_x = $this->plot_area[2] - 5;
2431
		$box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
2432
2433
2434
	// Draw box for legend
2435
		ImageFilledRectangle($this->img,
2436
			$box_start_x, $box_start_y,$box_end_x,
2437
			$box_end_y, $this->ndx_bg_color);
0 ignored issues
show
Bug introduced by
The property ndx_bg_color does not seem to exist. Did you mean bg_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2438
		ImageRectangle($this->img,
2439
			$box_start_x, $box_start_y,$box_end_x,
2440
			$box_end_y, $this->ndx_grid_color);
0 ignored issues
show
Bug introduced by
The property ndx_grid_color does not seem to exist. Did you mean grid_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2441
2442
		$color_index=0;
2443
		$i = 0;
2444
2445
2446
		foreach ($this->legend as $leg) {
0 ignored issues
show
Bug introduced by
The expression $this->legend of type string is not traversable.
Loading history...
2447
			$y_pos = $box_start_y + $this->small_font_height*($i)*($line_spacing) + $vert_margin;
2448
2449
			ImageString($this->img, $this->small_font,
2450
			$box_start_x + $this->small_font_width*( $max_legend_length - strlen($leg) + 1 ) ,
2451
			$y_pos,
2452
			$leg, $this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2453
2454
			if ($color_index >= count($this->ndx_data_color)) $color_index=0;
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2455
	// Draw a box in the data color
2456
			ImageFilledRectangle($this->img,
2457
				$box_end_x - $this->small_font_width*2,
2458
				$y_pos + 1, $box_end_x - $this->small_font_width,
2459
				$y_pos + $dot_height,
2460
				$this->ndx_data_color[$color_index]);
0 ignored issues
show
Bug introduced by
The property ndx_data_color does not seem to exist. Did you mean data_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2461
2462
			ImageRectangle($this->img,
2463
				$box_end_x - $this->small_font_width*2,
2464
				$y_pos + 1, $box_end_x - $this->small_font_width,
2465
				$y_pos + $dot_height,
2466
				$this->ndx_text_color);
0 ignored issues
show
Bug introduced by
The property ndx_text_color does not seem to exist. Did you mean text_color?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
2467
			$i++;
2468
			$color_index++;
2469
		}
2470
	} //function DrawLegend
2471
2472
2473
	function DrawGraph() {
2474
2475
		if (($this->img) == "") {
2476
			$this->DrawError('No Image Defined: DrawGraph');
2477
            //$this->PHPlot();
2478
        }
2479
2480
		if (! is_array($this->data_values)) {
2481
			$this->DrawBackground();
2482
			$this->DrawError("No array of data in \$data_values");
2483
		} else {
2484
			if (!$this->data_color) {
2485
				$this->SetDataColors(array('blue','green','yellow','red','orange','blue'),array('black'));
2486
			}
2487
2488
			$this->FindDataLimits();  //Get maxima and minima for scaling
2489
2490
			$this->SetXLabelHeight();		//Get data for bottom margin
2491
2492
			$this->SetYLabelWidth();		//Get data for left margin
2493
2494
			if (!$this->plot_area_width) {
2495
				$this->SetPlotAreaPixels('','','','');		//Set Margins
2496
			}
2497
2498
			if (!$this->plot_max_y) {  //If not set by user call SetPlotAreaWorld,
2499
				$this->SetPlotAreaWorld('','','','');
2500
			}
2501
2502
			if ($this->data_type == "text-data") {
2503
				$this->SetEqualXCoord();
2504
			}
2505
2506
			$this->SetPointSize($this->point_size);
2507
2508
			$this->DrawBackground();
2509
			$this->DrawImageBorder();
2510
2511
			$this->SetTranslation();
2512
2513
			if ($this->draw_plot_area_background == 1) {
2514
				$this->DrawPlotAreaBackground();
2515
			}
2516
//$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height";
2517
//ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);
2518
2519
			switch ($this->plot_type) {
2520
				case "bars":
2521
					$this->DrawPlotBorder();
2522
					$this->DrawLabels();
2523
					$this->DrawBars();
2524
					$this->DrawXAxis();
2525
					break;
2526
				case "thinbarline":
2527
					$this->DrawPlotBorder();
2528
					$this->DrawLabels();
2529
					$this->DrawThinBarLines();
2530
					break;
2531 View Code Duplication
				case "lines":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2532
					$this->DrawPlotBorder();
2533
					$this->DrawLabels();
2534
					if ( $this->data_type == "text-data") {
2535
						$this->DrawLines();
2536
					} elseif ( $this->data_type == "data-data-error") {
2537
						$this->DrawLinesError();
2538
					} else {
2539
						$this->DrawLines();
2540
					}
2541
					break;
2542
				case "area":
2543
					$this->DrawPlotBorder();
2544
					$this->DrawLabels();
2545
					if ( $this->data_type == "text-data") {
2546
						$this->DrawAreaSeries();
2547
					} else {
2548
						$this->DrawArea();
2549
					}
2550
					break;
2551
				case "linepoints":
2552
					$this->DrawPlotBorder();
2553
					$this->DrawLabels();
2554
					if ( $this->data_type == "text-data") {
2555
						$this->DrawLines();
2556
						$this->DrawDots();
2557
					} elseif ( $this->data_type == "data-data-error") {
2558
						$this->DrawLinesError();
2559
						$this->DrawDotsError();
2560
					} else {
2561
						$this->DrawLines();
2562
						$this->DrawDots();
2563
					}
2564
					break;
2565 View Code Duplication
				case "points";
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2566
					$this->DrawPlotBorder();
2567
					$this->DrawLabels();
2568
					if ( $this->data_type == "text-data") {
2569
						$this->DrawDots();
2570
					} elseif ( $this->data_type == "data-data-error") {
2571
						$this->DrawDotsError();
2572
					} else {
2573
						$this->DrawDots();
2574
					}
2575
					break;
2576
				case "pie":
2577
					$this->DrawPieChart();
2578
					$this->DrawLabels();
2579
					break;
2580
				default:
2581
					$this->DrawPlotBorder();
2582
					$this->DrawLabels();
2583
					$this->DrawBars();
2584
					break;
2585
			}
2586
2587
			if ($this->legend) {
2588
				$this->DrawLegend($this->legend_x_pos,$this->legend_y_pos,'');
2589
			}
2590
2591
		}
2592
		if ($this->print_image == 1) {
2593
			$this->PrintImage();
2594
		}
2595
	} //function DrawGraph
2596
2597
 }
2598
2599
// $graph = new PHPlot;
2600
2601
// $graph->DrawGraph();
2602
2603
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
2604