*--------------------------------------------------------
*  Screen graphics demonstration program                |
*  Universal terminal version                           |
*  John Hathaway    3/1/83                              |
*--------------------------------------------------------
RELEASE ALL
SET TALK OFF
ERASE
*--------------------------------------------------------
*       new DBF file ?            			|
*--------------------------------------------------------
? 'DBASE SCREEN GRAPHICS DEMONSTRATION PROGRAM'
?
IF FILE("UGRAPH.DBF")
USE UGRAPH
ELSE
? 'FILE "UGRAPH.DBF" NOT IN THIS USER GROUP' 
RETURN
ENDIF
STORE 0 TO D
DO WHILE D<50
STORE D+1 TO D
ENDDO
RELEASE D
*--------------------------------------------------------
* setup field variables and data base read conditions   |
*--------------------------------------------------------
*? 'ENTER FIELD VARIABLES AND CONDITIONS BELOW'
?
STORE 'X' TO VX
STORE 'Y' TO VY
STORE 'X<>0' TO C
?
?
STORE 'B' TO BARS
IF !(BARS)='B'
STORE  'LABEL' TO LABEL
ENDIF
ERASE
?'DETERMINING MINIMUM AND MAXIMUM DATA POINTS ...'
?
STORE -10000 TO XMAX
STORE 10000 TO XMIN
STORE -10000 TO YMAX
STORE 10000 TO YMIN
STORE 1 TO NUM
STORE 0 TO SUME
GOTO TOP
DO WHILE .NOT. EOF
*   DISPLAY OFF 'RECORD #:',#,CHR(11)
  IF &C
    IF &VX<=XMIN
        STORE &VX TO XMIN
    ELSE
    IF &VX>=XMAX
        STORE &VX TO XMAX
    ENDIF
    ENDIF
    IF &VY<=YMIN
        STORE &VY TO YMIN
    ELSE
    IF &VY>=YMAX
        STORE &VY TO YMAX
    ENDIF
    ENDIF
    STORE NUM+1 TO NUM
    STORE SUME+&VY TO SUME
  ENDIF
    SKIP+1
ENDDO
*-------------------------------------------------------
* display minimum and maximum - allow alternate entries|
*-------------------------------------------------------
STORE '  ' TO RET
ERASE
@ 2,10 SAY 'AXIS SETUP SCREEN'
@ 5,10 SAY 'NUMBER:'
@ 5,20 SAY STR(NUM,6,0)
@ 7,10 SAY 'AVERAGE:'
@ 7,20 SAY STR(SUME/NUM,8,2)
@ 8,10 SAY '-------------------'
@ 10,10 SAY 'LOWER X'
@ 10,20 SAY STR(XMIN,8,2)
@ 11,10 SAY 'UPPER X'
@ 11,20 SAY STR(XMAX,8,2)
@ 13,10 SAY 'LOWER Y'
@ 13,20 SAY STR(YMIN,8,2)
@ 14,10 SAY 'UPPER Y'
@ 14,20 SAY STR(YMAX,8,2)
@ 17,1 SAY 'THESE ARE THE ACTUAL MAXIMUM AND MINUMUM DATA POINTS IN THE DATA'
@ 18,1 SAY 'BASE.  THESE VALUES WOULD BE USED TO DETERMINE THE AXIS ENDPOINTS.'
@ 19,1 SAY 'THE Y AXIS HAS 4 INTERVALS SO THE DIFFERENCE BETWEEN THE UPPER POINT'
@ 20,1 SAY 'AND THE LOWER POINT SHOULD BE EVENLY DIVISABLE BY 4. X AXIS HAS 5.'
@ 23,10 SAY 'PRESS "RETURN" TO CONTINUE' GET RET
READ
STORE 0 TO XMIN
STORE 10 TO XMAX
STORE 0 TO YMIN
STORE 8 TO YMAX
*--------------------------------------------------------
*          determine axis scaling factors         	|
*--------------------------------------------------------
STORE XMAX-XMIN TO XDIF
STORE XDIF/5 TO XINC
STORE YMAX-YMIN TO YDIF
STORE YDIF/4 TO YINC
STORE 1 TO X
STORE 1 TO Y
STORE 1 TO A
ERASE
*--------------------------------------------------------
*                    draw Y axis   |
*--------------------------------------------------------
STORE YMAX TO B
STORE '    ' TO D
DO WHILE A<23
    STORE (A-2)/5 TO F
    IF YMAX>10
        STORE STR(B-F*YINC,3) TO D
    ELSE
        STORE STR(B-F*YINC,3,1) TO D
    ENDIF
    IF A=2 .OR. A=7 .OR. A=12 .OR. A=17 .OR. A=22
        @ A,1 SAY D
        @ A,4 SAY '+'
    ELSE
        @ A,4 SAY '|'
    ENDIF
    STORE A+1 TO A
ENDDO
*--------------------------------------------------------
*                       draw X axis			|
*--------------------------------------------------------
STORE 0 TO A
@ 22,4 SAY '+--------------+--------------+--------------+--------------+--------------+'
STORE 15 TO N5
DO WHILE A<6
    IF A=5 
        STORE 14.4 TO N5
    ENDIF
    STORE XMIN+A*XINC TO B
    @ 23,A*N5+1 SAY STR(B,5,1)
    STORE A+1 TO A
ENDDO
@ 1,50 SAY 'Y AXIS ='
@ 1,58 SAY VY
@ 1,30 SAY 'X AXIS ='
@ 1,38 SAY VX
*--------------------------------------------------------
*               read file and plot data 		|
*--------------------------------------------------------
GOTO TOP
DO WHILE .NOT. EOF
    IF &C 
        STORE (&VX-XMIN)/XDIF*75 TO X1
        STORE (&VY-YMIN)/YDIF*20 TO Y1
        STORE 22-Y1 TO JJ
      IF !(BARS)='B'
        @ JJ,X1+3 SAY '*'
        @ JJ,X1+4 SAY '*'
        @ JJ,X1+5 SAY '*'
        STORE JJ+1 TO JJ
        DO WHILE JJ<22
            @ JJ,X1+3 SAY '|'
            @ JJ,X1+5 SAY '|'
            STORE JJ+1 TO JJ
        ENDDO
*--------------------------------------------------------
*    plot labels vertically inside bars			|
*--------------------------------------------------------
        STORE 1 TO L
        STORE TRIM(&LABEL) TO TLABEL
        DO WHILE L<=LEN(TLABEL)
            @ 21-LEN(TLABEL)+L,X1+4 SAY $(TLABEL,L,1)
            STORE L+1 TO L
        ENDDO
*------------------------------------ scatter plot
      ELSE
        @ JJ,X1+4 SAY '*'
      ENDIF
    ENDIF
    SKIP+1
ENDDO
RELEASE ALL
*--------------------------------------------------------
*     jump up here to avoid rolling the screen up	|
*--------------------------------------------------------
STORE '  ' TO YS
@ 1,70 SAY 'RET' GET YS
READ
ERASE
? 'TYPE FILE "UGRAPH.DOC" FOR FURTHER INFORMATION'
DO DEMOCHC

