1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-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.
21 #include "TortoiseProc.h"
22 #include "StatGraphDlg.h"
25 #include "StringUtils.h"
26 #include "PathUtils.h"
27 #include "MessageBox.h"
29 #include "FormatMessageWrapper.h"
30 #include "SysProgressDlg.h"
39 using namespace Gdiplus
;
41 // BinaryPredicate for comparing authors based on their commit count
42 template<class DataType
>
43 class MoreCommitsThan
: public std::binary_function
<tstring
, tstring
, bool> {
45 typedef std::map
<tstring
, DataType
> MapType
;
46 MoreCommitsThan(MapType
&author_commits
) : m_authorCommits(author_commits
) {}
48 bool operator()(const tstring
& lhs
, const tstring
& rhs
) {
49 return (m_authorCommits
)[lhs
] > (m_authorCommits
)[rhs
];
53 MapType
&m_authorCommits
;
57 IMPLEMENT_DYNAMIC(CStatGraphDlg
, CResizableStandAloneDialog
)
58 CStatGraphDlg::CStatGraphDlg(CWnd
* pParent
/*=NULL*/)
59 : CResizableStandAloneDialog(CStatGraphDlg::IDD
, pParent
)
61 , m_GraphType(MyGraph::Bar
)
62 , m_bAuthorsCaseSensitive(TRUE
)
63 , m_bSortByCommitCount(TRUE
)
74 , m_bDiffFetched(FALSE
)
78 , m_nTotalFileChanges(0)
83 CStatGraphDlg::~CStatGraphDlg()
89 void CStatGraphDlg::OnOK() {
90 StoreCurrentGraphType();
94 void CStatGraphDlg::OnCancel() {
95 StoreCurrentGraphType();
99 void CStatGraphDlg::DoDataExchange(CDataExchange
* pDX
)
101 CResizableStandAloneDialog::DoDataExchange(pDX
);
102 DDX_Control(pDX
, IDC_GRAPH
, m_graph
);
103 DDX_Control(pDX
, IDC_GRAPHCOMBO
, m_cGraphType
);
104 DDX_Control(pDX
, IDC_SKIPPER
, m_Skipper
);
105 DDX_Check(pDX
, IDC_AUTHORSCASESENSITIVE
, m_bAuthorsCaseSensitive
);
106 DDX_Check(pDX
, IDC_SORTBYCOMMITCOUNT
, m_bSortByCommitCount
);
107 DDX_Control(pDX
, IDC_GRAPHBARBUTTON
, m_btnGraphBar
);
108 DDX_Control(pDX
, IDC_GRAPHBARSTACKEDBUTTON
, m_btnGraphBarStacked
);
109 DDX_Control(pDX
, IDC_GRAPHLINEBUTTON
, m_btnGraphLine
);
110 DDX_Control(pDX
, IDC_GRAPHLINESTACKEDBUTTON
, m_btnGraphLineStacked
);
111 DDX_Control(pDX
, IDC_GRAPHPIEBUTTON
, m_btnGraphPie
);
115 BEGIN_MESSAGE_MAP(CStatGraphDlg
, CResizableStandAloneDialog
)
116 ON_CBN_SELCHANGE(IDC_GRAPHCOMBO
, OnCbnSelchangeGraphcombo
)
118 ON_NOTIFY(TTN_NEEDTEXT
, NULL
, OnNeedText
)
119 ON_BN_CLICKED(IDC_AUTHORSCASESENSITIVE
, &CStatGraphDlg::AuthorsCaseSensitiveChanged
)
120 ON_BN_CLICKED(IDC_SORTBYCOMMITCOUNT
, &CStatGraphDlg::SortModeChanged
)
121 ON_BN_CLICKED(IDC_GRAPHBARBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarbutton
)
122 ON_BN_CLICKED(IDC_GRAPHBARSTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarstackedbutton
)
123 ON_BN_CLICKED(IDC_GRAPHLINEBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinebutton
)
124 ON_BN_CLICKED(IDC_GRAPHLINESTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinestackedbutton
)
125 ON_BN_CLICKED(IDC_GRAPHPIEBUTTON
, &CStatGraphDlg::OnBnClickedGraphpiebutton
)
126 ON_COMMAND(ID_FILE_SAVESTATGRAPHAS
, &CStatGraphDlg::OnFileSavestatgraphas
)
127 ON_BN_CLICKED(IDC_CALC_DIFF
, &CStatGraphDlg::OnBnClickedFetchDiff
)
130 void CStatGraphDlg::LoadStatQueries (__in UINT curStr
, Metrics loadMetric
, bool setDef
/* = false */)
133 temp
.LoadString(curStr
);
134 int sel
= m_cGraphType
.AddString(temp
);
135 m_cGraphType
.SetItemData(sel
, loadMetric
);
137 if (setDef
) m_cGraphType
.SetCurSel(sel
);
140 void CStatGraphDlg::SetSkipper (bool reloadSkiper
)
142 // We need to limit the number of authors due to GUI resource limitation.
143 // However, since author #251 will properly have < 1000th of the commits,
144 // the resolution limit of the screen will already not allow for displaying
145 // it in a reasonable way
147 int max_authors_count
= max(1, (int)min(m_authorNames
.size(), 250) );
148 m_Skipper
.SetRange (1, max_authors_count
);
149 m_Skipper
.SetPageSize(5);
152 m_Skipper
.SetPos (max_authors_count
);
155 BOOL
CStatGraphDlg::OnInitDialog()
157 CResizableStandAloneDialog::OnInitDialog();
159 // gather statistics data, only needs to be updated when the checkbox with
160 // the case sensitivity of author names is changed
163 m_pToolTip
= new CToolTipCtrl
;
164 if (m_pToolTip
->Create(this))
166 m_pToolTip
->AddTool(&m_btnGraphPie
, IDS_STATGRAPH_PIEBUTTON_TT
);
167 m_pToolTip
->AddTool(&m_btnGraphLineStacked
, IDS_STATGRAPH_LINESTACKEDBUTTON_TT
);
168 m_pToolTip
->AddTool(&m_btnGraphLine
, IDS_STATGRAPH_LINEBUTTON_TT
);
169 m_pToolTip
->AddTool(&m_btnGraphBarStacked
, IDS_STATGRAPH_BARSTACKEDBUTTON_TT
);
170 m_pToolTip
->AddTool(&m_btnGraphBar
, IDS_STATGRAPH_BARBUTTON_TT
);
172 m_pToolTip
->Activate(TRUE
);
175 m_bAuthorsCaseSensitive
= DWORD(CRegDWORD(_T("Software\\TortoiseGit\\StatAuthorsCaseSensitive")));
176 m_bSortByCommitCount
= DWORD(CRegDWORD(_T("Software\\TortoiseGit\\StatSortByCommitCount")));
179 //Load statistical queries
180 LoadStatQueries(IDS_STATGRAPH_STATS
, AllStat
, true);
181 LoadStatQueries(IDS_STATGRAPH_COMMITSBYDATE
, CommitsByDate
);
182 LoadStatQueries(IDS_STATGRAPH_COMMITSBYAUTHOR
, CommitsByAuthor
);
183 LoadStatQueries(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
, PercentageOfAuthorship
);
184 LoadStatQueries(IDS_STATGRAPH_LINES_BYDATE_W
, LinesWByDate
);
185 LoadStatQueries(IDS_STATGRAPH_LINES_BYDATE_WO
, LinesWOByDate
);
187 // set the dialog title to "Statistics - path/to/whatever/we/show/the/statistics/for"
189 GetWindowText(sTitle
);
190 if (m_path
.IsEmpty())
191 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sTitle
);
193 CAppUtils::SetWindowTitle(m_hWnd
, m_path
.GetUIPathString(), sTitle
);
195 m_btnGraphBar
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBAR
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
196 m_btnGraphBar
.SizeToContent();
197 m_btnGraphBar
.Invalidate();
198 m_btnGraphBarStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBARSTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
199 m_btnGraphBarStacked
.SizeToContent();
200 m_btnGraphBarStacked
.Invalidate();
201 m_btnGraphLine
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
202 m_btnGraphLine
.SizeToContent();
203 m_btnGraphLine
.Invalidate();
204 m_btnGraphLineStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINESTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
205 m_btnGraphLineStacked
.SizeToContent();
206 m_btnGraphLineStacked
.Invalidate();
207 m_btnGraphPie
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHPIE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
208 m_btnGraphPie
.SizeToContent();
209 m_btnGraphPie
.Invalidate();
211 AddAnchor(IDC_GRAPHTYPELABEL
, TOP_LEFT
);
212 AddAnchor(IDC_GRAPH
, TOP_LEFT
, BOTTOM_RIGHT
);
213 AddAnchor(IDC_GRAPHCOMBO
, TOP_LEFT
, TOP_RIGHT
);
215 AddAnchor(IDC_NUMWEEK
, TOP_LEFT
);
216 AddAnchor(IDC_NUMWEEKVALUE
, TOP_RIGHT
);
217 AddAnchor(IDC_NUMAUTHOR
, TOP_LEFT
);
218 AddAnchor(IDC_NUMAUTHORVALUE
, TOP_RIGHT
);
219 AddAnchor(IDC_NUMCOMMITS
, TOP_LEFT
);
220 AddAnchor(IDC_NUMCOMMITSVALUE
, TOP_RIGHT
);
221 AddAnchor(IDC_NUMFILECHANGES
, TOP_LEFT
);
222 AddAnchor(IDC_NUMFILECHANGESVALUE
, TOP_RIGHT
);
224 AddAnchor(IDC_TOTAL_LINE_WITHOUT_NEW_DEL
, TOP_LEFT
);
225 AddAnchor(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
, TOP_RIGHT
);
226 AddAnchor(IDC_TOTAL_LINE_WITH_NEW_DEL
, TOP_LEFT
);
227 AddAnchor(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
, TOP_RIGHT
);
229 AddAnchor(IDC_CALC_DIFF
, TOP_RIGHT
);
231 AddAnchor(IDC_AVG
, TOP_RIGHT
);
232 AddAnchor(IDC_MIN
, TOP_RIGHT
);
233 AddAnchor(IDC_MAX
, TOP_RIGHT
);
234 AddAnchor(IDC_COMMITSEACHWEEK
, TOP_LEFT
);
235 AddAnchor(IDC_MOSTACTIVEAUTHOR
, TOP_LEFT
);
236 AddAnchor(IDC_LEASTACTIVEAUTHOR
, TOP_LEFT
);
237 AddAnchor(IDC_MOSTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
238 AddAnchor(IDC_LEASTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
239 AddAnchor(IDC_FILECHANGESEACHWEEK
, TOP_LEFT
);
240 AddAnchor(IDC_COMMITSEACHWEEKAVG
, TOP_RIGHT
);
241 AddAnchor(IDC_COMMITSEACHWEEKMIN
, TOP_RIGHT
);
242 AddAnchor(IDC_COMMITSEACHWEEKMAX
, TOP_RIGHT
);
243 AddAnchor(IDC_MOSTACTIVEAUTHORAVG
, TOP_RIGHT
);
244 AddAnchor(IDC_MOSTACTIVEAUTHORMIN
, TOP_RIGHT
);
245 AddAnchor(IDC_MOSTACTIVEAUTHORMAX
, TOP_RIGHT
);
246 AddAnchor(IDC_LEASTACTIVEAUTHORAVG
, TOP_RIGHT
);
247 AddAnchor(IDC_LEASTACTIVEAUTHORMIN
, TOP_RIGHT
);
248 AddAnchor(IDC_LEASTACTIVEAUTHORMAX
, TOP_RIGHT
);
249 AddAnchor(IDC_FILECHANGESEACHWEEKAVG
, TOP_RIGHT
);
250 AddAnchor(IDC_FILECHANGESEACHWEEKMIN
, TOP_RIGHT
);
251 AddAnchor(IDC_FILECHANGESEACHWEEKMAX
, TOP_RIGHT
);
253 AddAnchor(IDC_GRAPHBARBUTTON
, BOTTOM_RIGHT
);
254 AddAnchor(IDC_GRAPHBARSTACKEDBUTTON
, BOTTOM_RIGHT
);
255 AddAnchor(IDC_GRAPHLINEBUTTON
, BOTTOM_RIGHT
);
256 AddAnchor(IDC_GRAPHLINESTACKEDBUTTON
, BOTTOM_RIGHT
);
257 AddAnchor(IDC_GRAPHPIEBUTTON
, BOTTOM_RIGHT
);
259 AddAnchor(IDC_AUTHORSCASESENSITIVE
, BOTTOM_LEFT
);
260 AddAnchor(IDC_SORTBYCOMMITCOUNT
, BOTTOM_LEFT
);
261 AddAnchor(IDC_SKIPPER
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
262 AddAnchor(IDC_SKIPPERLABEL
, BOTTOM_LEFT
);
263 AddAnchor(IDOK
, BOTTOM_RIGHT
);
264 EnableSaveRestore(_T("StatGraphDlg"));
266 // set the min/max values on the skipper
269 // we use a stats page encoding here, 0 stands for the statistics dialog
270 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseGit\\LastViewedStatsPage"), 0);
272 // open last viewed statistics page as first page
273 int graphtype
= lastStatsPage
/ 10;
274 for (int i
= 0; i
< m_cGraphType
.GetCount(); i
++)
276 if ((int)m_cGraphType
.GetItemData(i
) == graphtype
)
278 m_cGraphType
.SetCurSel(i
);
283 OnCbnSelchangeGraphcombo();
285 int statspage
= lastStatsPage
% 10;
288 m_GraphType
= MyGraph::Bar
;
292 m_GraphType
= MyGraph::Bar
;
296 m_GraphType
= MyGraph::Line
;
300 m_GraphType
= MyGraph::Line
;
304 m_GraphType
= MyGraph::PieChart
;
307 default : return TRUE
;
310 LCID m_locale
= MAKELCID((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
)), SORT_DEFAULT
);
312 bool bUseSystemLocale
= !!(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
);
313 LCID locale
= bUseSystemLocale
? MAKELCID(MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), SORT_DEFAULT
) : m_locale
;
316 memset(langBuf
, 0, sizeof(langBuf
));
317 GetLocaleInfo(locale
, LOCALE_IDATE
, langBuf
, _countof(langBuf
));
319 m_langOrder
= _ttoi(langBuf
);
324 void CStatGraphDlg::ShowLabels(BOOL bShow
)
326 if (m_parAuthors
.IsEmpty() || m_parDates
.IsEmpty() || m_parFileChanges
.IsEmpty())
329 int nCmdShow
= bShow
? SW_SHOW
: SW_HIDE
;
331 GetDlgItem(IDC_GRAPH
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
332 GetDlgItem(IDC_NUMWEEK
)->ShowWindow(nCmdShow
);
333 GetDlgItem(IDC_NUMWEEKVALUE
)->ShowWindow(nCmdShow
);
334 GetDlgItem(IDC_NUMAUTHOR
)->ShowWindow(nCmdShow
);
335 GetDlgItem(IDC_NUMAUTHORVALUE
)->ShowWindow(nCmdShow
);
336 GetDlgItem(IDC_NUMCOMMITS
)->ShowWindow(nCmdShow
);
337 GetDlgItem(IDC_NUMCOMMITSVALUE
)->ShowWindow(nCmdShow
);
338 GetDlgItem(IDC_NUMFILECHANGES
)->ShowWindow(nCmdShow
);
339 GetDlgItem(IDC_NUMFILECHANGESVALUE
)->ShowWindow(nCmdShow
);
340 GetDlgItem(IDC_TOTAL_LINE_WITHOUT_NEW_DEL
)->ShowWindow(nCmdShow
);
341 GetDlgItem(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
)->ShowWindow(nCmdShow
);
342 GetDlgItem(IDC_TOTAL_LINE_WITH_NEW_DEL
)->ShowWindow(nCmdShow
);
343 GetDlgItem(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
)->ShowWindow(nCmdShow
);
344 GetDlgItem(IDC_CALC_DIFF
)->ShowWindow(nCmdShow
&& !m_bDiffFetched
);
346 GetDlgItem(IDC_AVG
)->ShowWindow(nCmdShow
);
347 GetDlgItem(IDC_MIN
)->ShowWindow(nCmdShow
);
348 GetDlgItem(IDC_MAX
)->ShowWindow(nCmdShow
);
349 GetDlgItem(IDC_COMMITSEACHWEEK
)->ShowWindow(nCmdShow
);
350 GetDlgItem(IDC_MOSTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
351 GetDlgItem(IDC_LEASTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
352 GetDlgItem(IDC_MOSTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
353 GetDlgItem(IDC_LEASTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
354 //GetDlgItem(IDC_FILECHANGESEACHWEEK)->ShowWindow(nCmdShow);
355 GetDlgItem(IDC_COMMITSEACHWEEKAVG
)->ShowWindow(nCmdShow
);
356 GetDlgItem(IDC_COMMITSEACHWEEKMIN
)->ShowWindow(nCmdShow
);
357 GetDlgItem(IDC_COMMITSEACHWEEKMAX
)->ShowWindow(nCmdShow
);
358 GetDlgItem(IDC_MOSTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
359 GetDlgItem(IDC_MOSTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
360 GetDlgItem(IDC_MOSTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
361 GetDlgItem(IDC_LEASTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
362 GetDlgItem(IDC_LEASTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
363 GetDlgItem(IDC_LEASTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
364 GetDlgItem(IDC_FILECHANGESEACHWEEKAVG
)->ShowWindow(nCmdShow
);
365 GetDlgItem(IDC_FILECHANGESEACHWEEKMIN
)->ShowWindow(nCmdShow
);
366 GetDlgItem(IDC_FILECHANGESEACHWEEKMAX
)->ShowWindow(nCmdShow
);
368 GetDlgItem(IDC_SORTBYCOMMITCOUNT
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
369 GetDlgItem(IDC_SKIPPER
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
370 GetDlgItem(IDC_SKIPPERLABEL
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
371 m_btnGraphBar
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
372 m_btnGraphBarStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
373 m_btnGraphLine
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
374 m_btnGraphLineStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
375 m_btnGraphPie
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
378 void CStatGraphDlg::UpdateWeekCount()
381 if (m_parDates
.IsEmpty())
384 // Already updated? No need to do it again.
388 // Determine first and last date in dates array
389 __time64_t min_date
= (__time64_t
)m_parDates
.GetAt(0);
390 __time64_t max_date
= min_date
;
391 INT_PTR count
= m_parDates
.GetCount();
392 for (INT_PTR i
=0; i
<count
; ++i
)
394 __time64_t d
= (__time64_t
)m_parDates
.GetAt(i
);
395 if (d
< min_date
) min_date
= d
;
396 else if (d
> max_date
) max_date
= d
;
399 // Store start date of the interval in the member variable m_minDate
400 m_minDate
= min_date
;
401 m_maxDate
= max_date
;
403 // How many weeks does the time period cover?
405 // Get time difference between start and end date
406 double secs
= _difftime64(max_date
, m_minDate
);
408 m_nWeeks
= (int)ceil(secs
/ (double) m_SecondsInWeek
);
409 m_nDays
= (int)ceil(secs
/ (double) m_SecondsInDay
);
412 int CStatGraphDlg::GetCalendarWeek(const CTime
& time
)
415 // the calculation of the calendar week is wrong if DST is in effect
416 // and the date to calculate the week for is in DST and within the range
417 // of the DST offset (e.g. one hour).
418 // For example, if DST starts on Sunday march 30 and the date to get the week for
419 // is Monday, march 31, 0:30:00, then the returned week is one week less than
423 // getDSTOffset(const CTime& time)
424 // which returns the DST offset for a given time/date. Then we can use this offset
425 // to correct our GetDays() calculation to get the correct week again
426 // This of course won't work for 'history' dates, because Windows doesn't have
427 // that information (only Vista has such a function: GetTimeZoneInformationForYear() )
430 int iYear
= time
.GetYear();
431 int iFirstDayOfWeek
= 0;
432 int iFirstWeekOfYear
= 0;
434 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, loc
, _countof(loc
));
435 iFirstDayOfWeek
= int(loc
[0]-'0');
436 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, loc
, _countof(loc
));
437 iFirstWeekOfYear
= int(loc
[0]-'0');
438 CTime
dDateFirstJanuary(iYear
,1,1,0,0,0);
439 int iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
442 // 0 Week containing 1/1 is the first week of that year.
443 // 1 First full week following 1/1 is the first week of that year.
444 // 2 First week containing at least four days is the first week of that year.
445 switch (iFirstWeekOfYear
)
449 // Week containing 1/1 is the first week of that year.
451 // check if this week reaches into the next year
452 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
457 iDayOfWeek
= (time
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
459 catch (CException
* e
)
463 CTime dStartOfWeek
= time
-CTimeSpan(iDayOfWeek
,0,0,0);
465 // If this week spans over to 1/1 this is week 1
466 if (dStartOfWeek
+ CTimeSpan(6,0,0,0) >= dDateFirstJanuary
)
468 // we are in the last week of the year that spans over 1/1
473 // Get week day of 1/1
474 dDateFirstJanuary
= CTime(iYear
,1,1,0,0,0);
475 iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek() +5 + iFirstDayOfWeek
) % 7;
476 // Just count from 1/1
477 iWeekOfYear
= (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) + 1;
483 // First full week following 1/1 is the first week of that year.
485 // If the 1.1 is the start of the week everything is ok
486 // else we need the next week is the correct result
488 (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) +
489 (iDayOfWeek
==0 ? 1:0);
491 // If we are in week 0 we are in the first not full week
492 // calculate from the last year
495 // Special case: we are in the week of 1.1 but 1.1. is not on the
496 // start of week. Calculate based on the last year
497 dDateFirstJanuary
= CTime(iYear
-1,1,1,0,0,0);
499 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
500 // and we correct this in the same we we done this before but
501 // the result is now 52 or 53 and not 0
503 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
504 (iDayOfWeek
<=3 ? 1:0);
510 // First week containing at least four days is the first week of that year.
512 // Each year can start with any day of the week. But our
513 // weeks always start with Monday. So we add the day of week
514 // before calculation of the final week of year.
515 // Rule: is the 1.1 a Mo,Tu,We,Th than the week starts on the 1.1 with
516 // week==1, else a week later, so we add one for all those days if
517 // day is less <=3 Mo,Tu,We,Th. Otherwise 1.1 is in the last week of the
520 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
521 (iDayOfWeek
<=3 ? 1:0);
526 // special case week 0. We got a day before the 1.1, 2.1 or 3.1, were the
527 // 1.1. is not a Mo, Tu, We, Th. So the week 1 does not start with the 1.1.
528 // So we calculate the week according to the 1.1 of the year before
530 dDateFirstJanuary
= CTime(iYear
-1,1,1,0,0,0);
532 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
533 // and we correct this in the same we we done this before but the result
534 // is now 52 or 53 and not 0
536 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
537 (iDayOfWeek
<=3 ? 1:0);
539 else if (iWeekOfYear
==53)
541 // special case week 53. Either we got the correct week 53 or we just got the
542 // week 1 of the next year. So is the 1.1.(year+1) also a Mo, Tu, We, Th than
543 // we already have the week 1, otherwise week 53 is correct
545 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
547 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
548 // 1.1. in week 1 or week 53?
549 iWeekOfYear
= iDayOfWeek
<=3 ? 1:53;
577 CCommitPointer(const CCommitPointer
& P_Right
)
590 CCommitPointer
& operator = (const CCommitPointer
& P_Right
)
594 (*m_cont
->m_parDates
)[m_place
] = P_Right
.GetDate();
595 (*m_cont
->m_parFileChanges
)[m_place
] = P_Right
.GetChanges();
596 (*m_cont
->m_parAuthors
)[m_place
] = P_Right
.GetAuthor();
597 (*m_cont
->m_lineInc
)[m_place
] = P_Right
.GetLineInc();
598 (*m_cont
->m_lineDec
)[m_place
] = P_Right
.GetLineDec();
599 (*m_cont
->m_lineNew
)[m_place
] = P_Right
.GetLineNew();
600 (*m_cont
->m_lineDel
)[m_place
] = P_Right
.GetLineDel();
604 m_Date
= P_Right
.GetDate();
605 m_Changes
= P_Right
.GetChanges();
606 m_csAuthor
= P_Right
.GetAuthor();
607 m_lineInc
= P_Right
.GetLineInc();
608 m_lineDec
= P_Right
.GetLineDec();
609 m_lineNew
= P_Right
.GetLineNew();
610 m_lineDel
= P_Right
.GetLineDel();
615 void Clone(const CCommitPointer
& P_Right
)
617 m_cont
= P_Right
.m_cont
;
618 m_place
= P_Right
.m_place
;
619 m_Date
= P_Right
.m_Date
;
620 m_Changes
= P_Right
.m_Changes
;
621 m_csAuthor
= P_Right
.m_csAuthor
;
624 DWORD
GetDate() const {return IsPointer() ? (*m_cont
->m_parDates
)[m_place
] : m_Date
;}
625 DWORD
GetChanges() const {return IsPointer() ? (*m_cont
->m_parFileChanges
)[m_place
] : m_Changes
;}
626 DWORD
GetLineInc() const {return IsPointer() ? (*m_cont
->m_lineInc
)[m_place
] : m_lineInc
;}
627 DWORD
GetLineDec() const {return IsPointer() ? (*m_cont
->m_lineDec
)[m_place
] : m_lineDec
;}
628 DWORD
GetLineNew() const {return IsPointer() ? (*m_cont
->m_lineNew
)[m_place
] : m_lineNew
;}
629 DWORD
GetLineDel() const {return IsPointer() ? (*m_cont
->m_lineDel
)[m_place
] : m_lineDel
;}
630 CString
GetAuthor() const {return IsPointer() ? (*m_cont
->m_parAuthors
)[m_place
] : m_csAuthor
;}
632 bool IsPointer() const {return m_cont
!= NULL
;}
647 class iterator
: public std::iterator
<std::random_access_iterator_tag
, CCommitPointer
>
650 CCommitPointer m_ptr
;
653 iterator(const iterator
& P_Right
){*this = P_Right
;}
654 iterator
& operator=(const iterator
& P_Right
)
656 m_ptr
.Clone(P_Right
.m_ptr
);
660 CCommitPointer
& operator*(){return m_ptr
;}
661 CCommitPointer
* operator->(){return &m_ptr
;}
662 const CCommitPointer
& operator*()const{return m_ptr
;}
663 const CCommitPointer
* operator->()const{return &m_ptr
;}
665 iterator
& operator+=(size_t P_iOffset
){m_ptr
.m_place
+= (int)P_iOffset
;return *this;}
666 iterator
& operator-=(size_t P_iOffset
){m_ptr
.m_place
-= (int)P_iOffset
;return *this;}
667 iterator
operator+(size_t P_iOffset
)const{iterator
it(*this); it
+= P_iOffset
;return it
;}
668 iterator
operator-(size_t P_iOffset
)const{iterator
it(*this); it
-= P_iOffset
;return it
;}
670 iterator
& operator++(){++m_ptr
.m_place
;return *this;}
671 iterator
& operator--(){--m_ptr
.m_place
;return *this;}
672 iterator
operator++(int){iterator
it(*this);++*this;return it
;}
673 iterator
operator--(int){iterator
it(*this);--*this;return it
;}
675 size_t operator-(const iterator
& P_itRight
)const{return m_ptr
.m_place
- P_itRight
->m_place
;}
677 bool operator<(const iterator
& P_itRight
)const{return m_ptr
.m_place
< P_itRight
->m_place
;}
678 bool operator!=(const iterator
& P_itRight
)const{return m_ptr
.m_place
!= P_itRight
->m_place
;}
679 bool operator==(const iterator
& P_itRight
)const{return m_ptr
.m_place
== P_itRight
->m_place
;}
680 bool operator>(const iterator
& P_itRight
)const{return m_ptr
.m_place
> P_itRight
->m_place
;}
692 it
->m_place
= (int)m_parDates
->GetCount();
697 CDWordArray
* m_parDates
;
698 CDWordArray
* m_parFileChanges
;
699 CDWordArray
* m_lineInc
;
700 CDWordArray
* m_lineDec
;
701 CDWordArray
* m_lineNew
;
702 CDWordArray
* m_lineDel
;
703 CStringArray
* m_parAuthors
;
706 class CDateSorterLess
709 bool operator () (const CDateSorter::CCommitPointer
& P_Left
, const CDateSorter::CCommitPointer
& P_Right
) const
711 return P_Left
.GetDate() > P_Right
.GetDate(); //Last date first
716 int CStatGraphDlg::GatherData(BOOL fetchdiff
, BOOL keepFetchedData
)
718 m_parAuthors
.RemoveAll();
719 m_parDates
.RemoveAll();
720 if (!keepFetchedData
)
722 m_parFileChanges
.RemoveAll();
723 m_lineInc
.RemoveAll();
724 m_lineDec
.RemoveAll();
725 m_lineDel
.RemoveAll();
726 m_lineNew
.RemoveAll();
730 m_parFileChanges
.Copy(m_parFileChanges2
);
731 m_lineNew
.Copy(m_lineNew2
);
732 m_lineDel
.Copy(m_lineDel2
);
733 m_lineInc
.Copy(m_lineInc2
);
734 m_lineDec
.Copy(m_lineDec2
);
737 CSysProgressDlg progress
;
740 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_GATHERSTATISTICS
)));
741 progress
.FormatNonPathLine(1, IDS_PROC_STATISTICS_DIFF
);
742 progress
.SetAnimation(IDR_MOVEANI
);
743 progress
.SetTime(true);
744 progress
.ShowModeless(this);
747 // create arrays which are aware of the current filter
748 DWORD starttime
= GetTickCount();
750 GIT_MAILMAP mailmap
= nullptr;
751 git_read_mailmap(&mailmap
);
752 for (INT_PTR i
= 0; i
< m_ShowList
.GetCount(); ++i
)
754 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_ShowList
.SafeGetAt(i
));
755 int inc
, dec
, incnewfile
, decdeletedfile
, files
;
756 inc
= dec
= incnewfile
= decdeletedfile
= files
= 0;
758 // do not take working dir changes into statistics
759 if (pLogEntry
->m_CommitHash
.IsEmpty()) {
763 CString strAuthor
= pLogEntry
->GetAuthorName();
764 if (strAuthor
.IsEmpty())
766 strAuthor
.LoadString(IDS_STATGRAPH_EMPTYAUTHOR
);
770 CStringA email2A
= CUnicodeUtils::GetUTF8(pLogEntry
->GetAuthorEmail());
771 struct payload_struct
{ GitRev
* rev
; const char *authorName
; };
772 payload_struct payload
= { pLogEntry
, nullptr };
773 const char *author1
= git_get_mailmap_author(mailmap
, email2A
, &payload
,
774 [] (void *payload
) -> const char * { return ((payload_struct
*)payload
)->authorName
= _strdup(CUnicodeUtils::GetUTF8(((payload_struct
*)payload
)->rev
->GetAuthorName())); });
775 if (payload
.authorName
)
776 free((void *)payload
.authorName
);
778 strAuthor
= CUnicodeUtils::GetUnicode(author1
);
780 m_parAuthors
.Add(strAuthor
);
781 m_parDates
.Add((DWORD
)pLogEntry
->GetCommitterDate().GetTime());
783 if (fetchdiff
&& (pLogEntry
->m_ParentHash
.size() <= 1))
785 CTGitPathList
&list
= pLogEntry
->GetFiles(NULL
);
786 files
= list
.GetCount();
788 for (int j
= 0; j
< files
; j
++)
790 if (list
[j
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
791 decdeletedfile
+= _tstol(list
[j
].m_StatDel
);
792 else if(list
[j
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
793 incnewfile
+= _tstol(list
[j
].m_StatAdd
);
796 inc
+= _tstol(list
[j
].m_StatAdd
);
797 dec
+= _tstol(list
[j
].m_StatDel
);
800 if (progress
.HasUserCancelled())
802 git_free_mailmap(mailmap
);
807 if (!keepFetchedData
)
809 m_parFileChanges
.Add(files
);
812 m_lineDel
.Add(decdeletedfile
);
813 m_lineNew
.Add(incnewfile
);
816 if (progress
.IsVisible() && (GetTickCount() - starttime
> 100))
818 progress
.FormatNonPathLine(2, _T("%s: %s"), pLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()), pLogEntry
->GetSubject());
819 progress
.SetProgress64(i
, m_ShowList
.GetCount());
820 starttime
= GetTickCount();
824 git_free_mailmap(mailmap
);
828 m_parFileChanges2
.Copy(m_parFileChanges
);
829 m_lineNew2
.Copy(m_lineNew
);
830 m_lineDel2
.Copy(m_lineDel
);
831 m_lineInc2
.Copy(m_lineInc
);
832 m_lineDec2
.Copy(m_lineDec
);
835 CDateSorter W_Sorter
;
836 W_Sorter
.m_parAuthors
= &m_parAuthors
;
837 W_Sorter
.m_parDates
= &m_parDates
;
838 W_Sorter
.m_parFileChanges
= &m_parFileChanges
;
839 W_Sorter
.m_lineNew
= &m_lineNew
;
840 W_Sorter
.m_lineDel
= &m_lineDel
;
841 W_Sorter
.m_lineInc
= &m_lineInc
;
842 W_Sorter
.m_lineDec
= &m_lineDec
;
844 std::sort(W_Sorter
.begin(), W_Sorter
.end(), CDateSorterLess());
846 m_nTotalCommits
= m_parAuthors
.GetCount();
847 m_nTotalFileChanges
= 0;
849 // Update m_nWeeks and m_minDate
852 // Now create a mapping that holds the information per week.
853 m_commitsPerUnitAndAuthor
.clear();
854 m_filechangesPerUnitAndAuthor
.clear();
855 m_commitsPerAuthor
.clear();
856 m_PercentageOfAuthorship
.clear();
857 m_LinesWPerUnitAndAuthor
.clear();
858 m_LinesWOPerUnitAndAuthor
.clear();
861 __time64_t d
= (__time64_t
)m_parDates
.GetAt(0);
862 int nLastUnit
= GetUnit(d
);
863 double AllContributionAuthor
= 0;
865 m_nTotalLinesInc
= m_nTotalLinesDec
= m_nTotalLinesNew
= m_nTotalLinesDel
=0;
867 // Now loop over all weeks and gather the info
868 for (LONG i
=0; i
<m_nTotalCommits
; ++i
)
870 // Find the interval number
871 __time64_t commitDate
= (__time64_t
)m_parDates
.GetAt(i
);
872 int u
= GetUnit(commitDate
);
876 // Find the authors name
877 CString sAuth
= m_parAuthors
.GetAt(i
);
878 if (!m_bAuthorsCaseSensitive
)
879 sAuth
= sAuth
.MakeLower();
880 tstring author
= tstring(sAuth
);
881 // Increase total commit count for this author
882 m_commitsPerAuthor
[author
]++;
883 // Increase the commit count for this author in this week
884 m_commitsPerUnitAndAuthor
[interval
][author
]++;
886 m_LinesWPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
) + m_lineNew
.GetAt(i
) + + m_lineDel
.GetAt(i
);
887 m_LinesWOPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
);
889 CTime t
= m_parDates
.GetAt(i
);
890 m_unitNames
[interval
] = GetUnitLabel(nLastUnit
, t
);
891 // Increase the file change count for this author in this week
892 int fileChanges
= m_parFileChanges
.GetAt(i
);
893 m_filechangesPerUnitAndAuthor
[interval
][author
] += fileChanges
;
894 m_nTotalFileChanges
+= fileChanges
;
896 //calculate Contribution Author
897 double contributionAuthor
= CoeffContribution((int)m_nTotalCommits
- i
-1) * (fileChanges
? fileChanges
: 1);
898 AllContributionAuthor
+= contributionAuthor
;
899 m_PercentageOfAuthorship
[author
] += contributionAuthor
;
901 m_nTotalLinesInc
+= m_lineInc
.GetAt(i
);
902 m_nTotalLinesDec
+= m_lineDec
.GetAt(i
);
903 m_nTotalLinesNew
+= m_lineNew
.GetAt(i
);
904 m_nTotalLinesDel
+= m_lineDel
.GetAt(i
);
907 // Find first and last interval number.
908 if (!m_commitsPerUnitAndAuthor
.empty())
910 IntervalDataMap::iterator interval_it
= m_commitsPerUnitAndAuthor
.begin();
911 m_firstInterval
= interval_it
->first
;
912 interval_it
= m_commitsPerUnitAndAuthor
.end();
914 m_lastInterval
= interval_it
->first
;
915 // Sanity check - if m_lastInterval is too large it could freeze TSVN and take up all memory!!!
916 assert(m_lastInterval
>= 0 && m_lastInterval
< 10000);
924 // Get a list of authors names
925 LoadListOfAuthors(m_commitsPerAuthor
);
927 // Calculate percent of Contribution Authors
928 for (std::list
<tstring
>::iterator it
= m_authorNames
.begin(); it
!= m_authorNames
.end(); ++it
)
930 m_PercentageOfAuthorship
[*it
] = (m_PercentageOfAuthorship
[*it
] *100)/ AllContributionAuthor
;
933 // All done, now the statistics pages can retrieve the data and
934 // extract the information to be shown.
940 void CStatGraphDlg::FilterSkippedAuthors(std::list
<tstring
>& included_authors
,
941 std::list
<tstring
>& skipped_authors
)
943 included_authors
.clear();
944 skipped_authors
.clear();
946 unsigned int included_authors_count
= m_Skipper
.GetPos();
947 // if we only leave out one author, still include him with his name
948 if (included_authors_count
+ 1 == m_authorNames
.size())
949 ++included_authors_count
;
951 // add the included authors first
952 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
953 while (included_authors_count
> 0 && author_it
!= m_authorNames
.end())
955 // Add him/her to the included list
956 included_authors
.push_back(*author_it
);
958 --included_authors_count
;
961 // If we haven't reached the end yet, copy all remaining authors into the
962 // skipped author list.
963 std::copy(author_it
, m_authorNames
.end(), std::back_inserter(skipped_authors
) );
965 // Sort authors alphabetically if user wants that.
966 if (!m_bSortByCommitCount
)
967 included_authors
.sort();
970 bool CStatGraphDlg::PreViewStat(bool fShowLabels
)
972 if (m_parAuthors
.IsEmpty() || m_parDates
.IsEmpty() || m_parFileChanges
.IsEmpty())
974 ShowLabels(fShowLabels
);
977 if (!fShowLabels
) ClearGraph();
979 // This function relies on a previous call of GatherData().
980 // This can be detected by checking the week count.
981 // If the week count is equal to -1, it hasn't been called before.
983 GatherData(FALSE
, TRUE
);
984 // If week count is still -1, something bad has happened, probably invalid data!
991 MyGraphSeries
*CStatGraphDlg::PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
/*= NULL*/)
993 if(!PreViewStat(false))
996 // We need at least one author
997 if (m_authorNames
.empty())
1000 // Add a single series to the chart
1001 MyGraphSeries
* graphData
= new MyGraphSeries();
1002 m_graph
.AddSeries(*graphData
);
1003 m_graphDataArray
.Add(graphData
);
1005 // Set up the graph.
1008 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
1009 temp
.LoadString(YAxisLabel
);
1010 m_graph
.SetYAxisLabel(temp
);
1011 temp
.LoadString(XAxisLabel
);
1012 m_graph
.SetXAxisLabel(temp
);
1013 temp
.LoadString(GraphTitle
);
1014 m_graph
.SetGraphTitle(temp
);
1019 void CStatGraphDlg::ShowPercentageOfAuthorship()
1021 // Set up the graph.
1022 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
,
1023 IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIPY
,
1024 IDS_STATGRAPH_COMMITSBYAUTHORX
);
1025 if(graphData
== NULL
) return;
1027 // Find out which authors are to be shown and which are to be skipped.
1028 std::list
<tstring
> authors
;
1029 std::list
<tstring
> others
;
1032 FilterSkippedAuthors(authors
, others
);
1034 // Loop over all authors in the authors list and
1035 // add them to the graph.
1037 if (!authors
.empty())
1039 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1041 int group
= m_graph
.AppendGroup(it
->c_str());
1042 graphData
->SetData(group
, RollPercentageOfAuthorship(m_PercentageOfAuthorship
[*it
]));
1046 // If we have other authors, count them and their commits.
1047 if (!others
.empty())
1048 DrawOthers(others
, graphData
, m_PercentageOfAuthorship
);
1050 // Paint the graph now that we're through.
1051 m_graph
.Invalidate();
1054 void CStatGraphDlg::ShowCommitsByAuthor()
1056 // Set up the graph.
1057 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_COMMITSBYAUTHOR
,
1058 IDS_STATGRAPH_COMMITSBYAUTHORY
,
1059 IDS_STATGRAPH_COMMITSBYAUTHORX
);
1060 if(graphData
== NULL
) return;
1062 // Find out which authors are to be shown and which are to be skipped.
1063 std::list
<tstring
> authors
;
1064 std::list
<tstring
> others
;
1065 FilterSkippedAuthors(authors
, others
);
1067 // Loop over all authors in the authors list and
1068 // add them to the graph.
1070 if (!authors
.empty())
1072 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1074 int group
= m_graph
.AppendGroup(it
->c_str());
1075 graphData
->SetData(group
, m_commitsPerAuthor
[*it
]);
1079 // If we have other authors, count them and their commits.
1080 if (!others
.empty())
1081 DrawOthers(others
, graphData
, m_commitsPerAuthor
);
1083 // Paint the graph now that we're through.
1084 m_graph
.Invalidate();
1087 void CStatGraphDlg::ShowByDate(int stringx
, int title
, IntervalDataMap
&data
)
1089 if(!PreViewStat(false)) return;
1091 // We need at least one author
1092 if (m_authorNames
.empty()) return;
1094 // Set up the graph.
1097 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
1098 temp
.LoadString(stringx
);
1099 m_graph
.SetYAxisLabel(temp
);
1100 temp
.LoadString(title
);
1101 m_graph
.SetGraphTitle(temp
);
1103 m_graph
.SetXAxisLabel(GetUnitString());
1105 // Find out which authors are to be shown and which are to be skipped.
1106 std::list
<tstring
> authors
;
1107 std::list
<tstring
> others
;
1108 FilterSkippedAuthors(authors
, others
);
1110 // Add a graph series for each author.
1111 AuthorDataMap authorGraphMap
;
1112 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1113 authorGraphMap
[*it
] = m_graph
.AppendGroup(it
->c_str());
1114 // If we have skipped authors, add a graph series for all those.
1115 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1117 if (!others
.empty())
1119 temp
.Format(_T(" (%Iu)"), others
.size());
1121 othersName
= (LPCWSTR
)sOthers
;
1122 authorGraphMap
[othersName
] = m_graph
.AppendGroup(sOthers
);
1125 // Mapping to collect commit counts in each interval
1126 AuthorDataMap commitCount
;
1128 // Loop over all intervals/weeks and collect filtered data.
1129 // Sum up data in each interval until the time unit changes.
1130 for (int i
=m_lastInterval
; i
>=m_firstInterval
; --i
)
1132 // Collect data for authors listed by name.
1133 if (!authors
.empty())
1135 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1137 // Do we have some data for the current author in the current interval?
1138 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1139 if (data_it
== data
[i
].end())
1141 commitCount
[*it
] += data_it
->second
;
1144 // Collect data for all skipped authors.
1145 if (!others
.empty())
1147 for (std::list
<tstring
>::iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1149 // Do we have some data for the author in the current interval?
1150 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1151 if (data_it
== data
[i
].end())
1153 commitCount
[othersName
] += data_it
->second
;
1157 // Create a new data series for this unit/interval.
1158 MyGraphSeries
* graphData
= new MyGraphSeries();
1159 // Loop over all created graphs and set the corresponding data.
1160 if (!authorGraphMap
.empty())
1162 for (AuthorDataMap::const_iterator it
= authorGraphMap
.begin(); it
!= authorGraphMap
.end(); ++it
)
1164 graphData
->SetData(it
->second
, commitCount
[it
->first
]);
1167 graphData
->SetLabel(m_unitNames
[i
].c_str());
1168 m_graph
.AddSeries(*graphData
);
1169 m_graphDataArray
.Add(graphData
);
1171 // Reset commit count mapping.
1172 commitCount
.clear();
1175 // Paint the graph now that we're through.
1176 m_graph
.Invalidate();
1179 void CStatGraphDlg::ShowStats()
1181 if(!PreViewStat(true)) return;
1183 // Now we can use the gathered data to update the stats dialog.
1184 size_t nAuthors
= m_authorNames
.size();
1186 // Find most and least active author names.
1187 tstring mostActiveAuthor
;
1188 tstring leastActiveAuthor
;
1191 mostActiveAuthor
= m_authorNames
.front();
1192 leastActiveAuthor
= m_authorNames
.back();
1195 // Obtain the statistics for the table.
1196 long nCommitsMin
= -1;
1197 long nCommitsMax
= -1;
1198 long nFileChangesMin
= -1;
1199 long nFileChangesMax
= -1;
1201 long nMostActiveMaxCommits
= -1;
1202 long nMostActiveMinCommits
= -1;
1203 long nLeastActiveMaxCommits
= -1;
1204 long nLeastActiveMinCommits
= -1;
1206 // Loop over all intervals and find min and max values for commit count and file changes.
1207 // Also store the stats for the most and least active authors.
1208 for (int i
=m_firstInterval
; i
<=m_lastInterval
; ++i
)
1210 // Loop over all commits in this interval and count the number of commits by all authors.
1211 int commitCount
= 0;
1212 AuthorDataMap::iterator commit_endit
= m_commitsPerUnitAndAuthor
[i
].end();
1213 for (AuthorDataMap::iterator commit_it
= m_commitsPerUnitAndAuthor
[i
].begin();
1214 commit_it
!= commit_endit
; ++commit_it
)
1216 commitCount
+= commit_it
->second
;
1218 if (nCommitsMin
== -1 || commitCount
< nCommitsMin
)
1219 nCommitsMin
= commitCount
;
1220 if (nCommitsMax
== -1 || commitCount
> nCommitsMax
)
1221 nCommitsMax
= commitCount
;
1223 // Loop over all commits in this interval and count the number of file changes by all authors.
1224 int fileChangeCount
= 0;
1225 AuthorDataMap::iterator filechange_endit
= m_filechangesPerUnitAndAuthor
[i
].end();
1226 for (AuthorDataMap::iterator filechange_it
= m_filechangesPerUnitAndAuthor
[i
].begin();
1227 filechange_it
!= filechange_endit
; ++filechange_it
)
1229 fileChangeCount
+= filechange_it
->second
;
1231 if (nFileChangesMin
== -1 || fileChangeCount
< nFileChangesMin
)
1232 nFileChangesMin
= fileChangeCount
;
1233 if (nFileChangesMax
== -1 || fileChangeCount
> nFileChangesMax
)
1234 nFileChangesMax
= fileChangeCount
;
1236 // also get min/max data for most and least active authors
1239 // check if author is present in this interval
1240 AuthorDataMap::iterator author_it
= m_commitsPerUnitAndAuthor
[i
].find(mostActiveAuthor
);
1242 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1245 authorCommits
= author_it
->second
;
1246 if (nMostActiveMaxCommits
== -1 || authorCommits
> nMostActiveMaxCommits
)
1247 nMostActiveMaxCommits
= authorCommits
;
1248 if (nMostActiveMinCommits
== -1 || authorCommits
< nMostActiveMinCommits
)
1249 nMostActiveMinCommits
= authorCommits
;
1251 author_it
= m_commitsPerUnitAndAuthor
[i
].find(leastActiveAuthor
);
1252 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1255 authorCommits
= author_it
->second
;
1256 if (nLeastActiveMaxCommits
== -1 || authorCommits
> nLeastActiveMaxCommits
)
1257 nLeastActiveMaxCommits
= authorCommits
;
1258 if (nLeastActiveMinCommits
== -1 || authorCommits
< nLeastActiveMinCommits
)
1259 nLeastActiveMinCommits
= authorCommits
;
1262 if (nMostActiveMaxCommits
== -1) nMostActiveMaxCommits
= 0;
1263 if (nMostActiveMinCommits
== -1) nMostActiveMinCommits
= 0;
1264 if (nLeastActiveMaxCommits
== -1) nLeastActiveMaxCommits
= 0;
1265 if (nLeastActiveMinCommits
== -1) nLeastActiveMinCommits
= 0;
1267 int nWeeks
= m_lastInterval
-m_firstInterval
;
1270 // Adjust the labels with the unit type (week, month, ...)
1272 labelText
.Format(IDS_STATGRAPH_NUMBEROFUNIT
, GetUnitString());
1273 SetDlgItemText(IDC_NUMWEEK
, labelText
);
1274 labelText
.Format(IDS_STATGRAPH_COMMITSBYUNIT
, GetUnitString());
1275 SetDlgItemText(IDC_COMMITSEACHWEEK
, labelText
);
1276 labelText
.Format(IDS_STATGRAPH_FILECHANGESBYUNIT
, GetUnitString());
1277 SetDlgItemText(IDC_FILECHANGESEACHWEEK
, labelText
);
1278 // We have now all data we want and we can fill in the labels...
1280 number
.Format(_T("%d"), nWeeks
);
1281 SetDlgItemText(IDC_NUMWEEKVALUE
, number
);
1282 number
.Format(_T("%Iu"), nAuthors
);
1283 SetDlgItemText(IDC_NUMAUTHORVALUE
, number
);
1284 number
.Format(_T("%d"), m_nTotalCommits
);
1285 SetDlgItemText(IDC_NUMCOMMITSVALUE
, number
);
1286 number
.Format(_T("%ld"), m_nTotalFileChanges
);
1288 SetDlgItemText(IDC_NUMFILECHANGESVALUE
, number
);
1290 number
.Format(_T("%ld"), m_parAuthors
.GetCount() / nWeeks
);
1291 SetDlgItemText(IDC_COMMITSEACHWEEKAVG
, number
);
1292 number
.Format(_T("%ld"), nCommitsMax
);
1293 SetDlgItemText(IDC_COMMITSEACHWEEKMAX
, number
);
1294 number
.Format(_T("%ld"), nCommitsMin
);
1295 SetDlgItemText(IDC_COMMITSEACHWEEKMIN
, number
);
1297 number
.Format(_T("%ld"), m_nTotalFileChanges
/ nWeeks
);
1298 //SetDlgItemText(IDC_FILECHANGESEACHWEEKAVG, number);
1299 number
.Format(_T("%ld"), nFileChangesMax
);
1300 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMAX, number);
1301 number
.Format(_T("%ld"), nFileChangesMin
);
1302 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMIN, number);
1304 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
, m_nTotalLinesInc
, m_nTotalLinesDec
);
1306 SetDlgItemText(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
, number
);
1307 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
+ m_nTotalLinesNew
+ m_nTotalLinesDel
,
1308 m_nTotalLinesInc
+ m_nTotalLinesNew
, m_nTotalLinesDec
+ m_nTotalLinesDel
);
1310 SetDlgItemText(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
, number
);
1314 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, _T(""));
1315 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, _T("0"));
1316 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, _T("0"));
1317 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, _T("0"));
1318 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, _T(""));
1319 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, _T("0"));
1320 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, _T("0"));
1321 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, _T("0"));
1325 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, mostActiveAuthor
.c_str());
1326 number
.Format(_T("%ld"), m_commitsPerAuthor
[mostActiveAuthor
] / nWeeks
);
1327 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, number
);
1328 number
.Format(_T("%ld"), nMostActiveMaxCommits
);
1329 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, number
);
1330 number
.Format(_T("%ld"), nMostActiveMinCommits
);
1331 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, number
);
1333 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, leastActiveAuthor
.c_str());
1334 number
.Format(_T("%ld"), m_commitsPerAuthor
[leastActiveAuthor
] / nWeeks
);
1335 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, number
);
1336 number
.Format(_T("%ld"), nLeastActiveMaxCommits
);
1337 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, number
);
1338 number
.Format(_T("%ld"), nLeastActiveMinCommits
);
1339 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, number
);
1343 int CStatGraphDlg::RollPercentageOfAuthorship(double it
)
1344 { return (int)it
+ (it
- (int)it
>= 0.5);}
1346 void CStatGraphDlg::OnCbnSelchangeGraphcombo()
1350 Metrics useMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1356 m_btnGraphLine
.EnableWindow(TRUE
);
1357 m_btnGraphLineStacked
.EnableWindow(TRUE
);
1358 m_btnGraphPie
.EnableWindow(TRUE
);
1359 m_GraphType
= MyGraph::Line
;
1362 case PercentageOfAuthorship
:
1363 case CommitsByAuthor
:
1365 m_btnGraphLine
.EnableWindow(FALSE
);
1366 m_btnGraphLineStacked
.EnableWindow(FALSE
);
1367 m_btnGraphPie
.EnableWindow(TRUE
);
1368 m_GraphType
= MyGraph::Bar
;
1376 int CStatGraphDlg::GetUnitCount()
1383 return (m_nWeeks
/4)+1;
1385 return (m_nWeeks
/13)+1; // quarters
1386 return (m_nWeeks
/52)+1;
1389 int CStatGraphDlg::GetUnit(const CTime
& time
)
1392 return time
.GetMonth()*100 + time
.GetDay(); // month*100+day as the unit
1394 return GetCalendarWeek(time
);
1396 return time
.GetMonth();
1398 return ((time
.GetMonth()-1)/3)+1; // quarters
1399 return time
.GetYear();
1402 CStatGraphDlg::UnitType
CStatGraphDlg::GetUnitType()
1415 CString
CStatGraphDlg::GetUnitString()
1418 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXDAY
));
1420 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXWEEK
));
1422 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXMONTH
));
1424 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXQUARTER
));
1425 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXYEAR
));
1428 CString
CStatGraphDlg::GetUnitLabel(int unit
, CTime
&lasttime
)
1431 switch (GetUnitType())
1435 // month*100+day as the unit
1436 int day
= unit
% 100;
1437 int month
= unit
/ 100;
1438 switch (m_langOrder
)
1440 case 0: // month day year
1441 temp
.Format(_T("%d/%d/%.2d"), month
, day
, lasttime
.GetYear()%100);
1443 case 1: // day month year
1445 temp
.Format(_T("%d/%d/%.2d"), day
, month
, lasttime
.GetYear()%100);
1447 case 2: // year month day
1448 temp
.Format(_T("%.2d/%d/%d"), lasttime
.GetYear()%100, month
, day
);
1455 int year
= lasttime
.GetYear();
1456 if ((unit
== 1)&&(lasttime
.GetMonth() == 12))
1459 switch (m_langOrder
)
1461 case 0: // month day year
1462 case 1: // day month year
1464 temp
.Format(_T("%d/%.2d"), unit
, year
%100);
1466 case 2: // year month day
1467 temp
.Format(_T("%.2d/%d"), year
%100, unit
);
1473 switch (m_langOrder
)
1475 case 0: // month day year
1476 case 1: // day month year
1478 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1480 case 2: // year month day
1481 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1486 switch (m_langOrder
)
1488 case 0: // month day year
1489 case 1: // day month year
1491 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1493 case 2: // year month day
1494 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1499 temp
.Format(_T("%d"), unit
);
1505 void CStatGraphDlg::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
1507 if (nSBCode
== TB_THUMBTRACK
)
1508 return CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1510 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1511 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1514 void CStatGraphDlg::OnNeedText(NMHDR
*pnmh
, LRESULT
* /*pResult*/)
1516 TOOLTIPTEXT
* pttt
= (TOOLTIPTEXT
*) pnmh
;
1517 if (pttt
->hdr
.idFrom
== (UINT_PTR
) m_Skipper
.GetSafeHwnd())
1519 size_t included_authors_count
= m_Skipper
.GetPos();
1520 // if we only leave out one author, still include him with his name
1521 if (included_authors_count
+ 1 == m_authorNames
.size())
1522 ++included_authors_count
;
1524 // find the minimum number of commits that the shown authors have
1525 int min_commits
= 0;
1526 included_authors_count
= min(included_authors_count
, m_authorNames
.size());
1527 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
1528 advance(author_it
, included_authors_count
);
1529 if (author_it
!= m_authorNames
.begin())
1530 min_commits
= m_commitsPerAuthor
[ *(--author_it
) ];
1533 int percentage
= int(min_commits
*100.0/(m_nTotalCommits
? m_nTotalCommits
: 1));
1534 string
.Format(IDS_STATGRAPH_AUTHORSLIDER_TT
, m_Skipper
.GetPos(), min_commits
, percentage
);
1535 StringCchCopy(pttt
->szText
, _countof(pttt
->szText
), (LPCTSTR
) string
);
1539 void CStatGraphDlg::AuthorsCaseSensitiveChanged()
1541 UpdateData(); // update checkbox state
1542 GatherData(FALSE
, TRUE
); // first regenerate the statistics data
1543 RedrawGraph(); // then update the current statistics page
1546 void CStatGraphDlg::SortModeChanged()
1548 UpdateData(); // update checkbox state
1549 RedrawGraph(); // then update the current statistics page
1552 void CStatGraphDlg::ClearGraph()
1555 for (int j
=0; j
<m_graphDataArray
.GetCount(); ++j
)
1556 delete ((MyGraphSeries
*)m_graphDataArray
.GetAt(j
));
1557 m_graphDataArray
.RemoveAll();
1560 void CStatGraphDlg::RedrawGraph()
1562 EnableDisableMenu();
1563 m_btnGraphBar
.SetState(BST_UNCHECKED
);
1564 m_btnGraphBarStacked
.SetState(BST_UNCHECKED
);
1565 m_btnGraphLine
.SetState(BST_UNCHECKED
);
1566 m_btnGraphLineStacked
.SetState(BST_UNCHECKED
);
1567 m_btnGraphPie
.SetState(BST_UNCHECKED
);
1569 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1571 m_btnGraphBarStacked
.SetState(BST_CHECKED
);
1573 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1575 m_btnGraphBar
.SetState(BST_CHECKED
);
1577 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1579 m_btnGraphLineStacked
.SetState(BST_CHECKED
);
1581 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1583 m_btnGraphLine
.SetState(BST_CHECKED
);
1585 if (m_GraphType
== MyGraph::PieChart
)
1587 m_btnGraphPie
.SetState(BST_CHECKED
);
1591 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()), true);
1593 void CStatGraphDlg::OnBnClickedGraphbarbutton()
1595 m_GraphType
= MyGraph::Bar
;
1600 void CStatGraphDlg::OnBnClickedGraphbarstackedbutton()
1602 m_GraphType
= MyGraph::Bar
;
1607 void CStatGraphDlg::OnBnClickedGraphlinebutton()
1609 m_GraphType
= MyGraph::Line
;
1614 void CStatGraphDlg::OnBnClickedGraphlinestackedbutton()
1616 m_GraphType
= MyGraph::Line
;
1621 void CStatGraphDlg::OnBnClickedGraphpiebutton()
1623 m_GraphType
= MyGraph::PieChart
;
1628 BOOL
CStatGraphDlg::PreTranslateMessage(MSG
* pMsg
)
1630 if (NULL
!= m_pToolTip
)
1631 m_pToolTip
->RelayEvent(pMsg
);
1633 return CStandAloneDialogTmpl
<CResizableDialog
>::PreTranslateMessage(pMsg
);
1636 void CStatGraphDlg::EnableDisableMenu()
1638 UINT nEnable
= MF_BYCOMMAND
;
1640 Metrics SelectMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1642 nEnable
|= (SelectMetric
> TextStatStart
&& SelectMetric
< TextStatEnd
)
1643 ? (MF_DISABLED
| MF_GRAYED
) : MF_ENABLED
;
1645 GetMenu()->EnableMenuItem(ID_FILE_SAVESTATGRAPHAS
, nEnable
);
1648 void CStatGraphDlg::OnFileSavestatgraphas()
1651 int filterindex
= 0;
1652 if (CAppUtils::FileOpenSave(tempfile
, &filterindex
, IDS_REVGRAPH_SAVEPIC
, IDS_STATPICFILEFILTER
, false, m_hWnd
))
1654 // if the user doesn't specify a file extension, default to
1655 // wmf and add that extension to the filename. But only if the
1656 // user chose the 'pictures' filter. The filename isn't changed
1657 // if the 'All files' filter was chosen.
1659 int dotPos
= tempfile
.ReverseFind('.');
1660 int slashPos
= tempfile
.ReverseFind('\\');
1661 if (dotPos
> slashPos
)
1662 extension
= tempfile
.Mid(dotPos
);
1663 if ((filterindex
== 1)&&(extension
.IsEmpty()))
1665 extension
= _T(".wmf");
1666 tempfile
+= extension
;
1668 SaveGraph(tempfile
);
1672 void CStatGraphDlg::SaveGraph(CString sFilename
)
1674 CString extension
= CPathUtils::GetFileExtFromPath(sFilename
);
1675 if (extension
.CompareNoCase(_T(".wmf"))==0)
1677 // save the graph as an enhanced meta file
1678 CMyMetaFileDC wmfDC
;
1679 wmfDC
.CreateEnhanced(NULL
, sFilename
, NULL
, _T("TortoiseGit\0Statistics\0\0"));
1680 wmfDC
.SetAttribDC(GetDC()->GetSafeHdc());
1682 m_graph
.DrawGraph(wmfDC
);
1683 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
1684 DeleteEnhMetaFile(hemf
);
1688 // save the graph as a pixel picture instead of a vector picture
1689 // create dc to paint on
1692 CWindowDC
ddc(this);
1694 if (!dc
.CreateCompatibleDC(&ddc
))
1700 GetDlgItem(IDC_GRAPH
)->GetClientRect(&rect
);
1701 HBITMAP hbm
= ::CreateCompatibleBitmap(ddc
.m_hDC
, rect
.Width(), rect
.Height());
1707 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1708 // paint the whole graph
1710 m_graph
.DrawGraph(dc
);
1711 // now use GDI+ to save the picture
1713 GdiplusStartupInput gdiplusStartupInput
;
1714 ULONG_PTR gdiplusToken
;
1715 CString sErrormessage
;
1716 if (GdiplusStartup( &gdiplusToken
, &gdiplusStartupInput
, NULL
)==Ok
)
1719 Bitmap
bitmap(hbm
, NULL
);
1720 if (bitmap
.GetLastStatus()==Ok
)
1722 // Get the CLSID of the encoder.
1724 if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".png"))==0)
1725 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1726 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpg"))==0)
1727 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1728 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpeg"))==0)
1729 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1730 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".bmp"))==0)
1731 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1732 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".gif"))==0)
1733 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1736 sFilename
+= _T(".jpg");
1737 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1741 CStringW tfile
= CStringW(sFilename
);
1742 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1746 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, CPathUtils::GetFileExtFromPath(sFilename
));
1751 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1754 GdiplusShutdown(gdiplusToken
);
1758 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_GDIINIT
);
1760 dc
.SelectObject(oldbm
);
1762 if (!sErrormessage
.IsEmpty())
1764 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseGit"), MB_ICONERROR
);
1767 catch (CException
* pE
)
1769 TCHAR szErrorMsg
[2048];
1770 pE
->GetErrorMessage(szErrorMsg
, 2048);
1772 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseGit"), MB_ICONERROR
);
1777 int CStatGraphDlg::GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
)
1779 UINT num
= 0; // number of image encoders
1780 UINT size
= 0; // size of the image encoder array in bytes
1782 ImageCodecInfo
* pImageCodecInfo
= NULL
;
1784 if (GetImageEncodersSize(&num
, &size
)!=Ok
)
1787 return -1; // Failure
1789 pImageCodecInfo
= (ImageCodecInfo
*)(malloc(size
));
1790 if (pImageCodecInfo
== NULL
)
1791 return -1; // Failure
1793 if (GetImageEncoders(num
, size
, pImageCodecInfo
)==Ok
)
1795 for (UINT j
= 0; j
< num
; ++j
)
1797 if (wcscmp(pImageCodecInfo
[j
].MimeType
, format
) == 0)
1799 *pClsid
= pImageCodecInfo
[j
].Clsid
;
1800 free(pImageCodecInfo
);
1801 return j
; // Success
1805 free (pImageCodecInfo
);
1806 return -1; // Failure
1809 void CStatGraphDlg::StoreCurrentGraphType()
1812 DWORD graphtype
= static_cast<DWORD
>(m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1813 // encode the current chart type
1814 DWORD statspage
= graphtype
*10;
1815 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1819 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1823 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1827 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1831 if (m_GraphType
== MyGraph::PieChart
)
1836 // store current chart type in registry
1837 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseGit\\LastViewedStatsPage"), 0);
1838 lastStatsPage
= statspage
;
1840 CRegDWORD regAuthors
= CRegDWORD(_T("Software\\TortoiseGit\\StatAuthorsCaseSensitive"));
1841 regAuthors
= m_bAuthorsCaseSensitive
;
1843 CRegDWORD regSort
= CRegDWORD(_T("Software\\TortoiseGit\\StatSortByCommitCount"));
1844 regSort
= m_bSortByCommitCount
;
1847 void CStatGraphDlg::ShowErrorMessage()
1849 CFormatMessageWrapper errorDetails
;
1851 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1854 void CStatGraphDlg::ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
/* = false */)
1856 switch (SelectedMetric
)
1859 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1863 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1864 ShowByDate(IDS_STATGRAPH_COMMITSBYDATEY
, IDS_STATGRAPH_COMMITSBYDATE
, m_commitsPerUnitAndAuthor
);
1867 OnBnClickedFetchDiff();
1868 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1869 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_W_Y
, IDS_STATGRAPH_LINES_BYDATE_W
, m_LinesWPerUnitAndAuthor
);
1872 OnBnClickedFetchDiff();
1873 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1874 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_WO_Y
, IDS_STATGRAPH_LINES_BYDATE_WO
, m_LinesWOPerUnitAndAuthor
);
1876 case CommitsByAuthor
:
1877 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1878 ShowCommitsByAuthor();
1880 case PercentageOfAuthorship
:
1881 OnBnClickedFetchDiff();
1882 LoadListOfAuthors(m_PercentageOfAuthorship
, reloadSkiper
, true);
1883 ShowPercentageOfAuthorship();
1890 double CStatGraphDlg::CoeffContribution(int distFromEnd
) { return distFromEnd
? 1.0 / m_CoeffAuthorShip
* distFromEnd
: 1;}
1893 template <class MAP
>
1894 void CStatGraphDlg::DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
)
1897 for (std::list
<tstring
>::const_iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1899 nCommits
+= RollPercentageOfAuthorship(map
[*it
]);
1903 temp
.Format(_T(" (%Iu)"), others
.size());
1905 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1907 int group
= m_graph
.AppendGroup(sOthers
);
1908 graphData
->SetData(group
, (int)nCommits
);
1912 template <class MAP
>
1913 void CStatGraphDlg::LoadListOfAuthors (MAP
&map
, bool reloadSkiper
/*= false*/, bool compare
/*= false*/)
1915 m_authorNames
.clear();
1918 for (MAP::const_iterator it
= map
.begin(); it
!= map
.end(); ++it
)
1920 if ((compare
&& RollPercentageOfAuthorship(map
[it
->first
]) != 0) || !compare
)
1921 m_authorNames
.push_back(it
->first
);
1925 // Sort the list of authors based on commit count
1926 m_authorNames
.sort(MoreCommitsThan
< MAP::referent_type
>(map
));
1929 SetSkipper(reloadSkiper
);
1933 void CStatGraphDlg::OnBnClickedFetchDiff()
1937 if (GatherData(TRUE
))
1939 this->m_bDiffFetched
= TRUE
;
1940 GetDlgItem(IDC_CALC_DIFF
)->ShowWindow(!m_bDiffFetched
);