function plot($file) { $min = $this->m_minValue; $max = $this->m_maxValue + ($this->m_maxValue - $this->m_minValue) * 0.1 / 5 * 5; if ($min - $max == 0) { $min = 0; } // margins $margin = $this->m_margin; $marginy = $margin; if ($this->m_title) { $marginy += $this->m_fontHeight * 1.5; } $marginbottom = $margin + 5; if ($this->m_labelsDirection == HORIZONTAL) { $marginbottom += $this->m_labelsFontWidth; } else { $marginbottom += $this->m_labelsMaxLength * $this->m_labelsFontWidth; } if (@$this->m_axisXTitle) { $marginbottom += $this->m_axisXFontHeight * 1.5; } $height = $this->m_height - $marginy - $marginbottom; if ($m_withLegend) { // } $maxvalues = floor($height / $this->m_labelsFontHeight / 1.5); // max displayable values $marginx = $margin + 5; $marginx += strlen(number_format($this->m_maxValue, $this->m_numberOfDecimals, ',', '.')) * $this->m_labelsFontWidth; if (@$this->m_axisYTitle) { $marginx += $this->m_axisYFontHeight * 1.5; } $width = $this->m_width - $marginx - $margin; $w = $width / ($this->m_maxCount + 0.2); $dx = $w * 0.8; $sx = $w - $dx; $width = $w * $this->m_maxCount + $sx; $h = $height / $maxvalues; $dy = $height / ($max - $min); $vdy = ($max - $min) / $maxvalues; //plot border & background imagefilledrectangle($this->m_image, $marginx, $marginy, $marginx + $width, $marginy + $height, $this->m_fillColor); // plot title if ($this->m_title) { imagestring($this->m_image, $this->m_font, ($this->m_width - strlen($this->m_title) * $this->m_fontWidth) / 2, $margin, $this->m_title, $this->m_textColor); } // plot values (Y) _set_style($this->m_image, $this->m_axisYStyle, $this->m_axisYColor, $this->m_fillColor); for ($i = 0; $i <= $maxvalues; $i++) { $yvalue = number_format($min + $vdy * $i, $this->m_numberOfDecimals, $this->m_decimalSeparator, $this->m_thousandsSeparator); imageline($this->m_image, $marginx - 3, $marginy + $height - $i * $h, $marginx, $marginy + $height - $i * $h, IMG_COLOR_STYLED); imagestring($this->m_image, $this->m_labelsFont, $marginx - strlen($yvalue) * $this->m_labelsFontWidth - 4, $marginy + $height - $i * $h - $this->m_labelsFontHeight / 2, $yvalue, $this->m_labelsTextColor); } // plot grid if ($this->m_showHGrid) { for ($i = 0; $i <= $maxvalues; $i++) { _set_style($this->m_image, $this->m_gridHStyle, $this->m_gridHColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy + $height - $i * $h, $marginx + $width, $marginy + $height - $i * $h, IMG_COLOR_STYLED); } } if ($this->m_showVGrid) { for ($i = 0; $i < count($this->m_labels); $i++) { $len = strlen($this->m_labels[$i]); if ($len > 0) { _set_style($this->m_image, $this->m_gridVStyle, $this->m_gridVColor, $this->m_fillColor); imageline($this->m_image, $marginx + $i * $w + $dx / 2 + $sx, $height + $marginy, $i * $w + $marginx + $dx / 2 + $sx, $marginy, IMG_COLOR_STYLED); } } } _set_style($this->m_image, $this->m_style, $this->m_strokeColor, $this->m_fillColor); imagerectangle($this->m_image, $marginx, $marginy, $marginx + $width, $marginy + $height, IMG_COLOR_STYLED); // plot graph foreach ($this->m_series as $series) { $cnt = count($series->m_values); // LINE PLOT if ($series->m_type == 'line') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $startx = $marginx + $dx / 2 + $sx; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); for ($i = 1; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imageline($this->m_image, $startx, $starty, $x, $y, IMG_COLOR_STYLED); $startx = $x; $starty = $y; } // AREA PLOT } else { if ($series->m_type == 'area') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $vpoints = ''; $startx = $marginx + $dx / 2 + $sx; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); $vpoints[] = $startx; $vpoints[] = $marginy + $height; for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); $vpoints[] = $x; $vpoints[] = $y; $startx = $x; $starty = $y; } $vpoints[] = $x; $vpoints[] = $marginy + $height; imagefilledpolygon($this->m_image, $vpoints, $cnt + 2, $series->m_fillColor); imagepolygon($this->m_image, $vpoints, $cnt + 2, IMG_COLOR_STYLED); // BAR PLOT } else { if ($series->m_type == 'bar') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $vpoints = ''; for ($i = 0; $i < $cnt; $i++) { imagefilledrectangle($this->m_image, $sx + $marginx + $i * $w, $marginy + $height - $dy * ($series->m_values[$i] - $min), $sx + $marginx + $i * $w + $dx, $marginy + $height, $series->m_fillColor); imagerectangle($this->m_image, $sx + $marginx + $i * $w, $marginy + $height - $dy * ($series->m_values[$i] - $min), $sx + $marginx + $i * $w + $dx, $marginy + $height, IMG_COLOR_STYLED); } // IMPULS PLOT } else { if ($series->m_type == 'impuls') { _set_style($this->m_image, $series->m_style, $series->m_fillColor, $this->m_fillColor); for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imageline($this->m_image, $x, $y, $x, $marginy + $height, IMG_COLOR_STYLED); } // STEP PLOT } else { if ($series->m_type == 'step') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $cnt = $cnt; $vpoints = ''; $startx = $marginx + $sx / 2; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); $vpoints[] = $startx; $vpoints[] = $marginy + $height; $vpoints[] = $startx; $vpoints[] = $starty; for ($i = 1; $i < $cnt; $i++) { $x = $marginx + $i * $w + $sx / 2; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); $vpoints[] = $x; $vpoints[] = $starty; $vpoints[] = $x; $vpoints[] = $y; $startx = $x; $starty = $y; } $vpoints[] = $x + $w; $vpoints[] = $y; $vpoints[] = $x + $w; $vpoints[] = $marginy + $height; imagefilledpolygon($this->m_image, $vpoints, $cnt * 2 + 2, $series->m_fillColor); imagepolygon($this->m_image, $vpoints, $cnt * 2 + 2, IMG_COLOR_STYLED); // DOT PLOT } else { if ($series->m_type == 'dot') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imagerectangle($this->m_image, $x - 2, $y - 2, $x + 2, $y + 2, IMG_COLOR_STYLED); imagefilledrectangle($this->m_image, $x - 1, $y - 1, $x + 1, $y + 1, $series->m_fillColor); } } } } } } } } // plot X labels for ($i = 0; $i < count($this->m_labels); $i++) { $len = strlen($this->m_labels[$i]); if ($len > 0) { _set_style($this->m_image, $this->m_axisXStyle, $this->m_axisXColor, $this->m_fillColor); imageline($this->m_image, $dx / 2 + $sx + $marginx + $i * $w, $height + $marginy, $dx / 2 + $sx + $i * $w + $marginx, $height + $marginy + 3, IMG_COLOR_STYLED); if ($this->m_labelsDirection == HORIZONTAL) { imagestring($this->m_image, $this->m_labelsFont, $dx / 2 + $sx + $marginx + $i * $w - $len * $this->m_labelsFontWidth / 2, $marginy + 4 + $height, $this->m_labels[$i], $this->m_labelsTextColor); } else { imagestringup($this->m_image, $this->m_labelsFont, $dx / 2 + $sx + $marginx + $i * $w - $this->m_labelsFontHeight / 2, $marginy + $height + $len * $this->m_labelsFontWidth + 4, $this->m_labels[$i], $this->m_labelsTextColor); } } } // plot X axis if ($this->m_showXAxis) { _set_style($this->m_image, $this->m_axisXStyle, $this->m_axisXColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy + $height, $marginx + $width, $marginy + $height, IMG_COLOR_STYLED); if ($this->m_axisXTitle) { imagestring($this->m_image, $this->m_axisXFont, $marginx + ($width - strlen($this->m_axisXTitle) * $this->m_axisXFontWidth) / 2, $this->m_height - $margin - $this->m_axisXFontHeight, $this->m_axisXTitle, $this->m_axisXColor); } } // plot Y axis if ($this->m_showYAxis) { _set_style($this->m_image, $this->m_axisYStyle, $this->m_axisYColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy, $marginx, $marginy + $height, IMG_COLOR_STYLED); if ($this->m_axisYTitle) { $titlewidth = strlen($this->m_axisYTitle) * $this->m_axisYFontWidth; imagestringup($this->m_image, $this->m_axisYFont, $margin, $marginy + $titlewidth + ($height - $titlewidth) / 2, $this->m_axisYTitle, $this->m_axisYColor); } } if (strlen($file) > 0) { imagepng($this->m_image, $file); } else { imagepng($this->m_image); } }
function plot($file) { // patch this code changed by Emilio Veloso $min = $this->m_minValue; $max = $this->m_maxValue + ($this->m_maxValue - $this->m_minValue) * 0.1 / 5 * 5; // margins //with legends if (isset($this->m_withLegend)) { $count = count($this->m_numLegends); $this->m_legend_width = 0; foreach ($this->m_numLegends as $lege) { $this->m_legend_width += $this->m_legendFontWidth * strlen($lege); } // count separtator spaces $this->m_legend_width += 10 * (2 * ($count - 1)); // add box spaces $this->m_legend_width += $count * 9; // Add margins inside box $this->m_legend_width += 7 * 2; $this->m_legend_height = 10 + $this->m_legendFontHeight * $count; //print $this->m_legend_height; } $margin = $this->m_margin; $marginy = $margin; if ($this->m_title) { $marginy += $this->m_fontHeight * 1.5; } if (isset($this->m_legend_height)) { $marginbottom = $margin + $this->m_legend_height; } else { $marginbottom = $margin * 2; } if ($this->m_labelsDirection == HORIZONTAL) { $marginbottom += $this->m_labelsFontWidth; } else { $marginbottom += $this->m_labelsMaxLength * $this->m_labelsFontWidth; } if (@$this->m_axisXTitle) { $marginbottom += $this->m_axisXFontHeight * 1.5; } $height = $this->m_height - $marginy - $marginbottom; $maxvalues = floor($height / $this->m_labelsFontHeight / 1.5); // max displayable values $marginx = $margin; $marginx += strlen(number_format($this->m_maxValue, $this->m_numberOfDecimals, ',', '.')) * $this->m_labelsFontWidth; if (@$this->m_axisYTitle) { $marginx += $this->m_axisYFontHeight * 1.5; } $width = $this->m_width - $marginx - $margin; $w = $width / ($this->m_maxCount + 0.2); $dx = $w * 0.8; $sx = $w - $dx; $width = $w * $this->m_maxCount + $sx; $h = $height / $maxvalues; $dy = $height / ($max - $min); $vdy = ($max - $min) / $maxvalues; //plot border & background imagefilledrectangle($this->m_image, $marginx, $marginy, $marginx + $width, $marginy + $height, $this->m_fillColor); // plot title if ($this->m_title) { imagestring($this->m_image, $this->m_font, ($this->m_width - strlen($this->m_title) * $this->m_fontWidth) / 2, $margin, $this->m_title, $this->m_textColor); } // plot values (Y) _set_style($this->m_image, $this->m_axisYStyle, $this->m_axisYColor, $this->m_fillColor); for ($i = 0; $i <= $maxvalues; $i++) { $yvalue = number_format($min + $vdy * $i, $this->m_numberOfDecimals, $this->m_decimalSeparator, $this->m_thousandsSeparator); imageline($this->m_image, $marginx - 3, $marginy + $height - $i * $h, $marginx, $marginy + $height - $i * $h, IMG_COLOR_STYLED); imagestring($this->m_image, $this->m_labelsFont, $marginx - strlen($yvalue) * $this->m_labelsFontWidth - 4, $marginy + $height - $i * $h - $this->m_labelsFontHeight / 2, $yvalue, $this->m_labelsTextColor); } // plot grid if ($this->m_showHGrid) { for ($i = 0; $i <= $maxvalues; $i++) { _set_style($this->m_image, $this->m_gridHStyle, $this->m_gridHColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy + $height - $i * $h, $marginx + $width, $marginy + $height - $i * $h, IMG_COLOR_STYLED); } } if ($this->m_showVGrid) { for ($i = 0; $i < count($this->m_labels); $i++) { $len = strlen($this->m_labels[$i]); if ($len > 0) { _set_style($this->m_image, $this->m_gridVStyle, $this->m_gridVColor, $this->m_fillColor); imageline($this->m_image, $marginx + $i * $w + $dx / 2 + $sx, $height + $marginy, $i * $w + $marginx + $dx / 2 + $sx, $marginy, IMG_COLOR_STYLED); } } } _set_style($this->m_image, $this->m_style, $this->m_strokeColor, $this->m_fillColor); imagerectangle($this->m_image, $marginx, $marginy, $marginx + $width, $marginy + $height, IMG_COLOR_STYLED); // plot graph foreach ($this->m_series as $series) { $cnt = count($series->m_values); // LINE PLOT if ($series->m_type == 'line') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $startx = $marginx + $dx / 2 + $sx; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); for ($i = 1; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imageline($this->m_image, $startx, $starty, $x, $y, IMG_COLOR_STYLED); $startx = $x; $starty = $y; } // AREA PLOT } else { if ($series->m_type == 'area') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $vpoints = ''; $startx = $marginx + $dx / 2 + $sx; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); $vpoints[] = $startx; $vpoints[] = $marginy + $height; for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); $vpoints[] = $x; $vpoints[] = $y; $startx = $x; $starty = $y; } $vpoints[] = $x; $vpoints[] = $marginy + $height; imagefilledpolygon($this->m_image, $vpoints, $cnt + 2, $series->m_fillColor); imagepolygon($this->m_image, $vpoints, $cnt + 2, IMG_COLOR_STYLED); // BAR PLOT } else { if ($series->m_type == 'bar') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $vpoints = ''; for ($i = 0; $i < $cnt; $i++) { imagefilledrectangle($this->m_image, $sx + $marginx + $i * $w, $marginy + $height - $dy * ($series->m_values[$i] - $min), $sx + $marginx + $i * $w + $dx, $marginy + $height, $series->m_fillColor); imagerectangle($this->m_image, $sx + $marginx + $i * $w, $marginy + $height - $dy * ($series->m_values[$i] - $min), $sx + $marginx + $i * $w + $dx, $marginy + $height, IMG_COLOR_STYLED); } // IMPULS PLOT } else { if ($series->m_type == 'impuls') { _set_style($this->m_image, $series->m_style, $series->m_fillColor, $this->m_fillColor); for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imageline($this->m_image, $x, $y, $x, $marginy + $height, IMG_COLOR_STYLED); } // STEP PLOT } else { if ($series->m_type == 'step') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); $cnt = $cnt; $vpoints = ''; $startx = $marginx + $sx / 2; $starty = $marginy + $height - $dy * ($series->m_values[0] - $min); $vpoints[] = $startx; $vpoints[] = $marginy + $height; $vpoints[] = $startx; $vpoints[] = $starty; for ($i = 1; $i < $cnt; $i++) { $x = $marginx + $i * $w + $sx / 2; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); $vpoints[] = $x; $vpoints[] = $starty; $vpoints[] = $x; $vpoints[] = $y; $startx = $x; $starty = $y; } $vpoints[] = $x + $w; $vpoints[] = $y; $vpoints[] = $x + $w; $vpoints[] = $marginy + $height; imagefilledpolygon($this->m_image, $vpoints, $cnt * 2 + 2, $series->m_fillColor); imagepolygon($this->m_image, $vpoints, $cnt * 2 + 2, IMG_COLOR_STYLED); // DOT PLOT } else { if ($series->m_type == 'dot') { _set_style($this->m_image, $series->m_style, $series->m_strokeColor, $this->m_fillColor); for ($i = 0; $i < $cnt; $i++) { $x = $marginx + $i * $w + $dx / 2 + $sx; $y = $marginy + $height - $dy * ($series->m_values[$i] - $min); imagerectangle($this->m_image, $x - 2, $y - 2, $x + 2, $y + 2, IMG_COLOR_STYLED); imagefilledrectangle($this->m_image, $x - 1, $y - 1, $x + 1, $y + 1, $series->m_fillColor); } } } } } } } } // plot X labels for ($i = 0; $i < count($this->m_labels); $i++) { $len = strlen($this->m_labels[$i]); if ($len > 0) { _set_style($this->m_image, $this->m_axisXStyle, $this->m_axisXColor, $this->m_fillColor); imageline($this->m_image, $dx / 2 + $sx + $marginx + $i * $w, $height + $marginy, $dx / 2 + $sx + $i * $w + $marginx, $height + $marginy + 3, IMG_COLOR_STYLED); if ($this->m_labelsDirection == HORIZONTAL) { imagestring($this->m_image, $this->m_labelsFont, $dx / 2 + $sx + $marginx + $i * $w - $len * $this->m_labelsFontWidth / 2, $marginy + 4 + $height, $this->m_labels[$i], $this->m_labelsTextColor); } else { imagestringup($this->m_image, $this->m_labelsFont, $dx / 2 + $sx + $marginx + $i * $w - $this->m_labelsFontHeight / 2, $marginy + $height + $len * $this->m_labelsFontWidth + 4, $this->m_labels[$i], $this->m_labelsTextColor); } } } // plot X axis if ($this->m_showXAxis) { _set_style($this->m_image, $this->m_axisXStyle, $this->m_axisXColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy + $height, $marginx + $width, $marginy + $height, IMG_COLOR_STYLED); if ($this->m_axisXTitle) { imagestring($this->m_image, $this->m_axisXFont, $marginx + ($width - strlen($this->m_axisXTitle) * $this->m_axisXFontWidth) / 2, $this->m_height - $margin - $this->m_axisXFontHeight, $this->m_axisXTitle, $this->m_axisXColor); } } // plot Y axis if ($this->m_showYAxis) { _set_style($this->m_image, $this->m_axisYStyle, $this->m_axisYColor, $this->m_fillColor); imageline($this->m_image, $marginx, $marginy, $marginx, $marginy + $height, IMG_COLOR_STYLED); if ($this->m_axisYTitle) { $titlewidth = strlen($this->m_axisYTitle) * $this->m_axisYFontWidth; imagestringup($this->m_image, $this->m_axisYFont, $margin, $marginy + $titlewidth + ($height - $titlewidth) / 2, $this->m_axisYTitle, $this->m_axisYColor); } } // Plot Legends if ($this->m_withLegend) { $x1 = $this->m_margin; $y1 = $this->m_height - 30; $x2 = $x1 + $this->m_legend_width; $y2 = $this->m_height - 10; imagefilledrectangle($this->m_image, $x1, $y1, $x2, $y2, $this->m_legendStroke); imagefilledrectangle($this->m_image, $x1 + 1, $y1 + 1, $x2 - 1, $y2 - 1, $this->m_legendFill); // start plotting boxes $boxsize = 10; $sx1 = $x1 + 5; $sy1 = $y1 + 5; $sx2 = $sx1 + $boxsize; $sy2 = $sy1 + $boxsize; // add 9px (box size) to box start y $curr_x = $sx2; $boxsize = $boxsize; $font_y = ($sy2 - $sy1 - $this->m_legendFontHeight) / 2 + $sy1; $i = 0; foreach ($this->m_numLegends as $lege) { // add margin left //$sx1 += 5; imagefilledrectangle($this->m_image, $sx1, $sy1, $sx2, $sy2, $this->m_legendStroke); imagefilledrectangle($this->m_image, $sx1 + 1, $sy1 + 1, $sx2 - 1, $sy2 - 1, $this->m_fillLegend[$i]); imagestring($this->m_image, $this->m_legendFont, $curr_x + $boxsize / 2, $font_y, $this->m_numLegends[$i], $this->m_legendStroke); // Two little bug fixes by OscarB $curr_x += $this->m_legendFontWidth * strlen($this->m_numLegends[$i]) + $boxsize * 3; $sx1 += $this->m_legendFontWidth * strlen($this->m_numLegends[$i]) + $boxsize * 3; $sx2 = $sx1 + $boxsize; $i = $i + 1; } } if (strlen($file) > 0) { imagepng($this->m_image, $file); } else { imagepng($this->m_image); } }