//+++-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 ); }
//+++-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; } }
//+++-S-cf------------------------------------------------------------------- // NAME: Draw() // DESC: Draw chart points // PARAMETERS: CHART_HPAINT hp, // int x, // int y // RETURN: None //----------------------------------------------------------------------E-+++ void wxChartWindow::Draw( CHART_HPAINT hp, int x, int y ) { //----------------------------------------------------------------------- // Get window information //----------------------------------------------------------------------- CHART_RECT r; r.x = x; r.y = y; r.xscroll = 0; r.yscroll = 0; GetClientSize( &r.w, &r.h ); //----------------------------------------------------------------------- // Set Background //----------------------------------------------------------------------- #if 0 hp->SetBrush( wxBrush(0xecf1f1, wxSOLID) ); //fcfdd8, *wxLIGHT_GREY_BRUSH hp->SetPen( *wxTRANSPARENT_PEN ); hp->DrawRectangle( r.x + 2, r.y + 5, static_cast<int>(GetVirtualWidth()), r.h - 5 ); #endif //----------------------------------------------------------------------- // Draw horizontal lines //----------------------------------------------------------------------- if ( m_UseGrid ) DrawHLines( hp, &r ); //----------------------------------------------------------------------- // Draw all charts //----------------------------------------------------------------------- m_Chart.Draw( hp, &r ); }
//+++-S-cf------------------------------------------------------------------- // NAME: Draw() // DESC: Draw Bar chart // PARAMETERS: CHART_HPAINT hp, // CHART_HRECT hr // RETURN: None //----------------------------------------------------------------------E-+++ void wxBar3DChartPoints::Draw( CHART_HPAINT hp, CHART_HRECT hr ) { //----------------------------------------------------------------------- // get number of bars //----------------------------------------------------------------------- double iNodes = ceil( static_cast<double>(GetCount()) ); //----------------------------------------------------------------------- // Get sizes //----------------------------------------------------------------------- wxChartSizes *sizes = GetSizes(); //----------------------------------------------------------------------- // get max height //----------------------------------------------------------------------- double ValMax = ceil( sizes->GetMaxY() ); if ( ValMax == 0 ) ValMax = 1; hp->SetBrush( wxBrush(GetColor(), wxSOLID) ); //hp->SetPen( *wxTRANSPARENT_PEN ); //hp->SetPen( *wxLIGHT_GREY_PEN ); hp->SetPen( wxPen(wxChartColors::GetDarkColor(GetColor(), 15)) ); double x, y, w, h; //----------------------------------------------------------------------- // Get the real width of the bar // Assume 80% of sizes->GetWidthBar3d() //----------------------------------------------------------------------- w = sizes->GetWidthBar3d() * 0.80; //----------------------------------------------------------------------- // Get how mutch high deep the bar should start. // Suppose we to use 30 degree // rad = 2 * pi / 360 * grd //----------------------------------------------------------------------- h = ( sizes->GetWidthBar3d() - w ) / cos( 0.5236 ) * sin( 0.5236 ); h *= GetZoom(); for ( int iNode = 0; iNode < iNodes; ++ iNode ) { //------------------------------------------------------------------- // Get x-position for iNode bar //------------------------------------------------------------------- double xVal = ceil( GetXVal(iNode) ); x = hr->x + GetZoom() * xVal * ( sizes->GetWidthBar() * sizes->GetNumBar() + sizes->GetWidthBar3d() * sizes->GetNumBar3d() + sizes->GetGap() ); //------------------------------------------------------------------- // Get y-position for iNode bar //------------------------------------------------------------------- y = hr->y + ( (hr->h - sizes->GetSizeHeight() )* GetYVal(iNode) ) / ValMax ; hp->DrawRectangle( static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), static_cast<int>(ceil(w * GetZoom())), static_cast<int>(ceil(y))); //------------------------------------------------------------------- // Draw Poligon next to main Rectangle //------------------------------------------------------------------- hp->SetBrush( wxBrush(wxChartColors::GetDarkColor(GetColor(), 10), wxSOLID) ); //------------------------------------------------------------------- // Make sure that the difference y and y - h is at lease 1 //------------------------------------------------------------------- int y1 = static_cast<int>(ceil(static_cast<double>(hr->h))); int y2 = static_cast<int>(ceil(static_cast<double>(hr->h - h))); int y3 = static_cast<int>(ceil(static_cast<double>(hr->h - y - h))); int y4 = static_cast<int>(ceil(static_cast<double>(hr->h - y))); int d = y1 - y2 > y4 - y3 ? y1 - y2 : y4 - y3; if ( d == 0 ) d += 1; wxPoint next[] = { wxPoint( static_cast<int>(ceil(x + w * GetZoom())), y1 ), wxPoint( static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())), y1 - d ), wxPoint( static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())), y4 - d ), wxPoint( static_cast<int>(ceil(x + w * GetZoom())), y4 ), }; hp->DrawPolygon( 4, next ); //------------------------------------------------------------------- // Draw Poligon on top of main Rectangle //------------------------------------------------------------------- wxPoint top[] = { wxPoint( static_cast<int>(ceil(x)), y4 ), wxPoint( static_cast<int>(ceil(x + w * GetZoom())), y4 ), wxPoint( static_cast<int>(ceil(x + sizes->GetWidthBar3d() * GetZoom())), y4 - d ), wxPoint( static_cast<int>(ceil(x + (sizes->GetWidthBar3d() - w) * GetZoom())), y4 - d ), }; hp->DrawPolygon( 4, top ); hp->SetBrush( wxBrush(GetColor(), wxSOLID) ); //------------------------------------------------------------------- // Only draw Label if user wants it //------------------------------------------------------------------- if (!m_ShowLabel) continue; wxString lbl; wxLabel wxLbl; switch ( GetDisplayTag() ) { case XVALUE: lbl.Printf( wxT("%d"), static_cast<int>(xVal)); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP); break; case YVALUE: lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iNode))); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; case XVALUE_FLOAT: lbl.Printf( wxT("%4.1f"), xVal); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP); break; case YVALUE_FLOAT: lbl.Printf( wxT("%4.1f"), GetYVal(iNode)); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; case NAME: lbl = GetName(iNode).c_str(); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; default: break; } } hp->SetPen( *wxBLACK_PEN ); }
//+++-S-cf------------------------------------------------------------------- // NAME: Draw() // DESC: Draw Bar chart // PARAMETERS: CHART_HPAINT hp, // CHART_HRECT hr // RETURN: None //----------------------------------------------------------------------E-+++ void wxBarChartPoints::Draw( CHART_HPAINT hp, CHART_HRECT hr ) { //----------------------------------------------------------------------- // get number of bars //----------------------------------------------------------------------- double iNodes = ceil( static_cast<double>(GetCount()) ); //----------------------------------------------------------------------- // Get sizes //----------------------------------------------------------------------- wxChartSizes *sizes = GetSizes(); //----------------------------------------------------------------------- // get max height //----------------------------------------------------------------------- double ValMax = ceil( sizes->GetMaxY() ); if ( ValMax == 0 ) ValMax = 1; hp->SetBrush( wxBrush(GetColor(), wxSOLID) ); hp->SetPen( *wxTRANSPARENT_PEN ); double x, y; for ( int iNode = 0; iNode < iNodes; ++ iNode ) { //------------------------------------------------------------------- // Get x-position for iNode bar //------------------------------------------------------------------- double xVal = ceil( GetXVal(iNode) ); x = hr->x + GetZoom() * xVal * ( sizes->GetWidthBar() * sizes->GetNumBar() + sizes->GetWidthBar3d() * sizes->GetNumBar3d() + sizes->GetGap() ); //------------------------------------------------------------------- // Get y-position for iNode bar //------------------------------------------------------------------- y = hr->y + ( (hr->h - sizes->GetSizeHeight())* GetYVal(iNode) ) / ValMax ; hp->DrawRectangle( static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), static_cast<int>(sizes->GetWidthBar() * GetZoom()), static_cast<int>(ceil(y)) ); //------------------------------------------------------------------- // Only draw Label if user wants it //------------------------------------------------------------------- if (!m_ShowLabel) continue; wxString lbl; wxLabel wxLbl; switch ( GetDisplayTag() ) { case XVALUE: lbl.Printf( wxT("%d"), static_cast<int>(xVal)); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP); break; case YVALUE: lbl.Printf( wxT("%d"), static_cast<int>(GetYVal(iNode))); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; case XVALUE_FLOAT: lbl.Printf( wxT("%4.1f"), xVal); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP); break; case YVALUE_FLOAT: lbl.Printf( wxT("%4.1f"), GetYVal(iNode)); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; case NAME: lbl = GetName(iNode).c_str(); wxLbl.Draw( hp, static_cast<int>(ceil(x)), static_cast<int>(ceil(hr->h - y)), GetColor(), lbl, UP ); break; default: break; } } hp->SetPen( *wxBLACK_PEN ); }
//+++-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 ); }