9 * Author: Carlos Reche/Joe Hunt
10 * E-mail: carlosreche@yahoo.com/joe.hunt.consulting@gmail.com
11 * Sorocaba, SP - Brazil/Wellington, New Zealand
13 * Created: Sep 20, 2004
14 * Last Modification: Sep 20, 2004/Apr 01, 2007
20 * graph creates 6 different types of graphics with how many parameters you want. You can
21 * change the appearance of the graphics in 3 different skins, and you can still cross data from 2
22 * graphics in only 1! It's a powerful script, and I recommend you read all the instructions
23 * to learn how to use all of this features. Don't worry, it's very simple to use it.
25 * This script is free. Please keep the credits.
31 INSTRUNCTIONS OF HOW TO USE THIS SCRIPT (Please, take a minute to read it. It's important!)
34 NOTE: make sure that your PHP is compiled to work with GD Lib.
36 ///// START OF EXAMPLE.PHP /////
40 require "class.graphics.inc";
52 In your html file you set it up as:
54 <img src="example.php" border="1" />
57 You can supply extra parameters to display(). Ex. $pg->display("test.png") will save the image to a file.
58 Ex. $pg->display("", true) will paint a border around the image. It might be suitable if you choose to save to
59 file for later presentation.
61 ///// END OF EXAMPLE.PHP /////
65 Here is a list of all parameters you may set:
67 title => Title of the graphic
68 axis_x => Name of values from Axis X
69 axis_y => Name of values from Axis Y
70 graphic_1 => Name of Graphic_1 (only shown if you are gonna cross data from 2 different graphics)
71 graphic_2 => Name of Graphic_2 (same comment of above)
73 type => Type of graphic (values 1 to 6)
74 1 => Vertical bars (default)
81 skin => Skin of the graphic (values 1 to 3)
86 credits => Only if you want to show my credits in the image. :)
87 0 => doesn't show (default)
90 x[0] => Name of the first parameter in Axis X
91 x[1] => Name of the second parameter in Axis X
94 y[0] => Value from "graphic_1" relative for "x[0]"
95 y[1] => Value from "graphic_1" relative for "x[1]"
98 z[0] => Value from "graphic_2" relative for "x[0]"
99 z[1] => Value from "graphic_2" relative for "x[1]"
103 NOTE: You can't cross data between graphics if you use "pie" or "donut" graphic. Values for "z"
104 won't be considerated.
106 That's all! Hope you make a good use of it!
107 It would be nice to receive feedback from others users. All comments are welcome!
140 var $total_parameters;
143 var $biggest_parameter;
144 var $available_types;
147 var $h3d = 15; // 3D height
148 var $built_in = true;
153 $this->x = $this->y = $this->z = array();
155 $this->biggest_x = NULL;
156 $this->biggest_y = NULL;
157 $this->alternate_x = false;
158 $this->graphic_2_exists = false;
159 $this->total_parameters = 0;
160 $this->sum_total = 1;
161 $this->latin_notation = false;
165 function display($save="", $border=false)
167 $this->legend_exists = (ereg("(5|6)", $this->type)) ? true : false;
168 $this->biggest_graphic_name = (strlen($this->graphic_1) > strlen($this->graphic_2)) ? $this->graphic_1 : $this->graphic_2;
169 $this->height_title = (!empty($this->title)) ? ($this->string_height($this->tsize) + 15) : 0;
170 $this->space_between_bars = ($this->type == 1) ? 40 : 30;
171 $this->space_between_dots = 40;
172 $this->higher_value = 0;
173 $this->higher_value_str = 0;
177 $this->graphic_area_width = 0;
178 $this->graphic_area_height = 0;
179 $this->graphic_area_x1 = 30;
180 $this->graphic_area_y1 = 20 + $this->height_title;
181 $this->graphic_area_x2 = $this->graphic_area_x1 + $this->graphic_area_width;
182 $this->graphic_area_y2 = $this->graphic_area_y1 + $this->graphic_area_height;
184 if (count($this->z) && (ereg("(1|2|3|4)", $this->type)))
185 $this->graphic_2_exists = true;
186 $this->total_parameters = count($this->x);
187 for ($i = 0; $i < $this->total_parameters; $i++)
189 if (strlen($this->x[$i]) > strlen($this->biggest_x))
190 $this->biggest_x = $this->x[$i];
191 if ($this->y[$i] > $this->biggest_y)
192 $this->biggest_y = number_format(round($this->y[$i], 1), 1, ".", "");
193 if ($this->graphic_2_exists)
195 if (isset($this->z[$i]) && $this->z[$i] > $this->biggest_y)
196 $this->biggest_y = number_format(round($this->z[$i], 1), 1, ".", "");
200 if (($this->graphic_2_exists == true) && ((!empty($this->graphic_1)) || (!empty($this->graphic_2))))
202 $this->legend_exists = true;
205 $this->sum_total = array_sum($this->y);
206 $this->space_between_bars += ($this->graphic_2_exists == true) ? 10 : 0;
208 $this->calculate_higher_value();
209 $this->calculate_width();
210 $this->calculate_height();
212 $this->create_graphic($save, $border);
215 function create_graphic($save="", $border=false)
218 $this->img = imagecreatetruecolor($this->width, $this->height);
220 $this->load_color_palette();
223 imagefill($this->img, 0, 0, $this->color['background']);
224 //imagefilledrectangle($this->img, 0, 0, $this->width, $this->height, $this->color['background']);
226 imagerectangle($this->img, 0, 0, $this->width-1, $this->height-1, $this->color['bars']);
229 if (!empty($this->title))
231 $center = ($this->width / 2) - ($this->string_width($this->title, $this->tsize) / 2);
232 $this->_imagestring($this->img, $this->tsize, $center, 10, $this->title, $this->color['title']);
236 // Draw axis and background lines for "vertical bars", "dots" and "lines"
237 if (ereg("^(1|3|4)$", $this->type))
239 if ($this->legend_exists == true)
241 $this->draw_legend();
244 $higher_value_y = $this->graphic_area_y1 + (0.1 * $this->graphic_area_height);
245 $higher_value_size = 0.9 * $this->graphic_area_height;
247 $less = 7 * strlen($this->higher_value_str);
249 imageline($this->img, $this->graphic_area_x1, $higher_value_y, $this->graphic_area_x2, $higher_value_y, $this->color['bg_lines']);
250 $this->_imagestring($this->img, $this->size, ($this->graphic_area_x1-$less-7), ($higher_value_y-7), $this->higher_value_str, $this->color['axis_values']);
252 for ($i = 1; $i < 10; $i++)
254 $dec_y = $i * ($higher_value_size / 10);
255 $x1 = $this->graphic_area_x1;
256 $y1 = $this->graphic_area_y2 - $dec_y;
257 $x2 = $this->graphic_area_x2;
258 $y2 = $this->graphic_area_y2 - $dec_y;
260 imageline($this->img, $x1, $y1, $x2, $y2, $this->color['bg_lines']);
263 $value = $this->number_formated($this->higher_value * $i / 10, $this->dec1);
264 $less = 7 * strlen($value);
265 $this->_imagestring($this->img, $this->size, ($x1-$less-7), ($y2-7), $value, $this->color['axis_values']);
270 $this->_imagestring($this->img, $this->size, $this->graphic_area_x2+10, $this->graphic_area_y2+3, $this->axis_x, $this->color['title']);
271 imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
273 $this->_imagestring($this->img, $this->size, 20, $this->graphic_area_y1-20, $this->axis_y, $this->color['title']);
274 imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
278 // Draw axis and background lines for "horizontal bars"
279 else if ($this->type == 2)
281 if ($this->legend_exists == true)
283 $this->draw_legend();
286 $higher_value_x = $this->graphic_area_x2 - (0.2 * $this->graphic_area_width);
287 $higher_value_size = 0.8 * $this->graphic_area_width;
289 imageline($this->img, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y1, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y2, $this->color['bg_lines']);
290 $this->_imagestring($this->img, $this->size, (($this->graphic_area_x1+$higher_value_size) - ($this->string_width($this->higher_value, $this->size)/2)), ($this->graphic_area_y2+2), $this->higher_value_str, $this->color['axis_values']);
292 for ($i = 1, $alt = 15; $i < 10; $i++)
294 $dec_x = number_format(round($i * ($higher_value_size / 10), 1), 1, ".", "");
296 imageline($this->img, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y1, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y2, $this->color['bg_lines']);
299 $alt = (strlen($this->biggest_y) > 4 && $alt != 15) ? 15 : 2;
300 $value = $this->number_formated($this->higher_value * $i / 10, $this->dec1);
301 $this->_imagestring($this->img, $this->size, (($this->graphic_area_x1+$dec_x) - ($this->string_width($this->higher_value, $this->size)/2)), ($this->graphic_area_y2), $value, $this->color['axis_values'], $alt);
306 $this->_imagestring($this->img, $this->size, ($this->graphic_area_x2+10), ($this->graphic_area_y2+3), $this->axis_y, $this->color['title']);
307 imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
309 $this->_imagestring($this->img, $this->size, 20, ($this->graphic_area_y1-20), $this->axis_x, $this->color['title']);
310 imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
314 // Draw legend box for "pie" or "donut"
315 else if (ereg("^(5|6)$", $this->type))
317 $this->draw_legend();
323 * Draw graphic: VERTICAL BARS
325 if ($this->type == 1)
328 $x = $this->graphic_area_x1 + 20;
330 foreach ($this->x as $i => $parameter)
332 if (isset($this->z[$i]))
334 $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
336 $y1 = ($this->graphic_area_y2 - $size) + 1;
338 $y2 = $this->graphic_area_y2 - 1;
339 imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_2_shadow']);
340 imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_2_shadow']);
341 imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_2_shadow']);
342 imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
345 $size = round($this->y[$i] * $higher_value_size / $this->higher_value);
346 $alt = (($num % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
348 $y1 = ($this->graphic_area_y2 - $size) + 1;
350 $y2 = $this->graphic_area_y2 - 1;
351 $x += $this->space_between_bars;
354 imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_shadow']);
355 imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_shadow']);
356 imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_shadow']);
357 imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
358 $this->_imagestring($this->img, $this->size, ((($x1+$x2)/2) - (strlen($parameter)*7/2)), ($y2+2), $parameter, $this->color['axis_values'], $alt);
364 * Draw graphic: HORIZONTAL BARS
366 else if ($this->type == 2)
370 foreach ($this->x as $i => $parameter)
372 if (isset($this->z[$i]))
374 $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
375 $x1 = $this->graphic_area_x1 + 1;
376 $y1 = $this->graphic_area_y1 + $y + 10;
379 imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_2_shadow']);
380 imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_2_shadow']);
381 imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_2_shadow']);
382 imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
383 $this->_imagestring($this->img, $this->size, ($x2+7), ($y1+7), $this->number_formated($this->z[$i], $this->dec2), $this->color['bars_2_shadow']);
386 $size = round(($this->y[$i] / $this->higher_value) * $higher_value_size);
387 $x1 = $this->graphic_area_x1 + 1;
388 $y1 = $this->graphic_area_y1 + $y;
391 $y += $this->space_between_bars;
393 imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_shadow']);
394 imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_shadow']);
395 imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_shadow']);
396 imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
397 $this->_imagestring($this->img, $this->size, ($x2+7), ($y1+2), $this->number_formated($this->y[$i], $this->dec2), $this->color['bars_shadow']);
399 $this->_imagestring($this->img, $this->size, ($x1 - ((strlen($parameter)*7)+7)), ($y1+2), $parameter, $this->color['axis_values']);
405 * Draw graphic: DOTS or LINE
407 else if (ereg("^(3|4)$", $this->type))
410 $x[0] = $this->graphic_area_x1+1;
412 foreach ($this->x as $i => $parameter)
414 if ($this->graphic_2_exists == true)
416 $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
417 $z[$i] = $this->graphic_area_y2 - $size;
420 $alt = (($i % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
421 $size = round($this->y[$i] * $higher_value_size / $this->higher_value);
422 $y[$i] = $this->graphic_area_y2 - $size;
426 imageline($this->img, $x[$i], ($this->graphic_area_y1+10), $x[$i], ($this->graphic_area_y2-1), $this->color['bg_lines']);
428 $this->_imagestring($this->img, $this->size, ($x[$i] - (strlen($parameter)*7/2 )), ($this->graphic_area_y2+2), $parameter, $this->color['axis_values'], $alt);
430 $x[$i+1] = $x[$i] + 40;
433 foreach ($x as $i => $value_x)
435 if ($this->graphic_2_exists == true)
440 if ($this->type == 4)
442 imageline($this->img, $x[$i], $z[$i], $x[$i+1], $z[$i+1], $this->color['line_2']);
443 imageline($this->img, $x[$i], ($z[$i]+1), $x[$i+1], ($z[$i+1]+1), $this->color['line_2']);
445 imagefilledrectangle($this->img, $x[$i]-1, $z[$i]-1, $x[$i]+2, $z[$i]+2, $this->color['line_2']);
449 imagefilledrectangle($this->img, $x[$i-1]-1, $z[$i-1]-1, $x[$i-1]+2, $z[$i-1]+2, $this->color['line_2']);
458 if ($this->type == 4)
460 imageline($this->img, $x[$i], $y[$i], $x[$i+1], $y[$i+1], $this->color['line']);
461 imageline($this->img, $x[$i], ($y[$i]+1), $x[$i+1], ($y[$i+1]+1), $this->color['line']);
463 imagefilledrectangle($this->img, $x[$i]-1, $y[$i]-1, $x[$i]+2, $y[$i]+2, $this->color['line']);
467 imagefilledrectangle($this->img, $x[$i-1]-1, $y[$i-1]-1, $x[$i-1]+2, $y[$i-1]+2, $this->color['line']);
476 * Draw graphic: PIE or DONUT
478 else if (ereg("^(5|6)$", $this->type))
480 $center_x = ($this->graphic_area_x1 + $this->graphic_area_x2) / 2;
481 $center_y = ($this->graphic_area_y1 + $this->graphic_area_y2) / 2;
482 $width = $this->graphic_area_width;
483 $height = $this->graphic_area_height;
487 foreach ($this->x as $i => $parameter)
489 $size = $this->y[$i] * 360 / $this->sum_total;
496 if ($this->type == 5)
499 foreach ($sizes as $i => $size)
502 while ($num_color > 7)
506 $color = 'arc_' . $num_color . '_shadow';
508 for ($i = $this->h3d; $i >= 0; $i--)
510 //imagearc($this->img, $center_x, ($center_y+$i), $width, $height, $start, ($start+$size), $this->color[$color]);
511 imagefilledarc($this->img, $center_x, ($center_y+$i), $width, $height, $start, ($start+$size), $this->color[$color], IMG_ARC_NOFILL);
519 foreach ($sizes as $i => $size)
522 while ($num_color > 7)
526 $color = 'arc_' . $num_color;
528 imagefilledarc($this->img, $center_x, $center_y, ($width+2), ($height+2), $start, ($start+$size), $this->color[$color], IMG_ARC_EDGED);
534 else if ($this->type == 6)
536 foreach ($sizes as $i => $size)
539 while ($num_color > 7)
543 $color = 'arc_' . $num_color;
544 $color_shadow = 'arc_' . $num_color . '_shadow';
545 imagefilledarc($this->img, $center_x, $center_y, $width, $height, $start, ($start+$size), $this->color[$color], IMG_ARC_PIE);
548 imagefilledarc($this->img, $center_x, $center_y, 100, 100, 0, 360, $this->color['background'], IMG_ARC_PIE);
549 imagearc($this->img, $center_x, $center_y, 100, 100, 0, 360, $this->color['bg_legend']);
550 imagearc($this->img, $center_x, $center_y, ($width+1), ($height+1), 0, 360, $this->color['bg_legend']);
555 if ($this->credits == true)
557 $this->draw_credits();
560 imagepng($this->img, $save);
563 header('Content-type: image/png');
564 imagepng($this->img);
566 imagedestroy($this->img);
569 function calculate_width()
575 $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->tsize) + 25) : 0;
576 $this->graphic_area_width = ($this->space_between_bars * $this->total_parameters) + 30;
577 $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
578 $this->width += $this->graphic_area_x1 + 20;
579 $this->width += ($this->legend_exists == true) ? 50 : ((7 * strlen($this->axis_x)) + 10);
584 $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
585 $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;
586 $this->graphic_area_x1 += 7 * strlen($this->biggest_x);
587 $this->width += ($this->legend_exists == true) ? 60 : ((7 * strlen($this->axis_y)) + 30);
588 $this->width += $this->graphic_area_x1;
593 $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
594 $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
595 $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
596 $this->width += $this->graphic_area_x1 + 20;
597 $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
602 $this->legend_box_width = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, $this->size) + 25) : 0;
603 $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
604 $this->graphic_area_x1 += $this->string_width(($this->higher_value_str), $this->size);
605 $this->width += $this->graphic_area_x1 + 20;
606 $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
611 $this->legend_box_width = $this->string_width($this->biggest_x, $this->size) + 85;
612 $this->graphic_area_width = 200;
618 $this->legend_box_width = $this->string_width($this->biggest_x, $this->size) + 85;
619 $this->graphic_area_width = 180;
624 $this->width += $this->graphic_area_width;
625 $this->width += $this->legend_box_width;
628 $this->graphic_area_x2 = $this->graphic_area_x1 + $this->graphic_area_width;
629 $this->legend_box_x1 = $this->graphic_area_x2 + 40;
630 $this->legend_box_x2 = $this->legend_box_x1 + $this->legend_box_width;
633 function calculate_height()
639 $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
640 $this->graphic_area_height = 150;
646 $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
647 $this->graphic_area_height = ($this->space_between_bars * $this->total_parameters) + 10;
653 $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
654 $this->graphic_area_height = 150;
660 $this->legend_box_height = ($this->graphic_2_exists == true) ? 40 : 0;
661 $this->graphic_area_height = 150;
667 $this->legend_box_height = (!empty($this->axis_x)) ? 30 : 5;
668 $this->legend_box_height += (14 * $this->total_parameters);
669 $this->graphic_area_height = 150;
675 $this->legend_box_height = (!empty($this->axis_x)) ? 30 : 5;
676 $this->legend_box_height += (14 * $this->total_parameters);
677 $this->graphic_area_height = 180;
682 $this->height += $this->height_title;
683 $this->height += ($this->legend_box_height > $this->graphic_area_height) ? ($this->legend_box_height - $this->graphic_area_height) : 0;
684 $this->height += $this->graphic_area_height;
686 $this->graphic_area_y2 = $this->graphic_area_y1 + $this->graphic_area_height;
687 $this->legend_box_y1 = $this->graphic_area_y1 + 10;
688 $this->legend_box_y2 = $this->legend_box_y1 + $this->legend_box_height;
691 function draw_legend()
693 $x1 = $this->legend_box_x1;
694 $y1 = $this->legend_box_y1;
695 $x2 = $this->legend_box_x2;
696 $y2 = $this->legend_box_y2;
698 imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bg_legend']);
704 // Draw legend values for VERTICAL BARS, HORIZONTAL BARS, DOTS and LINES
705 if (ereg("^(1|2|3|4)$", $this->type))
707 $color_1 = (ereg("^(1|2)$", $this->type)) ? $this->color['bars'] : $this->color['line'];
708 $color_2 = (ereg("^(1|2)$", $this->type)) ? $this->color['bars_2'] : $this->color['line_2'];
710 imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_1);
711 imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
712 $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $this->graphic_1, $this->color['axis_values']);
714 imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_2);
715 imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
716 $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $this->graphic_2, $this->color['axis_values']);
719 // Draw legend values for PIE or DONUT
720 else if (ereg("^(5|6)$", $this->type))
722 if (!empty($this->axis_x))
724 $this->_imagestring($this->img, $this->size, ((($x1+$x2)/2) - (strlen($this->axis_x)*7/2)), $y, $this->axis_x, $this->color['title']);
730 foreach ($this->x as $i => $parameter)
736 $color = 'arc_' . $num;
738 $percent = number_format(round(($this->y[$i] * 100 / $this->sum_total), 2), 2, ".", "") . ' %';
739 $less = (strlen($percent) * 7);
743 imageline($this->img, ($x1+15), ($y-2), ($x2-5), ($y-2), $this->color['bg_lines']);
745 imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color[$color]);
746 imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
747 $this->_imagestring($this->img, $this->size, ($x+15), ($y-2), $parameter, $this->color['axis_values']);
748 $this->_imagestring($this->img, $this->size, ($x2-$less), ($y-2), $percent, $this->color['axis_values']);
756 function string_width($string, $size)
758 $single_width = $size + 4;
759 return $single_width * strlen($string);
762 function string_height($size)
779 function calculate_higher_value()
781 $digits = strlen(round($this->biggest_y));
782 $interval = pow(10, ($digits-1));
783 $this->higher_value = round(($this->biggest_y - ($this->biggest_y % $interval) + $interval), 1);
784 $this->higher_value_str = $this->number_formated($this->higher_value, $this->dec1);
787 function number_formated($number, $dec_size = 1)
789 if ($this->latin_notation == true)
790 return number_format(round($number, $dec_size), $dec_size, ",", ".");
791 return number_format(round($number, $dec_size), $dec_size, ".", ",");
794 function number_float($number)
796 if ($this->latin_notation == true)
797 $number = str_replace(".", "", $number);
798 return (float)str_replace(",", "", $number);
802 function draw_credits()
804 $this->_imagestring($this->img, $this->size - 2, ($this->width-120), ($this->height-10), "Powered by Carlos Reche", $this->color['title']);
808 function load_color_palette()
814 $this->color['title'] = imagecolorallocate($this->img, 50, 50, 50);
815 $this->color['background'] = imagecolorallocate($this->img, 238, 255, 238);
816 $this->color['axis_values'] = imagecolorallocate($this->img, 50, 50, 50);
817 $this->color['axis_line'] = imagecolorallocate($this->img, 100, 100, 100);
818 $this->color['bg_lines'] = imagecolorallocate($this->img, 220, 220, 220);
819 $this->color['bg_legend'] = imagecolorallocate($this->img, 255, 255, 255);
821 if (ereg("^(1|2)$", $this->type))
823 $this->color['bars'] = imagecolorallocate($this->img, 100, 150, 200);
824 $this->color['bars_shadow'] = imagecolorallocate($this->img, 50, 100, 150);
825 $this->color['bars_2'] = imagecolorallocate($this->img, 200, 250, 150);
826 $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 120, 170, 70);
828 else if (ereg("^(3|4)$", $this->type))
830 $this->color['line'] = imagecolorallocate($this->img, 100, 150, 200);
831 $this->color['line_2'] = imagecolorallocate($this->img, 230, 100, 100);
833 else if (ereg("^(5|6)$", $this->type))
835 $this->color['arc_1'] = imagecolorallocate($this->img, 255, 150, 0);
836 $this->color['arc_2'] = imagecolorallocate($this->img, 150, 0, 255);
837 $this->color['arc_3'] = imagecolorallocate($this->img, 0, 255, 255);
838 $this->color['arc_4'] = imagecolorallocate($this->img, 255, 0, 0);
839 $this->color['arc_5'] = imagecolorallocate($this->img, 0, 255, 0);
840 $this->color['arc_6'] = imagecolorallocate($this->img, 0, 0, 255);
841 $this->color['arc_7'] = imagecolorallocate($this->img, 255, 255, 0);
842 $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 127, 75, 0);
843 $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 75, 0, 127);
844 $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 0, 127, 127);
845 $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 127, 0, 0);
846 $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 0, 127, 0);
847 $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 0, 0, 127);
848 $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 127, 127, 0);
854 $this->color['title'] = imagecolorallocate($this->img, 255, 255, 255);
855 $this->color['background'] = imagecolorallocate($this->img, 0, 0, 0);
856 $this->color['axis_values'] = imagecolorallocate($this->img, 0, 230, 0);
857 $this->color['axis_line'] = imagecolorallocate($this->img, 0, 200, 0);
858 $this->color['bg_lines'] = imagecolorallocate($this->img, 100, 100, 100);
859 $this->color['bg_legend'] = imagecolorallocate($this->img, 70, 70, 70);
861 if (ereg("^(1|2)$", $this->type))
863 $this->color['bars'] = imagecolorallocate($this->img, 50, 200, 50);
864 $this->color['bars_shadow'] = imagecolorallocate($this->img, 0, 150, 0);
865 $this->color['bars_2'] = imagecolorallocate($this->img, 255, 255, 255);
866 $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 220, 220, 220);
868 else if (ereg("^(3|4)$", $this->type))
870 $this->color['line'] = imagecolorallocate($this->img, 220, 220, 220);
871 $this->color['line_2'] = imagecolorallocate($this->img, 0, 180, 0);
873 else if (ereg("^(5|6)$", $this->type))
875 $this->color['arc_1'] = imagecolorallocate($this->img, 255, 255, 255);
876 $this->color['arc_2'] = imagecolorallocate($this->img, 200, 220, 200);
877 $this->color['arc_3'] = imagecolorallocate($this->img, 160, 200, 160);
878 $this->color['arc_4'] = imagecolorallocate($this->img, 135, 180, 135);
879 $this->color['arc_5'] = imagecolorallocate($this->img, 115, 160, 115);
880 $this->color['arc_6'] = imagecolorallocate($this->img, 100, 140, 100);
881 $this->color['arc_7'] = imagecolorallocate($this->img, 90, 120, 90);
882 $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 127, 127, 127);
883 $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 100, 110, 100);
884 $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 80, 100, 80);
885 $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 67, 90, 67);
886 $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 57, 80, 57);
887 $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 50, 70, 50);
888 $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 45, 60, 45);
895 $this->color['title'] = imagecolorallocate($this->img, 250, 50, 50);
896 $this->color['background'] = imagecolorallocate($this->img, 250, 250, 220);
897 $this->color['axis_values'] = imagecolorallocate($this->img, 50, 150, 50);
898 $this->color['axis_line'] = imagecolorallocate($this->img, 50, 100, 50);
899 $this->color['bg_lines'] = imagecolorallocate($this->img, 200, 224, 180);
900 $this->color['bg_legend'] = imagecolorallocate($this->img, 230, 230, 200);
902 if (ereg("^(1|2)$", $this->type))
904 $this->color['bars'] = imagecolorallocate($this->img, 255, 170, 80);
905 $this->color['bars_shadow'] = imagecolorallocate($this->img, 200, 120, 30);
906 $this->color['bars_2'] = imagecolorallocate($this->img, 250, 230, 80);
907 $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 180, 150, 0);
909 else if (ereg("^(3|4)$", $this->type))
911 $this->color['line'] = imagecolorallocate($this->img, 230, 100, 0);
912 $this->color['line_2'] = imagecolorallocate($this->img, 220, 200, 50);
914 else if (ereg("^(5|6)$", $this->type))
916 $this->color['arc_1'] = imagecolorallocate($this->img, 100, 150, 200);
917 $this->color['arc_2'] = imagecolorallocate($this->img, 200, 250, 150);
918 $this->color['arc_3'] = imagecolorallocate($this->img, 250, 200, 150);
919 $this->color['arc_4'] = imagecolorallocate($this->img, 250, 150, 150);
920 $this->color['arc_5'] = imagecolorallocate($this->img, 250, 250, 150);
921 $this->color['arc_6'] = imagecolorallocate($this->img, 230, 180, 250);
922 $this->color['arc_7'] = imagecolorallocate($this->img, 200, 200, 150);
923 $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 50, 75, 100);
924 $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 100, 125, 75);
925 $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 125, 100, 75);
926 $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 125, 75, 75);
927 $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 125, 125, 75);
928 $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 115, 90, 125);
929 $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 100, 100, 75);
936 function _imagestring($img, $size, $x, $y, $string, $col, $alt=0)
938 if ($alt && strlen($string) > 12)
939 $string = substr($string, 0, 12);
942 imagestring($img, $size, $x, $y + $alt, $string, $col);
961 imagettftext($img, $size, $angle, $x, $y + $alt, $col, $this->fontfile, $string);