$inc = 50; } } $x = bound(-$zx * $zz, -$drawradius, $drawradius - 25); $y = bound($zy * $zz, -$drawradius, $drawradius - 10); for ($v = -$mapradius; $v <= $mapradius; $v += $inc) { $imagestring($image, 3, $cx + $x + 2, $cy - ($v - $zy) * $zz + 1, $v, $mgrey); $imagestring($image, 3, $cx + ($v - $zx) * $zz + 2, $cy + $y + 1, $v, $mgrey); } } function draw_grid($image, $mapradius, $drawradius) { draw_grid_lines($image, $mapradius, $drawradius); draw_grid_labels($image, $mapradius, $drawradius); } draw_grid($im, 500, 256); date_default_timezone_set("America/Los_Angeles"); $stamp1 = $words["last update"]; $stamp2 = substr($server_info['updated'], 0, 16); /* * Draw the rectangles */ $imagerectangle($im, $cx - 256, $cy - 256, $cx + 255, $cy + 255, $black); $caption_bounds = imagettfbbox(15, 0, "arialuni", $caption); if ($layout == "spread") { $imagefilledrectangle($im, 0, 0, 124, 511, $white); $imagefilledrectangle($im, 643, 0, 767, 511, $white); $imagerectangle($im, 0, 0, 124, 511, $black); $imagerectangle($im, 643, 0, 767, 511, $black); // $imagestring($im, 3, 704-strlen($caption)*3.45, 10, $caption, $black); // $imagestring($im, 3, 64-strlen($caption)*3.45, 10, $caption, $black);
function draw_data($data) { global $im, $cl, $iw, $ih, $xlm, $xrm, $ytm, $ybm; sort($data); $x_ticks = count($data); $y_ticks = 10; $y_scale = 1; $prescale = 1; $unit = 'K'; $offset = 0; $gr_h = $ih - $ytm - $ybm; $x_step = ($iw - $xlm - $xrm) / ($x_ticks ?: 1); $y_step = ($ih - $ytm - $ybm) / $y_ticks; $bar_w = $x_step / 2; // // determine scale // $low = 99999999999; $high = 0; for ($i = 0; $i < $x_ticks; $i++) { if ($data[$i]['rx'] < $low) { $low = $data[$i]['rx']; } if ($data[$i]['tx'] < $low) { $low = $data[$i]['tx']; } if ($data[$i]['rx'] > $high) { $high = $data[$i]['rx']; } if ($data[$i]['tx'] > $high) { $high = $data[$i]['tx']; } } while ($high > $prescale * $y_scale * $y_ticks) { $y_scale = $y_scale * 2; if ($y_scale >= 1024) { $prescale = $prescale * 1024; $y_scale = $y_scale / 1024; if ($unit == 'K') { $unit = 'M'; } else { if ($unit == 'M') { $unit = 'G'; } else { if ($unit == 'G') { $unit = 'T'; } } } } } draw_grid($x_ticks, $y_ticks); // // graph scale factor (per pixel) // imagesetthickness($im, 1); $sf = $prescale * $y_scale * $y_ticks / $gr_h; if (count($data) == 0) { $text = T('no data available'); $bbox = imagettfbbox(10, 0, GRAPH_FONT, $text); $textwidth = $bbox[2] - $bbox[0]; imagettftext($im, 10, 0, ($iw - $textwidth) / 2, $ytm + 80, $cl['text'], GRAPH_FONT, $text); } else { // // draw bars // for ($i = 0; $i < $x_ticks; $i++) { $x = $xlm + $i * $x_step; $y = $ytm + ($ih - $ytm - $ybm) - ($data[$i]['rx'] - $offset) / $sf; $depth = $x_step / 8; $space = 0; $x1 = $x; $y1 = $y; $x2 = $x + $bar_w - $space; $y2 = $ih - $ybm; imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['rx']); imagerectangle($im, $x1, $y1, $x2, $y2, $cl['rx_border']); imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['rx']); imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['rx_border']); imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx']); imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx_border']); imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx']); imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx_border']); $y1 = $ytm + ($ih - $ytm - $ybm) - ($data[$i]['tx'] - $offset) / $sf; $x1 = $x1 + $bar_w; $x2 = $x2 + $bar_w; imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['tx']); imagerectangle($im, $x1, $y1, $x2, $y2, $cl['tx_border']); imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx']); imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx_border']); imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx']); imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx_border']); imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx']); imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx_border']); } // // axis labels // for ($i = 0; $i <= $y_ticks; $i++) { $label = $i * $y_scale . $unit; $bbox = imagettfbbox(8, 0, GRAPH_FONT, $label); $textwidth = $bbox[2] - $bbox[0]; imagettftext($im, 8, 0, $xlm - $textwidth - 16, $ih - $ybm - $i * $y_step + 8 + $depth, $cl['text'], GRAPH_FONT, $label); } for ($i = 0; $i < $x_ticks; $i++) { $label = $data[$i]['img_label']; $bbox = imagettfbbox(9, 0, GRAPH_FONT, $label); $textwidth = $bbox[2] - $bbox[0]; imagettftext($im, 9, 0, $xlm + $i * $x_step + $x_step / 2 - $textwidth / 2 - $depth - 4, $ih - $ybm + 20 + $depth, $cl['text'], GRAPH_FONT, $label); } } draw_border(); // // legend // imagefilledrectangle($im, $xlm, $ih - $ybm + 39, $xlm + 8, $ih - $ybm + 47, $cl['rx']); imagerectangle($im, $xlm, $ih - $ybm + 39, $xlm + 8, $ih - $ybm + 47, $cl['text']); imagettftext($im, 8, 0, $xlm + 14, $ih - $ybm + 48, $cl['text'], GRAPH_FONT, T('bytes in')); imagefilledrectangle($im, $xlm + 120, $ih - $ybm + 39, $xlm + 128, $ih - $ybm + 47, $cl['tx']); imagerectangle($im, $xlm + 120, $ih - $ybm + 39, $xlm + 128, $ih - $ybm + 47, $cl['text']); imagettftext($im, 8, 0, $xlm + 134, $ih - $ybm + 48, $cl['text'], GRAPH_FONT, T('bytes out')); }
$blue = ImageColorAllocate($im, 0, 0, 255); $yellow = ImageColorAllocate($im, 255, 255, 0); $magenta = ImageColorAllocate($im, 255, 0, 255); $cyan = ImageColorAllocate($im, 0, 255, 255); $l_grey = ImageColorAllocate($im, 200, 200, 200); $color = array(-1 => imagecolorallocate($im, 100, 100, 100), 0 => ImageColorAllocate($im, 115, 255, 100), 1 => ImageColorAllocate($im, 255, 0, 0), 2 => ImageColorAllocate($im, 0, 0, 255), 3 => ImageColorAllocate($im, 255, 255, 0), 4 => ImageColorAllocate($im, 255, 0, 255), 5 => ImageColorAllocate($im, 0, 255, 255), 6 => ImageColorAllocate($im, 0, 150, 0), 7 => ImageColorAllocate($im, 120, 0, 0), 8 => ImageColorAllocate($im, 0, 0, 120), 9 => ImageColorAllocate($im, 120, 120, 0), 10 => ImageColorAllocate($im, 120, 0, 120), 11 => ImageColorAllocate($im, 0, 120, 120)); draw_axises($W, $H); //рисуем оси координат //вычисляем масштаб преобразования данных в координаты рабочей области $scaleX = 1; $scaleY = 1; //задаем шаг для координатной сетки в пикселах $xStep = 30; $yStep = 30; //рисуем координатную сетку draw_grid($xStep, $yStep, round($xStep / $scaleX, 1), round($yStep / $scaleY, 1), true); // ======================================================================================== // заносим данные из сессии в массив $pointData = $_SESSION['data1']; $coresData = $_SESSION['cores1']; define("CORE_WEIGHT", 10); define("POINT_WEIGHT", 3); // рисуем все точки for ($i = 0; $i < count($pointData); $i++) { $point = $pointData[$i]; draw_data($point['x'], $point['y'], POINT_WEIGHT, $color[$point['class']]); } // выделяем ядра for ($i = 0; $i < count($coresData); $i++) { $point = $pointData[$coresData[$i]]; draw_data($point['x'], $point['y'], CORE_WEIGHT, $color[$point['class']], true);
function draw_data($data) { global $cl, $iw, $ih, $xlm, $xrm, $ytm, $ybm; sort($data); $x_ticks = count($data); $y_ticks = 10; $y_scale = 1; $prescale = 1; $unit = 'K'; $offset = 0; $gr_h = $ih - $ytm - $ybm; $x_step = ($iw - $xlm - $xrm) / $x_ticks; $y_step = ($ih - $ytm - $ybm) / $y_ticks; $bar_w = $x_step / 2; // // determine scale // $low = 99999999999; $high = 0; for ($i = 0; $i < $x_ticks; $i++) { if ($data[$i]['rx'] < $low) { $low = $data[$i]['rx']; } if ($data[$i]['tx'] < $low) { $low = $data[$i]['tx']; } if ($data[$i]['rx'] > $high) { $high = $data[$i]['rx']; } if ($data[$i]['tx'] > $high) { $high = $data[$i]['tx']; } } while ($high > $prescale * $y_scale * $y_ticks) { $y_scale = $y_scale * 2; if ($y_scale >= 1024) { $prescale = $prescale * 1024; $y_scale = $y_scale / 1024; if ($unit == 'K') { $unit = 'M'; } else { if ($unit == 'M') { $unit = 'G'; } else { if ($unit == 'G') { $unit = 'T'; } } } } } draw_grid($x_ticks, $y_ticks); // // graph scale factor (per pixel) // $sf = $prescale * $y_scale * $y_ticks / $gr_h; if ($data[0] == 'nodata') { $text = 'no data available'; svg_text($iw / 2, $ytm + 80, $text, array('stroke' => $cl['text']['rgb'], 'fill' => $cl['text']['rgb'], 'stroke-width' => 0, 'font-family' => SVG_FONT, 'font-size' => '16pt', 'text-anchor' => 'middle')); } else { // // draw bars // for ($i = 0; $i < $x_ticks; $i++) { $x = $xlm + $i * $x_step; $y = $ytm + ($ih - $ytm - $ybm) - ($data[$i]['rx'] - $offset) / $sf; $depth = $x_ticks < 20 ? 8 : 6; $space = 0; $x1 = (int) $x; $y1 = (int) $y; $w = (int) ($bar_w - $space); $h = (int) ($ih - $ybm - $y); $x2 = (int) ($x + $bar_w - $space); $y2 = (int) ($ih - $ybm); svg_group(array('stroke' => $cl['rx_border']['rgb'], 'stroke-opacity' => $cl['rx_border']['opacity'], 'stroke-width' => 1, 'stroke-linejoin' => 'round', 'fill' => $cl['rx']['rgb'], 'fill-opacity' => $cl['rx']['opacity'])); svg_rect($x1, $y1, $w, $h); svg_rect($x1 - $depth, $y1 + $depth, $w, $h); svg_poly(array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth)); svg_poly(array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth)); svg_group_end(); $y1 = (int) ($ytm + ($ih - $ytm - $ybm) - ($data[$i]['tx'] - $offset) / $sf); $x1 = (int) ($x1 + $bar_w); $x2 = (int) ($x2 + $bar_w); $w = (int) ($bar_w - $space); $h = (int) ($ih - $ybm - $y1 - 1); svg_group(array('stroke' => $cl['tx_border']['rgb'], 'stroke-opacity' => $cl['tx_border']['opacity'], 'stroke-width' => 1, 'stroke-linejoin' => 'round', 'fill' => $cl['tx']['rgb'], 'fill-opacity' => $cl['tx']['opacity'])); svg_rect($x1, $y1, $w, $h); svg_rect($x1 - $depth, $y1 + $depth, $w, $h); svg_poly(array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth)); svg_poly(array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth)); svg_group_end(); } // // axis labels // svg_group(array('fill' => $cl['text']['rgb'], 'fill-opacity' => $cl['text']['opacity'], 'stroke-width' => '0', 'font-family' => SVG_FONT, 'font-size' => '10pt', 'text-anchor' => 'end')); for ($i = 0; $i <= $y_ticks; $i++) { $label = $i * $y_scale . $unit; $tx = $xlm - 16; $ty = (int) ($ih - $ybm - $i * $y_step + 8 + $depth); svg_text($tx, $ty, $label); } svg_group_end(); svg_group(array('fill' => $cl['text']['rgb'], 'fill-opacity' => $cl['text']['opacity'], 'stroke-width' => '0', 'font-family' => SVG_FONT, 'font-size' => '10pt', 'text-anchor' => 'middle')); for ($i = 0; $i < $x_ticks; $i++) { $label = $data[$i]['img_label']; svg_text($xlm + $i * $x_step + $x_step / 2 - $depth - 4, $ih - $ybm + 20 + $depth, $label); } svg_group_end(); } draw_border(); // // legend // svg_rect($xlm, $ih - $ybm + 39, 8, 8, array('stroke' => $cl['text']['rgb'], 'stroke-width' => 1, 'fill' => $cl['rx']['rgb'])); svg_text($xlm + 14, $ih - $ybm + 48, T('bytes in'), array('fill' => $cl['text']['rgb'], 'stroke-width' => 0, 'font-family' => SVG_FONT, 'font-size' => '8pt')); svg_rect($xlm + 120, $ih - $ybm + 39, 8, 8, array('stroke' => $cl['text']['rgb'], 'stroke-width' => 1, 'fill' => $cl['tx']['rgb'])); svg_text($xlm + 134, $ih - $ybm + 48, T('bytes out'), array('fill' => $cl['text']['rgb'], 'stroke-width' => 0, 'font-family' => SVG_FONT, 'font-size' => '8pt')); }
$data_height = 1; } $y0 = 13 * (count($graph->stat_list) + 1) / 2 + 7; $width = $full_width - 50; $height = $full_height - ($y0 + 20); $x0 = 10; //echo $width . " " . $height . "\n"; //echo $data_width . " " . $data_height. "\n"; $im = imagecreate($full_width, $full_height); $background = imagecolorallocate($im, 0xf8, 0xf8, 0xf0); imagefilledrectangle($im, 0, 0, $full_width, $full_height, $background); //$black = imagecolorallocate($im, 0, 0, 0); $grid_color = imagecolorallocate($im, 0xb0, 0xb0, 0xb0); $grid_low_color = imagecolorallocate($im, 0xe0, 0xe0, 0xe0); $label_color = imagecolorallocate($im, 0x60, 0x60, 0x60); draw_grid($im, $min_x, $min_y, $max_x, $max_y, $x0, $y0, $width, $height, $grid_low_color, $grid_color); imagerectangle($im, $x0, $y0, $x0 + $width, $y0 + $height, $grid_color); // x, y labels $s = date("H:i", $min_x / 1000); imagestring($im, 2, $x0, $y0 + $height + 2, $s, $label_color); $s = date("H:i", $max_x / 1000); imagestring($im, 2, $x0 + $width - 25, $y0 + $height + 2, $s, $label_color); $s = y_label($min_y); imagestring($im, 2, $x0 + $width + 2, $y0 + $height - 10, $s, $label_color); $s = y_label($max_y); imagestring($im, 2, $x0 + $width + 2, $y0, $s, $label_color); $colors[] = array(0xff, 0x0, 0x0); // red $colors[] = array(0x40, 0x40, 0xff); // blue $colors[] = array(0xff, 0xb0, 0x0);
$x[1] = $x[0] - 0.01 * ($maxXVal - $minXVal); $y[1] = $y[0] - 0.01 * ($maxYVal - $minYVal); $x[2] = $x[1]; $y[2] = $y[1] + 0.02 * ($maxYVal - $minYVal); $x[3] = $x[2] + 0.02 * ($maxXVal - $minXVal); $y[3] = $y[2]; $x[4] = $x[3]; $y[4] = $y[3] - 0.02 * ($maxYVal - $minYVal); $x[5] = $x[4] - 0.02 * ($maxXVal - $minXVal); $y[5] = $y[4]; } for ($i = 0; $i < count($x); $i++) { $x[$i] -= $minXVal; $y[$i] -= $minYVal; } draw_data($x, $y, count($x), $red); //рисуем первый график for ($i = 0; $i < count($x1); $i++) { $x1[$i] -= $minXVal; $y1[$i] -= $minYVal; } draw_data($x1, $y1, count($x1), $blue); //рисуем второй график imagefill($im, $x0 + $x1[500] * $scaleX + 1, $maxY - 1, $l_grey); //рисуем координатную сетку draw_grid($xStep, $yStep, round($xStep / $scaleX, 3), round($yStep / $scaleY, 5)); ImagePNG($im); //выводим рисунок imagedestroy($im); //освобождаем занимаемую рисунком память unset($_SESSION[graph_x], $_SESSION[graph_y], $_SESSION[graph_x1], $_SESSION[graph_y1]);
function graph_draw_impl($stat, $canvas, $c_width, $c_height, $names, $value_set, $start, $end, $step, $start_times) { global $g_colors; global $g_label_width; $l_margin = 50; $r_margin = 20; $width = $c_width - $l_margin - $r_margin; $col = floor($width / $g_label_width); if ($col == 0) { $col = 1; } $label_height = 10 * floor((count($value_set) + $col - 1) / $col); $b_margin = 30 + $label_height; $t_margin = 10; $height = $c_height - $b_margin - $t_margin; foreach ($value_set as $name => $values) { $bounds = calculate_bounds($bounds, $values); } list($x1, $y1, $x2, $y2) = $bounds; $x1 = $start * 1000; $x0 = $x1; $x2 = $end * 1000; $dx = ($x2 - $x1) / $width; $dy = ($y2 - $y1) / $height; if ($dx == 0) { $dx = 1; } if ($dy == 0) { $dy = 1; } echo "<script type='application/x-javascript'>\n"; echo "c = start_bounds('{$canvas}', {$c_width}, {$c_height}, {$l_margin}, {$t_margin});\n"; draw_grid($width, $height, $x1, $y1, $x2, $y2, 0, 0, $dx, $dy, "#c0c0c0", "#c0c0c0"); foreach ($start_times as $time) { echo "c.save();"; echo "c.strokeStyle = '#60c000';\n"; echo "c.lineWidth = 2;\n"; echo "c.beginPath();\n"; echo "c.moveTo(" . ($time - $x0) / $dx . "," . 0 . ");\n"; echo "c.lineTo(" . ($time - $x0) / $dx . "," . $height . ");\n"; echo "c.stroke();\n"; echo "c.restore();"; } $i = 0; foreach ($value_set as $name => $values) { echo "c.save();"; echo "c.strokeStyle = '" . $g_colors[$i] . "';\n"; echo "c.lineWidth = 1;\n"; echo "c.beginPath();\n"; echo "c.moveTo(" . ($values[0]->time - $x0) / $dx . "," . (($dy - $values[0]->value) / $dy + $height) . ");\n"; foreach ($values as $v) { printf("rl(c,%.2f,%.2f);\n", ($v->time - $x0) / $dx, ($dy - $v->value) / $dy + $height); } $l_margin = 40; echo "c.translate(" . ($g_label_width * floor($i % $col) - $l_margin) . ", " . ($height + 25 + 10 * floor($i / $col)) . ");"; echo "c.beginPath();"; //echo "c.strokeStyle = '" . $colors[$i] . "';"; echo "c.lineWidth = 2;"; echo "c.moveTo(0, 10);"; echo "c.lineTo(15, 10);"; echo "c.stroke();"; echo "c.beginPath();"; echo "c.font = '10px Times';\n"; echo "c.fillStyle = '#000000';\n"; $name_seg = preg_split('/[|]/', $name); $server = array_shift($name_seg); array_shift($name_seg); array_shift($name_seg); $name = join('|', $name_seg); $text = sprintf("%s - %s", $server, $name); $text = substr($text, 0, 40); echo "c.fillText('" . $text . "', 20, 13);"; echo "c.restore();"; $i++; } echo "c.beginPath();"; echo "c.strokeStyle ='#000000';\n"; echo "c.font = '10px Monotype';\n"; echo "c.fillStyle ='#000000';\n"; echo "c.fillText('" . print_value($y1) . "', -45, " . $height . ");\n"; echo "c.fillText('" . print_value($y2) . "', -45, " . 10 . ");\n"; echo "</script>\n"; }
$im = @ImageCreate($W, $H); $white = ImageColorAllocate($im, 255, 255, 255); $black = ImageColorAllocate($im, 0, 0, 0); $red = ImageColorAllocate($im, 255, 0, 0); $green = ImageColorAllocate($im, 0, 255, 0); $blue = ImageColorAllocate($im, 0, 0, 255); $yellow = ImageColorAllocate($im, 255, 255, 0); $magenta = ImageColorAllocate($im, 255, 0, 255); $cyan = ImageColorAllocate($im, 0, 255, 255); $l_grey = ImageColorAllocate($im, 200, 200, 200); draw_axises($W, $H); //рисуем оси координат //заносим данные из сессии в массив $tree = $_SESSION['mas']; if (count($tree) == 0) { draw_grid(20, 20, 1, 1, true); ImagePNG($im); //выводим рисунок imagedestroy($im); //освобождаем занимаемую рисунком память exit; } //получаем максимальные значения элементов для каждого массива $maxXVal = $_SESSION['max']; $maxYVal = $tree['y']; $minXVal = 0; $minYVal = 0; //вычисляем масштаб преобразования данных в координаты рабочей области $scaleX = ($maxX - $x0) / ($maxXVal - $minXVal); $scaleY = ($maxY - $y0) / ($maxYVal - $minYVal); //задаем шаг для координатной сетки в пикселах