- header('Content-type: image/png');
- imagepng($this->img);
- }
- imagedestroy($this->img);
- }
-
- function calculate_width()
- {
- switch ($this->type)
- {
- // Vertical bars
- case 1:
- $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->tsize) + 25) : 0;
- $this->graphic_area_width = ($this->space_between_bars * $this->total_parameters) + 30;
- $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
- $this->width += $this->graphic_area_x1 + 20;
- $this->width += ($this->legend_exists == true) ? 50 : ((7 * strlen($this->axis_x)) + 10);
- break;
-
- // Horizontal bars
- case 2:
- $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
- $this->graphic_area_width = ($this->string_width($this->higher_value_str, $this->size) > 50) ? (5 * ($this->string_width($this->higher_value_str, $this->size)) * 0.85) : 200;
- $this->graphic_area_x1 += 7 * strlen($this->biggest_x);
- $this->width += ($this->legend_exists == true) ? 60 : ((7 * strlen($this->axis_y)) + 30);
- $this->width += $this->graphic_area_x1;
- break;
-
- // Dots
- case 3:
- $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
- $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
- $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
- $this->width += $this->graphic_area_x1 + 20;
- $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
- break;
-
- // Lines
- case 4:
- $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
- $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
- $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
- $this->width += $this->graphic_area_x1 + 20;
- $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
- break;
-
- // Pie
- case 5:
- $this->legend_box_width = $this->string_width($this->biggest_x, $this->size) + 85;
- $this->graphic_area_width = 200;
- $this->width += 90;
- break;
-
- // Donut
- case 6:
- $this->legend_box_width = $this->string_width($this->biggest_x, $this->size) + 85;
- $this->graphic_area_width = 180;
- $this->width += 90;
- break;
- }
-
- $this->width += $this->graphic_area_width;
- $this->width += $this->legend_box_width;
-
-
- $this->graphic_area_x2 = $this->graphic_area_x1 + $this->graphic_area_width;
- $this->legend_box_x1 = $this->graphic_area_x2 + 40;
- $this->legend_box_x2 = $this->legend_box_x1 + $this->legend_box_width;
- }
-
- function calculate_height()
- {
- switch ($this->type)
- {
- // Vertical bars
- case 1:
- $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
- $this->graphic_area_height = 150;
- $this->height += 65;
- break;
-
- // Horizontal bars
- case 2:
- $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
- $this->graphic_area_height = ($this->space_between_bars * $this->total_parameters) + 10;
- $this->height += 65;
- break;
-
- // Dots
- case 3:
- $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
- $this->graphic_area_height = 150;
- $this->height += 65;
- break;
-
- // Lines
- case 4:
- $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
- $this->graphic_area_height = 150;
- $this->height += 65;
- break;
-
- // Pie
- case 5:
- $this->legend_box_height = (!empty($this->axis_x)) ? 30 : 5;
- $this->legend_box_height += (14 * $this->total_parameters);
- $this->graphic_area_height = 150;
- $this->height += 50;
- break;
-
- // Donut
- case 6:
- $this->legend_box_height = (!empty($this->axis_x)) ? 30 : 5;
- $this->legend_box_height += (14 * $this->total_parameters);
- $this->graphic_area_height = 180;
- $this->height += 50;
- break;
- }
-
- $this->height += $this->height_title;
- $this->height += ($this->legend_box_height > $this->graphic_area_height) ? ($this->legend_box_height - $this->graphic_area_height) : 0;
- $this->height += $this->graphic_area_height;
-
- $this->graphic_area_y2 = $this->graphic_area_y1 + $this->graphic_area_height;
- $this->legend_box_y1 = $this->graphic_area_y1 + 10;
- $this->legend_box_y2 = $this->legend_box_y1 + $this->legend_box_height;
- }
-
- function draw_legend()
- {
- $x1 = $this->legend_box_x1;
- $y1 = $this->legend_box_y1;
- $x2 = $this->legend_box_x2;
- $y2 = $this->legend_box_y2;
-
- imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bg_legend']);
-
- $x = $x1 + 5;
- $y = $y1 + 5;
-
-
- // Draw legend values for VERTICAL BARS, HORIZONTAL BARS, DOTS and LINES
- if (preg_match("/^(1|2|3|4)$/", $this->type))
- {
- $color_1 = (preg_match("/^(1|2)$/", $this->type)) ? $this->color['bars'] : $this->color['line'];
- $color_2 = (preg_match("/^(1|2)$/", $this->type)) ? $this->color['bars_2'] : $this->color['line_2'];
-
- imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_1);
- imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
- $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $this->graphic_1, $this->color['axis_values']);
- $y += 20;
- imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_2);
- imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
- $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $this->graphic_2, $this->color['axis_values']);
- }
-
- // Draw legend values for PIE or DONUT
- else if (preg_match("/^(5|6)$/", $this->type))
- {
- if (!empty($this->axis_x))
- {
- $this->_imagestring($this->img, $this->size, ((($x1+$x2)/2) - (strlen($this->axis_x)*7/2)), $y, $this->axis_x, $this->color['title']);
- $y += 25;
- }
-
- $num = 1;
-
- foreach ($this->x as $i => $parameter)
- {
- while ($num > 7)
- {
- $num -= 5;
- }
- $color = 'arc_' . $num;
-
- $percent = number_format(round(($this->y[$i] * 100 / $this->sum_total), 2), 2, ".", "") . ' %';
- $less = (strlen($percent) * 7);
-
- if ($num != 1)
- {
- imageline($this->img, ($x1+15), ($y-2), ($x2-5), ($y-2), $this->color['bg_lines']);
- }
- imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color[$color]);
- imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
- $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $parameter, $this->color['axis_values']);
- $this->_imagestring($this->img, $this->size, ($x2-$less), ($y-2), $percent, $this->color['axis_values']);
- $y += 14;
- $num++;
- }
- }
- }
-
-
- function string_width($string, $size)
- {
- $single_width = $size + 4;
- return $single_width * strlen($string);
- }
-
- function string_height($size)
- {
- if ($size <= 1)
- {
- $height = 8;
- }
- else if ($size <= 3)
- {
- $height = 12;
- }
- else if ($size >= 4)
- {
- $height = 14;
- }
- return $height;
- }
-
- function calculate_higher_value()
- {
- $digits = strlen(round($this->biggest_y));
- $interval = pow(10, ($digits-1));
- $this->higher_value = round(($this->biggest_y - ($this->biggest_y % $interval) + $interval), 1);
- $this->higher_value_str = $this->number_formated($this->higher_value, $this->dec1);
- }
-
- function number_formated($number, $dec_size = 1)
- {
- if ($this->latin_notation == true)
- return number_format(round($number, $dec_size), $dec_size, ",", ".");
- return number_format(round($number, $dec_size), $dec_size, ".", ",");
- }
-
- function number_float($number)
- {
- if ($this->latin_notation == true)
- $number = str_replace(".", "", $number);
- return (float)str_replace(",", "", $number);
- }
-
-
- function draw_credits()
- {
- $this->_imagestring($this->img, $this->size - 2, ($this->width-120), ($this->height-10), "Powered by Carlos Reche", $this->color['title']);
- }
-
-
- function load_color_palette()
- {
- switch ($this->skin)
- {
- // Office
- case 1:
- //$this->color['title'] = imagecolorallocate($this->img, 50, 50, 50);
- $this->color['title'] = imagecolorallocate($this->img, 40, 70, 130);
- //$this->color['background'] = imagecolorallocate($this->img, 238, 255, 238);
- $this->color['background'] = imagecolorallocate($this->img, 255, 255, 255);
- $this->color['axis_values'] = imagecolorallocate($this->img, 50, 50, 50);
- $this->color['axis_line'] = imagecolorallocate($this->img, 100, 100, 100);
- $this->color['bg_lines'] = imagecolorallocate($this->img, 220, 220, 220);
- $this->color['bg_legend'] = imagecolorallocate($this->img, 255, 255, 255);
-
- if (preg_match("/^(1|2)$/", $this->type))
- {
- $this->color['bars'] = imagecolorallocate($this->img, 100, 150, 200);
- $this->color['bars_shadow'] = imagecolorallocate($this->img, 50, 100, 150);
- $this->color['bars_2'] = imagecolorallocate($this->img, 200, 250, 150);
- $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 120, 170, 70);
- }
- else if (preg_match("/^(3|4)$/", $this->type))
- {
- $this->color['line'] = imagecolorallocate($this->img, 100, 150, 200);
- $this->color['line_2'] = imagecolorallocate($this->img, 230, 100, 100);
- }
- else if (preg_match("/^(5|6)$/", $this->type))
- {
- $this->color['arc_1'] = imagecolorallocate($this->img, 255, 150, 0);
- $this->color['arc_2'] = imagecolorallocate($this->img, 150, 0, 255);
- $this->color['arc_3'] = imagecolorallocate($this->img, 0, 255, 255);
- $this->color['arc_4'] = imagecolorallocate($this->img, 255, 0, 0);
- $this->color['arc_5'] = imagecolorallocate($this->img, 0, 255, 0);
- $this->color['arc_6'] = imagecolorallocate($this->img, 0, 0, 255);
- $this->color['arc_7'] = imagecolorallocate($this->img, 255, 255, 0);
- $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 127, 75, 0);
- $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 75, 0, 127);
- $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 0, 127, 127);
- $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 127, 0, 0);
- $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 0, 127, 0);
- $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 0, 0, 127);
- $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 127, 127, 0);
- }
- break;
-
- // Matrix
- case 2:
- $this->color['title'] = imagecolorallocate($this->img, 255, 255, 255);
- $this->color['background'] = imagecolorallocate($this->img, 0, 0, 0);
- $this->color['axis_values'] = imagecolorallocate($this->img, 0, 230, 0);
- $this->color['axis_line'] = imagecolorallocate($this->img, 0, 200, 0);
- $this->color['bg_lines'] = imagecolorallocate($this->img, 100, 100, 100);
- $this->color['bg_legend'] = imagecolorallocate($this->img, 70, 70, 70);
-
- if (preg_match("/^(1|2)$/", $this->type))
- {
- $this->color['bars'] = imagecolorallocate($this->img, 50, 200, 50);
- $this->color['bars_shadow'] = imagecolorallocate($this->img, 0, 150, 0);
- $this->color['bars_2'] = imagecolorallocate($this->img, 255, 255, 255);
- $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 220, 220, 220);
- }
- else if (preg_match("/^(3|4)$/", $this->type))
- {
- $this->color['line'] = imagecolorallocate($this->img, 220, 220, 220);
- $this->color['line_2'] = imagecolorallocate($this->img, 0, 180, 0);
- }
- else if (preg_match("/^(5|6)$/", $this->type))
- {
- $this->color['arc_1'] = imagecolorallocate($this->img, 255, 255, 255);
- $this->color['arc_2'] = imagecolorallocate($this->img, 200, 220, 200);
- $this->color['arc_3'] = imagecolorallocate($this->img, 160, 200, 160);
- $this->color['arc_4'] = imagecolorallocate($this->img, 135, 180, 135);
- $this->color['arc_5'] = imagecolorallocate($this->img, 115, 160, 115);
- $this->color['arc_6'] = imagecolorallocate($this->img, 100, 140, 100);
- $this->color['arc_7'] = imagecolorallocate($this->img, 90, 120, 90);
- $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 127, 127, 127);
- $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 100, 110, 100);
- $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 80, 100, 80);
- $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 67, 90, 67);
- $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 57, 80, 57);
- $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 50, 70, 50);
- $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 45, 60, 45);
- }
- break;
-
-
- // Spring
- case 3:
- $this->color['title'] = imagecolorallocate($this->img, 250, 50, 50);
- //$this->color['background'] = imagecolorallocate($this->img, 250, 250, 220);
- $this->color['background'] = imagecolorallocate($this->img, 255, 255, 255);
- $this->color['axis_values'] = imagecolorallocate($this->img, 50, 150, 50);
- $this->color['axis_line'] = imagecolorallocate($this->img, 50, 100, 50);
- $this->color['bg_lines'] = imagecolorallocate($this->img, 200, 224, 180);
- //$this->color['bg_legend'] = imagecolorallocate($this->img, 230, 230, 200);
- $this->color['bg_legend'] = imagecolorallocate($this->img, 255, 255, 255);
-
- if (preg_match("/^(1|2)$/", $this->type))
- {
- $this->color['bars'] = imagecolorallocate($this->img, 255, 170, 80);
- $this->color['bars_shadow'] = imagecolorallocate($this->img, 200, 120, 30);
- $this->color['bars_2'] = imagecolorallocate($this->img, 250, 230, 80);
- $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 180, 150, 0);
- }
- else if (preg_match("/^(3|4)$/", $this->type))
- {
- $this->color['line'] = imagecolorallocate($this->img, 230, 100, 0);
- $this->color['line_2'] = imagecolorallocate($this->img, 220, 200, 50);
- }
- else if (preg_match("/^(5|6)$/", $this->type))
- {
- $this->color['arc_1'] = imagecolorallocate($this->img, 100, 150, 200);
- $this->color['arc_2'] = imagecolorallocate($this->img, 200, 250, 150);
- $this->color['arc_3'] = imagecolorallocate($this->img, 250, 200, 150);
- $this->color['arc_4'] = imagecolorallocate($this->img, 250, 150, 150);
- $this->color['arc_5'] = imagecolorallocate($this->img, 250, 250, 150);
- $this->color['arc_6'] = imagecolorallocate($this->img, 230, 180, 250);
- $this->color['arc_7'] = imagecolorallocate($this->img, 200, 200, 150);
- $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 50, 75, 100);
- $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 100, 125, 75);
- $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 125, 100, 75);
- $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 125, 75, 75);
- $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 125, 125, 75);
- $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 115, 90, 125);
- $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 100, 100, 75);
- }
- break;
-
- }
- }
-
- function _imagestring($img, $size, $x, $y, $string, $col, $alt=0)
- {
- if ($alt && strlen($string) > 12)
- $string = substr($string, 0, 12);
-
- $encoding = $_SESSION['language']->encoding;
- if ($encoding != 'UTF-8') {
- if (function_exists('iconv'))
- $string = iconv($encoding, 'UTF-8', $string);