Adds a title to the chart, patch 1242262 Matthew D.P.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Michael Wetherell 2005-08-10 22:53:45 +00:00
parent 1c2ed09a15
commit 8fb816ff93
3 changed files with 76 additions and 8 deletions

View File

@ -44,6 +44,7 @@ class WXDLLIMPEXP_PLOT wxPlotArea;
class WXDLLIMPEXP_PLOT wxPlotXAxisArea;
class WXDLLIMPEXP_PLOT wxPlotYAxisArea;
class WXDLLIMPEXP_PLOT wxPlotWindow;
class WXDLLIMPEXP_CORE wxStaticText;
//-----------------------------------------------------------------------------
// consts
@ -128,15 +129,15 @@ public:
void SetStartY( double startY )
{ m_startY = startY; }
double GetStartY()
double GetStartY() const
{ return m_startY; }
void SetEndY( double endY )
{ m_endY = endY; }
double GetEndY()
double GetEndY() const
{ return m_endY; }
void SetOffsetY( int offsetY )
{ m_offsetY = offsetY; }
int GetOffsetY()
int GetOffsetY() const
{ return m_offsetY; }
void SetPenNormal( const wxPen &pen )
@ -144,6 +145,11 @@ public:
void SetPenSelected( const wxPen &pen )
{ m_penSelected = pen; }
const wxPen& GetPenNormal() const
{ return m_penNormal; }
const wxPen& GetPenSelected() const
{ return m_penSelected; }
private:
int m_offsetY;
double m_startY;
@ -358,6 +364,8 @@ public:
void ResetScrollbar();
void AddChartTitle( const wxString&, wxFont = *wxNORMAL_FONT, wxColour = *wxBLACK );
private:
friend class wxPlotArea;
friend class wxPlotXAxisArea;
@ -377,6 +385,14 @@ private:
bool m_scrollOnThumbRelease;
bool m_enlargeAroundWindowCentre;
wxString m_title;
wxFont m_titleFont;
wxColour m_titleColour;
wxStaticText* m_titleStaticText;
wxBoxSizer* m_plotAndTitleSizer;
void DrawChartTitle();
DECLARE_CLASS(wxPlotWindow)
DECLARE_EVENT_TABLE()
};

View File

@ -129,6 +129,13 @@ MyFrame::MyFrame()
m_plot->SetUnitsPerValue( 0.01 );
// m_plot->SetScrollOnThumbRelease( true );
//Add a blue, 16pt chart title
wxString titleText( _T("The Chart Title") );
wxFont titleFont( *wxNORMAL_FONT );
titleFont.SetPointSize( 16 );
wxColour titleColour( *wxBLUE );
m_plot->AddChartTitle( titleText, titleFont, titleColour );
m_plot->Add( new MyPlotCurve( 0, -1.5, 1.5 ) );
m_plot->Add( new MyPlotCurve( 50, -1.5, 1.5 ) );
wxPlotOnOffCurve *oo = new wxPlotOnOffCurve( 10 );

View File

@ -29,6 +29,7 @@
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/dcclient.h"
#include "wx/stattext.h"
#endif
#include "wx/plot/plot.h"
@ -112,6 +113,7 @@ wxPlotEvent::wxPlotEvent( wxEventType commandType, int id )
IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject)
wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY )
: m_penNormal(*wxGREY_PEN), m_penSelected(*wxBLACK_PEN)
{
m_offsetY = offsetY;
m_startY = startY;
@ -415,9 +417,9 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
wxPlotCurve *curve = (wxPlotCurve*) node->GetData();
if (curve == m_owner->GetCurrentCurve())
dc.SetPen( *wxBLACK_PEN );
dc.SetPen( curve->GetPenSelected() );
else
dc.SetPen( *wxGREY_PEN );
dc.SetPen( curve->GetPenNormal() );
DrawCurve( &dc, curve, update_x-1, update_x+update_width+2 );
@ -709,7 +711,8 @@ BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow)
END_EVENT_TABLE()
wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
: wxScrolledWindow( parent, id, pos, size, flag, _T("plotcanvas") )
: wxScrolledWindow( parent, id, pos, size, flag, _T("plotcanvas") ),
m_titleStaticText( NULL )
{
m_xUnitsPerValue = 1.0;
m_xZoom = 1.0;
@ -745,6 +748,11 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos,
wxBoxSizer *plotsizer = new wxBoxSizer( wxHORIZONTAL );
//Add sizer to hold the title and plot.
//Title to be added later.
m_plotAndTitleSizer = new wxBoxSizer( wxVERTICAL );
m_plotAndTitleSizer->Add( plotsizer, 1, wxEXPAND | wxTOP, 10 );
if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS) != 0)
{
m_yaxis = new wxPlotYAxisArea( this );
@ -775,7 +783,7 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos,
m_xaxis = (wxPlotXAxisArea*) NULL;
}
mainsizer->Add( plotsizer, 1, wxEXPAND );
mainsizer->Add( m_plotAndTitleSizer, 1, wxEXPAND );
SetAutoLayout( true );
SetSizer( mainsizer );
@ -981,10 +989,45 @@ void wxPlotWindow::ResetScrollbar()
(int)(((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1), 0 );
}
void wxPlotWindow::AddChartTitle(const wxString& title, wxFont font,
wxColour colour)
{
m_title = title;
m_titleFont = font;
m_titleColour = colour;
DrawChartTitle();
}
void wxPlotWindow::DrawChartTitle()
{
if(m_title.size() != 0)
{
//If it is already added, remove child and delete
if(m_titleStaticText)
{
RemoveChild( m_titleStaticText );
m_titleStaticText->Destroy();
}
//Create the text control and set the font, colour
m_titleStaticText = new wxStaticText( this, -1, m_title );
m_titleStaticText->SetFont( m_titleFont );
m_titleStaticText->SetForegroundColour( m_titleColour );
//Create a sizer for the title. Prepend it to the Plot + Title sizer.
wxBoxSizer* titleSizer = new wxBoxSizer( wxHORIZONTAL );
titleSizer->Add( m_titleStaticText, 0, wxALIGN_CENTER | wxALL, 10 );
m_plotAndTitleSizer->Prepend( titleSizer, 0, wxALIGN_CENTER_HORIZONTAL );
//Finally, force layout
m_plotAndTitleSizer->Layout();
}
}
void wxPlotWindow::RedrawXAxis()
{
if (m_xaxis)
m_xaxis->Refresh( false );
m_xaxis->Refresh( true );
}
void wxPlotWindow::RedrawYAxis()
@ -1000,6 +1043,8 @@ void wxPlotWindow::RedrawEverything()
if (m_yaxis)
m_yaxis->Refresh( true );
m_area->Refresh( true );
DrawChartTitle();
}
void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) )