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.
22 #include "StandAloneDlg.h"
25 #include "UnicodeUtils.h"
26 #include "GitLogListBase.h"
29 * \ingroup TortoiseProc
30 * Helper class for drawing and then saving the drawing to a meta file (wmf)
32 class CMyMetaFileDC
: public CMetaFileDC
35 HGDIOBJ
SelectObject(HGDIOBJ hObject
)
37 return (hObject
!= nullptr) ? ::SelectObject(m_hDC
, hObject
) : nullptr;
42 * \ingroup TortoiseProc
43 * Helper dialog showing statistics gathered from the log messages shown in the
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:
50 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
51 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
52 * commits = m_commitsPerAuthor[author_name];
55 class CStatGraphDlg
: public CResizableStandAloneDialog
//CResizableStandAloneDialog
57 DECLARE_DYNAMIC(CStatGraphDlg
)
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
;
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;
92 /// The types of units used in the various graphs.
102 // Available next metrics
109 PercentageOfAuthorship
,
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.
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.
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.
187 /// Updates the currently shown statistics page.
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
;
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;
240 // ** Member variables holding the statistical data **
242 /// Number of days in the revision interval.
244 /// Number of weeks in the revision interval.
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
;