⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataseries.cpp

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************************************
// $Header: /home/cvsroot/SoccerDoctor/Chart/DataSeries.cpp,v 1.4 2002/09/10 06:44:35 peter Exp $
//***********************************************************************************************
/************************************************************************************************/
/*                                                                                              */
/* File    : DataSeries.cpp                                                                     */
/*                                                                                              */
/* Purpose : interface for the data series within the CChartCtrl                                */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 10JUN02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          10JUN02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
#include "stdafx.h"
#include "DataSeries.h"
#include <float.h>
#include "2DScale.h"
#include "MemDC.h"

extern COLORREF SubdueColor(COLORREF Color);
extern COLORREF CreateBorderColor(COLORREF Color);

CDataSeries::CDataSeries(DATA_TYPE eDataType/*=TYPE_DBL_DATA*/) :
    m_eDataType(TYPE_NONE_DATA),
    m_wMaxInList(0),
    m_crColor(0),
    m_dXMin(DBL_MAX),
    m_dXMax(-DBL_MAX),
    m_dYMin(DBL_MAX),
    m_dYMax(10)/* 防止全是0的情况 */,
    m_dwLastID(-1) {
    
    m_DataArray.SetSize(0, 1);
    
    return;
    }

CDataSeries::~CDataSeries() {Purge();}

/************************************************************************************************/
/*                                                                                              */
/* Function: AddDataPoint()                                                                     */
/*                                                                                              */
/* Purpose : adds a data point to the serise                                                    */
/*                                                                                              */
/* Inputs  : CDataPoint* pDataPoint -> the data point to add                                    */
/*                                                                                              */
/* Outputs : BOOL <- TRUE if a data point has been removed from the series                      */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 12MAR02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          12MAR02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
BOOL CDataSeries::AddDataPoint(CDataPoint* pDataPoint) {
    
    BOOL bRemoved(FALSE);

    if (m_wMaxInList&&m_wMaxInList==GetNumOfDataPoints())
        bRemoved = !RemoveDataPoint(0);

    CDataPoint* pDP = new CDataPoint;
    *pDP = pDataPoint;
    
    //now get the stats
    _CalculateStats(pDataPoint);
    
    pDP->m_dwID = ++m_dwLastID;

    m_DataArray.Add(pDP);

    return bRemoved;
    }

/************************************************************************************************/
/*                                                                                              */
/* Function: _CalculateStats()                                                                  */
/*                                                                                              */
/* Purpose : calculates statistics for a data series                                            */
/*                                                                                              */
/* Inputs  : CDataPoint* pDataPoint -> the data point to compare the current stats with         */
/*                                                                                              */
/* Outputs : NONE                                                                               */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 12MAR02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          12MAR02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
void CDataSeries::_CalculateStats(CDataPoint* pDataPoint) {

    m_dXMin = m_dXMin+DBL_EPSILON>pDataPoint->m_dX?pDataPoint->m_dX:m_dXMin;
    m_dXMax = m_dXMax-DBL_EPSILON<pDataPoint->m_dX?pDataPoint->m_dX:m_dXMax;
    m_dYMin = m_dYMin+DBL_EPSILON>pDataPoint->m_dY?pDataPoint->m_dY:m_dYMin;
    m_dYMax = m_dYMax-DBL_EPSILON<pDataPoint->m_dY?pDataPoint->m_dY:m_dYMax;
}

/************************************************************************************************/
/*                                                                                              */
/* Function: RemoveDataPoint()                                                                  */
/*                                                                                              */
/* Purpose : removes a data point at the specified location                                     */
/*                                                                                              */
/* Inputs  : int i -> location to remove the data point from                                    */
/*                                                                                              */
/* Outputs : BOOL <- TRUE if a data point at the specified location does not exist              */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 12MAR02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          12MAR02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
BOOL CDataSeries::RemoveDataPoint(int i) {
    
    int nSize(m_DataArray.GetSize());

    if (nSize-1<i) {
        ASSERT(FALSE);
        return TRUE;
        }

    delete (CDataPoint*)m_DataArray.GetAt(i);
    m_DataArray.RemoveAt(i);

    /****need to recalculate the stats since we have removed an item****/
    m_dXMin = m_dYMin = DBL_MAX;
    m_dXMax = m_dYMax = DBL_MIN;
    for (i=0;i<m_DataArray.GetSize();i++)
        _CalculateStats((CDataPoint*)m_DataArray.GetAt(i));
    /****need to recalculate the stats since we have removed an item****/

    return FALSE;
    }

/************************************************************************************************/
/*                                                                                              */
/* Function: CDataSeries::Purge()                                                               */
/*                                                                                              */
/* Purpose : removes all data points from the series                                            */
/*                                                                                              */
/* Inputs  : NONE                                                                               */
/*                                                                                              */
/* Outputs : NONE                                                                               */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 12MAR02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          12MAR02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
void CDataSeries::Purge() {
    
    for (int i(0);i<m_DataArray.GetSize();i++)
        delete (CDataPoint*)m_DataArray.GetAt(i);
    
    m_DataArray.RemoveAll();
    
    m_dXMin = m_dYMin = DBL_MAX;
    m_dXMax = m_dYMax = DBL_MIN;

    m_dwLastID = -1;

    return;
    }

/***********************/
/***********************/
/***********************/
/***********************/
/***********************/
CDataSeriesArray::CDataSeriesArray(DATA_TYPE eDataType/*=TYPE_DBL_DATA*/) :
    m_dXMin(DBL_MAX),
    m_dXMax(-DBL_MAX),
    m_dYMin(DBL_MAX),
    m_dYMax(-DBL_MAX),
    m_eChartType(TYPE_LINE),
    m_dHeight(100),
    m_dElevation(5),
    m_wMaxInList(0),
    m_bRemoved(FALSE),
    m_pbScrolling(FALSE) {

    m_DataSeriesArray.SetSize(0, 1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -