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 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.
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.
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.
192 /// Updates the currently shown statistics page.
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);
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
;
227 CComboBox m_cGraphType
;
228 CSliderCtrl m_Skipper
;
229 BOOL m_bAuthorsCaseSensitive
;
230 BOOL m_bSortByCommitCount
;
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
;
242 CToolTipCtrl
* m_pToolTip
;
246 // ** Member variables holding the statistical data **
248 /// Number of days in the revision interval.
250 /// Number of weeks in the revision interval.
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.
270 /// Last interval number (key) in the mappings.
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
;