1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2003-2011,2014 - 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(_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
;
315 TCHAR langBuf
[11] = { 0 };
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;
433 TCHAR loc
[2] = { 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 (m_parFileChanges2
.IsEmpty()) // Fixes issue #1948
721 keepFetchedData
= FALSE
;
722 if (!keepFetchedData
)
724 m_parFileChanges
.RemoveAll();
725 m_lineInc
.RemoveAll();
726 m_lineDec
.RemoveAll();
727 m_lineDel
.RemoveAll();
728 m_lineNew
.RemoveAll();
732 m_parFileChanges
.Copy(m_parFileChanges2
);
733 m_lineNew
.Copy(m_lineNew2
);
734 m_lineDel
.Copy(m_lineDel2
);
735 m_lineInc
.Copy(m_lineInc2
);
736 m_lineDec
.Copy(m_lineDec2
);
739 CSysProgressDlg progress
;
742 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_GATHERSTATISTICS
)));
743 progress
.FormatNonPathLine(1, IDS_PROC_STATISTICS_DIFF
);
744 progress
.SetAnimation(IDR_MOVEANI
);
745 progress
.SetTime(true);
746 progress
.ShowModeless(this);
749 // create arrays which are aware of the current filter
750 DWORD starttime
= GetTickCount();
752 GIT_MAILMAP mailmap
= nullptr;
753 git_read_mailmap(&mailmap
);
754 for (INT_PTR i
= 0; i
< m_ShowList
.GetCount(); ++i
)
756 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_ShowList
.SafeGetAt(i
));
757 int inc
, dec
, incnewfile
, decdeletedfile
, files
;
758 inc
= dec
= incnewfile
= decdeletedfile
= files
= 0;
760 // do not take working dir changes into statistics
761 if (pLogEntry
->m_CommitHash
.IsEmpty()) {
765 CString strAuthor
= pLogEntry
->GetAuthorName();
766 if (strAuthor
.IsEmpty())
768 strAuthor
.LoadString(IDS_STATGRAPH_EMPTYAUTHOR
);
772 CStringA email2A
= CUnicodeUtils::GetUTF8(pLogEntry
->GetAuthorEmail());
773 struct payload_struct
{ GitRev
* rev
; const char *authorName
; };
774 payload_struct payload
= { pLogEntry
, nullptr };
775 const char *author1
= git_get_mailmap_author(mailmap
, email2A
, &payload
,
776 [] (void *payload
) -> const char * { return ((payload_struct
*)payload
)->authorName
= _strdup(CUnicodeUtils::GetUTF8(((payload_struct
*)payload
)->rev
->GetAuthorName())); });
777 free((void *)payload
.authorName
);
779 strAuthor
= CUnicodeUtils::GetUnicode(author1
);
781 m_parAuthors
.Add(strAuthor
);
782 m_parDates
.Add((DWORD
)pLogEntry
->GetCommitterDate().GetTime());
784 if (fetchdiff
&& (pLogEntry
->m_ParentHash
.size() <= 1))
786 CTGitPathList
&list
= pLogEntry
->GetFiles(NULL
);
787 files
= list
.GetCount();
789 for (int j
= 0; j
< files
; j
++)
791 if (list
[j
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
792 decdeletedfile
+= _tstol(list
[j
].m_StatDel
);
793 else if(list
[j
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
794 incnewfile
+= _tstol(list
[j
].m_StatAdd
);
797 inc
+= _tstol(list
[j
].m_StatAdd
);
798 dec
+= _tstol(list
[j
].m_StatDel
);
801 if (progress
.HasUserCancelled())
803 git_free_mailmap(mailmap
);
808 if (!keepFetchedData
)
810 m_parFileChanges
.Add(files
);
813 m_lineDel
.Add(decdeletedfile
);
814 m_lineNew
.Add(incnewfile
);
817 if (progress
.IsVisible() && (GetTickCount() - starttime
> 100))
819 progress
.FormatNonPathLine(2, _T("%s: %s"), pLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()), pLogEntry
->GetSubject());
820 progress
.SetProgress64(i
, m_ShowList
.GetCount());
821 starttime
= GetTickCount();
825 git_free_mailmap(mailmap
);
829 m_parFileChanges2
.Copy(m_parFileChanges
);
830 m_lineNew2
.Copy(m_lineNew
);
831 m_lineDel2
.Copy(m_lineDel
);
832 m_lineInc2
.Copy(m_lineInc
);
833 m_lineDec2
.Copy(m_lineDec
);
836 CDateSorter W_Sorter
;
837 W_Sorter
.m_parAuthors
= &m_parAuthors
;
838 W_Sorter
.m_parDates
= &m_parDates
;
839 W_Sorter
.m_parFileChanges
= &m_parFileChanges
;
840 W_Sorter
.m_lineNew
= &m_lineNew
;
841 W_Sorter
.m_lineDel
= &m_lineDel
;
842 W_Sorter
.m_lineInc
= &m_lineInc
;
843 W_Sorter
.m_lineDec
= &m_lineDec
;
845 std::sort(W_Sorter
.begin(), W_Sorter
.end(), CDateSorterLess());
847 m_nTotalCommits
= m_parAuthors
.GetCount();
848 m_nTotalFileChanges
= 0;
850 // Update m_nWeeks and m_minDate
853 // Now create a mapping that holds the information per week.
854 m_commitsPerUnitAndAuthor
.clear();
855 m_filechangesPerUnitAndAuthor
.clear();
856 m_commitsPerAuthor
.clear();
857 m_PercentageOfAuthorship
.clear();
858 m_LinesWPerUnitAndAuthor
.clear();
859 m_LinesWOPerUnitAndAuthor
.clear();
862 __time64_t d
= (__time64_t
)m_parDates
.GetAt(0);
863 int nLastUnit
= GetUnit(d
);
864 double AllContributionAuthor
= 0;
866 m_nTotalLinesInc
= m_nTotalLinesDec
= m_nTotalLinesNew
= m_nTotalLinesDel
=0;
868 // Now loop over all weeks and gather the info
869 for (LONG i
=0; i
<m_nTotalCommits
; ++i
)
871 // Find the interval number
872 __time64_t commitDate
= (__time64_t
)m_parDates
.GetAt(i
);
873 int u
= GetUnit(commitDate
);
877 // Find the authors name
878 CString sAuth
= m_parAuthors
.GetAt(i
);
879 if (!m_bAuthorsCaseSensitive
)
880 sAuth
= sAuth
.MakeLower();
881 tstring author
= tstring(sAuth
);
882 // Increase total commit count for this author
883 m_commitsPerAuthor
[author
]++;
884 // Increase the commit count for this author in this week
885 m_commitsPerUnitAndAuthor
[interval
][author
]++;
887 m_LinesWPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
) + m_lineNew
.GetAt(i
) + + m_lineDel
.GetAt(i
);
888 m_LinesWOPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
);
890 CTime t
= m_parDates
.GetAt(i
);
891 m_unitNames
[interval
] = GetUnitLabel(nLastUnit
, t
);
892 // Increase the file change count for this author in this week
893 int fileChanges
= m_parFileChanges
.GetAt(i
);
894 m_filechangesPerUnitAndAuthor
[interval
][author
] += fileChanges
;
895 m_nTotalFileChanges
+= fileChanges
;
897 //calculate Contribution Author
898 double contributionAuthor
= CoeffContribution((int)m_nTotalCommits
- i
-1) * (fileChanges
? fileChanges
: 1);
899 AllContributionAuthor
+= contributionAuthor
;
900 m_PercentageOfAuthorship
[author
] += contributionAuthor
;
902 m_nTotalLinesInc
+= m_lineInc
.GetAt(i
);
903 m_nTotalLinesDec
+= m_lineDec
.GetAt(i
);
904 m_nTotalLinesNew
+= m_lineNew
.GetAt(i
);
905 m_nTotalLinesDel
+= m_lineDel
.GetAt(i
);
908 // Find first and last interval number.
909 if (!m_commitsPerUnitAndAuthor
.empty())
911 IntervalDataMap::iterator interval_it
= m_commitsPerUnitAndAuthor
.begin();
912 m_firstInterval
= interval_it
->first
;
913 interval_it
= m_commitsPerUnitAndAuthor
.end();
915 m_lastInterval
= interval_it
->first
;
916 // Sanity check - if m_lastInterval is too large it could freeze TSVN and take up all memory!!!
917 assert(m_lastInterval
>= 0 && m_lastInterval
< 10000);
925 // Get a list of authors names
926 LoadListOfAuthors(m_commitsPerAuthor
);
928 // Calculate percent of Contribution Authors
929 for (std::list
<tstring
>::iterator it
= m_authorNames
.begin(); it
!= m_authorNames
.end(); ++it
)
931 m_PercentageOfAuthorship
[*it
] = (m_PercentageOfAuthorship
[*it
] *100)/ AllContributionAuthor
;
934 // All done, now the statistics pages can retrieve the data and
935 // extract the information to be shown.
941 void CStatGraphDlg::FilterSkippedAuthors(std::list
<tstring
>& included_authors
,
942 std::list
<tstring
>& skipped_authors
)
944 included_authors
.clear();
945 skipped_authors
.clear();
947 unsigned int included_authors_count
= m_Skipper
.GetPos();
948 // if we only leave out one author, still include him with his name
949 if (included_authors_count
+ 1 == m_authorNames
.size())
950 ++included_authors_count
;
952 // add the included authors first
953 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
954 while (included_authors_count
> 0 && author_it
!= m_authorNames
.end())
956 // Add him/her to the included list
957 included_authors
.push_back(*author_it
);
959 --included_authors_count
;
962 // If we haven't reached the end yet, copy all remaining authors into the
963 // skipped author list.
964 std::copy(author_it
, m_authorNames
.end(), std::back_inserter(skipped_authors
) );
966 // Sort authors alphabetically if user wants that.
967 if (!m_bSortByCommitCount
)
968 included_authors
.sort();
971 bool CStatGraphDlg::PreViewStat(bool fShowLabels
)
973 if (m_parAuthors
.IsEmpty() || m_parDates
.IsEmpty() || m_parFileChanges
.IsEmpty())
975 ShowLabels(fShowLabels
);
978 if (!fShowLabels
) ClearGraph();
980 // This function relies on a previous call of GatherData().
981 // This can be detected by checking the week count.
982 // If the week count is equal to -1, it hasn't been called before.
984 GatherData(FALSE
, TRUE
);
985 // If week count is still -1, something bad has happened, probably invalid data!
992 MyGraphSeries
*CStatGraphDlg::PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
/*= NULL*/)
994 if(!PreViewStat(false))
997 // We need at least one author
998 if (m_authorNames
.empty())
1001 // Add a single series to the chart
1002 MyGraphSeries
* graphData
= new MyGraphSeries();
1003 m_graph
.AddSeries(*graphData
);
1004 m_graphDataArray
.Add(graphData
);
1006 // Set up the graph.
1009 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
1010 temp
.LoadString(YAxisLabel
);
1011 m_graph
.SetYAxisLabel(temp
);
1012 temp
.LoadString(XAxisLabel
);
1013 m_graph
.SetXAxisLabel(temp
);
1014 temp
.LoadString(GraphTitle
);
1015 m_graph
.SetGraphTitle(temp
);
1020 void CStatGraphDlg::ShowPercentageOfAuthorship()
1022 // Set up the graph.
1023 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
,
1024 IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIPY
,
1025 IDS_STATGRAPH_COMMITSBYAUTHORX
);
1026 if(graphData
== NULL
) return;
1028 // Find out which authors are to be shown and which are to be skipped.
1029 std::list
<tstring
> authors
;
1030 std::list
<tstring
> others
;
1033 FilterSkippedAuthors(authors
, others
);
1035 // Loop over all authors in the authors list and
1036 // add them to the graph.
1038 if (!authors
.empty())
1040 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1042 int group
= m_graph
.AppendGroup(it
->c_str());
1043 graphData
->SetData(group
, RollPercentageOfAuthorship(m_PercentageOfAuthorship
[*it
]));
1047 // If we have other authors, count them and their commits.
1048 if (!others
.empty())
1049 DrawOthers(others
, graphData
, m_PercentageOfAuthorship
);
1051 // Paint the graph now that we're through.
1052 m_graph
.Invalidate();
1055 void CStatGraphDlg::ShowCommitsByAuthor()
1057 // Set up the graph.
1058 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_COMMITSBYAUTHOR
,
1059 IDS_STATGRAPH_COMMITSBYAUTHORY
,
1060 IDS_STATGRAPH_COMMITSBYAUTHORX
);
1061 if(graphData
== NULL
) return;
1063 // Find out which authors are to be shown and which are to be skipped.
1064 std::list
<tstring
> authors
;
1065 std::list
<tstring
> others
;
1066 FilterSkippedAuthors(authors
, others
);
1068 // Loop over all authors in the authors list and
1069 // add them to the graph.
1071 if (!authors
.empty())
1073 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1075 int group
= m_graph
.AppendGroup(it
->c_str());
1076 graphData
->SetData(group
, m_commitsPerAuthor
[*it
]);
1080 // If we have other authors, count them and their commits.
1081 if (!others
.empty())
1082 DrawOthers(others
, graphData
, m_commitsPerAuthor
);
1084 // Paint the graph now that we're through.
1085 m_graph
.Invalidate();
1088 void CStatGraphDlg::ShowByDate(int stringx
, int title
, IntervalDataMap
&data
)
1090 if(!PreViewStat(false)) return;
1092 // We need at least one author
1093 if (m_authorNames
.empty()) return;
1095 // Set up the graph.
1098 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
1099 temp
.LoadString(stringx
);
1100 m_graph
.SetYAxisLabel(temp
);
1101 temp
.LoadString(title
);
1102 m_graph
.SetGraphTitle(temp
);
1104 m_graph
.SetXAxisLabel(GetUnitString());
1106 // Find out which authors are to be shown and which are to be skipped.
1107 std::list
<tstring
> authors
;
1108 std::list
<tstring
> others
;
1109 FilterSkippedAuthors(authors
, others
);
1111 // Add a graph series for each author.
1112 AuthorDataMap authorGraphMap
;
1113 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1114 authorGraphMap
[*it
] = m_graph
.AppendGroup(it
->c_str());
1115 // If we have skipped authors, add a graph series for all those.
1116 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1118 if (!others
.empty())
1120 temp
.Format(_T(" (%Iu)"), others
.size());
1122 othersName
= (LPCWSTR
)sOthers
;
1123 authorGraphMap
[othersName
] = m_graph
.AppendGroup(sOthers
);
1126 // Mapping to collect commit counts in each interval
1127 AuthorDataMap commitCount
;
1129 // Loop over all intervals/weeks and collect filtered data.
1130 // Sum up data in each interval until the time unit changes.
1131 for (int i
=m_lastInterval
; i
>=m_firstInterval
; --i
)
1133 // Collect data for authors listed by name.
1134 if (!authors
.empty())
1136 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1138 // Do we have some data for the current author in the current interval?
1139 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1140 if (data_it
== data
[i
].end())
1142 commitCount
[*it
] += data_it
->second
;
1145 // Collect data for all skipped authors.
1146 if (!others
.empty())
1148 for (std::list
<tstring
>::iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1150 // Do we have some data for the author in the current interval?
1151 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1152 if (data_it
== data
[i
].end())
1154 commitCount
[othersName
] += data_it
->second
;
1158 // Create a new data series for this unit/interval.
1159 MyGraphSeries
* graphData
= new MyGraphSeries();
1160 // Loop over all created graphs and set the corresponding data.
1161 if (!authorGraphMap
.empty())
1163 for (AuthorDataMap::const_iterator it
= authorGraphMap
.begin(); it
!= authorGraphMap
.end(); ++it
)
1165 graphData
->SetData(it
->second
, commitCount
[it
->first
]);
1168 graphData
->SetLabel(m_unitNames
[i
].c_str());
1169 m_graph
.AddSeries(*graphData
);
1170 m_graphDataArray
.Add(graphData
);
1172 // Reset commit count mapping.
1173 commitCount
.clear();
1176 // Paint the graph now that we're through.
1177 m_graph
.Invalidate();
1180 void CStatGraphDlg::ShowStats()
1182 if(!PreViewStat(true)) return;
1184 // Now we can use the gathered data to update the stats dialog.
1185 size_t nAuthors
= m_authorNames
.size();
1187 // Find most and least active author names.
1188 tstring mostActiveAuthor
;
1189 tstring leastActiveAuthor
;
1192 mostActiveAuthor
= m_authorNames
.front();
1193 leastActiveAuthor
= m_authorNames
.back();
1196 // Obtain the statistics for the table.
1197 long nCommitsMin
= -1;
1198 long nCommitsMax
= -1;
1199 long nFileChangesMin
= -1;
1200 long nFileChangesMax
= -1;
1202 long nMostActiveMaxCommits
= -1;
1203 long nMostActiveMinCommits
= -1;
1204 long nLeastActiveMaxCommits
= -1;
1205 long nLeastActiveMinCommits
= -1;
1207 // Loop over all intervals and find min and max values for commit count and file changes.
1208 // Also store the stats for the most and least active authors.
1209 for (int i
=m_firstInterval
; i
<=m_lastInterval
; ++i
)
1211 // Loop over all commits in this interval and count the number of commits by all authors.
1212 int commitCount
= 0;
1213 AuthorDataMap::iterator commit_endit
= m_commitsPerUnitAndAuthor
[i
].end();
1214 for (AuthorDataMap::iterator commit_it
= m_commitsPerUnitAndAuthor
[i
].begin();
1215 commit_it
!= commit_endit
; ++commit_it
)
1217 commitCount
+= commit_it
->second
;
1219 if (nCommitsMin
== -1 || commitCount
< nCommitsMin
)
1220 nCommitsMin
= commitCount
;
1221 if (nCommitsMax
== -1 || commitCount
> nCommitsMax
)
1222 nCommitsMax
= commitCount
;
1224 // Loop over all commits in this interval and count the number of file changes by all authors.
1225 int fileChangeCount
= 0;
1226 AuthorDataMap::iterator filechange_endit
= m_filechangesPerUnitAndAuthor
[i
].end();
1227 for (AuthorDataMap::iterator filechange_it
= m_filechangesPerUnitAndAuthor
[i
].begin();
1228 filechange_it
!= filechange_endit
; ++filechange_it
)
1230 fileChangeCount
+= filechange_it
->second
;
1232 if (nFileChangesMin
== -1 || fileChangeCount
< nFileChangesMin
)
1233 nFileChangesMin
= fileChangeCount
;
1234 if (nFileChangesMax
== -1 || fileChangeCount
> nFileChangesMax
)
1235 nFileChangesMax
= fileChangeCount
;
1237 // also get min/max data for most and least active authors
1240 // check if author is present in this interval
1241 AuthorDataMap::iterator author_it
= m_commitsPerUnitAndAuthor
[i
].find(mostActiveAuthor
);
1243 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1246 authorCommits
= author_it
->second
;
1247 if (nMostActiveMaxCommits
== -1 || authorCommits
> nMostActiveMaxCommits
)
1248 nMostActiveMaxCommits
= authorCommits
;
1249 if (nMostActiveMinCommits
== -1 || authorCommits
< nMostActiveMinCommits
)
1250 nMostActiveMinCommits
= authorCommits
;
1252 author_it
= m_commitsPerUnitAndAuthor
[i
].find(leastActiveAuthor
);
1253 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1256 authorCommits
= author_it
->second
;
1257 if (nLeastActiveMaxCommits
== -1 || authorCommits
> nLeastActiveMaxCommits
)
1258 nLeastActiveMaxCommits
= authorCommits
;
1259 if (nLeastActiveMinCommits
== -1 || authorCommits
< nLeastActiveMinCommits
)
1260 nLeastActiveMinCommits
= authorCommits
;
1263 if (nMostActiveMaxCommits
== -1) nMostActiveMaxCommits
= 0;
1264 if (nMostActiveMinCommits
== -1) nMostActiveMinCommits
= 0;
1265 if (nLeastActiveMaxCommits
== -1) nLeastActiveMaxCommits
= 0;
1266 if (nLeastActiveMinCommits
== -1) nLeastActiveMinCommits
= 0;
1268 int nWeeks
= m_lastInterval
-m_firstInterval
;
1271 // Adjust the labels with the unit type (week, month, ...)
1273 labelText
.Format(IDS_STATGRAPH_NUMBEROFUNIT
, GetUnitString());
1274 SetDlgItemText(IDC_NUMWEEK
, labelText
);
1275 labelText
.Format(IDS_STATGRAPH_COMMITSBYUNIT
, GetUnitString());
1276 SetDlgItemText(IDC_COMMITSEACHWEEK
, labelText
);
1277 labelText
.Format(IDS_STATGRAPH_FILECHANGESBYUNIT
, GetUnitString());
1278 SetDlgItemText(IDC_FILECHANGESEACHWEEK
, labelText
);
1279 // We have now all data we want and we can fill in the labels...
1281 number
.Format(_T("%d"), nWeeks
);
1282 SetDlgItemText(IDC_NUMWEEKVALUE
, number
);
1283 number
.Format(_T("%Iu"), nAuthors
);
1284 SetDlgItemText(IDC_NUMAUTHORVALUE
, number
);
1285 number
.Format(_T("%Id"), m_nTotalCommits
);
1286 SetDlgItemText(IDC_NUMCOMMITSVALUE
, number
);
1287 number
.Format(_T("%ld"), m_nTotalFileChanges
);
1289 SetDlgItemText(IDC_NUMFILECHANGESVALUE
, number
);
1291 number
.Format(_T("%Id"), m_parAuthors
.GetCount() / nWeeks
);
1292 SetDlgItemText(IDC_COMMITSEACHWEEKAVG
, number
);
1293 number
.Format(_T("%ld"), nCommitsMax
);
1294 SetDlgItemText(IDC_COMMITSEACHWEEKMAX
, number
);
1295 number
.Format(_T("%ld"), nCommitsMin
);
1296 SetDlgItemText(IDC_COMMITSEACHWEEKMIN
, number
);
1298 number
.Format(_T("%ld"), m_nTotalFileChanges
/ nWeeks
);
1299 //SetDlgItemText(IDC_FILECHANGESEACHWEEKAVG, number);
1300 number
.Format(_T("%ld"), nFileChangesMax
);
1301 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMAX, number);
1302 number
.Format(_T("%ld"), nFileChangesMin
);
1303 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMIN, number);
1305 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
, m_nTotalLinesInc
, m_nTotalLinesDec
);
1307 SetDlgItemText(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
, number
);
1308 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
+ m_nTotalLinesNew
+ m_nTotalLinesDel
,
1309 m_nTotalLinesInc
+ m_nTotalLinesNew
, m_nTotalLinesDec
+ m_nTotalLinesDel
);
1311 SetDlgItemText(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
, number
);
1315 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, _T(""));
1316 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, _T("0"));
1317 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, _T("0"));
1318 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, _T("0"));
1319 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, _T(""));
1320 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, _T("0"));
1321 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, _T("0"));
1322 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, _T("0"));
1326 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, mostActiveAuthor
.c_str());
1327 number
.Format(_T("%ld"), m_commitsPerAuthor
[mostActiveAuthor
] / nWeeks
);
1328 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, number
);
1329 number
.Format(_T("%ld"), nMostActiveMaxCommits
);
1330 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, number
);
1331 number
.Format(_T("%ld"), nMostActiveMinCommits
);
1332 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, number
);
1334 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, leastActiveAuthor
.c_str());
1335 number
.Format(_T("%ld"), m_commitsPerAuthor
[leastActiveAuthor
] / nWeeks
);
1336 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, number
);
1337 number
.Format(_T("%ld"), nLeastActiveMaxCommits
);
1338 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, number
);
1339 number
.Format(_T("%ld"), nLeastActiveMinCommits
);
1340 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, number
);
1344 int CStatGraphDlg::RollPercentageOfAuthorship(double it
)
1345 { return (int)it
+ (it
- (int)it
>= 0.5);}
1347 void CStatGraphDlg::OnCbnSelchangeGraphcombo()
1351 Metrics useMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1357 m_btnGraphLine
.EnableWindow(TRUE
);
1358 m_btnGraphLineStacked
.EnableWindow(TRUE
);
1359 m_btnGraphPie
.EnableWindow(TRUE
);
1360 m_GraphType
= MyGraph::Line
;
1363 case PercentageOfAuthorship
:
1364 case CommitsByAuthor
:
1366 m_btnGraphLine
.EnableWindow(FALSE
);
1367 m_btnGraphLineStacked
.EnableWindow(FALSE
);
1368 m_btnGraphPie
.EnableWindow(TRUE
);
1369 m_GraphType
= MyGraph::Bar
;
1377 int CStatGraphDlg::GetUnitCount()
1384 return (m_nWeeks
/4)+1;
1386 return (m_nWeeks
/13)+1; // quarters
1387 return (m_nWeeks
/52)+1;
1390 int CStatGraphDlg::GetUnit(const CTime
& time
)
1393 return time
.GetMonth()*100 + time
.GetDay(); // month*100+day as the unit
1395 return GetCalendarWeek(time
);
1397 return time
.GetMonth();
1399 return ((time
.GetMonth()-1)/3)+1; // quarters
1400 return time
.GetYear();
1403 CStatGraphDlg::UnitType
CStatGraphDlg::GetUnitType()
1416 CString
CStatGraphDlg::GetUnitString()
1419 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXDAY
));
1421 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXWEEK
));
1423 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXMONTH
));
1425 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXQUARTER
));
1426 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXYEAR
));
1429 CString
CStatGraphDlg::GetUnitLabel(int unit
, CTime
&lasttime
)
1432 switch (GetUnitType())
1436 // month*100+day as the unit
1437 int day
= unit
% 100;
1438 int month
= unit
/ 100;
1439 switch (m_langOrder
)
1441 case 0: // month day year
1442 temp
.Format(_T("%d/%d/%.2d"), month
, day
, lasttime
.GetYear()%100);
1444 case 1: // day month year
1446 temp
.Format(_T("%d/%d/%.2d"), day
, month
, lasttime
.GetYear()%100);
1448 case 2: // year month day
1449 temp
.Format(_T("%.2d/%d/%d"), lasttime
.GetYear()%100, month
, day
);
1456 int year
= lasttime
.GetYear();
1457 if ((unit
== 1)&&(lasttime
.GetMonth() == 12))
1460 switch (m_langOrder
)
1462 case 0: // month day year
1463 case 1: // day month year
1465 temp
.Format(_T("%d/%.2d"), unit
, year
%100);
1467 case 2: // year month day
1468 temp
.Format(_T("%.2d/%d"), year
%100, unit
);
1474 switch (m_langOrder
)
1476 case 0: // month day year
1477 case 1: // day month year
1479 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1481 case 2: // year month day
1482 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1487 switch (m_langOrder
)
1489 case 0: // month day year
1490 case 1: // day month year
1492 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1494 case 2: // year month day
1495 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1500 temp
.Format(_T("%d"), unit
);
1506 void CStatGraphDlg::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
1508 if (nSBCode
== TB_THUMBTRACK
)
1509 return CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1511 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1512 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1515 void CStatGraphDlg::OnNeedText(NMHDR
*pnmh
, LRESULT
* /*pResult*/)
1517 TOOLTIPTEXT
* pttt
= (TOOLTIPTEXT
*) pnmh
;
1518 if (pttt
->hdr
.idFrom
== (UINT_PTR
) m_Skipper
.GetSafeHwnd())
1520 size_t included_authors_count
= m_Skipper
.GetPos();
1521 // if we only leave out one author, still include him with his name
1522 if (included_authors_count
+ 1 == m_authorNames
.size())
1523 ++included_authors_count
;
1525 // find the minimum number of commits that the shown authors have
1526 int min_commits
= 0;
1527 included_authors_count
= min(included_authors_count
, m_authorNames
.size());
1528 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
1529 advance(author_it
, included_authors_count
);
1530 if (author_it
!= m_authorNames
.begin())
1531 min_commits
= m_commitsPerAuthor
[ *(--author_it
) ];
1534 int percentage
= int(min_commits
*100.0/(m_nTotalCommits
? m_nTotalCommits
: 1));
1535 string
.Format(IDS_STATGRAPH_AUTHORSLIDER_TT
, m_Skipper
.GetPos(), min_commits
, percentage
);
1536 StringCchCopy(pttt
->szText
, _countof(pttt
->szText
), (LPCTSTR
) string
);
1540 void CStatGraphDlg::AuthorsCaseSensitiveChanged()
1542 UpdateData(); // update checkbox state
1543 GatherData(FALSE
, TRUE
); // first regenerate the statistics data
1544 RedrawGraph(); // then update the current statistics page
1547 void CStatGraphDlg::SortModeChanged()
1549 UpdateData(); // update checkbox state
1550 RedrawGraph(); // then update the current statistics page
1553 void CStatGraphDlg::ClearGraph()
1556 for (int j
=0; j
<m_graphDataArray
.GetCount(); ++j
)
1557 delete ((MyGraphSeries
*)m_graphDataArray
.GetAt(j
));
1558 m_graphDataArray
.RemoveAll();
1561 void CStatGraphDlg::RedrawGraph()
1563 EnableDisableMenu();
1564 m_btnGraphBar
.SetState(BST_UNCHECKED
);
1565 m_btnGraphBarStacked
.SetState(BST_UNCHECKED
);
1566 m_btnGraphLine
.SetState(BST_UNCHECKED
);
1567 m_btnGraphLineStacked
.SetState(BST_UNCHECKED
);
1568 m_btnGraphPie
.SetState(BST_UNCHECKED
);
1570 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1572 m_btnGraphBarStacked
.SetState(BST_CHECKED
);
1574 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1576 m_btnGraphBar
.SetState(BST_CHECKED
);
1578 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1580 m_btnGraphLineStacked
.SetState(BST_CHECKED
);
1582 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1584 m_btnGraphLine
.SetState(BST_CHECKED
);
1586 if (m_GraphType
== MyGraph::PieChart
)
1588 m_btnGraphPie
.SetState(BST_CHECKED
);
1592 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()), true);
1594 void CStatGraphDlg::OnBnClickedGraphbarbutton()
1596 m_GraphType
= MyGraph::Bar
;
1601 void CStatGraphDlg::OnBnClickedGraphbarstackedbutton()
1603 m_GraphType
= MyGraph::Bar
;
1608 void CStatGraphDlg::OnBnClickedGraphlinebutton()
1610 m_GraphType
= MyGraph::Line
;
1615 void CStatGraphDlg::OnBnClickedGraphlinestackedbutton()
1617 m_GraphType
= MyGraph::Line
;
1622 void CStatGraphDlg::OnBnClickedGraphpiebutton()
1624 m_GraphType
= MyGraph::PieChart
;
1629 BOOL
CStatGraphDlg::PreTranslateMessage(MSG
* pMsg
)
1631 if (NULL
!= m_pToolTip
)
1632 m_pToolTip
->RelayEvent(pMsg
);
1634 return CStandAloneDialogTmpl
<CResizableDialog
>::PreTranslateMessage(pMsg
);
1637 void CStatGraphDlg::EnableDisableMenu()
1639 UINT nEnable
= MF_BYCOMMAND
;
1641 Metrics SelectMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1643 nEnable
|= (SelectMetric
> TextStatStart
&& SelectMetric
< TextStatEnd
)
1644 ? (MF_DISABLED
| MF_GRAYED
) : MF_ENABLED
;
1646 GetMenu()->EnableMenuItem(ID_FILE_SAVESTATGRAPHAS
, nEnable
);
1649 void CStatGraphDlg::OnFileSavestatgraphas()
1652 int filterindex
= 0;
1653 if (CAppUtils::FileOpenSave(tempfile
, &filterindex
, IDS_REVGRAPH_SAVEPIC
, IDS_STATPICFILEFILTER
, false, m_hWnd
))
1655 // if the user doesn't specify a file extension, default to
1656 // wmf and add that extension to the filename. But only if the
1657 // user chose the 'pictures' filter. The filename isn't changed
1658 // if the 'All files' filter was chosen.
1660 int dotPos
= tempfile
.ReverseFind('.');
1661 int slashPos
= tempfile
.ReverseFind('\\');
1662 if (dotPos
> slashPos
)
1663 extension
= tempfile
.Mid(dotPos
);
1664 if ((filterindex
== 1)&&(extension
.IsEmpty()))
1666 extension
= _T(".wmf");
1667 tempfile
+= extension
;
1669 SaveGraph(tempfile
);
1673 void CStatGraphDlg::SaveGraph(CString sFilename
)
1675 CString extension
= CPathUtils::GetFileExtFromPath(sFilename
);
1676 if (extension
.CompareNoCase(_T(".wmf"))==0)
1678 // save the graph as an enhanced meta file
1679 CMyMetaFileDC wmfDC
;
1680 wmfDC
.CreateEnhanced(NULL
, sFilename
, NULL
, _T("TortoiseGit\0Statistics\0\0"));
1681 wmfDC
.SetAttribDC(GetDC()->GetSafeHdc());
1683 m_graph
.DrawGraph(wmfDC
);
1684 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
1685 DeleteEnhMetaFile(hemf
);
1689 // save the graph as a pixel picture instead of a vector picture
1690 // create dc to paint on
1693 CWindowDC
ddc(this);
1695 if (!dc
.CreateCompatibleDC(&ddc
))
1701 GetDlgItem(IDC_GRAPH
)->GetClientRect(&rect
);
1702 HBITMAP hbm
= ::CreateCompatibleBitmap(ddc
.m_hDC
, rect
.Width(), rect
.Height());
1708 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1709 // paint the whole graph
1711 m_graph
.DrawGraph(dc
);
1712 // now use GDI+ to save the picture
1714 GdiplusStartupInput gdiplusStartupInput
;
1715 ULONG_PTR gdiplusToken
;
1716 CString sErrormessage
;
1717 if (GdiplusStartup( &gdiplusToken
, &gdiplusStartupInput
, NULL
)==Ok
)
1720 Bitmap
bitmap(hbm
, NULL
);
1721 if (bitmap
.GetLastStatus()==Ok
)
1723 // Get the CLSID of the encoder.
1725 if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".png"))==0)
1726 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1727 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpg"))==0)
1728 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1729 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpeg"))==0)
1730 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1731 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".bmp"))==0)
1732 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1733 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".gif"))==0)
1734 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1737 sFilename
+= _T(".jpg");
1738 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1742 CStringW tfile
= CStringW(sFilename
);
1743 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1747 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, CPathUtils::GetFileExtFromPath(sFilename
));
1752 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1755 GdiplusShutdown(gdiplusToken
);
1759 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_GDIINIT
);
1761 dc
.SelectObject(oldbm
);
1763 if (!sErrormessage
.IsEmpty())
1765 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseGit"), MB_ICONERROR
);
1768 catch (CException
* pE
)
1770 TCHAR szErrorMsg
[2048] = { 0 };
1771 pE
->GetErrorMessage(szErrorMsg
, 2048);
1773 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseGit"), MB_ICONERROR
);
1778 int CStatGraphDlg::GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
)
1780 UINT num
= 0; // number of image encoders
1781 UINT size
= 0; // size of the image encoder array in bytes
1783 ImageCodecInfo
* pImageCodecInfo
= NULL
;
1785 if (GetImageEncodersSize(&num
, &size
)!=Ok
)
1788 return -1; // Failure
1790 pImageCodecInfo
= (ImageCodecInfo
*)(malloc(size
));
1791 if (pImageCodecInfo
== NULL
)
1792 return -1; // Failure
1794 if (GetImageEncoders(num
, size
, pImageCodecInfo
)==Ok
)
1796 for (UINT j
= 0; j
< num
; ++j
)
1798 if (wcscmp(pImageCodecInfo
[j
].MimeType
, format
) == 0)
1800 *pClsid
= pImageCodecInfo
[j
].Clsid
;
1801 free(pImageCodecInfo
);
1802 return j
; // Success
1806 free (pImageCodecInfo
);
1807 return -1; // Failure
1810 void CStatGraphDlg::StoreCurrentGraphType()
1813 DWORD graphtype
= static_cast<DWORD
>(m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1814 // encode the current chart type
1815 DWORD statspage
= graphtype
*10;
1816 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1820 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1824 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1828 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1832 if (m_GraphType
== MyGraph::PieChart
)
1837 // store current chart type in registry
1838 CRegDWORD
lastStatsPage(_T("Software\\TortoiseGit\\LastViewedStatsPage"), 0);
1839 lastStatsPage
= statspage
;
1841 CRegDWORD
regAuthors(_T("Software\\TortoiseGit\\StatAuthorsCaseSensitive"));
1842 regAuthors
= m_bAuthorsCaseSensitive
;
1844 CRegDWORD
regSort(_T("Software\\TortoiseGit\\StatSortByCommitCount"));
1845 regSort
= m_bSortByCommitCount
;
1848 void CStatGraphDlg::ShowErrorMessage()
1850 CFormatMessageWrapper errorDetails
;
1852 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1855 void CStatGraphDlg::ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
/* = false */)
1857 switch (SelectedMetric
)
1860 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1864 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1865 ShowByDate(IDS_STATGRAPH_COMMITSBYDATEY
, IDS_STATGRAPH_COMMITSBYDATE
, m_commitsPerUnitAndAuthor
);
1868 OnBnClickedFetchDiff();
1869 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1870 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_W_Y
, IDS_STATGRAPH_LINES_BYDATE_W
, m_LinesWPerUnitAndAuthor
);
1873 OnBnClickedFetchDiff();
1874 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1875 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_WO_Y
, IDS_STATGRAPH_LINES_BYDATE_WO
, m_LinesWOPerUnitAndAuthor
);
1877 case CommitsByAuthor
:
1878 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1879 ShowCommitsByAuthor();
1881 case PercentageOfAuthorship
:
1882 OnBnClickedFetchDiff();
1883 LoadListOfAuthors(m_PercentageOfAuthorship
, reloadSkiper
, true);
1884 ShowPercentageOfAuthorship();
1891 double CStatGraphDlg::CoeffContribution(int distFromEnd
) { return distFromEnd
? 1.0 / m_CoeffAuthorShip
* distFromEnd
: 1;}
1894 template <class MAP
>
1895 void CStatGraphDlg::DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
)
1898 for (std::list
<tstring
>::const_iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1900 nCommits
+= RollPercentageOfAuthorship(map
[*it
]);
1904 temp
.Format(_T(" (%Iu)"), others
.size());
1906 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1908 int group
= m_graph
.AppendGroup(sOthers
);
1909 graphData
->SetData(group
, (int)nCommits
);
1913 template <class MAP
>
1914 void CStatGraphDlg::LoadListOfAuthors (MAP
&map
, bool reloadSkiper
/*= false*/, bool compare
/*= false*/)
1916 m_authorNames
.clear();
1919 for (MAP::const_iterator it
= map
.begin(); it
!= map
.end(); ++it
)
1921 if ((compare
&& RollPercentageOfAuthorship(map
[it
->first
]) != 0) || !compare
)
1922 m_authorNames
.push_back(it
->first
);
1926 // Sort the list of authors based on commit count
1927 m_authorNames
.sort(MoreCommitsThan
< MAP::referent_type
>(map
));
1930 SetSkipper(reloadSkiper
);
1934 void CStatGraphDlg::OnBnClickedFetchDiff()
1938 if (GatherData(TRUE
))
1940 this->m_bDiffFetched
= TRUE
;
1941 GetDlgItem(IDC_CALC_DIFF
)->ShowWindow(!m_bDiffFetched
);