RebaseDlg: Correctly remember commits for rewriting on Squash after (Edit|Squash...
[TortoiseGit.git] / src / TortoiseProc / StatGraphDlg.h
blob84709ba4444e3ef6e973833cd7e55154397c1042
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2011-2013, 2015-2018, 2021-2023 - 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"
26 #include "GitLogListBase.h"
28 /**
29 * \ingroup TortoiseProc
30 * Helper class for drawing and then saving the drawing to a meta file (wmf)
32 class CMyMetaFileDC : public CMetaFileDC
34 public:
35 HGDIOBJ SelectObject(HGDIOBJ hObject)
37 return (hObject != nullptr) ? ::SelectObject(m_hDC, hObject) : nullptr;
41 /**
42 * \ingroup TortoiseProc
43 * Helper dialog showing statistics gathered from the log messages shown in the
44 * log dialog.
46 * The function GatherData() collects statistical information and stores it
47 * in the corresponding member variables. You can access the data as shown in
48 * the following examples:
49 * @code
50 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
51 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
52 * commits = m_commitsPerAuthor[author_name];
53 * @endcode
55 class CStatGraphDlg : public CResizableStandAloneDialog//CResizableStandAloneDialog
57 DECLARE_DYNAMIC(CStatGraphDlg)
59 public:
60 CStatGraphDlg(CWnd* pParent = nullptr);
61 virtual ~CStatGraphDlg();
63 enum { IDD = IDD_STATGRAPH };
65 std::vector<GitRevLoglist*> m_ShowList;
67 // Data passed from the caller of the dialog.
68 CDWordArray m_parDates;
69 CDWordArray m_parFileChanges;
70 CDWordArray m_parFileChanges2;
71 CDWordArray m_lineInc;
72 CDWordArray m_lineInc2;
73 CDWordArray m_lineDec;
74 CDWordArray m_lineDec2;
75 CDWordArray m_lineNew;
76 CDWordArray m_lineNew2;
77 CDWordArray m_lineDel;
78 CDWordArray m_lineDel2;
80 CStringArray m_parAuthors;
81 CTGitPath m_path;
83 protected:
85 // ** Constants **
86 static const long int m_SecondsInWeek = 604800; // ... a week has 604800 seconds
87 static const long int m_SecondsInDay = 86400; // ... a day has 86400.0 seconds
88 static const int m_CoeffAuthorShip = 2;
90 // ** Data types **
92 /// The types of units used in the various graphs.
93 enum UnitType
95 Days,
96 Weeks,
97 Months,
98 Quarters,
99 Years
102 // Available next metrics
103 enum Metrics
105 TextStatStart,
106 AllStat,
107 TextStatEnd,
108 GraphicStatStart,
109 PercentageOfAuthorship,
110 CommitsByAuthor,
111 CommitsByDate,
112 LinesWByDate,
113 LinesWOByDate,
114 GraphicStatEnd,
117 //TODO: try substitute map to hash_map
118 /// The mapping type used to store data per interval/week and author.
119 using IntervalDataMap = std::map<int, std::map<std::wstring, LONG>>;
121 //TODO: try substitute few Maps to one map, that store needs informations about Authors
122 /// The mapping type used to store data per author.
123 using AuthorDataMap = std::map<std::wstring, LONG>;
124 /// The mapping type used to store data per Percentage Of Authorship
125 using AuthorshipDataMap = std::map<std::wstring, double>;
127 // *** Re-implemented member functions from CDialog
128 void OnOK() override;
129 void OnCancel() override;
131 void DoDataExchange(CDataExchange* pDX) override;
132 BOOL OnInitDialog() override;
133 void ShowLabels(BOOL bShow);
134 afx_msg void OnCbnSelchangeGraphcombo();
135 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
136 afx_msg void OnNeedText(NMHDR *pnmh, LRESULT *pResult);
137 afx_msg void OnBnClickedGraphbarbutton();
138 afx_msg void OnBnClickedGraphbarstackedbutton();
139 afx_msg void OnBnClickedGraphlinebutton();
140 afx_msg void OnBnClickedGraphlinestackedbutton();
141 afx_msg void OnBnClickedGraphpiebutton();
142 afx_msg void OnFileSavestatgraphas();
143 afx_msg void OnBnClickedFetchDiff();
144 afx_msg void OnBnClickedCommitternames();
145 afx_msg void OnBnClickedCommitdates();
146 DECLARE_MESSAGE_MAP()
148 // ** Member functions **
150 /// Updates the variables m_nWeeks, m_nDays and m_minDate
151 void UpdateWeekCount();
152 /// Returns the week-of-the-year for the given time.
153 int GetCalendarWeek(const CTime& time);
154 /// Parses the data given to the dialog and generates mappings with statistical data.
155 int GatherData(BOOL fetchdiff = FALSE, BOOL keepFetchedData = FALSE);
156 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
157 void FilterSkippedAuthors(std::list<std::wstring>& included_authors, std::list<std::wstring>& skipped_authors);
158 /// Shows the graph Percentage Of Authorship
159 void ShowPercentageOfAuthorship();
160 /// Shows the graph with commit counts per author.
161 void ShowCommitsByAuthor();
162 /// Shows the graph with commit counts per author and date.
163 void ShowByDate(int StringY, int title, IntervalDataMap &data);
164 /// Shows the initial statistics page.
165 void ShowStats();
167 /// Rolling Percentage Of Authorship of author to integer
168 int RollPercentageOfAuthorship(double it);
170 /// Load list of drawing authors
171 template <class MAP> void LoadListOfAuthors (MAP &map, bool reloadSkiper = false, bool compare = false);
173 // If we have other authors, count them and their commits.
174 template <class MAP>
175 void DrawOthers(const std::list<std::wstring>& others, MyGraphSeries* graphData, MAP& map);
178 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
179 /// Recalculates statistical data because the number and names of authors
180 /// can have changed. Also calls RedrawGraph().
181 void AuthorsCaseSensitiveChanged();
182 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
183 /// Calls RedrawGraph().
184 void SortModeChanged();
185 /// Clears the current graph and frees all data series.
186 void ClearGraph();
187 /// Updates the currently shown statistics page.
188 void RedrawGraph();
190 /// PreShow Statistic function
191 bool PreViewStat(bool fShowLabels);
192 /// PreShow Graphic function
193 MyGraphSeries * PreViewGraph(__in UINT GraphTitle, __in UINT YAxisLabel, __in UINT XAxisLabel = NULL);
194 /// Show Selected Static metric
195 void ShowSelectStat(Metrics SelectedMetric, bool reloadSkiper = false);
197 int GetUnit(const CTime& time);
198 CStatGraphDlg::UnitType GetUnitType();
199 CString GetUnitString();
200 CString GetUnitLabel(int unit, CTime &lasttime);
202 void EnableDisableMenu();
204 void SaveGraph(CString sFilename);
205 int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
207 void StoreCurrentGraphType();
208 void ShowErrorMessage();
210 // init ruler & limit its range
211 void SetSkipper (bool reloadSkiper);
213 //Load statistical queries
214 void LoadStatQueries(__in UINT curStr, Metrics loadMetric, bool setDef = false);
216 //Considers coefficient contribution author
217 double CoeffContribution(int distFromEnd);
219 CPtrArray m_graphDataArray;
220 MyGraph m_graph;
221 CComboBox m_cGraphType;
222 CSliderCtrl m_Skipper;
223 BOOL m_bAuthorsCaseSensitive;
224 BOOL m_bSortByCommitCount;
225 BOOL m_bUseCommitterNames;
226 BOOL m_bUseCommitDates;
227 bool m_bDiffFetched = false;
229 CMFCButton m_btnGraphBar;
230 CMFCButton m_btnGraphBarStacked;
231 CMFCButton m_btnGraphLine;
232 CMFCButton m_btnGraphLineStacked;
233 CMFCButton m_btnGraphPie;
235 MyGraph::GraphType m_GraphType = MyGraph::GraphType::Bar;
236 bool m_bStacked = false;
238 int m_langOrder = 0;
240 // ** Member variables holding the statistical data **
242 /// Number of days in the revision interval.
243 int m_nDays = -1;
244 /// Number of weeks in the revision interval.
245 int m_nWeeks = -1;
246 /// The starting date/time for the revision interval.
247 __time64_t m_minDate = 0;
248 /// The ending date/time for the revision interval.
249 __time64_t m_maxDate = 0;
250 /// The total number of commits (equals size of the m_parXXX arrays).
251 INT_PTR m_nTotalCommits = 0;
252 /// The total number of file changes.
253 LONG m_nTotalFileChanges = 0;
254 /// Holds the number of commits per unit and author.
255 IntervalDataMap m_commitsPerUnitAndAuthor;
257 IntervalDataMap m_LinesWPerUnitAndAuthor;
258 IntervalDataMap m_LinesWOPerUnitAndAuthor;
260 /// Holds the number of file changes per unit and author.
261 IntervalDataMap m_filechangesPerUnitAndAuthor;
262 /// First interval number (key) in the mappings.
263 int m_firstInterval = 0;
264 /// Last interval number (key) in the mappings.
265 int m_lastInterval = 0;
266 /// Mapping of total commits per author, access data via
267 AuthorDataMap m_commitsPerAuthor;
268 /// Mapping of Percentage Of Authorship per author
269 AuthorshipDataMap m_PercentageOfAuthorship;
271 LONG m_nTotalLinesInc = 0;
272 LONG m_nTotalLinesDec = 0;
273 LONG m_nTotalLinesNew = 0;
274 LONG m_nTotalLinesDel = 0;
276 /// The list of author names sorted based on commit count
277 /// (author with most commits is first in list).
278 std::list<std::wstring> m_authorNames;
279 /// unit names by week/month/quarter
280 std::map<LONG, std::wstring> m_unitNames;