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.
22 #include "StandAloneDlg.h"
25 #include "UnicodeUtils.h"
28 #include "GitLogListBase.h"
34 * \ingroup TortoiseProc
35 * Helper class for drawing and then saving the drawing to a meta file (wmf)
37 class CMyMetaFileDC
: public CMetaFileDC
40 HGDIOBJ
SelectObject(HGDIOBJ hObject
)
42 return (hObject
!= NULL
) ? ::SelectObject(m_hDC
, hObject
) : NULL
;
47 * \ingroup TortoiseProc
48 * Helper dialog showing statistics gathered from the log messages shown in the
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:
55 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
56 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
57 * commits = m_commitsPerAuthor[author_name];
60 class CStatGraphDlg
: public CResizableStandAloneDialog
//CResizableStandAloneDialog
62 DECLARE_DYNAMIC(CStatGraphDlg
)
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
;
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;
97 /// The types of units used in the various graphs.
107 // Available next metrics
114 PercentageOfAuthorship
,
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
134 virtual void OnCancel();
136 virtual void DoDataExchange(CDataExchange
* pDX
);
137 virtual BOOL
OnInitDialog();
138 void ShowLabels(BOOL bShow
);
139 afx_msg
void OnCbnSelchangeGraphcombo();
140 afx_msg
void OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
141 afx_msg
void OnBnClickedStacked();
142 afx_msg
void OnNeedText(NMHDR
*pnmh
, LRESULT
*pResult
);
143 afx_msg
void OnBnClickedGraphbarbutton();
144 afx_msg
void OnBnClickedGraphbarstackedbutton();
145 afx_msg
void OnBnClickedGraphlinebutton();
146 afx_msg
void OnBnClickedGraphlinestackedbutton();
147 afx_msg
void OnBnClickedGraphpiebutton();
148 afx_msg
void OnFileSavestatgraphas();
149 afx_msg
void OnBnClickedFetchDiff();
150 DECLARE_MESSAGE_MAP()
152 // ** Member functions **
154 /// Updates the variables m_nWeeks, m_nDays and m_minDate
155 void UpdateWeekCount();
156 /// Returns the week-of-the-year for the given time.
157 int GetCalendarWeek(const CTime
& time
);
158 /// Parses the data given to the dialog and generates mappings with statistical data.
159 int GatherData(BOOL fetchdiff
= FALSE
, BOOL keepFetchedData
= FALSE
);
160 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
161 void FilterSkippedAuthors(std::list
<tstring
>& included_authors
, std::list
<tstring
>& skipped_authors
);
162 /// Shows the graph Percentage Of Authorship
163 void ShowPercentageOfAuthorship();
164 /// Shows the graph with commit counts per author.
165 void ShowCommitsByAuthor();
166 /// Shows the graph with commit counts per author and date.
167 void ShowByDate(int StringY
, int title
, IntervalDataMap
&data
);
168 /// Shows the initial statistics page.
171 /// Rolling Percentage Of Authorship of author to integer
172 int RollPercentageOfAuthorship(double it
);
174 /// Load list of drawing authors
175 template <class MAP
> void LoadListOfAuthors (MAP
&map
, bool reloadSkiper
= false, bool compare
= false);
177 // If we have other authors, count them and their commits.
179 void DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
);
182 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
183 /// Recalculates statistical data because the number and names of authors
184 /// can have changed. Also calls RedrawGraph().
185 void AuthorsCaseSensitiveChanged();
186 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
187 /// Calls RedrawGraph().
188 void SortModeChanged();
189 /// Clears the current graph and frees all data series.
191 /// Updates the currently shown statistics page.
194 /// PreShow Statistic function
195 bool PreViewStat(bool fShowLabels
);
196 /// PreShow Graphic function
197 MyGraphSeries
* PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
= NULL
);
198 /// Show Selected Static metric
199 void ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
= false);
202 int GetUnit(const CTime
& time
);
203 CStatGraphDlg::UnitType
GetUnitType();
204 CString
GetUnitString();
205 CString
GetUnitLabel(int unit
, CTime
&lasttime
);
207 void EnableDisableMenu();
209 void SaveGraph(CString sFilename
);
210 int GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
);
212 void StoreCurrentGraphType();
213 void ShowErrorMessage();
215 // init ruler & limit its range
216 void SetSkipper (bool reloadSkiper
);
218 //Load statistical queries
219 void LoadStatQueries(__in UINT curStr
, Metrics loadMetric
, bool setDef
= false);
221 //Considers coefficient contribution author
222 double CoeffContribution(int distFromEnd
);
224 CPtrArray m_graphDataArray
;
226 CComboBox m_cGraphType
;
227 CSliderCtrl m_Skipper
;
228 BOOL m_bAuthorsCaseSensitive
;
229 BOOL m_bSortByCommitCount
;
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
;
243 // ** Member variables holding the statistical data **
245 /// Number of days in the revision interval.
247 /// Number of weeks in the revision interval.
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.
267 /// Last interval number (key) in the mappings.
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
;