Fixed issue #1610: Average values on statistics dialog graph
[TortoiseGit.git] / src / Utils / MiscUI / MyGraph.h
blob75d954d8ff8d1b1de0549fa37d6b149872f47911
1 // MyGraph.h
3 #if !defined(MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_)
4 #define MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_
5 #pragma once
8 /////////////////////////////////////////////////////////////////////////////
9 // MyGraphSeries
11 class MyGraphSeries : public CObject
13 friend class MyGraph;
15 // Construction.
16 public:
17 MyGraphSeries(const CString& sLabel = _T(""));
18 virtual ~MyGraphSeries();
20 // Declared but not defined.
21 private:
22 MyGraphSeries(const MyGraphSeries& rhs);
23 MyGraphSeries& operator=(const MyGraphSeries& rhs);
25 // Operations.
26 public:
27 void Clear() {m_dwaValues.RemoveAll(); m_oaRegions.RemoveAll();}
28 void SetLabel(const CString& sLabel);
29 CString GetLabel() const;
30 void SetData(int nGroup, int nValue);
31 int GetData(int nGroup) const;
33 // Implementation.
34 private:
35 int GetMaxDataValue(bool bStackedGraph) const;
36 int GetAverageDataValue() const;
37 int GetNonZeroElementCount() const;
38 int GetDataTotal() const;
39 void SetTipRegion(int nGroup, const CRect& rc);
40 void SetTipRegion(int nGroup, CRgn* prgn);
41 int HitTest(const CPoint& pt, int searchStart) const;
42 CString GetTipText(int nGroup, const CString &unitString) const;
44 // Data.
45 private:
46 CString m_sLabel; // Series label.
47 CDWordArray m_dwaValues; // Values array.
48 CArray<CRgn*,CRgn*> m_oaRegions; // Tooltip regions.
52 /////////////////////////////////////////////////////////////////////////////
53 // MyGraph
55 class MyGraph : public CStatic
57 // Enum.
58 public:
59 enum GraphType { Bar, Line, PieChart }; // Renamed 'Pie' because it hides a GDI function name
61 // Construction.
62 public:
63 MyGraph(GraphType eGraphType = MyGraph::PieChart, bool bStackedGraph = false);
64 virtual ~MyGraph();
66 // Declared but not defined.
67 private:
68 MyGraph(const MyGraph& rhs);
69 MyGraph& operator=(const MyGraph& rhs);
71 // Operations.
72 public:
73 void Clear();
74 void AddSeries(MyGraphSeries& rMyGraphSeries);
75 void SetXAxisLabel(const CString& sLabel);
76 void SetYAxisLabel(const CString& sLabel);
77 int AppendGroup(const CString& sLabel);
78 void SetLegend(int nGroup, const CString& sLabel);
79 void SetGraphType(GraphType eType, bool bStackedGraph);
80 void SetGraphTitle(const CString& sTitle);
81 int LookupLabel(const CString& sLabel) const;
82 void DrawGraph(CDC& dc);
84 // Implementation.
85 private:
86 void DrawTitle(CDC& dc);
87 void SetupAxes(CDC& dc);
88 void DrawAxes(CDC& dc) const;
89 void DrawLegend(CDC& dc);
90 void DrawSeriesBar(CDC& dc) const;
91 void DrawSeriesLine(CDC& dc) const;
92 void DrawSeriesLineStacked(CDC& dc) const;
93 void DrawSeriesPie(CDC& dc) const;
95 int GetMaxLegendLabelLength(CDC& dc) const;
96 int GetMaxSeriesSize() const;
97 int GetMaxNonZeroSeriesSize() const;
98 int GetMaxDataValue() const;
99 int GetAverageDataValue() const;
100 int GetNonZeroSeriesCount() const;
102 CString GetTipText() const;
104 INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
106 CPoint WedgeEndFromDegrees(double degrees, const CPoint& ptCenter,
107 double radius) const;
109 static UINT SpinTheMessageLoop(bool bNoDrawing = false,
110 bool bOnlyDrawing = false,
111 UINT uiMsgAllowed = WM_NULL);
113 static void RGBtoHLS(COLORREF crRGB, WORD& wH, WORD& wL, WORD& wS);
114 static COLORREF HLStoRGB(WORD wH, WORD wL, WORD wS);
115 static WORD HueToRGB(WORD w1, WORD w2, WORD wH);
117 // Overrides
118 // ClassWizard generated virtual function overrides
119 //{{AFX_VIRTUAL(MyGraph)
120 protected:
121 virtual void PreSubclassWindow();
122 //}}AFX_VIRTUAL
124 // Generated message map functions
125 protected:
126 //{{AFX_MSG(MyGraph)
127 afx_msg void OnPaint();
128 afx_msg void OnSize(UINT nType, int cx, int cy);
129 //}}AFX_MSG
130 afx_msg BOOL OnNeedText(UINT uiId, NMHDR* pNMHDR, LRESULT* pResult);
131 DECLARE_MESSAGE_MAP()
133 // Data.
134 private:
135 int m_nXAxisWidth;
136 int m_nYAxisHeight;
137 int m_nAxisLabelHeight;
138 int m_nAxisTickLabelHeight;
139 CPoint m_ptOrigin;
140 CRect m_rcGraph;
141 CRect m_rcLegend;
142 CRect m_rcTitle;
143 CString m_sXAxisLabel;
144 CString m_sYAxisLabel;
145 CString m_sTitle;
146 CDWordArray m_dwaColors;
147 CStringArray m_saLegendLabels;
148 CList<MyGraphSeries*,MyGraphSeries*> m_olMyGraphSeries;
149 GraphType m_eGraphType;
150 bool m_bStackedGraph;
153 //{{AFX_INSERT_LOCATION}}
154 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
156 #endif // !defined(MYGRAPHH__9DB68B4D_3C7C_47E2_9F72_EEDA5D2CDBB0__INCLUDED_)