1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "StandAloneDlg.h"
24 #include "UnicodeUtils.h"
32 * \ingroup TortoiseProc
33 * Helper class for drawing and then saving the drawing to a meta file (wmf)
35 class CMyMetaFileDC
: public CMetaFileDC
38 HGDIOBJ
SelectObject(HGDIOBJ hObject
)
40 return (hObject
!= NULL
) ? ::SelectObject(m_hDC
, hObject
) : NULL
;
45 * \ingroup TortoiseProc
46 * Helper dialog showing statistics gathered from the log messages shown in the
49 * The function GatherData() collects statistical information and stores it
50 * in the corresponding member variables. You can access the data as shown in
51 * the following examples:
53 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
54 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
55 * commits = m_commitsPerAuthor[author_name];
58 class CStatGraphDlg
: public CResizableStandAloneDialog
//CResizableStandAloneDialog
60 DECLARE_DYNAMIC(CStatGraphDlg
)
63 CStatGraphDlg(CWnd
* pParent
= NULL
);
64 virtual ~CStatGraphDlg();
66 enum { IDD
= IDD_STATGRAPH
};
68 // Data passed from the caller of the dialog.
69 CDWordArray
* m_parDates
;
70 CDWordArray
* m_parFileChanges
;
71 CStringArray
* m_parAuthors
;
77 static const long int m_SecondsInWeek
= 604800; // ... a week has 604800 seconds
78 static const long int m_SecondsInDay
= 86400; // ... a day has 86400.0 seconds
79 static const int m_CoeffAuthorShip
= 2;
83 /// The types of units used in the various graphs.
93 // Available next metrics
100 PercentageOfAuthorship
,
106 //TODO: try substitute map to hash_map
107 /// The mapping type used to store data per interval/week and author.
108 typedef std::map
<int, std::map
<tstring
, LONG
> > IntervalDataMap
;
110 //TODO: try substitute few Maps to one map, that store needs informations about Authors
111 /// The mapping type used to store data per author.
112 typedef std::map
<tstring
, LONG
> AuthorDataMap
;
113 /// The mapping type used to store data per Percentage Of Authorship
114 typedef std::map
<tstring
, double> AuthorshipDataMap
;
116 // *** Re-implemented member functions from CDialog
118 virtual void OnCancel();
120 virtual void DoDataExchange(CDataExchange
* pDX
);
121 virtual BOOL
OnInitDialog();
122 void ShowLabels(BOOL bShow
);
123 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
124 afx_msg
void OnCbnSelchangeGraphcombo();
125 afx_msg
void OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
126 afx_msg
void OnBnClickedStacked();
127 afx_msg
void OnNeedText(NMHDR
*pnmh
, LRESULT
*pResult
);
128 afx_msg
void OnBnClickedGraphbarbutton();
129 afx_msg
void OnBnClickedGraphbarstackedbutton();
130 afx_msg
void OnBnClickedGraphlinebutton();
131 afx_msg
void OnBnClickedGraphlinestackedbutton();
132 afx_msg
void OnBnClickedGraphpiebutton();
133 afx_msg
void OnFileSavestatgraphas();
134 DECLARE_MESSAGE_MAP()
136 // ** Member functions **
138 /// Updates the variables m_nWeeks, m_nDays and m_minDate
139 void UpdateWeekCount();
140 /// Returns the week-of-the-year for the given time.
141 int GetCalendarWeek(const CTime
& time
);
142 /// Parses the data given to the dialog and generates mappings with statistical data.
144 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
145 void FilterSkippedAuthors(std::list
<tstring
>& included_authors
, std::list
<tstring
>& skipped_authors
);
146 /// Shows the graph Percentage Of Authorship
147 void ShowPercentageOfAuthorship();
148 /// Shows the graph with commit counts per author.
149 void ShowCommitsByAuthor();
150 /// Shows the graph with commit counts per author and date.
151 void ShowCommitsByDate();
152 /// Shows the initial statistics page.
155 /// Rolling Percentage Of Authorship of author to integer
156 int RollPercentageOfAuthorship(double it
);
158 /// Load list of drawing authors
159 template <class MAP
> void LoadListOfAuthors (MAP
&map
, bool reloadSkiper
= false, bool compare
= false);
161 // If we have other authors, count them and their commits.
163 void DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
);
166 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
167 /// Recalculates statistical data because the number and names of authors
168 /// can have changed. Also calls RedrawGraph().
169 void AuthorsCaseSensitiveChanged();
170 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
171 /// Calls RedrawGraph().
172 void SortModeChanged();
173 /// Clears the current graph and frees all data series.
175 /// Updates the currently shown statistics page.
178 /// PreShow Statistic function
179 bool PreViewStat(bool fShowLabels
);
180 /// PreShow Graphic function
181 MyGraphSeries
* PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
= NULL
);
182 /// Show Selected Static metric
183 void ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
= false);
186 int GetUnit(const CTime
& time
);
187 CStatGraphDlg::UnitType
GetUnitType();
188 CString
GetUnitString();
189 CString
GetUnitLabel(int unit
, CTime
&lasttime
);
191 void EnableDisableMenu();
193 void SaveGraph(CString sFilename
);
194 int GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
);
196 void StoreCurrentGraphType();
197 void ShowErrorMessage();
199 // init ruler & limit its range
200 void SetSkipper (bool reloadSkiper
);
202 //Load statistical queries
203 void LoadStatQueries(__in UINT curStr
, Metrics loadMetric
, bool setDef
= false);
205 //Considers coefficient contribution author
206 double CoeffContribution(int distFromEnd
);
208 CPtrArray m_graphDataArray
;
210 CComboBox m_cGraphType
;
211 CSliderCtrl m_Skipper
;
212 BOOL m_bAuthorsCaseSensitive
;
213 BOOL m_bSortByCommitCount
;
215 CMFCButton m_btnGraphBar
;
216 CMFCButton m_btnGraphBarStacked
;
217 CMFCButton m_btnGraphLine
;
218 CMFCButton m_btnGraphLineStacked
;
219 CMFCButton m_btnGraphPie
;
221 MyGraph::GraphType m_GraphType
;
224 CToolTipCtrl
* m_pToolTip
;
228 // ** Member variables holding the statistical data **
230 /// Number of days in the revision interval.
232 /// Number of weeks in the revision interval.
234 /// The starting date/time for the revision interval.
235 __time64_t m_minDate
;
236 /// The ending date/time for the revision interval.
237 __time64_t m_maxDate
;
238 /// The total number of commits (equals size of the m_parXXX arrays).
239 INT_PTR m_nTotalCommits
;
240 /// The total number of file changes.
241 LONG m_nTotalFileChanges
;
242 /// Holds the number of commits per unit and author.
243 IntervalDataMap m_commitsPerUnitAndAuthor
;
244 /// Holds the number of file changes per unit and author.
245 IntervalDataMap m_filechangesPerUnitAndAuthor
;
246 /// First interval number (key) in the mappings.
248 /// Last interval number (key) in the mappings.
250 /// Mapping of total commits per author, access data via
251 AuthorDataMap m_commitsPerAuthor
;
252 /// Mapping of Percentage Of Authorship per author
253 AuthorshipDataMap m_PercentageOfAuthorship
;
255 /// The list of author names sorted based on commit count
256 /// (author with most commits is first in list).
257 std::list
<tstring
> m_authorNames
;
258 /// unit names by week/month/quarter
259 std::map
<LONG
, tstring
> m_unitNames
;