Merge branch 'master' of git://github.com/Jopie64/tortoisegit
[TortoiseGit.git] / src / TortoiseProc / StatGraphDlg.h
blob805c5c02a1e6895cbb183b3e2063378d17473416
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #include "StandAloneDlg.h"
22 #include "MyGraph.h"
23 #include "XPImageButton.h"
24 #include "TGitPath.h"
25 #include "UnicodeUtils.h"
27 #include <map>
28 #include <list>
30 /**
31 * \ingroup TortoiseProc
32 * Helper class for drawing and then saving the drawing to a meta file (wmf)
34 class CMyMetaFileDC : public CMetaFileDC
36 public:
37 HGDIOBJ CMyMetaFileDC::SelectObject(HGDIOBJ hObject)
39 return (hObject != NULL) ? ::SelectObject(m_hDC, hObject) : NULL;
43 /**
44 * \ingroup TortoiseProc
45 * Helper dialog showing statistics gathered from the log messages shown in the
46 * log dialog.
48 * The function GatherData() collects statistical information and stores it
49 * in the corresponding member variables. You can access the data as shown in
50 * the following examples:
51 * @code
52 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
53 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
54 * commits = m_commitsPerAuthor[author_name];
55 * @endcode
58 class CStatGraphDlg : public CResizableStandAloneDialog//CResizableStandAloneDialog
60 DECLARE_DYNAMIC(CStatGraphDlg)
62 public:
63 CStatGraphDlg(CWnd* pParent = NULL);
64 virtual ~CStatGraphDlg();
66 enum { IDD = IDD_STATGRAPH };
68 // Data passed from the caller of the dialog.
69 CDWordArray * m_parDates;
70 CDWordArray * m_parFileChanges;
71 CStringArray * m_parAuthors;
72 CTGitPath m_path;
74 protected:
76 // ** Data types **
78 /// The types of units used in the various graphs.
79 enum UnitType
81 Weeks,
82 Months,
83 Quarters,
84 Years
87 /// The mapping type used to store data per interval/week and author.
88 typedef std::map<int, std::map<stdstring, LONG> > IntervalDataMap;
89 /// The mapping type used to store data per author.
90 typedef std::map<stdstring, LONG> AuthorDataMap;
92 // *** Re-implemented member functions from CDialog
93 virtual void OnOK();
94 virtual void OnCancel();
96 virtual void DoDataExchange(CDataExchange* pDX);
97 virtual BOOL OnInitDialog();
98 void ShowLabels(BOOL bShow);
99 virtual BOOL PreTranslateMessage(MSG* pMsg);
100 afx_msg void OnCbnSelchangeGraphcombo();
101 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
102 afx_msg void OnBnClickedStacked();
103 afx_msg void OnNeedText(NMHDR *pnmh, LRESULT *pResult);
104 afx_msg void OnBnClickedGraphbarbutton();
105 afx_msg void OnBnClickedGraphbarstackedbutton();
106 afx_msg void OnBnClickedGraphlinebutton();
107 afx_msg void OnBnClickedGraphlinestackedbutton();
108 afx_msg void OnBnClickedGraphpiebutton();
109 afx_msg void OnFileSavestatgraphas();
110 DECLARE_MESSAGE_MAP()
112 // ** Member functions **
114 /// Updates the variables m_weekCount and m_minDate and returns the number
115 /// of weeks in the revision interval.
116 void UpdateWeekCount();
117 /// Returns the week-of-the-year for the given time.
118 int GetCalendarWeek(const CTime& time);
119 /// Parses the data given to the dialog and generates mappings with statistical data.
120 void GatherData();
121 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
122 void FilterSkippedAuthors(std::list<stdstring>& included_authors, std::list<stdstring>& skipped_authors);
123 /// Shows the graph with commit counts per author.
124 void ShowCommitsByAuthor();
125 /// Shows the graph with commit counts per author and date.
126 void ShowCommitsByDate();
127 /// Shows the initial statistics page.
128 void ShowStats();
131 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
132 /// Recalculates statistical data because the number and names of authors
133 /// can have changed. Also calls RedrawGraph().
134 void AuthorsCaseSensitiveChanged();
135 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
136 /// Calls RedrawGraph().
137 void SortModeChanged();
138 /// Clears the current graph and frees all data series.
139 void ClearGraph();
140 /// Updates the currently shown statistics page.
141 void RedrawGraph();
143 int GetUnitCount();
144 int GetUnit(const CTime& time);
145 CStatGraphDlg::UnitType GetUnitType();
146 CString GetUnitString();
147 CString GetUnitLabel(int unit, CTime &lasttime);
149 void EnableDisableMenu();
151 void SaveGraph(CString sFilename);
152 int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
154 void StoreCurrentGraphType();
156 CPtrArray m_graphDataArray;
157 MyGraph m_graph;
158 CComboBox m_cGraphType;
159 CSliderCtrl m_Skipper;
160 BOOL m_bAuthorsCaseSensitive;
161 BOOL m_bSortByCommitCount;
163 CXPImageButton m_btnGraphBar;
164 CXPImageButton m_btnGraphBarStacked;
165 CXPImageButton m_btnGraphLine;
166 CXPImageButton m_btnGraphLineStacked;
167 CXPImageButton m_btnGraphPie;
169 HICON m_hGraphBarIcon;
170 HICON m_hGraphBarStackedIcon;
171 HICON m_hGraphLineIcon;
172 HICON m_hGraphLineStackedIcon;
173 HICON m_hGraphPieIcon;
175 MyGraph::GraphType m_GraphType;
176 bool m_bStacked;
178 CToolTipCtrl* m_pToolTip;
180 int m_langOrder;
182 // ** Member variables holding the statistical data **
184 /// Number of weeks in the revision interval.
185 int m_nWeeks;
186 /// The starting date/time for the revision interval.
187 __time64_t m_minDate;
188 /// The ending date/time for the revision interval.
189 __time64_t m_maxDate;
190 /// The total number of commits (equals size of the m_parXXX arrays).
191 INT_PTR m_nTotalCommits;
192 /// The total number of file changes.
193 LONG m_nTotalFileChanges;
194 /// Holds the number of commits per unit and author.
195 IntervalDataMap m_commitsPerUnitAndAuthor;
196 /// Holds the number of file changes per unit and author.
197 IntervalDataMap m_filechangesPerUnitAndAuthor;
198 /// First interval number (key) in the mappings.
199 int m_firstInterval;
200 /// Last interval number (key) in the mappings.
201 int m_lastInterval;
202 /// Mapping of total commits per author, access data via
203 AuthorDataMap m_commitsPerAuthor;
204 /// The list of author names sorted based on commit count
205 /// (author with most commits is first in list).
206 std::list<stdstring> m_authorNames;
207 /// unit names by week/month/quarter
208 std::map<LONG, stdstring> m_unitNames;