işaretli_grid_noktası = $ noktası ; $ bu -> işaretli_grid_renk = $ renk ; } function y_point ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ y ) { if ( $ this -> logaritmik_p ) { eğer ( $ ymax - $ ymin > 2 ) $ c = 1 ; eğer ( $ y == 0 ) $ yoff + $ yükseklik + (alog( $ ymin , $ c ) / (alog( $ ymax , $ c ) - alog( $ ymin , $ c ))) * $ yükseklik ; başka $ yoff + $ yükseklik - ((alog( $ y , $ c ) * 1.0 - alog( $ ymin , $ c )) / (alog( $ ymax , $ c ) - alog( $ ymin , $ c )) * $ yükseklik ); } başka dönüş $ yoff + $ yükseklik - (( $ y * 1.0 - $ ymin ) / ( $ ymax - $ ymin ) * $ yükseklik ); } set_grid_color işlevi ( $ color = false , $ grid_under = true ) { eğer ( $ renk ) $ this -> grid_color = $ color ; eğer ( $ grid_under ) $ this -> grid_position = 0 ; başka $ this -> grid_position = " son "; } işlev set_output_size ( $ genişlik , $ yükseklik ) { $ bu -> output_x_size = $ genişlik ; $ this -> output_y_size = $ yükseklik ; } işlev set_expired ( $ süresi doldu ) { $ this -> süresi doldu = $ süresi doldu ; } set_margins işlevi ( $ sol = 30 , $ sağ = 10 , $ üst = 20 , $ alt = 23 ) { $ this -> left_margin = $ left ; $ bu -> right_margin = $ right ; $ bu -> top_margin = $ top ; $ bu -> alt_margin = $ alt ; } işlev set_tick_distance ( $ mesafe ) { $ this -> tick_distance = $ mesafe ; } işlev set_labels ( $ x = false , $ y = false ) { $ bu -> x_label = $ x ; $ bu -> y_label = $ y ; } işlev set_extrema ( $ y_min = dizi (), $ y_max = dizi (), $ x_min = dizi (), $ x_max = dizi ()) { if (! is_array( $ y_min )) $ bu -> y_min = $ y_min ; if (! is_array( $ y_max )) $ bu -> y_max = $ y_max ; if (! is_array( $ x_min )) $ bu -> x_min = $ x_min ; if (! is_array( $ x_max )) $ bu -> x_max = $ x_max ; } işlev output_json () { $ dosya = $ bu -> önbellek . " .data "; eğer (dosya_varsa( $ dosya )) { $ fp = fopen( $ dosya , " r "); eğer ( $ fp ) { header(" İçerik türü: metin/düz "); echo " jsonCallback({ \" geri arama \" : $ this -> jsonpart , "; fpassthru( $ fp ); } çıkış; } } fonksiyon tablosu ( $ x , $ y , $ cache = false , $ jsonpart = false ) { küresel $ chart_debug ; hata_raporlama( 1 ); if ( $ jsonpart && $ önbellek ) { $ this -> set_cache_file_name ( $ önbellek ); $ bu -> jsonpart = $ jsonpart ; eğer (! $ chart_debug ) $ this -> output_json (); } // Bu görüntü zaten önbelleğe alınmışsa, o zaman kusarız // çıkar ve çık. eğer ( $ önbellek ) $ bu -> get_cache ( $ önbellek ); // Değilse, bu nesneyi başlatırız ve yürütmenin devam etmesine izin veririz. $ bu -> x_size = $ x ; $ bu -> y_size = $ y ; } işlev set_cache_file_name ( $ dosya ) { global $ chart_cache_directory ; $ dosya = $ chart_cache_directory . " / " . $ dosya ; // Muhtemelen buralarda bir güvenlik sorunu var. Sadece // tüm ".."'leri "__"'ye ve "//"leri "/_"ye dönüştürmek // yine de muhtemelen yardımcı olur. while (ereg(" [.][.] ", $ dosya )) $ dosya = ereg_replace(" [.][.] ", " __ ", $ dosya ); while (ereg(" // ", $ dosya )) $ dosya = ereg_replace(" // ", " /_ ", $ dosya ); $ bu -> önbellek = $ dosya ; } get_cache işlevi ( $ dosya ) { global $ chart_debug , $ chart_use_png ; $ this -> set_cache_file_name ( $ dosya ); $ dosya = $ bu -> önbellek ; eğer (! $ chart_debug ) { iken ( doğru ) { eğer (dosya_varsa( $ dosya )) { // Grafik zaten önbellekte, bu yüzden sadece sunuyoruz // dışarı. if ( $ file = fopen( $ file , " rb ")) { $ this -> başlıklar (); fpassthru( $ dosya ); çıkış; } } başka { // Buradaki fikir, kaydedilecek dosya üzerinde bir kilit elde etmektir. // yazmaya başlamadan önce yazılır. bu şekilde biz // artık hiçbir grafiğin oluşturulmamasını sağlayabiliriz // bir kereden fazla, eğer grafik çok önemli olabilir // CPU yoğun. $ this -> make_directory (dirname( $ file )); $ this -> lockfile = " $ file .lock "; $ lockfd = fopen( $ this -> lockfile , " a "); $ deneme = 0 ; while (! sürü( $ lockfd , 2 + 4 ) && $ try ++ < 20 && ! dosya_var( $ dosya )) { uyku( 1 ); } // Dosya şimdi mevcutsa, onu sunar ve çıkarız. if (file_exists( $ file ) && ( $ file = fopen( $ file , " rb "))) { fclose( $ kilitfd ); if ( $ this -> jsonpart ) { $ this -> output_json (); çıkış; } $ this -> başlıklar (); fpassthru( $ dosya ); çıkış; } if ( $ çalışır >= 20 ) { // 20 saniyeden fazla denedik, bu yüzden // dosyayı kilitle ve tekrar dene. fclose( $ kilitfd ); if (file_exists( $ this -> lockfile )) bağlantıyı kaldır( $ this -> lockfile ); } başka { // Kilidi aldık, bu yüzden döngüyü kırıyoruz ve // geri dönün ve grafiği kendimiz oluşturun. $ bu -> lockfd = $ lockfd ; mola ; } } } } yanlış dönüş ; } işlev put_cache ( $ resim ) { global $ chart_use_png ; $ dosya = $ bu -> önbellek ; eğer (dosya_varsa( $ dosya )) bağlantıyı kaldır( $ dosya ); $ this -> make_directory (dirname( $ file )); // Bir tmp dosyasına yazıyoruz ve ardından tmp dosyasını şu şekilde yeniden adlandırıyoruz: // gerçek dosya bize çoğu mantıklı dosya sisteminde biraz atomiklik verir. // Yani, gerçek dosya hiçbir zaman yarı yazılmış durumda olmayacaktır. eğer ( $ chart_use_png ) imagepng ( $ resim , " $ dosya.tmp "); başka imagegif ( $ resim , " $ dosya.tmp "); eğer (file_exists(" $ dosya .tmp ")) rename(" $ dosya .tmp ", " $ dosya "); imagedestroy( $ resim ); // Kilit dosyasını kaldırın. if ( $ this -> lockfd != - 1 ) { fclose( $ this -> lockfd ); bağlantıyı kaldır( $ this -> lockfile ); } if ( $ this -> jsonpart ) { $ this -> output_json (); çıkış; } if ( $ file = fopen( $ file , " rb ")) { $ this -> başlıklar (); fpassthru( $ dosya ); çıkış; } doğru dönüş ; } işlev make_directory ( $ dosya ) { while (! (dosya_var( $ dosya ))) { $ dizin [] = $ dosya ; $ dosya = dizin adı( $ dosya ); } for ( $ i = sizeof( $ dirs )- 1 ; $ i >= 0 ; $ i --) { if (strlen(basename( $ dirs [ $ i ])) > 256 ) { echo " Dosya adı çok uzun "; çıkış; } if (! file_exists( $ dizin [ $ i ])) @mkdir( $ dizin [ $ i ], 0777 ); } } işlev set_border ( $ renk = " siyah ", $ genişlik = 1 ) { $ this -> border_color = $ color ; $ bu -> border_width = $ genişlik ; } işlev set_background_color ( $ renk , $ kenar_rengi = yanlış ) { $ this -> background_color = $ color ; eğer ( $ marj_rengi ) $ bu -> marj_renk = $ marj_renk ; } işlev set_x_ticks ( $ tikler , $ format = " tarih ") { $ this -> x_ticks = $ ticks ; $ this -> x_ticks_format = $ format ; } işlev set_frame ( $ çerçeve = doğru ) { $ bu -> çerçeve = $ çerçeve ; } işlev set_font ( $ yazı tipi , $ tür = 0 , $ boyut = yanlış ) { $ this -> font_name = $ font ; $ bu -> font_type = $ type ; eğer ( $ boyutu ) $ bu -> font_size = $ boyut ; } işlev set_title ( $ başlık , $ renk = " siyah ", $ burada = " merkez ") { $ this -> title_text [] = $ başlık ; $ this -> title_where [] = $ burada ; $ this -> title_color [] = $ color ; } add_legend işlevi ( $ string , $ color = " siyah ") { $ this -> efsaneler [] = dizi ( $ string , $ color ); } işlev set_axes ( $ hangi = " xy ", $ renk = " siyah ") { $ this -> eksenler = $ olan ; $ this -> axes_color = $ color ; } işlev ve arsa ( $ c1 , $ c2 = false , $ color = false , $ style = false , $ to_color = false , $ param = false , $ metinler = yanlış ) { if ( $ c2 && $ this -> x_ticks_format == " date_2d ") { /* Tarih listesini, 19700101'den bu yana geçen gün listesine dönüştür monoton taban 10 sayıları elde etme sırası.*/ $ c2b = dizi (); foreach ( $ c2 olarak $ tarih ) { $ c2b [] = $ this -> datadatetotime ( $ date )/( 24 * 60 * 60 ); } $ c2 = $ c2b ; } $ arsa = yeni arsa ( $ c1 , $ c2 ); eğer ( $ renk ) $ arsa -> set_color ( $ renk ); eğer ( $ to_color ) $ arsa -> set_gradient_color ( $ to_color , $ param ); eğer ( $ tarzı ) $ arsa -> set_style ( $ stil ); eğer ( $ metinler ) $ arsa -> set_texts ( $ texts ); eğer ( $ parametresi ) $ arsa -> set_param ( $ param ); $ this -> grafikler [] = & $ arsa ; $ grafiğini döndür ; } fonksiyon alanı ( $ grafiği ) { $ this -> grafikler [] = & $ arsa ; } işlev vuruşu ( $ geri çağırma = yanlış ) { global $ chart_use_png , $ type1_font_encoding ; $ xs = $ bu -> x_size ; $ ys = $ bu -> y_size ; // Bu grafik için yazı tipini yükleyin. if ( $ this -> font_type == " type1 ") { $ bu -> font = imagepsloadfont( $ this -> font_name ); imagepsencodefont( $ this -> font , $ type1_font_encoding ); } elseif ( $ this -> font_type == " ttf ") { $ bu -> font = imagettfloadfont( $ this -> font_name ); } başka { $ bu -> font = $ bu -> font_name ; } eğer ( $ xs == 0 || $ ys == 0 ) { printf(" Geçersiz X veya Y boyutları: (%s, %s) ", $ xs , $ ys ); çıkış; } $ im = imagecreate( $ xs , $ ys ); eğer (! $ im ) çıkış; $ bu -> resim = $ im ; if ( $ this -> background_from_color ) { $ cs = rgb_allocate_colors( $ im , $ this -> background_from_color , $ this -> background_to_color , 10 , 100 ); eğer ( $ cs ) { foreach ( $ cs as $ c ) $ renkler [] = $ c ; } için ( $ ben = 0 ; $ ben < $ ys ; $ ben ++) { $ renk = $ renkler [ $ i / $ ys * sizeof( $ renkler )]; imageline( $ im , 0 , $ i , $ xs , $ i , $ renk ); } } başka { $ bgcolor = $ bu -> allocate_color ( $ this -> background_color ); imagefilledrectangle( $ im , 0 , 0 , $ xs , $ ys , $ bgcolor ); } list ( $ xmin , $ xmax ) = $ bu -> get_extrema ( 2 ); if (is_array( $ this -> y_min ) || is_array( $ this -> y_max )) { list ( $ ymin , $ ymax ) = $ bu -> get_extrema ( 1 ); // Neredeyse 0'a dokunan bir logaritmik grafik yapıyorsak, o zaman // grafiği 0'ın altına uzatırsak gerçekten çirkin görünür. // bunu yap o zaman. if ( $ this -> logarithmic_p && $ ymin < 1 ) $ lütuf = 0 ; başka $ zarafet = ( $ ymax - $ ymin )* 0.01 ; $ ymin -= $ lütuf ; $ ymax += $ ödemesiz ; } if (! is_array( $ this -> y_min )) $ ymin = $ bu -> y_min ; if (! is_array( $ this -> y_max )) $ ymax = $ bu -> y_max ; if (! is_array( $ this -> x_min )) $ xmin = $ bu -> x_min ; if (! is_array( $ this -> x_max )) $ xmax = $ bu -> x_max ; if ( $ ymax == $ ymin ) { $ ymax *= 1.01 ; $ ymin *= 0.99 ; } eğer ( $ xmaks == $ xmin ) $ xmaks ++; eğer ( $ ymaks == $ ymin ) $ ymaks ++; $ xoff = $ bu -> left_margin ; $ yoff = $ bu -> top_margin ; $ genişlik = $ xs - $ bu -> left_margin - $ bu -> right_margin ; $ yükseklik = $ ys - $ bu -> top_margin - $ bu -> bottom_margin ; $ axes_color = $ bu -> allocate_color ( $ this -> axes_color ); if (! $ this -> cleanup_after_plotting ) { $ kenar boşluğu = $ bu -> tahsis_rengi ( $ bu -> kenar_rengi ); imagefilledrectangle( $ im , 0 , 0 , $ xs , $ this -> top_margin - 1 , $ marj ); imagefilledrectangle( $ im , $ xs - $ this -> right_margin + 1 , $ this -> top_margin - 1 , $ xs , $ ys , $ marj ); imagefilledrectangle( $ im , 0 , $ ys - $ this -> bottom_margin + 1 , $ xs , $ ys , $ marj ); imagefilledrectangle( $ im , 0 , 0 , $ this -> left_margin - 1 , $ ys , $ marj ); } // Tüm çizimleri gözden geçirin ve çizin. if ( $ geri arama != false ) { if ( $ this -> grid_position == 0 ) $ this -> draw_grid ( $ xmin , $ xmax , $ ymin , $ ymax ); $ geri arama ( $ im , $ xmin , $ xmax , $ ymin , $ ymax , $ xoff , $ yoff , $ genişlik , $ yükseklik ); } başka { for ( $ i = 0 ; $ i < sizeof( $ this -> grafikler ); $ i ++) { if ( $ this -> grid_position == $ i ) $ this -> draw_grid ( $ xmin , $ xmax , $ ymin , $ ymax ); $ arsa = & $ bu -> grafikler [ $ i ]; $ arsa -> vuruş ( $ im , $ xmin , $ xmax , $ ymin , $ ymax , $ xoff , $ yoff , $ genişlik , $ yükseklik ve $ bu ); } } if (! strcmp( $ this -> grid_position , " last ")) $ this -> draw_grid ( $ xmin , $ xmax , $ ymin , $ ymax ); // Çizim, tahsis edilenin dışında çizilmiş olabilir. // "çerçeveli" alan (eğer otomatik ölçeklendirme kullanımda değilse), yani // çevredeki alanı boşaltın. if ( $ this -> cleanup_after_plotting ) { $ kenar boşluğu = $ bu -> tahsis_rengi ( $ bu -> kenar_rengi ); imagefilledrectangle( $ im , 0 , 0 , $ xs , $ this -> top_margin - 1 , $ marj ); imagefilledrectangle( $ im , $ xs - $ this -> right_margin + 1 , $ this -> top_margin - 1 , $ xs , $ ys , $ marj ); imagefilledrectangle( $ im , 0 , $ ys - $ this -> bottom_margin + 1 , $ xs , $ ys , $ marj ); imagefilledrectangle( $ im , 0 , 0 , $ this -> left_margin - 1 , $ ys , $ marj ); } if (! $ this -> frame ) { if ( $ this -> border_color ) { imageline( $ im , $ this -> left_margin , $ this -> top_margin , $ this -> left_margin , $ ys - $ this -> bottom_margin + 3 , $ axes_color ); imageline( $ im , $ this -> left_margin - 3 , $ ys - $ this -> bottom_margin , $ xs - $ bu -> right_margin , $ ys - $ bu -> bottom_margin , $ eksen_rengi ); } } başka { imagerectangle( $ im , $ this -> left_margin , $ this -> top_margin , $ xs - $ bu -> right_margin , $ ys - $ bu -> bottom_margin , $ this -> allocate_color ( $ this -> border_color )); } // Metni eksenlere yerleştirin. if ( $ this -> do_draw_y_axis ) $ this -> draw_y_axis ( $ im , $ ymin , $ ymax , $ xs , $ ys , $ yükseklik , $ yoff , true , $ eksen_rengi ); if ( $ this -> do_draw_x_axis ) $ this -> draw_x_axis ( $ im , $ xmin , $ xmax , $ xs , $ ys , $ genişlik , $ xoff , true , $ eksen_rengi ); $ title_color = $ this -> allocate_color (" black "); // Varsa etiketleri çizin. if ( $ this -> y_label ) { if ( $ this -> font_type == " type1 ") { imagepstext ( $ im , $ this -> y_label , $ this -> font , $ this -> font_size , $ this -> allocate_color ( $ title_color ), $ this -> allocate_color (" beyaz "), 15 , ( int )( $ ys / 2 + $ this -> string_pixels ( $ this -> y_label )/ 2 ), 0 , 0 , 90 , 16 ); } başka { imagestringup( $ im , $ this -> font , 5 , $ ys / 2 + $ this -> string_pixels ( $ this -> y_label )/ 2 , $ this -> y_label , $ title_color ); } } if ( $ this -> x_label ) imagestring( $ im , $ this -> font , $ xs / 2 - $ this -> string_pixels ( $ this -> x_label )/ 2 , $ ys - 20 , $ this -> x_label , $ title_color ); // Sınırı çiz. if ( $ this -> border_color ) imagerectangle( $ im , 0 , 0 , $ xs - 1 , $ ys - 1 , $ this -> allocate_color ( $ this -> border_color )); // Başlığı çiz. $ tx = " noval "; for ( $ i = 0 ; $ i title_text ); $ i ++) { if ( $ this -> font_type == " type1 ") { if ( $ tx == " noval ") { if (!strcmp( $ this -> title_where [ $ i ], " center ")) { liste ( $ llx , $ lly , $ urx , $ ury ) = imagepsbbox( $ this -> title_text [ $ i ], $ bu -> yazı tipi , $ this -> font_size ); $ tx = $ xs / 2 - ( $ urx - $ llx )/ 2 ; if ( $ this -> title_auto_y ) $ ty = $ ury - $ lly + 2 ; başka $ ti = 15 ; } başka $ tx = 0 ; } imagepstext ( $ im , $ this -> title_text [ $ i ], $ this -> font , $ this -> font_size , $ this -> allocate_color ( $ this -> title_color [ $ i ]), $ this -> allocate_color (" beyaz "), ( int ) $ tx , ( int ) $ ty , 0 , 0 , 0 , 16 ); } elseif ( $ this -> font_type == " dahili ") { if (!strcmp( $ this -> title_where [ $ i ], " center ")) $ tx = $ xs / 2 - $ this -> string_pixels ( $ this -> title_text [ $ i ])/ 2 ; başka $ tx = 0 ; imagestring( $ im , $ this -> font , $ tx , 5 , $ this -> title_text [ $ i ], $ this -> allocate_color ( $ this -> title_color [ $ i ])); } } // Göstergeyi çizin. if (sizeof( $ this -> efsaneler ) != 0 ) { $ maksimumuzunluk = 0 ; foreach ( $ this -> $ legend olarak efsaneler ) { $ uzunluk = $ bu -> real_string_pixels ( $ gösterge [ 0 ]); if ( $ uzunluk > $ maksimum uzunluk ) $ maksimum uzunluk = $ uzunluk ; } if ( $ this -> legend_placement == " r ") { $ x = ( int )( $ bu -> x_size - $ bu -> right_margin - $ maksimum uzunluk - 20 ); $ y = ( int )( $ bu -> top_margin + 20 ); } başka { $ x = ( int )( $ this -> left_margin + 40 ); $ y = ( int )( $ bu -> top_margin + 20 ); } $ lmargin = $ bu -> legend_margin ; // Göstergenin arkasına bir kutu çizin. if ( $ this -> legend_background_color ) { imagefilledrectangle( $ im , $ x - $ lmargin , $ y - $ lmargin , $ x + $ lmargin + $ maksimumuzunluk , $ y + $ lmargin + (( $ this -> font_size + 2 )*sizeof( $ this -> efsaneler )), $ this -> allocate_color ( $ this -> legend_background_color )); } if ( $ this -> legend_border_color ) { imagerectangle( $ im , $ x - $ lmargin , $ y - $ lmargin , $ x + $ lmargin + $ maksimumuzunluk , $ y + $ lmargin + (( $ this -> font_size + 2 )*sizeof( $ this -> efsaneler )), $ this -> allocate_color ( $ this -> legend_border_color )); } foreach ( $ this -> $ legend olarak efsaneler ) { eğer ( $ this -> legend_text_alignment == " l ") $ this -> Draw_text ( $ yazı [ 0 ], $ yazı [ 1 ], $ x , $ y ); başka $ this -> Draw_text ( $ açıklama [ 0 ], $ açıklama [ 1 ], $ x + $ maksimum uzunluk - $ this -> real_string_pixels ( $ gösterge [ 0 ]), $ y ); $ y += $ bu -> font_size + 2 ; } } // İstenirse çıktı almadan önce görüntüyü yeniden ölçeklendirin. if ( $ this -> output_x_size ) { küresel $ gd2 ; $ genişlik = $ bu -> output_x_size ; $ oheight = $ bu -> output_x_size ; $ om = imagecreate( $ genişlik , $ yükseklik ); eğer (! $ om ) çıkış; eğer ( $ gd2 ) imagecopyresampled( $ om , $ im , 0 , 0 , 0 , 0 , $ genişlik , $ oheight , $ xs , $ ys ); başka imagecopyresize( $ om , $ im , 0 , 0 , 0 , 0 , $ genişlik , $ oheight , $ xs , $ ys ); $ im = $ om ; } // Kullanıcının son bir değişiklik yapmasına izin ver. if ( $ this -> final_callback ) { $ call = $ this -> final_callback ; $ call ( $ im , $ xmin , $ xmax , $ ymin , $ ymax , $ xoff , $ yoff , $ genişlik , $ yükseklik ve $ bu ); // Geri arama, görüntünün yerini almış olabilir. $ im = $ bu -> resim ; } if ( $ this -> output_data && $ this -> önbellek ) $ this -> output_data_file (); // Bu ifade genellikle geri dönmez. if ( $ this -> önbellek ) $ bu -> put_cache ( $ im ); $ this -> başlıklar (); eğer ( $ chart_use_png ) imagepng( $ im ); başka resimgif( $ im ); imagedestroy( $ im ); doğru dönüş ; } işlev output_data_file () { $ ilk = doğru ; $ dosya = $ bu -> önbellek . " .data "; eğer (dosya_varsa( $ dosya )) bağlantıyı kaldır( $ dosya ); $ this -> make_directory (dirname( $ file )); $ fp = fopen( $ dosya , " w "); eğer (! $ fp ) çıkış; fwrite( $ fp , "\" ymin \" : $ bu -> ymin , \" ymax \" : $ bu -> ymax , \" yükseklik \" : $ bu -> yükseklik , \" yoff \" : $ bu -> yoff , "); fwrite( $ fp , "\" değerler \" : [ "); $ önceki_x = - 1 ; if ( $ this -> output_data [ 1 ]) { foreach ( $ this -> output_data [ 1 ] as $ x => $ elem ) $ ek [] = $ elem [ 0 ]; } $ indeksi = 0 ; foreach ( $ this -> output_data [ 0 ] as $ x => $ elem ) { eğer ( $ x - $ önceki_x < 2 ) devam et ; $ önceki_x = $ x ; eğer (! $ ilk ) fwrite( $ fp , " , "); başka $ ilk = yanlış ; $ değeri = $ elem [ 0 ]; if (sprintf(" %.2f ", $ değeri ) == $ değeri ) $ değer = sprintf(" %.2f ", $ değer ); eğer ( ek $ ) $ ekstra = " , \"" . $ ek [ $ dizin ] . "\""; fwrite( $ fp , " [ " . $ x . " , \"" . $ değer . "\" , \"" . tarih(" dmY ", $ this -> datadatetotime ( $ elem [ 1 ])) . "\"" . $ ekstra . " ] "); $ dizini ++; } fwrite( $ fp , " ]}); "); fclose( $ fp ); } işlev başlıkları () { global $ chart_use_png ; if ( $ this -> süresi doldu ) { header(" Sona Erme: 26 Temmuz 1997 Pzt 05:00:00 GMT "); header(" Son Değiştirme Tarihi: " . gmdate(" D, d MYH:i:s ") . " GMT "); header(" Cache-Control: no-cache, must-revalidate "); header(" Pragma: önbellek yok "); } eğer ( $ chart_use_png ) header(" İçerik türü: resim/png "); başka header(" İçerik tipi: resim/gif "); } işlev datadatetotime ( $ datatime ) { if (ereg (" ([0-9]{4})([0-9]{2})([0-9]{2}) ", $ datatime , $ regs )) { dönüş mktime ( 1 , 0 , 0 , $ kayıtlar [ 2 ], $ kayıtlar [ 3 ], $ kayıtlar [ 1 ]); } 0 dönüşü ; } function shortnorvegiandate ( $ zaman ) { dönüş tarihi(" dmy ", $ zaman ); } function shortnorwegianmdate ( $ zaman ) { $ ay adları = dizi (" ocak ", " şubat ", " mars ", " nisan ", " mai ", " haziran ", " Temmuz ", " Ağustos ", " Eylül ", " Ekim ", " Kasım ", " aralık "); if (tarih(" d ", $ saat ) == 1 ) { # dönüş substr($ayadları[tarih("m", $zaman)-1], 0, 3) . " " . tarih("Y", $zaman); $ ay adlarını döndür [tarih(" m ", $ saat )- 1 ]; } başka { dönüş tarihi(" dmy ", $ zaman ); } } saniyeden saniyeye işlev ( $ s ) { dönüş substr( $ s , 0 , 2 )* 60 * 60 +substr( $ s , 2 , 2 )* 60 +substr( $ s , 4 , 2 ); } ay_uzunluk işlevi ( $ ay , $ yıl ) { $ uzunluk = $ bu -> ay [ $ ay - 1 ]; // Şubat ayına özel kurallar. eğer ( $ ay == 2 ) { if ( !( $ yıl % 4 ) && ( $ yıl % 100 || !( $ yıl % 400 ))) $ uzunluk = 29 ; } dönüş $ uzunluğu ; } grid_grid işlevi ( $ xmin , $ xmax , $ ymin , $ ymax ) { // Izgarayı ve eksenleri çizin. $ im = $ bu -> resim ; $ xs = $ bu -> x_size ; $ ys = $ bu -> y_size ; $ xoff = $ bu -> left_margin ; $ yoff = $ bu -> top_margin ; $ genişlik = $ xs - $ bu -> left_margin - $ bu -> right_margin ; $ yükseklik = $ ys - $ bu -> top_margin - $ bu -> bottom_margin ; $ axes_color = $ bu -> allocate_color ( $ this -> axes_color ); if ( $ this -> do_draw_grid ) $ this -> draw_y_axis ( $ im , $ ymin , $ ymax , $ xs , $ ys , $ yükseklik , $ yoff , false , $ eksen_rengi ); $ this -> draw_marked_grid ( $ im , $ ymin , $ ymax , $ xs , $ ys , $ yükseklik , $ yoff ); if ( $ this -> do_draw_grid ) $ this -> draw_x_axis ( $ im , $ xmin , $ xmax , $ xs , $ ys , $ genişlik , $ xoff , false , $ eksen_rengi ); } x_axis işlevi ( $ im , $ xmin , $ xmax , $ xs , $ ys , $ genişlik , $ xoff , $ do_text , $ axes_color ) { if ( $ this -> do_draw_x_axis == false && $ do_text ) dönüş ; $ grid_color = $ bu -> allocate_color ( $ this -> grid_color ); $ do_tick_texts = yanlış ; $ inceltme_faktörü = 70 ; $ numara_uygun değil = 0 ; $ kullanılan_ticks_counter = 0 ; if ( !(strcmp( $ this -> eksenler , " x ")) || !(strcmp( $ this -> eksenler , " xy "))) { if ( $ this -> x_ticks_format == " zaman " || $ this -> x_ticks_format == " saniye " ) { $ do_tick_texts = doğru ; $ inceltme_faktörü = 40 ; if ( $ this -> x_ticks_format == " time ") { $ start = $ this -> saniyeden saniyeye ( $ this -> x_ticks [ 0 ]); $ bitiş = $ bu -> saniyeden saniyeye ( $ bu -> x_ticks [sizeof( $ this -> x_ticks )- 1 ]); } başka { $ başla = $ bu -> x_ticks [ 0 ]; $ end = $ bu -> x_ticks [sizeof( $ this -> x_ticks )- 1 ]; } $ xmax = sizeof( $ this -> x_ticks )- 1 ; $ xmin = 0 ; $ süre = $ bitiş - $ başlangıç ​​; eğer ( $ süre == 0 ) dönüş ; $ ölçek = ( $ xmax - $ xmin )/ $ süre ; eğer ( $ süre < 10 * 60 ) { $ adım = 60 ; } elseif ( $ süre < 30 * 60 ) { $ adım = 60 * 5 ; } elseif ( $ süre < 2 * 60 * 60 ) { $ adım = 60 * 10 ; } elseif ( $ süre < 4 * 60 * 60 ) { $ adım = 60 * 30 ; } başka { $ adım = 3600 ; eğer ( $ süre < 10 * 60 * 60 ) $ this -> tick_whole_x = true ; } // Başlangıç/bitiş konumları "güzel"e yakınsa // sayılar, sonra yukarı/aşağı yuvarlarız. if ((! $ start % $ step ) || (( $ start % $ step ) / ( $ end - $ start )) > 0.01 ) $ kbaşlangıç ​​= $ başlangıç ; başka $ kstart = $ start -( $ start % $ step ); if ((! $ end % $ step ) || ( $ step - $ end % $ step ) / ( $ end - $ kstart ) > 0.01 ) $ kend = $ bitiş ; başka $ kend = $ end - $ end % $ adım + $ adım ; // Mümkünse bir saatte başlayıp başlayamayacağımıza bakın. if ( $ adım == 3600 && $ kstart % 3600 != 0 && $ kstart + 3600 < $ end ) $ kstart += 3600 - $ kstart % 3600 ; for ( $ saat = $ kstart ; $ saat <= $ kend ; $ saat += $ adım ) { $ tikler [] = (( $ saat - $ başlangıç ​​)* $ ölçek ); if ( $ adım == 3600 && $ saat % 3600 == 0 ) $ tick_texts [] = ( int )( $ saat / 3600 ); başka $ tick_texts [] = sprintf(" %02d:%02d ", ( int )( $ saat / 3600 ), ( $ saat % 3600 / 60 )); } } else if ( $ this -> x_ticks_format == " fiyat ") { $ do_tick_texts = doğru ; $ start = ( int )( $ this -> x_ticks [ 0 ] * 10000 ); $ end = ( int )( $ bu -> x_ticks [sizeof( $ this -> x_ticks )- 1 ] * 10000 ); $ xmax = sizeof( $ this -> x_ticks )- 1 ; $ xmin = 0 ; $ aralığı = $ bitiş - $ başlangıç ; eğer ( $ aralığı == 0 ) dönüş ; $ ölçek = ( $ xmax - $ xmin )/ $ aralık ; eğer ( $ aralığı < 10000 ) $ adım = 1000 ; elseif ( $ aralığı < 10 * 10000 ) $ adım = 5000 ; başka $ adım = 10000 ; // Başlangıç/bitiş konumları "güzel"e yakınsa // sayılar, sonra yukarı/aşağı yuvarlarız. if ((! $ start % $ step ) || (( $ start % $ step ) / ( $ end - $ start )) > 10000 ) $ kbaşlangıç ​​= $ başlangıç ; başka $ kstart = $ start -( $ start % $ step ); için ( $ fiyat = $ kbaşlangıç ​​; $ fiyat <= $ bitiş ; $ fiyat += $ adım ) { $ keneler [] = ( $ fiyat - $ başlangıç ​​)* $ ölçek ; $ tick_texts [] = sprintf(" %.2f ", $ fiyat / 10000 ); } } elseif ( $ this -> x_ticks_format == " tarih " || $ this -> x_ticks_format == " date_2d " || $ this -> x_ticks_format == " sdate " || $ this -> x_ticks_format == " seyrek_tarih ") { $ do_tick_texts = doğru ; $ inceltme_faktörü = 60 ; $ start = $ this -> datadatetotime ( $ this -> x_ticks [ 0 ])/( 24 * 60 * 60 ); $ end = $ this -> datadatetotime ( $ this -> x_ticks [sizeof( $ this -> x_ticks )- 1 ])/ ( 24 * 60 * 60 ); $ süre = $ bitiş - $ başlangıç ​​; $ gdate = getdate( $ başlangıç ​​*( 24 * 60 * 60 )); $ ay = $ gdate [" pzt "]; $ gün = $ gdate [" gün "]; $ gday = $ gdate [" wday "]; $ yıl = $ gdate [" yıl "]; $ muzunluk = $ bu -> ay_uzunluk ( $ ay , $ yıl ); $ ilk = doğru ; için ( $ i = $ başlangıç ​​; $ i < $ bitiş ; $ i ++) { eğer ( $ gün == 1 ) $ ilkler [] = $ ben ; if ( $ gün == 1 || $ gün == 15 ) { eğer ( önce $ ) { $ ilk = yanlış ; eğer ( $ gün == 15 ) $ numara_uygun değil = 1 ; } $ ortalar [] = $ ben ; } if ( $ wday == 1 ) $ pazartesi [] = $ i ; if ( $ ay == 1 && $ gün == 1 ) $ ilk_ocak [] = $ i ; if ( $ mday ++ > $ m uzunluk - 1 ) { if ( $ ay ++ > 12 - 1 ) { $ ay = 1 ; $ yıl ++; } $ muzunluk = $ bu -> ay_uzunluk ( $ ay , $ yıl ); $ gün = 1 ; } if ( $ wday ++ > 7 - 1 ) $ gün = 1 ; } $ wdformat = yanlış ; eğer ( $ süre > 0 ) { eğer ( $ this -> x_ticks_format == " seyrek_tarih ") $ ölçek = ( $ xmax - $ xmin + 1 )/sizeof( $ this -> x_ticks ); başka $ ölçek = ( $ xmax - $ xmin )/ $ süre ; } başka $ ölçek = 1 ; eğer ( $ süre < 24 ) { için ( $ i = $ başlangıç ​​; $ i < $ bitiş ; $ i ++) $ tarihler [] = $ ben ; } elseif ( $ süre < 62 ) { $ tarihler = $ pazartesiler ; $ wdformat = doğru ; } elseif ( $ süre < 31 * 6 ) { $ tarihler = $ ortalar ; } elseif ( $ süre < 365 * 2 ) { $ tarihler = $ ilkler ; } başka { $ tarihler = $ first_januarys ; } için ( $ i = 0 ; $ i x_ticks_format == " date_2d ") { /* Bir tarih dizisini ikinci bağımsız değişken olarak kullanırken doğru ölçeği elde et arg ile $this->plot() */ $ tikler [] = (( $ tarihler [ $ i ])* $ ölçek ); } else if ( $ this -> x_ticks_format == " seyrek_tarih ") { /* Buradaki fikir şu ki hoş tarihler seçmek istiyoruz, ama eşit olmayan bir şekilde dağıtılmasını da istiyoruz. Yani, veri kümesinde olmayan tarihleri ​​atlayın. */ iken (( $ tick_date = $ this -> datadatetotime ( $ this -> x_ticks [ $ used_ticks_counter ])/( 24 * 60 * 60 )) != 0 && $ tick_date <= $ tarihler [ $ i ]) { $ kullanılmış_ticks_counter ++; } $ tikler [] = ( $ kullanılmış_ticks_counter - 1 ) * $ ölçek ; } başka { $ tikler [] = (( $ tarihler [ $ i ]- $ başlangıç ​​)* $ ölçek ); } eğer (! $ wdformat ) $ tick_texts [] = $ this -> shortnorwegiandate ( $ tarihler [ $ i ]* 24 * 60 * 60 ); başka { if ( $ this -> x_ticks_format == " sdate ") $ tick_texts [] = tarih(" dm ", $ tarihler [ $ i ]* 24 * 60 * 60 ); başka $ tick_texts [] = " Anne " . $ this -> shortnorwegiandate ( $ tarihler [ $ i ]* 24 * 60 * 60 ); } } } başka { $ keneler = $ bu -> get_ticks ( $ xmin , $ xmax , $ xs ); } if (! $ this -> tick_whole_x ) { eğer ( $ do_tick_texts ) $ thinning_factor = $ this -> string_pixels ( $ tick_texts [ 0 ]) + 6 ; $ adım = ceil(sizeof( $ ticks )* 1.0 / ( $ genişlik / $ inceltme_faktörü )); } başka $ adım = 1 ; $ kene uzunluğu = sizeof( $ keneler ); için ( $ i = 0 ; $ i < $ kene uzunluğu ; $ i += 1 ) { $ x = $ işaretler [ $ i ]; $ xt = $ xoff +( $ x- $ xmin ) / ( $ xmax- $ xmin )* $ genişlik ; if ( $ do_text && $ xt >= $ xoff ) { if ((( $ i + $ numara_uygun değil ) % $ adım ) == 0 ) { eğer ( $ do_tick_texts ) { $ metin = $ tick_texts [ $ i ]; } elseif ( $ this -> x_ticks ) { if (!strcmp( $ this -> x_ticks_format , " tarih ")) { $ text = $ this -> shortnorwegiadate ( $ this -> datadatetotime ( $ this -> x_ticks [ $ x ])); } elseif (!strcmp( $ this -> x_ticks_format , " sdate ")) { $ metin = tarih(" dm ", ( $ this -> datadatetotime ( $ this -> x_ticks [ $ x ]))); } elseif (!strcmp( $ this -> x_ticks_format , " time ")) { $ metin = $ bu -> x_ticks [" $ x "]; $ metin = altstr( $ metin , 0 , 2 ) . " : " . substr( $ metin , 2 , 2 ); } elseif (!strcmp( $ this -> x_ticks_format , " ctime ")) { $ dtext = $ text = tarih(" m/d ", $ x ); if (isset( $ odtext ) && $ text != $ odtext ) $ metin .= " " . tarih(" G:i ", $ x ); başka $ metin = tarih(" G:i ", $ x ); $ odtext = $ dtext ; } elseif (!strcmp( $ this -> x_ticks_format , " cdate ")) { $ metin = tarih(" m/d ", $ x ); } elseif (!strcmp( $ this -> x_ticks_format , " text ")) { $ metin = $ bu -> x_ticks [" $ x "]; } } elseif ( $ this -> x_ticks_format == " yok ") { $ metin = ""; } başka { $ metin = $ x ; } if ( $ this -> font_type == " type1 ") { imagepstext( $ im , $ text , $ this -> font , $ this -> font_size , $ eksen_rengi , $ this -> allocate_color (" beyaz "), ( int )( $ xt -(strlen( $ text )* $ this -> font_size / 4 )+ 0 ), ( int )( $ ys - $ this -> bottom_margin + $ this -> font_size + 5 ), 0 , 0 , 0 , 16 ); } elseif ( $ this -> font_type == " dahili ") { imagestring( $ im , $ this -> font , $ xt -(strlen( $ text )* 6 / 2 ), $ ys - $ this -> bottom_margin + 5 , $ metin , $ axes_color ); } imageline( $ im , $ xt , $ ys - $ this -> bottom_margin , $ xt , $ ys - $ bu -> bottom_margin + 3 , $ axes_color ); } başka { imageline( $ im , $ xt , $ ys - $ this -> bottom_margin , $ xt , $ ys - $ bu -> bottom_margin + 1 , $ axes_color ); } } başka { if ( $ xt > $ this -> left_margin ) imageline( $ im , $ xt , $ this -> top_margin , $ xt , $ ys - $ bu -> bottom_margin - 1 , $ grid_color ); } } } } işlev hoşa giden_sayılar ( $ sayı , $ serisi = 0 , minimum $ = 0 ) { $ bir = 0.001 ; iki $ = 0.002 ; beş dolar = 0.005 ; iken ( doğru ) { if ( $ sayı < $ bir && ( $ serisi == 0 || $ serisi == 1 ) && $ bir >= $ minimum ) dönüş dizisi ( $ bir , 1 ); $ bir *= 10 ; if ( $ sayı < $ iki && ( $ serisi == 0 || $ serisi == 2 ) && $ iki >= $ minimum ) dönüş dizisi ( $ iki , 2 ); $ iki *= 10 ; if ( $ sayı < $ beş && ( $ serisi == 0 || $ serisi == 5 ) && $ beş >= $ minimum ) dönüş dizisi ( $ beş , 5 ); $ beş *= 10 ; } } function_draw_text ( $ string , $ color , $ x , $ y ) { if ( $ this -> font_type == " type1 ") { imagepstext( $ this -> image , $ string , $ this -> font , $ this -> font_size , $ this -> allocate_color ( $ color ), $ this -> allocate_color ( $ this -> background_color ), $ x , $ y + $ this -> font_size - 2 , 0 , 0 , 0 , 16 ); } elseif ( $ this -> font_type == " dahili ") { imagestring( $ this -> image , $ this -> font , $ x , $ y , $ string , $ this -> allocate_color ( $ color )); } } Draw_y_axis işlevi ( $ im , $ ymin , $ ymax , $ xs , $ ys , $ yükseklik , $ yoff , $ do_text , $ axes_color ) { if ( $ this -> do_draw_y_axis == false && $ do_text ) dönüş ; if (!(strcmp( $ this -> eksenler , " y ") || strcmp( $ this -> eksenler , " xy "))) dönüş ; $ grid_color = $ bu -> allocate_color ( $ this -> grid_color ); // Y eksenini hesapla. $ tikler = $ bu -> get_ticks ( $ ymin , $ ymax , $ yükseklik ); $ uzunluk = sizeof( $ tikler ); $ tam = doğru ; $ ideal = $ yükseklik / $ bu -> font_size + 1 ; if ( $ ideal >= $ uzunluk ) { $ faktörü = .1 ; $ valfactor = .1 ; } başka { liste ( $ faktörü , $ serisi ) = $ this -> hoş_sayılar (tavan( $ uzunluk / $ ideal )); /* Burada çok büyük bir çarpan alırsak onu azaltırız. */ eğer ( $ uzunluk / $ faktör < 2 ) liste ( $ faktörü , $ serisi ) = $ this -> hoş_sayılar (tavan( $ uzunluk / $ ideal ) / 2 ); list ( $ valfactor ) = $ this -> hoşa giden_sayılar (( $ ymax - $ ymin )/ 100 , $ series ); } $ aralık = abs( $ tikler [ 1 ] - $ tikler [ 0 ]); için ( $ i = 0 ; $ i < $ uzunluk * 2 ; $ i ++) { $ y = $ işaretler [ 0 ] + $ boşluk * $ i ; if (! mod( $ y , $ factor )) { $ ofset = mod( $ i , $ factor )/ 1000 ; mola ; } } $ ben = - 1 ; $ yazdır_gerçek = yanlış ; için ( $ ben = 0 ; $ ben < $ uzunluk ; $ ben += 1 ) { $ y = $ tikler [ $ i ]; $ yt = $ this -> y_point ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ y ); eğer ( $ do_text ) { eğer ( $ i >= $ ofset ) $ iy ++; if ((! (( int )( $ iy * 1000 )%( $ factor * 1000 )))) && ( $ iy > - 1 )) { if (tavan( $ boşluk * 100 ) == 10 || tavan( $ boşluk * 100 ) == 20 ) $ yst = sprintf(" %.1f ", $ y ); else if ( $ boşluk < 1 && ! mod( $ boşluk * 10 , 1 )) $ yst = sprintf(" %.1f ", $ y ); başka if (mutlak( $ boşluk ) < 0.01 ) $ yst = sprintf(" %.3f ", $ y ); elseif (mutlak( $ boşluk ) < 1 ) $ yst = sprintf(" %.2f ", $ y ); elseif (!( $ boşluk % 1000000000 )) $ yst = sprintf(" %dG ", $ y / 1000000000 ); elseif (!( $ boşluk % 1000000 )) $ yst = sprintf(" %dM ", $ y / 1000000 ); elseif (!( $ boşluk % 1000 )) $ yst = sprintf(" %dk ", $ y / 1000 ); elseif (! $ tam ) $ yst = sprintf(" %.1f ", $ y ); başka $ yst = $ y ; if (strlen( $ yst ) > 5 ) $ yst = ( int ) $ yst ; if ( $ this -> y_format == " yüzde ") $ yst .= " % "; eğer (( $ y * 10 )% 10 ) $ tam = yanlış ; if ( $ this -> font_type == " type1 ") { liste ( $ llx , $ lly , $ urx , $ ury ) = imagepsbbox(" $ yst ", $ bu -> font , $ bu -> font_size ); // Bu, herhangi bir pikseli ayıklamak için bir filtredir // metin genişliğindeki farklılıklar. $ ww = ( $ urx - $ llx ); if ( $ önceki_ww != $ ww && abs( $ önceki_ww - $ ww ) < 3 ) $ ww = $ önceki_ww ; başka $ önceki_ww = $ ww ; imagepstext ( $ im , " $ yst ", $ this -> font , $ this -> font_size , $ eksen_rengi , $ this -> allocate_color (" beyaz "), ( int )( $ this -> left_margin - 6 - $ ww ), ( int )( $ yt + 4 ), 0 , 0 , 0 , 16 ); } elseif ( $ this -> font_type == " dahili ") { imagestring( $ im , $ this -> font , $ this -> left_margin - 3 -strlen( $ yst )* 6 , $ yt - 7 , $ yst , $ eksen_rengi ); } imageline( $ im , $ this -> left_margin - 3 , $ yt , $ this -> left_margin , $ yt , $ axes_color ); } başka { imageline( $ im , $ this -> left_margin - 1 , $ yt , $ this -> left_margin , $ yt , $ axes_color ); } } başka { // Izgara çizgisini çizin. görüntü çizgisi ( $ im , $ this -> left_margin + 1 , $ yt , $ xs - $ this -> right_margin , $ yt , $ grid_color ); } } } Draw_marked_grid işlevi ( $ im , $ ymin , $ ymax , $ xs , $ ys , $ yükseklik , $ yoff ) { if ( $ this -> işaretli_grid_renkli ) { $ y = $ bu -> işaretli_grid_nokta ; $ yt = $ this -> y_point ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ y ); görüntü çizgisi ( $ im , $ this -> left_margin + 1 , $ yt , $ xs - $ this -> right_margin , $ yt , $ bu -> tahsis_rengi ( $ bu -> işaretli_grid_renk )); } } işlev real_string_pixels ( $ string ) { if ( $ this -> font_type == " type1 ") { liste ( $ llx , $ lly , $ urx , $ ury ) = imagepsbbox( $ string , $ this -> font , $ this -> font_size ); $ urx'i döndür - $ llx ; } başka dönüş strlen( $ dizge )* 6 ; } string_pixels işlevi ( $ string ) { eğer ( $ this -> font_type == " type1 ") dönüş strlen( $ string ) * ( $ this -> font_size - 5.5 ); başka dönüş strlen( $ dizge )* 6 ; } get_ticks işlevi ( $ min , $ maks , $ yükseklik , $ bütün = yanlış ) { $ faktörü = 1000 ; $ fark = abs( $ maks - $ min ); list ( $ çift ) = $ bu -> memnun edici_sayılar ( $ fark / $ yükseklik * 10 ); eğer ( $ tamamı ) $ çift = max( 1 , $ çift ); eğer ( $ dak < 0 ) $ başlangıç ​​= kat( $ min * $ faktör ) + $ çift * $ faktör -(kat( $ min * $ faktör )%( $ çift * $ faktör )) - $ çift * $ çarpanı ; başka if ( $ min == 0 ) $ başlangıç ​​= 0 ; başka { // Bu, başka bir PHP kayan nokta hatasını gidermek içindir. $ m = sprintf(" %.10f ", $ min ); $ m = ( $ m * $ faktör ); $ e = ( $ çift * $ faktör ); $ başlangıç ​​= kat( $ m + $ e -((( $ m * $ faktör ) % ( $ e * $ faktör )) / $ faktör )); } for ( $ elem = $ başlangıç ​​, $ i = 0 ; $ elem < $ max * $ factor ; $ elem += kat( $ çift * $ faktör ), $ i ++) { $ tikler [ $ i ] = $ elem / $ çarpanı ; eğer ( $ ben > 1000 ) $ kenelerini döndür ; } $ kenelerini döndür ; } işlev set_scale ( $ type = " lineer ") { $ bu -> ölçek = $ tür ; } işlev tahsis_renk ( $ renk ) { return rgb_allocate( $ this -> image , $ color ); } get_extrema işlevi ( $ dim ) { for ( $ i = 0 ; $ i < sizeof( $ this -> grafikler ); $ i ++) { $ arsa = $ bu -> grafikler [ $ i ]; if (( $ arsa -> stil == " dolgu " || $ arsa -> stil == " dolgu gradyanı ") && $ karartma == 2 ) list ( $ mi , $ ma ) = $ arsa -> get_extrema ( 3 ); başka list ( $ mi , $ ma ) = $ arsa -> get_extrema ( $ dim ); eğer (! isset( $ max )) $ maks = $ ma ; eğer (! isset( $ min )) $ dak = $ mi ; eğer ( $ ma > $ max ) $ maks = $ ma ; eğer ( $ mi < $ min ) $ dak = $ mi ; if (( $ arsa -> stil == " dolgu " || $ arsa -> stil == " dolgu gradyanı ") && $ karartma == 1 ) { list ( $ mi , $ ma ) = $ arsa -> get_extrema ( 2 , true ); eğer ( $ ma > $ max ) $ maks = $ ma ; eğer ( $ mi < $ min ) $ dak = $ mi ; } } dönüş dizisi ( $ min , $ maks ); } } sınıf arsa { var $ koordinatları ; var $ color = " siyah ", $ to_color = false , $ param = 0 ; var $ style = " satırlar "; var $ boyut = 1 ; var $ metinler = yanlış ; var $ çizgi_genişliği = 1 ; var $ output_data = false ; fonksiyon grafiği ( $ c1 , $ c2 ) { $ this -> kodlar [] = $ c1 ; $ this -> kodlar [] = $ c2 ; eğer ( $ c2 == 0 ) { $ bu -> boyut = 1 ; } başka { $ this -> boyut = 2 ; } doğru dönüş ; } işlev set_color ( $ renk ) { $ bu -> renk = $ renk ; doğru dönüş ; } işlev set_metinleri ( $ metinler ) { $ this -> metinler = $ metinler ; doğru dönüş ; } işlev set_gradient_color ( $ to_color ) { $ this -> to_color = $ to_color ; } fonksiyon set_param ( $ param ) { $ bu -> param = $ param ; } işlev get_color () { $ this - > color ; } işlev set_style ( $ stil ) { $ bu -> stil = $ stil ; } işlev set_dimension ( $ dim ) { $ this -> boyut = $ dim ; } get_extrema işlevi ( $ dim , $ force_true = false ) { if ( $ dim > $ this -> boyut || (! $ force_true && $ dim == 2 && ( $ this -> style == " fill " || $ this -> style == " fillgradient "))) dönüş dizisi ( 0 , sizeof( $ this -> coords [ 0 ])- 1 ); $ dizi = $ bu -> koordinatlar [ $ dim - 1 ]; için ( $ j = 0 ; $ j < sizeof( $ dizi ); $ j ++) { if ((! is_string( $ dizi [ $ j ])) || (strcmp( $ dizi [ $ j ], " noplot "))) { eğer (! isset( $ max )) $ maks = $ dizi [ $ j ]; eğer (! isset( $ min )) $ dak = $ dizi [ $ j ]; eğer ( $ dizi [ $ j ] > $ maks ) $ maks = $ dizi [ $ j ]; eğer ( $ dizi [ $ j ] < $ min ) $ dak = $ dizi [ $ j ]; } } dönüş dizisi ( $ min , $ maks ); } fonksiyon vuruşu ( $ im , $ xmin , $ xmax , $ ymin , $ ymax , $ xoff , $ yoff , $ genişlik , $ yükseklik ve $ grafik ) { $ color = rgb_allocate( $ im , $ this -> color ); $ stil = $ bu -> stil ; $ param = $ bu -> param ; $ ycoords = $ this -> coords [ 0 ]; $ end = sizeof( $ ycoords ); $ output_data = dizi (); if (!strcmp( $ stil , " puan ")) $ stil = 1 ; elseif (!strcmp( $ stil , " satırlar ")) $ stili = 2 ; elseif (!strcmp( $ stil , " dürtü ")) $ stili = 3 ; elseif (!strcmp( $ stil , " daire ")) { $ stili = 4 ; eğer ( $ parametresi ) { if (is_array( $ param )) { $ daire_boyutu = $ parametre [ 0 ]; $ pozisyon_stil = $ parametre [ 1 ]; } başka { $ daire_boyutu = $ param ; } } başka $ daire_boyutu = 10 ; } elseif (!strcmp( $ stil , " çapraz ")) { $ stili = 5 ; eğer ( $ parametresi ) $ cross_size = $ param / 2 ; başka $ çapraz_boyut = 5 ; } elseif (!strcmp( $ stil , " doldur ")) { $ stili = 6 ; $ bu -> boyut = 1 ; } elseif (!strcmp( $ stil , " kare ")) $ stili = 7 ; elseif (!strcmp( $ stil , " dolu kare ")) $ stili = 15 ; elseif (!strcmp( $ stil , " üçgen ")) { if ( $ this -> to_color ) $ dcolor = $ this -> to_color ; başka $ dcolor = $ bu -> renk ; $ dcolor = rgb_allocate( $ im , $ dcolor ); $ stili = 9 ; } elseif (!strcmp( $ stil , " kutu ")) { if ( $ this -> to_color ) $ to_color = $ bu -> to_color ; başka $ to_color = $ bu -> renk ; $ tcolors = rgb_allocate_colors( $ im , $ this -> color , $ to_color , 3 ); $ stili = 10 ; } elseif (!strcmp( $ stil , " gradyan ") || !strcmp( $ stil , " dolgu gradyan ")) { // Gradyanı hesapla. if (!strcmp( $ stil , " gradyan ")) $ stili = 8 ; başka { $ stili = 12 ; $ bu -> boyut = 1 ; } $ gradyan_stil = $ bu -> param & 1 ; $ gradyan_updown = $ bu -> parametre & 2 ; $ gradyan_yön = $ bu -> param & 4 ; $ gradyan_horizontal = $ bu -> param & 8 ; eğer ( $ gradyan_horizontal ) $ h = $ genişlik + 2 ; başka $ h = $ yükseklik + 2 ; if (ereg(" , ", $ this -> color )) { $ gcolors = patlama(" , ", $ bu -> renk ); için ( $ i = 0 ; $ i < sizeof( $ gcolors ) - 1 ; $ i ++) $ gacolors [] = dizi ( $ gcolors [ $ i ], $ gcolors [ $ i + 1 ]); } başka { $ gacolors [] = dizi ( $ bu -> renk , $ bu -> to_color ); } $ h = ( int )( $ h / sizeof( $ gacolors )); $ renkler = dizi (); foreach ( $ gacolors as $ tfcolors ) { if ( $ gradyan_direction == 0 ) { liste ( $' dan , $' a ) = $ tfcolors ; } başka { liste ( $ to , $ from ) = $ tfcolors ; } $ cs = rgb_allocate_colors( $ im , $ den , $ to , $ h , 200 /sizeof( $ gacolors )); eğer ( $ cs ) { foreach ( $ cs as $ c ) $ renkler [] = $ c ; } } } elseif (!strcmp( $ stil , " metin ")) { $ stili = 11 ; $ metinnum = 0 ; $ pozisyon_stil = $ param ; $ daire_boyutu = 10 ; } elseif (!strcmp( $ style , " origo-impulse ")) { $ stili = 12 ; } elseif (!strcmp( $ stil , " şamdan ")) $ stili = 13 ; elseif (!strcmp( $ stil , " aralık ")) $ stili = 14 ; elseif (!strcmp( $ stil , " yok ")) $ stili = 16 ; if ( $ end == 1 && $ position_style == " son ") { $ y = $ ykoords [ 0 ]; $ xt = $ xoff + $ genişlik ; $ yt = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ y ); eğer ( $ stili == 11 ) { imagepstext( $ im , $ bu -> metinler [ 0 ], $ grafiği -> yazı tipi , $ grafiği -> font_size , $ grafiği -> tahsis_rengi (" kırmızı "), $ grafiği -> allocate_color (" beyaz "), ( int )( $ xt - $ chart -> real_string_pixels ( $ this -> texts [ 0 ])), ( int ) $ yt , 0 , 0 , 0 , 16 ); } başka { imagearc( $ im , $ xt , $ yt , $ daire_boyutu , $ daire_boyutu , 0 , 360 , $ renk ); } dönüş ( $ renk ); } için ( $ i = 0 ; $ i < $ bitiş ; $ i ++) { $ y = $ ycoords [ $ i ]; if ((! is_array( $ y ) && ((! is_string( $ y )) || (strcmp( $ y , " noplot "))))) { if ( $ this -> boyut == 1 ) $ x = $ ben ; başka $ x = $ this -> koordinatlar [ 1 ][ $ i ]; $ xt = $ xoff +( $ x- $ xmin ) / ( $ xmax- $ xmin )* $ genişlik ; $ yt = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ y ); if ( $ this -> output_data ) $ output_data [ $ xt ] = dizi ( $ y , $ grafik -> x_ticks [ $ i ]); eğer (! isset( $ pxt )) $ pxt = $ xt ; eğer (! isset( $ pyt )) $ puan = $ yt ; eğer ( $ stili == 1 ) imageline( $ im , $ xt , $ yt , $ xt , $ yt , $ renk ); başka if ( $ stil == 2 ) { if ( $ this -> line_width > 1 ) { $ bu -> kalın_çizgi ( $ im , $ pxt , $ pyt , $ xt , $ yt , $ color , $ this -> line_width ); } başka { imageline( $ im , $ pxt , $ pyt , $ xt , $ yt , $ renk ); } } elseif ( $ stil == 3 ) { imageline( $ im , $ xt , $ yoff + $ yükseklik , $ xt , $ yt , $ renk ); } başka if ( $ stil == 12 ) { görüntü satırı( $ im , $ xt , $ grafiği -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , 0 ), $ xt , $ yt , $ renk ); } elseif ( $ stil == 4 ) { imagearc( $ im , $ xt , $ yt , $ daire_boyutu , $ daire_boyutu , 0 , 360 , $ renk ); } elseif ( $ stil == 5 ) { imageline( $ im , $ xt - $ cross_size , $ yt - $ cross_size , $ xt + $ cross_size , $ yt + $ cross_size , $ color ); imageline( $ im , $ xt + $ cross_size , $ yt - $ cross_size , $ xt - $ çapraz_boyut , $ yt + $ çapraz_boyut , $ renk ); } elseif ( $ stil == 6 ) { // Doldurmak eğer (! isset( $ poyt )) $ poyt = $ oyt ; $ oyt = $ grafik -> y_point ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ this -> koordinatlar [ 1 ][ $ i ]); için ( $ j = $ pxt ; $ j <= $ xt ; $ j ++) imageline( $ im , $ j , $ oyt , $ j , $ yt , $ renk ); $ poyt = $ oyt ; } elseif ( $ stil == 7 ) { imageline( $ im , $ pxt , $ pyt , $ pxt , $ yt , $ renk ); imageline( $ im , $ pxt , $ yt , $ xt , $ yt , $ renk ); } elseif ( $ stil == 15 ) { imagefilledrectangle( $ im , $ pxt , $ yt , $ xt , $ yoff + $ yükseklik , $ renk ); } elseif ( $ stil == 8 ) { // gradyan // Değerden grafiğin altına doğru çiziyoruz. // Çizilecek öğelerin birkaç piksel genişliğinde olabilir, // bu yüzden önce grafiğin tepesinin gradyanını hesaplıyoruz // iki nokta arasında. Yani "gradyan" ın tepesi // grafik "kare"ye değil "çizgiler" grafiğine benzeyecek // çizelge. eğer ( $ xt == $ pxt ) { $ b = 0 ; } başka { $ b = ( $ yt - $ pyt ) / ( $ xt - $ pxt ); } $ a = $ yt - $ b * $ xt ; için ( $ x = $ pxt ; $ x <= $ xt ; $ x ++) { $ birinci = $ a + $ b * $ x ; eğer ( $ gradyan_updown == 0 ) { için ( $ y = $ a + $ b * $ x ; $ y < $ yoff + $ yükseklik ; $ y ++) { if ( $ gradyan_stil && ! $ gradyan_horizontal ) $ coff = $ y - $ birinci ; elseif (! $ gradyan_stil && ! $ gradyan_horizontal ) $ coff = $ y - $ yoff ; başka if ( $ gradyan_stil && $ gradyan_horizontal ) $ coff = $ x - $ firstx ; elseif (! $ gradyan_stil && $ gradyan_horizontal ) $ coff = $ x - $ xoff ; imagesetpixel( $ im , $ x , $ y , $ renkler [ $ coff ]); } } başka { için ( $ y = $ a + $ b * $ x ; $ y > $ yoff ; $ y --) { if ( $ gradyan_stil && ! $ gradyan_horizontal ) $ coff = $ birinci - $ y ; elseif (! $ gradyan_stil && ! $ gradyan_horizontal ) $ coff = $ y - $ yoff ; başka if ( $ gradyan_stil && $ gradyan_horizontal ) $ coff = $ firstx - $ x ; elseif (! $ gradyan_stil && $ gradyan_horizontal ) $ coff = $ x - $ xoff ; imagesetpixel( $ im , $ x , $ y , $ renkler [ $ coff ]); } } } } başka if ( $ stil == 12 ) { // dolgu gradyanı eğer (! isset( $ poyt )) $ poyt = $ oyt ; $ oyt = $ grafik -> y_point ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ this -> koordinatlar [ 1 ][ $ i ]); için ( $ x = $ pxt ; $ x <= $ xt ; $ x ++) { if ( $ oyt < $ yt ) { $ miny = $ oyt ; $ maksimum = $ yt ; } başka { $ miny = $ yt ; $ maksimum = $ oy ; } $ firsty = $ oyt ; eğer ( $ gradyan_updown == 0 ) { için ( $ y = $ miny ; $ y < $ maks ; $ y ++) { eğer ( $ gradyan_stil == 1 ) { imagesetpixel( $ im , $ x , $ y , $ renkler [ $ y - $ ilk ]); } başka { imagesetpixel( $ im , $ x , $ y , $ renkler [ $ y - $ yoff ]); } } } başka { için ( $ y = $ maks ; $ y > $ miny ; $ y --) { eğer ( $ gradyan_stil == 1 ) { imagesetpixel( $ im , $ x , $ y , $ renkler [ $ ilk - $ y ]); } başka { imagesetpixel( $ im , $ x , $ y , $ renkler [ $ y - $ yoff ]); } } } } $ poyt = $ oyt ; } elseif ( $ stil == 9 ) { // üçgen imageline( $ im , $ xt - 3 , $ yt + 3 , $ xt + 3 , $ yt + 3 , $ dcolor ); imageline( $ im , $ xt - 3 , $ yt + 2 , $ xt + 3 , $ yt + 2 , $ renk ); imageline( $ im , $ xt - 2 , $ yt + 1 , $ xt + 2 , $ yt + 1 , $ renk ); imageline( $ im , $ xt - 2 , $ yt , $ xt + 2 , $ yt , $ renk ); imageline( $ im , $ xt - 1 , $ yt - 1 , $ xt + 1 , $ yt - 1 , $ renk ); imageline( $ im , $ xt - 1 , $ yt - 2 , $ xt + 1 , $ yt - 2 , $ renk ); imagesetpixel( $ im , $ xt , $ yt - 3 , $ renk ); imagesetpixel( $ im , $ xt , $ yt - 4 , $ renk ); imageline( $ im , $ xt + 4 , $ yt + 3 , $ xt + 1 , $ yt - 4 , $ dcolor ); } başka if ( $ stil == 10 ) { // Kutu imageline( $ im , $ xt - 2 , $ yt - 2 , $ xt + 2 , $ yt - 2 , $ tcolors [ 0 ]); imageline( $ im , $ xt - 2 , $ yt - 1 , $ xt - 2 , $ yt + 2 , $ tcolors [ 0 ]); imageline( $ im , $ xt - 1 , $ yt - 1 , $ xt + 1 , $ yt - 1 , $ tcolors [ 1 ]); imageline( $ im , $ xt - 1 , $ yt , $ xt + 1 , $ yt , $ tcolors [ 1 ]); imageline( $ im , $ xt - 1 , $ yt + 1 , $ xt + 1 , $ yt + 1 , $ tcolors [ 1 ]); imageline( $ im , $ xt - 1 , $ yt + 2 , $ xt + 2 , $ yt + 2 , $ tcolors [ 2 ]); imageline( $ im , $ xt + 2 , $ yt - 1 , $ xt + 2 , $ yt + 1 , $ tcolors [ 2 ]); } başka if ( $ stil == 11 ) { imagestring( $ im , $ this -> font , $ xt , $ yt , $ this -> metinler [ $ textnum ++], $ renk ); } elseif ( $ stil == 16 ) { // "Yok" stili -- hiçbir şey yapmayın. Sadece yan etki için çağrıldı. } $ pxt = $ xt ; $ puan = $ yt ; } else if (is_array( $ y ) && ( $ style == 13 || $ style == 14 )) { // Şamdanlar ve yüksek/düşük. if ( $ this -> boyut == 1 ) $ x = $ ben ; başka $ x = $ this -> koordinatlar [ 1 ][ $ i ]; $ xt = $ xoff +( $ x- $ xmin ) / ( $ xmax- $ xmin )* $ genişlik ; liste ( $ açık , $ yüksek , $ düşük , $ kapalı ) = $ y ; // Yüksek/düşük çizgi. $ ht = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ yüksek ); $ lt = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ düşük ); imageline( $ im , $ xt , $ ht , $ xt , $ lt , $ renk ); eğer ( $ stili == 13 ) { // Kutu. $ ot = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ açık ); $ ct = $ grafik -> y_noktası ( $ yoff , $ yükseklik , $ ymin , $ ymax , $ yakın ); eğer ( $ kapat > $ aç ) { imageline( $ im , $ xt , $ ct , $ xt , $ ot , $ grafik -> allocate_color (" beyaz ")); imagerectangle( $ im , $ xt - 2 , $ ct , $ xt + 2 , $ ot , $ renk ); } başka { imagefilledrectangle( $ im , $ xt - 2 , $ ot , $ xt + 2 , $ ct , $ renk ); } } } } eğer ( $ output_data ) { $ grafik -> output_data [] = & $ output_data ; $ grafiği -> ymin = $ ymin ; $ grafiği -> ymax = $ ymax ; $ grafiği -> yoff = $ yoff ; $ grafik -> yükseklik = $ yükseklik ; } dönüş ( $ renk ); } kalın_çizgi işlevi ( $ im , $ start_x , $ start_y , $ end_x , $ end_y , $ color , $ kalınlık ) { eğer ( $ end_x - $ start_x == 0 ) $ b = 0 ; başka $ b = ( $ bitiş_y - $ başlangıç_y ) / ( $ bitiş_x - $ başlangıç_x ); $ a = $ end_y - ( $ b * $ end_x ); if (mutlak( $ başlangıç_x - $ bitiş_x ) > mutlak( $ başlangıç_y - $ bitiş_y )) { $ start_x = tavan( $ start_x ); için ( $ x = $ start_x ; $ x <= $ end_x ; $ x ++) { $ y = $ b * $ x + $ bir ; imagefilledellipse( $ im , $ x , $ y , $ kalınlık , $ kalınlık , $ renk ); } } başka { $ start = ceil(min( $ start_y , $ end_y )); $ bitiş = maks( $ başlangıç_y , $ bitiş_y ); için ( $ y = $ başlangıç ​​; $ y <= $ bitiş ; $ y ++) { $ x = ( $ y - $ a ) / $ b ; imagefilledellipse( $ im , $ x , $ y , $ kalınlık , $ kalınlık , $ renk ); } } } }