home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1985
/
13
/
bar6.bas
< prev
Wrap
BASIC Source File
|
1980-01-02
|
6KB
|
166 lines
'Figure 6: (longest line = 64 characters; stat 67% in 2-column width)
0 '** High resolution stacked bars: Program 6 **
10 INF=1.7E+38 'Infinity
20 LM=40:RM=635:TM=5:BM=190 'Screen margins
30 IF BM>190 THEN CLS:PRINT"The bottom margin is too large
for":PRINT"the titles to fit. Use a larger one.":END
40 IF TM<3 THEN CLS:PRINT"The top margin is too small
for":PRINT"the titles to fit. Use a larger one.":END
50 'Read patterns
60 READ NP 'Number of patterns
70 DIM P$(NP)
80 FOR I=1 TO NP
90 FOR J=1 TO 8
100 T=0
110 FOR K=1 TO 8
120 READ C:T=T+C*2^(8-K)
130 NEXT
140 P$(I)=P$(I)+CHR$(T)
150 NEXT
160 NEXT
170 SCREEN 0:WIDTH 80:CLS 'Set text mode
180 INPUT"Number of bars ";N:IF N<2 THEN 180
190 INPUT"Number of levels ";NL:IF NL<1 THEN 190
200 DIM S(N,NL),T$(N),T(N) 'Set space for N values,titles
and totals
210 DIM M(200),N(200) 'Temporary arrays for GET and PUT
220 MAX=-INF 'Set maximum to minus infinity
230 MIN=0 'Set minimum to zero for stacked bars
240 FOR I=1 TO N
250 PRINT I;
260 INPUT"Title ";T$(I)
270 FOR J=1 TO NL
280 PRINT " ";J;
290 INPUT S(I,J)
300 IF S(I,J)<0 THEN PRINT"< 0 illegal in stacked bars.
Repeat ":GOTO 280
310 T(I)=T(I)+S(I,J)
320 NEXT
330 IF T(I)>MAX THEN MAX=T(I)
340 NEXT
350 'Find longest value
360 MAXLEN=LEN(STR$(MAX)):IF MAX>=0 THEN MAXLEN=MAXLEN-1
370 'Draw chart
380 SCREEN 2:CLS
390 LINE(LM,TM)-(LM,BM) 'Y-axis
400 LINE(LM,BM)-(RM,BM) 'X-axis
410 WC=(RM-LM+1)/N 'Width of one column
420 WB=WC*.8 'Width of one bar
430 MWT=WB\8 'Maximum width of titles
440 SPB=LM+WC*.5-(WB*.5) 'Starting point of first bar
450 CC=SPB+WB\2 'Center of first column
460 HW=BM-TM+1 'Height of window
470 MVP=INT(HW*.95) 'Maximum vertical point
480 FACTOR=MVP/(MAX-MIN) 'Scaling factor for bars
490 D=MAX-MIN 'Distance between MIN and MAX
500 FV=1/(NV-1) 'Factor to scale values
510 DY=MVP/(NV-1) 'Vertical distance between values
520 PY=TM+MVP-3:PX=LM-2-MAXLEN*8 'Position of values
530 'Put values in vertical axis
540 FOR I=LM+2 TO RM STEP 3:PSET(I,0):NEXT
550 GET(LM+2,0)-(RM,0),N:CLS 'Dotted line
560 LINE(LM,TM)-(LM,BM) 'Y-axis
570 LINE(LM,BM)-(RM,BM) 'X-axis
580 F$=STRING$(MAXLEN,"#")
590 MA=MAX-MIN
600 'Normalize numbers and find number of zeros
610 IF MA<1 THEN 650
620 WHILE INT(MA)>=10:MA=MA/10:R=R+1:WEND:B=MA
630 IF R=0 THEN F$=F$+".#" 'At least one decimal in the format
640 GOTO 670
650 WHILE INT(MA)<1:MA=MA*10:R=R-1:WEND:B=MA+.001
660 F$=F$+"."+STRING$(ABS(R),"#") 'R zeros after the decimal
point
670 IF B>=1.2 THEN 690 ELSE R=R-1:ST=10:IF R<=-2 THEN F$=F$+"#"
680 GOTO 730
690 IF B>=5 THEN 720 ELSE ST=5 'Since step is 0.5, add
700 IF INSTR(F$,".")<>0 THEN F$=F$+"#" 'one decimal to format
710 GOTO 730
720 ST=10
730 MAXLEN=LEN(F$) 'F$ is the format
740 IF MAXLEN*8+2>LM THEN CLS:PRINT"The left margin is too small
for the":PRINT"values to fit. Use a larger value.":END
750 'Print values
760 EX=10^(R-1)
770 A=MIN/(ST*EX) 'Find bottom number
780 IF A<>INT(A)THEN A=INT(A)+1 ELSE A=INT(A)
790 WHILE A*ST*EX-MAX < .000001
800 T=A*ST*EX 'Number on axis
810 Y=MVP+TM-(T-MIN)*FACTOR 'Scaled height of number
820 LINE(LM-1,Y)-(LM+2,Y) 'Line in vertical axis
830 PUT(LM+2,Y),N 'Put dotted line
840 LOCATE 1,1:PRINT USING F$;T; 'Print number
850 GET(0,0)-(MAXLEN*8-1,7),M 'Copy in graphics form
860 LOCATE 1,1:PRINT SPACE$(MAXLEN); 'Erase number
870 PUT(LM-MAXLEN*8-2,Y-3),M,PSET 'Put number in its place
880 A=A+1 'Increment for next number
890 WEND
900 GET(0,0)-(200,7),N 'Copy top-left part of screen
910 'Put titles in horizontal axis
920 FOR I=1 TO N
930 LOCATE 1,1:T$=LEFT$(T$(I),MWT):PRINT T$;" "
940 LT=LEN(T$)*8 'Length of title, in pixels
950 GET(0,0)-(LT,7),M 'Copy title in graphics form
960 PUT(CC-LT\2,BM+2),M 'Put title in its
970 CC=CC+WC
980 NEXT
990 LOCATE 1,1:PRINT SPACE$(20); 'Erase last title
1000 PUT(0,0),N,PSET 'Restore axis and value
1010 'Draw bars
1020 FOR I=1 TO N
1030 T=0
1040 X1=SPB:X2=SPB+WB:Y2=BM
1050 PAT=1 'Pattern for first stacked bar
1060 FOR J=1 TO NL
1070 T=T+S(I,J)
1080 HEIGHT=(T-MIN)*FACTOR 'Height of bar
1090 Y1=MVP+TM-HEIGHT
1100 LINE(X1,Y1)-(X2,Y2),0,BF
1110 LINE(X1,Y1)-(X2,Y2),1,B
1120 IF X2-X1>2 THEN PAINT(X1+2,Y1+1),P$(PAT),1
1130 Y2=Y1
1140 PAT=PAT+1:IF PAT>NP THEN PAT=1
1150 NEXT
1160 SPB=SPB+WC 'Set position of next bar
1170 NEXT
1180 W$=INPUT$(1)
2000 DATA 4: 'Number of patterns
2010 'First Pattern
2020 DATA 1,0,0,0,1,0,0,0
2030 DATA 0,0,0,0,0,0,0,0
2040 DATA 0,0,1,0,0,0,1,0
2050 DATA 0,0,0,0,0,0,0,0
2060 DATA 1,0,0,0,1,0,0,0
2070 DATA 0,0,0,0,0,0,0,0
2080 DATA 0,0,1,0,0,0,1,0
2090 DATA 0,0,0,0,0,0,0,0
2100 'Second Pattern
2110 DATA 1,0,0,0,0,0,0,0
2120 DATA 0,1,0,0,0,0,0,0
2130 DATA 0,0,1,0,0,0,0,0
2140 DATA 0,0,0,1,0,0,0,0
2150 DATA 0,0,0,0,1,0,0,0
2160 DATA 0,0,0,0,0,1,0,0
2170 DATA 0,0,0,0,0,0,1,0
2180 DATA 0,0,0,0,0,0,0,1
2190 'Third pattern
2200 DATA 0,1,1,1,0,1,1,1
2210 DATA 1,1,1,1,1,1,1,1
2220 DATA 1,1,0,1,1,1,0,1
2230 DATA 1,1,1,1,1,1,1,1
2240 DATA 0,1,1,1,0,1,1,1
2250 DATA 1,1,1,1,1,1,1,1
2260 DATA 1,1,0,1,1,1,0,1
2270 DATA 1,1,1,1,1,1,1,1
2280 'Fourth pattern
2290 DATA 1,0,0,0,0,0,0,1
2300 DATA 0,0,0,0,0,1,1,0
2310 DATA 0,0,0,1,1,0,0,0
2320 DATA 0,1,1,0,0,0,0,0
2330 DATA 1,0,0,0,0,0,0,1
2340 DATA 0,0,0,0,0,1,1,0
2350 DATA 0,0,0,1,1,0,0,0
2360 DATA 0,1,1,0,0,0,0,0