(***********************************************************) (* *) (* TURBO GRAPHIX version 1.05A *) (* *) (* Bar chart module *) (* Module version 1.05A *) (* *) (* Copyright (C) 1985 by *) (* BORLAND International *) (* *) (***********************************************************) procedure DrawHistogram(A:PlotArray; NPoints:integer; Hatching:boolean; HatchStyle:integer); var x1,x2,y2,NPixels,Delta,NDiff,YRef:integer; LineStyleLoc,i:integer; Fract,s,y,YAxis:real; DirectModeLoc,Negative:boolean; wtemp:WindowType; X1Loc,Y1Loc,X2Loc,Y2Loc:integer; function Balance:integer; begin Balance:=0; s:=s+Fract; if s>=0.0 then begin s:=s-1.0; Balance:=1; end; end; begin { DrawHistogram } if abs(NPoints)>=2 then begin X1Loc := X1Glb; Y1Loc := Y1Glb; X2Loc := X2Glb; Y2Loc := Y2Glb; LineStyleLoc:=LinestyleGlb; SetLineStyle(0); if AxisGlb then begin wtemp:=window[WindowNdxGlb]; ReDefineWindow(WindowNdxGlb,X1RefGlb+4+X1Glb,Y1RefGlb+6+Y1Glb, X2RefGlb-2-X2Glb,Y2RefGlb-14-Y2Glb); SelectWindow(WindowNdxGlb); AxisGlb := true; end; DirectModeLoc:=DirectModeGlb; DirectModeGlb:=true; Negative:=NPoints<0; NPoints:=abs(NPoints); NPixels:=(X2RefGlb-X1RefGlb) shl 3+7; Delta:=NPixels div NPoints; NDiff:=NPixels-Delta*NPoints; Fract:=NDiff/NPoints; s:=-Fract; x1:=X1RefGlb shl 3; YRef:=trunc(Y2RefGlb+Y1RefGlb-AyGlb); if Negative then DrawStraight(x1,X2RefGlb shl 3+7,YRef); YAxis:=Y1RefGlb; if BYGlb>0 then YAxis:=Y2RefGlb; for i:=1 to NPoints do begin x2:=x1+Delta+Balance; y:=A[i,2]; if not Negative then y:=abs(y); if AxisGlb then y2:=trunc(AyGlb+ByGlb*y) else y2:=trunc((AyGlb+ByGlb*y)*0.99); y2:=Y2RefGlb+Y1RefGlb-y2; if not Negative then begin DrawLine(x1,YAxis,x1,y2); DrawStraight(x1,x2,y2); DrawLine(x2,y2,x2,YAxis); if Hatching then if odd(i) then hatch(x1,y2,x2,YAxis,HatchStyle) else hatch(x1,y2,x2,YAxis,-HatchStyle); end else begin DrawLine(x1,YRef,x1,y2); DrawStraight(x1,x2,y2); DrawLine(x2,y2,x2,YRef); if Hatching then if YRef-y2<0 then if odd(i) then hatch(x1,YRef,x2,y2,HatchStyle) else hatch(x1,YRef,x2,y2,-HatchStyle) else if odd(i) then hatch(x1,y2,x2,YRef,HatchStyle) else hatch(x1,y2,x2,YRef,-HatchStyle); end; x1:=x2; end; if AxisGlb then begin window[WindowNdxGlb]:=wtemp; SelectWindow(WindowNdxGlb); X1Glb := X1Loc; Y1Glb := Y1Loc; X2Glb := X2Loc; Y2Glb := Y2Loc; AxisGlb:=false; end; DirectModeGlb:=DirectModeLoc; SetLineStyle(LineStyleLoc); end else error(19,4); end;