/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ // radarView.cpp : implementation of the CRadarView class // #include "stdafx.h" #include "radar.h" #include "radarDoc.h" #include "radarView.h" #include "Axis.h" #include "AxisCollection.h" #include "Bar.h" #include "Border.h" #include "ChartArea.h" #include "Chart2DData.h" #include "ChartGroup.h" #include "ChartGroupCollection.h" #include "ChartLabel.h" #include "ChartLabelCollection.h" #include "ChartStyle.h" #include "ChartStyleCollection.h" #include "DataIndex.h" #include "DerivedDouble.h" #include "FillStyle.h" #include "Font.h" #include "GridLines.h" #include "Interior.h" #include "Label.h" #include "LabelCollection.h" #include "LineStyle.h" #include "Legend.h" #include "PlotArea.h" #include "Title.h" #include "2dConst.h" #include "oc_color.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRadarView IMPLEMENT_DYNCREATE(CRadarView, CView) BEGIN_MESSAGE_MAP(CRadarView, CView) //{{AFX_MSG_MAP(CRadarView) ON_WM_CREATE() ON_COMMAND(ID_OPTIONS_FILLED, OnOptionsFilled) ON_COMMAND(ID_OPTIONS_STACKED, OnOptionsStacked) ON_UPDATE_COMMAND_UI(ID_OPTIONS_STACKED, OnUpdateOptionsStacked) ON_UPDATE_COMMAND_UI(ID_OPTIONS_FILLED, OnUpdateOptionsFilled) ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRadarView construction/destruction CRadarView::CRadarView() { // No Construction Necessary for this Simple Demo } CRadarView::~CRadarView() { } BOOL CRadarView::PreCreateWindow(CREATESTRUCT& cs) { return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CRadarView drawing void CRadarView::OnDraw(CDC* pDC) { CRadarDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); } ///////////////////////////////////////////////////////////////////////////// // CRadarView diagnostics #ifdef _DEBUG void CRadarView::AssertValid() const { CView::AssertValid(); } void CRadarView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CRadarDoc* CRadarView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRadarDoc))); return (CRadarDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRadarView message handlers int CRadarView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // Check if we can create the chart if (!m_chart.Create(NULL, WS_VISIBLE, CRect(0, 0, 800, 500), this, 1)) { return -1; } //Setup how the Chart looks SetupTheChart(); return 0; } // Helper procedure to set chart properties and data void CRadarView::SetupTheChart() { COleCurrency hFontSize; // needed for setting font sizes CTitle header; CLegend legend; CAxis axis; CLabelCollection labels; VARIANT va; // needed for setting labels CChart2DData data; CChartGroup chartGroup; TotalPoints = 7; // we have 7 data // Batch all the updates to the Chart so all the changes occur at once m_chart.SetIsBatched(true); // set the chart type to Radar m_chart.GetChartGroups().GetItem(COleVariant(1L)).SetChartType(oc2dTypeRadar); //Change some colors m_chart.GetInterior().SetBackgroundColor(ocColorLightBlue); m_chart.GetChartArea().GetInterior().SetBackgroundColor(ocColorLightYellow); m_chart.GetChartArea().GetPlotArea().GetInterior().SetBackgroundColor(ocColorAntiqueWhite); // Change some border styles m_chart.GetBorder().SetType(oc2dBorder3DIn); m_chart.GetBorder().SetWidth(4); m_chart.GetChartArea().GetBorder().SetType(oc2dBorder3DIn); m_chart.GetChartArea().GetBorder().SetWidth(4); //Setup the Header header = m_chart.GetHeader(); header.GetText().SetText("Radar Chart for System Adaptability"); hFontSize.SetCurrency(14, 0); header.GetFont().SetSize(hFontSize); header.GetBorder().SetType(oc2dBorderShadow); header.GetBorder().SetWidth(4); header.GetInterior().SetBackgroundColor(ocColorPaleTurquoise); // Setup the Legend legend = m_chart.GetLegend(); hFontSize.SetCurrency(9, 0); legend.GetFont().SetSize(hFontSize); legend.GetBorder().SetType(oc2dBorderShadow); legend.GetBorder().SetWidth(4); legend.GetInterior().SetBackgroundColor(ocColorAntiqueWhite); legend.SetOrientation(oc2dOrientHorizontal); legend.SetAnchor(oc2dAnchorSouth); //Setup the X and Y Axes axis = m_chart.GetChartArea().GetAxes().GetItem(COleVariant(1L)); axis.SetAnnotationMethod(oc2dAnnotatePointLabels); hFontSize.SetCurrency(10, 0); axis.GetFont().SetSize(hFontSize); axis.SetIsReversed(true); axis.GetMajorGrid().GetSpacing().SetIsDefault(true); axis = m_chart.GetChartArea().GetAxes().GetItem(COleVariant(2L)); axis.GetMajorGrid().GetSpacing().SetIsDefault(true); axis.GetDataMin().SetValue(0); // Add some labels to put at the end of each Axis 'Spoke' VariantInit(&va); va.vt = VT_I4; labels = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetPointLabels(); va.lVal = labels.GetCount() + 1; labels.Add("Introduce", va); va.lVal = labels.GetCount() + 1; labels.Add("Response",va); va.lVal = labels.GetCount() + 1; labels.Add("Travel Time",va); va.lVal = labels.GetCount() + 1; labels.Add("Get On/Off",va); va.lVal = labels.GetCount() + 1; labels.Add("Comfort",va); va.lVal = labels.GetCount() + 1; labels.Add("Social",va); va.lVal = labels.GetCount() + 1; labels.Add("Operate",va); // Add some labels to put in the Legend VariantInit(&va); va.vt = VT_I4; labels = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetSeriesLabels(); va.lVal = labels.GetCount() + 1; labels.Add("New Transport", va); va.lVal = labels.GetCount() + 1; labels.Add("OTIS", va); va.lVal = labels.GetCount() + 1; labels.Add("Mobile Walk", va); // Setup the data structure of the Chart data = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetData(); data.SetNumSeries(3); data.SetNumPoints(1,0); data.SetNumPoints(1,7); // Fill in the Series 1 Data data = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetData(); data.SetX(1, 1, 1); data.SetY(1, 1, 2.8); data.SetX(1, 2, 2); data.SetY(1, 2, 3.5); data.SetX(1, 3, 3); data.SetY(1, 3, 3.3); data.SetX(1, 4, 4); data.SetY(1, 4, 2); data.SetX(1, 5, 5); data.SetY(1, 5, 4); data.SetX(1, 6, 6); data.SetY(1, 6, 3); data.SetX(1, 7, 7); data.SetY(1, 7, 2.9); // Fill in the Series 2 Data data = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetData(); data.SetY(2, 1, 3.2); data.SetY(2, 2, 3.3); data.SetY(2, 3, 3.5); data.SetY(2, 4, 2.4); data.SetY(2, 5, 3.8); data.SetY(2, 6, 3.4); data.SetY(2, 7, 4.2); // Fill in the Series 3 Data data = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetData(); data.SetY(3, 1, 3.6); data.SetY(3, 2, 5); data.SetY(3, 3, 3.3); data.SetY(3, 4, 5); data.SetY(3, 5, 3.6); data.SetY(3, 6, 4.3); data.SetY(3, 7, 3.8); // Change the colors of the 3 Series chartGroup = m_chart.GetChartGroups().GetItem(COleVariant(1L)); chartGroup.GetStyles().GetItem(COleVariant(1L)).GetLine().SetColor(ocColorOrange); chartGroup.GetStyles().GetItem(COleVariant(2L)).GetLine().SetColor(ocColorBlue); chartGroup.GetStyles().GetItem(COleVariant(3L)).GetLine().SetColor(ocColorGreen); // Resume regular updating of the Chart m_chart.SetIsBatched(false); //Go back to normal chart updates } void CRadarView::OnOptionsFilled() { // Set the chart type CChartGroup group = m_chart.GetChartGroups().GetItem(COleVariant(1L)); if (group.GetChartType() == oc2dTypeRadar) group.SetChartType(oc2dTypeFilledRadar); else group.SetChartType(oc2dTypeRadar); } void CRadarView::OnUpdateOptionsFilled(CCmdUI* pCmdUI) { // Update the Check CChartGroup group = m_chart.GetChartGroups().GetItem(COleVariant(1L)); if (group.GetChartType() == oc2dTypeRadar) pCmdUI->SetCheck(false); else pCmdUI->SetCheck(true); } void CRadarView::OnOptionsStacked() { // Set the Is Stacked Option CChartGroup group = m_chart.GetChartGroups().GetItem(COleVariant(1L)); group.SetIsStacked(!group.GetIsStacked()); } void CRadarView::OnUpdateOptionsStacked(CCmdUI* pCmdUI) { // Update the Check pCmdUI->SetCheck(m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetIsStacked()); } void CRadarView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); // Call Parent's Size Function CView::OnSize(nType, cx, cy); // size the chart to fit the window if ((cx > 0) && (cy > 0)) { m_chart.MoveWindow(0, 0, cx, cy); } }