示例#1
0
//+++-S-cf-------------------------------------------------------------------
//  NAME:       WriteLabel()
//  DESC:       Write ROWS_PAGE labels starting from page 
//  PARAMETERS: CHART_HPAINT hp, 
//              int x, 
//              int y, 
//              int page
//  RETURN:     None
//----------------------------------------------------------------------E-+++
void wxLegend::WriteLabel(
    CHART_HPAINT hp, 
    int x, 
    int y, 
    int page
)
{    
    int iDatas = GetCount();

    wxFont font(8, wxROMAN, wxNORMAL, wxNORMAL);
    hp->SetFont(font);
    hp->SetPen( *wxBLACK_PEN );

    wxString label;
    
    for ( int iData = page * ROWS_PAGE; 
          iData < iDatas && iData < (page+1) * ROWS_PAGE; 
          ++ iData )
    {
        hp->SetBrush( wxBrush(GetColor(iData), wxSOLID) );
        hp->SetPen( *wxTRANSPARENT_PEN );
        hp->DrawRectangle( x, y+2, 10, 10 );
        
        hp->SetPen( *wxBLACK_PEN );
        label = GetLabel( iData ).c_str();
        label.Truncate( 5 );
        hp->DrawText( label, x + 15, y );
        
        y += ROW_SIZE;
    }
}
示例#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 );
    }
}
示例#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 );
}