// chartView.cpp : implementation of the CChartView class
//
#include "stdafx.h"
#include "chart.h"
#include "chartDoc.h"
#include "chartView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChartView
IMPLEMENT_DYNCREATE(CChartView, CFormView)
BEGIN_MESSAGE_MAP(CChartView, CFormView)
//{{AFX_MSG_MAP(CChartView)
ON_WM_SIZE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChartView construction/destruction
CChartView::CChartView()
: CFormView(CChartView::IDD)
{
//{{AFX_DATA_INIT(CChartView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
m_chart = NULL;
}
CChartView::~CChartView()
{
if(m_chart)
delete m_chart;
}
void CChartView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChartView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CChartView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CChartView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
CString label = _T("abcdefghijklmnopqrstuvwxyz")
_T("abcdefghijklmnopqrstuvwxyz")
_T("abcdefghijklmnopqrstuvwxyz");
CRect rect;
GetClientRect(&rect);
m_chart = new CDataChart();
m_chart->Create(_T("STATIC"), "Hi", WS_CHILD | WS_VISIBLE, rect, this, IDC_CHART);
m_chart->SetStyle(STYLE_PIE);
m_chart->Add( 0, 1, 200.0 );
m_chart->Add( 0, 2, 120.0 );
m_chart->Add( 0, 3, 310.0 );
m_chart->Add( 0, 6, 150.0 );
m_chart->Add( 0, 7, 160.0 );
m_chart->Add( 0, 9, 190.0 );
m_chart->Add( 0, 10, 320.0 );
m_chart->Add( 0, 15, 300.0 );
m_chart->Add( 0, 21, 250.0 );
m_chart->Add( 1, 12, 200.0 );
m_chart->Add( 1, 16, 120.0 );
m_chart->Add( 1, 18, 310.0 );
m_chart->Add( 1, 22, 150.0 );
m_chart->Add( 2, 1, 240.0 );
m_chart->Add( 2, 3, 285.0 );
m_chart->Add( 3, 6, 150.0 );
m_chart->Add( 3, 10, 320.0 );
m_chart->Add( 4, 15, 280.0 );
m_chart->Add( 4, 21, 250.0 );
m_chart->Add( 5, 4, 280.0 );
m_chart->Add( 5, 6, 250.0 );
m_chart->Add( 6, 15, 100.0 );
m_chart->Add( 6, 21, 280.0 );
m_chart->SetTitle("Session Length Distribution");
m_chart->SetYText("Number");
m_chart->SetXText("Session Length");
m_chart->SetXLabelStep( 2 );
m_chart->ShowGrid();
m_chart->SetDatasetLabel(0, label);
m_chart->SetDatasetLabel(1, label);
m_chart->SetDatasetLabel(2, label);
m_chart->SetDatasetLabel(3, label);
m_chart->SetDatasetLabel(4, label);
m_chart->SetDatasetLabel(5, label);
}
/////////////////////////////////////////////////////////////////////////////
// CChartView printing
BOOL CChartView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChartView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChartView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CChartView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CChartView diagnostics
#ifdef _DEBUG
void CChartView::AssertValid() const
{
CFormView::AssertValid();
}
void CChartView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CChartDoc* CChartView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChartDoc)));
return (CChartDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChartView message handlers
void CChartView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
if(m_chart)
m_chart->MoveWindow(rect);
}