示例#1
0
//+++-S-cf-------------------------------------------------------------------
//  NAME:       Draw()
//  DESC:       Draw Bar chart
//  PARAMETERS: CHART_HPAINT hp,
//              CHART_HRECT hr
//  RETURN:     None
//----------------------------------------------------------------------E-+++
void wxPieChartPoints::Draw(
    CHART_HPAINT hp,
    CHART_HRECT hr
)
{

    //-----------------------------------------------------------------------
    // Get sizes
    //-----------------------------------------------------------------------
    wxChartSizes *sizes = GetSizes();

    int r = (int)wxMin( (int)hr->w/2,
        (int)(hr->h - 2*sizes->GetSizeHeight())/2 );

    if ( r > 0 )
    {
        int iNodes = GetCount();

        if ( iNodes > 0 )
        {
            int iData;
            int ValTot;
            int iDatas = GetCount();
            for ( iData = 0, ValTot = 0; iData < iDatas; ++ iData )
                ValTot += static_cast<int>(GetYVal( iData ));

            double percent;
            double grad;
            double rad;
            int x1, y1, x2, y2, xc, yc;
            xc = hr->x + hr->w/2;
            yc = hr->y + hr->h/2;
            x1 = xc + r;
            y1 = yc;

            hp->SetPen( *wxBLACK_PEN );

            for ( iData = 0, rad = 0; iData < iDatas; ++ iData )
            {
                hp->SetBrush( wxBrush(GetColor(iData), wxSOLID) );

                // Calc radiants
                percent = (double)(GetYVal(iData) * 100) / (double)ValTot;
                grad    = (double)(percent * 360) / (double)100;
                rad     += (double)(grad * 3.1415) / (double)180;

                x2 = (int)(xc + r * cos( rad ));
                y2 = (int)(yc - r * sin( rad ));
                hp->DrawArc( x1, y1, x2, y2, xc, yc );
                x1 = x2;
                y1 = y2;

                //-----------------------------------------------------------
                // Only draw Label if user wants it
                //-----------------------------------------------------------
                if (!m_ShowLabel)
                    continue;

                wxString lbl;
                wxLabel wxLbl;

                LABEL_POSITION p;
                if ( x2 > xc )
                    p = RIGHT;
                else
                    p = LEFT;
                if ( y2 > yc )
                    p = (LABEL_POSITION)( p | DOWN );
                else
                    p = (LABEL_POSITION)( p | UP );

                switch ( GetDisplayTag() )
                {
                case XVALUE:
                    lbl.Printf( wxT("%d"), static_cast<int>(GetXVal(iData)) );
                    wxLbl.Draw( hp, x2, y2, GetColor(iData), lbl, p );
                    break;
                case YVALUE:
                    lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iData)) );
                    wxLbl.Draw( hp, x2, y2, GetColor(iData), lbl, p );
                    break;
                case XVALUE_FLOAT:
                    lbl.Printf( wxT("%4.1f"), GetXVal(iData) );
                    wxLbl.Draw( hp, x2, y2, GetColor(iData), lbl, p );
                    break;
                case YVALUE_FLOAT:
                    lbl.Printf( wxT("%4.1f"), GetYVal(iData) );
                    wxLbl.Draw( hp, x2, y2, GetColor(iData), lbl, p );
                    break;
                    case NAME:
                    lbl = GetName(iData).c_str();
                    wxLbl.Draw( hp, x2, y2, GetColor(iData), lbl, p );
                    break;
                default:
                    break;
                }
            }
        }
    }

}
//+++-S-cf-------------------------------------------------------------------
//  NAME:       Draw()
//  DESC:       Draw Bar chart
//  PARAMETERS: CHART_HPAINT hp, 
//              CHART_HRECT hr
//  RETURN:     None
//----------------------------------------------------------------------E-+++
void wxPie3DChartPoints::Draw(
    CHART_HPAINT hp, 
    CHART_HRECT hr
)
{
    
    //-----------------------------------------------------------------------
    // Get sizes
    //-----------------------------------------------------------------------
    wxChartSizes *sizes = GetSizes();

    //-----------------------------------------------------------------------
    // Fit Ellisse in window
    //-----------------------------------------------------------------------
    int r = (int)wxMin( (int)hr->w / 2, 
        (int)(hr->h - 2 * sizes->GetSizeHeight() * ELLISSE_H) / 2 );
         
    if ( r > 0 )
    {
        int iNodes = GetCount();

        if ( iNodes > 0 )
        {
            int iData;
            int ValTot;         
            int iDatas = GetCount();
            for ( iData = 0, ValTot = 0; iData < iDatas; ++ iData )
                ValTot += static_cast<int>(GetYVal( iData ));

            hp->SetPen( *wxBLACK_PEN );

            double percent;
            double grad, grad1;
            double rad;
            int deep;
            int x, y, w, h;

			// Calc Size of Rectangle which hold Ellisse
            w = (int)floor(r * ELLISSE_W);
			h = (int)floor(r * ELLISSE_H);

			// Top corner left hand side
            x = hr->x + hr->w/2 - w/2;
            y = hr->y + hr->h/2 - h;
                        
            // Shadow Deep
            deep = (int)floor( SHADOW_DEEP * GetZoom() );
                        
			//---------------------------------------------------------------
			// Draw shadow part of chart
			//---------------------------------------------------------------      

			hp->DrawEllipticArc( 
				x, 
				y + deep, // Shadow Deep
				w, 
				h, 
				175, // Draw half Ellisse
				360);
			hp->DrawEllipticArc( 
				x, 
				y + deep, // Shadow Deep
				w, 
				h, 
				0, // Draw half Ellisse
				5);

			// left hand side line
			rad = DegToRad( 180 );
			
			hp->DrawLine( 
                EllipsePoint( w, h, x, y, rad ).x,
                EllipsePoint( w, h, x, y, rad ).y,
                EllipsePoint( w, h, x, y, rad ).x,
                EllipsePoint( w, h, x, y + deep, rad ).y + 1
            );

			// right hand side line
			rad = DegToRad( 360 );

            hp->DrawLine( 
                EllipsePoint( w, h, x, y, rad ).x,
                EllipsePoint( w, h, x, y, rad ).y,
                EllipsePoint( w, h, x, y, rad ).x,
                EllipsePoint( w - 180, h, x, y + deep, rad ).y
            );

			grad = 0;
			//int count = 0;
            for ( iData = 0; iData < iDatas; ++ iData )
            {
                hp->SetPen( *wxBLACK_PEN );
                hp->SetBrush( wxBrush(GetColor(iData), wxSOLID) );

                // Calc radiants
                percent = (double)(GetYVal(iData) * 100) / (double)ValTot;
                grad1    = grad + (double)(percent * 360) / (double)100;
                rad     = DegToRad( grad );
                
                hp->DrawEllipticArc( x, y, w, h, grad, grad1);

                //-----------------------------------------------------------
                // Fill the shadow with right color
                //-----------------------------------------------------------
                if ( grad1 > 180 )
                {
					//if (++count > 3)
					//	return;

                    // set colors to draw
                    hp->SetPen( 
                        wxPen(wxChartColors::GetDarkColor(
                            GetColor(iData), 15)) 
                    );
                    hp->SetBrush( 
                        wxBrush(wxChartColors::GetDarkColor(
                            GetColor(iData), 15), 
                        wxSOLID) 
                    );
                    
                    // Avoid redraw line
                    if ( grad1 < 360 )
                    {
                        hp->DrawLine( 
                            EllipsePoint( w, h, x, y, DegToRad( grad1 ) ).x,
                            EllipsePoint( w, h, x, y, DegToRad( grad1 ) ).y - 1,
                            EllipsePoint( w, h, x, y, DegToRad( grad1 ) ).x,
                            EllipsePoint( w, h, x, y + deep, 
                                DegToRad( grad1 ) ).y + 1
                        );
                    }
                    hp->FloodFill(
                        EllipsePoint( w, h, x, y, 
                            DegToRad( grad1 ) ).x - 3, // just inside
                        (int)floor(EllipsePoint( w, h, x, y, 
                            DegToRad( grad1 ) ).y + (double)deep/2), // middle
                        *wxWHITE
                    );
				}
                                
                //-----------------------------------------------------------
                // Only draw Label if user wants it
                //-----------------------------------------------------------
                if (!m_ShowLabel)
                    continue;

                wxString lbl; 
                wxLabel wxLbl;
                
                LABEL_POSITION p;
                if ( grad < 90 ||
                    grad > 270 )
                    p = RIGHT;
                else
                    p = LEFT;
                if ( grad  > 180 )
                    p = (LABEL_POSITION)( p | DOWN );
                else
                    p = (LABEL_POSITION)( p | UP );

                switch ( GetDisplayTag() )
                {
                case XVALUE:
                    lbl.Printf( wxT("%d"), static_cast<int>(GetXVal(iData)) );
                    wxLbl.Draw( hp, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).x, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).y, 
                        GetColor(iData), lbl, p );
                    break;
                case YVALUE:
                    lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iData)) );
                    wxLbl.Draw( hp, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).x, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).y, 
                        GetColor(iData), lbl, p );
                    break;
                case XVALUE_FLOAT:
                    lbl.Printf( wxT("%4.1f"), GetXVal(iData) );
                    wxLbl.Draw( hp, 
                                EllipsePoint( w, h, x, y, DegToRad( grad ) ).x, 
                                EllipsePoint( w, h, x, y, DegToRad( grad ) ).y, 
                                GetColor(iData), lbl, p );
                    break;
                case YVALUE_FLOAT:
                    lbl.Printf( wxT("%4.1f"), GetYVal(iData) );
                    wxLbl.Draw( hp, 
                                EllipsePoint( w, h, x, y, DegToRad( grad ) ).x, 
                                EllipsePoint( w, h, x, y, DegToRad( grad ) ).y, 
                                GetColor(iData), lbl, p );
                    break;
                    case NAME:
                    lbl = GetName(iData).c_str();
                    wxLbl.Draw( hp, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).x, 
                        EllipsePoint( w, h, x, y, DegToRad( grad ) ).y, 
                        GetColor(iData), lbl, p );
                    break;
                default:
                    break;            
                }

                grad = grad1;

            }

        }
    }
}