From b89f770803a11ba470efeba6557396730a9e6bf2 Mon Sep 17 00:00:00 2001 From: Guilherme Calabria Filho Date: Thu, 4 Apr 2024 23:20:19 -0300 Subject: [PATCH] Casting everything and removed imagefilledpolygon num_points --- phplot/phplot.php | 3742 +++++++++++++++++++++++++++------------------ 1 file changed, 2266 insertions(+), 1476 deletions(-) diff --git a/phplot/phplot.php b/phplot/phplot.php index f18f3e6..d95f4de 100644 --- a/phplot/phplot.php +++ b/phplot/phplot.php @@ -1,4 +1,5 @@ + * @link https://github.com/AJRepo/PHPlot/ PHPlot Web Site with downloads, tracker, discussion + * @link https://github.com/AJRepo/PHPlot/ PHPlot Project Web Site with links to documentation + * @author lbayuk (2006-2016) * @author Miguel de Benito Delgado (co-author and maintainer, 2003-2005) - * @author Afan Ottenheimer (original author) + * @author Afan Ottenheimer (1998-present) */ /* @@ -56,12 +57,13 @@ * the type of image produced matches the type of the background image. * */ + class PHPlot { /** PHPlot version constant as a string */ - const version = '6.2.1-Unreleased $Revision: 1792 $'; + public const version = '8.0.0-rc1 $Revision$'; /** PHPlot version constant as a number = major * 10000 + minor * 100 + patch */ - const version_id = 60201; + public const version_id = 80000; // All class variables are declared here, and initialized (if applicable). // Starting with PHPlot-6.0, most variables have 'protected' visibility @@ -91,29 +93,29 @@ class PHPlot /** Ratio of the width of the 'T' ends of box plot whiskers to the width of the boxes */ public $boxes_t_width = 0.6; /** Flag: Don't send cache suppression headers */ - protected $browser_cache = FALSE; + protected $browser_cache = false; /** Max bubble size for bubbles plots */ public $bubbles_max_size; /** Min bubbles size for bubble plots */ public $bubbles_min_size = 6; /** Callback (hook) function information, indexed by callback reason */ protected $callbacks = array( - 'data_points' => NULL, - 'draw_setup' => NULL, - 'draw_image_background' => NULL, - 'draw_plotarea_background' => NULL, - 'draw_titles' => NULL, - 'draw_axes' => NULL, - 'draw_graph' => NULL, - 'draw_border' => NULL, - 'draw_legend' => NULL, - 'draw_all' => NULL, - 'data_color' => NULL, - 'debug_textbox' => NULL, - 'debug_scale' => NULL, + 'data_points' => null, + 'draw_setup' => null, + 'draw_image_background' => null, + 'draw_plotarea_background' => null, + 'draw_titles' => null, + 'draw_axes' => null, + 'draw_graph' => null, + 'draw_border' => null, + 'draw_legend' => null, + 'draw_all' => null, + 'data_color' => null, + 'debug_textbox' => null, + 'debug_scale' => null, ); /** Flag: Draw dashed or solid grid lines? */ - protected $dashed_grid = TRUE; + protected $dashed_grid = true; /** Initial dashed pattern code */ protected $dashed_style = '2-4'; /** The (converted) data array */ @@ -149,18 +151,18 @@ class PHPlot /** Flag: data type includes Y and Z value pairs */ protected $datatype_yz; /** Static array of data type information */ - static protected $datatypes = array( // See DecodeDataType() and $datatype_* flags - 'text-data' => array('implied' => TRUE), - 'text-data-single' => array('implied' => TRUE, 'pie_single' => TRUE), + protected static $datatypes = array( // See DecodeDataType() and $datatype_* flags + 'text-data' => array('implied' => true), + 'text-data-single' => array('implied' => true, 'pie_single' => true), 'data-data' => array(), - 'data-data-error' => array('error_bars' => TRUE), - 'data-data-yx' => array('swapped_xy' => TRUE), - 'text-data-yx' => array('implied' => TRUE, 'swapped_xy' => TRUE), - 'data-data-xyz' => array('yz' => TRUE), - 'data-data-yx-error' => array('swapped_xy' => TRUE, 'error_bars' => TRUE), + 'data-data-error' => array('error_bars' => true), + 'data-data-yx' => array('swapped_xy' => true), + 'text-data-yx' => array('implied' => true, 'swapped_xy' => true), + 'data-data-xyz' => array('yz' => true), + 'data-data-yx-error' => array('swapped_xy' => true, 'error_bars' => true), ); /** Static array of data type aliases => primary name */ - static protected $datatypes_map = array( + protected static $datatypes_map = array( 'text-linear' => 'text-data', 'linear-linear' => 'data-data', 'linear-linear-error' => 'data-data-error', @@ -181,21 +183,21 @@ class PHPlot /** Array of flags for elements that must be drawn at most once */ protected $done = array(); /** Flag: How to handle missing Y values */ - protected $draw_broken_lines = FALSE; + protected $draw_broken_lines = false; /** Flag: Draw data borders, available with some plot types */ protected $draw_data_borders; /** Flag: Draw legend border */ - protected $draw_legend_border = TRUE; + protected $draw_legend_border = true; /** Flag: Draw borders on pie chart segments */ protected $draw_pie_borders; /** Flag: Draw the background of the plot area */ - protected $draw_plot_area_background = FALSE; + protected $draw_plot_area_background = false; /** Flag: Draw X data label lines */ - protected $draw_x_data_label_lines = FALSE; + protected $draw_x_data_label_lines = false; /** Flag: Draw X grid lines? */ protected $draw_x_grid; /** Flag: Draw Y data label lines */ - protected $draw_y_data_label_lines = FALSE; + protected $draw_y_data_label_lines = false; /** Flag: Draw Y grid lines? */ protected $draw_y_grid; /** Color (R,G,B,A) to use for data value labels */ @@ -213,7 +215,7 @@ class PHPlot /** Array of font information (should be protected, but public for possible callback use) */ public $fonts; /** Flag: Draw grid on top of or behind the plot */ - public $grid_at_foreground = FALSE; + public $grid_at_foreground = false; /** Color (R,G,B,A) to use for axes, plot area border, legend border, pie chart lines and text */ protected $grid_color; /** Controls fraction of bar group space used for bar */ @@ -233,7 +235,7 @@ class PHPlot /** Prevent recursion in error message image production */ protected $in_error; /** Flag: don't send headers */ - protected $is_inline = FALSE; + protected $is_inline = false; /** Label format info */ protected $label_format = array('x' => array(), 'xd' => array(), 'y' => array(), 'yd' => array()); /** Pie chart label position factor */ @@ -253,13 +255,13 @@ class PHPlot /** Array holding legend position information */ protected $legend_pos; /** Flag: reverse the order of lines in the legend box, bottom to top */ - protected $legend_reverse_order = FALSE; + protected $legend_reverse_order = false; /** Legend style setting, left or right */ protected $legend_text_align = 'right'; /** Color (R,G,B,A) for the legend text */ protected $legend_text_color; /** Draw color boxes (if false or unset) or shape markers (if true) in the legend */ - protected $legend_use_shapes = FALSE; + protected $legend_use_shapes = false; /** Color (R,G,B,A) for grid lines and X data lines */ protected $light_grid_color; /** Controls inter-line spacing of text */ @@ -269,7 +271,7 @@ class PHPlot /** Plot line width(s) */ protected $line_widths = 1; /** Flag to avoid importing locale info */ - public $locale_override = FALSE; + public $locale_override = false; /** Overall max X value in the data array */ protected $max_x; /** Overall max Y value in the data array */ @@ -347,9 +349,9 @@ class PHPlot /** Aspect ratio for shaded pie charts */ public $pie_diam_factor = 0.5; /** Flag: True to draw pie chart segments clockwise, false or unset for counter-clockwise. */ - protected $pie_direction_cw = FALSE; + protected $pie_direction_cw = false; /** Flag: If true, do not include label sizes when calculating pie size. */ - protected $pie_full_size = FALSE; + protected $pie_full_size = false; /** Source of label text for pie charts (percent, value, label, or index) */ protected $pie_label_source; /** Minimum amount of the plot area that will be reserved for the pie */ @@ -389,10 +391,10 @@ class PHPlot /** Plot area background image tiling mode */ protected $plotbgmode; /** Array of plot type information, indexed by plot type */ - static protected $plots = array( + protected static $plots = array( 'area' => array( 'draw_method' => 'DrawArea', - 'abs_vals' => TRUE, + 'abs_vals' => true, ), 'bars' => array( 'draw_method' => 'DrawBars', @@ -407,12 +409,12 @@ class PHPlot ), 'candlesticks' => array( 'draw_method' => 'DrawOHLC', - 'draw_arg' => array(TRUE, FALSE), // Draw candlesticks, only fill if "closed down" + 'draw_arg' => array(true, false), // Draw candlesticks, only fill if "closed down" 'adjust_type' => 2, // See GetRangeEndAdjust() ), 'candlesticks2' => array( 'draw_method' => 'DrawOHLC', - 'draw_arg' => array(TRUE, TRUE), // Draw candlesticks, fill always + 'draw_arg' => array(true, true), // Draw candlesticks, fill always 'adjust_type' => 2, // See GetRangeEndAdjust() ), 'linepoints' => array( @@ -425,13 +427,13 @@ class PHPlot ), 'ohlc' => array( 'draw_method' => 'DrawOHLC', - 'draw_arg' => array(FALSE), // Don't draw candlesticks + 'draw_arg' => array(false), // Don't draw candlesticks 'adjust_type' => 2, // See GetRangeEndAdjust() ), 'pie' => array( 'draw_method' => 'DrawPieChart', - 'suppress_axes' => TRUE, - 'abs_vals' => TRUE, + 'suppress_axes' => true, + 'abs_vals' => true, ), 'points' => array( 'draw_method' => 'DrawDots', @@ -443,23 +445,23 @@ class PHPlot ), 'squaredarea' => array( 'draw_method' => 'DrawSquaredArea', - 'abs_vals' => TRUE, + 'abs_vals' => true, ), 'stackedarea' => array( 'draw_method' => 'DrawArea', - 'draw_arg' => array(TRUE), // Tells DrawArea to draw stacked area plot - 'sum_vals' => TRUE, - 'abs_vals' => TRUE, + 'draw_arg' => array(true), // Tells DrawArea to draw stacked area plot + 'sum_vals' => true, + 'abs_vals' => true, ), 'stackedbars' => array( 'draw_method' => 'DrawStackedBars', - 'sum_vals' => TRUE, + 'sum_vals' => true, ), 'stackedsquaredarea' => array( 'draw_method' => 'DrawSquaredArea', - 'draw_arg' => array(TRUE), // Tells DrawSquaredArea the data is cumulative - 'sum_vals' => TRUE, - 'abs_vals' => TRUE, + 'draw_arg' => array(true), // Tells DrawSquaredArea the data is cumulative + 'sum_vals' => true, + 'abs_vals' => true, ), 'thinbarline' => array( 'draw_method' => 'DrawThinBarLines', @@ -474,16 +476,16 @@ class PHPlot /** Marker sizes for point plots */ protected $point_sizes = array(6); /** Flag: Automatic PrintImage after DrawGraph? */ - protected $print_image = TRUE; + protected $print_image = true; /** Tuning parameters for plot range calculation */ protected $rangectl = array( 'x' => array( 'adjust_mode' => 'T', // T=adjust to next tick - 'adjust_amount' => NULL, // See GetRangeEndAdjust() + 'adjust_amount' => null, // See GetRangeEndAdjust() 'zero_magnet' => 0.857142, // Value is 6/7 ), 'y' => array( 'adjust_mode' => 'T', // T=adjust to next tick - 'adjust_amount' => NULL, // See GetRangeEndAdjust() + 'adjust_amount' => null, // See GetRangeEndAdjust() 'zero_magnet' => 0.857142, // Value is 6/7 )); /** Area for each bar in a bar chart */ @@ -499,13 +501,13 @@ class PHPlot /** Drop shadow size for pie and bar charts */ protected $shading = 5; /** Skip bottom tick mark */ - protected $skip_bottom_tick = FALSE; + protected $skip_bottom_tick = false; /** Skip left tick mark */ - protected $skip_left_tick = FALSE; + protected $skip_left_tick = false; /** Skip right tick mark */ - protected $skip_right_tick = FALSE; + protected $skip_right_tick = false; /** Skip top tick mark */ - protected $skip_top_tick = FALSE; + protected $skip_top_tick = false; /** MIME boundary sequence used with streaming plots */ protected $stream_boundary; /** Boundary and MIME header, output before each frame in a plot stream */ @@ -513,11 +515,11 @@ class PHPlot /** Name of the GD output function for this image type, used with streaming plots */ protected $stream_output_f; /** Flag: Don't produce an error image on fatal error */ - protected $suppress_error_image = FALSE; + protected $suppress_error_image = false; /** Flag: Don't draw the X axis line */ - protected $suppress_x_axis = FALSE; + protected $suppress_x_axis = false; /** Flag: Don't draw the Y axis line */ - protected $suppress_y_axis = FALSE; + protected $suppress_y_axis = false; /** Color (R,G,B,A) for labels and legend text */ protected $text_color; /** Character to use to group 1000s in formatted numbers */ @@ -526,14 +528,14 @@ class PHPlot protected $tick_color; /** Tuning parameters for tick increment calculation */ protected $tickctl = array( 'x' => array( - 'tick_mode' => NULL, + 'tick_mode' => null, 'min_ticks' => 8, - 'tick_inc_integer' => FALSE, + 'tick_inc_integer' => false, ), 'y' => array( - 'tick_mode' => NULL, + 'tick_mode' => null, 'min_ticks' => 8, - 'tick_inc_integer' => FALSE, + 'tick_inc_integer' => false, )); /** Color (R,G,B,A) to use for tick labels */ protected $ticklabel_color; @@ -552,7 +554,7 @@ class PHPlot /** TrueType font directory */ protected $ttf_path = '.'; /** Default font type, True for TrueType, False for GD */ - protected $use_ttf = FALSE; + protected $use_ttf = false; /** Position of X axis (in world coordinates) */ protected $x_axis_position; /** Device coordinate for the X axis */ @@ -660,7 +662,7 @@ class PHPlot * @param string $output_file Path for output file. Omit, or NULL, or '' to mean no output file * @param string $input_file Path to a file to be used as background. Omit, NULL, or '' for none */ - function __construct($width=600, $height=400, $output_file=NULL, $input_file=NULL) + public function __construct($width = 600, $height = 400, $output_file = null, $input_file = null) { $this->initialize('imagecreate', $width, $height, $output_file, $input_file); } @@ -679,8 +681,9 @@ protected function initialize($imagecreate_function, $width, $height, $output_fi { $this->SetRGBArray('small'); - if (isset($output_file) && $output_file !== '') + if (isset($output_file) && $output_file !== '') { $this->SetOutputFile($output_file); + } if (isset($input_file) && $input_file !== '') { $this->SetInputFile($input_file); @@ -688,8 +691,9 @@ protected function initialize($imagecreate_function, $width, $height, $output_fi $this->image_width = $width; $this->image_height = $height; $this->img = call_user_func($imagecreate_function, $width, $height); - if (!$this->img) + if (!$this->img) { return $this->PrintError(get_class($this) . '(): Could not create image resource.'); + } } $this->SetDefaultStyles(); $this->SetDefaultFonts(); @@ -706,7 +710,7 @@ protected function initialize($imagecreate_function, $width, $height, $output_fi * @return string[] Array of object property names, as required by PHP spec for __sleep() * @since 5.8.0 */ - function __sleep() + public function __sleep() { $this->truecolor = imageistruecolor($this->img); // Remember image type $this->saved_version = self::version; // Remember version of PHPlot, for checking on unserialize @@ -719,14 +723,16 @@ function __sleep() * Recreates the image resource (which is not serializable), after validating the PHPlot version. * @since 5.8.0 */ - function __wakeup() + public function __wakeup() { - if (strcmp($this->saved_version, self::version) != 0) + if (strcmp($this->saved_version, self::version) != 0) { $this->PrintError(get_class($this) . '(): Unserialize version mismatch'); + } $imagecreate_function = $this->truecolor ? 'imagecreatetruecolor' : 'imagecreate'; $this->img = call_user_func($imagecreate_function, $this->image_width, $this->image_height); - if (!$this->img) + if (!$this->img) { $this->PrintError(get_class($this) . '(): Could not create image resource.'); + } unset($this->truecolor, $this->saved_version); } @@ -748,18 +754,18 @@ protected function GetImage($image_filename, &$width, &$height) } else { $image_type = $size[2]; switch ($image_type) { - case IMAGETYPE_GIF: - $img = @ ImageCreateFromGIF ($image_filename); - break; - case IMAGETYPE_PNG: - $img = @ ImageCreateFromPNG ($image_filename); - break; - case IMAGETYPE_JPEG: - $img = @ ImageCreateFromJPEG ($image_filename); - break; - default: - $error = "Unknown image type ($image_type) for image file $image_filename"; - break; + case IMAGETYPE_GIF: + $img = @ ImageCreateFromGIF($image_filename); + break; + case IMAGETYPE_PNG: + $img = @ ImageCreateFromPNG($image_filename); + break; + case IMAGETYPE_JPEG: + $img = @ ImageCreateFromJPEG($image_filename); + break; + default: + $error = "Unknown image type ($image_type) for image file $image_filename"; + break; } } if (empty($error) && !$img) { @@ -781,22 +787,24 @@ protected function GetImage($image_filename, &$width, &$height) * @deprecated Public use discouraged; intended for use by class constructor * @return bool True (False on error if an error handler returns True) */ - function SetInputFile($which_input_file) + public function SetInputFile($which_input_file) { $im = $this->GetImage($which_input_file, $this->image_width, $this->image_height); - if (!$im) - return FALSE; // GetImage already produced an error message. + if (!$im) { + return false; // GetImage already produced an error message. + } // Deallocate any resources previously allocated - if (isset($this->img)) + if (isset($this->img)) { imagedestroy($this->img); + } $this->img = $im; // Do not overwrite the input file with the background color. - $this->done['background'] = TRUE; + $this->done['background'] = true; - return TRUE; + return true; } ///////////////////////////////////////////// @@ -817,7 +825,9 @@ function SetInputFile($which_input_file) */ protected function GetColorIndex(&$color, $default_color_index = 0) { - if (empty($color)) return $default_color_index; + if (empty($color)) { + return $default_color_index; + } list($r, $g, $b, $a) = $color; return imagecolorresolvealpha($this->img, $r, $g, $b, $a); } @@ -837,8 +847,9 @@ protected function GetColorIndexArray($color_array, $max_colors) { $n = min(count($color_array), $max_colors); $result = array(); - for ($i = 0; $i < $n; $i++) + for ($i = 0; $i < $n; $i++) { $result[] = $this->GetColorIndex($color_array[$i]); + } return $result; } @@ -856,8 +867,9 @@ protected function GetDarkColorIndexArray($color_array, $max_colors) { $n = min(count($color_array), $max_colors); $result = array(); - for ($i = 0; $i < $n; $i++) + for ($i = 0; $i < $n; $i++) { $result[] = $this->GetDarkColorIndex($color_array[$i]); + } return $result; } @@ -899,7 +911,7 @@ protected function SetDefaultStyles() $this->SetDataColors(); $this->SetErrorBarColors(); $this->SetDataBorderColors(); - return TRUE; + return true; } /** @@ -908,7 +920,7 @@ protected function SetDefaultStyles() * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetBackgroundColor($which_color) + public function SetBackgroundColor($which_color) { return (bool)($this->bg_color = $this->SetRGBColor($which_color)); } @@ -919,7 +931,7 @@ function SetBackgroundColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetPlotBgColor($which_color) + public function SetPlotBgColor($which_color) { return (bool)($this->plot_bg_color = $this->SetRGBColor($which_color)); } @@ -930,7 +942,7 @@ function SetPlotBgColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetTitleColor($which_color) + public function SetTitleColor($which_color) { return (bool)($this->title_color = $this->SetRGBColor($which_color)); } @@ -942,7 +954,7 @@ function SetTitleColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.2.0 */ - function SetXTitleColor($which_color) + public function SetXTitleColor($which_color) { return (bool)($this->x_title_color = $this->SetRGBColor($which_color)); } @@ -954,7 +966,7 @@ function SetXTitleColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.2.0 */ - function SetYTitleColor($which_color) + public function SetYTitleColor($which_color) { return (bool)($this->y_title_color = $this->SetRGBColor($which_color)); } @@ -965,7 +977,7 @@ function SetYTitleColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetTickColor($which_color) + public function SetTickColor($which_color) { return (bool)($this->tick_color = $this->SetRGBColor($which_color)); } @@ -973,7 +985,7 @@ function SetTickColor($which_color) /** * @deprecated Use SetTitleColor() instead */ - function SetLabelColor($which_color) + public function SetLabelColor($which_color) { return $this->SetTitleColor($which_color); } @@ -984,7 +996,7 @@ function SetLabelColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetTextColor($which_color) + public function SetTextColor($which_color) { return (bool)($this->text_color = $this->SetRGBColor($which_color)); } @@ -996,7 +1008,7 @@ function SetTextColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.7.0 */ - function SetDataLabelColor($which_color) + public function SetDataLabelColor($which_color) { return (bool)($this->datalabel_color = $this->SetRGBColor($which_color)); } @@ -1010,7 +1022,7 @@ function SetDataLabelColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.7.0 */ - function SetDataValueLabelColor($which_color) + public function SetDataValueLabelColor($which_color) { return (bool)($this->dvlabel_color = $this->SetRGBColor($which_color)); } @@ -1022,7 +1034,7 @@ function SetDataValueLabelColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.7.0 */ - function SetPieLabelColor($which_color) + public function SetPieLabelColor($which_color) { return (bool)($this->pielabel_color = $this->SetRGBColor($which_color)); } @@ -1034,7 +1046,7 @@ function SetPieLabelColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function SetPieBorderColor($which_color) + public function SetPieBorderColor($which_color) { return (bool)($this->pieborder_color = $this->SetRGBColor($which_color)); } @@ -1046,7 +1058,7 @@ function SetPieBorderColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 5.7.0 */ - function SetTickLabelColor($which_color) + public function SetTickLabelColor($which_color) { return (bool)($this->ticklabel_color = $this->SetRGBColor($which_color)); } @@ -1057,7 +1069,7 @@ function SetTickLabelColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetLightGridColor($which_color) + public function SetLightGridColor($which_color) { return (bool)($this->light_grid_color = $this->SetRGBColor($which_color)); } @@ -1072,7 +1084,7 @@ function SetLightGridColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetGridColor($which_color) + public function SetGridColor($which_color) { return (bool)($this->grid_color = $this->SetRGBColor($which_color)); } @@ -1083,7 +1095,7 @@ function SetGridColor($which_color) * @param string|int[] $which_color Color name or spec (#rrggbb, (r,g,b) array, etc) * @return bool True (False on error if an error handler returns True) */ - function SetImageBorderColor($which_color) + public function SetImageBorderColor($which_color) { return (bool)($this->i_border = $this->SetRGBColor($which_color)); } @@ -1094,10 +1106,10 @@ function SetImageBorderColor($which_color) * @param string|int[]|null $which_color Color to make transparent; empty|omit|NULL to reset to none * @return bool True (False on error if an error handler returns True) */ - function SetTransparentColor($which_color = NULL) + public function SetTransparentColor($which_color = null) { - $this->transparent_color = empty($which_color) ? NULL : $this->SetRGBColor($which_color); - return ($this->transparent_color !== FALSE); // True unless SetRGBColor() returned an error + $this->transparent_color = empty($which_color) ? null : $this->SetRGBColor($which_color); + return ($this->transparent_color !== false); // True unless SetRGBColor() returned an error } /** @@ -1107,7 +1119,7 @@ function SetTransparentColor($which_color = NULL) * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function SetLegendBgColor($which_color) + public function SetLegendBgColor($which_color) { return (bool)($this->legend_bg_color = $this->SetRGBColor($which_color)); } @@ -1119,7 +1131,7 @@ function SetLegendBgColor($which_color) * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function SetLegendTextColor($which_color) + public function SetLegendTextColor($which_color) { return (bool)($this->legend_text_color = $this->SetRGBColor($which_color)); } @@ -1134,7 +1146,7 @@ function SetLegendTextColor($which_color) * @param array|string $which_color_array Color map array (name=>(R,G,B[,A]), or keyword small | large * @return bool True always */ - function SetRGBArray($which_color_array) + public function SetRGBArray($which_color_array) { if (is_array($which_color_array)) { // User defined array $this->rgb_array = $which_color_array; @@ -1177,7 +1189,7 @@ function SetRGBArray($which_color_array) 'azure1' => array(240, 255, 255), 'aquamarine1' => array(127, 255, 212) ); - } elseif ($which_color_array == 'large') { // Large color array + } elseif ($which_color_array == 'large') { // Large color array if (!@include('rgb.inc.php')) { return $this->PrintError("SetRGBArray(): Large color map could not be loaded " . "from 'rgb.inc.php'."); @@ -1187,7 +1199,7 @@ function SetRGBArray($which_color_array) return $this->PrintError("SetRGBArray(): Invalid color map selection"); } - return TRUE; + return true; } /** @@ -1204,38 +1216,43 @@ function SetRGBArray($which_color_array) * @return int[] Color component values as array (red, green, blue, alpha) * @deprecated Public use discouraged; intended for class internal use */ - function SetRGBColor($color_asked, $alpha = 0) + public function SetRGBColor($color_asked, $alpha = 0) { if (empty($color_asked)) { $ret_val = array(0, 0, 0); - - } elseif (is_array($color_asked) && (($n = count($color_asked)) == 3 || $n == 4) ) { + } elseif (is_array($color_asked) && (($n = count($color_asked)) == 3 || $n == 4)) { // Already an array of 3 or 4 elements: $ret_val = $color_asked; - - } elseif (preg_match('/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i', - $color_asked, $ss)) { + } elseif ( + preg_match( + '/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i', + $color_asked, + $ss + ) + ) { // #RRGGBB or #RRGGBBAA notation: $ret_val = array(hexdec($ss[1]), hexdec($ss[2]), hexdec($ss[3])); - if (isset($ss[4])) $ret_val[] = hexdec($ss[4]); - + if (isset($ss[4])) { + $ret_val[] = hexdec($ss[4]); + } } elseif (isset($this->rgb_array[$color_asked])) { // Color by name: $ret_val = $this->rgb_array[$color_asked]; - - } elseif (preg_match('/(.+):([\d]+)$/', $color_asked, $ss) - && isset($this->rgb_array[$ss[1]])) { + } elseif ( + preg_match('/(.+):([\d]+)$/', $color_asked, $ss) + && isset($this->rgb_array[$ss[1]]) + ) { // Color by name with ":alpha" suffix, alpha is a decimal number: $ret_val = $this->rgb_array[$ss[1]]; $ret_val[3] = (int)$ss[2]; - } else { return $this->PrintError("SetRGBColor(): Color '$color_asked' is not valid."); } // Append alpha if not already provided for: - if (count($ret_val) == 3) + if (count($ret_val) == 3) { $ret_val[] = $alpha; + } return $ret_val; } @@ -1256,7 +1273,7 @@ function SetRGBColor($color_asked, $alpha = 0) * @param int $alpha Default alpha to apply to all data colors that do not have an alpha value * @return bool True (False on error if an error handler returns True) */ - function SetDataColors($which_data = NULL, $which_border = NULL, $alpha = NULL) + public function SetDataColors($which_data = null, $which_border = null, $alpha = null) { if (is_array($which_data)) { $colors = $which_data; // Use supplied array @@ -1276,18 +1293,21 @@ function SetDataColors($which_data = NULL, $which_border = NULL, $alpha = NULL) } } // No need to reparse the colors or anything else. - return TRUE; + return true; } - if (!isset($alpha)) + if (!isset($alpha)) { $alpha = 0; // Actual default is opaque colors. + } // Check each color and convert to array (r,g,b,a) form. // Use the $alpha argument as a default for the alpha value of each color. $this->data_colors = array(); foreach ($colors as $color) { $color_array = $this->SetRGBColor($color, $alpha); - if (!$color_array) return FALSE; // SetRGBColor already did an error message. + if (!$color_array) { + return false; // SetRGBColor already did an error message. + } $this->data_colors[] = $color_array; } @@ -1307,7 +1327,7 @@ function SetDataColors($which_data = NULL, $which_border = NULL, $alpha = NULL) * @param array|string $which_br Array of color specifications, or one color, or empty * @return bool True (False on error if an error handler returns True) */ - function SetDataBorderColors($which_br = NULL) + public function SetDataBorderColors($which_br = null) { if (is_array($which_br)) { $colors = $which_br; // Use supplied array @@ -1316,17 +1336,19 @@ function SetDataBorderColors($which_br = NULL) } elseif (empty($this->data_border_colors) || !is_null($which_br)) { $colors = array('black'); // Use default } else { - return TRUE; // Do nothing: which_br is NULL or missing and a color array is already set. + return true; // Do nothing: which_br is NULL or missing and a color array is already set. } // Check each color and convert to array (r,g,b,a) form. $this->data_border_colors = array(); foreach ($colors as $color) { $color_array = $this->SetRGBColor($color); - if (!$color_array) return FALSE; // SetRGBColor already did an error message. + if (!$color_array) { + return false; // SetRGBColor already did an error message. + } $this->data_border_colors[] = $color_array; } - return TRUE; + return true; } /** @@ -1339,7 +1361,7 @@ function SetDataBorderColors($which_br = NULL) * @param array|string $which_err Array of color specifications, or one color, or empty * @return bool True (False on error if an error handler returns True) */ - function SetErrorBarColors($which_err = NULL) + public function SetErrorBarColors($which_err = null) { if (is_array($which_err)) { $colors = $which_err; // Use supplied array @@ -1348,17 +1370,19 @@ function SetErrorBarColors($which_err = NULL) } elseif (empty($this->error_bar_colors) || !is_null($which_err)) { $colors = $this->default_colors; // Use default color array } else { - return TRUE; // Do nothing: which_err is NULL or missing and a color array is already set. + return true; // Do nothing: which_err is NULL or missing and a color array is already set. } // Check each color and convert to array (r,g,b,a) form. $this->error_bar_colors = array(); foreach ($colors as $color) { $color_array = $this->SetRGBColor($color); - if (!$color_array) return FALSE; // SetRGBColor already did an error message. + if (!$color_array) { + return false; // SetRGBColor already did an error message. + } $this->error_bar_colors[] = $color_array; } - return TRUE; + return true; } /** @@ -1374,14 +1398,14 @@ function SetErrorBarColors($which_err = NULL) * @param string $which_style Dashed line specification, in the form -... * @return bool True (False on error if an error handler returns True) */ - function SetDefaultDashedStyle($which_style) + public function SetDefaultDashedStyle($which_style) { // Validate the argument as "(number)-(number)-..." with at least 2 numbers: if (!preg_match('/^\d+-\d+(-\d+)*$/', $which_style)) { return $this->PrintError("SetDefaultDashedStyle(): Wrong parameter '$which_style'."); } $result = ''; - $use_color = TRUE; + $use_color = true; $transparent = ' ' . IMG_COLOR_TRANSPARENT; // Expand the dashed line style specifier: foreach (explode('-', $which_style) as $n) { @@ -1389,7 +1413,7 @@ function SetDefaultDashedStyle($which_style) $use_color = !$use_color; // Alternate color and transparent } $this->default_dashed_style = ltrim($result); - return TRUE; + return true; } /** @@ -1405,10 +1429,11 @@ function SetDefaultDashedStyle($which_style) * @param bool $use_style TRUE or omit for dashed lines, FALSE for solid lines * @return int A GD color index for drawing: either $which_ndxcol or IMG_COLOR_STYLED */ - protected function SetDashedStyle($which_ndxcol, $use_style = TRUE) + protected function SetDashedStyle($which_ndxcol, $use_style = true) { - if (!$use_style) + if (!$use_style) { return $which_ndxcol; // Styles are off; use original color for drawing + } // Set the line style, substituting the specified color for the # marker: imagesetstyle($this->img, explode(' ', str_replace('#', $which_ndxcol, $this->default_dashed_style))); return IMG_COLOR_STYLED; // Use this value as the color for drawing @@ -1420,14 +1445,14 @@ protected function SetDashedStyle($which_ndxcol, $use_style = TRUE) * @param int[]|int $which_lw Array of line widths in pixels, or a single value to use for all data sets * @return bool True always */ - function SetLineWidths($which_lw=NULL) + public function SetLineWidths($which_lw = null) { if (is_array($which_lw)) { $this->line_widths = $which_lw; // Use provided array } elseif (!is_null($which_lw)) { $this->line_widths = array($which_lw); // Convert value to array } - return TRUE; + return true; } /** @@ -1436,14 +1461,14 @@ function SetLineWidths($which_lw=NULL) * @param string[]|string $which_ls Array or single keyword: solid | dashed | none * @return bool True always */ - function SetLineStyles($which_ls=NULL) + public function SetLineStyles($which_ls = null) { if (is_array($which_ls)) { $this->line_styles = $which_ls; // Use provided array } elseif (!is_null($which_ls)) { $this->line_styles = ($which_ls) ? array($which_ls) : array('solid'); } - return TRUE; + return true; } ///////////////////////////////////////////// @@ -1456,10 +1481,10 @@ function SetLineStyles($which_ls=NULL) * @param int $which_spc Text line spacing factor (pixels for GD text, scale control for TTF text) * @return bool True always */ - function SetLineSpacing($which_spc) + public function SetLineSpacing($which_spc) { $this->line_spacing = $which_spc; - return TRUE; + return true; } /** @@ -1468,7 +1493,7 @@ function SetLineSpacing($which_spc) * @param bool $which_ttf True to default to TrueType fonts, False to default to GD (fixed) fonts * @return bool True (False on error if an error handler returns True) */ - function SetUseTTF($which_ttf) + public function SetUseTTF($which_ttf) { $this->use_ttf = $which_ttf; return $this->SetDefaultFonts(); @@ -1480,13 +1505,13 @@ function SetUseTTF($which_ttf) * @param string $which_path Full path to a directory containing TrueType fonts * @return bool True (False on error if an error handler returns True) */ - function SetTTFPath($which_path) + public function SetTTFPath($which_path) { if (!is_dir($which_path) || !is_readable($which_path)) { return $this->PrintError("SetTTFPath(): $which_path is not a valid path."); } $this->ttf_path = $which_path; - return TRUE; + return true; } /** @@ -1495,10 +1520,10 @@ function SetTTFPath($which_path) * @param string $which_font Font filename or path; omit or NULL to use a default font * @return bool True (False on error if an error handler returns True) */ - function SetDefaultTTFont($which_font = NULL) + public function SetDefaultTTFont($which_font = null) { $this->default_ttfont = $which_font; - return $this->SetUseTTF(TRUE); + return $this->SetUseTTF(true); } /** @@ -1524,11 +1549,12 @@ protected function GetDefaultTTFont() ); foreach ($fonts as $font) { // First try the font name alone, to see if GD can find and load it. - if (@imagettfbbox(10, 0, $font, "1") !== False) + if (@imagettfbbox(10, 0, $font, "1") !== false) { break; + } // If the font wasn't found, try it with the default TTF path in front. $font_with_path = $this->ttf_path . DIRECTORY_SEPARATOR . $font; - if (@imagettfbbox(10, 0, $font_with_path, "1") !== False) { + if (@imagettfbbox(10, 0, $font_with_path, "1") !== false) { $font = $font_with_path; break; } @@ -1577,24 +1603,28 @@ protected function SetDefaultFonts() * @return bool True (False on error if an error handler returns True) * @since 5.0.6 */ - function SetFontGD($which_elem, $which_font, $which_spacing = NULL) + public function SetFontGD($which_elem, $which_font, $which_spacing = null) { if ($which_font < 1 || 5 < $which_font) { return $this->PrintError(__FUNCTION__ . ': Font size must be 1, 2, 3, 4 or 5'); } - if (!$this->CheckOption($which_elem, - 'generic, title, legend, x_label, y_label, x_title, y_title', - __FUNCTION__)) { - return FALSE; + if ( + !$this->CheckOption( + $which_elem, + 'generic, title, legend, x_label, y_label, x_title, y_title', + __FUNCTION__ + ) + ) { + return false; } // Store the font parameters: name/size, char cell height and width. - $this->fonts[$which_elem] = array('ttf' => FALSE, + $this->fonts[$which_elem] = array('ttf' => false, 'font' => $which_font, 'height' => ImageFontHeight($which_font), 'width' => ImageFontWidth($which_font), 'line_spacing' => $which_spacing); - return TRUE; + return true; } /** @@ -1609,25 +1639,30 @@ function SetFontGD($which_elem, $which_font, $which_spacing = NULL) * @return bool True (False on error if an error handler returns True) * @since 5.0.6 */ - function SetFontTTF($which_elem, $which_font, $which_size = 12, $which_spacing = NULL) + public function SetFontTTF($which_elem, $which_font, $which_size = 12, $which_spacing = null) { - if (!$this->CheckOption($which_elem, - 'generic, title, legend, x_label, y_label, x_title, y_title', - __FUNCTION__)) { - return FALSE; + if ( + !$this->CheckOption( + $which_elem, + 'generic, title, legend, x_label, y_label, x_title, y_title', + __FUNCTION__ + ) + ) { + return false; } // Empty font name means use the default font. - if (empty($which_font)) + if (empty($which_font)) { $which_font = $this->GetDefaultTTFont(); + } $path = $which_font; // First try the font name directly, if not then try with path. // Use GD imagettfbbox() to determine if this is a valid font. // The return $bbox is used below, if valid. - if (($bbox = @imagettfbbox($which_size, 0, $path, "E")) === False) { + if (($bbox = @imagettfbbox($which_size, 0, $path, "E")) === false) { $path = $this->ttf_path . DIRECTORY_SEPARATOR . $which_font; - if (($bbox = @imagettfbbox($which_size, 0, $path, "E")) === False) { + if (($bbox = @imagettfbbox($which_size, 0, $path, "E")) === false) { return $this->PrintError(__FUNCTION__ . ": Can't find TrueType font $which_font"); } } @@ -1645,14 +1680,14 @@ function SetFontTTF($which_elem, $which_font, $which_size = 12, $which_spacing = $spacing = $bbox[1] - $bbox[5] - 2 * $height; // Store the font parameters: - $this->fonts[$which_elem] = array('ttf' => TRUE, + $this->fonts[$which_elem] = array('ttf' => true, 'font' => $path, 'size' => $which_size, 'height' => $height, 'width' => $width, 'spacing' => $spacing, 'line_spacing' => $which_spacing); - return TRUE; + return true; } /** @@ -1669,10 +1704,11 @@ function SetFontTTF($which_elem, $which_font, $which_size = 12, $which_spacing = * @param int $line_spacing Optional line spacing adjustment factor * @return bool True (False on error if an error handler returns True) */ - function SetFont($which_elem, $which_font, $which_size = 12, $line_spacing = NULL) + public function SetFont($which_elem, $which_font, $which_size = 12, $line_spacing = null) { - if ($this->use_ttf) + if ($this->use_ttf) { return $this->SetFontTTF($which_elem, $which_font, $which_size, $line_spacing); + } return $this->SetFontGD($which_elem, $which_font, $line_spacing); } @@ -1686,10 +1722,11 @@ function SetFont($which_elem, $which_font, $which_size = 12, $line_spacing = NUL protected function GetLineSpacing($font) { // Use the per-font line spacing preference, if set, else the global value: - if (isset($font['line_spacing'])) + if (isset($font['line_spacing'])) { $line_spacing = $font['line_spacing']; - else + } else { $line_spacing = $this->line_spacing; + } // For GD fonts, that is the spacing in pixels. // For TTF, adjust based on the 'natural' font spacing (see SetFontTTF): @@ -1795,7 +1832,9 @@ protected function ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, foreach (explode("\n", $text) as $each_line) { $lines[] = $line = trim($each_line); $line_lens[] = $line_len = strlen($line); - if ($line_len > $longest) $longest = $line_len; + if ($line_len > $longest) { + $longest = $line_len; + } } $n_lines = count($lines); @@ -1805,7 +1844,9 @@ protected function ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, $total_height = $n_lines * $font_height + ($n_lines - 1) * $line_spacing; if (!$draw_it) { - if ($angle < 45) return array($total_width, $total_height); + if ($angle < 45) { + return array($total_width, $total_height); + } return array($total_height, $total_width); } @@ -1822,16 +1863,19 @@ protected function ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, $draw_func = 'ImageStringUp'; // Rotation matrix "R" for 90 degrees (with Y pointing down): - $r00 = 0; $r01 = 1; - $r10 = -1; $r11 = 0; - + $r00 = 0; + $r01 = 1; + $r10 = -1; + $r11 = 0; } else { // Horizontal text (0 degrees): $draw_func = 'ImageString'; // Rotation matrix "R" for 0 degrees: - $r00 = 1; $r01 = 0; - $r10 = 0; $r11 = 1; + $r00 = 1; + $r01 = 0; + $r10 = 0; + $r11 = 1; } // Adjust for vertical alignment (horizontal text) or horizontal alignment (vertical text): @@ -1856,7 +1900,6 @@ protected function ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, } for ($i = 0; $i < $n_lines; $i++) { - // Adjust for alignment of this line within the text block: $factor = (int)($line_lens[$i] * $font_width * $h_factor); $x = $xpos - $r00 * $factor; @@ -1869,7 +1912,7 @@ protected function ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, $xpos += $r01 * $interline_step; $ypos += $r11 * $interline_step; } - return TRUE; + return true; } /** @@ -1913,7 +1956,9 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text $lines[] = $line = trim($each_line); $bbox = ImageTTFBBox($font_size, 0, $font_file, $line); $line_widths[] = $width = $bbox[2] - $bbox[0]; - if ($width > $total_width) $total_width = $width; + if ($width > $total_width) { + $total_width = $width; + } $lastline_descent = 1 + $bbox[1]; } $n_lines = count($lines); @@ -1924,8 +1969,10 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text $theta = deg2rad($angle); $cos_t = cos($theta); $sin_t = sin($theta); - $r00 = $cos_t; $r01 = $sin_t; - $r10 = -$sin_t; $r11 = $cos_t; + $r00 = $cos_t; + $r01 = $sin_t; + $r10 = -$sin_t; + $r11 = $cos_t; // Make a bounding box of the right size, with upper left corner at (0,0). // By convention, the point order is: LL, LR, UR, UL. @@ -1940,16 +1987,19 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text } else { $b[1] = $total_height + $lastline_descent; } - $b[2] = $total_width; $b[3] = $b[1]; - $b[4] = $total_width; $b[5] = 0; - $b[6] = 0; $b[7] = 0; + $b[2] = $total_width; + $b[3] = $b[1]; + $b[4] = $total_width; + $b[5] = 0; + $b[6] = 0; + $b[7] = 0; // Rotate the bounding box, then offset to the reference point: for ($i = 0; $i < 8; $i += 2) { $x_b = $b[$i]; - $y_b = $b[$i+1]; + $y_b = $b[$i + 1]; $c[$i] = $x + $r00 * $x_b + $r01 * $y_b; - $c[$i+1] = $y + $r10 * $x_b + $r11 * $y_b; + $c[$i + 1] = $y + $r10 * $x_b + $r11 * $y_b; } // Get an orthogonal (aligned with X and Y axes) bounding box around it, by @@ -1958,11 +2008,17 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text $bbox_ref_y = $bbox_max_y = $c[1]; for ($i = 2; $i < 8; $i += 2) { $x_b = $c[$i]; - if ($x_b < $bbox_ref_x) $bbox_ref_x = $x_b; - elseif ($bbox_max_x < $x_b) $bbox_max_x = $x_b; - $y_b = $c[$i+1]; - if ($y_b < $bbox_ref_y) $bbox_ref_y = $y_b; - elseif ($bbox_max_y < $y_b) $bbox_max_y = $y_b; + if ($x_b < $bbox_ref_x) { + $bbox_ref_x = $x_b; + } elseif ($bbox_max_x < $x_b) { + $bbox_max_x = $x_b; + } + $y_b = $c[$i + 1]; + if ($y_b < $bbox_ref_y) { + $bbox_ref_y = $y_b; + } elseif ($bbox_max_y < $y_b) { + $bbox_max_y = $y_b; + } } $bbox_width = $bbox_max_x - $bbox_ref_x; $bbox_height = $bbox_max_y - $bbox_ref_y; @@ -1999,18 +2055,22 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text if ($sin_t > 0) { if ($cos_t > 0) { // Quadrant: 0d - 90d: - $px = $qx; $py = $qy - $total_width * $sin_t; + $px = $qx; + $py = $qy - $total_width * $sin_t; } else { // Quadrant: 90d - 180d: - $px = $qx + $total_width * $cos_t; $py = $qy - $bbox_height; + $px = $qx + $total_width * $cos_t; + $py = $qy - $bbox_height; } } else { if ($cos_t < 0) { // Quadrant: 180d - 270d: - $px = $qx - $bbox_width; $py = $qy + $total_height * $cos_t; + $px = $qx - $bbox_width; + $py = $qy + $total_height * $cos_t; } else { // Quadrant: 270d - 360d: - $px = $qx + $total_height * $sin_t; $py = $qy; + $px = $qx + $total_height * $sin_t; + $py = $qy; } } $this->DoCallback('debug_textbox', $px, $py, $bbox_width, $bbox_height); @@ -2025,17 +2085,22 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text // 135 < angle <= 225 reversed h_align // 225 < angle <= 315 v_align if ($cos_t >= $sin_t) { - if ($cos_t >= -$sin_t) $line_align_factor = $h_factor; - else $line_align_factor = $v_factor; + if ($cos_t >= -$sin_t) { + $line_align_factor = $h_factor; + } else { + $line_align_factor = $v_factor; + } } else { - if ($cos_t >= -$sin_t) $line_align_factor = 1-$v_factor; - else $line_align_factor = 1-$h_factor; + if ($cos_t >= -$sin_t) { + $line_align_factor = 1 - $v_factor; + } else { + $line_align_factor = 1 - $h_factor; + } } // Now we have the start point, spacing and in-line alignment factor. // We are finally ready to start drawing the text, line by line. for ($i = 0; $i < $n_lines; $i++) { - // For drawing TTF text, the reference point is the left edge of the // text baseline (not the lower left corner of the bounding box). // The following also adjusts for horizontal (relative to @@ -2048,14 +2113,14 @@ protected function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text $ry = $qy + $r10 * $width_factor + $r11 * $font_height; // Finally, draw the text: - ImageTTFText($this->img, $font_size, $angle, $rx, $ry, $color, $font_file, $lines[$i]); + ImageTTFText($this->img, $font_size, $angle, (int)$rx, (int)$ry, (int)$color, $font_file, $lines[$i]); // Step to position of next line. // This is a rotation of (x=0,y=height+line_spacing) by $angle: $qx += $r01 * $interline_step; $qy += $r11 * $interline_step; } - return TRUE; + return true; } /** @@ -2080,27 +2145,50 @@ protected function ProcessText($draw_it, $font_id, $angle, $x, $y, $color, $text { // Empty text case: if ($text === '') { - if ($draw_it) return TRUE; + if ($draw_it) { + return true; + } return array(0, 0); } // Calculate width and height offset factors using the alignment args: - if ($valign == 'top') $v_factor = 0; - elseif ($valign == 'center') $v_factor = 0.5; - else $v_factor = 1.0; // 'bottom' - if ($halign == 'left') $h_factor = 0; - elseif ($halign == 'center') $h_factor = 0.5; - else $h_factor = 1.0; // 'right' + if ($valign == 'top') { + $v_factor = 0; + } elseif ($valign == 'center') { + $v_factor = 0.5; + } else { + $v_factor = 1.0; // 'bottom' + } + if ($halign == 'left') { + $h_factor = 0; + } elseif ($halign == 'center') { + $h_factor = 0.5; + } else { + $h_factor = 1.0; // 'right' + } // Preferred usage for $font_id is a text element name (see SetFont()), but for compatibility // accept a font array too. For external (callback) usage, support a default font. - if (is_array($font_id)) $font = $font_id; // Use supplied array; deprecated - elseif (!empty($font_id) && isset($this->fonts[$font_id])) $font = $this->fonts[$font_id]; - else $font = $this->fonts['generic']; // Fallback default, or font_id is empty. + if (is_array($font_id)) { + $font = $font_id; // Use supplied array; deprecated + } elseif (!empty($font_id) && isset($this->fonts[$font_id])) { + $font = $this->fonts[$font_id]; + } else { + $font = $this->fonts['generic']; // Fallback default, or font_id is empty. + } if ($font['ttf']) { - return $this->ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text, - $h_factor, $v_factor); + return $this->ProcessTextTTF( + $draw_it, + $font, + $angle, + $x, + $y, + $color, + $text, + $h_factor, + $v_factor + ); } return $this->ProcessTextGD($draw_it, $font, $angle, $x, $y, $color, $text, $h_factor, $v_factor); } @@ -2121,12 +2209,27 @@ protected function ProcessText($draw_it, $font_id, $angle, $x, $y, $color, $text * @param string $which_valign Vertical alignment (relative to the image): top | center | bottom * @return bool True always */ - function DrawText($which_font, $which_angle, $which_xpos, $which_ypos, $which_color, $which_text, - $which_halign = 'left', $which_valign = 'bottom') - { - return $this->ProcessText(TRUE, - $which_font, $which_angle, $which_xpos, $which_ypos, - $which_color, $which_text, $which_halign, $which_valign); + public function DrawText( + $which_font, + $which_angle, + $which_xpos, + $which_ypos, + $which_color, + $which_text, + $which_halign = 'left', + $which_valign = 'bottom' + ) { + return $this->ProcessText( + true, + $which_font, + $which_angle, + $which_xpos, + $which_ypos, + $which_color, + $which_text, + $which_halign, + $which_valign + ); } /** @@ -2144,11 +2247,20 @@ function DrawText($which_font, $which_angle, $which_xpos, $which_ypos, $which_co * @param string $which_text The text to calculate size of * @return int[] A two element array ($width, $height) of the text */ - function SizeText($which_font, $which_angle, $which_text) + public function SizeText($which_font, $which_angle, $which_text) { // Color, position, and alignment are not used when calculating the size. - return $this->ProcessText(FALSE, - $which_font, $which_angle, 0, 0, 1, $which_text, '', ''); + return $this->ProcessText( + false, + $which_font, + $which_angle, + 0, + 0, + 1, + $which_text, + '', + '' + ); } ///////////////////////////////////////////// @@ -2161,29 +2273,31 @@ function SizeText($which_font, $which_angle, $which_text) * @param string $format The format to use: jpg | png | gif | wbmp * @return bool True (False on error if an error handler returns True) */ - function SetFileFormat($format) + public function SetFileFormat($format) { $asked = $this->CheckOption($format, 'jpg, png, gif, wbmp', __FUNCTION__); - if (!$asked) return FALSE; + if (!$asked) { + return false; + } switch ($asked) { - case 'jpg': - $format_test = IMG_JPG; - break; - case 'png': - $format_test = IMG_PNG; - break; - case 'gif': - $format_test = IMG_GIF; - break; - case 'wbmp': - $format_test = IMG_WBMP; - break; + case 'jpg': + $format_test = IMG_JPG; + break; + case 'png': + $format_test = IMG_PNG; + break; + case 'gif': + $format_test = IMG_GIF; + break; + case 'wbmp': + $format_test = IMG_WBMP; + break; } if (!(imagetypes() & $format_test)) { return $this->PrintError("SetFileFormat(): File format '$format' not supported"); } $this->file_format = $asked; - return TRUE; + return true; } /** @@ -2193,11 +2307,11 @@ function SetFileFormat($format) * @param string $mode Optional method for the background: centeredtile | tile | scale * @return bool True (False on error if an error handler returns True) */ - function SetBgImage($input_file, $mode='centeredtile') + public function SetBgImage($input_file, $mode = 'centeredtile') { $this->bgmode = $this->CheckOption($mode, 'tile, centeredtile, scale', __FUNCTION__); $this->bgimg = $input_file; - return (boolean)$this->bgmode; + return (bool)$this->bgmode; } /** @@ -2207,11 +2321,11 @@ function SetBgImage($input_file, $mode='centeredtile') * @param string $mode Optional method for the background: centeredtile | tile | scale * @return bool True (False on error if an error handler returns True) */ - function SetPlotAreaBgImage($input_file, $mode='tile') + public function SetPlotAreaBgImage($input_file, $mode = 'tile') { $this->plotbgmode = $this->CheckOption($mode, 'tile, centeredtile, scale', __FUNCTION__); $this->plotbgimg = $input_file; - return (boolean)$this->plotbgmode; + return (bool)$this->plotbgmode; } /** @@ -2222,13 +2336,14 @@ function SetPlotAreaBgImage($input_file, $mode='tile') * @param string $which_output_file Pathname of the file to write the image data into * @return bool True always */ - function SetOutputFile($which_output_file) + public function SetOutputFile($which_output_file) { - if (isset($which_output_file) && $which_output_file !== '') + if (isset($which_output_file) && $which_output_file !== '') { $this->output_file = $which_output_file; - else - $this->output_file = NULL; - return TRUE; + } else { + $this->output_file = null; + } + return true; } /** @@ -2239,10 +2354,10 @@ function SetOutputFile($which_output_file) * @param bool $which_ii True to suppress HTTP headers, False to include the headers * @return bool True always */ - function SetIsInline($which_ii) + public function SetIsInline($which_ii) { $this->is_inline = (bool)$which_ii; - return TRUE; + return true; } /** @@ -2256,27 +2371,27 @@ function SetIsInline($which_ii) protected function GetImageType(&$mime_type, &$output_f) { switch ($this->file_format) { - case 'png': - $mime_type = 'image/png'; - $output_f = 'imagepng'; - break; - case 'jpg': - $mime_type = 'image/jpeg'; - $output_f = 'imagejpeg'; - break; - case 'gif': - $mime_type = 'image/gif'; - $output_f = 'imagegif'; - break; - case 'wbmp': - $mime_type = 'image/wbmp'; - $output_f = 'imagewbmp'; - break; - default: - // Report the error on PrintImage, because that is where this code used to be. - return $this->PrintError('PrintImage(): Please select an image type!'); - } - return TRUE; + case 'png': + $mime_type = 'image/png'; + $output_f = 'imagepng'; + break; + case 'jpg': + $mime_type = 'image/jpeg'; + $output_f = 'imagejpeg'; + break; + case 'gif': + $mime_type = 'image/gif'; + $output_f = 'imagegif'; + break; + case 'wbmp': + $mime_type = 'image/wbmp'; + $output_f = 'imagewbmp'; + break; + default: + // Report the error on PrintImage, because that is where this code used to be. + return $this->PrintError('PrintImage(): Please select an image type!'); + } + return true; } /** @@ -2295,23 +2410,26 @@ protected function DisableCaching() header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT'); header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Pragma: no-cache'); - return TRUE; + return true; } /** * Outputs the generated image to standard output or to a file * - * This is automatically called by DrawGraph(), unless SetPrintImage(False) was used. + * Automatically called by DrawGraph(), unless SetPrintImage(False) was used. * * @return bool True always */ - function PrintImage() + public function PrintImage() { - if (!$this->browser_cache && !$this->is_inline) + if (!$this->browser_cache && !$this->is_inline) { $this->DisableCaching(); + } // Get MIME type and GD output function name: - if (!$this->GetImageType($mime_type, $output_f)) return FALSE; + if (!$this->GetImageType($mime_type, $output_f)) { + return false; + } if (!$this->is_inline) { Header("Content-type: $mime_type"); @@ -2321,7 +2439,7 @@ function PrintImage() } else { $output_f($this->img); } - return TRUE; + return true; } /** @@ -2331,19 +2449,21 @@ function PrintImage() * @return string Encoded image data (False on error if error handler returns True) * @since 5.5.0 */ - function EncodeImage($encoding = 'dataurl') + public function EncodeImage($encoding = 'dataurl') { $enc = $this->CheckOption($encoding, 'dataurl, raw, base64', __FUNCTION__); - if (!$enc || !$this->GetImageType($mime_type, $output_f)) return FALSE; + if (!$enc || !$this->GetImageType($mime_type, $output_f)) { + return false; + } ob_start(); $output_f($this->img); switch ($enc) { - case 'raw': - return ob_get_clean(); - case 'base64': - return base64_encode(ob_get_clean()); - default: // 'dataurl', checked above. - return "data:$mime_type;base64,\n" . chunk_split(base64_encode(ob_get_clean())); + case 'raw': + return ob_get_clean(); + case 'base64': + return base64_encode(ob_get_clean()); + default: // 'dataurl', checked above. + return "data:$mime_type;base64,\n" . chunk_split(base64_encode(ob_get_clean())); } } @@ -2361,44 +2481,56 @@ function EncodeImage($encoding = 'dataurl') * @return bool True always * @since 5.7.0 */ - function DrawMessage($text, $options = NULL) + public function DrawMessage($text, $options = null) { // Merge options with defaults, and set as local variables: - extract( array_merge( array( - 'draw_background' => FALSE, // Draw image background per SetBgImage(), SetBackgroundColor() - 'draw_border' => FALSE, // Draw image border as set with SetBorder*() - 'force_print' => TRUE, // Ignore SetPrintImage() setting and always output - 'reset_font' => TRUE, // Reset fonts (to avoid possible TTF error) + extract(array_merge(array( + 'draw_background' => false, // Draw image background per SetBgImage(), SetBackgroundColor() + 'draw_border' => false, // Draw image border as set with SetBorder*() + 'force_print' => true, // Ignore SetPrintImage() setting and always output + 'reset_font' => true, // Reset fonts (to avoid possible TTF error) 'text_color' => '', // If not empty, text color specification - 'text_wrap' => TRUE, // Wrap the message text with wordwrap() + 'text_wrap' => true, // Wrap the message text with wordwrap() 'wrap_width' => 75, // Width in characters for wordwrap() ), (array)$options)); // Do colors, background, and border: - if ($draw_border && !isset($this->ndx_i_border) || $draw_background && !isset($this->ndx_bg_color)) + if ($draw_border && !isset($this->ndx_i_border) || $draw_background && !isset($this->ndx_bg_color)) { $this->SetBgColorIndexes(); + } if ($draw_background) { // User-specified background - $this->DrawBackground(TRUE); // TRUE means force overwriting of background + $this->DrawBackground(true); // TRUE means force overwriting of background } else { // Default to plain white background $bgcolor = imagecolorresolve($this->img, 255, 255, 255); - ImageFilledRectangle($this->img, 0, 0, $this->image_width, $this->image_height, $bgcolor); + ImageFilledRectangle($this->img, 0, 0, intval($this->image_width), intval($this->image_height), intval($bgcolor)); + } + if ($draw_border) { + $this->DrawImageBorder(true); + } + if (empty($text_color)) { + $rgb = array(0, 0, 0); + } else { + $rgb = $this->SetRGBColor($text_color); } - if ($draw_border) $this->DrawImageBorder(TRUE); - if (empty($text_color)) $rgb = array(0, 0, 0); - else $rgb = $this->SetRGBColor($text_color); $ndx_text_color = imagecolorresolve($this->img, $rgb[0], $rgb[1], $rgb[2]); // Error images should reset fonts, to avoid chance of a TTF error when displaying an error. - if ($reset_font) $this->SetUseTTF(FALSE); + if ($reset_font) { + $this->SetUseTTF(false); + } // Determine the space needed for the text, and center the text box within the image: - if ($text_wrap) $text = wordwrap($text, $wrap_width); + if ($text_wrap) { + $text = wordwrap($text, $wrap_width); + } list($text_width, $text_height) = $this->SizeText('generic', 0, $text); $x = max($this->safe_margin, ($this->image_width - $text_width) / 2); $y = max($this->safe_margin, ($this->image_height - $text_height) / 2); $this->DrawText('generic', 0, $x, $y, $ndx_text_color, $text, 'left', 'top'); - if ($force_print || $this->print_image) $this->PrintImage(); - return TRUE; + if ($force_print || $this->print_image) { + $this->PrintImage(); + } + return true; } /** @@ -2419,8 +2551,10 @@ function DrawMessage($text, $options = NULL) protected function PrintError($error_message) { // Be sure not to loop recursively, e.g. PrintError - PrintImage - PrintError. - if (isset($this->in_error)) return FALSE; - $this->in_error = TRUE; + if (isset($this->in_error)) { + return false; + } + $this->in_error = true; // Output an image containing the error message: if (!$this->suppress_error_image) { @@ -2434,7 +2568,7 @@ protected function PrintError($error_message) trigger_error($error_message, E_USER_ERROR); // This is only reached if the error handler returns TRUE unset($this->in_error); - return FALSE; + return false; } /** @@ -2444,10 +2578,10 @@ protected function PrintError($error_message) * @return bool True always * @since 5.5.0 */ - function SetFailureImage($error_image) + public function SetFailureImage($error_image) { $this->suppress_error_image = !$error_image; - return TRUE; + return true; } /** @@ -2456,14 +2590,14 @@ function SetFailureImage($error_image) * @return bool True always * @since 5.8.0 */ - function StartStream() + public function StartStream() { $this->GetImageType($mime_type, $this->stream_output_f); $this->stream_boundary = "PHPlot-Streaming-Frame"; // Arbitrary MIME boundary $this->stream_frame_header = "\r\n--$this->stream_boundary\r\nContent-Type: $mime_type\r\n"; $this->DisableCaching(); // Send headers to disable browser-side caching header("Content-type: multipart/x-mixed-replace; boundary=\"$this->stream_boundary\""); - return TRUE; + return true; } /** @@ -2472,11 +2606,11 @@ function StartStream() * @return bool True always * @since 5.8.0 */ - function EndStream() + public function EndStream() { echo "\r\n--$this->stream_boundary--\r\n"; flush(); - return TRUE; + return true; } /** @@ -2485,7 +2619,7 @@ function EndStream() * @return bool True always * @since 5.8.0 */ - function PrintImageFrame() + public function PrintImageFrame() { ob_start(); call_user_func($this->stream_output_f, $this->img); @@ -2495,7 +2629,7 @@ function PrintImageFrame() flush(); // This gets the next DrawGraph() to do background and titles again. $this->done = array(); - return TRUE; + return true; } ///////////////////////////////////////////// @@ -2513,14 +2647,19 @@ function PrintImageFrame() * @param string $which_xdlp Desired label position: plotdown | plotup | both | none | plotin | plotstack * @return bool True (False on error if an error handler returns True) */ - function SetXDataLabelPos($which_xdlp) + public function SetXDataLabelPos($which_xdlp) { - $which_xdlp = $this->CheckOption($which_xdlp, 'plotdown, plotup, both, none, plotin, plotstack', - __FUNCTION__); - if (!$which_xdlp) return FALSE; + $which_xdlp = $this->CheckOption( + $which_xdlp, + 'plotdown, plotup, both, none, plotin, plotstack', + __FUNCTION__ + ); + if (!$which_xdlp) { + return false; + } $this->x_data_label_pos = $which_xdlp; - return TRUE; + return true; } /** @@ -2534,14 +2673,19 @@ function SetXDataLabelPos($which_xdlp) * @param string $which_ydlp Desired label position: plotleft | plotright | both | none | ... * @return bool True (False on error if an error handler returns True) */ - function SetYDataLabelPos($which_ydlp) + public function SetYDataLabelPos($which_ydlp) { - $which_ydlp = $this->CheckOption($which_ydlp, 'plotleft, plotright, both, none, plotin, plotstack', - __FUNCTION__); - if (!$which_ydlp) return FALSE; + $which_ydlp = $this->CheckOption( + $which_ydlp, + 'plotleft, plotright, both, none, plotin, plotstack', + __FUNCTION__ + ); + if (!$which_ydlp) { + return false; + } $this->y_data_label_pos = $which_ydlp; - return TRUE; + return true; } /** @@ -2550,14 +2694,19 @@ function SetYDataLabelPos($which_ydlp) * @param string $which_xtlp Desired label position: plotdown | plotup | both | none | xaxis * @return bool True (False on error if an error handler returns True) */ - function SetXTickLabelPos($which_xtlp) + public function SetXTickLabelPos($which_xtlp) { - $which_xtlp = $this->CheckOption($which_xtlp, 'plotdown, plotup, both, xaxis, none', - __FUNCTION__); - if (!$which_xtlp) return FALSE; + $which_xtlp = $this->CheckOption( + $which_xtlp, + 'plotdown, plotup, both, xaxis, none', + __FUNCTION__ + ); + if (!$which_xtlp) { + return false; + } $this->x_tick_label_pos = $which_xtlp; - return TRUE; + return true; } /** @@ -2566,14 +2715,19 @@ function SetXTickLabelPos($which_xtlp) * @param string $which_ytlp Desired label position: plotleft | plotright | both | none | yaxis * @return bool True (False on error if an error handler returns True) */ - function SetYTickLabelPos($which_ytlp) + public function SetYTickLabelPos($which_ytlp) { - $which_ytlp = $this->CheckOption($which_ytlp, 'plotleft, plotright, both, yaxis, none', - __FUNCTION__); - if (!$which_ytlp) return FALSE; + $which_ytlp = $this->CheckOption( + $which_ytlp, + 'plotleft, plotright, both, yaxis, none', + __FUNCTION__ + ); + if (!$which_ytlp) { + return false; + } $this->y_tick_label_pos = $which_ytlp; - return TRUE; + return true; } /** @@ -2602,55 +2756,59 @@ function SetYTickLabelPos($which_ytlp) */ protected function SetLabelType($mode, $args) { - if (!$this->CheckOption($mode, 'x, y, xd, yd, p', __FUNCTION__)) - return FALSE; + if (!$this->CheckOption($mode, 'x, y, xd, yd, p', __FUNCTION__)) { + return false; + } $type = isset($args[0]) ? $args[0] : ''; $format = &$this->label_format[$mode]; // Shorthand reference to format storage variables switch ($type) { - case 'data': - if (isset($args[1])) - $format['precision'] = $args[1]; - elseif (!isset($format['precision'])) - $format['precision'] = 1; - $format['prefix'] = isset($args[2]) ? $args[2] : ''; - $format['suffix'] = isset($args[3]) ? $args[3] : ''; - break; - - case 'time': - if (isset($args[1])) - $format['time_format'] = $args[1]; - elseif (!isset($format['time_format'])) - $format['time_format'] = '%H:%M:%S'; - break; - - case 'printf': - if (isset($args[1])) + case 'data': + if (isset($args[1])) { + $format['precision'] = $args[1]; + } elseif (!isset($format['precision'])) { + $format['precision'] = 1; + } + $format['prefix'] = isset($args[2]) ? $args[2] : ''; + $format['suffix'] = isset($args[3]) ? $args[3] : ''; + break; + + case 'time': + if (isset($args[1])) { + $format['time_format'] = $args[1]; + } elseif (!isset($format['time_format'])) { + $format['time_format'] = '%H:%M:%S'; + } + break; + + case 'printf': + if (isset($args[1])) { // Accept 1, 2, or 3 format strings (see FormatLabel) - $format['printf_format'] = array_slice($args, 1, 3); - elseif (!isset($format['printf_format'])) - $format['printf_format'] = '%e'; - break; - - case 'custom': - if (isset($args[1])) { - $format['custom_callback'] = $args[1]; - $format['custom_arg'] = isset($args[2]) ? $args[2] : NULL; - } else { - $type = ''; // Error, 'custom' without a function, set to no-format mode. - } - break; + $format['printf_format'] = array_slice($args, 1, 3); + } elseif (!isset($format['printf_format'])) { + $format['printf_format'] = '%e'; + } + break; + + case 'custom': + if (isset($args[1])) { + $format['custom_callback'] = $args[1]; + $format['custom_arg'] = isset($args[2]) ? $args[2] : null; + } else { + $type = ''; // Error, 'custom' without a function, set to no-format mode. + } + break; - case '': - case 'title': // Retained for backwards compatibility? - break; + case '': + case 'title': // Retained for backwards compatibility? + break; - default: - $this->CheckOption($type, 'data, time, printf, custom', __FUNCTION__); - $type = ''; + default: + $this->CheckOption($type, 'data, time, printf, custom', __FUNCTION__); + $type = ''; } $format['type'] = $type; - return (boolean)$type; + return (bool)$type; } /** @@ -2660,7 +2818,7 @@ protected function SetLabelType($mode, $args) * @param mixed $varargs One or more additional arguments that depend on $type * @return bool True (False on error if an error handler returns True) */ - function SetXLabelType($type=NULL, $varargs=NULL) // Variable arguments + public function SetXLabelType($type = null, $varargs = null) // Variable arguments { $args = func_get_args(); return $this->SetLabelType('x', $args); @@ -2674,7 +2832,7 @@ function SetXLabelType($type=NULL, $varargs=NULL) // Variable arguments * @return bool True (False on error if an error handler returns True) * @since 5.1.0 */ - function SetXDataLabelType($type=NULL, $varargs=NULL) // Variable arguments, named params are unused + public function SetXDataLabelType($type = null, $varargs = null) // Variable arguments, named params are unused { $args = func_get_args(); return $this->SetLabelType('xd', $args); @@ -2687,7 +2845,7 @@ function SetXDataLabelType($type=NULL, $varargs=NULL) // Variable arguments, na * @param mixed $varargs One or more additional arguments that depend on $type * @return bool True (False on error if an error handler returns True) */ - function SetYLabelType($type=NULL, $varargs=NULL) // Variable arguments, named params are unused + public function SetYLabelType($type = null, $varargs = null) // Variable arguments, named params are unused { $args = func_get_args(); return $this->SetLabelType('y', $args); @@ -2701,7 +2859,7 @@ function SetYLabelType($type=NULL, $varargs=NULL) // Variable arguments, named * @return bool True (False on error if an error handler returns True) * @since 5.1.0 */ - function SetYDataLabelType($type=NULL, $varargs=NULL) // Variable arguments, named params are unused + public function SetYDataLabelType($type = null, $varargs = null) // Variable arguments, named params are unused { $args = func_get_args(); return $this->SetLabelType('yd', $args); @@ -2716,17 +2874,22 @@ function SetYDataLabelType($type=NULL, $varargs=NULL) // Variable arguments, na * @return bool True (False on error if an error handler returns True) * @since 5.6.0 */ - function SetPieLabelType($source_, $type=NULL, $varargs=NULL) // Variable arguments, named params unused + public function SetPieLabelType($source_, $type = null, $varargs = null) // Variable arguments, named params unused { $args = func_get_args(); $source = array_shift($args); if (empty($source)) { - $this->pie_label_source = NULL; // Restore default + $this->pie_label_source = null; // Restore default $args = array(''); // See below - tells SetLabelType to do no formatting or default. } else { - $this->pie_label_source = $this->CheckOptionArray($source, 'percent, value, label, index', - __FUNCTION__); - if (empty($this->pie_label_source)) return FALSE; + $this->pie_label_source = $this->CheckOptionArray( + $source, + 'percent, value, label, index', + __FUNCTION__ + ); + if (empty($this->pie_label_source)) { + return false; + } } return $this->SetLabelType('p', $args); } @@ -2741,10 +2904,10 @@ function SetPieLabelType($source_, $type=NULL, $varargs=NULL) // Variable argum * @param string $which_xtf Formatting string to use (see PHP function strftime()) * @return bool True always */ - function SetXTimeFormat($which_xtf) + public function SetXTimeFormat($which_xtf) { $this->label_format['x']['time_format'] = $which_xtf; - return TRUE; + return true; } /** @@ -2757,10 +2920,10 @@ function SetXTimeFormat($which_xtf) * @param string $which_ytf Formatting string (see PHP function strftime()) * @return bool True always */ - function SetYTimeFormat($which_ytf) + public function SetYTimeFormat($which_ytf) { $this->label_format['y']['time_format'] = $which_ytf; - return TRUE; + return true; } /** @@ -2774,11 +2937,11 @@ function SetYTimeFormat($which_ytf) * @return bool True always * @since 5.0.4 */ - function SetNumberFormat($decimal_point, $thousands_sep) + public function SetNumberFormat($decimal_point, $thousands_sep) { $this->decimal_point = $decimal_point; $this->thousands_sep = $thousands_sep; - return TRUE; + return true; } /** @@ -2787,10 +2950,10 @@ function SetNumberFormat($decimal_point, $thousands_sep) * @param float $which_xla Desired angle for label text, in degrees * @return bool True always */ - function SetXLabelAngle($which_xla) + public function SetXLabelAngle($which_xla) { $this->x_label_angle = $which_xla; - return TRUE; + return true; } /** @@ -2801,10 +2964,10 @@ function SetXLabelAngle($which_xla) * @param float $which_yla Desired angle for label text, in degrees * @return bool True always */ - function SetYLabelAngle($which_yla) + public function SetYLabelAngle($which_yla) { $this->y_label_angle = $which_yla; - return TRUE; + return true; } /** @@ -2814,10 +2977,10 @@ function SetYLabelAngle($which_yla) * @return bool True always * @since 5.1.0 */ - function SetXDataLabelAngle($which_xdla) + public function SetXDataLabelAngle($which_xdla) { $this->x_data_label_angle_u = $which_xdla; - return TRUE; + return true; } /** @@ -2827,10 +2990,10 @@ function SetXDataLabelAngle($which_xdla) * @return bool True always * @since 5.1.0 */ - function SetYDataLabelAngle($which_ydla) + public function SetYDataLabelAngle($which_ydla) { $this->y_data_label_angle = $which_ydla; - return TRUE; + return true; } ///////////////////////////////////////////// @@ -2850,11 +3013,12 @@ protected function CheckOption($which_opt, $which_acc, $which_func) $asked = strtolower(trim($which_opt)); // Look for the supplied value in a comma/space separated list. - if (strpos(", $which_acc,", ", $asked,") !== FALSE) + if (strpos(", $which_acc,", ", $asked,") !== false) { return $asked; + } $this->PrintError("$which_func(): '$which_opt' not in available choices: '$which_acc'."); - return NULL; + return null; } /** @@ -2875,7 +3039,9 @@ protected function CheckOptionArray($opt, $acc, $func) $result = array(); foreach ($opt_array as $option) { $choice = $this->CheckOption($option, $acc, $func); - if (is_null($choice)) return NULL; // In case CheckOption error handler returns + if (is_null($choice)) { + return null; // In case CheckOption error handler returns + } $result[] = $choice; } return $result; @@ -2894,12 +3060,13 @@ protected function CheckOptionArray($opt, $acc, $func) */ protected function CheckDataType($valid_types) { - if (strpos(", $valid_types,", ", $this->data_type,") !== FALSE) - return TRUE; + if (strpos(", $valid_types,", ", $this->data_type,") !== false) { + return true; + } $this->PrintError("Data type '$this->data_type' is not valid for '$this->plot_type' plots." . " Supported data type(s): '$valid_types'"); - return FALSE; + return false; } /** @@ -2961,32 +3128,36 @@ protected function CheckDataArray() $this->data_columns = (int)(($this->records_per_group - $skip) / 3); // Validate the data array for error plots: (label, X, then groups of Y, +err, -err): for ($i = 0; $i < $this->num_data_rows; $i++) { - if ($this->num_recs[$i] < $skip || ($this->num_recs[$i] - $skip) % 3 != 0) + if ($this->num_recs[$i] < $skip || ($this->num_recs[$i] - $skip) % 3 != 0) { return $this->PrintError("DrawGraph(): Invalid $this->data_type data array (row $i)"); + } } } elseif ($this->datatype_pie_single) { $this->data_columns = $this->num_data_rows; // Special case for this type of pie chart. // Validate the data array for text-data-single pie charts. Requires 1 value per row. for ($i = 0; $i < $this->num_data_rows; $i++) { - if ($this->num_recs[$i] != 2) + if ($this->num_recs[$i] != 2) { return $this->PrintError("DrawGraph(): Invalid $this->data_type data array (row $i)"); + } } } elseif ($this->datatype_yz) { $this->data_columns = (int)(($this->records_per_group - $skip) / 2); // (y, z) pairs // Validate the data array for plots using X, Y, Z: (label, X, then pairs of Y, Z) for ($i = 0; $i < $this->num_data_rows; $i++) { - if ($this->num_recs[$i] < $skip || ($this->num_recs[$i] - $skip) % 2 != 0) + if ($this->num_recs[$i] < $skip || ($this->num_recs[$i] - $skip) % 2 != 0) { return $this->PrintError("DrawGraph(): Invalid $this->data_type data array (row $i)"); + } } } else { $this->data_columns = $this->records_per_group - $skip; // Validate the data array for non-error plots: for ($i = 0; $i < $this->num_data_rows; $i++) { - if ($this->num_recs[$i] < $skip) + if ($this->num_recs[$i] < $skip) { return $this->PrintError("DrawGraph(): Invalid $this->data_type data array (row $i)"); + } } } - return TRUE; + return true; } /** @@ -2995,10 +3166,10 @@ protected function CheckDataArray() * @param bool $which_browser_cache True to allow the browser to cache the image, false to not allow * @return bool True always */ - function SetBrowserCache($which_browser_cache) + public function SetBrowserCache($which_browser_cache) { $this->browser_cache = $which_browser_cache; - return TRUE; + return true; } /** @@ -3007,10 +3178,10 @@ function SetBrowserCache($which_browser_cache) * @param bool $which_pi True to have DrawGraph() call PrintImage() when done, false to not output * @return bool True always */ - function SetPrintImage($which_pi) + public function SetPrintImage($which_pi) { $this->print_image = $which_pi; - return TRUE; + return true; } /** @@ -3022,10 +3193,13 @@ function SetPrintImage($which_pi) * @param string|string[] $pdt Border control keyword(s): left|right|top|bottom|sides|none|full * @return bool True (False on error if an error handler returns True) */ - function SetPlotBorderType($pbt) + public function SetPlotBorderType($pbt) { - $this->plot_border_type = $this->CheckOptionArray($pbt, 'left, right, top, bottom, sides, none, full', - __FUNCTION__); + $this->plot_border_type = $this->CheckOptionArray( + $pbt, + 'left, right, top, bottom, sides, none, full', + __FUNCTION__ + ); return !empty($this->plot_border_type); } @@ -3035,10 +3209,10 @@ function SetPlotBorderType($pbt) * @param string $sibt Border type: raised | solid | plain | none * @return bool True (False on error if an error handler returns True) */ - function SetImageBorderType($sibt) + public function SetImageBorderType($sibt) { $this->image_border_type = $this->CheckOption($sibt, 'raised, plain, solid, none', __FUNCTION__); - return (boolean)$this->image_border_type; + return (bool)$this->image_border_type; } /** @@ -3048,10 +3222,10 @@ function SetImageBorderType($sibt) * @return bool True always * @since 5.1.2 */ - function SetImageBorderWidth($width) + public function SetImageBorderWidth($width) { $this->image_border_width = $width; - return TRUE; + return true; } /** @@ -3060,10 +3234,10 @@ function SetImageBorderWidth($width) * @param bool $dpab True to draw the plot area background color, false to not draw it * @return bool True always */ - function SetDrawPlotAreaBackground($dpab) + public function SetDrawPlotAreaBackground($dpab) { $this->draw_plot_area_background = (bool)$dpab; - return TRUE; + return true; } /** @@ -3072,10 +3246,10 @@ function SetDrawPlotAreaBackground($dpab) * @param bool $dxg True to draw the X grid lines, false to not draw them; or NULL to restore default * @return bool True always */ - function SetDrawXGrid($dxg = NULL) + public function SetDrawXGrid($dxg = null) { $this->draw_x_grid = $dxg; - return TRUE; + return true; } /** @@ -3084,10 +3258,10 @@ function SetDrawXGrid($dxg = NULL) * @param bool $dyg True to draw the Y grid lines, false to not draw them; or NULL to restore default * @return bool True always */ - function SetDrawYGrid($dyg = NULL) + public function SetDrawYGrid($dyg = null) { $this->draw_y_grid = $dyg; - return TRUE; + return true; } /** @@ -3096,10 +3270,10 @@ function SetDrawYGrid($dyg = NULL) * @param bool $ddg True to draw the grid with dashed lines, false to use solid lines * @return bool True always */ - function SetDrawDashedGrid($ddg) + public function SetDrawDashedGrid($ddg) { $this->dashed_grid = (bool)$ddg; - return TRUE; + return true; } /** @@ -3108,10 +3282,10 @@ function SetDrawDashedGrid($ddg) * @param bool $dxdl True to draw the X data label lines, false to not draw them * @return bool True always */ - function SetDrawXDataLabelLines($dxdl) + public function SetDrawXDataLabelLines($dxdl) { $this->draw_x_data_label_lines = (bool)$dxdl; - return TRUE; + return true; } /** @@ -3121,10 +3295,10 @@ function SetDrawXDataLabelLines($dxdl) * @return bool True always * @since 6.0.0 */ - function SetDrawYDataLabelLines($dydl) + public function SetDrawYDataLabelLines($dydl) { $this->draw_y_data_label_lines = (bool)$dydl; - return TRUE; + return true; } /** @@ -3134,10 +3308,10 @@ function SetDrawYDataLabelLines($dydl) * @return bool True always * @since 6.0.0 */ - function SetDrawPieBorders($dpb) + public function SetDrawPieBorders($dpb) { $this->draw_pie_borders = (bool)$dpb; - return TRUE; + return true; } /** @@ -3150,10 +3324,10 @@ function SetDrawPieBorders($dpb) * @return bool True always * @since 6.0.0 */ - function SetDrawDataBorders($ddb) + public function SetDrawDataBorders($ddb) { $this->draw_data_borders = (bool)$ddb; - return TRUE; + return true; } /** @@ -3162,10 +3336,10 @@ function SetDrawDataBorders($ddb) * @param string $which_title The text to use for the main plot title. Can contain multiple lines * @return bool True always */ - function SetTitle($which_title) + public function SetTitle($which_title) { $this->title_txt = $which_title; - return TRUE; + return true; } /** @@ -3179,15 +3353,17 @@ function SetTitle($which_title) * @param string $which_xpos Optional position for the X axis and title: plotdown plotup both none * @return bool True (False on error if an error handler returns True) */ - function SetXTitle($which_xtitle, $which_xpos = 'plotdown') + public function SetXTitle($which_xtitle, $which_xpos = 'plotdown') { - if (!($which_xpos = $this->CheckOption($which_xpos, 'plotdown, plotup, both, none', __FUNCTION__))) - return FALSE; - if (($this->x_title_txt = $which_xtitle) === '') + if (!($which_xpos = $this->CheckOption($which_xpos, 'plotdown, plotup, both, none', __FUNCTION__))) { + return false; + } + if (($this->x_title_txt = $which_xtitle) === '') { $this->x_title_pos = 'none'; - else + } else { $this->x_title_pos = $which_xpos; - return TRUE; + } + return true; } /** @@ -3201,15 +3377,17 @@ function SetXTitle($which_xtitle, $which_xpos = 'plotdown') * @param string $which_ypos Optional position for the X axis and title: plotleft plotright both none * @return bool True (False on error if an error handler returns True) */ - function SetYTitle($which_ytitle, $which_ypos = 'plotleft') + public function SetYTitle($which_ytitle, $which_ypos = 'plotleft') { - if (!($which_ypos = $this->CheckOption($which_ypos, 'plotleft, plotright, both, none', __FUNCTION__))) - return FALSE; - if (($this->y_title_txt = $which_ytitle) === '') + if (!($which_ypos = $this->CheckOption($which_ypos, 'plotleft, plotright, both, none', __FUNCTION__))) { + return false; + } + if (($this->y_title_txt = $which_ytitle) === '') { $this->y_title_pos = 'none'; - else + } else { $this->y_title_pos = $which_ypos; - return TRUE; + } + return true; } /** @@ -3222,10 +3400,10 @@ function SetYTitle($which_ytitle, $which_ypos = 'plotleft') * @param int $which_s Size of the drop shadow in pixels * @return bool True always */ - function SetShading($which_s) + public function SetShading($which_s) { $this->shading = (int)$which_s; - return TRUE; + return true; } /** @@ -3234,11 +3412,11 @@ function SetShading($which_s) * @param string $which_pt The plot type, such as bars, lines, pie, ... * @return bool True (False on error if an error handler returns True) */ - function SetPlotType($which_pt) + public function SetPlotType($which_pt) { $avail_plot_types = implode(', ', array_keys(self::$plots)); // List of known plot types $this->plot_type = $this->CheckOption($which_pt, $avail_plot_types, __FUNCTION__); - return (boolean)$this->plot_type; + return (bool)$this->plot_type; } /** @@ -3247,10 +3425,10 @@ function SetPlotType($which_pt) * @param float $pos Axis position as an integer Y world coordinate; '' or omit for default * @return bool True always */ - function SetXAxisPosition($pos='') + public function SetXAxisPosition($pos = '') { - $this->x_axis_position = ($pos === '') ? NULL : (int)$pos; - return TRUE; + $this->x_axis_position = ($pos === '') ? null : (int)$pos; + return true; } /** @@ -3259,10 +3437,10 @@ function SetXAxisPosition($pos='') * @param float $pos Axis position as an integer X world coordinate; '' or omit for default * @return bool True always */ - function SetYAxisPosition($pos='') + public function SetYAxisPosition($pos = '') { - $this->y_axis_position = ($pos === '') ? NULL : (int)$pos; - return TRUE; + $this->y_axis_position = ($pos === '') ? null : (int)$pos; + return true; } /** @@ -3274,10 +3452,10 @@ function SetYAxisPosition($pos='') * @return bool True always * @since 5.3.0 */ - function SetDrawXAxis($draw) + public function SetDrawXAxis($draw) { $this->suppress_x_axis = !$draw; // See DrawXAxis() - return TRUE; + return true; } /** @@ -3289,10 +3467,10 @@ function SetDrawXAxis($draw) * @return bool True always * @since 5.3.0 */ - function SetDrawYAxis($draw) + public function SetDrawYAxis($draw) { $this->suppress_y_axis = !$draw; // See DrawYAxis() - return TRUE; + return true; } /** @@ -3301,10 +3479,10 @@ function SetDrawYAxis($draw) * @param string $which_xst The scale type: linear | log * @return bool True (False on error if an error handler returns True) */ - function SetXScaleType($which_xst) + public function SetXScaleType($which_xst) { $this->xscale_type = $this->CheckOption($which_xst, 'linear, log', __FUNCTION__); - return (boolean)$this->xscale_type; + return (bool)$this->xscale_type; } /** @@ -3313,10 +3491,10 @@ function SetXScaleType($which_xst) * @param string $which_yst The scale type: linear | log * @return bool True (False on error if an error handler returns True) */ - function SetYScaleType($which_yst) + public function SetYScaleType($which_yst) { - $this->yscale_type = $this->CheckOption($which_yst, 'linear, log', __FUNCTION__); - return (boolean)$this->yscale_type; + $this->yscale_type = $this->CheckOption($which_yst, 'linear, log', __FUNCTION__); + return (bool)$this->yscale_type; } /** @@ -3327,7 +3505,7 @@ function SetYScaleType($which_yst) * @param int $which_prec Number of digits to display * @return bool True (False on error if an error handler returns True) */ - function SetPrecisionX($which_prec) + public function SetPrecisionX($which_prec) { return $this->SetXLabelType('data', $which_prec); } @@ -3340,7 +3518,7 @@ function SetPrecisionX($which_prec) * @param int $which_prec Number of digits to display * @return bool True (False on error if an error handler returns True) */ - function SetPrecisionY($which_prec) + public function SetPrecisionY($which_prec) { return $this->SetYLabelType('data', $which_prec); } @@ -3351,10 +3529,10 @@ function SetPrecisionY($which_prec) * @param int $which_seblw Desired width in pixels of the lines used to draw error bars * @return bool True always */ - function SetErrorBarLineWidth($which_seblw) + public function SetErrorBarLineWidth($which_seblw) { $this->error_bar_line_width = $which_seblw; - return TRUE; + return true; } /** @@ -3363,10 +3541,10 @@ function SetErrorBarLineWidth($which_seblw) * @param float $which_blp Label position factor (0 <= blp <= 1); 0 or False for no labels * @return bool True always */ - function SetLabelScalePosition($which_blp) + public function SetLabelScalePosition($which_blp) { $this->label_scale_position = $which_blp; - return TRUE; + return true; } /** @@ -3375,10 +3553,10 @@ function SetLabelScalePosition($which_blp) * @param int $which_ebs Length in pixels of the error bar "T" * @return bool True always */ - function SetErrorBarSize($which_ebs) + public function SetErrorBarSize($which_ebs) { $this->error_bar_size = $which_ebs; - return TRUE; + return true; } /** @@ -3387,10 +3565,10 @@ function SetErrorBarSize($which_ebs) * @param string $which_ebs Error bar shape: tee | line * @return bool True (False on error if an error handler returns True) */ - function SetErrorBarShape($which_ebs) + public function SetErrorBarShape($which_ebs) { $this->error_bar_shape = $this->CheckOption($which_ebs, 'tee, line', __FUNCTION__); - return (boolean)$this->error_bar_shape; + return (bool)$this->error_bar_shape; } /** @@ -3426,7 +3604,7 @@ protected function CheckPointParams() * @param string|string[] $which_pt Array (or single value) of valid point shapes * @return bool True (False on error if an error handler returns True) */ - function SetPointShapes($which_pt) + public function SetPointShapes($which_pt) { $this->point_shapes = $this->CheckOptionArray($which_pt, 'halfline, line, plus, cross, rect,' . ' circle, dot, diamond, triangle, trianglemid, delta, yield, star, hourglass,' @@ -3443,7 +3621,7 @@ function SetPointShapes($which_pt) * @param string[]|string $which_ps Array (or single value) of point sizes in pixels * @return bool True always */ - function SetPointSizes($which_ps) + public function SetPointSizes($which_ps) { if (is_array($which_ps)) { // Use provided array: @@ -3452,7 +3630,7 @@ function SetPointSizes($which_ps) // Make the single value into an array: $this->point_sizes = array($which_ps); } - return TRUE; + return true; } /** @@ -3461,10 +3639,10 @@ function SetPointSizes($which_ps) * @param bool $bl True to break the lines, false to connect around missing data * @return bool True always */ - function SetDrawBrokenLines($bl) + public function SetDrawBrokenLines($bl) { $this->draw_broken_lines = (bool)$bl; - return TRUE; + return true; } /** @@ -3475,15 +3653,16 @@ function SetDrawBrokenLines($bl) * @param string $which_dt The data array format type: text-data | data-data | ... * @return bool True (False on error if an error handler returns True) */ - function SetDataType($which_dt) + public function SetDataType($which_dt) { // Handle data type aliases - mostly for backward compatibility: - if (isset(self::$datatypes_map[$which_dt])) + if (isset(self::$datatypes_map[$which_dt])) { $which_dt = self::$datatypes_map[$which_dt]; + } // Validate the datatype argument against the available data types: $valid_data_types = implode(', ', array_keys(self::$datatypes)); $this->data_type = $this->CheckOption($which_dt, $valid_data_types, __FUNCTION__); - return (boolean)$this->data_type; + return (bool)$this->data_type; } /** @@ -3497,7 +3676,7 @@ function SetDataType($which_dt) * @param array $which_dv The data array, an array of row arrays, interpreted per SetDataType() * @return bool True (False on error if an error handler returns True) */ - function SetDataValues($which_dv) + public function SetDataValues($which_dv) { $this->num_data_rows = count($which_dv); $this->total_records = 0; @@ -3515,7 +3694,7 @@ function SetDataValues($which_dv) // This is the size of the widest row in the data array // Note records_per_group isn't used much anymore. See data_columns in CheckDataArray() $this->records_per_group = empty($this->num_recs) ? 0 : max($this->num_recs); - return TRUE; + return true; } /** @@ -3534,7 +3713,7 @@ protected function PadArrays() $this->pad_array($this->line_styles, $this->data_columns); $this->pad_array($this->ndx_data_colors, $this->data_columns); $this->pad_array($this->ndx_data_border_colors, $this->data_columns); - return TRUE; + return true; } /** @@ -3554,7 +3733,9 @@ protected function pad_array(&$arr, $size) } $n = count($arr); $base = 0; - while ($n < $size) $arr[$n++] = $arr[$base++]; + while ($n < $size) { + $arr[$n++] = $arr[$base++]; + } } /** @@ -3571,7 +3752,7 @@ protected function pad_array(&$arr, $size) * @param int $decimals Number of decimal places in the result * @return string The formatted result */ - protected function number_format($number, $decimals=0) + protected function number_format($number, $decimals = 0) { // Try to get the proper decimal and thousands separators if they are not already set. if (!isset($this->decimal_point, $this->thousands_sep)) { @@ -3583,7 +3764,9 @@ protected function number_format($number, $decimals=0) // Fetch locale settings: $locale = @localeconv(); // Restore locale. (See note above.) - if (!empty($save_locale)) @setlocale(LC_NUMERIC, $save_locale); + if (!empty($save_locale)) { + @setlocale(LC_NUMERIC, $save_locale); + } if (isset($locale['decimal_point'], $locale['thousands_sep'])) { $this->decimal_point = $locale['decimal_point']; $this->thousands_sep = $locale['thousands_sep']; @@ -3607,13 +3790,14 @@ protected function number_format($number, $decimals=0) * @return bool True if the callback reason is valid, else False * @since 5.0.4 */ - function SetCallback($reason, $function, $arg = NULL) + public function SetCallback($reason, $function, $arg = null) { // Use array_key_exists because valid reason keys have NULL as value. - if (!array_key_exists($reason, $this->callbacks)) - return FALSE; + if (!array_key_exists($reason, $this->callbacks)) { + return false; + } $this->callbacks[$reason] = array($function, $arg); - return TRUE; + return true; } /** @@ -3627,11 +3811,12 @@ function SetCallback($reason, $function, $arg = NULL) * @return callback|false The current callback for the reason; False if none or invalid * @since 5.0.4 */ - function GetCallback($reason) + public function GetCallback($reason) { - if (isset($this->callbacks[$reason])) + if (isset($this->callbacks[$reason])) { return $this->callbacks[$reason][0]; - return FALSE; + } + return false; } /** @@ -3644,12 +3829,13 @@ function GetCallback($reason) * @return bool True if it was a valid callback reason, else False * @since 5.0.4 */ - function RemoveCallback($reason) + public function RemoveCallback($reason) { - if (!array_key_exists($reason, $this->callbacks)) - return FALSE; - $this->callbacks[$reason] = NULL; - return TRUE; + if (!array_key_exists($reason, $this->callbacks)) { + return false; + } + $this->callbacks[$reason] = null; + return true; } /** @@ -3664,10 +3850,11 @@ function RemoveCallback($reason) * @param mixed $varargs Zero or more additional arguments to be passed to the callback * @return mixed Whatever value is returned by the callback function (if any) */ - protected function DoCallback($reason, $varargs = NULL) + protected function DoCallback($reason, $varargs = null) { - if (!isset($this->callbacks[$reason])) + if (!isset($this->callbacks[$reason])) { return; + } $args = func_get_args(); // Make the argument vector $args[] look like: $image, $passthru, [$arg...] list($function, $args[0]) = $this->callbacks[$reason]; @@ -3751,8 +3938,10 @@ protected function SetColorIndexes() // and border defaults to grid color. $this->ndx_legend_bg_color = $this->GetColorIndex($this->legend_bg_color, $this->ndx_bg_color); $this->ndx_legend_text_color = $this->GetColorIndex($this->legend_text_color, $this->ndx_text_color); - $this->ndx_legend_border_color = $this->GetColorIndex($this->legend_border_color, - $this->ndx_grid_color); + $this->ndx_legend_border_color = $this->GetColorIndex( + $this->legend_border_color, + $this->ndx_grid_color + ); // Set up a color as transparent, if SetTransparentColor was used. if (!empty($this->transparent_color)) { @@ -3818,18 +4007,26 @@ protected function NeedErrorBarColors() * @param bool $reverse True to reverse the alignment, e.g. for text inside an ellipse * @since 5.6.0 */ - protected function GetTextAlignment($sin_t, $cos_t, &$h_align, &$v_align, $reverse = FALSE) + protected function GetTextAlignment($sin_t, $cos_t, &$h_align, &$v_align, $reverse = false) { if ($reverse) { // Return the opposite alignment, align(T-180) vs align(T) $sin_t = -$sin_t; // sin(T-180) = -sin(T) $cos_t = -$cos_t; // cos(T-180) = -cos(T) } - if ($sin_t >= 0.383) $v_align = 'bottom'; // 0.383 = sin(22.5 degrees) - elseif ($sin_t >= -0.383) $v_align = 'center'; - else $v_align = 'top'; - if ($cos_t >= 0.383) $h_align = 'left'; // 0.383 = cos(90 - 22.5 degrees) - elseif ($cos_t >= -0.383) $h_align = 'center'; - else $h_align = 'right'; + if ($sin_t >= 0.383) { + $v_align = 'bottom'; // 0.383 = sin(22.5 degrees) + } elseif ($sin_t >= -0.383) { + $v_align = 'center'; + } else { + $v_align = 'top'; + } + if ($cos_t >= 0.383) { + $h_align = 'left'; // 0.383 = cos(90 - 22.5 degrees) + } elseif ($cos_t >= -0.383) { + $h_align = 'center'; + } else { + $h_align = 'right'; + } } /** @@ -3850,8 +4047,9 @@ protected function GetTextAlignment($sin_t, $cos_t, &$h_align, &$v_align, $rever */ protected function CheckDataValueLabels($label_control, &$dvl) { - if ($label_control != 'plotin') - return FALSE; // No data value labels + if ($label_control != 'plotin') { + return false; // No data value labels + } $angle = deg2rad($this->data_value_label_angle); $cos = cos($angle); $sin = sin($angle); @@ -3860,7 +4058,7 @@ protected function CheckDataValueLabels($label_control, &$dvl) // Choose text alignment based on angle: $this->GetTextAlignment($sin, $cos, $dvl['h_align'], $dvl['v_align']); - return TRUE; + return true; } /** @@ -3874,10 +4072,10 @@ protected function CheckDataValueLabels($label_control, &$dvl) * @return bool True always * @since 5.6.0 */ - function SetPieAutoSize($enable) + public function SetPieAutoSize($enable) { $this->pie_full_size = !$enable; - return TRUE; + return true; } /** @@ -3887,10 +4085,10 @@ function SetPieAutoSize($enable) * @return bool True always * @since 6.0.0 */ - function SetPieStartAngle($angle) + public function SetPieStartAngle($angle) { $this->pie_start_angle = $angle; - return TRUE; + return true; } /** @@ -3900,12 +4098,14 @@ function SetPieStartAngle($angle) * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function SetPieDirection($which) + public function SetPieDirection($which) { $control = $this->CheckOption($which, 'clockwise, cw, counterclockwise, ccw', __FUNCTION__); - if (empty($control)) return FALSE; + if (empty($control)) { + return false; + } $this->pie_direction_cw = ($control == 'clockwise' || $control == 'cw'); - return TRUE; + return true; } ////////////////////////////////////////////////////////// @@ -3950,8 +4150,9 @@ protected function FindDataLimits() $all_iv = array(); // Calculated below } // For X/Y/Z plots, make sure these are not left over from a previous plot. - if ($this->datatype_yz) - $this->min_z = $this->max_z = NULL; + if ($this->datatype_yz) { + $this->min_z = $this->max_z = null; + } // Process all rows of data: for ($i = 0; $i < $this->num_data_rows; $i++) { @@ -3969,7 +4170,6 @@ protected function FindDataLimits() } while ($j < $n_vals) { if (is_numeric($val = $this->data[$i][$j++])) { - if ($this->datatype_error_bars) { $all_dv[] = $val + (double)$this->data[$i][$j++]; $all_dv[] = $val - (double)$this->data[$i][$j++]; @@ -3984,13 +4184,20 @@ protected function FindDataLimits() } if ($this->datatype_yz) { $z = $this->data[$i][$j++]; // Note Z is required if Y is present. - if (!isset($this->min_z) || $z < $this->min_z) $this->min_z = $z; - if (!isset($this->max_z) || $z > $this->max_z) $this->max_z = $z; + if (!isset($this->min_z) || $z < $this->min_z) { + $this->min_z = $z; + } + if (!isset($this->max_z) || $z > $this->max_z) { + $this->max_z = $z; + } } } } else { // Missing DV value - if ($this->datatype_error_bars) $j += 2; - elseif ($this->datatype_yz) $j++; + if ($this->datatype_error_bars) { + $j += 2; + } elseif ($this->datatype_yz) { + $j++; + } } } if (!empty($all_dv)) { @@ -4035,7 +4242,7 @@ protected function FindDataLimits() 'min_z' => isset($this->min_z) ? $this->min_z : '', 'max_z' => isset($this->max_z) ? $this->max_z : '')); } - return TRUE; + return true; } /** @@ -4088,19 +4295,23 @@ protected function CalcMargins($maximize) // Special case for maximum area usage with no X/Y titles or labels, only main title: if ($maximize) { - if (!isset($this->x_left_margin)) + if (!isset($this->x_left_margin)) { $this->x_left_margin = $base_margin; - if (!isset($this->x_right_margin)) + } + if (!isset($this->x_right_margin)) { $this->x_right_margin = $base_margin; + } if (!isset($this->y_top_margin)) { $this->y_top_margin = $base_margin; - if ($title_height > 0) + if ($title_height > 0) { $this->y_top_margin += $title_height + $gap; + } } - if (!isset($this->y_bot_margin)) + if (!isset($this->y_bot_margin)) { $this->y_bot_margin = $base_margin; + } - return TRUE; + return true; } list($unused, $x_title_height) = $this->SizeText('x_title', 0, $this->x_title_txt); @@ -4108,18 +4319,20 @@ protected function CalcMargins($maximize) // For X/Y tick and label position of 'xaxis' or 'yaxis', determine if the axis happens to be // on an edge of a plot. If it is, we need to account for the margins there. - if ($this->x_axis_position <= $this->plot_min_y) + if ($this->x_axis_position <= $this->plot_min_y) { $x_axis_pos = 'bottom'; - elseif ($this->x_axis_position >= $this->plot_max_y) + } elseif ($this->x_axis_position >= $this->plot_max_y) { $x_axis_pos = 'top'; - else + } else { $x_axis_pos = 'none'; - if ($this->y_axis_position <= $this->plot_min_x) + } + if ($this->y_axis_position <= $this->plot_min_x) { $y_axis_pos = 'left'; - elseif ($this->y_axis_position >= $this->plot_max_x) + } elseif ($this->y_axis_position >= $this->plot_max_x) { $y_axis_pos = 'right'; - else + } else { $y_axis_pos = 'none'; + } // Calculate the heights for X tick and data labels, and the max (used if they are overlaid): $x_data_label_height = ($this->x_data_label_pos == 'none') ? 0 : $this->CalcMaxDataLabelSize('x'); @@ -4212,15 +4425,18 @@ protected function CalcMargins($maximize) $this->x_title_bot_offset = $gap; // Space for main title? - if ($title_height > 0) + if ($title_height > 0) { $top_margin += $title_height + $gap; + } // Reserve space for X title, above and/or below as needed: if ($x_title_height > 0 && ($pos = $this->x_title_pos) != 'none') { - if ($pos == 'plotup' || $pos == 'both') + if ($pos == 'plotup' || $pos == 'both') { $top_margin += $x_title_height + $gap; - if ($pos == 'plotdown' || $pos == 'both') + } + if ($pos == 'plotdown' || $pos == 'both') { $bot_margin += $x_title_height + $gap; + } } // Space for X Labels above the plot? @@ -4236,8 +4452,10 @@ protected function CalcMargins($maximize) } // Space for X Ticks above the plot? - if ($this->x_tick_pos == 'plotup' || $this->x_tick_pos == 'both' - || ($this->x_tick_pos == 'xaxis' && $x_axis_pos == 'top')) { + if ( + $this->x_tick_pos == 'plotup' || $this->x_tick_pos == 'both' + || ($this->x_tick_pos == 'xaxis' && $x_axis_pos == 'top') + ) { $top_margin += $this->x_tick_length; $this->x_label_top_offset = $this->x_tick_length + $gap; $this->x_title_top_offset += $this->x_tick_length; @@ -4247,8 +4465,10 @@ protected function CalcMargins($maximize) } // Space for X Ticks below the plot? - if ($this->x_tick_pos == 'plotdown' || $this->x_tick_pos == 'both' - || ($this->x_tick_pos == 'xaxis' && $x_axis_pos == 'bottom')) { + if ( + $this->x_tick_pos == 'plotdown' || $this->x_tick_pos == 'both' + || ($this->x_tick_pos == 'xaxis' && $x_axis_pos == 'bottom') + ) { $bot_margin += $this->x_tick_length; $this->x_label_bot_offset = $this->x_tick_length + $gap; $this->x_title_bot_offset += $this->x_tick_length; @@ -4273,10 +4493,12 @@ protected function CalcMargins($maximize) // Reserve space for Y title, on left and/or right as needed: if ($y_title_width > 0 && ($pos = $this->y_title_pos) != 'none') { - if ($pos == 'plotleft' || $pos == 'both') + if ($pos == 'plotleft' || $pos == 'both') { $left_margin += $y_title_width + $gap; - if ($pos == 'plotright' || $pos == 'both') + } + if ($pos == 'plotright' || $pos == 'both') { $right_margin += $y_title_width + $gap; + } } // Space for Y Labels left of the plot? @@ -4292,8 +4514,10 @@ protected function CalcMargins($maximize) } // Space for Y Ticks left of plot? - if ($this->y_tick_pos == 'plotleft' || $this->y_tick_pos == 'both' - || ($this->y_tick_pos == 'yaxis' && $y_axis_pos == 'left')) { + if ( + $this->y_tick_pos == 'plotleft' || $this->y_tick_pos == 'both' + || ($this->y_tick_pos == 'yaxis' && $y_axis_pos == 'left') + ) { $left_margin += $this->y_tick_length; $this->y_label_left_offset = $this->y_tick_length + $gap; $this->y_title_left_offset += $this->y_tick_length; @@ -4303,8 +4527,10 @@ protected function CalcMargins($maximize) } // Space for Y Ticks right of plot? - if ($this->y_tick_pos == 'plotright' || $this->y_tick_pos == 'both' - || ($this->y_tick_pos == 'yaxis' && $y_axis_pos == 'right')) { + if ( + $this->y_tick_pos == 'plotright' || $this->y_tick_pos == 'both' + || ($this->y_tick_pos == 'yaxis' && $y_axis_pos == 'right') + ) { $right_margin += $this->y_tick_length; $this->y_label_right_offset = $this->y_tick_length + $gap; $this->y_title_right_offset += $this->y_tick_length; @@ -4322,14 +4548,18 @@ protected function CalcMargins($maximize) // Apply the minimum margins and store in the object. // Do not set margins which were user-defined (see note at top of function). - if (!isset($this->y_top_margin)) + if (!isset($this->y_top_margin)) { $this->y_top_margin = max($min_margin, $top_margin); - if (!isset($this->y_bot_margin)) + } + if (!isset($this->y_bot_margin)) { $this->y_bot_margin = max($min_margin, $bot_margin); - if (!isset($this->x_left_margin)) + } + if (!isset($this->x_left_margin)) { $this->x_left_margin = max($min_margin, $left_margin); - if (!isset($this->x_right_margin)) + } + if (!isset($this->x_right_margin)) { $this->x_right_margin = max($min_margin, $right_margin); + } if ($this->GetCallback('debug_scale')) { // (Too bad compact() doesn't work on class member variables...) @@ -4354,7 +4584,7 @@ protected function CalcMargins($maximize) 'y_title_right_offset' => $this->y_title_right_offset)); } - return TRUE; + return true; } /** @@ -4376,7 +4606,7 @@ protected function CalcPlotAreaPixels() $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1]; $this->DoCallback('debug_scale', __FUNCTION__, $this->plot_area); - return TRUE; + return true; } /** @@ -4391,13 +4621,13 @@ protected function CalcPlotAreaPixels() * @param int $which_bm Bottom margin in pixels; omit or NULL to auto-calculate * @return bool True always */ - function SetMarginsPixels($which_lm = NULL, $which_rm = NULL, $which_tm = NULL, $which_bm = NULL) + public function SetMarginsPixels($which_lm = null, $which_rm = null, $which_tm = null, $which_bm = null) { $this->x_left_margin = $which_lm; $this->x_right_margin = $which_rm; $this->y_top_margin = $which_tm; $this->y_bot_margin = $which_bm; - return TRUE; + return true; } /** @@ -4417,13 +4647,13 @@ function SetMarginsPixels($which_lm = NULL, $which_rm = NULL, $which_tm = NULL, * @param int $y2 Bottom right corner Y coordinate in pixels; omit or NULL to auto-calculate * @return bool True always */ - function SetPlotAreaPixels($x1 = NULL, $y1 = NULL, $x2 = NULL, $y2 = NULL) + public function SetPlotAreaPixels($x1 = null, $y1 = null, $x2 = null, $y2 = null) { $this->x_left_margin = $x1; - $this->x_right_margin = isset($x2) ? $this->image_width - $x2 : NULL; + $this->x_right_margin = isset($x2) ? $this->image_width - $x2 : null; $this->y_top_margin = $y1; - $this->y_bot_margin = isset($y2) ? $this->image_height - $y2 : NULL; - return TRUE; + $this->y_bot_margin = isset($y2) ? $this->image_height - $y2 : null; + return true; } /** @@ -4444,8 +4674,11 @@ protected function CalcStep125($range, $min_ticks) $vi = (int)floor($v); $tick_step = pow(10, $vi); $f = $v - $vi; - if ($f > 0.69897) $tick_step *= 5; // Note 0.69897 = log10(5) - elseif ($f > 0.301) $tick_step *= 2; // Note 0.30103 = log10(2), truncated to fix edge cases + if ($f > 0.69897) { + $tick_step *= 5; // Note 0.69897 = log10(5) + } elseif ($f > 0.301) { + $tick_step *= 2; // Note 0.30103 = log10(2), truncated to fix edge cases + } return $tick_step; } @@ -4476,8 +4709,11 @@ protected function CalcStepDatetime($range, $min_ticks) // Find the biggest value in the table <= tick_limit (which is the // exact interval which would give min_ticks steps): foreach ($datetime_steps as $v) { - if ($v <= $tick_limit) $tick_step = $v; - else break; + if ($v <= $tick_limit) { + $tick_step = $v; + } else { + break; + } } } else { // Use the numeric-mode algorithm to find a 1,2,5*10**n solution, in units of days. @@ -4506,7 +4742,9 @@ protected function CalcStepDatetime($range, $min_ticks) protected function CalcStepBinary($range, $min_ticks) { $log2 = log($range / $min_ticks, 2); - if ($log2 > 0) $log2 *= 1.000001; // See note above + if ($log2 > 0) { + $log2 *= 1.000001; // See note above + } return pow(2, (int)floor($log2)); } @@ -4527,10 +4765,11 @@ protected function CalcStep($which, $range) // If tick_mode is null, default to decimal mode unless the axis uses date/time formatting: if (!isset($tick_mode)) { - if (isset($this->label_format[$which]['type']) && $this->label_format[$which]['type'] == 'time') + if (isset($this->label_format[$which]['type']) && $this->label_format[$which]['type'] == 'time') { $tick_mode = 'date'; - else + } else { $tick_mode = 'decimal'; + } } // Use proper mode to calculate the tick increment, with integer override option. @@ -4563,7 +4802,7 @@ protected function CalcRangeInit(&$plot_limit, $implied, $data_limit) { if (isset($plot_limit) && $plot_limit !== '') { // Use the user-supplied value, and do no further adjustments. - return array($plot_limit, FALSE); + return array($plot_limit, false); } // Start with the actual data range. Set adjustment flag TRUE unless the range was implied. return array($data_limit, !$implied); @@ -4593,15 +4832,17 @@ protected function CalcRangeInit(&$plot_limit, $implied, $data_limit) */ protected function CheckPlotRange($which, &$plot_min, &$plot_max, $adjust_min, $adjust_max) { - if ($plot_min < $plot_max) - return TRUE; // No adjustment needed. + if ($plot_min < $plot_max) { + return true; // No adjustment needed. + } // Bad range, plot_min >= plot_max, needs fixing. if ($adjust_max && $adjust_min) { // Both min and max are calculated, so either or both can be adjusted. // It should not be possible that plot_min > plot_max here, but check it to be safe: - if ($plot_max != $plot_min) + if ($plot_max != $plot_min) { return $this->PrintError("SetPlotAreaWorld(): Inverse auto $which range error"); + } if ($plot_max == 0.0) { // All 0. Use the arbitrary range 0:10 @@ -4617,19 +4858,23 @@ protected function CheckPlotRange($which, &$plot_min, &$plot_max, $adjust_min, $ } } elseif ($adjust_max) { // Equivalent to: ($adjust_max && !$adjust_min) // Max is calculated, min was set, so adjust max - if ($plot_min < 0) $plot_max = 0; - else $plot_max = $plot_min + 10; - + if ($plot_min < 0) { + $plot_max = 0; + } else { + $plot_max = $plot_min + 10; + } } elseif ($adjust_min) { // Equivalent to: (!$adjust_max && $adjust_min) // Min is calculated, max was set, so adjust min - if ($plot_max > 0) $plot_min = 0; - else $plot_min = $plot_max - 10; - + if ($plot_max > 0) { + $plot_min = 0; + } else { + $plot_min = $plot_max - 10; + } } else { // Equivalent to: (!$adjust_max && !$adjust_min) // Both limits are set. This should never happen, since SetPlotAreaWorld stops it. return $this->PrintError("SetPlotAreaWorld(): Inverse $which range error"); } - return TRUE; + return true; } /** @@ -4644,22 +4889,24 @@ protected function CheckPlotRange($which, &$plot_min, &$plot_max, $adjust_min, $ */ protected function GetRangeEndAdjust($which, &$adjust) { - if (isset($adjust)) return; // Already set, nothing to do + if (isset($adjust)) { + return; // Already set, nothing to do + } // The plot type can customize how an end adjustment is applied: if (empty(self::$plots[$this->plot_type]['adjust_type'])) { // Default (adjust_type missing or 0) means pad the dependent variable axis only. - $adjust = ($which == 'x' XOR $this->datatype_swapped_xy) ? 0 : 0.03; + $adjust = ($which == 'x' xor $this->datatype_swapped_xy) ? 0 : 0.03; } else { switch (self::$plots[$this->plot_type]['adjust_type']) { - case 1: - // Adjust type = 1 means add extra padding to both X and Y axis ends - $adjust = 0.03; - break; - case 2: - // Adjust type = 2 means do not add extra padding to either axis. - $adjust = 0; - break; + case 1: + // Adjust type = 1 means add extra padding to both X and Y axis ends + $adjust = 0.03; + break; + case 2: + // Adjust type = 2 means do not add extra padding to either axis. + $adjust = 0; + break; } } } @@ -4679,7 +4926,7 @@ protected function GetRangeEndAdjust($which, &$adjust) protected function CalcPlotRange($which) { // Independent variable is X in the usual vertical plots; Y in horizontal plots: - $independent_variable = ($this->datatype_swapped_xy XOR $which == 'x'); + $independent_variable = ($this->datatype_swapped_xy xor $which == 'x'); // 'implied' means this is a non-explicitly given independent variable, e.g. X in 'text-data'. $implied = $this->datatype_implied && $independent_variable; @@ -4706,8 +4953,9 @@ protected function CalcPlotRange($which) } // Validate the range, which must be positive. Adjusts plot_min and plot_max if necessary. - if (!$this->CheckPlotRange($which, $plot_min, $plot_max, $adjust_min, $adjust_max)) - return FALSE; + if (!$this->CheckPlotRange($which, $plot_min, $plot_max, $adjust_min, $adjust_max)) { + return false; + } // Adjust the min and max values, if flagged above for adjustment. @@ -4720,21 +4968,25 @@ protected function CalcPlotRange($which) $range = $plot_max - $plot_min; // When all data > 0, test to see if the zero magnet is strong enough to pull the min down to zero: - if ($adjust_min && $plot_min > 0 && $zero_magnet > 0 && ($zero_magnet == 1.0 || - $plot_max / $range < $zero_magnet / (1 - $zero_magnet))) { + if ( + $adjust_min && $plot_min > 0 && $zero_magnet > 0 && ($zero_magnet == 1.0 || + $plot_max / $range < $zero_magnet / (1 - $zero_magnet)) + ) { $plot_min = 0; $range = $plot_max; } // Similar to above, but for negative data: zero magnet pulls max up to zero: - if ($adjust_max && $plot_max < 0 && $zero_magnet > 0 && ($zero_magnet == 1.0 || - -$plot_min / $range < $zero_magnet / (1 - $zero_magnet))) { + if ( + $adjust_max && $plot_max < 0 && $zero_magnet > 0 && ($zero_magnet == 1.0 || + -$plot_min / $range < $zero_magnet / (1 - $zero_magnet)) + ) { $plot_max = 0; $range = 0 - $plot_min; } // Calculate the tick increment, if it wasn't set using Set[XY]TickIncrement(). - $num_ticks_override = FALSE; + $num_ticks_override = false; if (empty($tick_inc)) { if (empty($num_ticks)) { // Calculate a reasonable tick increment, based on the current plot area limits @@ -4743,7 +4995,7 @@ protected function CalcPlotRange($which) // Number of ticks was provided: use exactly that. // Adjustment is below, after range is calculated using mode 'R': $adjust_mode = 'R'; - $num_ticks_override = TRUE; + $num_ticks_override = true; } } @@ -4751,8 +5003,9 @@ protected function CalcPlotRange($which) if ($adjust_min && $plot_min != 0) { // Mode 'R' and basis for other modes: Extend the limit by a percentage of the // plot range, but only when the data is negative (to leave room below for labels). - if ($plot_min < 0) + if ($plot_min < 0) { $plot_min -= $adjust_amount * $range; + } if ($adjust_mode == 'T') { // Mode 'T': Adjust to previous tick mark, taking tick anchor into account. @@ -4769,8 +5022,9 @@ protected function CalcPlotRange($which) if ($adjust_max && $plot_max != 0) { // Mode 'R' and basis for other modes: Extend the limit by a percentage of the // plot range, but only when the max is positive (leaves room above for labels). - if ($plot_max > 0) + if ($plot_max > 0) { $plot_max += $adjust_amount * $range; + } if ($adjust_mode == 'T') { // Mode 'T': Adjust to next tick mark, taking tick anchor into account: @@ -4790,14 +5044,18 @@ protected function CalcPlotRange($which) // Check log scale range - plot_min and plot_max must be > 0. if ($which == 'y' && $this->yscale_type == 'log' || $which == 'x' && $this->xscale_type == 'log') { - if ($plot_min <= 0) $plot_min = 1; + if ($plot_min <= 0) { + $plot_min = 1; + } if ($plot_max <= 0) { // Note: Error message names the public function, not this function. return $this->PrintError("SetPlotAreaWorld(): Invalid $which range for log scale"); } } // Final error check to ensure the range is positive. - if ($plot_min >= $plot_max) $plot_max = $plot_min + 1; + if ($plot_min >= $plot_max) { + $plot_max = $plot_min + 1; + } // Return the calculated values. (Note these get stored back into class variables.) return array($tick_inc, $plot_min, $plot_max); @@ -4850,15 +5108,19 @@ protected function CalcPlotAreaWorld() * @param float $ymax Y data range maximum; omit or NULL to auto-calculate * @return bool True (False on error if an error handler returns True) */ - function SetPlotAreaWorld($xmin=NULL, $ymin=NULL, $xmax=NULL, $ymax=NULL) + public function SetPlotAreaWorld($xmin = null, $ymin = null, $xmax = null, $ymax = null) { $this->plot_min_x = $xmin; $this->plot_max_x = $xmax; $this->plot_min_y = $ymin; $this->plot_max_y = $ymax; - if (isset($xmin) && isset($xmax) && $xmin >= $xmax) $bad = 'X'; - elseif (isset($ymin) && isset($ymax) && $ymin >= $ymax) $bad = 'Y'; - else return TRUE; + if (isset($xmin) && isset($xmax) && $xmin >= $xmax) { + $bad = 'X'; + } elseif (isset($ymin) && isset($ymax) && $ymin >= $ymax) { + $bad = 'Y'; + } else { + return true; + } return $this->PrintError("SetPlotAreaWorld(): $bad range error - min >= max"); } @@ -4918,7 +5180,7 @@ protected function CalcBarWidths($stacked, $verticals) 'actual_bar_width' => $this->actual_bar_width, 'bar_adjust_gap' => $this->bar_adjust_gap)); } - return TRUE; + return true; } /** @@ -4982,7 +5244,7 @@ protected function CalcAxisPositions() 'y_axis_position' => $this->y_axis_position)); } - return TRUE; + return true; } /** @@ -5040,7 +5302,7 @@ protected function CalcTranslation() 'x_axis_y_pixels' => $this->x_axis_y_pixels)); } - return TRUE; + return true; } /** @@ -5050,7 +5312,7 @@ protected function CalcTranslation() * @return int Translated X device (pixel) coordinate * @deprecated Public use discouraged; use GetDeviceXY() instead */ - function xtr($x_world) + public function xtr($x_world) { if ($this->xscale_type == 'log') { $x_pixels = $this->plot_origin_x + log10($x_world) * $this->xscale ; @@ -5067,7 +5329,7 @@ function xtr($x_world) * @return int Translated Y device (pixel) coordinate * @deprecated Public use discouraged; use GetDeviceXY() instead */ - function ytr($y_world) + public function ytr($y_world) { if ($this->yscale_type == 'log') { //minus because GD defines y = 0 at top. doh! @@ -5095,7 +5357,7 @@ function ytr($y_world) * @return int[] Array of ($x, $y) device coordinates; False on error if error handler returns True * @since 5.1.0 */ - function GetDeviceXY($x_world, $y_world) + public function GetDeviceXY($x_world, $y_world) { if (!isset($this->xscale)) { return $this->PrintError("GetDeviceXY() was called before translation factors were calculated"); @@ -5139,18 +5401,25 @@ protected function CalcTicks($which) // If a tick anchor was given, adjust the start of the range so the anchor falls // at an exact tick mark (or would, if it was within range). - if (isset($anchor)) + if (isset($anchor)) { $tick_start = $anchor - $tick_step * floor(($anchor - $tick_start) / $tick_step); + } // Lastly, adjust for option to skip left/bottom or right/top tick marks: - if ($skip_lo) + if ($skip_lo) { $tick_start += $tick_step; - if ($skip_hi) + } + if ($skip_hi) { $tick_end -= $tick_step; + } - if ($this->GetCallback('debug_scale')) - $this->DoCallback('debug_scale', __FUNCTION__, - compact('which', 'tick_start', 'tick_end', 'tick_step')); + if ($this->GetCallback('debug_scale')) { + $this->DoCallback( + 'debug_scale', + __FUNCTION__, + compact('which', 'tick_start', 'tick_end', 'tick_step') + ); + } return array($tick_start, $tick_end, $tick_step); } @@ -5182,8 +5451,12 @@ protected function CalcMaxTickLabelSize($which) while ($tick_val <= $tick_end) { $tick_label = $this->FormatLabel($which, $tick_val); list($width, $height) = $this->SizeText($font_id, $angle, $tick_label); - if ($width > $max_width) $max_width = $width; - if ($height > $max_height) $max_height = $height; + if ($width > $max_width) { + $max_width = $width; + } + if ($height > $max_height) { + $max_height = $height; + } $tick_val = $tick_start + ++$n * $tick_step; } if ($this->GetCallback('debug_scale')) { @@ -5191,8 +5464,9 @@ protected function CalcMaxTickLabelSize($which) 'which' => $which, 'height' => $max_height, 'width' => $max_width)); } - if ($which == 'x') + if ($which == 'x') { return $max_height; + } return $max_width; } @@ -5218,8 +5492,9 @@ protected function CalcMaxDataLabelSize($which = 'x') { // Shortcut: Y data labels for vertical plots, and X data labels for horizontal plots, // are inside the plot, rather than along the axis lines, and so take up no margin space. - if ($which == 'y' XOR $this->datatype_swapped_xy) + if ($which == 'y' xor $this->datatype_swapped_xy) { return 0; + } $angle = ($which == 'x') ? $this->x_data_label_angle : $this->y_data_label_angle; $font_id = $which . '_label'; // Use x_label or y_label font. @@ -5231,16 +5506,21 @@ protected function CalcMaxDataLabelSize($which = 'x') for ($i = 0; $i < $this->num_data_rows; $i++) { $label = $this->FormatLabel($format_code, $this->data[$i][0], $i); list($width, $height) = $this->SizeText($font_id, $angle, $label); - if ($width > $max_width) $max_width = $width; - if ($height > $max_height) $max_height = $height; + if ($width > $max_width) { + $max_width = $width; + } + if ($height > $max_height) { + $max_height = $height; + } } if ($this->GetCallback('debug_scale')) { $this->DoCallback('debug_scale', __FUNCTION__, array( 'height' => $max_height, 'width' => $max_width)); } - if ($this->datatype_swapped_xy) + if ($this->datatype_swapped_xy) { return $max_width; + } return $max_height; } @@ -5254,9 +5534,12 @@ protected function CalcMaxDataLabelSize($which = 'x') */ protected function CheckLabelsAllEmpty() { - for ($i = 0; $i < $this->num_data_rows; $i++) - if ($this->data[$i][0] !== '') return FALSE; - return TRUE; + for ($i = 0; $i < $this->num_data_rows; $i++) { + if ($this->data[$i][0] !== '') { + return false; + } + } + return true; } /** @@ -5272,34 +5555,39 @@ protected function CheckLabelsAllEmpty() protected function CheckLabels() { // Default for X data label angle is a special case (different from Y). - if ($this->x_data_label_angle_u === '') + if ($this->x_data_label_angle_u === '') { $this->x_data_label_angle = $this->x_label_angle; // Not set with SetXDataLabelAngle() - else + } else { $this->x_data_label_angle = $this->x_data_label_angle_u; // Set with SetXDataLabelAngle() + } // X Label position fixups, for x_data_label_pos and x_tick_label_pos: if ($this->datatype_swapped_xy) { // Just apply defaults - there is no position conflict for X labels. - if (!isset($this->x_tick_label_pos)) + if (!isset($this->x_tick_label_pos)) { $this->x_tick_label_pos = 'plotdown'; - if (!isset($this->x_data_label_pos)) + } + if (!isset($this->x_data_label_pos)) { $this->x_data_label_pos = 'none'; + } } else { // Apply defaults but do not allow conflict between tick and data labels. if (isset($this->x_data_label_pos)) { if (!isset($this->x_tick_label_pos)) { // Case: data_label_pos is set, tick_label_pos needs a default: - if ($this->x_data_label_pos == 'none') + if ($this->x_data_label_pos == 'none') { $this->x_tick_label_pos = 'plotdown'; - else + } else { $this->x_tick_label_pos = 'none'; + } } } elseif (isset($this->x_tick_label_pos)) { // Case: tick_label_pos is set, data_label_pos needs a default: - if ($this->x_tick_label_pos == 'none') + if ($this->x_tick_label_pos == 'none') { $this->x_data_label_pos = 'plotdown'; - else + } else { $this->x_data_label_pos = 'none'; + } } else { // Case: Neither tick_label_pos nor data_label_pos is set. // We do not want them to be both on (as PHPlot used to do in this case). @@ -5317,26 +5605,30 @@ protected function CheckLabels() // Y Label position fixups, for y_data_label_pos and y_tick_label_pos: if (!$this->datatype_swapped_xy) { // Just apply defaults - there is no position conflict. - if (!isset($this->y_tick_label_pos)) + if (!isset($this->y_tick_label_pos)) { $this->y_tick_label_pos = 'plotleft'; - if (!isset($this->y_data_label_pos)) + } + if (!isset($this->y_data_label_pos)) { $this->y_data_label_pos = 'none'; + } } else { // Apply defaults but do not allow conflict between tick and data labels. if (isset($this->y_data_label_pos)) { if (!isset($this->y_tick_label_pos)) { // Case: data_label_pos is set, tick_label_pos needs a default: - if ($this->y_data_label_pos == 'none') + if ($this->y_data_label_pos == 'none') { $this->y_tick_label_pos = 'plotleft'; - else + } else { $this->y_tick_label_pos = 'none'; + } } } elseif (isset($this->y_tick_label_pos)) { // Case: tick_label_pos is set, data_label_pos needs a default: - if ($this->y_tick_label_pos == 'none') + if ($this->y_tick_label_pos == 'none') { $this->y_data_label_pos = 'plotleft'; - else + } else { $this->y_data_label_pos = 'none'; + } } else { // Case: Neither tick_label_pos nor data_label_pos is set. // Turn on data labels if any were supplied, else tick labels. @@ -5349,7 +5641,7 @@ protected function CheckLabels() } } } - return TRUE; + return true; } /** @@ -5360,54 +5652,57 @@ protected function CheckLabels() * @param mixed $varargs Zero or more additional arguments to pass to a custom format function * @return string The formatted label value (original value if no formatting is enabled) */ - protected function FormatLabel($which_pos, $which_lab, $varargs=NULL) // Variable additional arguments + protected function FormatLabel($which_pos, $which_lab, $varargs = null) // Variable additional arguments { // Assign a reference shortcut to the label format controls, default xd,yd to x,y. - if ($which_pos == 'xd' && empty($this->label_format['xd'])) + if ($which_pos == 'xd' && empty($this->label_format['xd'])) { $which_pos = 'x'; - elseif ($which_pos == 'yd' && empty($this->label_format['yd'])) + } elseif ($which_pos == 'yd' && empty($this->label_format['yd'])) { $which_pos = 'y'; + } $format = &$this->label_format[$which_pos]; // Don't format empty strings (especially as time or numbers), or if no type was set. if ($which_lab !== '' && !empty($format['type'])) { switch ($format['type']) { - case 'title': // Note: This is obsolete - $which_lab = @ $this->data[$which_lab][0]; - break; - case 'data': - $which_lab = $format['prefix'] + case 'title': // Note: This is obsolete + $which_lab = @ $this->data[$which_lab][0]; + break; + case 'data': + $which_lab = $format['prefix'] . $this->number_format($which_lab, $format['precision']) . $this->data_units_text // Obsolete . $format['suffix']; - break; - case 'time': - $which_lab = strftime($format['time_format'], $which_lab); - break; - case 'printf': - if (!is_array($format['printf_format'])) { - $use_format = $format['printf_format']; - } else { - // Select from 1, 2, or 3 formats based on the sign of the value (like spreadsheets). - // With 2 formats, use [0] for >= 0, [1] for < 0. - // With 3 formats, use [0] for > 0, [1] for < 0, [2] for = 0. - $n_formats = count($format['printf_format']); - if ($n_formats == 3 && $which_lab == 0) { - $use_format = $format['printf_format'][2]; - } elseif ($n_formats > 1 && $which_lab < 0) { - $use_format = $format['printf_format'][1]; - $which_lab = -$which_lab; // Format the absolute value - } else $use_format = $format['printf_format'][0]; - } - $which_lab = sprintf($use_format, $which_lab); - break; - case 'custom': - // Build argument vector: (text, custom_callback_arg, other_args...) - $argv = func_get_args(); - $argv[0] = $which_lab; - $argv[1] = $format['custom_arg']; - $which_lab = call_user_func_array($format['custom_callback'], $argv); - break; + break; + case 'time': + $which_lab = strftime($format['time_format'], $which_lab); + break; + case 'printf': + if (!is_array($format['printf_format'])) { + $use_format = $format['printf_format']; + } else { + // Select from 1, 2, or 3 formats based on the sign of the value (like spreadsheets). + // With 2 formats, use [0] for >= 0, [1] for < 0. + // With 3 formats, use [0] for > 0, [1] for < 0, [2] for = 0. + $n_formats = count($format['printf_format']); + if ($n_formats == 3 && $which_lab == 0) { + $use_format = $format['printf_format'][2]; + } elseif ($n_formats > 1 && $which_lab < 0) { + $use_format = $format['printf_format'][1]; + $which_lab = -$which_lab; // Format the absolute value + } else { + $use_format = $format['printf_format'][0]; + } + } + $which_lab = sprintf($use_format, $which_lab); + break; + case 'custom': + // Build argument vector: (text, custom_callback_arg, other_args...) + $argv = func_get_args(); + $argv[0] = $which_lab; + $argv[1] = $format['custom_arg']; + $which_lab = call_user_func_array($format['custom_callback'], $argv); + break; } } return $which_lab; @@ -5428,13 +5723,16 @@ protected function FormatLabel($which_pos, $which_lab, $varargs=NULL) // Variabl */ protected function TuneAutoRange($which, $zero_magnet, $adjust_mode, $adjust_amount) { - if (isset($zero_magnet) && $zero_magnet >= 0 && $zero_magnet <= 1.0) + if (isset($zero_magnet) && $zero_magnet >= 0 && $zero_magnet <= 1.0) { $this->rangectl[$which]['zero_magnet'] = $zero_magnet; - if (isset($adjust_mode) && strpos('TRI', $adjust_mode[0]) !== FALSE) + } + if (isset($adjust_mode) && strpos('TRI', $adjust_mode[0]) !== false) { $this->rangectl[$which]['adjust_mode'] = $adjust_mode; - if (isset($adjust_amount) && $adjust_amount >= 0) + } + if (isset($adjust_amount) && $adjust_amount >= 0) { $this->rangectl[$which]['adjust_amount'] = $adjust_amount; - return TRUE; + } + return true; } /** @@ -5448,7 +5746,7 @@ protected function TuneAutoRange($which, $zero_magnet, $adjust_mode, $adjust_amo * @return bool True always * @since 6.0.0 */ - function TuneXAutoRange($zero_magnet = NULL, $adjust_mode = NULL, $adjust_amount = NULL) + public function TuneXAutoRange($zero_magnet = null, $adjust_mode = null, $adjust_amount = null) { return $this->TuneAutoRange('x', $zero_magnet, $adjust_mode, $adjust_amount); } @@ -5464,7 +5762,7 @@ function TuneXAutoRange($zero_magnet = NULL, $adjust_mode = NULL, $adjust_amount * @return bool True always * @since 6.0.0 */ - function TuneYAutoRange($zero_magnet = NULL, $adjust_mode = NULL, $adjust_amount = NULL) + public function TuneYAutoRange($zero_magnet = null, $adjust_mode = null, $adjust_amount = null) { return $this->TuneAutoRange('y', $zero_magnet, $adjust_mode, $adjust_amount); } @@ -5483,18 +5781,24 @@ function TuneYAutoRange($zero_magnet = NULL, $adjust_mode = NULL, $adjust_amount */ protected function TuneAutoTicks($which, $min_ticks, $tick_mode, $tick_inc_integer) { - if (isset($min_ticks) && $min_ticks > 0) - $this->tickctl[$which]['min_ticks'] = (integer)$min_ticks; + if (isset($min_ticks) && $min_ticks > 0) { + $this->tickctl[$which]['min_ticks'] = (int)$min_ticks; + } if (isset($tick_mode)) { - $tick_mode = $this->CheckOption($tick_mode, 'decimal, binary, date', - 'Tune' . strtoupper($which) . 'AutoTicks'); - if (!$tick_mode) - return FALSE; + $tick_mode = $this->CheckOption( + $tick_mode, + 'decimal, binary, date', + 'Tune' . strtoupper($which) . 'AutoTicks' + ); + if (!$tick_mode) { + return false; + } $this->tickctl[$which]['tick_mode'] = $tick_mode; } - if (isset($tick_inc_integer)) + if (isset($tick_inc_integer)) { $this->tickctl[$which]['tick_inc_integer'] = (bool)$tick_inc_integer; - return TRUE; + } + return true; } /** @@ -5508,7 +5812,7 @@ protected function TuneAutoTicks($which, $min_ticks, $tick_mode, $tick_inc_integ * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function TuneXAutoTicks($min_ticks = NULL, $tick_mode = NULL, $tick_inc_integer = NULL) + public function TuneXAutoTicks($min_ticks = null, $tick_mode = null, $tick_inc_integer = null) { return $this->TuneAutoTicks('x', $min_ticks, $tick_mode, $tick_inc_integer); } @@ -5524,7 +5828,7 @@ function TuneXAutoTicks($min_ticks = NULL, $tick_mode = NULL, $tick_inc_integer * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function TuneYAutoTicks($min_ticks = NULL, $tick_mode = NULL, $tick_inc_integer = NULL) + public function TuneYAutoTicks($min_ticks = null, $tick_mode = null, $tick_inc_integer = null) { return $this->TuneAutoTicks('y', $min_ticks, $tick_mode, $tick_inc_integer); } @@ -5540,10 +5844,10 @@ function TuneYAutoTicks($min_ticks = NULL, $tick_mode = NULL, $tick_inc_integer * @param float $which_ti X tick increment in world coordinates; omit or '' for default auto-calculate * @return bool True always */ - function SetXTickIncrement($which_ti='') + public function SetXTickIncrement($which_ti = '') { $this->x_tick_inc_u = $which_ti; - return TRUE; + return true; } /** @@ -5552,10 +5856,10 @@ function SetXTickIncrement($which_ti='') * @param float $which_ti Y tick increment in world coordinates; omit or '' for default auto-calculate * @return bool True always */ - function SetYTickIncrement($which_ti='') + public function SetYTickIncrement($which_ti = '') { $this->y_tick_inc_u = $which_ti; - return TRUE; + return true; } /** @@ -5564,10 +5868,10 @@ function SetYTickIncrement($which_ti='') * @param int $which_nt Number of X tick intervals; omit or '' for default auto-calculate * @return bool True always */ - function SetNumXTicks($which_nt='') + public function SetNumXTicks($which_nt = '') { $this->num_x_ticks = $which_nt; - return TRUE; + return true; } /** @@ -5576,10 +5880,10 @@ function SetNumXTicks($which_nt='') * @param int $which_nt Number of Y tick intervals; omit or '' for default auto-calculate * @return bool True always */ - function SetNumYTicks($which_nt='') + public function SetNumYTicks($which_nt = '') { $this->num_y_ticks = $which_nt; - return TRUE; + return true; } /** @@ -5588,11 +5892,14 @@ function SetNumYTicks($which_nt='') * @param string $which_tp Tick mark position: plotdown | plotup | both | xaxis | none * @return bool True (False on error if an error handler returns True) */ - function SetXTickPos($which_tp) + public function SetXTickPos($which_tp) { - $this->x_tick_pos = $this->CheckOption($which_tp, 'plotdown, plotup, both, xaxis, none', - __FUNCTION__); - return (boolean)$this->x_tick_pos; + $this->x_tick_pos = $this->CheckOption( + $which_tp, + 'plotdown, plotup, both, xaxis, none', + __FUNCTION__ + ); + return (bool)$this->x_tick_pos; } /** @@ -5601,11 +5908,14 @@ function SetXTickPos($which_tp) * @param string $which_tp Tick mark position: plotleft | plotright | both | yaxis | none * @return bool True (False on error if an error handler returns True) */ - function SetYTickPos($which_tp) + public function SetYTickPos($which_tp) { - $this->y_tick_pos = $this->CheckOption($which_tp, 'plotleft, plotright, both, yaxis, none', - __FUNCTION__); - return (boolean)$this->y_tick_pos; + $this->y_tick_pos = $this->CheckOption( + $which_tp, + 'plotleft, plotright, both, yaxis, none', + __FUNCTION__ + ); + return (bool)$this->y_tick_pos; } /** @@ -5614,10 +5924,10 @@ function SetYTickPos($which_tp) * @param bool $skip True to skip the tick mark and label; false to draw them * @return bool True always */ - function SetSkipTopTick($skip) + public function SetSkipTopTick($skip) { $this->skip_top_tick = (bool)$skip; - return TRUE; + return true; } /** @@ -5626,10 +5936,10 @@ function SetSkipTopTick($skip) * @param bool $skip True to skip the tick mark and label; false to draw them * @return bool True always */ - function SetSkipBottomTick($skip) + public function SetSkipBottomTick($skip) { $this->skip_bottom_tick = (bool)$skip; - return TRUE; + return true; } /** @@ -5638,10 +5948,10 @@ function SetSkipBottomTick($skip) * @param bool $skip True to skip the tick mark and label; false to draw them * @return bool True always */ - function SetSkipLeftTick($skip) + public function SetSkipLeftTick($skip) { $this->skip_left_tick = (bool)$skip; - return TRUE; + return true; } /** @@ -5650,10 +5960,10 @@ function SetSkipLeftTick($skip) * @param bool $skip True to skip the tick mark and label; false to draw them * @return bool True always */ - function SetSkipRightTick($skip) + public function SetSkipRightTick($skip) { $this->skip_right_tick = (bool)$skip; - return TRUE; + return true; } /** @@ -5662,10 +5972,10 @@ function SetSkipRightTick($skip) * @param int $which_xln Outer length of the tick marks, in pixels * @return bool True always */ - function SetXTickLength($which_xln) + public function SetXTickLength($which_xln) { $this->x_tick_length = $which_xln; - return TRUE; + return true; } /** @@ -5674,10 +5984,10 @@ function SetXTickLength($which_xln) * @param int $which_yln Outer length of the tick marks, in pixels * @return bool True always */ - function SetYTickLength($which_yln) + public function SetYTickLength($which_yln) { $this->y_tick_length = $which_yln; - return TRUE; + return true; } /** @@ -5686,10 +5996,10 @@ function SetYTickLength($which_yln) * @param int $which_xc Crossing length of the tick marks, in pixels * @return bool True always */ - function SetXTickCrossing($which_xc) + public function SetXTickCrossing($which_xc) { $this->x_tick_cross = $which_xc; - return TRUE; + return true; } /** @@ -5698,10 +6008,10 @@ function SetXTickCrossing($which_xc) * @param int $which_yc Crossing length of the tick marks, in pixels * @return bool True always */ - function SetYTickCrossing($which_yc) + public function SetYTickCrossing($which_yc) { $this->y_tick_cross = $which_yc; - return TRUE; + return true; } /** @@ -5713,10 +6023,10 @@ function SetYTickCrossing($which_yc) * @return bool True always * @since 5.4.0 */ - function SetXTickAnchor($xta = NULL) + public function SetXTickAnchor($xta = null) { $this->x_tick_anchor = $xta; - return TRUE; + return true; } /** @@ -5728,10 +6038,10 @@ function SetXTickAnchor($xta = NULL) * @return bool True always * @since 5.4.0 */ - function SetYTickAnchor($yta = NULL) + public function SetYTickAnchor($yta = null) { $this->y_tick_anchor = $yta; - return TRUE; + return true; } ///////////////////////////////////////////// @@ -5744,19 +6054,25 @@ function SetYTickAnchor($yta = NULL) * @param bool $overwrite True to do it even if already done, False or omit to do once only * @return bool True always */ - protected function DrawBackground($overwrite=FALSE) + protected function DrawBackground($overwrite = false) { // Check if background should be drawn: if (empty($this->done['background']) || $overwrite) { if (isset($this->bgimg)) { // If bgimg is defined, use it $this->tile_img($this->bgimg, 0, 0, $this->image_width, $this->image_height, $this->bgmode); } else { // Else use solid color - ImageFilledRectangle($this->img, 0, 0, $this->image_width, $this->image_height, - $this->ndx_bg_color); + ImageFilledRectangle( + $this->img, + 0, + 0, + intval($this->image_width), + intval($this->image_height), + intval($this->ndx_bg_color) + ); } - $this->done['background'] = TRUE; + $this->done['background'] = true; } - return TRUE; + return true; } /** @@ -5767,13 +6083,25 @@ protected function DrawBackground($overwrite=FALSE) protected function DrawPlotAreaBackground() { if (isset($this->plotbgimg)) { - $this->tile_img($this->plotbgimg, $this->plot_area[0], $this->plot_area[1], - $this->plot_area_width, $this->plot_area_height, $this->plotbgmode); + $this->tile_img( + $this->plotbgimg, + $this->plot_area[0], + $this->plot_area[1], + $this->plot_area_width, + $this->plot_area_height, + $this->plotbgmode + ); } elseif ($this->draw_plot_area_background) { - ImageFilledRectangle($this->img, $this->plot_area[0], $this->plot_area[1], - $this->plot_area[2], $this->plot_area[3], $this->ndx_plot_bg_color); + ImageFilledRectangle( + $this->img, + intval($this->plot_area[0]), + intval($this->plot_area[1]), + intval($this->plot_area[2]), + intval($this->plot_area[3]), + intval($this->ndx_plot_bg_color) + ); } - return TRUE; + return true; } /** @@ -5791,18 +6119,29 @@ protected function DrawPlotAreaBackground() protected function tile_img($file, $xorig, $yorig, $width, $height, $mode) { $im = $this->GetImage($file, $tile_width, $tile_height); - if (!$im) - return FALSE; // GetImage already produced an error message. + if (!$im) { + return false; // GetImage already produced an error message. + } if ($mode == 'scale') { - imagecopyresampled($this->img, $im, $xorig, $yorig, 0, 0, $width, $height, - $tile_width, $tile_height); - return TRUE; + imagecopyresampled( + $this->img, + $im, + $xorig, + $yorig, + 0, + 0, + $width, + $height, + $tile_width, + $tile_height + ); + return true; } if ($mode == 'centeredtile') { - $x0 = - floor($tile_width/2); // Make the tile look better - $y0 = - floor($tile_height/2); + $x0 = - floor($tile_width / 2); // Make the tile look better + $y0 = - floor($tile_height / 2); } else { // Accept anything else as $mode == 'tile' $x0 = 0; $y0 = 0; @@ -5810,21 +6149,24 @@ protected function tile_img($file, $xorig, $yorig, $width, $height, $mode) // Draw the tile onto a temporary image first. $tmp = imagecreate($width, $height); - if (! $tmp) + if (! $tmp) { return $this->PrintError('tile_img(): Could not create image resource.'); + } - for ($x = $x0; $x < $width; $x += $tile_width) - for ($y = $y0; $y < $height; $y += $tile_height) + for ($x = $x0; $x < $width; $x += $tile_width) { + for ($y = $y0; $y < $height; $y += $tile_height) { imagecopy($tmp, $im, $x, $y, 0, 0, $tile_width, $tile_height); + } + } // Copy the temporary image onto the final one. - imagecopy($this->img, $tmp, $xorig, $yorig, 0,0, $width, $height); + imagecopy($this->img, $tmp, $xorig, $yorig, 0, 0, $width, $height); // Free resources imagedestroy($tmp); imagedestroy($im); - return TRUE; + return true; } /** @@ -5835,12 +6177,15 @@ protected function tile_img($file, $xorig, $yorig, $width, $height, $mode) */ protected function GetImageBorderWidth() { - if ($this->image_border_type == 'none') + if ($this->image_border_type == 'none') { return 0; // No border - if (!empty($this->image_border_width)) + } + if (!empty($this->image_border_width)) { return $this->image_border_width; // Specified border width - if ($this->image_border_type == 'raised') + } + if ($this->image_border_type == 'raised') { return 2; // Default for raised border is 2 pixels. + } return 1; // Default for other border types is 1 pixel. } @@ -5857,41 +6202,43 @@ protected function GetImageBorderWidth() * @return bool True (False on error if an error handler returns True) * */ - protected function DrawImageBorder($overwrite=FALSE) + protected function DrawImageBorder($overwrite = false) { // Check if border should be drawn: - if ($this->image_border_type == 'none' || !(empty($this->done['border']) || $overwrite)) - return TRUE; + if ($this->image_border_type == 'none' || !(empty($this->done['border']) || $overwrite)) { + return true; + } $width = $this->GetImageBorderWidth(); $color1 = $this->ndx_i_border; $color2 = $this->ndx_i_border_dark; $ex = $this->image_width - 1; $ey = $this->image_height - 1; switch ($this->image_border_type) { - case 'raised': - // Top and left lines use border color, right and bottom use the darker shade. - // Drawing order matters in the upper right and lower left corners. - for ($i = 0; $i < $width; $i++, $ex--, $ey--) { - imageline($this->img, $i, $i, $ex, $i, $color1); // Top - imageline($this->img, $ex, $i, $ex, $ey, $color2); // Right - imageline($this->img, $i, $i, $i, $ey, $color1); // Left - imageline($this->img, $i, $ey, $ex, $ey, $color2); // Bottom - } - break; - case 'plain': // See note above re colors - $color1 = $color2; - // Fall through - case 'solid': - for ($i = 0; $i < $width; $i++, $ex--, $ey--) { - imagerectangle($this->img, $i, $i, $ex, $ey, $color1); - } - break; - default: - return $this->PrintError( - "DrawImageBorder(): unknown image_border_type: '$this->image_border_type'"); + case 'raised': + // Top and left lines use border color, right and bottom use the darker shade. + // Drawing order matters in the upper right and lower left corners. + for ($i = 0; $i < $width; $i++, $ex--, $ey--) { + imageline($this->img, intval($i ), intval($i ), intval($ex), intval($i ), intval($color1)); // Top + imageline($this->img, intval($ex), intval($i ), intval($ex), intval($ey), intval($color2)); // Right + imageline($this->img, intval($i ), intval($i ), intval($i ), intval($ey), intval($color1)); // Left + imageline($this->img, intval($i ), intval($ey), intval($ex), intval($ey), intval($color2)); // Bottom + } + break; + case 'plain': // See note above re colors + $color1 = $color2; + // Fall through + case 'solid': + for ($i = 0; $i < $width; $i++, $ex--, $ey--) { + imagerectangle($this->img, intval($i), intval($i), intval($ex), intval($ey), intval($color1)); + } + break; + default: + return $this->PrintError( + "DrawImageBorder(): unknown image_border_type: '$this->image_border_type'" + ); } - $this->done['border'] = TRUE; // Border should only be drawn once per image. - return TRUE; + $this->done['border'] = true; // Border should only be drawn once per image. + return true; } /** @@ -5901,8 +6248,9 @@ protected function DrawImageBorder($overwrite=FALSE) */ protected function DrawTitle() { - if (!empty($this->done['title']) || $this->title_txt === '') - return TRUE; + if (!empty($this->done['title']) || $this->title_txt === '') { + return true; + } // Center of the image: $xpos = $this->image_width / 2; @@ -5912,8 +6260,8 @@ protected function DrawTitle() $this->DrawText('title', 0, $xpos, $ypos, $this->ndx_title_color, $this->title_txt, 'center', 'top'); - $this->done['title'] = TRUE; - return TRUE; + $this->done['title'] = true; + return true; } /** @@ -5923,8 +6271,9 @@ protected function DrawTitle() */ protected function DrawXTitle() { - if ($this->x_title_pos == 'none') - return TRUE; + if ($this->x_title_pos == 'none') { + return true; + } // Center of the plot $xpos = ($this->plot_area[2] + $this->plot_area[0]) / 2; @@ -5932,16 +6281,32 @@ protected function DrawXTitle() // Upper title if ($this->x_title_pos == 'plotup' || $this->x_title_pos == 'both') { $ypos = $this->plot_area[1] - $this->x_title_top_offset; - $this->DrawText('x_title', 0, $xpos, $ypos, $this->ndx_x_title_color, - $this->x_title_txt, 'center', 'bottom'); + $this->DrawText( + 'x_title', + 0, + $xpos, + $ypos, + $this->ndx_x_title_color, + $this->x_title_txt, + 'center', + 'bottom' + ); } // Lower title if ($this->x_title_pos == 'plotdown' || $this->x_title_pos == 'both') { $ypos = $this->plot_area[3] + $this->x_title_bot_offset; - $this->DrawText('x_title', 0, $xpos, $ypos, $this->ndx_x_title_color, - $this->x_title_txt, 'center', 'top'); + $this->DrawText( + 'x_title', + 0, + $xpos, + $ypos, + $this->ndx_x_title_color, + $this->x_title_txt, + 'center', + 'top' + ); } - return TRUE; + return true; } /** @@ -5951,24 +6316,41 @@ protected function DrawXTitle() */ protected function DrawYTitle() { - if ($this->y_title_pos == 'none') - return TRUE; + if ($this->y_title_pos == 'none') { + return true; + } // Center the title vertically to the plot area $ypos = ($this->plot_area[3] + $this->plot_area[1]) / 2; if ($this->y_title_pos == 'plotleft' || $this->y_title_pos == 'both') { $xpos = $this->plot_area[0] - $this->y_title_left_offset; - $this->DrawText('y_title', 90, $xpos, $ypos, $this->ndx_y_title_color, - $this->y_title_txt, 'right', 'center'); + $this->DrawText( + 'y_title', + 90, + $xpos, + $ypos, + $this->ndx_y_title_color, + $this->y_title_txt, + 'right', + 'center' + ); } if ($this->y_title_pos == 'plotright' || $this->y_title_pos == 'both') { $xpos = $this->plot_area[2] + $this->y_title_right_offset; - $this->DrawText('y_title', 90, $xpos, $ypos, $this->ndx_y_title_color, - $this->y_title_txt, 'left', 'center'); + $this->DrawText( + 'y_title', + 90, + $xpos, + $ypos, + $this->ndx_y_title_color, + $this->y_title_txt, + 'left', + 'center' + ); } - return TRUE; + return true; } /** @@ -5983,10 +6365,16 @@ protected function DrawXAxis() //Draw X Axis at Y = x_axis_y_pixels, unless suppressed (See SetXAxisPosition) if (!$this->suppress_x_axis) { - ImageLine($this->img, $this->plot_area[0]+1, $this->x_axis_y_pixels, - $this->plot_area[2]-1, $this->x_axis_y_pixels, $this->ndx_grid_color); + ImageLine( + $this->img, + intval($this->plot_area[0] + 1), + intval($this->x_axis_y_pixels), + intval($this->plot_area[2] - 1), + intval($this->x_axis_y_pixels), + intval($this->ndx_grid_color) + ); } - return TRUE; + return true; } /** @@ -6004,10 +6392,16 @@ protected function DrawYAxis() // Draw Y axis at X = y_axis_x_pixels, unless suppressed (See SetYAxisPosition) if (!$this->suppress_y_axis) { - ImageLine($this->img, $this->y_axis_x_pixels, $this->plot_area[1], - $this->y_axis_x_pixels, $this->plot_area[3], $this->ndx_grid_color); + ImageLine( + $this->img, + intval($this->y_axis_x_pixels), + intval($this->plot_area[1]), + intval($this->y_axis_x_pixels), + intval($this->plot_area[3]), + intval($this->ndx_grid_color) + ); } - return TRUE; + return true; } /** @@ -6022,20 +6416,38 @@ protected function DrawXTick($x, $x_pixels) { // Ticks on X axis if ($this->x_tick_pos == 'xaxis') { - ImageLine($this->img, $x_pixels, $this->x_axis_y_pixels - $this->x_tick_cross, - $x_pixels, $this->x_axis_y_pixels + $this->x_tick_length, $this->ndx_tick_color); + ImageLine( + $this->img, + intval($x_pixels), + intval($this->x_axis_y_pixels - $this->x_tick_cross), + intval($x_pixels), + intval($this->x_axis_y_pixels + $this->x_tick_length), + intval($this->ndx_tick_color) + ); } // Ticks on top of the Plot Area if ($this->x_tick_pos == 'plotup' || $this->x_tick_pos == 'both') { - ImageLine($this->img, $x_pixels, $this->plot_area[1] - $this->x_tick_length, - $x_pixels, $this->plot_area[1] + $this->x_tick_cross, $this->ndx_tick_color); + ImageLine( + $this->img, + intval($x_pixels), + intval($this->plot_area[1] - $this->x_tick_length), + intval($x_pixels), + intval($this->plot_area[1] + $this->x_tick_cross), + intval($this->ndx_tick_color) + ); } // Ticks on bottom of Plot Area if ($this->x_tick_pos == 'plotdown' || $this->x_tick_pos == 'both') { - ImageLine($this->img, $x_pixels, $this->plot_area[3] + $this->x_tick_length, - $x_pixels, $this->plot_area[3] - $this->x_tick_cross, $this->ndx_tick_color); + ImageLine( + $this->img, + intval($x_pixels), + intval($this->plot_area[3] + $this->x_tick_length), + intval($x_pixels), + intval($this->plot_area[3] - $this->x_tick_cross), + intval($this->ndx_tick_color) + ); } if ($this->x_tick_label_pos != 'none') { @@ -6043,26 +6455,47 @@ protected function DrawXTick($x, $x_pixels) // Label on X axis if ($this->x_tick_label_pos == 'xaxis') { - $this->DrawText('x_label', $this->x_label_angle, - $x_pixels, $this->x_axis_y_pixels + $this->x_label_axis_offset, - $this->ndx_ticklabel_color, $x_label, 'center', 'top'); + $this->DrawText( + 'x_label', + $this->x_label_angle, + $x_pixels, + $this->x_axis_y_pixels + $this->x_label_axis_offset, + $this->ndx_ticklabel_color, + $x_label, + 'center', + 'top' + ); } // Label on top of the plot area if ($this->x_tick_label_pos == 'plotup' || $this->x_tick_label_pos == 'both') { - $this->DrawText('x_label', $this->x_label_angle, - $x_pixels, $this->plot_area[1] - $this->x_label_top_offset, - $this->ndx_ticklabel_color, $x_label, 'center', 'bottom'); + $this->DrawText( + 'x_label', + $this->x_label_angle, + $x_pixels, + $this->plot_area[1] - $this->x_label_top_offset, + $this->ndx_ticklabel_color, + $x_label, + 'center', + 'bottom' + ); } // Label on bottom of the plot area if ($this->x_tick_label_pos == 'plotdown' || $this->x_tick_label_pos == 'both') { - $this->DrawText('x_label', $this->x_label_angle, - $x_pixels, $this->plot_area[3] + $this->x_label_bot_offset, - $this->ndx_ticklabel_color, $x_label, 'center', 'top'); + $this->DrawText( + 'x_label', + $this->x_label_angle, + $x_pixels, + $this->plot_area[3] + $this->x_label_bot_offset, + $this->ndx_ticklabel_color, + $x_label, + 'center', + 'top' + ); } } - return TRUE; + return true; } /** @@ -6077,20 +6510,38 @@ protected function DrawYTick($y, $y_pixels) { // Ticks on Y axis if ($this->y_tick_pos == 'yaxis') { - ImageLine($this->img, $this->y_axis_x_pixels - $this->y_tick_length, $y_pixels, - $this->y_axis_x_pixels + $this->y_tick_cross, $y_pixels, $this->ndx_tick_color); + ImageLine( + $this->img, + intval($this->y_axis_x_pixels - $this->y_tick_length), + intval($y_pixels), + intval($this->y_axis_x_pixels + $this->y_tick_cross), + intval($y_pixels), + intval($this->ndx_tick_color) + ); } // Ticks to the left of the Plot Area - if (($this->y_tick_pos == 'plotleft') || ($this->y_tick_pos == 'both') ) { - ImageLine($this->img, $this->plot_area[0] - $this->y_tick_length, $y_pixels, - $this->plot_area[0] + $this->y_tick_cross, $y_pixels, $this->ndx_tick_color); + if (($this->y_tick_pos == 'plotleft') || ($this->y_tick_pos == 'both')) { + ImageLine( + $this->img, + intval($this->plot_area[0] - $this->y_tick_length), + intval($y_pixels), + intval($this->plot_area[0] + $this->y_tick_cross), + intval($y_pixels), + intval($this->ndx_tick_color) + ); } // Ticks to the right of the Plot Area - if (($this->y_tick_pos == 'plotright') || ($this->y_tick_pos == 'both') ) { - ImageLine($this->img, $this->plot_area[2] + $this->y_tick_length, $y_pixels, - $this->plot_area[2] - $this->y_tick_cross, $y_pixels, $this->ndx_tick_color); + if (($this->y_tick_pos == 'plotright') || ($this->y_tick_pos == 'both')) { + ImageLine( + $this->img, + intval($this->plot_area[2] + $this->y_tick_length), + intval($y_pixels), + intval($this->plot_area[2] - $this->y_tick_cross), + intval($y_pixels), + intval($this->ndx_tick_color) + ); } if ($this->y_tick_label_pos != 'none') { @@ -6098,26 +6549,47 @@ protected function DrawYTick($y, $y_pixels) // Labels on Y axis if ($this->y_tick_label_pos == 'yaxis') { - $this->DrawText('y_label', $this->y_label_angle, - $this->y_axis_x_pixels - $this->y_label_axis_offset, $y_pixels, - $this->ndx_ticklabel_color, $y_label, 'right', 'center'); + $this->DrawText( + 'y_label', + $this->y_label_angle, + $this->y_axis_x_pixels - $this->y_label_axis_offset, + $y_pixels, + $this->ndx_ticklabel_color, + $y_label, + 'right', + 'center' + ); } // Labels to the left of the plot area if ($this->y_tick_label_pos == 'plotleft' || $this->y_tick_label_pos == 'both') { - $this->DrawText('y_label', $this->y_label_angle, - $this->plot_area[0] - $this->y_label_left_offset, $y_pixels, - $this->ndx_ticklabel_color, $y_label, 'right', 'center'); + $this->DrawText( + 'y_label', + $this->y_label_angle, + $this->plot_area[0] - $this->y_label_left_offset, + $y_pixels, + $this->ndx_ticklabel_color, + $y_label, + 'right', + 'center' + ); } // Labels to the right of the plot area if ($this->y_tick_label_pos == 'plotright' || $this->y_tick_label_pos == 'both') { - $this->DrawText('y_label', $this->y_label_angle, - $this->plot_area[2] + $this->y_label_right_offset, $y_pixels, - $this->ndx_ticklabel_color, $y_label, 'left', 'center'); + $this->DrawText( + 'y_label', + $this->y_label_angle, + $this->plot_area[2] + $this->y_label_right_offset, + $y_pixels, + $this->ndx_ticklabel_color, + $y_label, + 'left', + 'center' + ); } } - return TRUE; + return true; } /** @@ -6142,13 +6614,13 @@ protected function DrawXTicks() // Draw vertical grid line: if ($draw_grid) { - ImageLine($this->img, $x_pixels, $this->plot_area[1], $x_pixels, $this->plot_area[3], $style); + ImageLine($this->img, intval($x_pixels), intval($this->plot_area[1]), intval($x_pixels), intval($this->plot_area[3]), intval($style)); } // Draw tick mark and tick label: $this->DrawXTick($x, $x_pixels); } - return TRUE; + return true; } /** @@ -6173,14 +6645,20 @@ protected function DrawYTicks() // Draw horizontal grid line: if ($draw_grid) { - ImageLine($this->img, $this->plot_area[0]+1, $y_pixels, $this->plot_area[2]-1, - $y_pixels, $style); + ImageLine( + $this->img, + intval($this->plot_area[0] + 1), + intval($y_pixels), + intval($this->plot_area[2] - 1), + intval($y_pixels), + intval($style) + ); } // Draw tick mark and tick label: $this->DrawYTick($y, $y_pixels); } - return TRUE; + return true; } /** @@ -6193,36 +6671,75 @@ protected function DrawYTicks() * @param bool $draw_axes True or omit to draw the X axis and Y axis, false to not (for pie charts) * @return bool True always */ - protected function DrawPlotBorder($draw_axes = TRUE) + protected function DrawPlotBorder($draw_axes = true) { // Force plot_border_type to array and apply defaults. if (isset($this->plot_border_type)) { $pbt = (array)$this->plot_border_type; - } elseif ($draw_axes) $pbt = array('sides'); - else return TRUE; // Default to no border for plots without axes (e.g. pie charts) + } elseif ($draw_axes) { + $pbt = array('sides'); + } else { + return true; // Default to no border for plots without axes (e.g. pie charts) + } $sides = 0; // Bitmap: 1=left 2=top 4=right 8=bottom $map = array('left' => 1, 'plotleft' => 1, 'right' => 4, 'plotright' => 4, 'top' => 2, 'bottom' => 8, 'both' => 5, 'sides' => 5, 'full' => 15, 'none' => 0); - foreach ($pbt as $option) $sides |= $map[$option]; + foreach ($pbt as $option) { + $sides |= $map[$option]; + } if ($sides == 15) { // Border on all 4 sides - imagerectangle($this->img, $this->plot_area[0], $this->plot_area[1], - $this->plot_area[2], $this->plot_area[3], $this->ndx_grid_color); + imagerectangle( + $this->img, + intval($this->plot_area[0]), + intval($this->plot_area[1]), + intval($this->plot_area[2]), + intval($this->plot_area[3]), + intval($this->ndx_grid_color) + ); } else { - if ($sides & 1) // Left - imageline($this->img, $this->plot_area[0], $this->plot_area[1], - $this->plot_area[0], $this->plot_area[3], $this->ndx_grid_color); - if ($sides & 2) // Top - imageline($this->img, $this->plot_area[0], $this->plot_area[1], - $this->plot_area[2], $this->plot_area[1], $this->ndx_grid_color); - if ($sides & 4) // Right - imageline($this->img, $this->plot_area[2], $this->plot_area[1], - $this->plot_area[2], $this->plot_area[3], $this->ndx_grid_color); - if ($sides & 8) // Bottom - imageline($this->img, $this->plot_area[0], $this->plot_area[3], - $this->plot_area[2], $this->plot_area[3], $this->ndx_grid_color); + if ($sides & 1) { // Left + imageline( + $this->img, + intval($this->plot_area[0]), + intval($this->plot_area[1]), + intval($this->plot_area[0]), + intval($this->plot_area[3]), + intval($this->ndx_grid_color) + ); + } + if ($sides & 2) { // Top + imageline( + $this->img, + intval($this->plot_area[0]), + intval($this->plot_area[1]), + intval($this->plot_area[2]), + intval($this->plot_area[1]), + intval($this->ndx_grid_color) + ); + } + if ($sides & 4) { // Right + imageline( + $this->img, + intval($this->plot_area[2]), + intval($this->plot_area[1]), + intval($this->plot_area[2]), + intval($this->plot_area[3]), + intval($this->ndx_grid_color) + ); + } + if ($sides & 8) { // Bottom + imageline( + $this->img, + intval($this->plot_area[0]), + intval($this->plot_area[3]), + intval($this->plot_area[2]), + intval($this->plot_area[3]), + intval($this->ndx_grid_color) + ); + } } - return TRUE; + return true; } /** @@ -6267,14 +6784,25 @@ protected function DrawDataValueLabel($x_or_y, $row, $column, $x_world, $y_world // Check to see if the text fits in the available space, if requested. if (isset($min_width) || isset($min_height)) { list($width, $height) = $this->SizeText($font_id, $angle, $formatted_text); - if ((isset($min_width) && ($min_width - $width) < 2) - || (isset($min_height) && ($min_height - $height) < 2)) - return FALSE; + if ( + (isset($min_width) && ($min_width - $width) < 2) + || (isset($min_height) && ($min_height - $height) < 2) + ) { + return false; + } } - $this->DrawText($font_id, $angle, $this->xtr($x_world) + $x_offset, $this->ytr($y_world) + $y_offset, - $this->ndx_dvlabel_color, $formatted_text, $h_align, $v_align); - return TRUE; + $this->DrawText( + $font_id, + $angle, + $this->xtr($x_world) + $x_offset, + $this->ytr($y_world) + $y_offset, + $this->ndx_dvlabel_color, + $formatted_text, + $h_align, + $v_align + ); + return true; } /** @@ -6286,25 +6814,42 @@ protected function DrawDataValueLabel($x_or_y, $row, $column, $x_world, $y_world * @param bool $do_lines True for plot types that support data label lines, False or omit if not * @return bool True always */ - protected function DrawXDataLabel($xlab, $xpos, $row, $do_lines=FALSE) + protected function DrawXDataLabel($xlab, $xpos, $row, $do_lines = false) { $xlab = $this->FormatLabel('xd', $xlab, $row); // Labels below the plot area - if ($this->x_data_label_pos == 'plotdown' || $this->x_data_label_pos == 'both') - $this->DrawText('x_label', $this->x_data_label_angle, - $xpos, $this->plot_area[3] + $this->x_label_bot_offset, - $this->ndx_datalabel_color, $xlab, 'center', 'top'); + if ($this->x_data_label_pos == 'plotdown' || $this->x_data_label_pos == 'both') { + $this->DrawText( + 'x_label', + $this->x_data_label_angle, + $xpos, + $this->plot_area[3] + $this->x_label_bot_offset, + $this->ndx_datalabel_color, + $xlab, + 'center', + 'top' + ); + } // Labels above the plot area - if ($this->x_data_label_pos == 'plotup' || $this->x_data_label_pos == 'both') - $this->DrawText('x_label', $this->x_data_label_angle, - $xpos, $this->plot_area[1] - $this->x_label_top_offset, - $this->ndx_datalabel_color, $xlab, 'center', 'bottom'); - - if ($do_lines && $this->draw_x_data_label_lines) + if ($this->x_data_label_pos == 'plotup' || $this->x_data_label_pos == 'both') { + $this->DrawText( + 'x_label', + $this->x_data_label_angle, + $xpos, + $this->plot_area[1] - $this->x_label_top_offset, + $this->ndx_datalabel_color, + $xlab, + 'center', + 'bottom' + ); + } + + if ($do_lines && $this->draw_x_data_label_lines) { $this->DrawXDataLine($xpos, $row); - return TRUE; + } + return true; } /** @@ -6317,25 +6862,42 @@ protected function DrawXDataLabel($xlab, $xpos, $row, $do_lines=FALSE) * @return bool True always * @since 5.1.2 */ - protected function DrawYDataLabel($ylab, $ypos, $row, $do_lines=FALSE) + protected function DrawYDataLabel($ylab, $ypos, $row, $do_lines = false) { $ylab = $this->FormatLabel('yd', $ylab, $row); // Labels left of the plot area - if ($this->y_data_label_pos == 'plotleft' || $this->y_data_label_pos == 'both') - $this->DrawText('y_label', $this->y_data_label_angle, - $this->plot_area[0] - $this->y_label_left_offset, $ypos, - $this->ndx_datalabel_color, $ylab, 'right', 'center'); + if ($this->y_data_label_pos == 'plotleft' || $this->y_data_label_pos == 'both') { + $this->DrawText( + 'y_label', + $this->y_data_label_angle, + $this->plot_area[0] - $this->y_label_left_offset, + $ypos, + $this->ndx_datalabel_color, + $ylab, + 'right', + 'center' + ); + } // Labels right of the plot area - if ($this->y_data_label_pos == 'plotright' || $this->y_data_label_pos == 'both') - $this->DrawText('y_label', $this->y_data_label_angle, - $this->plot_area[2] + $this->y_label_right_offset, $ypos, - $this->ndx_datalabel_color, $ylab, 'left', 'center'); - - if ($do_lines && $this->draw_y_data_label_lines) + if ($this->y_data_label_pos == 'plotright' || $this->y_data_label_pos == 'both') { + $this->DrawText( + 'y_label', + $this->y_data_label_angle, + $this->plot_area[2] + $this->y_label_right_offset, + $ypos, + $this->ndx_datalabel_color, + $ylab, + 'left', + 'center' + ); + } + + if ($do_lines && $this->draw_y_data_label_lines) { $this->DrawYDataLine($ypos, $row); - return TRUE; + } + return true; } /** @@ -6356,17 +6918,17 @@ protected function DrawXDataLine($xpos, $row) if ($this->x_data_label_pos == 'both') { // Lines from the bottom up - ImageLine($this->img, $xpos, $this->plot_area[3], $xpos, $this->plot_area[1], $style); + ImageLine($this->img, intval($xpos), intval($this->plot_area[3]), intval($xpos), intval($this->plot_area[1]), intval($style)); } elseif ($this->x_data_label_pos == 'plotdown' && isset($this->data_max[$row])) { // Lines from the bottom of the plot up to the max Y value at this X: $ypos = $this->ytr($this->data_max[$row]); - ImageLine($this->img, $xpos, $ypos, $xpos, $this->plot_area[3], $style); + ImageLine($this->img, intval($xpos), intval($ypos), intval($xpos), intval($this->plot_area[3]), intval($style)); } elseif ($this->x_data_label_pos == 'plotup' && isset($this->data_min[$row])) { // Lines from the top of the plot down to the min Y value at this X: $ypos = $this->ytr($this->data_min[$row]); - ImageLine($this->img, $xpos, $this->plot_area[1], $xpos, $ypos, $style); + ImageLine($this->img, intval($xpos), intval($this->plot_area[1]), intval($xpos), intval($ypos), intval($style)); } - return TRUE; + return true; } /** @@ -6388,17 +6950,17 @@ protected function DrawYDataLine($ypos, $row) if ($this->y_data_label_pos == 'both') { // Lines from the left side to the right side - ImageLine($this->img, $this->plot_area[0], $ypos, $this->plot_area[2], $ypos, $style); + ImageLine($this->img, intval($this->plot_area[0]), intval($ypos), intval($this->plot_area[2]), intval($ypos), intval($style)); } elseif ($this->y_data_label_pos == 'plotleft' && isset($this->data_max[$row])) { // Lines from the left of the plot rightwards the max X value at this Y: $xpos = $this->xtr($this->data_max[$row]); - ImageLine($this->img, $xpos, $ypos, $this->plot_area[0], $ypos, $style); + ImageLine($this->img, intval($xpos), intval($ypos), intval($this->plot_area[0]), intval($ypos), intval($style)); } elseif ($this->y_data_label_pos == 'plotright' && isset($this->data_min[$row])) { // Lines from the right of the plot leftwards to the min X value at this Y: $xpos = $this->xtr($this->data_min[$row]); - ImageLine($this->img, $this->plot_area[2], $ypos, $xpos, $ypos, $style); + ImageLine($this->img, intval($this->plot_area[2]), intval($ypos), intval($xpos), intval($ypos), intval($style)); } - return TRUE; + return true; } /** @@ -6416,17 +6978,17 @@ protected function FormatPieLabel($index, $pie_label_source, $arc_angle, $slice_ $values = array(); // Builds up label value, one field at a time. foreach ($pie_label_source as $word) { switch ($word) { - case 'label': // Use label from data array, but only if data type is compatible - $values[] = $this->datatype_pie_single ? $this->data[$index][0] : ''; - break; - case 'value': // Use actual numeric value of the slice - $values[] = $slice_weight; - break; - case 'index': // Use slice index: 0, 1, 2... - $values[] = $index; - break; - default: // Use percentage: 100% x arc_angle / (360 degrees) = arc_angle / 3.6 - $values[] = $arc_angle / 3.6; + case 'label': // Use label from data array, but only if data type is compatible + $values[] = $this->datatype_pie_single ? $this->data[$index][0] : ''; + break; + case 'value': // Use actual numeric value of the slice + $values[] = $slice_weight; + break; + case 'index': // Use slice index: 0, 1, 2... + $values[] = $index; + break; + default: // Use percentage: 100% x arc_angle / (360 degrees) = arc_angle / 3.6 + $values[] = $arc_angle / 3.6; } } // Format the label and return the result. Note: The conditional avoids a number-to-string @@ -6469,14 +7031,24 @@ protected function DrawPieLabel($label_txt, $xc, $yc, $start_angle, $arc_angle, // shaded area and above. (This isn't perfect at all, but works for reasonably low shading.) if ($this->label_scale_position >= 0.5 && $this->shading > 0 && $sin_mid < 0) { $yoff = min($this->shading, -$sin_mid * $r['y']); - } else $yoff = 0; + } else { + $yoff = 0; + } // Calculate text alignment (h_align, v_align) based on angle: $this->GetTextAlignment($sin_mid, $cos_mid, $h_align, $v_align, $r['reverse']); // Draw the label: - $this->DrawText('generic', 0, $label_x, $label_y + $yoff, $this->ndx_pielabel_color, - $label_txt, $h_align, $v_align); - return TRUE; + $this->DrawText( + 'generic', + 0, + $label_x, + $label_y + $yoff, + $this->ndx_pielabel_color, + $label_txt, + $h_align, + $v_align + ); + return true; } ///////////////////////////////////////////// @@ -6494,17 +7066,19 @@ protected function DrawPieLabel($label_txt, $xc, $yc, $start_angle, $arc_angle, * @param string|string[] $which_leg Array of strings for the legend, or a single string to append * @return bool True always */ - function SetLegend($which_leg) + public function SetLegend($which_leg) { if (is_array($which_leg)) { // use array (or cancel, if empty array) $this->legend = $which_leg; } elseif (!is_null($which_leg)) { // append string - if (!isset($this->legend)) $this->legend = array(); // Seems unnecessary, but be safe. + if (!isset($this->legend)) { + $this->legend = array(); // Seems unnecessary, but be safe. + } $this->legend[] = $which_leg; } else { - $this->legend = NULL; // Reset to no legend. + $this->legend = null; // Reset to no legend. } - return TRUE; + return true; } /** @@ -6514,7 +7088,7 @@ function SetLegend($which_leg) * @param int $which_y Y coordinate in pixels of the upper left corner of the legend box * @return bool True (False on error if an error handler returns True) */ - function SetLegendPixels($which_x=NULL, $which_y=NULL) + public function SetLegendPixels($which_x = null, $which_y = null) { return $this->SetLegendPosition(0, 0, 'image', 0, 0, $which_x, $which_y); } @@ -6526,7 +7100,7 @@ function SetLegendPixels($which_x=NULL, $which_y=NULL) * @param int $which_y World coordinate Y of the upper left corner of the legend box * @return bool True (False on error if an error handler returns True) */ - function SetLegendWorld($which_x, $which_y) + public function SetLegendWorld($which_x, $which_y) { return $this->SetLegendPosition(0, 0, 'world', $which_x, $which_y); } @@ -6557,19 +7131,20 @@ function SetLegendWorld($which_x, $which_y) * @return bool True (False on error if an error handler returns True) * @since 5.4.0 */ - function SetLegendPosition($x, $y, $relative_to, $x_base, $y_base, $x_offset = 0, $y_offset = 0) + public function SetLegendPosition($x, $y, $relative_to, $x_base, $y_base, $x_offset = 0, $y_offset = 0) { // Special case: NULL means restore the default positioning. if (!isset($x, $y, $x_offset, $y_offset)) { - $this->legend_pos = NULL; + $this->legend_pos = null; } else { $mode = $this->CheckOption($relative_to, 'image, plot, title, world', __FUNCTION__); - if (empty($mode)) - return FALSE; + if (empty($mode)) { + return false; + } // Save all values for use by GetLegendPosition() $this->legend_pos = compact('x', 'y', 'mode', 'x_base', 'y_base', 'x_offset', 'y_offset'); } - return TRUE; + return true; } /** @@ -6580,14 +7155,18 @@ function SetLegendPosition($x, $y, $relative_to, $x_base, $y_base, $x_offset = 0 * @return bool True (False on error if an error handler returns True) * @since 5.0.4 */ - function SetLegendStyle($text_align, $colorbox_align = '') + public function SetLegendStyle($text_align, $colorbox_align = '') { $this->legend_text_align = $this->CheckOption($text_align, 'left, right', __FUNCTION__); - if (empty($colorbox_align)) + if (empty($colorbox_align)) { $this->legend_colorbox_align = $this->legend_text_align; - else - $this->legend_colorbox_align = $this->CheckOption($colorbox_align, 'left, right, none', - __FUNCTION__); + } else { + $this->legend_colorbox_align = $this->CheckOption( + $colorbox_align, + 'left, right, none', + __FUNCTION__ + ); + } return ($this->legend_text_align && $this->legend_colorbox_align); } @@ -6598,10 +7177,10 @@ function SetLegendStyle($text_align, $colorbox_align = '') * @return bool True always * @since 5.4.0 */ - function SetLegendUseShapes($use_shapes) + public function SetLegendUseShapes($use_shapes) { $this->legend_use_shapes = (bool)$use_shapes; - return TRUE; + return true; } /** @@ -6611,10 +7190,10 @@ function SetLegendUseShapes($use_shapes) * @return bool True always * @since 5.5.0 */ - function SetLegendReverse($reversal = False) + public function SetLegendReverse($reversal = false) { $this->legend_reverse_order = (bool)$reversal; - return TRUE; + return true; } /** @@ -6624,11 +7203,14 @@ function SetLegendReverse($reversal = False) * @return bool True (False on error if an error handler returns True) * @since 6.0.0 */ - function SetLegendColorboxBorders($cbbmode = 'textcolor') + public function SetLegendColorboxBorders($cbbmode = 'textcolor') { - $this->legend_colorbox_borders = $this->CheckOption($cbbmode, 'none, textcolor, databordercolor', - __FUNCTION__); - return (boolean)$this->legend_colorbox_borders; + $this->legend_colorbox_borders = $this->CheckOption( + $cbbmode, + 'none, textcolor, databordercolor', + __FUNCTION__ + ); + return (bool)$this->legend_colorbox_borders; } /** @@ -6638,10 +7220,10 @@ function SetLegendColorboxBorders($cbbmode = 'textcolor') * @return bool True always * @since 6.2.1 */ - function SetDrawLegendBorder($draw) + public function SetDrawLegendBorder($draw) { $this->draw_legend_border = (bool)$draw; - return TRUE; + return true; } /** @@ -6651,10 +7233,10 @@ function SetDrawLegendBorder($draw) * @return bool True (False on error if an error handler returns True) * @since 6.2.1 */ - function SetLegendBorderColor($border_color) - { + public function SetLegendBorderColor($border_color) + { return (bool)($this->legend_border_color = $this->SetRGBColor($border_color)); - } + } /** * Calculates legend sizing parameters @@ -6682,7 +7264,9 @@ protected function GetLegendSizeParams() $max_width = 0; foreach ($this->legend as $line) { list($width, $unused) = $this->SizeText('legend', 0, $line); - if ($width > $max_width) $max_width = $width; + if ($width > $max_width) { + $max_width = $width; + } } // Font parameters are used to size the color boxes: @@ -6693,7 +7277,7 @@ protected function GetLegendSizeParams() // Get color-box mode. Note GetLegendSizeParams can be called from GetLegendSize, and not all // settings are defined then, but the colorbox_mode won't be used then so it need not be valid. if ($this->legend_colorbox_align == 'none') { - $colorbox_mode = False; // Color boxes are off + $colorbox_mode = false; // Color boxes are off } elseif (!$this->legend_use_shapes || empty(self::$plots[$this->plot_type]['legend_alt_marker'])) { $colorbox_mode = 'box'; // Not using shapes, or plot type defines no shape, so use boxes. } else { @@ -6706,8 +7290,9 @@ protected function GetLegendSizeParams() $colorbox_width = $char_w * $this->legend_colorbox_width; // Color box width, with adjustment // The 'line' style marker needs a wider colorbox than shape or box. - if ($colorbox_mode == 'line') + if ($colorbox_mode == 'line') { $colorbox_width *= 4; + } // Calculate overall legend box width and height. // Width is e.g.: "| space colorbox space text space |" where each space adds $char_w, @@ -6719,8 +7304,16 @@ protected function GetLegendSizeParams() } $height = $dot_height * count($this->legend) + 2 * $v_margin; - return compact('width', 'height', 'char_w', 'char_h', 'v_margin', - 'colorbox_mode', 'dot_height', 'colorbox_width'); + return compact( + 'width', + 'height', + 'char_w', + 'char_h', + 'v_margin', + 'colorbox_mode', + 'dot_height', + 'colorbox_width' + ); } /** @@ -6729,10 +7322,11 @@ protected function GetLegendSizeParams() * @return int[] Legend box size as array of (width, height) in pixels, False if no legend defined. * @since 5.4.0 */ - function GetLegendSize() + public function GetLegendSize() { - if (empty($this->legend)) - return FALSE; + if (empty($this->legend)) { + return false; + } $params = $this->GetLegendSizeParams(); return array($params['width'], $params['height']); } @@ -6751,37 +7345,37 @@ function GetLegendSize() protected function GetLegendPosition($width, $height) { // Extract variables set by SetLegend*(): $mode, $x, $y, $x_base, $y_base, $x_offset, $y_offset - if (isset($this->legend_pos['mode'])) + if (isset($this->legend_pos['mode'])) { extract($this->legend_pos); - else + } else { $mode = ''; // Default legend position mode. + } switch ($mode) { - - case 'plot': // SetLegendPosition with mode='plot', relative coordinates over plot area. - return array((int)($x_base * $this->plot_area_width - $x * $width) + case 'plot': // SetLegendPosition with mode='plot', relative coordinates over plot area. + return array((int)($x_base * $this->plot_area_width - $x * $width) + $this->plot_area[0] + $x_offset, (int)($y_base * $this->plot_area_height - $y * $height) + $this->plot_area[1] + $y_offset); - case 'world': // User-defined position in world-coordinates (SetLegendWorld), using x_base, y_base - return array($this->xtr($x_base) + $x_offset - (int)($x * $width), + case 'world': // User-defined position in world-coordinates (SetLegendWorld), using x_base, y_base + return array($this->xtr($x_base) + $x_offset - (int)($x * $width), $this->ytr($y_base) + $y_offset - (int)($y * $height)); - case 'image': // SetLegendPosition with mode='image', relative coordinates over image area. + case 'image': // SetLegendPosition with mode='image', relative coordinates over image area. // SetLegendPixels() uses this too, with x=y=0. - return array((int)($x_base * $this->image_width - $x * $width) + $x_offset, + return array((int)($x_base * $this->image_width - $x * $width) + $x_offset, (int)($y_base * $this->image_height - $y * $height) + $y_offset); - case 'title': // SetLegendPosition with mode='title', relative to main title. - // Recalculate main title position/size, since CalcMargins does not save it. See DrawTitle() - list($title_width, $title_height) = $this->SizeText('title', 0, $this->title_txt); - $title_x = (int)(($this->image_width - $title_width) / 2); - return array((int)($x_base * $title_width - $x * $width) + $title_x + $x_offset, + case 'title': // SetLegendPosition with mode='title', relative to main title. + // Recalculate main title position/size, since CalcMargins does not save it. See DrawTitle() + list($title_width, $title_height) = $this->SizeText('title', 0, $this->title_txt); + $title_x = (int)(($this->image_width - $title_width) / 2); + return array((int)($x_base * $title_width - $x * $width) + $title_x + $x_offset, (int)($y_base * $title_height - $y * $height) + $this->title_offset + $y_offset); - default: // If mode is unset (or invalid), use default position. - return array ($this->plot_area[2] - $width - $this->safe_margin, + default: // If mode is unset (or invalid), use default position. + return array ($this->plot_area[2] - $width - $this->safe_margin, $this->plot_area[1] + $this->safe_margin); } } @@ -6803,34 +7397,49 @@ protected function DrawLegend() $box_end_x = $box_start_x + $width; // Draw outer box - ImageFilledRectangle($this->img, $box_start_x, $box_start_y, $box_end_x, $box_end_y, - $this->ndx_legend_bg_color); + ImageFilledRectangle( + $this->img, + intval($box_start_x), + intval($box_start_y), + intval($box_end_x), + intval($box_end_y), + intval($this->ndx_legend_bg_color) + ); if ($this->draw_legend_border) { - ImageRectangle($this->img, $box_start_x, $box_start_y, $box_end_x, $box_end_y, - $this->ndx_legend_border_color); + ImageRectangle( + $this->img, + intval($box_start_x), + intval($box_start_y), + intval($box_end_x), + intval($box_end_y), + intval($this->ndx_legend_border_color) + ); } // Calculate color box and text horizontal positions. if (!$colorbox_mode) { - if ($this->legend_text_align == 'left') + if ($this->legend_text_align == 'left') { $x_pos = $box_start_x + $char_w; - else + } else { $x_pos = $box_end_x - $char_w; + } $dot_left_x = 0; // Not used directly if color boxes/shapes are off, but referenced below. } elseif ($this->legend_colorbox_align == 'left') { $dot_left_x = $box_start_x + $char_w; $dot_right_x = $dot_left_x + $colorbox_width; - if ($this->legend_text_align == 'left') + if ($this->legend_text_align == 'left') { $x_pos = $dot_right_x + $char_w; - else + } else { $x_pos = $box_end_x - $char_w; + } } else { // colorbox_align == 'right' $dot_right_x = $box_end_x - $char_w; $dot_left_x = $dot_right_x - $colorbox_width; - if ($this->legend_text_align == 'left') + if ($this->legend_text_align == 'left') { $x_pos = $box_start_x + $char_w; - else + } else { $x_pos = $dot_left_x - $char_w; + } } // $y_pos is the bottom of each color box. $yc is the vertical center of the color box or @@ -6859,53 +7468,80 @@ protected function DrawLegend() foreach ($this->legend as $leg) { // Draw text with requested alignment: - $this->DrawText('legend', 0, $x_pos, $yc, $this->ndx_legend_text_color, $leg, - $this->legend_text_align, 'center'); + $this->DrawText( + 'legend', + 0, + $x_pos, + $yc, + $this->ndx_legend_text_color, + $leg, + $this->legend_text_align, + 'center' + ); if ($colorbox_mode) { $y1 = $y_pos - $dot_height + 1; $y2 = $y_pos - 1; // If plot area background is on, draw a background for any non-box shapes: if ($this->draw_plot_area_background && $colorbox_mode != 'box') { - ImageFilledRectangle($this->img, $dot_left_x, $y1, $dot_right_x, $y2, - $this->ndx_plot_bg_color); + ImageFilledRectangle( + $this->img, + intval($dot_left_x), + intval($y1), + intval($dot_right_x), + intval($y2), + intval($this->ndx_plot_bg_color) + ); } switch ($colorbox_mode) { - case 'shape': - // Draw the shape. DrawShape() takes shape_index modulo number of defined shapes. - $this->DrawShape($xc, $yc, $shape_index++, $this->ndx_data_colors[$color_index], FALSE); - break; - - case 'line': - // Draw a short line segment with proper color, width, and style - imagesetthickness($this->img, $this->line_widths[$lws_index]); - $style = $this->SetDashedStyle($this->ndx_data_colors[$color_index], - $this->line_styles[$lws_index] == 'dashed'); - imageline($this->img, $dot_left_x, $yc, $dot_right_x, $yc, $style); - imagesetthickness($this->img, 1); - if (++$lws_index >= $this->data_columns) $lws_index = 0; // Wrap around - break; - - default: - // Draw color boxes: - ImageFilledRectangle($this->img, $dot_left_x, $y1, $dot_right_x, $y2, - $this->ndx_data_colors[$color_index]); - // Draw a rectangle around the box, if enabled. - if ($this->legend_colorbox_borders != 'none') { - if ($this->legend_colorbox_borders == 'databordercolor') - $color = $this->ndx_data_border_colors[$color_index]; - else - $color = $this->ndx_text_color; - ImageRectangle($this->img, $dot_left_x, $y1, $dot_right_x, $y2, $color); - } + case 'shape': + // Draw the shape. DrawShape() takes shape_index modulo number of defined shapes. + $this->DrawShape($xc, $yc, $shape_index++, $this->ndx_data_colors[$color_index], false); + break; + + case 'line': + // Draw a short line segment with proper color, width, and style + imagesetthickness($this->img,intval($this->line_widths[$lws_index])); + $style = $this->SetDashedStyle( + $this->ndx_data_colors[$color_index], + $this->line_styles[$lws_index] == 'dashed' + ); + imageline($this->img, intval($dot_left_x), intval($yc), intval($dot_right_x), intval($yc), intval($style)); + imagesetthickness($this->img,1); + if (++$lws_index >= $this->data_columns) { + $lws_index = 0; // Wrap around + } + break; + + default: + // Draw color boxes: + ImageFilledRectangle( + $this->img, + intval($dot_left_x), + intval($y1), + intval($dot_right_x), + intval($y2), + $this->ndx_data_colors[$color_index] + ); + // Draw a rectangle around the box, if enabled. + if ($this->legend_colorbox_borders != 'none') { + if ($this->legend_colorbox_borders == 'databordercolor') { + $color = $this->ndx_data_border_colors[$color_index]; + } else { + $color = $this->ndx_text_color; + } + ImageRectangle($this->img,intval( $dot_left_x), intval($y1), intval($dot_right_x), intval($y2), intval($color)); + } + } + if (++$color_index > $max_color_index) { + $color_index = 0; } - if (++$color_index > $max_color_index) $color_index = 0; } $y_pos += $delta_y; $yc += $delta_y; } - return TRUE; + return true; } ///////////////////////////////////////////// @@ -6996,8 +7632,9 @@ protected function GetBarColors($row, $idx, &$vars, &$data_color, &$shade_color, { // Initialize or extract this functions persistant state variables: if (empty($vars)) { - if (($shaded = ($this->shading > 0))) + if (($shaded = ($this->shading > 0))) { $this->NeedDataDarkColors(); // Plot needs dark colors for shading + } $custom_color = (bool)$this->GetCallback('data_color'); $num_data_colors = count($this->ndx_data_colors); $num_border_colors = count($this->ndx_data_border_colors); @@ -7018,8 +7655,8 @@ protected function GetBarColors($row, $idx, &$vars, &$data_color, &$shade_color, $i_data = $i_border = $idx; } $data_color = $this->ndx_data_colors[$i_data]; - $shade_color = $shaded ? $this->ndx_data_dark_colors[$i_data] : NULL; - $border_color = $borders ? $this->ndx_data_border_colors[$i_border] : NULL; + $shade_color = $shaded ? $this->ndx_data_dark_colors[$i_data] : null; + $border_color = $borders ? $this->ndx_data_border_colors[$i_border] : null; } /** @@ -7034,8 +7671,9 @@ protected function GetBarColors($row, $idx, &$vars, &$data_color, &$shade_color, */ protected function GetGridSetting($xy) { - if ($xy == 'x') + if ($xy == 'x') { return isset($this->draw_x_grid) ? $this->draw_x_grid : $this->datatype_swapped_xy; + } // Assumed 'y' return isset($this->draw_y_grid) ? $this->draw_y_grid : !$this->datatype_swapped_xy; } @@ -7054,7 +7692,7 @@ protected function GetGridSetting($xy) * @return bool True always * @since 5.4.0 */ - protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE) + protected function DrawShape($x, $y, $record, $color, $allow_none = true) { $index = $record % $this->point_counts; $point_size = $this->point_sizes[$index]; @@ -7066,85 +7704,88 @@ protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE) $y2 = $y + $half_point; switch ($this->point_shapes[$index]) { - case 'halfline': - ImageLine($this->img, $x1, $y, $x, $y, $color); - break; - case 'none': /* Special case, no point shape here */ - if ($allow_none) break; // But fall throught to line if a shape is required - case 'line': - ImageLine($this->img, $x1, $y, $x2, $y, $color); - break; - case 'plus': - ImageLine($this->img, $x1, $y, $x2, $y, $color); - ImageLine($this->img, $x, $y1, $x, $y2, $color); - break; - case 'cross': - ImageLine($this->img, $x1, $y1, $x2, $y2, $color); - ImageLine($this->img, $x1, $y2, $x2, $y1, $color); - break; - case 'circle': - ImageArc($this->img, $x, $y, $point_size, $point_size, 0, 360, $color); - break; - case 'dot': - ImageFilledEllipse($this->img, $x, $y, $point_size, $point_size, $color); - break; - case 'diamond': - $arrpoints = array($x1, $y, $x, $y1, $x2, $y, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); - break; - case 'triangle': - $arrpoints = array($x1, $y, $x2, $y, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); - break; - case 'trianglemid': - $arrpoints = array($x1, $y1, $x2, $y1, $x, $y); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); - break; - case 'yield': - $arrpoints = array($x1, $y1, $x2, $y1, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); - break; - case 'delta': - $arrpoints = array($x1, $y2, $x2, $y2, $x, $y1); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); - break; - case 'star': - ImageLine($this->img, $x1, $y, $x2, $y, $color); - ImageLine($this->img, $x, $y1, $x, $y2, $color); - ImageLine($this->img, $x1, $y1, $x2, $y2, $color); - ImageLine($this->img, $x1, $y2, $x2, $y1, $color); - break; - case 'hourglass': - $arrpoints = array($x1, $y1, $x2, $y1, $x1, $y2, $x2, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); - break; - case 'bowtie': - $arrpoints = array($x1, $y1, $x1, $y2, $x2, $y1, $x2, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); - break; - case 'target': - ImageFilledRectangle($this->img, $x1, $y1, $x, $y, $color); - ImageFilledRectangle($this->img, $x, $y, $x2, $y2, $color); - ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color); - break; - case 'box': - ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color); - break; - case 'home': /* As in: "home plate" (baseball), also looks sort of like a house. */ - $arrpoints = array($x1, $y2, $x2, $y2, $x2, $y, $x, $y1, $x1, $y); - ImageFilledPolygon($this->img, $arrpoints, 5, $color); - break; - case 'up': - ImagePolygon($this->img, array($x, $y1, $x2, $y2, $x1, $y2), 3, $color); - break; - case 'down': - ImagePolygon($this->img, array($x, $y2, $x1, $y1, $x2, $y1), 3, $color); - break; - default: /* Also 'rect' */ - ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color); - break; - } - return TRUE; + case 'halfline': + ImageLine($this->img, intval($x1), intval($y), intval($x), intval($y), intval($color)); + break; + case 'none': /* Special case, no point shape here */ + if ($allow_none) { + break; // But fall throught to line if a shape is required + } + //no break + case 'line': + ImageLine($this->img, intval($x1), intval($y), intval($x2), intval($y), intval($color)); + break; + case 'plus': + ImageLine($this->img, intval($x1), intval($y ), intval($x2), intval($y ), intval($color)); + ImageLine($this->img, intval($x ), intval($y1), intval($x ), intval($y2), intval($color)); + break; + case 'cross': + ImageLine($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($color)); + ImageLine($this->img, intval($x1), intval($y2), intval($x2), intval($y1), intval($color)); + break; + case 'circle': + ImageArc($this->img, $x, $y, $point_size, $point_size, 0, 360, $color); + break; + case 'dot': + ImageFilledEllipse($this->img, $x, $y, $point_size, $point_size, $color); + break; + case 'diamond': + $arrpoints = array($x1, $y, $x, $y1, $x2, $y, $x, $y2); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'triangle': + $arrpoints = array($x1, $y, $x2, $y, $x, $y2); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'trianglemid': + $arrpoints = array($x1, $y1, $x2, $y1, $x, $y); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'yield': + $arrpoints = array($x1, $y1, $x2, $y1, $x, $y2); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'delta': + $arrpoints = array($x1, $y2, $x2, $y2, $x, $y1); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'star': + ImageLine($this->img, intval($x1), intval($y ), intval($x2), intval($y ), intval($color)); + ImageLine($this->img, intval($x), intval($y1), intval($x ), intval($y2), intval($color)); + ImageLine($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($color)); + ImageLine($this->img, intval($x1), intval($y2), intval($x2), intval($y1), intval($color)); + break; + case 'hourglass': + $arrpoints = array($x1, $y1, $x2, $y1, $x1, $y2, $x2, $y2); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'bowtie': + $arrpoints = array($x1, $y1, $x1, $y2, $x2, $y1, $x2, $y2); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'target': + ImageFilledRectangle($this->img, intval($x1), intval($y1), intval($x), intval($y), intval($color)); + ImageFilledRectangle($this->img, intval($x), intval($y), intval($x2), intval($y2), intval($color)); + ImageRectangle($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($color)); + break; + case 'box': + ImageRectangle($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($color)); + break; + case 'home': /* As in: "home plate" (baseball), also looks sort of like a house. */ + $arrpoints = array($x1, $y2, $x2, $y2, $x2, $y, $x, $y1, $x1, $y); + ImageFilledPolygon($this->img, $arrpoints, $color); + break; + case 'up': + ImagePolygon($this->img, array($x, $y1, $x2, $y2, $x1, $y2), 3, $color); + break; + case 'down': + ImagePolygon($this->img, array($x, $y2, $x1, $y1, $x2, $y1), 3, $color); + break; + default: /* Also 'rect' */ + ImageFilledRectangle($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($color)); + break; + } + return true; } /** @@ -7188,20 +7829,34 @@ protected function DrawDot($row, $column, $x_world, $y_world, $color) * @return bool True always * @since 5.2.0 */ - protected function DrawBar($row, $column, $x1, $y1, $x2, $y2, $data_color, $shade_color, $border_color, - $shade_top = TRUE, $shade_side = TRUE) - { + protected function DrawBar( + $row, + $column, + $x1, + $y1, + $x2, + $y2, + $data_color, + $shade_color, + $border_color, + $shade_top = true, + $shade_side = true + ) { // Sort the points so x1,y1 is upper left and x2,y2 is lower right. This // is needed in order to get the shading right, and imagerectangle may require it. if ($x1 > $x2) { - $t = $x1; $x1 = $x2; $x2 = $t; + $t = $x1; + $x1 = $x2; + $x2 = $t; } if ($y1 > $y2) { - $t = $y1; $y1 = $y2; $y2 = $t; + $t = $y1; + $y1 = $y2; + $y2 = $t; } // Draw the bar - ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $data_color); + ImageFilledRectangle($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($data_color)); // Draw a shade, if shading is on. if (isset($shade_color)) { @@ -7214,19 +7869,20 @@ protected function DrawBar($row, $column, $x1, $y1, $x2, $y2, $data_color, $shad } else { // Suppress top shading (Note shade_top==FALSE && shade_side==FALSE is not allowed) $pts = array($x2, $y2, $x2, $y1, $x2 + $shade, $y1 - $shade, $x2 + $shade, $y2 - $shade); } - ImageFilledPolygon($this->img, $pts, count($pts) / 2, $shade_color); + ImageFilledPolygon($this->img, $pts, $shade_color); } // Draw a border around the bar, if enabled. if (isset($border_color)) { // Avoid a PHP/GD bug with zero-height ImageRectangle resulting in "T"-shaped ends. - if ($y1 == $y2) - imageline($this->img, $x1, $y1, $x2, $y2, $border_color); - else - imagerectangle($this->img, $x1, $y1, $x2, $y2, $border_color); + if ($y1 == $y2) { + imageline($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($border_color)); + } else { + imagerectangle($this->img, intval($x1), intval($y1), intval($x2), intval($y2), intval($border_color)); + } } $this->DoCallback('data_points', 'rect', $row, $column, $x1, $y1, $x2, $y2); - return TRUE; + return true; } /** @@ -7247,15 +7903,15 @@ protected function DrawXErrorBars($x, $y, $error_plus, $error_minus, $color) $x2p = $this->xtr($x + $error_plus); $x2m = $this->xtr($x - $error_minus); - imagesetthickness($this->img, $this->error_bar_line_width); - imageline($this->img, $x2p, $y1 , $x2m, $y1, $color); + imagesetthickness($this->img,intval($this->error_bar_line_width)); + imageline($this->img, intval($x2p), intval($y1), intval($x2m), intval($y1), intval($color)); if ($this->error_bar_shape == 'tee') { $e = $this->error_bar_size; - imageline($this->img, $x2p, $y1 - $e, $x2p, $y1 + $e, $color); - imageline($this->img, $x2m, $y1 - $e, $x2m, $y1 + $e, $color); + imageline($this->img, intval($x2p), intval($y1 - $e), intval($x2p), intval($y1 + $e), intval($color)); + imageline($this->img, intval($x2m), intval($y1 - $e), intval($x2m), intval($y1 + $e), intval($color)); } - imagesetthickness($this->img, 1); - return TRUE; + imagesetthickness($this->img,1); + return true; } /** @@ -7276,15 +7932,15 @@ protected function DrawYErrorBars($x, $y, $error_plus, $error_minus, $color) $y2p = $this->ytr($y + $error_plus); $y2m = $this->ytr($y - $error_minus); - imagesetthickness($this->img, $this->error_bar_line_width); - imageline($this->img, $x1, $y2p , $x1, $y2m, $color); + imagesetthickness($this->img,intval($this->error_bar_line_width)); + imageline($this->img, intval($x1), intval($y2p), intval($x1), intval($y2m), intval($color)); if ($this->error_bar_shape == 'tee') { $e = $this->error_bar_size; - imageline($this->img, $x1 - $e, $y2p, $x1 + $e, $y2p, $color); - imageline($this->img, $x1 - $e, $y2m, $x1 + $e, $y2m, $color); + imageline($this->img, intval($x1 - $e), intval($y2p), intval($x1 + $e), intval($y2p),intval( $color)); + imageline($this->img, intval($x1 - $e), intval($y2m), intval($x1 + $e), intval($y2m),intval( $color)); } - imagesetthickness($this->img, 1); - return TRUE; + imagesetthickness($this->img,1); + return true; } /** @@ -7335,38 +7991,45 @@ protected function SetupAreaPlot($stacked, &$xd, &$yd) for ($row = 0; $row < $this->num_data_rows; $row++) { $rec = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied X values? + if ($this->datatype_implied) { // Implied X values? $x_now = 0.5 + $row; // Place text-data at X = 0.5, 1.5, 2.5, etc... - else + } else { $x_now = $this->data[$row][$rec++]; // Read it, advance record index + } $xd[$row] = $x_now_pixels = $this->xtr($x_now); // Save in device coordinates - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } // There is an artificial Y value at the X axis. For stacked plots, it goes before the // first real Y, so the first area fill is from the axis to the first Y data set. // For non-stacked plots, it goes after the last Y, so the last area fill is from axis // to the last Y data set. - if ($stacked) + if ($stacked) { $yd[$row] = array($this->x_axis_y_pixels); - else + } else { $yd[$row] = array(); + } // Store the Y values for this X. Missing Y values are not supported, and are replaced with 0. // Negative numbers are not supported, and are replaced with absolute values. // The resulting numbers are also clipped to the X axis' Y value (which can be > 0). $y = 0; // Accumulate (if not reset below) the Y values for ($idx = 0; $rec < $this->records_per_group; $rec++, $idx++) { - if (is_numeric($y_now = $this->data[$row][$rec])) + if (is_numeric($y_now = $this->data[$row][$rec])) { $y += abs($y_now); + } $yd[$row][] = $this->ytr(max($this->x_axis_position, $y)); - if (!$stacked) $y = 0; // For non-stacked plots, reset Y in each loop. + if (!$stacked) { + $y = 0; // For non-stacked plots, reset Y in each loop. + } } // See above: For non-stacked plots, the Y value for X axis goes at the end. - if (!$stacked) + if (!$stacked) { $yd[$row][] = $this->x_axis_y_pixels; + } } return ($this->data_columns + 1); // This is the size of each yd[][] } @@ -7385,10 +8048,10 @@ protected function SetupAreaPlot($stacked, &$xd, &$yd) * @return bool True always * @since 6.2.0 */ - function DrawAreaFillBorders($n_columns, $xd, $yd, $stacked, $stepped) - { + public function DrawAreaFillBorders($n_columns, $xd, $yd, $stacked, $stepped) + { for ($col = 1; $col < $n_columns; $col++) { - $color = $this->ndx_data_border_colors[$col-1]; + $color = $this->ndx_data_border_colors[$col - 1]; // This is due to the difference in the $yd array for stacked and unstacked. if ($stacked) { $this_col = $col; // Border follows column = 1 to N-1 @@ -7401,7 +8064,7 @@ function DrawAreaFillBorders($n_columns, $xd, $yd, $stacked, $stepped) // Left edge: $x = $xd[0]; $y = $yd[0][$this_col]; - ImageLine($this->img, $x, $yd[0][$other_col], $x, $y, $color); + ImageLine($this->img, intval($x), intval($yd[0][$other_col]), intval($x), intval($y), intval($color)); // Across the top, with an 'X then Y' step at each point: for ($row = 1; $row < $this->num_data_rows; $row++) { @@ -7410,18 +8073,18 @@ function DrawAreaFillBorders($n_columns, $xd, $yd, $stacked, $stepped) $x = $xd[$row]; $y = $yd[$row][$this_col]; if ($stepped) { - ImageLine($this->img, $prev_x, $prev_y, $x, $prev_y, $color); - ImageLine($this->img, $x, $prev_y, $x, $y, $color); + ImageLine($this->img, intval($prev_x), intval($prev_y), intval($x), intval($prev_y),intval( $color)); + ImageLine($this->img, intval($x ), intval($prev_y), intval($x), intval( $y), intval($color)); } else { - ImageLine($this->img, $prev_x, $prev_y, $x, $y, $color); + ImageLine($this->img, intval($prev_x), intval($prev_y), intval($x), intval($y), intval($color)); } } // Right edge: - ImageLine($this->img, $x, $y, $x, $yd[$this->num_data_rows - 1][$other_col], $color); + ImageLine($this->img, intval($x), intval($y), intval($x), intval($yd[$this->num_data_rows - 1][$other_col]), intval($color)); } - return TRUE; - } + return true; + } ///////////////////////////////////////////// //////////////////// PLOT DRAWING @@ -7457,8 +8120,9 @@ function DrawAreaFillBorders($n_columns, $xd, $yd, $stacked, $stepped) protected function DrawPieChart() { // Early checks and initialization: - if (!$this->CheckDataType('text-data, text-data-single, data-data')) - return FALSE; + if (!$this->CheckDataType('text-data, text-data-single, data-data')) { + return false; + } // SetLabelScalePosition(0 or FALSE) means no labels. $do_labels = !empty($this->label_scale_position); @@ -7483,19 +8147,22 @@ protected function DrawPieChart() } // Pie center point is always the center of the plot area, regardless of label sizes. - $xpos = $this->plot_area[0] + $this->plot_area_width/2; - $ypos = $this->plot_area[1] + $this->plot_area_height/2; + $xpos = $this->plot_area[0] + $this->plot_area_width / 2; + $ypos = $this->plot_area[1] + $this->plot_area_height / 2; // Reduce the data array into sumarr[], accounting for the data type: $num_slices = $this->data_columns; // See CheckDataArray which calculates this for us. - if ($num_slices < 1) return TRUE; // Give up early if there is no data at all. + if ($num_slices < 1) { + return true; // Give up early if there is no data at all. + } $sumarr = array_fill(0, $num_slices, 0); // Initialize array of per-sector sums. if ($this->datatype_pie_single) { // text-data-single: One data column per row, one pie slice per row. for ($i = 0; $i < $num_slices; $i++) { - if (is_numeric($val = $this->data[$i][1])) + if (is_numeric($val = $this->data[$i][1])) { $sumarr[$i] = abs($val); + } } } else { // text-data: Sum each column (skipping label), one pie slice per column. @@ -7503,8 +8170,9 @@ protected function DrawPieChart() $skip = ($this->datatype_implied) ? 1 : 2; // Leading values to skip in each row. for ($i = 0; $i < $this->num_data_rows; $i++) { for ($j = $skip; $j < $this->num_recs[$i]; $j++) { - if (is_numeric($val = $this->data[$i][$j])) - $sumarr[$j-$skip] += abs($val); + if (is_numeric($val = $this->data[$i][$j])) { + $sumarr[$j - $skip] += abs($val); + } } } } @@ -7513,7 +8181,7 @@ protected function DrawPieChart() if ($total == 0) { // There are either no valid data points, or all are 0. // See top comment about why not to make this an error. - return TRUE; + return true; } // Pre-calculate the label strings, if labels are on. Also get the maximum height and width @@ -7545,8 +8213,12 @@ protected function DrawPieChart() $labels[$j] = $this->FormatPieLabel($j, $pie_label_source, $arc_angle, $slice_weight); if ($labels_outside) { // Labels are outside the pie chart list($width, $height) = $this->SizeText('generic', 0, $labels[$j]); - if ($width > $label_max_width) $label_max_width = $width; - if ($height > $label_max_height) $label_max_height = $height; + if ($width > $label_max_width) { + $label_max_width = $width; + } + if ($height > $label_max_height) { + $label_max_height = $height; + } } } } @@ -7571,12 +8243,14 @@ protected function DrawPieChart() $avail_width = min( ($this->plot_area_width / 2 - $label_max_width - $this->safe_margin) / $this->label_scale_position, - $this->plot_area_width - 4 * $this->safe_margin - 2 * $label_max_width); + $this->plot_area_width - 4 * $this->safe_margin - 2 * $label_max_width + ); $avail_height = min( - ($this->plot_area_height / 2 - $label_max_height - $this->safe_margin - $this->shading) / + ($this->plot_area_height / 2 - $label_max_height - $this->safe_margin - $this->shading) / $this->label_scale_position, - $this->plot_area_height - 4*$this->safe_margin - 2*($label_max_height + $this->shading)); + $this->plot_area_height - 4 * $this->safe_margin - 2 * ($label_max_height + $this->shading) + ); // Sanity check - don't let large labels shrink the pie too much. $avail_width = max($avail_width, $this->pie_min_size_factor * $this->plot_area_width); @@ -7626,10 +8300,11 @@ protected function DrawPieChart() $arc_angle = 360 * $slice_weight / $total; // For shaded pies: the last one (at the top of the "stack") has a brighter color: - if ($h == 0) + if ($h == 0) { $slicecol = $this->ndx_data_colors[$color_index]; - else + } else { $slicecol = $this->ndx_data_dark_colors[$color_index]; + } // Calculate the two angles that define this pie segment. // Note that regardless of the direction (CW or CCW), start_angle < end_angle. @@ -7648,31 +8323,60 @@ protected function DrawPieChart() // Don't try to draw a 0 degree slice - it would make a full circle. if ($arc_start_angle > $arc_end_angle) { // Draw the slice - ImageFilledArc($this->img, $xpos, $ypos+$h, $pie_width, $pie_height, - $arc_end_angle, $arc_start_angle, $slicecol, IMG_ARC_PIE); + ImageFilledArc( + $this->img, + $xpos, + $ypos + $h, + $pie_width, + $pie_height, + $arc_end_angle, + $arc_start_angle, + $slicecol, + IMG_ARC_PIE + ); // Processing to do only for the last (if shaded) or only (if unshaded) loop: if ($h == 0) { // Draw the pie segment outline (if enabled): if ($do_borders) { - ImageFilledArc($this->img, $xpos, $ypos, $pie_width, $pie_height, - $arc_end_angle, $arc_start_angle, $this->ndx_pieborder_color, - IMG_ARC_PIE | IMG_ARC_EDGED |IMG_ARC_NOFILL); + ImageFilledArc( + $this->img, + $xpos, + $ypos, + $pie_width, + $pie_height, + $arc_end_angle, + $arc_start_angle, + $this->ndx_pieborder_color, + IMG_ARC_PIE | IMG_ARC_EDGED | IMG_ARC_NOFILL + ); } // Draw the label: - if ($do_labels) + if ($do_labels) { $this->DrawPieLabel($labels[$j], $xpos, $ypos, $start_angle, $arc_angle, $r); + } // Trigger a data points callback; note it gets the calculated (reversed) angles: - $this->DoCallback('data_points', 'pie', $j, 0, $xpos, $ypos, $pie_width, - $pie_height, $arc_start_angle, $arc_end_angle); + $this->DoCallback( + 'data_points', + 'pie', + $j, + 0, + $xpos, + $ypos, + $pie_width, + $pie_height, + $arc_start_angle, + $arc_end_angle + ); } } - if (++$color_index >= $max_data_colors) + if (++$color_index >= $max_data_colors) { $color_index = 0; + } } // end loop for each slice } // end loop for each level of shading - return TRUE; + return true; } /** @@ -7691,11 +8395,14 @@ protected function DrawPieChart() * @param bool $paired True if doing a linepoints plot, False or omit for points plot * @return bool True (False on error if an error handler returns True) */ - protected function DrawDots($paired = FALSE) + protected function DrawDots($paired = false) { - if (!$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx, ' - . 'data-data-error, data-data-yx-error')) - return FALSE; + if ( + !$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx, ' + . 'data-data-error, data-data-yx-error') + ) { + return false; + } // Adjust the point shapes and point sizes arrays: $this->CheckPointParams(); @@ -7707,36 +8414,37 @@ protected function DrawDots($paired = FALSE) // Data labels, Data Value Labels? (Skip if doing the points from a linepoints plot) if ($this->datatype_swapped_xy) { // Horizontal plots can have X Data Value Labels, Y Axis Data Labels - $do_x_axis_labels = FALSE; + $do_x_axis_labels = false; $do_x_valu_labels = !$paired && $this->CheckDataValueLabels($this->x_data_label_pos, $dvl); $do_y_axis_labels = !$paired && $this->y_data_label_pos != 'none'; - $do_y_valu_labels = FALSE; + $do_y_valu_labels = false; } else { // Vertical plots can have X Axis Data Labels, Y Data Value Labels $do_x_axis_labels = !$paired && $this->x_data_label_pos != 'none'; - $do_x_valu_labels = FALSE; - $do_y_axis_labels = FALSE; + $do_x_valu_labels = false; + $do_y_axis_labels = false; $do_y_valu_labels = !$paired && $this->CheckDataValueLabels($this->y_data_label_pos, $dvl); } for ($row = 0; $row < $this->num_data_rows; $row++) { $rec = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied independent variable values? + if ($this->datatype_implied) { // Implied independent variable values? $iv = 0.5 + $row; // Place text-data at 0.5, 1.5, 2.5, etc... - else + } else { $iv = $this->data[$row][$rec++]; // Read it, advance record index + } // Axis data label? - if ($do_x_axis_labels) - $this->DrawXDataLabel($this->data[$row][0], $this->xtr($iv), $row, TRUE); - elseif ($do_y_axis_labels) - $this->DrawYDataLabel($this->data[$row][0], $this->ytr($iv), $row, TRUE); + if ($do_x_axis_labels) { + $this->DrawXDataLabel($this->data[$row][0], $this->xtr($iv), $row, true); + } elseif ($do_y_axis_labels) { + $this->DrawYDataLabel($this->data[$row][0], $this->ytr($iv), $row, true); + } // Proceed with dependent values for ($idx = 0; $rec < $this->num_recs[$row]; $idx++) { if (is_numeric($dv = $this->data[$row][$rec++])) { // Allow for missing data - // Select the color(s): if ($this->datatype_error_bars) { $this->GetDataErrorColors($row, $idx, $gcvars, $data_color, $error_color, $alt_flag); @@ -7748,14 +8456,24 @@ protected function DrawDots($paired = FALSE) if ($this->datatype_swapped_xy) { $this->DrawDot($row, $idx, $dv, $iv, $data_color); if ($this->datatype_error_bars) { - $this->DrawXErrorBars($dv, $iv, $this->data[$row][$rec], - $this->data[$row][$rec+1], $error_color); + $this->DrawXErrorBars( + $dv, + $iv, + $this->data[$row][$rec], + $this->data[$row][$rec + 1], + $error_color + ); } } else { $this->DrawDot($row, $idx, $iv, $dv, $data_color); if ($this->datatype_error_bars) { - $this->DrawYErrorBars($iv, $dv, $this->data[$row][$rec], - $this->data[$row][$rec+1], $error_color); + $this->DrawYErrorBars( + $iv, + $dv, + $this->data[$row][$rec], + $this->data[$row][$rec + 1], + $error_color + ); } } @@ -7771,7 +8489,7 @@ protected function DrawDots($paired = FALSE) } } } - return TRUE; + return true; } /** @@ -7791,54 +8509,70 @@ protected function DrawDots($paired = FALSE) */ protected function DrawThinBarLines() { - if (!$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx')) - return FALSE; + if (!$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx')) { + return false; + } $gcvars = array(); // For GetDataColor, which initializes and uses this. for ($row = 0; $row < $this->num_data_rows; $row++) { $rec = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied independent variable values? + if ($this->datatype_implied) { // Implied independent variable values? $iv_now = 0.5 + $row; // Place text-data at 0.5, 1.5, 2.5, etc... - else + } else { $iv_now = $this->data[$row][$rec++]; // Read it, advance record index + } if ($this->datatype_swapped_xy) { $y_now_pixels = $this->ytr($iv_now); // Draw Y Data labels? - if ($this->y_data_label_pos != 'none') + if ($this->y_data_label_pos != 'none') { $this->DrawYDataLabel($this->data[$row][0], $y_now_pixels, $row); + } } else { $x_now_pixels = $this->xtr($iv_now); // Draw X Data labels? - if ($this->x_data_label_pos != 'none') + if ($this->x_data_label_pos != 'none') { $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } } // Proceed with dependent values for ($idx = 0; $rec < $this->num_recs[$row]; $rec++, $idx++) { if (is_numeric($dv = $this->data[$row][$rec])) { // Allow for missing data - ImageSetThickness($this->img, $this->line_widths[$idx]); + imagesetthickness($this->img,intval($this->line_widths[$idx])); // Select the color: $this->GetDataColor($row, $idx, $gcvars, $data_color); if ($this->datatype_swapped_xy) { // Draw a line from user defined y axis position right (or left) to xtr($dv) - ImageLine($this->img, $this->y_axis_x_pixels, $y_now_pixels, - $this->xtr($dv), $y_now_pixels, $data_color); + ImageLine( + $this->img, + intval($this->y_axis_x_pixels), + intval($y_now_pixels), + intval($this->xtr($dv)), + intval($y_now_pixels), + intval($data_color) + ); } else { // Draw a line from user defined x axis position up (or down) to ytr($dv) - ImageLine($this->img, $x_now_pixels, $this->x_axis_y_pixels, - $x_now_pixels, $this->ytr($dv), $data_color); - } + ImageLine( + $this->img, + intval($x_now_pixels), + intval($this->x_axis_y_pixels), + intval($x_now_pixels), + intval($this->ytr($dv)), + intval($data_color) + ); + } } } } - ImageSetThickness($this->img, 1); - return TRUE; + imagesetthickness($this->img,1); + return true; } /** @@ -7859,19 +8593,22 @@ protected function DrawThinBarLines() * @param bool $do_stacked True for stackedarea plot, false or omit for area plot * @return bool True (False on error if an error handler returns True) */ - protected function DrawArea($do_stacked = FALSE) + protected function DrawArea($do_stacked = false) { - if (!$this->CheckDataType('text-data, data-data')) - return FALSE; + if (!$this->CheckDataType('text-data, data-data')) { + return false; + } // Validation: Need at least 2 rows; all rows must have same number of columns. - if (($n_rows = $this->num_data_rows) < 2) return TRUE; + if (($n_rows = $this->num_data_rows) < 2) { + return true; + } if ($this->records_per_group != min($this->num_recs)) { return $this->PrintError("DrawArea(): Data array must contain the same number" . " of Y values for each X"); } - // Calculate and store device coordinates xd[] and yd[][], and draw the data labels. + // Calculate and store device coordinates xd[] and yd[][], and draw the data labels. $n_columns = $this->SetupAreaPlot($do_stacked, $xd, $yd); // Draw the filled polygons. @@ -7889,16 +8626,17 @@ protected function DrawArea($do_stacked = FALSE) array_push($pts, $xd[$row], $yd[$row][$col]); } // Draw it: - ImageFilledPolygon($this->img, $pts, $n_rows * 2, $this->ndx_data_colors[$prev_col]); + ImageFilledPolygon($this->img, $pts, $this->ndx_data_colors[$prev_col]); $prev_col = $col; } // Draw the data borders, if enabled. (After, else the area fills cover parts of it.) - if (!empty($this->draw_data_borders)) - $this->DrawAreaFillBorders($n_columns, $xd, $yd, $do_stacked, FALSE); + if (!empty($this->draw_data_borders)) { + $this->DrawAreaFillBorders($n_columns, $xd, $yd, $do_stacked, false); + } - return TRUE; + return true; } /** @@ -7917,41 +8655,46 @@ protected function DrawArea($do_stacked = FALSE) * @param bool $paired True if doing a linepoints plots, False or omit for lines plot * @return bool True (False on error if an error handler returns True) */ - protected function DrawLines($paired = FALSE) + protected function DrawLines($paired = false) { - if (!$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx, ' - . 'data-data-error, data-data-yx-error')) - return FALSE; + if ( + !$this->CheckDataType('text-data, data-data, text-data-yx, data-data-yx, ' + . 'data-data-error, data-data-yx-error') + ) { + return false; + } // Flag array telling if the current point is valid, one element per plot line. // If start_lines[i] is true, then (lastx[i], lasty[i]) is the previous point. - if ($this->data_columns > 0) - $start_lines = array_fill(0, $this->data_columns, FALSE); + if ($this->data_columns > 0) { + $start_lines = array_fill(0, $this->data_columns, false); + } $gcvars = array(); // For GetDataColor, which initializes and uses this. // Data labels, Data Value Labels? if ($this->datatype_swapped_xy) { // Horizontal plots can have X Data Value Labels, Y Axis Data Labels - $do_x_axis_labels = FALSE; + $do_x_axis_labels = false; $do_x_valu_labels = $this->CheckDataValueLabels($this->x_data_label_pos, $dvl); $do_y_axis_labels = $this->y_data_label_pos != 'none'; - $do_y_valu_labels = FALSE; + $do_y_valu_labels = false; } else { // Vertical plots can have X Axis Data Labels, Y Data Value Labels $do_x_axis_labels = $this->x_data_label_pos != 'none'; - $do_x_valu_labels = FALSE; - $do_y_axis_labels = FALSE; + $do_x_valu_labels = false; + $do_y_axis_labels = false; $do_y_valu_labels = $this->CheckDataValueLabels($this->y_data_label_pos, $dvl); } for ($row = 0; $row < $this->num_data_rows; $row++) { $rec = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied X values? + if ($this->datatype_implied) { // Implied X values? $iv = 0.5 + $row; // Place text-data at X = 0.5, 1.5, 2.5, etc... - else + } else { $iv = $this->data[$row][$rec++]; // Get actual X value from array + } // Convert independent variable to device coordinates if ($this->datatype_swapped_xy) { @@ -7961,10 +8704,11 @@ protected function DrawLines($paired = FALSE) } // Axis data label? - if ($do_x_axis_labels) - $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row, TRUE); - elseif ($do_y_axis_labels) - $this->DrawYDataLabel($this->data[$row][0], $y_now_pixels, $row, TRUE); + if ($do_x_axis_labels) { + $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row, true); + } elseif ($do_y_axis_labels) { + $this->DrawYDataLabel($this->data[$row][0], $y_now_pixels, $row, true); + } // Proceed with dependent values for ($idx = 0; $rec < $this->num_recs[$row]; $idx++) { @@ -7973,7 +8717,6 @@ protected function DrawLines($paired = FALSE) // Skip point if data value is missing. Also skip if the whole line is suppressed // with style='none' (useful with linepoints plots) if (is_numeric($dv = $this->data[$row][$rec++]) && $line_style != 'none') { - // Convert dependent variable to device coordinates if ($this->datatype_swapped_xy) { $x_now_pixels = $this->xtr($dv); @@ -7990,46 +8733,64 @@ protected function DrawLines($paired = FALSE) if ($start_lines[$idx]) { // Set line width, revert it to normal at the end - ImageSetThickness($this->img, $this->line_widths[$idx]); + imagesetthickness($this->img,intval($this->line_widths[$idx])); // Select solid color or dashed line $style = $this->SetDashedStyle($data_color, $line_style == 'dashed'); // Draw the line segment: - ImageLine($this->img, $x_now_pixels, $y_now_pixels, - $lastx[$idx], $lasty[$idx], $style); + ImageLine( + $this->img, + intval($x_now_pixels), + intval($y_now_pixels), + intval($lastx[$idx]), + intval($lasty[$idx]), + intval($style) + ); } // Draw error bars, but not for linepoints plots, because DrawPoints() does it. if ($this->datatype_error_bars && !$paired) { if ($this->datatype_swapped_xy) { - $this->DrawXErrorBars($dv, $iv, $this->data[$row][$rec], - $this->data[$row][$rec+1], $error_color); + $this->DrawXErrorBars( + $dv, + $iv, + $this->data[$row][$rec], + $this->data[$row][$rec + 1], + $error_color + ); } else { - $this->DrawYErrorBars($iv, $dv, $this->data[$row][$rec], - $this->data[$row][$rec+1], $error_color); + $this->DrawYErrorBars( + $iv, + $dv, + $this->data[$row][$rec], + $this->data[$row][$rec + 1], + $error_color + ); } } // Draw data value labels? - if ($do_y_valu_labels) // Vertical plot + if ($do_y_valu_labels) { // Vertical plot $this->DrawDataValueLabel('y', $row, $idx, $iv, $dv, $dv, $dvl); - elseif ($do_x_valu_labels) // Horizontal plot + } elseif ($do_x_valu_labels) { // Horizontal plot $this->DrawDataValueLabel('x', $row, $idx, $dv, $iv, $dv, $dvl); + } $lastx[$idx] = $x_now_pixels; $lasty[$idx] = $y_now_pixels; - $start_lines[$idx] = TRUE; + $start_lines[$idx] = true; } elseif ($this->draw_broken_lines) { - $start_lines[$idx] = FALSE; // Missing point value or line style suppression + $start_lines[$idx] = false; // Missing point value or line style suppression } - if ($this->datatype_error_bars) + if ($this->datatype_error_bars) { $rec += 2; // Skip over error bar values, even in missing data case. + } } } - ImageSetThickness($this->img, 1); // Revert to original state for lines to be drawn later. - return TRUE; + imagesetthickness($this->img,1); // Revert to original state for lines to be drawn later. + return true; } /** @@ -8049,7 +8810,7 @@ protected function DrawLines($paired = FALSE) */ protected function DrawLinePoints() { - return $this->DrawLines(TRUE) && $this->DrawDots(TRUE); + return $this->DrawLines(true) && $this->DrawDots(true); } /** @@ -8063,13 +8824,15 @@ protected function DrawLinePoints() */ protected function DrawSquared() { - if (!$this->CheckDataType('text-data, data-data')) - return FALSE; + if (!$this->CheckDataType('text-data, data-data')) { + return false; + } // Flag array telling if the current point is valid, one element per plot line. // If start_lines[i] is true, then (lastx[i], lasty[i]) is the previous point. - if ($this->data_columns > 0) - $start_lines = array_fill(0, $this->data_columns, FALSE); + if ($this->data_columns > 0) { + $start_lines = array_fill(0, $this->data_columns, false); + } $gcvars = array(); // For GetDataColor, which initializes and uses this. @@ -8079,15 +8842,17 @@ protected function DrawSquared() for ($row = 0; $row < $this->num_data_rows; $row++) { $record = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied X values? + if ($this->datatype_implied) { // Implied X values? $x_now = 0.5 + $row; // Place text-data at X = 0.5, 1.5, 2.5, etc... - else + } else { $x_now = $this->data[$row][$record++]; // Read it, advance record index + } $x_now_pixels = $this->xtr($x_now); // Absolute coordinates - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } // Draw Lines for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) { @@ -8096,7 +8861,7 @@ protected function DrawSquared() if ($start_lines[$idx]) { // Set line width, revert it to normal at the end - ImageSetThickness($this->img, $this->line_widths[$idx]); + imagesetthickness($this->img,intval($this->line_widths[$idx])); // Select the color: $this->GetDataColor($row, $idx, $gcvars, $data_color); @@ -8106,25 +8871,26 @@ protected function DrawSquared() // Draw the step: $y_mid = $lasty[$idx]; - ImageLine($this->img, $lastx[$idx], $y_mid, $x_now_pixels, $y_mid, $style); - ImageLine($this->img, $x_now_pixels, $y_mid, $x_now_pixels, $y_now_pixels, $style); + ImageLine($this->img, intval($lastx[$idx] ), intval($y_mid), intval($x_now_pixels), intval($y_mid ), intval($style)); + ImageLine($this->img, intval($x_now_pixels), intval($y_mid), intval($x_now_pixels), intval($y_now_pixels), intval($style)); } // Draw data value labels? - if ($do_dvls) + if ($do_dvls) { $this->DrawDataValueLabel('y', $row, $idx, $x_now, $y_now, $y_now, $dvl); + } $lastx[$idx] = $x_now_pixels; $lasty[$idx] = $y_now_pixels; - $start_lines[$idx] = TRUE; + $start_lines[$idx] = true; } elseif ($this->draw_broken_lines) { // Y data missing, leave a gap. - $start_lines[$idx] = FALSE; + $start_lines[$idx] = false; } } } - ImageSetThickness($this->img, 1); - return TRUE; + imagesetthickness($this->img,1); + return true; } /** @@ -8138,25 +8904,27 @@ protected function DrawSquared() * @param bool $do_stacked True for cumulative (stacked), false or omit for unstacked. * @return bool True (False on error if an error handler returns True) */ - protected function DrawSquaredArea($do_stacked = FALSE) + protected function DrawSquaredArea($do_stacked = false) { - if (!$this->CheckDataType('text-data, data-data')) - return FALSE; + if (!$this->CheckDataType('text-data, data-data')) { + return false; + } // Validation: Need at least 2 rows; all rows must have same number of columns. - if (($n_rows = $this->num_data_rows) < 2) return TRUE; + if (($n_rows = $this->num_data_rows) < 2) { + return true; + } if ($this->records_per_group != min($this->num_recs)) { return $this->PrintError("DrawSquaredArea(): Data array must contain the same number" . " of Y values for each X"); } - // Calculate and store device coordinates xd[] and yd[][], and draw the data labels. + // Calculate and store device coordinates xd[] and yd[][], and draw the data labels. $n_columns = $this->SetupAreaPlot($do_stacked, $xd, $yd); // Draw a filled polygon for each Y column $prev_col = 0; for ($col = 1; $col < $n_columns; $col++) { // 1 extra for X axis artificial column - // Current data set forms the top. For each point after the first, add 2 points. $x_prev = $xd[0]; $y_prev = $yd[0][$col]; @@ -8184,15 +8952,16 @@ protected function DrawSquaredArea($do_stacked = FALSE) } // Draw the resulting polygon, which has (2 * (1 + 2*(n_rows-1))) points: - ImageFilledPolygon($this->img, $pts, 4 * $n_rows - 2, $this->ndx_data_colors[$prev_col]); + ImageFilledPolygon($this->img, $pts, $this->ndx_data_colors[$prev_col]); $prev_col = $col; } // Draw the data borders, if enabled. (After, else the area fills cover parts of it.) - if (!empty($this->draw_data_borders)) - $this->DrawAreaFillBorders($n_columns, $xd, $yd, $do_stacked, TRUE); + if (!empty($this->draw_data_borders)) { + $this->DrawAreaFillBorders($n_columns, $xd, $yd, $do_stacked, true); + } - return TRUE; + return true; } /** @@ -8206,11 +8975,13 @@ protected function DrawSquaredArea($do_stacked = FALSE) */ protected function DrawBars() { - if (!$this->CheckDataType('text-data, text-data-yx')) - return FALSE; - if ($this->datatype_swapped_xy) + if (!$this->CheckDataType('text-data, text-data-yx')) { + return false; + } + if ($this->datatype_swapped_xy) { return $this->DrawHorizBars(); - $this->CalcBarWidths(FALSE, TRUE); // Calculate bar widths for unstacked, vertical + } + $this->CalcBarWidths(false, true); // Calculate bar widths for unstacked, vertical // This is the X offset from the bar group's label center point to the left side of the first bar // in the group. See also CalcBarWidths above. @@ -8223,8 +8994,9 @@ protected function DrawBars() $x_now_pixels = $this->xtr(0.5 + $row); // Place text-data at X = 0.5, 1.5, 2.5, etc... - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } // Lower left X of first bar in the group: $x1 = $x_now_pixels - $x_first_bar; @@ -8258,14 +9030,14 @@ protected function DrawBars() $dvl['v_align'] = 'top'; $dvl['y_offset'] = 2; } - $this->DrawDataValueLabel('y', $row, $idx, $row+0.5, $y, $y, $dvl); + $this->DrawDataValueLabel('y', $row, $idx, $row + 0.5, $y, $y, $dvl); } } // Step to next bar in group: $x1 += $this->record_bar_width; } } - return TRUE; + return true; } /** @@ -8279,7 +9051,7 @@ protected function DrawBars() */ protected function DrawHorizBars() { - $this->CalcBarWidths(FALSE, FALSE); // Calculate bar widths for unstacked, vertical + $this->CalcBarWidths(false, false); // Calculate bar widths for unstacked, vertical // This is the Y offset from the bar group's label center point to the bottom of the first bar // in the group. See also CalcBarWidths above. @@ -8292,8 +9064,9 @@ protected function DrawHorizBars() $y_now_pixels = $this->ytr(0.5 + $row); // Place bars at Y=0.5, 1.5, 2.5, etc... - if ($this->y_data_label_pos != 'none') // Draw Y Data Labels? + if ($this->y_data_label_pos != 'none') { // Draw Y Data Labels? $this->DrawYDataLabel($this->data[$row][0], $y_now_pixels, $row); + } // Lower left Y of first bar in the group: $y1 = $y_now_pixels + $y_first_bar; @@ -8327,14 +9100,14 @@ protected function DrawHorizBars() $dvl['h_align'] = 'right'; $dvl['x_offset'] = -2; } - $this->DrawDataValueLabel('x', $row, $idx, $x, $row+0.5, $x, $dvl); + $this->DrawDataValueLabel('x', $row, $idx, $x, $row + 0.5, $x, $dvl); } } // Step to next bar in group: $y1 -= $this->record_bar_width; } } - return TRUE; + return true; } /** @@ -8349,11 +9122,13 @@ protected function DrawHorizBars() */ protected function DrawStackedBars() { - if (!$this->CheckDataType('text-data, text-data-yx')) - return FALSE; - if ($this->datatype_swapped_xy) + if (!$this->CheckDataType('text-data, text-data-yx')) { + return false; + } + if ($this->datatype_swapped_xy) { return $this->DrawHorizStackedBars(); - $this->CalcBarWidths(TRUE, TRUE); // Calculate bar widths for stacked, vertical + } + $this->CalcBarWidths(true, true); // Calculate bar widths for stacked, vertical // This is the X offset from the bar's label center point to the left side of the bar. $x_first_bar = $this->record_bar_width / 2 - $this->bar_adjust_gap; @@ -8370,13 +9145,14 @@ protected function DrawStackedBars() $x_now_pixels = $this->xtr(0.5 + $row); // Place text-data at X = 0.5, 1.5, 2.5, etc... - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } // Determine bar direction based on 1st non-zero value. Note the bar direction is // based on zero, not the axis value. $n_recs = $this->num_recs[$row]; - $upward = TRUE; // Initialize this for the case of all segments = 0 + $upward = true; // Initialize this for the case of all segments = 0 for ($i = $record; $i < $n_recs; $i++) { if (is_numeric($this_y = $this->data[$row][$i]) && $this_y != 0) { $upward = ($this_y > 0); @@ -8390,17 +9166,14 @@ protected function DrawStackedBars() $wy2 = $this->x_axis_position; // World coordinates Y2, last drawn value // Draw bar segments and labels in this stack. - $first = TRUE; + $first = true; for ($idx = 0; $record < $n_recs; $record++, $idx++) { - // Skip missing Y values. Process Y=0 values due to special case of moved axis. if (is_numeric($this_y = $this->data[$row][$record])) { - $wy1 += $this_y; // Keep the running total for this bar stack // Draw the segment only if it will increase the stack height (ignore if wrong direction): if (($upward && $wy1 > $wy2) || (!$upward && $wy2 > $wy1)) { - $y1 = $this->ytr($wy1); // Convert to device coordinates. $y1 is outermost value. $y2 = $this->ytr($wy2); // $y2 is innermost (closest to axis). @@ -8408,10 +9181,20 @@ protected function DrawStackedBars() $this->GetBarColors($row, $idx, $gcvars, $data_color, $shade_color, $border_color); // Draw the bar, and the shade or border: - $this->DrawBar($row, $idx, $x1, $y1, $x2, $y2, - $data_color, $shade_color, $border_color, + $this->DrawBar( + $row, + $idx, + $x1, + $y1, + $x2, + $y2, + $data_color, + $shade_color, + $border_color, // Only shade the top for upward bars, or the first segment of downward bars: - $upward || $first, TRUE); + $upward || $first, + true + ); // Draw optional data label for this bar segment just inside the end. // Text value is the current Y, but position is the cumulative Y. @@ -8425,11 +9208,11 @@ protected function DrawStackedBars() $dvl['v_align'] = 'bottom'; $dvl['y_offset'] = -3; } - $this->DrawDataValueLabel('y', $row, $idx, $row+0.5, $wy1, $this_y, $dvl); + $this->DrawDataValueLabel('y', $row, $idx, $row + 0.5, $wy1, $this_y, $dvl); } // Mark the new end of the bar, conditional on segment height > 0. $wy2 = $wy1; - $first = FALSE; + $first = false; } } } // end for @@ -8438,7 +9221,7 @@ protected function DrawStackedBars() // Value is wy1 (total value), but position is wy2 (end of the bar stack). // These differ only with wrong-direction segments, or a stack completely clipped by the axis. if ($data_labels_end) { - $dvl['min_height'] = NULL; // Might be set above, but the whole array might not exist. + $dvl['min_height'] = null; // Might be set above, but the whole array might not exist. if ($upward) { $dvl['v_align'] = 'bottom'; $dvl['y_offset'] = $data_label_y_offset; @@ -8446,10 +9229,10 @@ protected function DrawStackedBars() $dvl['v_align'] = 'top'; $dvl['y_offset'] = 5; } - $this->DrawDataValueLabel('y', $row, NULL, $row+0.5, $wy2, $wy1, $dvl); + $this->DrawDataValueLabel('y', $row, null, $row + 0.5, $wy2, $wy1, $dvl); } } // end for - return TRUE; + return true; } /** @@ -8463,7 +9246,7 @@ protected function DrawStackedBars() */ protected function DrawHorizStackedBars() { - $this->CalcBarWidths(TRUE, FALSE); // Calculate bar widths for stacked, horizontal + $this->CalcBarWidths(true, false); // Calculate bar widths for stacked, horizontal // This is the Y offset from the bar's label center point to the bottom of the bar $y_first_bar = $this->record_bar_width / 2 - $this->bar_adjust_gap; @@ -8480,13 +9263,14 @@ protected function DrawHorizStackedBars() $y_now_pixels = $this->ytr(0.5 + $row); // Place bars at Y=0.5, 1.5, 2.5, etc... - if ($this->y_data_label_pos != 'none') // Draw Y Data labels? + if ($this->y_data_label_pos != 'none') { // Draw Y Data labels? $this->DrawYDataLabel($this->data[$row][0], $y_now_pixels, $row); + } // Determine bar direction based on 1st non-zero value. Note the bar direction is // based on zero, not the axis value. $n_recs = $this->num_recs[$row]; - $rightward = TRUE; // Initialize this for the case of all segments = 0 + $rightward = true; // Initialize this for the case of all segments = 0 for ($i = $record; $i < $n_recs; $i++) { if (is_numeric($this_x = $this->data[$row][$i]) && $this_x != 0) { $rightward = ($this_x > 0); @@ -8501,17 +9285,14 @@ protected function DrawHorizStackedBars() $wx2 = $this->y_axis_position; // World coordinates X2, last drawn value // Draw bar segments and labels in this stack. - $first = TRUE; + $first = true; for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) { - // Skip missing X values. Process X=0 values due to special case of moved axis. if (is_numeric($this_x = $this->data[$row][$record])) { - $wx1 += $this_x; // Keep the running total for this bar stack // Draw the segment only if it will increase the stack length (ignore if wrong direction): if (($rightward && $wx1 > $wx2) || (!$rightward && $wx2 > $wx1)) { - $x1 = $this->xtr($wx1); // Convert to device coordinates. $x1 is outermost value. $x2 = $this->xtr($wx2); // $x2 is innermost (closest to axis). @@ -8519,10 +9300,20 @@ protected function DrawHorizStackedBars() $this->GetBarColors($row, $idx, $gcvars, $data_color, $shade_color, $border_color); // Draw the bar, and the shade or border: - $this->DrawBar($row, $idx, $x1, $y1, $x2, $y2, - $data_color, $shade_color, $border_color, + $this->DrawBar( + $row, + $idx, + $x1, + $y1, + $x2, + $y2, + $data_color, + $shade_color, + $border_color, // Only shade the side for rightward bars, or the first segment of leftward bars: - TRUE, $rightward || $first); + true, + $rightward || $first + ); // Draw optional data label for this bar segment just inside the end. // Text value is the current X, but position is the cumulative X. @@ -8536,11 +9327,11 @@ protected function DrawHorizStackedBars() $dvl['h_align'] = 'left'; $dvl['x_offset'] = 3; } - $this->DrawDataValueLabel('x', $row, $idx, $wx1, $row+0.5, $this_x, $dvl); + $this->DrawDataValueLabel('x', $row, $idx, $wx1, $row + 0.5, $this_x, $dvl); } // Mark the new end of the bar, conditional on segment width > 0. $wx2 = $wx1; - $first = FALSE; + $first = false; } } } // end for @@ -8549,7 +9340,7 @@ protected function DrawHorizStackedBars() // Value is wx1 (total value), but position is wx2 (end of the bar stack). // These differ only with wrong-direction segments, or a stack completely clipped by the axis. if ($data_labels_end) { - $dvl['min_width'] = NULL; // Might be set above, but the whole array might not exist. + $dvl['min_width'] = null; // Might be set above, but the whole array might not exist. if ($rightward) { $dvl['h_align'] = 'left'; $dvl['x_offset'] = $data_label_x_offset; @@ -8557,10 +9348,10 @@ protected function DrawHorizStackedBars() $dvl['h_align'] = 'right'; $dvl['x_offset'] = -5; } - $this->DrawDataValueLabel('x', $row, NULL, $wx2, $row+0.5, $wx1, $dvl); + $this->DrawDataValueLabel('x', $row, null, $wx2, $row + 0.5, $wx1, $dvl); } } // end for - return TRUE; + return true; } /** @@ -8577,20 +9368,24 @@ protected function DrawHorizStackedBars() * @return bool True (False on error if an error handler returns True) * @since 5.3.0 */ - protected function DrawOHLC($draw_candles, $always_fill = FALSE) + protected function DrawOHLC($draw_candles, $always_fill = false) { - if (!$this->CheckDataType('text-data, data-data')) - return FALSE; - if ($this->data_columns != 4) // early error check (more inside the loop) + if (!$this->CheckDataType('text-data, data-data')) { + return false; + } + if ($this->data_columns != 4) { // early error check (more inside the loop) return $this->PrintError("DrawOHLC(): rows must have 4 values."); + } // Assign name of GD function to draw candlestick bodies for stocks that close up. $draw_body_close_up = $always_fill ? 'imagefilledrectangle' : 'imagerectangle'; // Calculate the half-width of the candle body, or length of the tick marks. // This is scaled based on the plot density, but within tight limits. - $dw = max($this->ohlc_min_width, min($this->ohlc_max_width, - (int)($this->ohlc_frac_width * $this->plot_area_width / $this->num_data_rows))); + $dw = max($this->ohlc_min_width, min( + $this->ohlc_max_width, + (int)($this->ohlc_frac_width * $this->plot_area_width / $this->num_data_rows) + )); // Get line widths to use: index 0 for body/stroke, 1 for wick/tick. list($body_thickness, $wick_thickness) = $this->line_widths; @@ -8600,26 +9395,30 @@ protected function DrawOHLC($draw_candles, $always_fill = FALSE) for ($row = 0; $row < $this->num_data_rows; $row++) { $record = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied X values? + if ($this->datatype_implied) { // Implied X values? $x_now = 0.5 + $row; // Place text-data at X = 0.5, 1.5, 2.5, etc... - else + } else { $x_now = $this->data[$row][$record++]; // Read it, advance record index + } $x_now_pixels = $this->xtr($x_now); // Convert X to device coordinates $x_left = $x_now_pixels - $dw; $x_right = $x_now_pixels + $dw; - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row); + } // Each row must have 4 values, but skip rows with non-numeric entries. if ($this->num_recs[$row] - $record != 4) { return $this->PrintError("DrawOHLC(): row $row must have 4 values."); } - if (!is_numeric($yo = $this->data[$row][$record++]) - || !is_numeric($yh = $this->data[$row][$record++]) - || !is_numeric($yl = $this->data[$row][$record++]) - || !is_numeric($yc = $this->data[$row][$record++])) { + if ( + !is_numeric($yo = $this->data[$row][$record++]) + || !is_numeric($yh = $this->data[$row][$record++]) + || !is_numeric($yl = $this->data[$row][$record++]) + || !is_numeric($yc = $this->data[$row][$record++]) + ) { continue; } @@ -8638,7 +9437,7 @@ protected function DrawOHLC($draw_candles, $always_fill = FALSE) $this->GetDataColor($row, 0, $gcvars, $body_color); // Color 0 for body, closing down $this->GetDataColor($row, 2, $gcvars, $ext_color); // Color 2 for wicks/ticks } - imagesetthickness($this->img, $body_thickness); + imagesetthickness($this->img,intval($body_thickness)); if ($draw_candles) { // Note: Unlike ImageFilledRectangle, ImageRectangle 'requires' its arguments in @@ -8648,8 +9447,9 @@ protected function DrawOHLC($draw_candles, $always_fill = FALSE) $yb2_pixels = $yo_pixels; // Lower body Y $draw_body = $draw_body_close_up; // Avoid a PHP/GD bug resulting in "T"-shaped ends to zero height unfilled rectangle: - if ($yb1_pixels == $yb2_pixels) + if ($yb1_pixels == $yb2_pixels) { $draw_body = 'imagefilledrectangle'; + } } else { $yb1_pixels = $yo_pixels; $yb2_pixels = $yc_pixels; @@ -8660,24 +9460,24 @@ protected function DrawOHLC($draw_candles, $always_fill = FALSE) $draw_body($this->img, $x_left, $yb1_pixels, $x_right, $yb2_pixels, $body_color); // Draw upper and lower wicks, if they have height. (In device coords, that's dY<0) - imagesetthickness($this->img, $wick_thickness); + imagesetthickness($this->img,intval($wick_thickness)); if ($yh_pixels < $yb1_pixels) { - imageline($this->img, $x_now_pixels, $yb1_pixels, $x_now_pixels, $yh_pixels, $ext_color); + imageline($this->img, intval($x_now_pixels), intval($yb1_pixels), intval($x_now_pixels), intval($yh_pixels), intval($ext_color)); } if ($yl_pixels > $yb2_pixels) { - imageline($this->img, $x_now_pixels, $yb2_pixels, $x_now_pixels, $yl_pixels, $ext_color); + imageline($this->img, intval($x_now_pixels), intval($yb2_pixels), intval($x_now_pixels), intval($yl_pixels), intval($ext_color)); } } else { // Basic OHLC - imageline($this->img, $x_now_pixels, $yl_pixels, $x_now_pixels, $yh_pixels, $body_color); - imagesetthickness($this->img, $wick_thickness); - imageline($this->img, $x_left, $yo_pixels, $x_now_pixels, $yo_pixels, $ext_color); - imageline($this->img, $x_right, $yc_pixels, $x_now_pixels, $yc_pixels, $ext_color); + imageline($this->img, intval($x_now_pixels), intval($yl_pixels), intval($x_now_pixels), intval($yh_pixels), intval($body_color)); + imagesetthickness($this->img,intval($wick_thickness)); + imageline($this->img, intval($x_left), intval($yo_pixels), intval($x_now_pixels), intval($yo_pixels), intval($ext_color)); + imageline($this->img, intval($x_right), intval($yc_pixels), intval($x_now_pixels), intval($yc_pixels), intval($ext_color)); } - imagesetthickness($this->img, 1); + imagesetthickness($this->img,1); $this->DoCallback('data_points', 'rect', $row, 0, $x_left, $yh_pixels, $x_right, $yl_pixels); } - return TRUE; + return true; } /** @@ -8693,8 +9493,9 @@ protected function DrawOHLC($draw_candles, $always_fill = FALSE) */ protected function DrawBubbles() { - if (!$this->CheckDataType('data-data-xyz')) - return FALSE; + if (!$this->CheckDataType('data-data-xyz')) { + return false; + } $gcvars = array(); // For GetDataColor, which initializes and uses this. @@ -8719,15 +9520,15 @@ protected function DrawBubbles() $x = $this->xtr($this->data[$row][$rec++]); // Get X value from data array. // Draw X Data labels? - if ($this->x_data_label_pos != 'none') - $this->DrawXDataLabel($this->data[$row][0], $x, $row, TRUE); + if ($this->x_data_label_pos != 'none') { + $this->DrawXDataLabel($this->data[$row][0], $x, $row, true); + } // Proceed with Y,Z values for ($idx = 0; $rec < $this->num_recs[$row]; $rec += 2, $idx++) { - if (is_numeric($y_now = $this->data[$row][$rec])) { //Allow for missing Y data $y = $this->ytr($y_now); - $z = (double)$this->data[$row][$rec+1]; // Z is required if Y is present. + $z = (double)$this->data[$row][$rec + 1]; // Z is required if Y is present. $size = (int)($f_size * $z + $b_size); // Calculate bubble size // Select the color: @@ -8739,7 +9540,7 @@ protected function DrawBubbles() } } } - return TRUE; + return true; } /** @@ -8756,18 +9557,22 @@ protected function DrawBubbles() */ protected function DrawBoxes() { - if (!$this->CheckDataType('text-data, data-data')) - return FALSE; - if ($this->data_columns < 5) // early error check (more inside the loop) + if (!$this->CheckDataType('text-data, data-data')) { + return false; + } + if ($this->data_columns < 5) { // early error check (more inside the loop) return $this->PrintError("DrawBoxes(): rows must have 5 or more values."); + } // Set up the point shapes/sizes arrays - needed for outliers: $this->CheckPointParams(); // Calculate the half-width of the boxes. // This is scaled based on the plot density, but within tight limits. - $width1 = max($this->boxes_min_width, min($this->boxes_max_width, - (int)($this->boxes_frac_width * $this->plot_area_width / $this->num_data_rows))); + $width1 = max($this->boxes_min_width, min( + $this->boxes_max_width, + (int)($this->boxes_frac_width * $this->plot_area_width / $this->num_data_rows) + )); // This is the half-width of the upper and lower T's and the ends of the whiskers: $width2 = $this->boxes_t_width * $width1; @@ -8779,17 +9584,19 @@ protected function DrawBoxes() for ($row = 0; $row < $this->num_data_rows; $row++) { $record = 1; // Skip record #0 (data label) - if ($this->datatype_implied) // Implied X values? + if ($this->datatype_implied) { // Implied X values? $xw = 0.5 + $row; // Place text-data at X = 0.5, 1.5, 2.5, etc... - else + } else { $xw = $this->data[$row][$record++]; // Read it, advance record index + } $xd = $this->xtr($xw); // Convert X to device coordinates $x_left = $xd - $width1; $x_right = $xd + $width1; - if ($this->x_data_label_pos != 'none') // Draw X Data labels? + if ($this->x_data_label_pos != 'none') { // Draw X Data labels? $this->DrawXDataLabel($this->data[$row][0], $xd, $row); + } // Each row must have at least 5 values: $num_y = $this->num_recs[$row] - $record; @@ -8800,11 +9607,13 @@ protected function DrawBoxes() // Collect the 5 primary Y values, plus any outliers: $yd = array(); // Device coords for ($i = 0; $i < $num_y; $i++) { - $yd[$i] = is_numeric($y = $this->data[$row][$record++]) ? $this->ytr($y) : NULL; + $yd[$i] = is_numeric($y = $this->data[$row][$record++]) ? $this->ytr($y) : null; } // Skip the row if either YQ1 or YQ3 is missing: - if (!isset($yd[1], $yd[3])) continue; + if (!isset($yd[1], $yd[3])) { + continue; + } // Box plot uses 4 colors, and 1 dashed line style for the whiskers: $this->GetDataColor($row, 0, $gcvars, $box_color); @@ -8815,38 +9624,39 @@ protected function DrawBoxes() // Draw the lower whisker and T if (isset($yd[0]) && $yd[0] > $yd[1]) { // Note device Y coordinates are inverted (*-1) - imagesetthickness($this->img, $whisker_thickness); - imageline($this->img, $xd, $yd[0], $xd, $yd[1], $whisker_style); - imageline($this->img, $xd - $width2, $yd[0], $xd + $width2, $yd[0], $whisker_color); + imagesetthickness($this->img,intval($whisker_thickness)); + imageline($this->img, intval($xd ), intval($yd[0]), intval($xd ), intval($yd[1]), intval($whisker_style)); + imageline($this->img, intval($xd - $width2), intval($yd[0]), intval($xd + $width2), intval($yd[0]), intval($whisker_color)); } // Draw the upper whisker and T if (isset($yd[4]) && $yd[3] > $yd[4]) { // Meaning: Yworld[3] < Yworld[4] - imagesetthickness($this->img, $whisker_thickness); - imageline($this->img, $xd, $yd[3], $xd, $yd[4], $whisker_style); - imageline($this->img, $xd - $width2, $yd[4], $xd + $width2, $yd[4], $whisker_color); + imagesetthickness($this->img,intval($whisker_thickness)); + imageline($this->img, intval($xd ), intval($yd[3]), intval($xd ), intval($yd[4]), intval($whisker_style)); + imageline($this->img, intval($xd - $width2), intval($yd[4]), intval($xd + $width2), intval($yd[4]), intval($whisker_color)); } // Draw the median belt (before the box, so the ends of the belt don't break up the box.) if (isset($yd[2])) { - imagesetthickness($this->img, $belt_thickness); - imageline($this->img, $x_left, $yd[2], $x_right, $yd[2], $belt_color); - } + imagesetthickness($this->img,intval($belt_thickness)); + imageline($this->img, intval($x_left), intval($yd[2]), intval($x_right), intval($yd[2]), intval($belt_color)); + } // Draw the box - imagesetthickness($this->img, $box_thickness); - imagerectangle($this->img, $x_left, $yd[3], $x_right, $yd[1], $box_color); - imagesetthickness($this->img, 1); + imagesetthickness($this->img,intval($box_thickness)); + imagerectangle($this->img, intval($x_left), intval($yd[3]), intval($x_right), intval($yd[1]), intval($box_color)); + imagesetthickness($this->img,1); // Draw any outliers, all using the same shape marker (index 0) and color: for ($i = 5; $i < $num_y; $i++) { - if (isset($yd[$i])) + if (isset($yd[$i])) { $this->DrawShape($xd, $yd[$i], 0, $outlier_color); + } } $this->DoCallback('data_points', 'rect', $row, 0, $x_left, $yd[4], $x_right, $yd[0]); } - return TRUE; + return true; } /** @@ -8859,11 +9669,12 @@ protected function DrawBoxes() * * @return bool True (False on error if an error handler returns True) */ - function DrawGraph() + public function DrawGraph() { // Test for missing image, missing data, empty data: - if (!$this->CheckDataArray()) - return FALSE; // Error message already reported. + if (!$this->CheckDataArray()) { + return false; // Error message already reported. + } // Load some configuration values from the array of plot types: $pt = &self::$plots[$this->plot_type]; // Use reference for shortcut @@ -8876,14 +9687,15 @@ function DrawGraph() // Calculate scaling, but only for plots with axes (excludes pie charts). if ($draw_axes) { - // Get maxima and minima for scaling: - if (!$this->FindDataLimits()) - return FALSE; + if (!$this->FindDataLimits()) { + return false; + } // Set plot area world values (plot_max_x, etc.): - if (!$this->CalcPlotAreaWorld()) - return FALSE; + if (!$this->CalcPlotAreaWorld()) { + return false; + } // Calculate X and Y axis positions in World Coordinates: $this->CalcAxisPositions(); @@ -8900,7 +9712,9 @@ function DrawGraph() $this->CalcPlotAreaPixels(); // Calculate the mapping between world and device coordinates: - if ($draw_axes) $this->CalcTranslation(); + if ($draw_axes) { + $this->CalcTranslation(); + } // Pad color and style arrays to fit records per group: $this->PadArrays(); @@ -8946,10 +9760,11 @@ function DrawGraph() } $this->DoCallback('draw_all', $this->plot_area); - if ($this->print_image && !$this->PrintImage()) - return FALSE; + if ($this->print_image && !$this->PrintImage()) { + return false; + } - return TRUE; + return true; } ///////////////////////////////////////////// @@ -8966,27 +9781,29 @@ function DrawGraph() /** * @deprecated Use SetYTickPos() instead */ - function SetDrawVertTicks($which_dvt) + public function SetDrawVertTicks($which_dvt) { - if ($which_dvt != 1) + if ($which_dvt != 1) { $this->SetYTickPos('none'); - return TRUE; + } + return true; } /** * @deprecated Use SetXTickPos() instead */ - function SetDrawHorizTicks($which_dht) + public function SetDrawHorizTicks($which_dht) { - if ($which_dht != 1) - $this->SetXTickPos('none'); - return TRUE; + if ($which_dht != 1) { + $this->SetXTickPos('none'); + } + return true; } /** * @deprecated Use SetNumXTicks() instead */ - function SetNumHorizTicks($n) + public function SetNumHorizTicks($n) { return $this->SetNumXTicks($n); } @@ -8994,7 +9811,7 @@ function SetNumHorizTicks($n) /** * @deprecated Use SetNumYTicks() instead */ - function SetNumVertTicks($n) + public function SetNumVertTicks($n) { return $this->SetNumYTicks($n); } @@ -9002,7 +9819,7 @@ function SetNumVertTicks($n) /** * @deprecated Use SetXTickIncrement() instead */ - function SetHorizTickIncrement($inc) + public function SetHorizTickIncrement($inc) { return $this->SetXTickIncrement($inc); } @@ -9010,7 +9827,7 @@ function SetHorizTickIncrement($inc) /** * @deprecated Use SetYTickIncrement() instead */ - function SetVertTickIncrement($inc) + public function SetVertTickIncrement($inc) { return $this->SetYTickIncrement($inc); } @@ -9018,7 +9835,7 @@ function SetVertTickIncrement($inc) /** * @deprecated Use SetYTickPos() instead */ - function SetVertTickPosition($which_tp) + public function SetVertTickPosition($which_tp) { return $this->SetYTickPos($which_tp); } @@ -9026,7 +9843,7 @@ function SetVertTickPosition($which_tp) /** * @deprecated Use SetXTickPos() instead */ - function SetHorizTickPosition($which_tp) + public function SetHorizTickPosition($which_tp) { return $this->SetXTickPos($which_tp); } @@ -9034,7 +9851,7 @@ function SetHorizTickPosition($which_tp) /** * @deprecated Use SetFont() instead */ - function SetTitleFontSize($which_size) + public function SetTitleFontSize($which_size) { return $this->SetFont('title', $which_size); } @@ -9042,7 +9859,7 @@ function SetTitleFontSize($which_size) /** * @deprecated Use SetFont() instead */ - function SetAxisFontSize($which_size) + public function SetAxisFontSize($which_size) { $this->SetFont('x_label', $which_size); $this->SetFont('y_label', $which_size); @@ -9051,7 +9868,7 @@ function SetAxisFontSize($which_size) /** * @deprecated Use SetFont() instead */ - function SetSmallFontSize($which_size) + public function SetSmallFontSize($which_size) { return $this->SetFont('generic', $which_size); } @@ -9059,7 +9876,7 @@ function SetSmallFontSize($which_size) /** * @deprecated Use SetFont() instead */ - function SetXLabelFontSize($which_size) + public function SetXLabelFontSize($which_size) { return $this->SetFont('x_title', $which_size); } @@ -9067,7 +9884,7 @@ function SetXLabelFontSize($which_size) /** * @deprecated Use SetFont() instead */ - function SetYLabelFontSize($which_size) + public function SetYLabelFontSize($which_size) { return $this->SetFont('y_title', $which_size); } @@ -9075,7 +9892,7 @@ function SetYLabelFontSize($which_size) /** * @deprecated Use SetXTitle() instead */ - function SetXLabel($which_xlab) + public function SetXLabel($which_xlab) { return $this->SetXTitle($which_xlab); } @@ -9083,7 +9900,7 @@ function SetXLabel($which_xlab) /** * @deprecated Use SetYTitle() instead */ - function SetYLabel($which_ylab) + public function SetYLabel($which_ylab) { return $this->SetYTitle($which_ylab); } @@ -9091,17 +9908,17 @@ function SetYLabel($which_ylab) /** * @deprecated Use SetXTickLength() and SetYTickLength() instead */ - function SetTickLength($which_tl) + public function SetTickLength($which_tl) { $this->SetXTickLength($which_tl); $this->SetYTickLength($which_tl); - return TRUE; + return true; } /** * @deprecated Use SetYLabelType() instead */ - function SetYGridLabelType($which_yglt) + public function SetYGridLabelType($which_yglt) { return $this->SetYLabelType($which_yglt); } @@ -9109,7 +9926,7 @@ function SetYGridLabelType($which_yglt) /** * @deprecated Use SetXLabelType() instead */ - function SetXGridLabelType($which_xglt) + public function SetXGridLabelType($which_xglt) { return $this->SetXLabelType($which_xglt); } @@ -9117,7 +9934,7 @@ function SetXGridLabelType($which_xglt) /** * @deprecated Use SetYTickLabelPos() instead */ - function SetYGridLabelPos($which_yglp) + public function SetYGridLabelPos($which_yglp) { return $this->SetYTickLabelPos($which_yglp); } @@ -9125,7 +9942,7 @@ function SetYGridLabelPos($which_yglp) /** * @deprecated Use SetXTickLabelPos() instead */ - function SetXGridLabelPos($which_xglp) + public function SetXGridLabelPos($which_xglp) { return $this->SetXTickLabelPos($which_xglp); } @@ -9133,36 +9950,37 @@ function SetXGridLabelPos($which_xglp) /** * @deprecated Use SetXtitle() instead */ - function SetXTitlePos($xpos) + public function SetXTitlePos($xpos) { $this->x_title_pos = $xpos; - return TRUE; + return true; } /** * @deprecated Use SetYTitle() instead */ - function SetYTitlePos($xpos) + public function SetYTitlePos($xpos) { $this->y_title_pos = $xpos; - return TRUE; + return true; } /** * @deprecated Use SetXDataLabelPos() instead */ - function SetDrawXDataLabels($which_dxdl) + public function SetDrawXDataLabels($which_dxdl) { - if ($which_dxdl == '1' ) + if ($which_dxdl == '1') { $this->SetXDataLabelPos('plotdown'); - else + } else { $this->SetXDataLabelPos('none'); + } } /** * @deprecated Use SetPlotAreaPixels() instead */ - function SetNewPlotAreaPixels($x1, $y1, $x2, $y2) + public function SetNewPlotAreaPixels($x1, $y1, $x2, $y2) { return $this->SetPlotAreaPixels($x1, $y1, $x2, $y2); } @@ -9170,7 +9988,7 @@ function SetNewPlotAreaPixels($x1, $y1, $x2, $y2) /** * @deprecated Use SetLineWidths() instead */ - function SetLineWidth($which_lw) + public function SetLineWidth($which_lw) { $this->SetLineWidths($which_lw); @@ -9178,63 +9996,35 @@ function SetLineWidth($which_lw) if (!$this->error_bar_line_width) { $this->SetErrorBarLineWidth($which_lw); } - return TRUE; + return true; } /** * @deprecated Use SetPointShapes() instead */ - function SetPointShape($which_pt) + public function SetPointShape($which_pt) { $this->SetPointShapes($which_pt); - return TRUE; + return true; } /** * @deprecated Use SetPointSizes() instead */ - function SetPointSize($which_ps) + public function SetPointSize($which_ps) { $this->SetPointSizes($which_ps); - return TRUE; + return true; } /** * @deprecated Use PrintError() instead */ - protected function DrawError($error_message, $where_x = NULL, $where_y = NULL) + protected function DrawError($error_message) { return $this->PrintError($error_message); } - } -/** - * Class for creating a plot using a truecolor (24-bit R,G,B) image - * - * The PHPlot_truecolor class extends the PHPlot class to use GD truecolor - * images. Unlike PHPlot which usually creates indexed RGB files limited to - * 256 total colors, PHPlot_truecolor objects use images which do not have a - * limit on the number of colors. - * - * Note: Without a background image, the PHPlot class creates a palette - * (indexed) color image, and the PHPlot_truecolor class creates a truecolor - * image. If a background image is used with the constructor of either class, - * the type of image produced matches the type of the background image. - * - */ -class PHPlot_truecolor extends PHPlot -{ - /** - * Constructor: Sets up GD truecolor image resource, and initializes plot style controls - * - * @param int $width Image width in pixels - * @param int $height Image height in pixels - * @param string $output_file Path for output file. Omit, or NULL, or '' to mean no output file - * @param string $input_file Path to a file to be used as background. Omit, NULL, or '' for none - */ - function __construct($width=600, $height=400, $output_file=NULL, $input_file=NULL) - { - $this->initialize('imagecreatetruecolor', $width, $height, $output_file, $input_file); - } -} +// PRS12: Move subclasses to separate files +// require_once 'phplot_truecolor.php';