Statistical programming, matrix languages, and more

gpie: colors with alpha transparency

Reply
Contributor
Posts: 24

gpie: colors with alpha transparency

[Running SAS 9.2 on linux]

This may be more a SAS/Graph question, but occurs in an IML context...

A cc:'d reply to friendly@yorku.ca would be appreciated, if this doesn't violate protocol for this discussion.

In the code below, I am plotting two overlapping circles using gpie and wish to draw attention to the area of overlap.

Rather than using cross-hatch patterns, I would prefer solid fill using transparent colors.  I tried appending

an alpha value to the hex codes for red and blue, e.g., CXrrggbbaa, but that doesn't have an effect.

Does SAS 9.2 support transparent colors in some other way?

proc iml;

start twocirc(cx, cy, radius, r, labels, colors, patterns);

   *-- Draw two circles showing partial relations;

   rsq = r##2;

   d = centdist( rsq ) # radius;

   x  = (cx - d/2)//

        (cx + d/2);

   y  = cy // cy;

   print 'Circle centers', x y radius rsq;

   call gpie(x, y, radius, 0, 360, colors, , patterns);

   call gpiexy(lx1, ly1, 1.25, 240, x[1]||y[1], radius);

   call gpiexy(lx2, ly2, 1.25, 300, x[2]||y[2], radius);

   call gstrlen(len,labels);

   lx = lx1-len[1] // lx2;

   ly = ly1 // ly2;

   call gscript(lx, ly, labels);

finish;

start centdist( r );

   *-- Compute distance between centers of circles from rsq;

   if r = 1 then return( 0 );         /* complete overlap     */

   else if r = 0 then return( 2 );    /* completely disjoint  */

   else do;                           /* intersecting circles */

      pi = 3.14159;

      lo = 0;  hi = pi;     /* angle theta, 0 <= theta <= pi radians */

      q = r # pi;           /* sector area of overlap */

      old = 0;

      alpha = pi/2;

      delta = 1;

      iter=0;

      do until (delta < .001);

         iter = iter + 1;

         if iter > 20 then goto done;

         z = alpha - sin(alpha);

         if z = q then delta = 0;

         else do;          /* adjust */

            old = alpha;

            if z > q then do;

               alpha = alpha - (alpha-lo)/2;

               hi = old;

            end;

            else do;

               alpha = alpha + (hi-alpha)/2;

               lo = old;

            end;

            delta = abs(old-alpha);

         end;

      end;

done:

*  print iter alpha delta lo hi;

   alpha = alpha/2;

   dist = 2 # cos(alpha);

   end;

   return( dist );

finish;

   call gstart;

   call gwindow({-5 -5 , 104 104});

   colors = { 'CXFF00000080', 'CX0000FF80' };

   patterns = {'psolid', 'psolid'};

   cx = 50; cy=50;

   rad = 25;

   r = .60;

   lab = {'Y.X' 'X.Y'};

   run twocirc(cx, cy, rad, r, lab, colors, patterns);

   call gshow;

SAS Super FREQ
Posts: 3,232

gpie: colors with alpha transparency

As far as I know, the old G-style graphics in PROC IML do not support transparency.

If you have SAS 9.22 or later, you can use the SUBMIT/ENDSUBMIT statements in the twocirc module.

I think I'd try to solve this problem by using a SUBMIT statement  to call a SAS/GRAPH or ODS Graphics procedure that supports transparency.

Post a Question
Discussion Stats
  • 1 reply
  • 207 views
  • 0 likes
  • 2 in conversation