Don't import ogdf namespace
[TortoiseGit.git] / src / TortoiseProc / StatGraphDlg.h
blob109009f6d541a0ce32e5ac45480677b71ea85b81
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2011-2013, 2015-2017 - TortoiseGit
4 // Copyright (C) 2003-2011, 2015 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 #include "StandAloneDlg.h"
23 #include "MyGraph.h"
24 #include "TGitPath.h"
25 #include "UnicodeUtils.h"
27 #include "tstring.h"
28 #include "GitLogListBase.h"
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 SelectObject(HGDIOBJ hObject)
39 return (hObject != nullptr) ? ::SelectObject(m_hDC, hObject) : nullptr;
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
57 class CStatGraphDlg : public CResizableStandAloneDialog//CResizableStandAloneDialog
59 DECLARE_DYNAMIC(CStatGraphDlg)
61 public:
62 CStatGraphDlg(CWnd* pParent = nullptr);
63 virtual ~CStatGraphDlg();
65 enum { IDD = IDD_STATGRAPH };
67 std::vector<GitRevLoglist*> m_ShowList;
69 // Data passed from the caller of the dialog.
70 CDWordArray m_parDates;
71 CDWordArray m_parFileChanges;
72 CDWordArray m_parFileChanges2;
73 CDWordArray m_lineInc;
74 CDWordArray m_lineInc2;
75 CDWordArray m_lineDec;
76 CDWordArray m_lineDec2;
77 CDWordArray m_lineNew;
78 CDWordArray m_lineNew2;
79 CDWordArray m_lineDel;
80 CDWordArray m_lineDel2;
82 CStringArray m_parAuthors;
83 CTGitPath m_path;
85 protected:
87 // ** Constants **
88 static const long int m_SecondsInWeek = 604800; // ... a week has 604800 seconds
89 static const long int m_SecondsInDay = 86400; // ... a day has 86400.0 seconds
90 static const int m_CoeffAuthorShip = 2;
92 // ** Data types **
94 /// The types of units used in the various graphs.
95 enum UnitType
97 Days,
98 Weeks,
99 Months,
100 Quarters,
101 Years
104 // Available next metrics
105 enum Metrics
107 TextStatStart,
108 AllStat,
109 TextStatEnd,
110 GraphicStatStart,
111 PercentageOfAuthorship,
112 CommitsByAuthor,
113 CommitsByDate,
114 LinesWByDate,
115 LinesWOByDate,
116 GraphicStatEnd,
119 //TODO: try substitute map to hash_map
120 /// The mapping type used to store data per interval/week and author.
121 typedef std::map<int, std::map<tstring, LONG> > IntervalDataMap;
123 //TODO: try substitute few Maps to one map, that store needs informations about Authors
124 /// The mapping type used to store data per author.
125 typedef std::map<tstring, LONG> AuthorDataMap;
126 /// The mapping type used to store data per Percentage Of Authorship
127 typedef std::map<tstring, double> AuthorshipDataMap;
129 // *** Re-implemented member functions from CDialog
130 virtual void OnOK() override;
131 virtual void OnCancel() override;
133 virtual void DoDataExchange(CDataExchange* pDX) override;
134 virtual BOOL OnInitDialog() override;
135 void ShowLabels(BOOL bShow);
136 afx_msg void OnCbnSelchangeGraphcombo();
137 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
138 afx_msg void OnNeedText(NMHDR *pnmh, LRESULT *pResult);
139 afx_msg void OnBnClickedGraphbarbutton();
140 afx_msg void OnBnClickedGraphbarstackedbutton();
141 afx_msg void OnBnClickedGraphlinebutton();
142 afx_msg void OnBnClickedGraphlinestackedbutton();
143 afx_msg void OnBnClickedGraphpiebutton();
144 afx_msg void OnFileSavestatgraphas();
145 afx_msg void OnBnClickedFetchDiff();
146 afx_msg void OnBnClickedCommitternames();
147 afx_msg void OnBnClickedCommitdates();
148 DECLARE_MESSAGE_MAP()
150 // ** Member functions **
152 /// Updates the variables m_nWeeks, m_nDays and m_minDate
153 void UpdateWeekCount();
154 /// Returns the week-of-the-year for the given time.
155 int GetCalendarWeek(const CTime& time);
156 /// Parses the data given to the dialog and generates mappings with statistical data.
157 int GatherData(BOOL fetchdiff = FALSE, BOOL keepFetchedData = FALSE);
158 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
159 void FilterSkippedAuthors(std::list<tstring>& included_authors, std::list<tstring>& skipped_authors);
160 /// Shows the graph Percentage Of Authorship
161 void ShowPercentageOfAuthorship();
162 /// Shows the graph with commit counts per author.
163 void ShowCommitsByAuthor();
164 /// Shows the graph with commit counts per author and date.
165 void ShowByDate(int StringY, int title, IntervalDataMap &data);
166 /// Shows the initial statistics page.
167 void ShowStats();
169 /// Rolling Percentage Of Authorship of author to integer
170 int RollPercentageOfAuthorship(double it);
172 /// Load list of drawing authors
173 template <class MAP> void LoadListOfAuthors (MAP &map, bool reloadSkiper = false, bool compare = false);
175 // If we have other authors, count them and their commits.
176 template <class MAP>
177 void DrawOthers(const std::list<tstring> &others, MyGraphSeries *graphData, MAP &map);
180 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
181 /// Recalculates statistical data because the number and names of authors
182 /// can have changed. Also calls RedrawGraph().
183 void AuthorsCaseSensitiveChanged();
184 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
185 /// Calls RedrawGraph().
186 void SortModeChanged();
187 /// Clears the current graph and frees all data series.
188 void ClearGraph();
189 /// Updates the currently shown statistics page.
190 void RedrawGraph();
192 /// PreShow Statistic function
193 bool PreViewStat(bool fShowLabels);
194 /// PreShow Graphic function
195 MyGraphSeries * PreViewGraph(__in UINT GraphTitle, __in UINT YAxisLabel, __in UINT XAxisLabel = NULL);
196 /// Show Selected Static metric
197 void ShowSelectStat(Metrics SelectedMetric, bool reloadSkiper = false);
199 int GetUnitCount();
200 int GetUnit(const CTime& time);
201 CStatGraphDlg::UnitType GetUnitType();
202 CString GetUnitString();
203 CString GetUnitLabel(int unit, CTime &lasttime);
205 void EnableDisableMenu();
207 void SaveGraph(CString sFilename);
208 int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
210 void StoreCurrentGraphType();
211 void ShowErrorMessage();
213 // init ruler & limit its range
214 void SetSkipper (bool reloadSkiper);
216 //Load statistical queries
217 void LoadStatQueries(__in UINT curStr, Metrics loadMetric, bool setDef = false);
219 //Considers coefficient contribution author
220 double CoeffContribution(int distFromEnd);
222 CPtrArray m_graphDataArray;
223 MyGraph m_graph;
224 CComboBox m_cGraphType;
225 CSliderCtrl m_Skipper;
226 BOOL m_bAuthorsCaseSensitive;
227 BOOL m_bSortByCommitCount;
228 BOOL m_bUseCommitterNames;
229 BOOL m_bUseCommitDates;
230 BOOL m_bDiffFetched;
232 CMFCButton m_btnGraphBar;
233 CMFCButton m_btnGraphBarStacked;
234 CMFCButton m_btnGraphLine;
235 CMFCButton m_btnGraphLineStacked;
236 CMFCButton m_btnGraphPie;
238 MyGraph::GraphType m_GraphType;
239 bool m_bStacked;
241 int m_langOrder;
243 // ** Member variables holding the statistical data **
245 /// Number of days in the revision interval.
246 int m_nDays;
247 /// Number of weeks in the revision interval.
248 int m_nWeeks;
249 /// The starting date/time for the revision interval.
250 __time64_t m_minDate;
251 /// The ending date/time for the revision interval.
252 __time64_t m_maxDate;
253 /// The total number of commits (equals size of the m_parXXX arrays).
254 INT_PTR m_nTotalCommits;
255 /// The total number of file changes.
256 LONG m_nTotalFileChanges;
257 /// Holds the number of commits per unit and author.
258 IntervalDataMap m_commitsPerUnitAndAuthor;
260 IntervalDataMap m_LinesWPerUnitAndAuthor;
261 IntervalDataMap m_LinesWOPerUnitAndAuthor;
263 /// Holds the number of file changes per unit and author.
264 IntervalDataMap m_filechangesPerUnitAndAuthor;
265 /// First interval number (key) in the mappings.
266 int m_firstInterval;
267 /// Last interval number (key) in the mappings.
268 int m_lastInterval;
269 /// Mapping of total commits per author, access data via
270 AuthorDataMap m_commitsPerAuthor;
271 /// Mapping of Percentage Of Authorship per author
272 AuthorshipDataMap m_PercentageOfAuthorship;
274 LONG m_nTotalLinesInc;
275 LONG m_nTotalLinesDec;
276 LONG m_nTotalLinesNew;
277 LONG m_nTotalLinesDel;
279 /// The list of author names sorted based on commit count
280 /// (author with most commits is first in list).
281 std::list<tstring> m_authorNames;
282 /// unit names by week/month/quarter
283 std::map<LONG, tstring> m_unitNames;