📄 gdchart.c
字号:
} else /* CLOSE_CONNECTED and CONNECTING are mutually exclusive*/ if( GDC_HLC_style & GDC_HLC_CONNECTING ) /* thin connecting line */ { int y1 = PY(uvals[CLOSESET+j*3][i-1]), y2 = PY(uvals[CLOSESET+j*3][i]); draw_3d_line( im, PY(0), PX(i-1), PX(i), &y1, &y2, /* rem only 1 set*/ xdepth_3D, ydepth_3D, 1, &(ExtColor I(CLOSESET+j*3,i)), &(ExtColorShd I(CLOSESET+j*3,i)) ); /* edge font of it*/ gdImageLine( im, PX(i-1), PY(uvals[CLOSESET+j*3][i-1]), PX(i), PY(uvals[CLOSESET+j*3][i]), ExtColorShd I(CLOSESET+j*3,i) ); } /* top half 'I' again*/ if( PY(uvals[CLOSESET+j*3][i-1]) <= PY(uvals[CLOSESET+j*3][i]) && uvals[HIGHSET+j*3][i-1] != GDC_NOVALUE ) if( GDC_HLC_style & GDC_HLC_I_CAP ) { SET_3D_POLY( poly, PX(i-1)-hlf_hlccapwdth, PX(i-1)+hlf_hlccapwdth, PY(uvals[HIGHSET+j*3][i-1]), PY(uvals[HIGHSET+j*3][i-1]), xdepth_3D, ydepth_3D ); gdImageFilledPolygon( im, poly, 4, ExtColor I(HIGHSET+j*3,i-1) ); gdImagePolygon( im, poly, 4, ExtColorShd I(HIGHSET+j*3,i-1) ); } } if( GDC_HLC_style & GDC_HLC_DIAMOND ) { /* front*/ poly[0].x = PX(i-1)-hlf_hlccapwdth; poly[0].y = PY(uvals[CLOSESET+j*3][i-1]); poly[1].x = PX(i-1); poly[1].y = PY(uvals[CLOSESET+j*3][i-1])+hlf_hlccapwdth; poly[2].x = PX(i-1)+hlf_hlccapwdth; poly[2].y = PY(uvals[CLOSESET+j*3][i-1]); poly[3].x = PX(i-1); poly[3].y = PY(uvals[CLOSESET+j*3][i-1])-hlf_hlccapwdth; gdImageFilledPolygon( im, poly, 4, ExtColor I(CLOSESET+j*3,i-1) ); gdImagePolygon( im, poly, 4, ExtColorShd I(CLOSESET+j*3,i-1) ); /* bottom side*/ SET_3D_POLY( poly, PX(i-1), PX(i-1)+hlf_hlccapwdth, PY(uvals[CLOSESET+j*3][i-1])+hlf_hlccapwdth, PY(uvals[CLOSESET+j*3][i-1]), xdepth_3D, ydepth_3D ); gdImageFilledPolygon( im, poly, 4, ExtColorShd I(CLOSESET+j*3,i-1) ); /* gdImagePolygon( im, poly, 4, ExtColor I(CLOSESET+j*3,i-1) );*/ /* top side*/ SET_3D_POLY( poly, PX(i-1), PX(i-1)+hlf_hlccapwdth, PY(uvals[CLOSESET+j*3][i-1])-hlf_hlccapwdth, PY(uvals[CLOSESET+j*3][i-1]), xdepth_3D, ydepth_3D ); gdImageFilledPolygon( im, poly, 4, ExtColor I(CLOSESET+j*3,i-1) ); gdImagePolygon( im, poly, 4, ExtColorShd I(CLOSESET+j*3,i-1) ); } } } } break; case GDC_HILOCLOSE: case GDC_COMBO_HLC_BAR: case GDC_COMBO_HLC_AREA: for( j=num_hlc_sets-1; j>=0; --j ) { for( i=0; i<num_points; ++i ) if( uvals[CLOSESET+j*3][i] != GDC_NOVALUE ) { /* all HLC have vert line */ if( uvals[LOWSET+j*3][i] != GDC_NOVALUE ) gdImageLine( im, PX(i), PY(uvals[CLOSESET+j*3][i]), PX(i), PY(uvals[LOWSET+j*3][i]), ExtColor I(LOWSET+(j*3),i) ); if( uvals[HIGHSET+j*3][i] != GDC_NOVALUE ) gdImageLine( im, PX(i), PY(uvals[HIGHSET+j*3][i]), PX(i), PY(uvals[CLOSESET+j*3][i]), ExtColor I(HIGHSET+j*3,i) ); if( GDC_HLC_style & GDC_HLC_I_CAP ) { if( uvals[LOWSET+j*3][i] != GDC_NOVALUE ) gdImageLine( im, PX(i)-hlf_hlccapwdth, PY(uvals[LOWSET+j*3][i]), PX(i)+hlf_hlccapwdth, PY(uvals[LOWSET+j*3][i]), ExtColor I(LOWSET+j*3,i) ); if( uvals[HIGHSET+j*3][i] != GDC_NOVALUE ) gdImageLine( im, PX(i)-hlf_hlccapwdth, PY(uvals[HIGHSET+j*3][i]), PX(i)+hlf_hlccapwdth, PY(uvals[HIGHSET+j*3][i]), ExtColor I(HIGHSET+j*3,i) ); } if( GDC_HLC_style & GDC_HLC_DIAMOND ) { gdPoint cd[4]; cd[0].x = PX(i)-hlf_hlccapwdth; cd[0].y = PY(uvals[CLOSESET+j*3][i]); cd[1].x = PX(i); cd[1].y = PY(uvals[CLOSESET+j*3][i])+hlf_hlccapwdth; cd[2].x = PX(i)+hlf_hlccapwdth; cd[2].y = PY(uvals[CLOSESET+j*3][i]); cd[3].x = PX(i); cd[3].y = PY(uvals[CLOSESET+j*3][i])-hlf_hlccapwdth; gdImageFilledPolygon( im, cd, 4, ExtColor I(CLOSESET+j*3,i) ); } } for( i=1; i<num_points; ++i ) if( uvals[CLOSESET+j*3][i-1] != GDC_NOVALUE && uvals[CLOSESET+j*3][i] != GDC_NOVALUE ) { if( GDC_HLC_style & GDC_HLC_CLOSE_CONNECTED ) /* line from prev close*/ gdImageLine( im, PX(i-1), PY(uvals[CLOSESET+j*3][i-1]), PX(i), PY(uvals[CLOSESET+j*3][i-1]), ExtColor I(CLOSESET+j*3,i) ); else /* CLOSE_CONNECTED and CONNECTING are mutually exclusive*/ if( GDC_HLC_style & GDC_HLC_CONNECTING ) /* thin connecting line*/ gdImageLine( im, PX(i-1), PY(uvals[CLOSESET+j*3][i-1]), PX(i), PY(uvals[CLOSESET+j*3][i]), ExtColor I(CLOSESET+j*3,i) ); } } break; } setno = 0; /* ---------- scatter points over all other plots ---------- */ /* scatters, by their very nature, don't lend themselves to standard array of points */ /* also, this affords the opportunity to include scatter points onto any type of chart */ /* drawing of the scatter point should be an exposed function, so the user can */ /* use it to draw a legend, and/or add their own */ if( GDC_scatter ) { int#ifdef USE_ALLOCA *scatter_clr = (int*)alloca (GDC_num_scatter_pts * sizeof (int));#else scatter_clr[GDC_num_scatter_pts];#endif /* USE_ALLOCA */ gdPoint ct[3]; for( i=0; i<GDC_num_scatter_pts; ++i ) { int hlf_scatterwdth = (int)( (float)(PX(2)-PX(1)) * (((float)((GDC_scatter+i)->width)/100.0)/2.0) ); int scat_x = PX( (GDC_scatter+i)->point + (do_bar?1:0) ), scat_y = PY( (GDC_scatter+i)->val ); if( (GDC_scatter+i)->point >= num_points || /* invalid point*/ (GDC_scatter+i)->point < 0 ) continue; scatter_clr[i] = clrallocate( im, (GDC_scatter+i)->color ); switch( (GDC_scatter+i)->ind ) { case GDC_SCATTER_TRIANGLE_UP: ct[0].x = scat_x; ct[0].y = scat_y; ct[1].x = scat_x - hlf_scatterwdth; ct[1].y = scat_y + hlf_scatterwdth;; ct[2].x = scat_x + hlf_scatterwdth; ct[2].y = scat_y + hlf_scatterwdth; if( !do_bar ) { if( (GDC_scatter+i)->point == 0 ) ct[1].x = scat_x; else if( (GDC_scatter+i)->point == num_points-1 ) ct[2].x = scat_x; } gdImageFilledPolygon( im, ct, 3, scatter_clr[i] ); break; case GDC_SCATTER_TRIANGLE_DOWN: ct[0].x = scat_x; ct[0].y = scat_y; ct[1].x = scat_x - hlf_scatterwdth; ct[1].y = scat_y - hlf_scatterwdth;; ct[2].x = scat_x + hlf_scatterwdth; ct[2].y = scat_y - hlf_scatterwdth; if( !do_bar ) { if( (GDC_scatter+i)->point == 0 ) ct[1].x = scat_x; else if( (GDC_scatter+i)->point == num_points-1 ) ct[2].x = scat_x; } gdImageFilledPolygon( im, ct, 3, scatter_clr[i] ); break; } } }/* overlay with a value and an arrow (e.g., total daily change)*/#ifdef THUMB_VALS /* put thmbl and thumbval over vol and plot lines */ if( thumbnail ) { int n, d, w; char thmbl[32]; char *price_to_str( float, int*, int*, int* ); char nmrtr[3+1], dmntr[3+1], whole[8]; char *dbg = price_to_str( ABS(thumbval),&n,&d,&w ); sprintf( nmrtr, "%d", n ); sprintf( dmntr, "%d", d ); sprintf( whole, "%d", w ); gdImageString( im, gdFontSmall, graphwidth/2-strlen(thumblabel)*SFONTWDTH/2, 1, thumblabel, ThumbLblColor ); if( w || n ) { int chgcolor = thumbval>0.0? ThumbUColor: ThumbDColor; int thmbvalwidth = SFONTWDTH + /* up/down arrow*/ (w?strlen(whole)*SFONTWDTH: 0) + /* whole*/ (n?strlen(nmrtr)*TFONTWDTH + /* numerator*/ SFONTWDTH + strlen(dmntr)*TFONTWDTH: /* denominator*/ 0); /* no frac part*/ smallarrow( im, graphwidth/2-thmbvalwidth/2, SFONTHGT, thumbval>0.0, chgcolor ); if( w ) { gdImageString( im, gdFontSmall, (graphwidth/2-thmbvalwidth/2)+SFONTWDTH, SFONTHGT+2, whole, chgcolor ); } if( n ) { gdImageString( im, gdFontTiny, (graphwidth/2-thmbvalwidth/2) + /* start*/ SFONTWDTH + /* arrow*/ (w? strlen(whole)*SFONTWDTH: 0) + /* whole*/ 2, SFONTHGT+2-2, nmrtr, chgcolor ); gdImageChar ( im, gdFontSmall, (graphwidth/2-thmbvalwidth/2) + /* start*/ SFONTWDTH + /* arrow*/ (w? strlen(whole)*SFONTWDTH: 0) + /* whole*/ strlen(nmrtr)*TFONTWDTH, /* numerator*/ SFONTHGT+2, '/', chgcolor ); gdImageString( im, gdFontTiny, (graphwidth/2-thmbvalwidth/2) + /* start*/ SFONTWDTH + /* arrow*/ (w? strlen(whole)*SFONTWDTH: 0) + /* whole*/ strlen(nmrtr)*TFONTWDTH + /* numerator*/ SFONTWDTH - 3, /* */ SFONTHGT+2+4, dmntr, chgcolor ); } } } /* thumblabel, thumbval*/#endif /* box it off */ /* after plotting so the outline covers any plot lines */ if( GDC_border ) { gdImageLine( im, PX(0), PY(lowest), PX(num_points-1+(do_bar?2:0)), PY(lowest), LineColor ); setno = GDC_stack_type==GDC_STACK_DEPTH? num_hlc_sets? num_hlc_sets: num_sets: 1; gdImageLine( im, PX(0), PY(highest), PX(num_points-1+(do_bar?2:0)), PY(highest), LineColor ); setno = 0; } if( GDC_border ) { int x1, y1, x2, y2; x1 = PX(0); y1 = PY(highest); x2 = PX(num_points-1+(do_bar?2:0)); y2 = PY(lowest); gdImageLine( im, x1, PY(lowest), x1, y1, LineColor ); setno = GDC_stack_type==GDC_STACK_DEPTH? num_hlc_sets? num_hlc_sets: num_sets: 1; gdImageLine( im, x1, y1, PX(0), PY(highest), LineColor ); /* if( !GDC_grid || do_vol || GDC_thumbnail ) */ /* grid leaves right side Y open*/ { gdImageLine( im, x2, y2, PX(num_points-1+(do_bar?2:0)), PY(lowest), LineColor ); gdImageLine( im, PX(num_points-1+(do_bar?2:0)), PY(lowest), PX(num_points-1+(do_bar?2:0)), PY(highest), LineColor ); } setno = 0; } if( GDC_0Shelf && threeD && /* front of 0 shelf */ ( (lowest < 0.0 && highest > 0.0) || (lowest < 0.0 && highest > 0.0) ) ) { int x2 = PX( num_points-1+(do_bar?2:0) ), y2 = PY( 0 ); gdImageLine( im, PX(0), PY(0), x2, y2, LineColor ); /* front line*/ setno = GDC_stack_type==GDC_STACK_DEPTH? num_hlc_sets? num_hlc_sets: num_sets: 1; /* backmost*/ /* depth for 3Ds*/ gdImageLine( im, x2, y2, PX(num_points-1+(do_bar?2:0)), PY(0), LineColor ); setno = 0; /* set back to foremost*/ } if( GDC_annotation ) /* front half of annotation line */ { int x1 = PX(GDC_annotation->point+(do_bar?1:0)), y1 = PY(highest); int x2; /* front line*/ gdImageLine( im, x1, PY(lowest)+1, x1, y1, AnnoteColor ); if( threeD ) { /* on back plane*/ setno = GDC_stack_type==GDC_STACK_DEPTH? num_hlc_sets? num_hlc_sets: num_sets: 1; x2 = PX(GDC_annotation->point+(do_bar?1:0)); /* prspective line*/ gdImageLine( im, x1, y1, x2, PY(highest), AnnoteColor ); } else /* for 3D done with back line*/ { x2 = PX(GDC_annotation->point+(do_bar?1:0)); gdImageLine( im, x1, y1, x1, y1-2, AnnoteColor ); } /* line-to and note */ if( *(GDC_annotation->note) ) /* any note?*/ { if( GDC_annotation->point >= (num_points/2) ) /* note to the left */ { gdImageLine( im, x2, PY(highest)-2, x2-annote_hgt/2, PY(highest)-2-annote_hgt/2, AnnoteColor ); GDCImageStringNL( im, &GDC_fontc[GDC_annotation_font], x2-annote_hgt/2-1-annote_len - 1, PY(highest)-annote_hgt+1, GDC_annotation->note, AnnoteColor, GDC_JUSTIFY_RIGHT ); } else /* note to right */ { gdImageLine( im, x2, PY(highest)-2, x2+annote_hgt/2, PY(highest)-2-annote_hgt/2, AnnoteColor ); GDCImageStringNL( im, &GDC_fontc[GDC_annotation_font], x2+annote_hgt/2+1 + 1, PY(highest)-annote_hgt+1, GDC_annotation->note, AnnoteColor, GDC_JUSTIFY_LEFT ); } } setno = 0; } /* usually GDC_generate_gif is used in conjunction with hard or hold options */ if( GDC_generate_gif ) { fflush(gif_fptr); /* clear anything buffered */ gdImageGif( im, gif_fptr ); } if( bg_img ) gdImageDestroy(bg_img); if( GDC_hold_img & GDC_EXPOSE_IMAGE ) GDC_image = (void*)im; else gdImageDestroy(im); return 0;}/* $Id: gdchart.c,v 1.7 2003/05/21 16:30:47 renaud Exp $ * local variables: * mode: c * tab-width: 4 * fill-column: 120 * end: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -