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_lineInc
;
76 CDWordArray m_lineDec
;
77 CDWordArray m_lineNew
;
78 CDWordArray m_lineDel
;
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 typedef std::map
<int, std::map
<tstring
, LONG
> > IntervalDataMap
;
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 typedef std::map
<tstring
, LONG
> AuthorDataMap
;
124 /// The mapping type used to store data per Percentage Of Authorship
125 typedef std::map
<tstring
, double> AuthorshipDataMap
;
127 // *** Re-implemented member functions from CDialog
129 virtual void OnCancel();
131 virtual void DoDataExchange(CDataExchange
* pDX
);
132 virtual BOOL
OnInitDialog();
133 void ShowLabels(BOOL bShow
);
134 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
135 afx_msg
void OnCbnSelchangeGraphcombo();
136 afx_msg
void OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
137 afx_msg
void OnBnClickedStacked();
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 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
);
156 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
157 void FilterSkippedAuthors(std::list
<tstring
>& included_authors
, std::list
<tstring
>& 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
<tstring
> &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);
198 int GetUnit(const CTime
& time
);
199 CStatGraphDlg::UnitType
GetUnitType();
200 CString
GetUnitString();
201 CString
GetUnitLabel(int unit
, CTime
&lasttime
);
203 void EnableDisableMenu();
205 void SaveGraph(CString sFilename
);
206 int GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
);
208 void StoreCurrentGraphType();
209 void ShowErrorMessage();
211 // init ruler & limit its range
212 void SetSkipper (bool reloadSkiper
);
214 //Load statistical queries
215 void LoadStatQueries(__in UINT curStr
, Metrics loadMetric
, bool setDef
= false);
217 //Considers coefficient contribution author
218 double CoeffContribution(int distFromEnd
);
220 CPtrArray m_graphDataArray
;
222 CComboBox m_cGraphType
;
223 CSliderCtrl m_Skipper
;
224 BOOL m_bAuthorsCaseSensitive
;
225 BOOL m_bSortByCommitCount
;
228 CMFCButton m_btnGraphBar
;
229 CMFCButton m_btnGraphBarStacked
;
230 CMFCButton m_btnGraphLine
;
231 CMFCButton m_btnGraphLineStacked
;
232 CMFCButton m_btnGraphPie
;
234 MyGraph::GraphType m_GraphType
;
237 CToolTipCtrl
* m_pToolTip
;
241 // ** Member variables holding the statistical data **
243 /// Number of days in the revision interval.
245 /// Number of weeks in the revision interval.
247 /// The starting date/time for the revision interval.
248 __time64_t m_minDate
;
249 /// The ending date/time for the revision interval.
250 __time64_t m_maxDate
;
251 /// The total number of commits (equals size of the m_parXXX arrays).
252 INT_PTR m_nTotalCommits
;
253 /// The total number of file changes.
254 LONG m_nTotalFileChanges
;
255 /// Holds the number of commits per unit and author.
256 IntervalDataMap m_commitsPerUnitAndAuthor
;
258 IntervalDataMap m_LinesWPerUnitAndAuthor
;
259 IntervalDataMap m_LinesWOPerUnitAndAuthor
;
261 /// Holds the number of file changes per unit and author.
262 IntervalDataMap m_filechangesPerUnitAndAuthor
;
263 /// First interval number (key) in the mappings.
265 /// Last interval number (key) in the mappings.
267 /// Mapping of total commits per author, access data via
268 AuthorDataMap m_commitsPerAuthor
;
269 /// Mapping of Percentage Of Authorship per author
270 AuthorshipDataMap m_PercentageOfAuthorship
;
272 LONG m_nTotalLinesInc
;
273 LONG m_nTotalLinesDec
;
274 LONG m_nTotalLinesNew
;
275 LONG m_nTotalLinesDel
;
277 /// The list of author names sorted based on commit count
278 /// (author with most commits is first in list).
279 std::list
<tstring
> m_authorNames
;
280 /// unit names by week/month/quarter
281 std::map
<LONG
, tstring
> m_unitNames
;