Ejemplo n.º 1
0
//+++-S-cf-------------------------------------------------------------------
//  NAME:       Draw()
//  DESC:       Draw legend
//  PARAMETERS: CHART_HPAINT hp, 
//              CHART_HRECT hr
//  RETURN:     None
//----------------------------------------------------------------------E-+++
void wxLegend::Draw(
    CHART_HPAINT hp, 
    CHART_HRECT hr
)
{    
    int iPages = NumPages();
    int iLines = iPages > 0 ? ROWS_PAGE : GetCount();
    wxCoord h;
    //h = (ROWS_PAGE * ROW_SIZE < hr->h) ? ROWS_PAGE * ROW_SIZE : hr->h;
    h = (iLines * ROW_SIZE < hr->h) ? iLines * ROW_SIZE : hr->h;

    wxCoord x, y;
    x = (wxCoord)( 5 + hr->x );
    y = (wxCoord)( 5 + hr->y );

    //-----------------------------------------------------------------------
    // draw arrows
    //-----------------------------------------------------------------------
    if ( iPages > 0 )
    {
        hp->SetBrush( *wxGREY_BRUSH );
        hp->SetPen( *wxBLACK_PEN );
        
        DrawArrow( hp, x+hr->w/2, y, 8, ARROW_UP, false );
        hp->DrawLine( x+15, y+10, x+hr->w-15, y+10);
        DrawArrow( hp, x+hr->w/2, y + 20, 8, ARROW_DOWN, false );
    }

    //-----------------------------------------------------------------------
    // draw shadow
    //-----------------------------------------------------------------------
    y += 30;
    hp->SetBrush( *wxGREY_BRUSH );
    hp->SetPen( *wxTRANSPARENT_PEN );
    hp->DrawRectangle( x +5, y +5, hr->w - 10, h );

    //-----------------------------------------------------------------------
    // draw legend window
    //-----------------------------------------------------------------------
    hp->SetBrush( *wxWHITE_BRUSH );
    hp->SetPen( *wxBLACK_PEN );
    hp->DrawRectangle( x, y, hr->w - 10, h );

    //-----------------------------------------------------------------------
    // write labels
    //-----------------------------------------------------------------------
    WriteLabel( hp, x+3, y+3, m_Page );

}
Ejemplo n.º 2
0
//+++-S-cf-------------------------------------------------------------------
//	NAME:		Draw()
//	DESC:		Draw xaxis
//	PARAMETERS:	CHART_HPAINT hp,
//				CHART_HRECT hr
//	RETURN:		None
//----------------------------------------------------------------------E-+++
void wxYAxis::Draw(
    CHART_HPAINT hp,
    CHART_HRECT hr
)
{
    if ( GetVirtualMax() > 0 )
    {
        double range = GetVirtualMax();
        double start = 0;
        double end = range;

        int int_log_range = (int)floor( log10( range ) );
        double step = 1.0;
        if (int_log_range > 0)
        {
            for (int i = 0; i < int_log_range; i++)
                step *= 10;
        }
        if (int_log_range < 0)
        {
            for (int i = 0; i < -int_log_range; i++)
                step /= 10;
        }
        double lower = ceil(start / step) * step;
        double upper = floor(end / step) * step;

        // if too few values, shrink size
        if ((range/step) < 4)
        {
            step /= 2;
            if (lower-step > start) lower -= step;
            if (upper+step < end) upper += step;
        }

        // if still too few, again
        if ((range/step) < 4)
        {
            step /= 2;
            if (lower-step > start) lower -= step;
            if (upper+step < end) upper += step;
        }

        wxChartSizes *sizes = GetSizes();


        wxFont font( 8, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
        hp->SetFont(font);
        hp->SetPen( *wxBLACK_PEN );

        double current = lower;
        while (current < upper+(step/2))
        {
            int y = (int)( (GetVirtualMax()-current) /
                           range * ((double)hr->h - sizes->GetSizeHeight())) - 1;
            if ((y > 10) && (y < hr->h - 7 - sizes->GetSizeHeight()))
            {
                hp->DrawLine( hr->x + hr->w - 15,
                              y + sizes->GetSizeHeight() + hr->y,
                              hr->x + hr->w - 7,
                              y + sizes->GetSizeHeight() + hr->y );
                wxString label;
                if (range < 50)
                {
                    label.Printf( wxT("%f"), current );
                    while (label.Last() == wxT('0'))
                        label.RemoveLast();
                    if ((label.Last() == wxT('.')) || (label.Last() == wxT(',')))
                        label.Append( wxT('0') );
                }
                else
                    label.Printf( wxT("%d"), (int)floor(current) );
                hp->DrawText( label, hr->x + 5,
                              hr->y + y - 7 + sizes->GetSizeHeight() );
            }

            current += step;
        }

        hp->DrawLine( hr->w - 1, 6 + sizes->GetSizeHeight(),
                      hr->w - 1, hr->h );

        //hp->DrawLine( hr->w - 7, 6 + sizes.s_height,
        //			  hr->w - 7, hr->h );
        //hp->DrawLine( hr->w - 7, 2 + sizes.s_height,
        //			  hr->w - 13, 8 + sizes.s_height );
        //hp->DrawLine( hr->w - 7, 2 + sizes.s_height,
        //			  hr->w - 2, 8 + sizes.s_height );
    }
}
Ejemplo n.º 3
0
//+++-S-cf-------------------------------------------------------------------
//	NAME:		Draw()
//	DESC:		Draw Label Area
//	PARAMETERS:	wxDC* dc,
//				int x,
//				int y,
//				ChartString lbl,
//				POSITION pos = UP
//	RETURN:		None
//----------------------------------------------------------------------E-+++
void wxLabel::Draw(
    CHART_HPAINT hp,
	int x,
	int y,
    ChartColor c,
	wxString& lbl,
	LABEL_POSITION pos
)
{
	//-----------------------------------------------------------------------
	// Get actual configuration
	//-----------------------------------------------------------------------
    wxFont oldFont = hp->GetFont();
    wxBrush oldBrush = hp->GetBrush();
    wxPen oldPen = hp->GetPen();

	//-----------------------------------------------------------------------
	// Set new values
	//-----------------------------------------------------------------------
	wxFont font( 8, wxROMAN, wxNORMAL, wxNORMAL );
    hp->SetFont( font );
    hp->SetBrush( wxBrush(c, wxSOLID) );
    hp->SetPen( wxPen(LBL_LINE_COL, 1, wxSOLID) );

	//-----------------------------------------------------------------------
	// Get the size of the label for the specify font
	//-----------------------------------------------------------------------
	int w, h;
    hp->GetTextExtent( lbl, &w, &h );

	//-----------------------------------------------------------------------
	// Add boarder
	//-----------------------------------------------------------------------
	w += 5;
	h += 5;

	//-----------------------------------------------------------------------
	// Get the left-top rectangle point
	//-----------------------------------------------------------------------
	int xr = x, yr = y;
	if ( pos & UP )
		yr -= LBL_GAP;
	if ( pos & DOWN )
		yr += LBL_GAP;
	if ( pos & LEFT )
		xr -= LBL_GAP;
	if ( pos & RIGHT )
		xr += LBL_GAP;

	//-----------------------------------------------------------------------
	// Draw all
	//-----------------------------------------------------------------------
    hp->DrawRectangle( xr, yr, w, h );
	if ( pos & DOWN )
        hp->DrawLine( x, y, xr + w/2, yr );
	else
        hp->DrawLine( x, y, xr + w/2, yr + h);
    hp->DrawText( lbl, xr+2, yr );


	//-----------------------------------------------------------------------
	// Set old configuration
	//-----------------------------------------------------------------------
    hp->SetFont( oldFont );
    hp->SetBrush( oldBrush );
    hp->SetPen( oldPen );
}
Ejemplo n.º 4
0
//+++-S-cf-------------------------------------------------------------------
//  NAME:       DrawHLines()
//  DESC:       Draw horizontal lines
//  PARAMETERS: CHART_HPAINT hp,
//              CHART_HRECT hr
//  RETURN:     None
//----------------------------------------------------------------------E-+++
void wxChartWindow::DrawHLines(
    CHART_HPAINT hp,
    CHART_HRECT hr
)
{
    if ( GetVirtualMaxY() > 0 )
    {
        double range = GetVirtualMaxY();
        double start = 0;
        double end = range;

        int int_log_range = (int)floor( log10( range ) );
        double step = 1.0;
        if (int_log_range > 0)
        {
            for (int i = 0; i < int_log_range; i++)
                step *= 10;
        }
        if (int_log_range < 0)
        {
            for (int i = 0; i < -int_log_range; i++)
                step /= 10;
        }
        double lower = ceil(start / step) * step;
        double upper = floor(end / step) * step;

        // if too few values, shrink size
        if ((range/step) < 4)
        {
            step /= 2;
            if (lower-step > start) lower -= step;
            if (upper+step < end) upper += step;
        }

        // if still too few, again
        if ((range/step) < 4)
        {
            step /= 2;
            if (lower-step > start) lower -= step;
            if (upper+step < end) upper += step;
        }

        wxChartSizes *sizes = GetSizes();
/* C::B begin */
        // avoid crashes if style contains USE_GRID and no charts are added to chartctrl
        if(!sizes)
            return;
/* C::B end */

        hp->SetPen( *wxBLACK_DASHED_PEN );

        double current = lower;
        while (current < upper+(step/2))
        {
            int y = (int)( (GetVirtualMaxY()-current) /
                    range * ((double)hr->h - sizes->GetSizeHeight())) - 1;
            if ((y > 10) && (y < hr->h - 7 - sizes->GetSizeHeight()))
            {
                hp->DrawLine( hr->x,
                              y + sizes->GetSizeHeight() + hr->y,
                    hr->x + static_cast<int>(GetVirtualWidth()),
                    y + sizes->GetSizeHeight() + hr->y );
            }

            current += step;
        }
    }
}
//+++-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;

            }

        }
    }
}