Пример #1
0
static void PieGraph( void )
/*==========================

    Draw pie graph. */

{
    int                 i;
    float               x1, y1;
    float               x2, y2;
    float               x3, y3;
    float               x4, y4;
    float               xc, yc;
    float               xradius, yradius;
    float               theta;
    long                total;

/*  Calculate data for pie graph. */

    total = 0;
    for( i = 0; i < NUMSECT; ++i ) {
        total += Values[ i ];
    }

/*  Calculate centre and radius of pie */

    xc = 0.75;
    yc = 0.45;
    xradius = 0.20;
    yradius = 0.20 * 4 / 3;

/*  Calculate bounding rectangle */

    x1 = xc - xradius;
    y1 = yc - yradius;
    x2 = xc + xradius;
    y2 = yc + yradius;

/*  Draw the slices */

    x3 = xc + xradius;
    y3 = yc;
    theta = 0.0;
    for( i = 0; i < NUMSECT; ++i ) {
        theta += Values[ i ] * 2 * PI / total;
        x4 = xc + xradius * cos( theta );
        y4 = yc + yradius * sin( theta );
        _setcolor( i % ( VC.numcolors - 1 ) + 1 );
        _setfillmask( Masks[ i % 8 ] );
        _pie_w( _GFILLINTERIOR, x1, y1, x2, y2, x3, y3, x4, y4 );
        _pie_w( _GBORDER, x1, y1, x2, y2, x3, y3, x4, y4 );
        x3 = x4;
        y3 = y4;
    }
}
Пример #2
0
void _GrClear( short x1, short y1, short x2, short y2 )
/*=====================================================

    Clear area of screen in graphics mode. */

{
    unsigned char       prev_mask[ MASK_LEN ];
    grcolor             prev_colour;
    short               prev_action;

    prev_action = _setplotaction( _GPSET );
    _getfillmask( prev_mask );
    _setfillmask( NULL );
    prev_colour = _getcolor();
    _setcolor( 0 );
    _L1Block( x1, y1, x2, y2 );
    _setcolor( prev_colour );
    _setfillmask( prev_mask );
    _setplotaction( prev_action );
}
Пример #3
0
static void DoBars( float xleft, float ybottom, float xlen, float ylen )
/*======================================================================

    Draw bars of graph. */

{
    int                 i;
    float               x1, y1;
    float               x2, y2;
    float               bar_width;

    bar_width = ( 2 * xlen ) / ( 3 * NUMSECT + 1 );
    y1 = ybottom + 1.0 / VC.numypixels;
    for( i = 0; i < NUMSECT; ++i ) {
        x1 = xleft + ( 3 * i + 1 ) * bar_width / 2;
        x2 = x1 + bar_width;
        y2 = y1 + ylen * Values[ i ] / 100;
        _setcolor( i % ( VC.numcolors - 1 ) + 1 );
        _setfillmask( Masks[ i % 8 ] );
        _rectangle_w( _GFILLINTERIOR, x1, y1, x2, y2 );
        _rectangle_w( _GBORDER, x1, y1, x2, y2 );
    }
}
Пример #4
0
static void _DrawPie( chartenv _WCI86FAR* env,
                      float _WCI86FAR *values, short _WCI86FAR *explode, short n )
//======================================================================

/*  Uses shorts to graph the pie.

    +-----------+   -circle initially takes up 90% of the datawindow.
    |    |    |   -space is made ( maxlength ) for percent if needed
    |  |--  |   -initial vector is ( 1, 0 )
    | +- |   -percents are printed out so that they either start or
    |  |  |    end at the bisecting angle of the segment
    |    |    |   -exploded segments are placed 1/10th of the radius away
    +-----------+    from the center along the bisecting angle of the segment
*/

{
    short               xradius, yradius;
    short               newx, newy;
    short               oldx, oldy;
    short               xc, yc;
    short               x1, y1;
    short               x2, y2;
    float               xratio, yratio;
    short               xincrement, yincrement;
    float               newangle, oldangle;
    float               total = 0;
    float               running_total = 0;
    float               tmp;
    short               i;

    _Radius( env, &xradius, &yradius );
    oldangle = 0;
    xc = ( env->datawindow.x1 + env->datawindow.x2 ) / 2;
    yc = ( env->datawindow.y1 + env->datawindow.y2 ) / 2;
    x1 = xc - xradius;
    y1 = yc - yradius;
    x2 = xc + xradius;
    y2 = yc + yradius;
    oldx = x2;
    oldy = yc;
    for( i = 0; i < n; i++ ) {
        if( values[ i ] != _PG_MISSINGVALUE && values[ i ] > 0 ) {
            total += values[ i ];
        }
    }
    _setlinestyle( _PGPalette[ 1 ].style );
    for( i = 0; i < n; ++i ) {
        if( values[ i ] != _PG_MISSINGVALUE && values[ i ] > 0 ) {
            running_total += values[ i ];
            newangle = 2.0f * PI * running_total / total;
//          newx = xc + cos( newangle ) * xradius;
            tmp = newangle;
            _GR_cos( &tmp );        // tmp = cos( tmp )
            newx = xc + tmp * xradius;
//          newy = yc - sin( newangle ) * yradius;
            tmp = newangle;
            _GR_sin( &tmp );        // tmp = sin( tmp )
            newy = yc - tmp * yradius;
//          xratio = cos( ( newangle + oldangle ) / 2 );
            xratio = ( newangle + oldangle ) / 2;
            _GR_cos( &xratio );    // xratio = cos( xratio )
//          yratio = sin( ( newangle + oldangle ) / 2 );
            yratio = ( newangle + oldangle ) / 2;
            _GR_sin( &yratio );    // yratio = sin( yratio )
            _setcolor( _PGPalette[ i % 15 + 1 ].color );
            _setfillmask( _PGPalette[ i % 15 + 1 ].fill );
            if( !explode[ i ] ) {
                xincrement = 0;
                yincrement = 0;
            } else {
                xincrement = xratio * xradius / 10;
                yincrement = yratio * yradius / 10;
            }
            _DrawTwoPies( x1, y1, x2, y2, oldx, oldy, newx, newy,
                                          xincrement, yincrement );
            if( env->chartstyle == _PG_PERCENT ) {
                _DrawPercentLabel( xc + xincrement, yc - yincrement, xradius,
                        yradius, xratio, yratio, values[ i ] / total );
            }
            oldangle = newangle;
            oldx = newx;
            oldy = newy;
        }
    }
}