Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This is application file
- (c) by Redfern89
- Created date: 2022-09-17 22:57:22
- */
- class WO_dia {
- function imagedashedrectangle(&$img, $x, $y, $width, $height, $color) {
- imagedashedline($img, $x, $y, $width, $y, $color);
- imagedashedline($img, $x, $y+$height-$y, $width, $y+$height-$y, $color);
- imagedashedline($img, $x, $y, $x, $y + $height - $y, $color);
- imagedashedline($img, $width, $y, $width, $y + $height - $y, $color);
- }
- public function begin_act() {
- $width = (isset($_GET['w'])) ? $_GET['w'] : 0;
- $width = ($width && $width > 0) ? $width : 2000;
- $height = (isset($_GET['h'])) ? $_GET['h'] : 0;
- $height = ($height && $height > 0) ? $height : 800;
- $paddingX1 = 10;
- $paddingY1 = 15;
- $paddingX2 = 10;
- $paddingY2 = 30;
- $grid_Cnt = 10;
- $gridFont = 22;
- $ellipseR = 7;
- $data = @$_GET['data'];
- $data = is_array($data) ? $data : [];
- $data = !empty($data) ? $data : [];
- $legend = @$_GET['legend'];
- $legend = !empty($legend) ? explode(',', $legend) : [];
- $title = @$_GET['title'];
- $titleFS = 42;
- $titleMB = 5;
- $font = dirname(__FILE__) . '/arialmt.ttf';
- $img = imagecreatetruecolor($width, $height);
- $dataFull = array();
- $dataCounts = array();
- $dataCountMAX = 0;
- $dataCountMIN = 0;
- $legendFS = 19;
- $legendRectS = 32;
- $legendFieldMT = 10;
- $legendFieldMS = 10;
- $legendFieldMB = 10;
- $colors = [0xFF0000, 0x0f60f6, 0x009631];
- imagefill($img, 0, 0, 0xFCFCFC);
- if (!empty($title)) {
- $titleBbox = imagettfbbox($titleFS, 0, $font, $title);
- $x = (($width / 2) - (($titleBbox[2] - $titleBbox[0]) / 2));
- $y = $paddingY1 + (($titleBbox[3] - $titleBbox[5]) / 2) + $titleBbox[3];
- imagettftext($img, $titleFS, 0, (int)$x, (int)$y, 0x000000, $font, $title);
- $paddingY1 = ($titleBbox[3] - $titleBbox[5]) + $paddingY1 + $titleMB;
- }
- if (!empty($data)) {
- for ($i = 0; $i < count($data); $i++) {
- $dataCurrent = $data[$i];
- $dataCurrent = explode(',', $dataCurrent);
- $dataCounts[] = count($dataCurrent);
- if (!empty($dataCurrent)) {
- for ($j = 0; $j < count($dataCurrent); $j++) {
- $dataNum = (float)$dataCurrent[$j];
- $dataFull[] = $dataNum;
- }
- }
- }
- $dataCountMAX = max($dataCounts);
- $dataCountMIN = min($dataCounts);
- $max = max($dataFull);
- $min = min($dataFull);
- $average = ($min + $max) / 2;
- $max_bbox = imagettfbbox($gridFont, 0, $font, $max);
- $min_bbox = imagettfbbox($gridFont, 0, $font, $min);
- $ave_bbox = imagettfbbox($gridFont, 0, $font, $average);
- $bboxes = array();
- $bbox_max_width = max($max_bbox[2], $min_bbox[2], $ave_bbox[2]);
- $paddingX1 = $bbox_max_width + $paddingX1;
- imagettftext($img, $gridFont, 0, (int)(($paddingX1 - $max_bbox[2]) -2), (int)(($paddingY1) - ($max_bbox[7] / 2)), 0x00, $font, $max);
- imagettftext($img, $gridFont, 0, (int)(($paddingX1 - $min_bbox[2]) -2), (int)(($height - $paddingY2) - ($min_bbox[7] / 2)), 0x00, $font, $min);
- imagettftext($img, $gridFont, 0, (int)(($paddingX1 - $ave_bbox[2]) -2), (int)((($height / 2) - (($paddingY2 - $paddingY1) / 2) - ($ave_bbox[7] / 2))), 0x00, $font, $average);
- }
- for ($i = 0; $i < $grid_Cnt; $i++) {
- $linesW = (($height - ($paddingY1 + $paddingY2)) / $grid_Cnt);
- if ($i % 2) $bg = 0xdfdfdf; else $bg = 0xf0f0f0;
- $x1 = $paddingX1;
- $x2 = $width - $paddingX2;
- $y1 = (int)(($i * $linesW)) + ($paddingY1);
- $y2 = (int)($y1 + $linesW);
- imagefilledrectangle($img, $x1, $y1, $x2, $y2, $bg);
- $this -> imagedashedrectangle($img, $x1, $y1, $x2, $y2 , 0x474747);
- }
- if (!empty($data)) {
- for ($i = 0; $i < count($data); $i++) {
- $dataCurrent = explode(',', $data[$i]);
- if (!empty($dataCurrent)) {
- $dataLinesArray = array();
- $percC = count($dataCurrent) * (100 / $dataCountMAX);
- $dWidthMAX = $width - ($paddingX1 + $paddingX2);
- $dWidth = (int)($percC * ($dWidthMAX / 100));
- $dHeight = $height - ($paddingY1 + $paddingY2);
- $count = count($dataCurrent);
- $dataImg = imagecreatetruecolor($dWidth, $dHeight);
- $col = imagecolorallocatealpha($dataImg, 255, 255, 255, 127);
- imagefill($dataImg, 0, 0, $col);
- imageantialias($dataImg, true);
- for ($j = 0; $j < $count; $j++) {
- if ($count > 0 && $dataCurrent[$j] != '') {
- if ($max - $min > 0) {
- $x = (int)(($dWidth / ($count -1)) * $j);
- $y = (int)($dHeight) - ((int)$dataCurrent[$j] - (int)$min) * ($dHeight) / ((int)$max - (int)$min);
- $dataLinesArray[] = array($x, $y);
- }
- }
- }
- for ($j = 0; $j < count($dataLinesArray); $j++) {
- $xy = $dataLinesArray[$j];
- if ($j != 0) {
- $xy_ = $dataLinesArray[$j -1];
- } else {
- $xy_ = $xy;
- }
- imageline($dataImg, (int)$xy_[0], (int)$xy_[1], (int)$xy[0], (int)$xy[1], $colors[$i]);
- imageline($dataImg, (int)$xy_[0]+1, (int)$xy_[1]+1, (int)$xy[0]+1, (int)$xy[1]+1, $colors[$i]);
- imagefilledellipse($dataImg, (int)$xy[0], (int)$xy[1], $ellipseR, $ellipseR, $colors[$i]);
- //imagedashedline($dataImg, (int)$xy[0], $dHeight, (int)$xy[0], (int)$xy[1], 0x474747);
- }
- $dataLinesArray = array();
- imagecopyresampled($img, $dataImg, $paddingX1, $paddingY1, 0, 0, $dWidth, $dHeight, $dWidth, $dHeight);
- imagedestroy($dataImg);
- }
- }
- }
- imageantialias($img, true);
- if (!empty($legend)) {
- if (true) {
- for ($i = 0; $i < count($legend); $i++) {
- $x1 = ($paddingX1) + $legendFieldMS;
- $x2 = $x1 + $legendRectS;
- $mb = ($i * $legendFieldMB);
- $y1 = ($legendRectS * $i) + ($paddingY1 + $legendFieldMT);
- $y2 = ($y1 + $legendRectS);
- imagefilledrectangle($img, $x1, $y1 + $mb, $x2, $y2 + $mb, $colors[$i]);
- imagerectangle($img, $x1, $y1+$mb, $x2, $y2 + $mb, 0x00);
- $legendBbox = imagettfbbox($legendFS, 0, $font, $legend[$i]);
- $x = $paddingX1 + ($legendRectS) + $legendFieldMS + 10;
- $y = ($legendRectS * $i) + ($paddingY1 + $legendFieldMT) + ($legendRectS) - 5;
- imagettftext($img, $legendFS, 0, $x, $y + $mb, 0x00, $font, $legend[$i]);
- }
- }
- }
- imageline($img, $paddingX1, $height - $paddingY2, $width - $paddingX2, $height - $paddingY2, 0x00);
- imageline($img, $paddingX1, $height - $paddingY2-1, $width - $paddingX2, $height - $paddingY2-1, 0x00);
- imageline($img, $paddingX1, $height - $paddingY2, $paddingX1, $paddingY1, 0x00);
- imageline($img, $paddingX1+1, $height - $paddingY2, $paddingX1+1, $paddingY1, 0x00);
- header('Content-Type: image/png');
- imagepng($img);
- imagedestroy($img);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment