📄 graph.h
字号:
//--------------------------------------------------------------------------
//
// Filename: Graph.h
//
// Description:
//
//--------------------------------------------------------------------------
// $Archive: /WirelessUSB/WUSB Kits/CY3635 N-to-1 DVK/DocSrc/CD_Root/Software/Nto1/common/Graph/Graph.h $
// $Modtime: 10/06/04 6:19p $
// $Revision: 1 $
//--------------------------------------------------------------------------
//
// Copyright 2004, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------
#if !defined(MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_)
#define MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_
#pragma once
/////////////////////////////////////////////////////////////////////////////
// Constants.
#define TICK_PIXELS 6 // Size of tick marks.
#define GAP_PIXELS 6 // Better if an even value.
#define LEGEND_COLOR_BAR_WIDTH_PIXELS 50 // Width of color bar.
#define LEGEND_COLOR_BAR_GAP_PIXELS 1 // Space between color bars.
#define Y_AXIS_MAX_TICK_COUNT 10 // How many ticks on y axis.
#define X_AXIS_TICK_LABEL_COUNT 5 // How many ticks between labels on x axis.
#define X_AXIS_MAX_TICK_COUNT 25 // Max ticks on X axis.
#define INTERSERIES_PERCENT_USED 0.85 // How much of the graph is
// used for bars/pies (the
// rest is for inter-series
// spacing).
#define TITLE_DIVISOR 4 // Scale font to graph width.
#define LEGEND_DIVISOR 4 // Scale font to graph width.
#define X_AXIS_LABEL_DIVISOR 6 // Scale font to graph width.
#define Y_AXIS_LABEL_DIVISOR 4 // Scale font to graph width.
#define MAX_GROUPS_ALLOWED 10
#define PI 3.1415926535897932384626433832795
#define INVALID_MAX_VALUE 0xFFFFFFFF
/////////////////////////////////////////////////////////////////////////////
// CGraphSeries
class CGraphSeries : public CObject
{
friend class CGraph;
// Construction.
public:
CGraphSeries(CString sLabel = "");
virtual ~CGraphSeries();
// Operations.
public:
void SetLabel(CString sLabel);
CString GetLabel();
void SetData(int nGroup, int nValue);
int GetData(int nGroup);
void DeleteData(int nGroup);
// Implementation.
private:
int GetMaxDataValue();
int GetNonZeroElementCount();
int GetDataTotal();
// Data.
private:
CString m_sLabel; // Series label.
CPtrArray m_dwaValues; // Values array.
};
/////////////////////////////////////////////////////////////////////////////
// CGraph
typedef struct
{
CString sLabel;
DWORD dwColor;
} GRAPHICLEGEND, *PGRAPHICLEGEND;
class CGraph : public CStatic
{
// Enum.
public:
enum GraphType { Bar, Line, Pie };
static int m_nXAxisScale;
static CFileTime m_nXAxisStartFT;
// Construction.
public:
CGraph(GraphType eGraphType = CGraph::Line);
virtual ~CGraph();
// Operations.
public:
void SetXAxisLabel(CString sLabel);
void SetYAxisLabel(CString sLabel);
int AppendGroup(CString sLabel);
void AddLegend(int nGroup, CString sLabel);
void RenameLegend(int nGroup, CString sLabel);
void SetGraphType(GraphType eType);
void SetGraphTitle(CString sTitle);
int LookupLabel(CString sLabel);
void DrawGraph(CDC* pDc);
int GetGroup(CString sLabel);
void RemoveGroup(int group);
void AddSeries(CGraphSeries* pCGraphSeries);
CGraphSeries* GetSeries(CString sLabel);
int GetSeriesSize();
void RemoveSeries(CGraphSeries* series);
void RemoveAllSeries();
void RemoveAllLegend();
void ShiftYAxis(int nShift) { m_nYAxisShift += nShift; }
void SetMaxDataValueAllowed(int value) {m_nMaxDataValueAllowed = value;}
void SetMinDataValueAllowed(int value) {m_nYAxisShift = value;}
int GetMaxDataValueAllowed() {return m_nMaxDataValueAllowed;}
int GetMinDataValueAllowed() {return m_nYAxisShift;}
// Implementation.
private:
void DrawTitle(CDC* pDc);
void SetupAxes(CDC* pDc);
void DrawAxes(CDC* pDc);
void DrawLegend(CDC* pDc);
void DrawSeriesBar(CDC* pDc);
void DrawSeriesLine(CDC* pDc);
void DrawSeriesPie(CDC* pDc);
int GetMaxLegendLabelLength(CDC* pDc);
int GetMaxSeriesSize();
int GetMaxNonZeroSeriesSize();
int GetMaxDataValue();
int GetNonZeroSeriesCount();
CPoint WedgeEndFromDegrees(int nDegrees, CPoint *ptCenter,
int nRadius);
static UINT SpinTheMessageLoop(bool bNoDrawing = false,
bool bOnlyDrawing = false,
UINT uiMsgAllowed = WM_NULL);
static void RGBtoHLS(COLORREF crRGB, WORD wH, WORD wL, WORD wS);
static COLORREF HLStoRGB(WORD wH, WORD wL, WORD wS);
static WORD HueToRGB(WORD w1, WORD w2, WORD wH);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGraph)
//}}AFX_VIRTUAL
// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
// Data.
private:
int m_nXAxisWidth;
int m_nYAxisHeight;
CPoint m_ptOrigin;
CRect m_rcGraph;
CRect m_rcLegend;
CRect m_rcTitle;
CString m_sXAxisLabel;
CString m_sYAxisLabel;
CString m_sTitle;
CDWordArray m_dwaColors;
CPtrArray m_paLegend;
CObList m_olCGraphSeries;
GraphType m_eGraphType;
int m_nYAxisShift;
int m_nMaxDataValueAllowed;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -