/* To see the graphic as it will look when printed,     */
              /* display it as colored text on a white background.    */
              /* Use black for normal text and lines, and use red to  */
              /* highlight maximum values. For some output devices    */
              /* it may be necessary to specify a target device or    */
              /* rotation in the GOPTIONS statement.                  */
         goptions reset=all        /* Set graph options to defaults.  */                                                                            goptions reset=all        /* Set graph options to defaults.    */
                  gunit=pct        /* Define output area in percent.  */
                  cback=white      /* Use a white background.         */
                  targetdevice=pscolor  /* Emulate a Postscript       */
                                        /* device.                    */
                  rotate=landscape /* Make sure orientation is        */
                                   /* correct.                        */
                  ;

       data _null_;
         set mouse end=EOF;

         array treat(6) con brom nal morph bmor nmor;

         if (_n_=1) then
         do; /* Initialize graphics */
            rc=ginit(); /* Makes DSGI libraries available */
            link H;     /* Set up graphics environment    */
         end;

                 x=32;      /* Start each data line at this x value. */

          mx=max(con,brom,nal,morph,bmor,nmor); /* Determine maximum */
                                                /* value.            */
          rc=gset('texfont','swissl');          /* Set font.         */
          rc=gset('texcolor',1);  /* Initial color will be black.    */
          sg=put(surgery,$sur.);  /* Get formatted value for surgery. */
          rc=gdraw('text',5,y,sg);
          do i=1 to 6;            /* Step through variables.         */
             if treat(i)=mx then
             do; /* If value is maximum then change the color and    */
                 /*   font.                                          */
                rc=gset('texcolor',2); /* Value assigned in 'H'       */
                                       /* labeled section.            */
                rc=gset('texfont','swissi');

             end;
             else do; /* If not maximum then do not change color and  */
                      /* font                                         */
                rc=gset('texcolor',1);
                rc=gset('texfont','swissl');
             end;

               /* The values entered by the 'text' parameter of the */
               /* GDRAW function must be character, so the put      */
               /* function is used to convert numeric to character  */
               /* values.                                           */
             rc=gdraw('text',x,y,put(treat(i),3.));
             x+15; /* Increment x for the next column. */
          end; /* Step through variables. */

          y+(-5); /* Decrement y for the next row. */

            /* If there are less than 10 lines left on the current graph */
            /* or the end of the file has been processed then print the  */
            /* footnote.                                                 */
         if y le 10 or EOF then link NEXTP;
return;


H:  /* Initialize the graphic environment */

     /* Default values are set for such things as text   */
     /* fonts, colors, line drawing characteristics, and */
     /* graph name and destination.                      */
     /* For multiple pages, we can store each page as    */
     /* a separately named graph: test1, test2, and so on. */
     /* By default they are stored in a catalog called   */
     /* WORK.GSEG.                                       */
          n+1; /* Use this counter to name graph. */

                  /* Name the new graph - TEST1, TEST2, and so on. */
          rc=graph('clear','test'!!left(put(n,3.)));


       rc=gset('VIEWPORT',1,0,0,1,1); /* Define viewports '1' to be the  */
                                      /* entire active output area.      */

        /* 'x' starts at 32 for my data entry into the table. I          */
        /* want to increment 'x' by 15 for each column and leave a right */
        /* margin of 15. Therefore, I can set my maximum 'x' as 32+15*6   */
        /* or 122. Thus, my horizontal dimension (or range) will run      */
        /* from 0 to 122.                                                */

       rc=gset('WINDOW',1,0,0,122,100); /* Set window '1' in viewport    */
                                        /* to have a horizontal range of */
                                        /* 0 to 122. The vertical range  */
                                        /* is from 0 to 100.             */
       rc=gset('TRANSNO',1); /* Associate viewport '1' with window '1'   */
                             /* and make viewports '1' active.           */

              /* The versatility of graphics requires the         */
              /* addition of statements to control the            */
              /* appearance of the output. For example,           */
              /* initial values can be set for text appearance,   */
              /* colors, etc.                                     */
           rc=gset('texfont','zapf');  /* Select initial font.   */

              /* Associate colors to be used with 'index' numbers. */
           rc=gset('colrep',1,'black');
           rc=gset('colrep',2,'red');
           rc=gset('texalign','left','normal'); /* Align text left    */
                                                /* in columns.        */
           rc=gset('texcolor',1); /* Start with a text color of black */

              /* Title of table.
              /* We can use TITLE statements, but for comparison    */
              /* with the non-graphics example, let's use DSGI to   */
              /* generate the titles.                               */
           rc=gset('texheight',7); /* Title font size. */
           rc=gdraw('text',10,90,'Surgery by Drug Treatment');
                 /* Subtitle. */
           rc=gset('texheight',5); /* Smaller font for subtitle     */
           rc=gdraw('text',10,80,'C57BL6J Mice');

           rc=gset('lincolors',1); /* Draw lines in black */

              /* The horizontal range of the window is from 0 to 122.  */
              /* We want a margin of 5 before and after the line.      */
              /* Specify 5 for the beginning 'x' values and 122-5=117  */
              /* for the ending value. Also, the horizontal line is    */
              /* being drawn 77% up from the bottom of the graph.      */
           rc=gdraw('line',.,5,117,77,77);
           rc=gset('texheight',4.5); /* Text height for table body. */

              /* Column headings. */
           rc=gdraw('text',5,72,'Surgery');
           rc=gdraw('text',32,72,'Contr.');
           rc=gdraw('text',47,72,'Bromo.');
           rc=gdraw('text',62,72,'Nalox.');
           rc=gdraw('text',77,72,'Morph.');
           rc=gdraw('text',92,72,'Br/Mor.');
           rc=gdraw('text',107,72,'Na/Mor.');
           rc=gdraw('line',.,5,117,70,70);
           y=62; /* initial y value */

     return;


     NEXTP:  /* Draw footnote, display graphic and either */
             /* quit or go to next page.                 */

          y+(-3); /* Decrement 'y' from bottom of table to  */
                  /* ensure that the footnote will be drawn */
                  /* below the last row of the table.       */
             /* Use red and bold font. */
          rc=gset('texcolor',2);
          rc=gset('texfont','swissb');
          rc=gdraw('text',10,y,'Red ');

             /* Use black and normal font. */
          rc=gset('texfont','swissl');
          rc=gset('texcolor',1);
          rc=gdraw('text',17,y,
             'represents maximum value across drug
             ' treatment for surgery');

          rc=graph('update'); /* Graph is completed, so store and display. */
          if eof then
          do; /* If no more data */

             rc=gterm(); /* Terminate DSGI. */
             stop;

          end;

          else link H;

      return;

run;