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