get("SELECT * FROM mutual_phenomena_data WHERE obs_id=$oid ORDER BY dt, ms"); $obs = $sql->get_record(0, "SELECT * FROM mutual_phenomena_obs WHERE id=$oid LIMIT 1"); $img = imagecreatetruecolor($width, $height); imagefill($img, 0, 0, bg_color); if (!$data || !$obs) { imagestring($img, 5, 10, 10, "No valid data for observation ID $oid", 0xFF0000); header('Content-type: image/png'); imagepng($img); die; }; $cnt = count($data); $jd_min = $data[0]['jd']; $jd_max = $data[$cnt-1]['jd']; $jd_len = $jd_max - $jd_min; $rm_min = $rm_max = $data[0]['rel_mag']; foreach($data as $p) { if ($rm_max < $p['rel_mag']) $rm_max = $p['rel_mag']; if ($rm_min > $p['rel_mag']) $rm_min = $p['rel_mag']; }; $rm_len = $rm_max - $rm_min; $img = imagecreatetruecolor($width, $height); imagefill($img, 0, 0, bg_color); function jd2x($jd) { global $width, $jd_min, $jd_len; return round(50 + ($width-60) * ($jd - $jd_min)/$jd_len); }; function mag2y($mag) { global $rm_min, $rm_len, $height; return round(30 + ($height-60) * ($mag - $rm_min)/$rm_len); }; // обсчет координатной сетки $ut = strtotime(substr($data[0]['dt'], 0, 16).' GMT'); $mins = $jd_len*24*60; if ($mins > 60) $step = 15; elseif ($mins > 30) $step = 10; elseif ($mins > 10) $step = 5; elseif ($mins > 5) $step = 2; else $step = 1; $step *= 60; while(true) { $jd = datetime_to_jd('UT'.$ut); if ($jd >= $jd_max) break; $dt = gmdate('H:i', $ut); $x = jd2x($jd); imageline($img, $x, 0, $x, $height, grid_color); imagestring($img, 4, $x-18, $height-16, $dt, label_color); $ut += $step; }; $step = 1; $i = 0; while(($rm_len*100 / $step) > 10) { $step *= ($i%2) ? 5 : 2; $i++; }; $step = $step / 100; $rm = floor($rm_min/$step)*$step; while($rm <= $rm_max) { $rm = round($rm, 4); $y = mag2y($rm); imageline($img, 0, $y, $width, $y, grid_color); imagestring($img, 4, 0, $y, $rm, label_color); $rm += $step; }; $dy = mag2y($obs['sigma_mag']) - mag2y(0); foreach($data as $p) { $x = jd2x($p['jd']); $y = mag2y($p['rel_mag']); //imageline($img, $x, $y-$dy/2, $x, $y+$dy/2, prec_color); imagefilledellipse($img, $x, $y, 3, 3, dot_color); }; $x = jd2x($obs['jd']); imageline($img, $x, 0, $x, $height, max_color); imagestring($img, 4, $x+10, 0, 'JD: '.$obs['jd'], max_color); /* $y = mag2y($rm_min); imageline($img, 0, $y, $width, $y, prec_color); imagestring($img, 4, 0, $y-15, "$rm_min mag", prec_color); $y = mag2y($rm_max); imageline($img, 0, $y, $width, $y, prec_color); imagestring($img, 4, 0, $y, "$rm_max mag", prec_color); */ header('Content-type: image/png'); imagepng($img);