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"
38 using namespace Gdiplus
;
40 // BinaryPredicate for comparing authors based on their commit count
41 template<class DataType
>
42 class MoreCommitsThan
: public std::binary_function
<tstring
, tstring
, bool> {
44 typedef std::map
<tstring
, DataType
> MapType
;
45 MoreCommitsThan(MapType
&author_commits
) : m_authorCommits(author_commits
) {}
47 bool operator()(const tstring
& lhs
, const tstring
& rhs
) {
48 return (m_authorCommits
)[lhs
] > (m_authorCommits
)[rhs
];
52 MapType
&m_authorCommits
;
56 IMPLEMENT_DYNAMIC(CStatGraphDlg
, CResizableStandAloneDialog
)
57 CStatGraphDlg::CStatGraphDlg(CWnd
* pParent
/*=NULL*/)
58 : CResizableStandAloneDialog(CStatGraphDlg::IDD
, pParent
)
60 , m_GraphType(MyGraph::Bar
)
61 , m_bAuthorsCaseSensitive(TRUE
)
62 , m_bSortByCommitCount(TRUE
)
73 , m_bDiffFetched(FALSE
)
79 CStatGraphDlg::~CStatGraphDlg()
85 void CStatGraphDlg::OnOK() {
86 StoreCurrentGraphType();
90 void CStatGraphDlg::OnCancel() {
91 StoreCurrentGraphType();
95 void CStatGraphDlg::DoDataExchange(CDataExchange
* pDX
)
97 CResizableStandAloneDialog::DoDataExchange(pDX
);
98 DDX_Control(pDX
, IDC_GRAPH
, m_graph
);
99 DDX_Control(pDX
, IDC_GRAPHCOMBO
, m_cGraphType
);
100 DDX_Control(pDX
, IDC_SKIPPER
, m_Skipper
);
101 DDX_Check(pDX
, IDC_AUTHORSCASESENSITIVE
, m_bAuthorsCaseSensitive
);
102 DDX_Check(pDX
, IDC_SORTBYCOMMITCOUNT
, m_bSortByCommitCount
);
103 DDX_Control(pDX
, IDC_GRAPHBARBUTTON
, m_btnGraphBar
);
104 DDX_Control(pDX
, IDC_GRAPHBARSTACKEDBUTTON
, m_btnGraphBarStacked
);
105 DDX_Control(pDX
, IDC_GRAPHLINEBUTTON
, m_btnGraphLine
);
106 DDX_Control(pDX
, IDC_GRAPHLINESTACKEDBUTTON
, m_btnGraphLineStacked
);
107 DDX_Control(pDX
, IDC_GRAPHPIEBUTTON
, m_btnGraphPie
);
111 BEGIN_MESSAGE_MAP(CStatGraphDlg
, CResizableStandAloneDialog
)
112 ON_CBN_SELCHANGE(IDC_GRAPHCOMBO
, OnCbnSelchangeGraphcombo
)
114 ON_NOTIFY(TTN_NEEDTEXT
, NULL
, OnNeedText
)
115 ON_BN_CLICKED(IDC_AUTHORSCASESENSITIVE
, &CStatGraphDlg::AuthorsCaseSensitiveChanged
)
116 ON_BN_CLICKED(IDC_SORTBYCOMMITCOUNT
, &CStatGraphDlg::SortModeChanged
)
117 ON_BN_CLICKED(IDC_GRAPHBARBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarbutton
)
118 ON_BN_CLICKED(IDC_GRAPHBARSTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarstackedbutton
)
119 ON_BN_CLICKED(IDC_GRAPHLINEBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinebutton
)
120 ON_BN_CLICKED(IDC_GRAPHLINESTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinestackedbutton
)
121 ON_BN_CLICKED(IDC_GRAPHPIEBUTTON
, &CStatGraphDlg::OnBnClickedGraphpiebutton
)
122 ON_COMMAND(ID_FILE_SAVESTATGRAPHAS
, &CStatGraphDlg::OnFileSavestatgraphas
)
123 ON_BN_CLICKED(IDC_CALC_DIFF
, &CStatGraphDlg::OnBnClickedFetchDiff
)
126 void CStatGraphDlg::LoadStatQueries (__in UINT curStr
, Metrics loadMetric
, bool setDef
/* = false */)
129 temp
.LoadString(curStr
);
130 int sel
= m_cGraphType
.AddString(temp
);
131 m_cGraphType
.SetItemData(sel
, loadMetric
);
133 if (setDef
) m_cGraphType
.SetCurSel(sel
);
136 void CStatGraphDlg::SetSkipper (bool reloadSkiper
)
138 // We need to limit the number of authors due to GUI resource limitation.
139 // However, since author #251 will properly have < 1000th of the commits,
140 // the resolution limit of the screen will already not allow for displaying
141 // it in a reasonable way
143 int max_authors_count
= max(1, (int)min(m_authorNames
.size(), 250) );
144 m_Skipper
.SetRange (1, max_authors_count
);
145 m_Skipper
.SetPageSize(5);
148 m_Skipper
.SetPos (max_authors_count
);
151 BOOL
CStatGraphDlg::OnInitDialog()
153 CResizableStandAloneDialog::OnInitDialog();
155 // gather statistics data, only needs to be updated when the checkbox with
156 // the case sensitivity of author names is changed
159 m_pToolTip
= new CToolTipCtrl
;
160 if (m_pToolTip
->Create(this))
162 m_pToolTip
->AddTool(&m_btnGraphPie
, IDS_STATGRAPH_PIEBUTTON_TT
);
163 m_pToolTip
->AddTool(&m_btnGraphLineStacked
, IDS_STATGRAPH_LINESTACKEDBUTTON_TT
);
164 m_pToolTip
->AddTool(&m_btnGraphLine
, IDS_STATGRAPH_LINEBUTTON_TT
);
165 m_pToolTip
->AddTool(&m_btnGraphBarStacked
, IDS_STATGRAPH_BARSTACKEDBUTTON_TT
);
166 m_pToolTip
->AddTool(&m_btnGraphBar
, IDS_STATGRAPH_BARBUTTON_TT
);
168 m_pToolTip
->Activate(TRUE
);
171 m_bAuthorsCaseSensitive
= DWORD(CRegDWORD(_T("Software\\TortoiseGit\\StatAuthorsCaseSensitive")));
172 m_bSortByCommitCount
= DWORD(CRegDWORD(_T("Software\\TortoiseGit\\StatSortByCommitCount")));
175 //Load statistical queries
176 LoadStatQueries(IDS_STATGRAPH_STATS
, AllStat
, true);
177 LoadStatQueries(IDS_STATGRAPH_COMMITSBYDATE
, CommitsByDate
);
178 LoadStatQueries(IDS_STATGRAPH_COMMITSBYAUTHOR
, CommitsByAuthor
);
179 LoadStatQueries(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
, PercentageOfAuthorship
);
180 LoadStatQueries(IDS_STATGRAPH_LINES_BYDATE_W
, LinesWByDate
);
181 LoadStatQueries(IDS_STATGRAPH_LINES_BYDATE_WO
, LinesWOByDate
);
183 // set the dialog title to "Statistics - path/to/whatever/we/show/the/statistics/for"
185 GetWindowText(sTitle
);
186 CAppUtils::SetWindowTitle(m_hWnd
, m_path
.GetUIPathString(), sTitle
);
188 m_btnGraphBar
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBAR
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
189 m_btnGraphBar
.SizeToContent();
190 m_btnGraphBar
.Invalidate();
191 m_btnGraphBarStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBARSTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
192 m_btnGraphBarStacked
.SizeToContent();
193 m_btnGraphBarStacked
.Invalidate();
194 m_btnGraphLine
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
195 m_btnGraphLine
.SizeToContent();
196 m_btnGraphLine
.Invalidate();
197 m_btnGraphLineStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINESTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
198 m_btnGraphLineStacked
.SizeToContent();
199 m_btnGraphLineStacked
.Invalidate();
200 m_btnGraphPie
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHPIE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
201 m_btnGraphPie
.SizeToContent();
202 m_btnGraphPie
.Invalidate();
204 AddAnchor(IDC_GRAPHTYPELABEL
, TOP_LEFT
);
205 AddAnchor(IDC_GRAPH
, TOP_LEFT
, BOTTOM_RIGHT
);
206 AddAnchor(IDC_GRAPHCOMBO
, TOP_LEFT
, TOP_RIGHT
);
208 AddAnchor(IDC_NUMWEEK
, TOP_LEFT
);
209 AddAnchor(IDC_NUMWEEKVALUE
, TOP_RIGHT
);
210 AddAnchor(IDC_NUMAUTHOR
, TOP_LEFT
);
211 AddAnchor(IDC_NUMAUTHORVALUE
, TOP_RIGHT
);
212 AddAnchor(IDC_NUMCOMMITS
, TOP_LEFT
);
213 AddAnchor(IDC_NUMCOMMITSVALUE
, TOP_RIGHT
);
214 AddAnchor(IDC_NUMFILECHANGES
, TOP_LEFT
);
215 AddAnchor(IDC_NUMFILECHANGESVALUE
, TOP_RIGHT
);
217 AddAnchor(IDC_TOTAL_LINE_WITHOUT_NEW_DEL
, TOP_LEFT
);
218 AddAnchor(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
, TOP_RIGHT
);
219 AddAnchor(IDC_TOTAL_LINE_WITH_NEW_DEL
, TOP_LEFT
);
220 AddAnchor(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
, TOP_RIGHT
);
222 AddAnchor(IDC_CALC_DIFF
, TOP_RIGHT
);
224 AddAnchor(IDC_AVG
, TOP_RIGHT
);
225 AddAnchor(IDC_MIN
, TOP_RIGHT
);
226 AddAnchor(IDC_MAX
, TOP_RIGHT
);
227 AddAnchor(IDC_COMMITSEACHWEEK
, TOP_LEFT
);
228 AddAnchor(IDC_MOSTACTIVEAUTHOR
, TOP_LEFT
);
229 AddAnchor(IDC_LEASTACTIVEAUTHOR
, TOP_LEFT
);
230 AddAnchor(IDC_MOSTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
231 AddAnchor(IDC_LEASTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
232 AddAnchor(IDC_FILECHANGESEACHWEEK
, TOP_LEFT
);
233 AddAnchor(IDC_COMMITSEACHWEEKAVG
, TOP_RIGHT
);
234 AddAnchor(IDC_COMMITSEACHWEEKMIN
, TOP_RIGHT
);
235 AddAnchor(IDC_COMMITSEACHWEEKMAX
, TOP_RIGHT
);
236 AddAnchor(IDC_MOSTACTIVEAUTHORAVG
, TOP_RIGHT
);
237 AddAnchor(IDC_MOSTACTIVEAUTHORMIN
, TOP_RIGHT
);
238 AddAnchor(IDC_MOSTACTIVEAUTHORMAX
, TOP_RIGHT
);
239 AddAnchor(IDC_LEASTACTIVEAUTHORAVG
, TOP_RIGHT
);
240 AddAnchor(IDC_LEASTACTIVEAUTHORMIN
, TOP_RIGHT
);
241 AddAnchor(IDC_LEASTACTIVEAUTHORMAX
, TOP_RIGHT
);
242 AddAnchor(IDC_FILECHANGESEACHWEEKAVG
, TOP_RIGHT
);
243 AddAnchor(IDC_FILECHANGESEACHWEEKMIN
, TOP_RIGHT
);
244 AddAnchor(IDC_FILECHANGESEACHWEEKMAX
, TOP_RIGHT
);
246 AddAnchor(IDC_GRAPHBARBUTTON
, BOTTOM_RIGHT
);
247 AddAnchor(IDC_GRAPHBARSTACKEDBUTTON
, BOTTOM_RIGHT
);
248 AddAnchor(IDC_GRAPHLINEBUTTON
, BOTTOM_RIGHT
);
249 AddAnchor(IDC_GRAPHLINESTACKEDBUTTON
, BOTTOM_RIGHT
);
250 AddAnchor(IDC_GRAPHPIEBUTTON
, BOTTOM_RIGHT
);
252 AddAnchor(IDC_AUTHORSCASESENSITIVE
, BOTTOM_LEFT
);
253 AddAnchor(IDC_SORTBYCOMMITCOUNT
, BOTTOM_LEFT
);
254 AddAnchor(IDC_SKIPPER
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
255 AddAnchor(IDC_SKIPPERLABEL
, BOTTOM_LEFT
);
256 AddAnchor(IDOK
, BOTTOM_RIGHT
);
257 EnableSaveRestore(_T("StatGraphDlg"));
259 // set the min/max values on the skipper
262 // we use a stats page encoding here, 0 stands for the statistics dialog
263 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseGit\\LastViewedStatsPage"), 0);
265 // open last viewed statistics page as first page
266 int graphtype
= lastStatsPage
/ 10;
267 for (int i
= 0; i
< m_cGraphType
.GetCount(); i
++)
269 if ((int)m_cGraphType
.GetItemData(i
) == graphtype
)
271 m_cGraphType
.SetCurSel(i
);
276 OnCbnSelchangeGraphcombo();
278 int statspage
= lastStatsPage
% 10;
281 m_GraphType
= MyGraph::Bar
;
285 m_GraphType
= MyGraph::Bar
;
289 m_GraphType
= MyGraph::Line
;
293 m_GraphType
= MyGraph::Line
;
297 m_GraphType
= MyGraph::PieChart
;
300 default : return TRUE
;
303 LCID m_locale
= MAKELCID((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
)), SORT_DEFAULT
);
305 bool bUseSystemLocale
= !!(DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
);
306 LCID locale
= bUseSystemLocale
? MAKELCID(MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), SORT_DEFAULT
) : m_locale
;
309 memset(langBuf
, 0, sizeof(langBuf
));
310 GetLocaleInfo(locale
, LOCALE_IDATE
, langBuf
, _countof(langBuf
));
312 m_langOrder
= _ttoi(langBuf
);
317 void CStatGraphDlg::ShowLabels(BOOL bShow
)
319 if (m_parAuthors
.IsEmpty() || m_parDates
.IsEmpty() || m_parFileChanges
.IsEmpty())
322 int nCmdShow
= bShow
? SW_SHOW
: SW_HIDE
;
324 GetDlgItem(IDC_GRAPH
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
325 GetDlgItem(IDC_NUMWEEK
)->ShowWindow(nCmdShow
);
326 GetDlgItem(IDC_NUMWEEKVALUE
)->ShowWindow(nCmdShow
);
327 GetDlgItem(IDC_NUMAUTHOR
)->ShowWindow(nCmdShow
);
328 GetDlgItem(IDC_NUMAUTHORVALUE
)->ShowWindow(nCmdShow
);
329 GetDlgItem(IDC_NUMCOMMITS
)->ShowWindow(nCmdShow
);
330 GetDlgItem(IDC_NUMCOMMITSVALUE
)->ShowWindow(nCmdShow
);
331 GetDlgItem(IDC_NUMFILECHANGES
)->ShowWindow(nCmdShow
);
332 GetDlgItem(IDC_NUMFILECHANGESVALUE
)->ShowWindow(nCmdShow
);
333 GetDlgItem(IDC_TOTAL_LINE_WITHOUT_NEW_DEL
)->ShowWindow(nCmdShow
);
334 GetDlgItem(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
)->ShowWindow(nCmdShow
);
335 GetDlgItem(IDC_TOTAL_LINE_WITH_NEW_DEL
)->ShowWindow(nCmdShow
);
336 GetDlgItem(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
)->ShowWindow(nCmdShow
);
337 GetDlgItem(IDC_CALC_DIFF
)->ShowWindow(nCmdShow
&& !m_bDiffFetched
);
339 GetDlgItem(IDC_AVG
)->ShowWindow(nCmdShow
);
340 GetDlgItem(IDC_MIN
)->ShowWindow(nCmdShow
);
341 GetDlgItem(IDC_MAX
)->ShowWindow(nCmdShow
);
342 GetDlgItem(IDC_COMMITSEACHWEEK
)->ShowWindow(nCmdShow
);
343 GetDlgItem(IDC_MOSTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
344 GetDlgItem(IDC_LEASTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
345 GetDlgItem(IDC_MOSTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
346 GetDlgItem(IDC_LEASTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
347 //GetDlgItem(IDC_FILECHANGESEACHWEEK)->ShowWindow(nCmdShow);
348 GetDlgItem(IDC_COMMITSEACHWEEKAVG
)->ShowWindow(nCmdShow
);
349 GetDlgItem(IDC_COMMITSEACHWEEKMIN
)->ShowWindow(nCmdShow
);
350 GetDlgItem(IDC_COMMITSEACHWEEKMAX
)->ShowWindow(nCmdShow
);
351 GetDlgItem(IDC_MOSTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
352 GetDlgItem(IDC_MOSTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
353 GetDlgItem(IDC_MOSTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
354 GetDlgItem(IDC_LEASTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
355 GetDlgItem(IDC_LEASTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
356 GetDlgItem(IDC_LEASTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
357 GetDlgItem(IDC_FILECHANGESEACHWEEKAVG
)->ShowWindow(nCmdShow
);
358 GetDlgItem(IDC_FILECHANGESEACHWEEKMIN
)->ShowWindow(nCmdShow
);
359 GetDlgItem(IDC_FILECHANGESEACHWEEKMAX
)->ShowWindow(nCmdShow
);
361 GetDlgItem(IDC_SORTBYCOMMITCOUNT
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
362 GetDlgItem(IDC_SKIPPER
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
363 GetDlgItem(IDC_SKIPPERLABEL
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
364 m_btnGraphBar
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
365 m_btnGraphBarStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
366 m_btnGraphLine
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
367 m_btnGraphLineStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
368 m_btnGraphPie
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
371 void CStatGraphDlg::UpdateWeekCount()
374 if (m_parDates
.IsEmpty())
377 // Already updated? No need to do it again.
381 // Determine first and last date in dates array
382 __time64_t min_date
= (__time64_t
)m_parDates
.GetAt(0);
383 __time64_t max_date
= min_date
;
384 INT_PTR count
= m_parDates
.GetCount();
385 for (INT_PTR i
=0; i
<count
; ++i
)
387 __time64_t d
= (__time64_t
)m_parDates
.GetAt(i
);
388 if (d
< min_date
) min_date
= d
;
389 else if (d
> max_date
) max_date
= d
;
392 // Store start date of the interval in the member variable m_minDate
393 m_minDate
= min_date
;
394 m_maxDate
= max_date
;
396 // How many weeks does the time period cover?
398 // Get time difference between start and end date
399 double secs
= _difftime64(max_date
, m_minDate
);
401 m_nWeeks
= (int)ceil(secs
/ (double) m_SecondsInWeek
);
402 m_nDays
= (int)ceil(secs
/ (double) m_SecondsInDay
);
405 int CStatGraphDlg::GetCalendarWeek(const CTime
& time
)
408 // the calculation of the calendar week is wrong if DST is in effect
409 // and the date to calculate the week for is in DST and within the range
410 // of the DST offset (e.g. one hour).
411 // For example, if DST starts on Sunday march 30 and the date to get the week for
412 // is Monday, march 31, 0:30:00, then the returned week is one week less than
416 // getDSTOffset(const CTime& time)
417 // which returns the DST offset for a given time/date. Then we can use this offset
418 // to correct our GetDays() calculation to get the correct week again
419 // This of course won't work for 'history' dates, because Windows doesn't have
420 // that information (only Vista has such a function: GetTimeZoneInformationForYear() )
423 int iYear
= time
.GetYear();
424 int iFirstDayOfWeek
= 0;
425 int iFirstWeekOfYear
= 0;
427 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, loc
, _countof(loc
));
428 iFirstDayOfWeek
= int(loc
[0]-'0');
429 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, loc
, _countof(loc
));
430 iFirstWeekOfYear
= int(loc
[0]-'0');
431 CTime
dDateFirstJanuary(iYear
,1,1,0,0,0);
432 int iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
435 // 0 Week containing 1/1 is the first week of that year.
436 // 1 First full week following 1/1 is the first week of that year.
437 // 2 First week containing at least four days is the first week of that year.
438 switch (iFirstWeekOfYear
)
442 // Week containing 1/1 is the first week of that year.
444 // check if this week reaches into the next year
445 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
450 iDayOfWeek
= (time
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
452 catch (CException
* e
)
456 CTime dStartOfWeek
= time
-CTimeSpan(iDayOfWeek
,0,0,0);
458 // If this week spans over to 1/1 this is week 1
459 if (dStartOfWeek
+ CTimeSpan(6,0,0,0) >= dDateFirstJanuary
)
461 // we are in the last week of the year that spans over 1/1
466 // Get week day of 1/1
467 dDateFirstJanuary
= CTime(iYear
,1,1,0,0,0);
468 iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek() +5 + iFirstDayOfWeek
) % 7;
469 // Just count from 1/1
470 iWeekOfYear
= (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) + 1;
476 // First full week following 1/1 is the first week of that year.
478 // If the 1.1 is the start of the week everything is ok
479 // else we need the next week is the correct result
481 (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) +
482 (iDayOfWeek
==0 ? 1:0);
484 // If we are in week 0 we are in the first not full week
485 // calculate from the last year
488 // Special case: we are in the week of 1.1 but 1.1. is not on the
489 // start of week. Calculate based on the last year
490 dDateFirstJanuary
= CTime(iYear
-1,1,1,0,0,0);
492 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
493 // and we correct this in the same we we done this before but
494 // the result is now 52 or 53 and not 0
496 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
497 (iDayOfWeek
<=3 ? 1:0);
503 // First week containing at least four days is the first week of that year.
505 // Each year can start with any day of the week. But our
506 // weeks always start with Monday. So we add the day of week
507 // before calculation of the final week of year.
508 // Rule: is the 1.1 a Mo,Tu,We,Th than the week starts on the 1.1 with
509 // week==1, else a week later, so we add one for all those days if
510 // day is less <=3 Mo,Tu,We,Th. Otherwise 1.1 is in the last week of the
513 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
514 (iDayOfWeek
<=3 ? 1:0);
519 // special case week 0. We got a day before the 1.1, 2.1 or 3.1, were the
520 // 1.1. is not a Mo, Tu, We, Th. So the week 1 does not start with the 1.1.
521 // So we calculate the week according to the 1.1 of the year before
523 dDateFirstJanuary
= CTime(iYear
-1,1,1,0,0,0);
525 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
526 // and we correct this in the same we we done this before but the result
527 // is now 52 or 53 and not 0
529 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
530 (iDayOfWeek
<=3 ? 1:0);
532 else if (iWeekOfYear
==53)
534 // special case week 53. Either we got the correct week 53 or we just got the
535 // week 1 of the next year. So is the 1.1.(year+1) also a Mo, Tu, We, Th than
536 // we already have the week 1, otherwise week 53 is correct
538 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
540 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
541 // 1.1. in week 1 or week 53?
542 iWeekOfYear
= iDayOfWeek
<=3 ? 1:53;
560 CCommitPointer():m_cont(NULL
){}
561 CCommitPointer(const CCommitPointer
& P_Right
)
567 CCommitPointer
& operator = (const CCommitPointer
& P_Right
)
571 (*m_cont
->m_parDates
)[m_place
] = P_Right
.GetDate();
572 (*m_cont
->m_parFileChanges
)[m_place
] = P_Right
.GetChanges();
573 (*m_cont
->m_parAuthors
)[m_place
] = P_Right
.GetAuthor();
574 (*m_cont
->m_lineInc
)[m_place
] = P_Right
.GetLineInc();
575 (*m_cont
->m_lineDec
)[m_place
] = P_Right
.GetLineDec();
576 (*m_cont
->m_lineNew
)[m_place
] = P_Right
.GetLineNew();
577 (*m_cont
->m_lineDel
)[m_place
] = P_Right
.GetLineDel();
581 m_Date
= P_Right
.GetDate();
582 m_Changes
= P_Right
.GetChanges();
583 m_csAuthor
= P_Right
.GetAuthor();
584 m_lineInc
= P_Right
.GetLineInc();
585 m_lineDec
= P_Right
.GetLineDec();
586 m_lineNew
= P_Right
.GetLineNew();
587 m_lineDel
= P_Right
.GetLineDel();
592 void Clone(const CCommitPointer
& P_Right
)
594 m_cont
= P_Right
.m_cont
;
595 m_place
= P_Right
.m_place
;
596 m_Date
= P_Right
.m_Date
;
597 m_Changes
= P_Right
.m_Changes
;
598 m_csAuthor
= P_Right
.m_csAuthor
;
601 DWORD
GetDate() const {return IsPointer() ? (*m_cont
->m_parDates
)[m_place
] : m_Date
;}
602 DWORD
GetChanges() const {return IsPointer() ? (*m_cont
->m_parFileChanges
)[m_place
] : m_Changes
;}
603 DWORD
GetLineInc() const {return IsPointer() ? (*m_cont
->m_lineInc
)[m_place
] : m_lineInc
;}
604 DWORD
GetLineDec() const {return IsPointer() ? (*m_cont
->m_lineDec
)[m_place
] : m_lineDec
;}
605 DWORD
GetLineNew() const {return IsPointer() ? (*m_cont
->m_lineNew
)[m_place
] : m_lineNew
;}
606 DWORD
GetLineDel() const {return IsPointer() ? (*m_cont
->m_lineDel
)[m_place
] : m_lineDel
;}
607 CString
GetAuthor() const {return IsPointer() ? (*m_cont
->m_parAuthors
)[m_place
] : m_csAuthor
;}
609 bool IsPointer() const {return m_cont
!= NULL
;}
624 class iterator
: public std::iterator
<std::random_access_iterator_tag
, CCommitPointer
>
627 CCommitPointer m_ptr
;
630 iterator(const iterator
& P_Right
){*this = P_Right
;}
631 iterator
& operator=(const iterator
& P_Right
)
633 m_ptr
.Clone(P_Right
.m_ptr
);
637 CCommitPointer
& operator*(){return m_ptr
;}
638 CCommitPointer
* operator->(){return &m_ptr
;}
639 const CCommitPointer
& operator*()const{return m_ptr
;}
640 const CCommitPointer
* operator->()const{return &m_ptr
;}
642 iterator
& operator+=(size_t P_iOffset
){m_ptr
.m_place
+= (int)P_iOffset
;return *this;}
643 iterator
& operator-=(size_t P_iOffset
){m_ptr
.m_place
-= (int)P_iOffset
;return *this;}
644 iterator
operator+(size_t P_iOffset
)const{iterator
it(*this); it
+= P_iOffset
;return it
;}
645 iterator
operator-(size_t P_iOffset
)const{iterator
it(*this); it
-= P_iOffset
;return it
;}
647 iterator
& operator++(){++m_ptr
.m_place
;return *this;}
648 iterator
& operator--(){--m_ptr
.m_place
;return *this;}
649 iterator
operator++(int){iterator
it(*this);++*this;return it
;}
650 iterator
operator--(int){iterator
it(*this);--*this;return it
;}
652 size_t operator-(const iterator
& P_itRight
)const{return m_ptr
.m_place
- P_itRight
->m_place
;}
654 bool operator<(const iterator
& P_itRight
)const{return m_ptr
.m_place
< P_itRight
->m_place
;}
655 bool operator!=(const iterator
& P_itRight
)const{return m_ptr
.m_place
!= P_itRight
->m_place
;}
656 bool operator==(const iterator
& P_itRight
)const{return m_ptr
.m_place
== P_itRight
->m_place
;}
657 bool operator>(const iterator
& P_itRight
)const{return m_ptr
.m_place
> P_itRight
->m_place
;}
669 it
->m_place
= (int)m_parDates
->GetCount();
674 CDWordArray
* m_parDates
;
675 CDWordArray
* m_parFileChanges
;
676 CDWordArray
* m_lineInc
;
677 CDWordArray
* m_lineDec
;
678 CDWordArray
* m_lineNew
;
679 CDWordArray
* m_lineDel
;
680 CStringArray
* m_parAuthors
;
683 class CDateSorterLess
686 bool operator () (const CDateSorter::CCommitPointer
& P_Left
, const CDateSorter::CCommitPointer
& P_Right
) const
688 return P_Left
.GetDate() > P_Right
.GetDate(); //Last date first
693 int CStatGraphDlg::GatherData(BOOL fetchdiff
)
695 m_parAuthors
.RemoveAll();
696 m_parDates
.RemoveAll();
697 m_parFileChanges
.RemoveAll();
698 m_lineInc
.RemoveAll();
699 m_lineDec
.RemoveAll();
700 m_lineDel
.RemoveAll();
701 m_lineNew
.RemoveAll();
703 CSysProgressDlg progress
;
706 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_GATHERSTATISTICS
)));
707 progress
.FormatNonPathLine(1, IDS_PROC_STATISTICS_DIFF
);
708 progress
.SetAnimation(IDR_MOVEANI
);
709 progress
.SetTime(true);
710 progress
.ShowModeless(this);
713 // create arrays which are aware of the current filter
714 DWORD starttime
= GetTickCount();
716 GIT_MAILMAP mailmap
= nullptr;
717 git_read_mailmap(&mailmap
);
718 for (INT_PTR i
= 0; i
< m_ShowList
.GetCount(); ++i
)
720 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_ShowList
.SafeGetAt(i
));
721 int inc
, dec
, incnewfile
, decdeletedfile
, files
;
722 inc
= dec
= incnewfile
= decdeletedfile
= files
= 0;
724 // do not take working dir changes into statistics
725 if (pLogEntry
->m_CommitHash
.IsEmpty()) {
729 CString strAuthor
= pLogEntry
->GetAuthorName();
730 if (strAuthor
.IsEmpty())
732 strAuthor
.LoadString(IDS_STATGRAPH_EMPTYAUTHOR
);
736 CStringA email2A
= CUnicodeUtils::GetUTF8(pLogEntry
->GetAuthorEmail());
737 struct payload_struct
{ GitRev
* rev
; const char *authorName
; };
738 payload_struct payload
= { pLogEntry
, nullptr };
739 const char *author1
= git_get_mailmap_author(mailmap
, email2A
, &payload
,
740 [] (void *payload
) -> const char * { return ((payload_struct
*)payload
)->authorName
= _strdup(CUnicodeUtils::GetUTF8(((payload_struct
*)payload
)->rev
->GetAuthorName())); });
741 if (payload
.authorName
)
742 free((void *)payload
.authorName
);
744 strAuthor
= CUnicodeUtils::GetUnicode(author1
);
746 m_parAuthors
.Add(strAuthor
);
747 m_parDates
.Add((DWORD
)pLogEntry
->GetCommitterDate().GetTime());
749 if (fetchdiff
&& (pLogEntry
->m_ParentHash
.size() <= 1))
751 CTGitPathList
&list
= pLogEntry
->GetFiles(NULL
);
752 files
= list
.GetCount();
754 for (int j
= 0; j
< files
; j
++)
756 if (list
[j
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
757 decdeletedfile
+= _tstol(list
[j
].m_StatDel
);
758 else if(list
[j
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
759 incnewfile
+= _tstol(list
[j
].m_StatAdd
);
762 inc
+= _tstol(list
[j
].m_StatAdd
);
763 dec
+= _tstol(list
[j
].m_StatDel
);
766 if (progress
.HasUserCancelled())
768 git_clear_mailmap(mailmap
);
773 m_parFileChanges
.Add(files
);
776 m_lineDel
.Add(decdeletedfile
);
777 m_lineNew
.Add(incnewfile
);
779 if (progress
.IsVisible() && (GetTickCount() - starttime
> 100))
781 progress
.FormatNonPathLine(2, _T("%s: %s"), pLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()), pLogEntry
->GetSubject());
782 progress
.SetProgress64(i
, m_ShowList
.GetCount());
783 starttime
= GetTickCount();
787 git_clear_mailmap(mailmap
);
789 CDateSorter W_Sorter
;
790 W_Sorter
.m_parAuthors
= &m_parAuthors
;
791 W_Sorter
.m_parDates
= &m_parDates
;
792 W_Sorter
.m_parFileChanges
= &m_parFileChanges
;
793 W_Sorter
.m_lineNew
= &m_lineNew
;
794 W_Sorter
.m_lineDel
= &m_lineDel
;
795 W_Sorter
.m_lineInc
= &m_lineInc
;
796 W_Sorter
.m_lineDec
= &m_lineDec
;
798 std::sort(W_Sorter
.begin(), W_Sorter
.end(), CDateSorterLess());
800 m_nTotalCommits
= m_parAuthors
.GetCount();
801 m_nTotalFileChanges
= 0;
803 // Update m_nWeeks and m_minDate
806 // Now create a mapping that holds the information per week.
807 m_commitsPerUnitAndAuthor
.clear();
808 m_filechangesPerUnitAndAuthor
.clear();
809 m_commitsPerAuthor
.clear();
810 m_PercentageOfAuthorship
.clear();
811 m_LinesWPerUnitAndAuthor
.clear();
812 m_LinesWOPerUnitAndAuthor
.clear();
815 __time64_t d
= (__time64_t
)m_parDates
.GetAt(0);
816 int nLastUnit
= GetUnit(d
);
817 double AllContributionAuthor
= 0;
819 m_nTotalLinesInc
= m_nTotalLinesDec
= m_nTotalLinesNew
= m_nTotalLinesDel
=0;
821 // Now loop over all weeks and gather the info
822 for (LONG i
=0; i
<m_nTotalCommits
; ++i
)
824 // Find the interval number
825 __time64_t commitDate
= (__time64_t
)m_parDates
.GetAt(i
);
826 int u
= GetUnit(commitDate
);
830 // Find the authors name
831 CString sAuth
= m_parAuthors
.GetAt(i
);
832 if (!m_bAuthorsCaseSensitive
)
833 sAuth
= sAuth
.MakeLower();
834 tstring author
= tstring(sAuth
);
835 // Increase total commit count for this author
836 m_commitsPerAuthor
[author
]++;
837 // Increase the commit count for this author in this week
838 m_commitsPerUnitAndAuthor
[interval
][author
]++;
840 m_LinesWPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
) + m_lineNew
.GetAt(i
) + + m_lineDel
.GetAt(i
);
841 m_LinesWOPerUnitAndAuthor
[interval
][author
] += m_lineInc
.GetAt(i
) + m_lineDec
.GetAt(i
);
843 CTime t
= m_parDates
.GetAt(i
);
844 m_unitNames
[interval
] = GetUnitLabel(nLastUnit
, t
);
845 // Increase the file change count for this author in this week
846 int fileChanges
= m_parFileChanges
.GetAt(i
);
847 m_filechangesPerUnitAndAuthor
[interval
][author
] += fileChanges
;
848 m_nTotalFileChanges
+= fileChanges
;
850 //calculate Contribution Author
851 double contributionAuthor
= CoeffContribution((int)m_nTotalCommits
- i
-1) * (fileChanges
? fileChanges
: 1);
852 AllContributionAuthor
+= contributionAuthor
;
853 m_PercentageOfAuthorship
[author
] += contributionAuthor
;
855 m_nTotalLinesInc
+= m_lineInc
.GetAt(i
);
856 m_nTotalLinesDec
+= m_lineDec
.GetAt(i
);
857 m_nTotalLinesNew
+= m_lineNew
.GetAt(i
);
858 m_nTotalLinesDel
+= m_lineDel
.GetAt(i
);
861 // Find first and last interval number.
862 if (!m_commitsPerUnitAndAuthor
.empty())
864 IntervalDataMap::iterator interval_it
= m_commitsPerUnitAndAuthor
.begin();
865 m_firstInterval
= interval_it
->first
;
866 interval_it
= m_commitsPerUnitAndAuthor
.end();
868 m_lastInterval
= interval_it
->first
;
869 // Sanity check - if m_lastInterval is too large it could freeze TSVN and take up all memory!!!
870 assert(m_lastInterval
>= 0 && m_lastInterval
< 10000);
878 // Get a list of authors names
879 LoadListOfAuthors(m_commitsPerAuthor
);
881 // Calculate percent of Contribution Authors
882 for (std::list
<tstring
>::iterator it
= m_authorNames
.begin(); it
!= m_authorNames
.end(); ++it
)
884 m_PercentageOfAuthorship
[*it
] = (m_PercentageOfAuthorship
[*it
] *100)/ AllContributionAuthor
;
887 // All done, now the statistics pages can retrieve the data and
888 // extract the information to be shown.
894 void CStatGraphDlg::FilterSkippedAuthors(std::list
<tstring
>& included_authors
,
895 std::list
<tstring
>& skipped_authors
)
897 included_authors
.clear();
898 skipped_authors
.clear();
900 unsigned int included_authors_count
= m_Skipper
.GetPos();
901 // if we only leave out one author, still include him with his name
902 if (included_authors_count
+ 1 == m_authorNames
.size())
903 ++included_authors_count
;
905 // add the included authors first
906 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
907 while (included_authors_count
> 0 && author_it
!= m_authorNames
.end())
909 // Add him/her to the included list
910 included_authors
.push_back(*author_it
);
912 --included_authors_count
;
915 // If we haven't reached the end yet, copy all remaining authors into the
916 // skipped author list.
917 std::copy(author_it
, m_authorNames
.end(), std::back_inserter(skipped_authors
) );
919 // Sort authors alphabetically if user wants that.
920 if (!m_bSortByCommitCount
)
921 included_authors
.sort();
924 bool CStatGraphDlg::PreViewStat(bool fShowLabels
)
926 if (m_parAuthors
.IsEmpty() || m_parDates
.IsEmpty() || m_parFileChanges
.IsEmpty())
928 ShowLabels(fShowLabels
);
931 if (!fShowLabels
) ClearGraph();
933 // This function relies on a previous call of GatherData().
934 // This can be detected by checking the week count.
935 // If the week count is equal to -1, it hasn't been called before.
938 // If week count is still -1, something bad has happened, probably invalid data!
945 MyGraphSeries
*CStatGraphDlg::PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
/*= NULL*/)
947 if(!PreViewStat(false))
950 // We need at least one author
951 if (m_authorNames
.empty())
954 // Add a single series to the chart
955 MyGraphSeries
* graphData
= new MyGraphSeries();
956 m_graph
.AddSeries(*graphData
);
957 m_graphDataArray
.Add(graphData
);
962 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
963 temp
.LoadString(YAxisLabel
);
964 m_graph
.SetYAxisLabel(temp
);
965 temp
.LoadString(XAxisLabel
);
966 m_graph
.SetXAxisLabel(temp
);
967 temp
.LoadString(GraphTitle
);
968 m_graph
.SetGraphTitle(temp
);
973 void CStatGraphDlg::ShowPercentageOfAuthorship()
976 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
,
977 IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIPY
,
978 IDS_STATGRAPH_COMMITSBYAUTHORX
);
979 if(graphData
== NULL
) return;
981 // Find out which authors are to be shown and which are to be skipped.
982 std::list
<tstring
> authors
;
983 std::list
<tstring
> others
;
986 FilterSkippedAuthors(authors
, others
);
988 // Loop over all authors in the authors list and
989 // add them to the graph.
991 if (!authors
.empty())
993 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
995 int group
= m_graph
.AppendGroup(it
->c_str());
996 graphData
->SetData(group
, RollPercentageOfAuthorship(m_PercentageOfAuthorship
[*it
]));
1000 // If we have other authors, count them and their commits.
1001 if (!others
.empty())
1002 DrawOthers(others
, graphData
, m_PercentageOfAuthorship
);
1004 // Paint the graph now that we're through.
1005 m_graph
.Invalidate();
1008 void CStatGraphDlg::ShowCommitsByAuthor()
1010 // Set up the graph.
1011 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_COMMITSBYAUTHOR
,
1012 IDS_STATGRAPH_COMMITSBYAUTHORY
,
1013 IDS_STATGRAPH_COMMITSBYAUTHORX
);
1014 if(graphData
== NULL
) return;
1016 // Find out which authors are to be shown and which are to be skipped.
1017 std::list
<tstring
> authors
;
1018 std::list
<tstring
> others
;
1019 FilterSkippedAuthors(authors
, others
);
1021 // Loop over all authors in the authors list and
1022 // add them to the graph.
1024 if (!authors
.empty())
1026 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1028 int group
= m_graph
.AppendGroup(it
->c_str());
1029 graphData
->SetData(group
, m_commitsPerAuthor
[*it
]);
1033 // If we have other authors, count them and their commits.
1034 if (!others
.empty())
1035 DrawOthers(others
, graphData
, m_commitsPerAuthor
);
1037 // Paint the graph now that we're through.
1038 m_graph
.Invalidate();
1041 void CStatGraphDlg::ShowByDate(int stringx
, int title
, IntervalDataMap
&data
)
1043 if(!PreViewStat(false)) return;
1045 // We need at least one author
1046 if (m_authorNames
.empty()) return;
1048 // Set up the graph.
1051 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
1052 temp
.LoadString(stringx
);
1053 m_graph
.SetYAxisLabel(temp
);
1054 temp
.LoadString(title
);
1055 m_graph
.SetGraphTitle(temp
);
1057 m_graph
.SetXAxisLabel(GetUnitString());
1059 // Find out which authors are to be shown and which are to be skipped.
1060 std::list
<tstring
> authors
;
1061 std::list
<tstring
> others
;
1062 FilterSkippedAuthors(authors
, others
);
1064 // Add a graph series for each author.
1065 AuthorDataMap authorGraphMap
;
1066 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1067 authorGraphMap
[*it
] = m_graph
.AppendGroup(it
->c_str());
1068 // If we have skipped authors, add a graph series for all those.
1069 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1071 if (!others
.empty())
1073 temp
.Format(_T(" (%ld)"), others
.size());
1075 othersName
= (LPCWSTR
)sOthers
;
1076 authorGraphMap
[othersName
] = m_graph
.AppendGroup(sOthers
);
1079 // Mapping to collect commit counts in each interval
1080 AuthorDataMap commitCount
;
1082 // Loop over all intervals/weeks and collect filtered data.
1083 // Sum up data in each interval until the time unit changes.
1084 for (int i
=m_lastInterval
; i
>=m_firstInterval
; --i
)
1086 // Collect data for authors listed by name.
1087 if (!authors
.empty())
1089 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
1091 // Do we have some data for the current author in the current interval?
1092 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1093 if (data_it
== data
[i
].end())
1095 commitCount
[*it
] += data_it
->second
;
1098 // Collect data for all skipped authors.
1099 if (!others
.empty())
1101 for (std::list
<tstring
>::iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1103 // Do we have some data for the author in the current interval?
1104 AuthorDataMap::const_iterator data_it
= data
[i
].find(*it
);
1105 if (data_it
== data
[i
].end())
1107 commitCount
[othersName
] += data_it
->second
;
1111 // Create a new data series for this unit/interval.
1112 MyGraphSeries
* graphData
= new MyGraphSeries();
1113 // Loop over all created graphs and set the corresponding data.
1114 if (!authorGraphMap
.empty())
1116 for (AuthorDataMap::const_iterator it
= authorGraphMap
.begin(); it
!= authorGraphMap
.end(); ++it
)
1118 graphData
->SetData(it
->second
, commitCount
[it
->first
]);
1121 graphData
->SetLabel(m_unitNames
[i
].c_str());
1122 m_graph
.AddSeries(*graphData
);
1123 m_graphDataArray
.Add(graphData
);
1125 // Reset commit count mapping.
1126 commitCount
.clear();
1129 // Paint the graph now that we're through.
1130 m_graph
.Invalidate();
1133 void CStatGraphDlg::ShowStats()
1135 if(!PreViewStat(true)) return;
1137 // Now we can use the gathered data to update the stats dialog.
1138 size_t nAuthors
= m_authorNames
.size();
1140 // Find most and least active author names.
1141 tstring mostActiveAuthor
;
1142 tstring leastActiveAuthor
;
1145 mostActiveAuthor
= m_authorNames
.front();
1146 leastActiveAuthor
= m_authorNames
.back();
1149 // Obtain the statistics for the table.
1150 long nCommitsMin
= -1;
1151 long nCommitsMax
= -1;
1152 long nFileChangesMin
= -1;
1153 long nFileChangesMax
= -1;
1155 long nMostActiveMaxCommits
= -1;
1156 long nMostActiveMinCommits
= -1;
1157 long nLeastActiveMaxCommits
= -1;
1158 long nLeastActiveMinCommits
= -1;
1160 // Loop over all intervals and find min and max values for commit count and file changes.
1161 // Also store the stats for the most and least active authors.
1162 for (int i
=m_firstInterval
; i
<=m_lastInterval
; ++i
)
1164 // Loop over all commits in this interval and count the number of commits by all authors.
1165 int commitCount
= 0;
1166 AuthorDataMap::iterator commit_endit
= m_commitsPerUnitAndAuthor
[i
].end();
1167 for (AuthorDataMap::iterator commit_it
= m_commitsPerUnitAndAuthor
[i
].begin();
1168 commit_it
!= commit_endit
; ++commit_it
)
1170 commitCount
+= commit_it
->second
;
1172 if (nCommitsMin
== -1 || commitCount
< nCommitsMin
)
1173 nCommitsMin
= commitCount
;
1174 if (nCommitsMax
== -1 || commitCount
> nCommitsMax
)
1175 nCommitsMax
= commitCount
;
1177 // Loop over all commits in this interval and count the number of file changes by all authors.
1178 int fileChangeCount
= 0;
1179 AuthorDataMap::iterator filechange_endit
= m_filechangesPerUnitAndAuthor
[i
].end();
1180 for (AuthorDataMap::iterator filechange_it
= m_filechangesPerUnitAndAuthor
[i
].begin();
1181 filechange_it
!= filechange_endit
; ++filechange_it
)
1183 fileChangeCount
+= filechange_it
->second
;
1185 if (nFileChangesMin
== -1 || fileChangeCount
< nFileChangesMin
)
1186 nFileChangesMin
= fileChangeCount
;
1187 if (nFileChangesMax
== -1 || fileChangeCount
> nFileChangesMax
)
1188 nFileChangesMax
= fileChangeCount
;
1190 // also get min/max data for most and least active authors
1193 // check if author is present in this interval
1194 AuthorDataMap::iterator author_it
= m_commitsPerUnitAndAuthor
[i
].find(mostActiveAuthor
);
1196 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1199 authorCommits
= author_it
->second
;
1200 if (nMostActiveMaxCommits
== -1 || authorCommits
> nMostActiveMaxCommits
)
1201 nMostActiveMaxCommits
= authorCommits
;
1202 if (nMostActiveMinCommits
== -1 || authorCommits
< nMostActiveMinCommits
)
1203 nMostActiveMinCommits
= authorCommits
;
1205 author_it
= m_commitsPerUnitAndAuthor
[i
].find(leastActiveAuthor
);
1206 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
1209 authorCommits
= author_it
->second
;
1210 if (nLeastActiveMaxCommits
== -1 || authorCommits
> nLeastActiveMaxCommits
)
1211 nLeastActiveMaxCommits
= authorCommits
;
1212 if (nLeastActiveMinCommits
== -1 || authorCommits
< nLeastActiveMinCommits
)
1213 nLeastActiveMinCommits
= authorCommits
;
1216 if (nMostActiveMaxCommits
== -1) nMostActiveMaxCommits
= 0;
1217 if (nMostActiveMinCommits
== -1) nMostActiveMinCommits
= 0;
1218 if (nLeastActiveMaxCommits
== -1) nLeastActiveMaxCommits
= 0;
1219 if (nLeastActiveMinCommits
== -1) nLeastActiveMinCommits
= 0;
1221 int nWeeks
= m_lastInterval
-m_firstInterval
;
1224 // Adjust the labels with the unit type (week, month, ...)
1226 labelText
.Format(IDS_STATGRAPH_NUMBEROFUNIT
, GetUnitString());
1227 SetDlgItemText(IDC_NUMWEEK
, labelText
);
1228 labelText
.Format(IDS_STATGRAPH_COMMITSBYUNIT
, GetUnitString());
1229 SetDlgItemText(IDC_COMMITSEACHWEEK
, labelText
);
1230 labelText
.Format(IDS_STATGRAPH_FILECHANGESBYUNIT
, GetUnitString());
1231 SetDlgItemText(IDC_FILECHANGESEACHWEEK
, labelText
);
1232 // We have now all data we want and we can fill in the labels...
1234 number
.Format(_T("%ld"), nWeeks
);
1235 SetDlgItemText(IDC_NUMWEEKVALUE
, number
);
1236 number
.Format(_T("%ld"), nAuthors
);
1237 SetDlgItemText(IDC_NUMAUTHORVALUE
, number
);
1238 number
.Format(_T("%ld"), m_nTotalCommits
);
1239 SetDlgItemText(IDC_NUMCOMMITSVALUE
, number
);
1240 number
.Format(_T("%ld"), m_nTotalFileChanges
);
1242 SetDlgItemText(IDC_NUMFILECHANGESVALUE
, number
);
1244 number
.Format(_T("%ld"), m_parAuthors
.GetCount() / nWeeks
);
1245 SetDlgItemText(IDC_COMMITSEACHWEEKAVG
, number
);
1246 number
.Format(_T("%ld"), nCommitsMax
);
1247 SetDlgItemText(IDC_COMMITSEACHWEEKMAX
, number
);
1248 number
.Format(_T("%ld"), nCommitsMin
);
1249 SetDlgItemText(IDC_COMMITSEACHWEEKMIN
, number
);
1251 number
.Format(_T("%ld"), m_nTotalFileChanges
/ nWeeks
);
1252 //SetDlgItemText(IDC_FILECHANGESEACHWEEKAVG, number);
1253 number
.Format(_T("%ld"), nFileChangesMax
);
1254 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMAX, number);
1255 number
.Format(_T("%ld"), nFileChangesMin
);
1256 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMIN, number);
1258 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
, m_nTotalLinesInc
, m_nTotalLinesDec
);
1260 SetDlgItemText(IDC_TOTAL_LINE_WITHOUT_NEW_DEL_VALUE
, number
);
1261 number
.Format(_T("%ld (%ld (+) %ld (-))"), m_nTotalLinesInc
+ m_nTotalLinesDec
+ m_nTotalLinesNew
+ m_nTotalLinesDel
,
1262 m_nTotalLinesInc
+ m_nTotalLinesNew
, m_nTotalLinesDec
+ m_nTotalLinesDel
);
1264 SetDlgItemText(IDC_TOTAL_LINE_WITH_NEW_DEL_VALUE
, number
);
1268 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, _T(""));
1269 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, _T("0"));
1270 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, _T("0"));
1271 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, _T("0"));
1272 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, _T(""));
1273 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, _T("0"));
1274 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, _T("0"));
1275 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, _T("0"));
1279 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, mostActiveAuthor
.c_str());
1280 number
.Format(_T("%ld"), m_commitsPerAuthor
[mostActiveAuthor
] / nWeeks
);
1281 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, number
);
1282 number
.Format(_T("%ld"), nMostActiveMaxCommits
);
1283 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, number
);
1284 number
.Format(_T("%ld"), nMostActiveMinCommits
);
1285 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, number
);
1287 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, leastActiveAuthor
.c_str());
1288 number
.Format(_T("%ld"), m_commitsPerAuthor
[leastActiveAuthor
] / nWeeks
);
1289 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, number
);
1290 number
.Format(_T("%ld"), nLeastActiveMaxCommits
);
1291 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, number
);
1292 number
.Format(_T("%ld"), nLeastActiveMinCommits
);
1293 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, number
);
1297 int CStatGraphDlg::RollPercentageOfAuthorship(double it
)
1298 { return (int)it
+ (it
- (int)it
>= 0.5);}
1300 void CStatGraphDlg::OnCbnSelchangeGraphcombo()
1304 Metrics useMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1310 m_btnGraphLine
.EnableWindow(TRUE
);
1311 m_btnGraphLineStacked
.EnableWindow(TRUE
);
1312 m_btnGraphPie
.EnableWindow(TRUE
);
1313 m_GraphType
= MyGraph::Line
;
1316 case PercentageOfAuthorship
:
1317 case CommitsByAuthor
:
1319 m_btnGraphLine
.EnableWindow(FALSE
);
1320 m_btnGraphLineStacked
.EnableWindow(FALSE
);
1321 m_btnGraphPie
.EnableWindow(TRUE
);
1322 m_GraphType
= MyGraph::Bar
;
1330 int CStatGraphDlg::GetUnitCount()
1337 return (m_nWeeks
/4)+1;
1339 return (m_nWeeks
/13)+1; // quarters
1340 return (m_nWeeks
/52)+1;
1343 int CStatGraphDlg::GetUnit(const CTime
& time
)
1346 return time
.GetMonth()*100 + time
.GetDay(); // month*100+day as the unit
1348 return GetCalendarWeek(time
);
1350 return time
.GetMonth();
1352 return ((time
.GetMonth()-1)/3)+1; // quarters
1353 return time
.GetYear();
1356 CStatGraphDlg::UnitType
CStatGraphDlg::GetUnitType()
1369 CString
CStatGraphDlg::GetUnitString()
1372 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXDAY
));
1374 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXWEEK
));
1376 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXMONTH
));
1378 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXQUARTER
));
1379 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXYEAR
));
1382 CString
CStatGraphDlg::GetUnitLabel(int unit
, CTime
&lasttime
)
1385 switch (GetUnitType())
1389 // month*100+day as the unit
1390 int day
= unit
% 100;
1391 int month
= unit
/ 100;
1392 switch (m_langOrder
)
1394 case 0: // month day year
1395 temp
.Format(_T("%d/%d/%.2d"), month
, day
, lasttime
.GetYear()%100);
1397 case 1: // day month year
1399 temp
.Format(_T("%d/%d/%.2d"), day
, month
, lasttime
.GetYear()%100);
1401 case 2: // year month day
1402 temp
.Format(_T("%.2d/%d/%d"), lasttime
.GetYear()%100, month
, day
);
1409 int year
= lasttime
.GetYear();
1410 if ((unit
== 1)&&(lasttime
.GetMonth() == 12))
1413 switch (m_langOrder
)
1415 case 0: // month day year
1416 case 1: // day month year
1418 temp
.Format(_T("%d/%.2d"), unit
, year
%100);
1420 case 2: // year month day
1421 temp
.Format(_T("%.2d/%d"), year
%100, unit
);
1427 switch (m_langOrder
)
1429 case 0: // month day year
1430 case 1: // day month year
1432 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1434 case 2: // year month day
1435 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1440 switch (m_langOrder
)
1442 case 0: // month day year
1443 case 1: // day month year
1445 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1447 case 2: // year month day
1448 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1453 temp
.Format(_T("%d"), unit
);
1459 void CStatGraphDlg::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
1461 if (nSBCode
== TB_THUMBTRACK
)
1462 return CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1464 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1465 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1468 void CStatGraphDlg::OnNeedText(NMHDR
*pnmh
, LRESULT
* /*pResult*/)
1470 TOOLTIPTEXT
* pttt
= (TOOLTIPTEXT
*) pnmh
;
1471 if (pttt
->hdr
.idFrom
== (UINT_PTR
) m_Skipper
.GetSafeHwnd())
1473 size_t included_authors_count
= m_Skipper
.GetPos();
1474 // if we only leave out one author, still include him with his name
1475 if (included_authors_count
+ 1 == m_authorNames
.size())
1476 ++included_authors_count
;
1478 // find the minimum number of commits that the shown authors have
1479 int min_commits
= 0;
1480 included_authors_count
= min(included_authors_count
, m_authorNames
.size());
1481 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
1482 advance(author_it
, included_authors_count
);
1483 if (author_it
!= m_authorNames
.begin())
1484 min_commits
= m_commitsPerAuthor
[ *(--author_it
) ];
1487 int percentage
= int(min_commits
*100.0/(m_nTotalCommits
? m_nTotalCommits
: 1));
1488 string
.Format(IDS_STATGRAPH_AUTHORSLIDER_TT
, m_Skipper
.GetPos(), min_commits
, percentage
);
1489 ::lstrcpy(pttt
->szText
, (LPCTSTR
) string
);
1493 void CStatGraphDlg::AuthorsCaseSensitiveChanged()
1495 UpdateData(); // update checkbox state
1496 GatherData(); // first regenerate the statistics data
1497 RedrawGraph(); // then update the current statistics page
1500 void CStatGraphDlg::SortModeChanged()
1502 UpdateData(); // update checkbox state
1503 RedrawGraph(); // then update the current statistics page
1506 void CStatGraphDlg::ClearGraph()
1509 for (int j
=0; j
<m_graphDataArray
.GetCount(); ++j
)
1510 delete ((MyGraphSeries
*)m_graphDataArray
.GetAt(j
));
1511 m_graphDataArray
.RemoveAll();
1514 void CStatGraphDlg::RedrawGraph()
1516 EnableDisableMenu();
1517 m_btnGraphBar
.SetState(BST_UNCHECKED
);
1518 m_btnGraphBarStacked
.SetState(BST_UNCHECKED
);
1519 m_btnGraphLine
.SetState(BST_UNCHECKED
);
1520 m_btnGraphLineStacked
.SetState(BST_UNCHECKED
);
1521 m_btnGraphPie
.SetState(BST_UNCHECKED
);
1523 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1525 m_btnGraphBarStacked
.SetState(BST_CHECKED
);
1527 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1529 m_btnGraphBar
.SetState(BST_CHECKED
);
1531 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1533 m_btnGraphLineStacked
.SetState(BST_CHECKED
);
1535 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1537 m_btnGraphLine
.SetState(BST_CHECKED
);
1539 if (m_GraphType
== MyGraph::PieChart
)
1541 m_btnGraphPie
.SetState(BST_CHECKED
);
1545 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()), true);
1547 void CStatGraphDlg::OnBnClickedGraphbarbutton()
1549 m_GraphType
= MyGraph::Bar
;
1554 void CStatGraphDlg::OnBnClickedGraphbarstackedbutton()
1556 m_GraphType
= MyGraph::Bar
;
1561 void CStatGraphDlg::OnBnClickedGraphlinebutton()
1563 m_GraphType
= MyGraph::Line
;
1568 void CStatGraphDlg::OnBnClickedGraphlinestackedbutton()
1570 m_GraphType
= MyGraph::Line
;
1575 void CStatGraphDlg::OnBnClickedGraphpiebutton()
1577 m_GraphType
= MyGraph::PieChart
;
1582 BOOL
CStatGraphDlg::PreTranslateMessage(MSG
* pMsg
)
1584 if (NULL
!= m_pToolTip
)
1585 m_pToolTip
->RelayEvent(pMsg
);
1587 return CStandAloneDialogTmpl
<CResizableDialog
>::PreTranslateMessage(pMsg
);
1590 void CStatGraphDlg::EnableDisableMenu()
1592 UINT nEnable
= MF_BYCOMMAND
;
1594 Metrics SelectMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1596 nEnable
|= (SelectMetric
> TextStatStart
&& SelectMetric
< TextStatEnd
)
1597 ? (MF_DISABLED
| MF_GRAYED
) : MF_ENABLED
;
1599 GetMenu()->EnableMenuItem(ID_FILE_SAVESTATGRAPHAS
, nEnable
);
1602 void CStatGraphDlg::OnFileSavestatgraphas()
1605 int filterindex
= 0;
1606 if (CAppUtils::FileOpenSave(tempfile
, &filterindex
, IDS_REVGRAPH_SAVEPIC
, IDS_STATPICFILEFILTER
, false, m_hWnd
))
1608 // if the user doesn't specify a file extension, default to
1609 // wmf and add that extension to the filename. But only if the
1610 // user chose the 'pictures' filter. The filename isn't changed
1611 // if the 'All files' filter was chosen.
1613 int dotPos
= tempfile
.ReverseFind('.');
1614 int slashPos
= tempfile
.ReverseFind('\\');
1615 if (dotPos
> slashPos
)
1616 extension
= tempfile
.Mid(dotPos
);
1617 if ((filterindex
== 1)&&(extension
.IsEmpty()))
1619 extension
= _T(".wmf");
1620 tempfile
+= extension
;
1622 SaveGraph(tempfile
);
1626 void CStatGraphDlg::SaveGraph(CString sFilename
)
1628 CString extension
= CPathUtils::GetFileExtFromPath(sFilename
);
1629 if (extension
.CompareNoCase(_T(".wmf"))==0)
1631 // save the graph as an enhanced meta file
1632 CMyMetaFileDC wmfDC
;
1633 wmfDC
.CreateEnhanced(NULL
, sFilename
, NULL
, _T("TortoiseGit\0Statistics\0\0"));
1634 wmfDC
.SetAttribDC(GetDC()->GetSafeHdc());
1636 m_graph
.DrawGraph(wmfDC
);
1637 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
1638 DeleteEnhMetaFile(hemf
);
1642 // save the graph as a pixel picture instead of a vector picture
1643 // create dc to paint on
1646 CWindowDC
ddc(this);
1648 if (!dc
.CreateCompatibleDC(&ddc
))
1654 GetDlgItem(IDC_GRAPH
)->GetClientRect(&rect
);
1655 HBITMAP hbm
= ::CreateCompatibleBitmap(ddc
.m_hDC
, rect
.Width(), rect
.Height());
1661 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1662 // paint the whole graph
1664 m_graph
.DrawGraph(dc
);
1665 // now use GDI+ to save the picture
1667 GdiplusStartupInput gdiplusStartupInput
;
1668 ULONG_PTR gdiplusToken
;
1669 CString sErrormessage
;
1670 if (GdiplusStartup( &gdiplusToken
, &gdiplusStartupInput
, NULL
)==Ok
)
1673 Bitmap
bitmap(hbm
, NULL
);
1674 if (bitmap
.GetLastStatus()==Ok
)
1676 // Get the CLSID of the encoder.
1678 if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".png"))==0)
1679 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1680 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpg"))==0)
1681 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1682 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpeg"))==0)
1683 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1684 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".bmp"))==0)
1685 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1686 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".gif"))==0)
1687 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1690 sFilename
+= _T(".jpg");
1691 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1695 CStringW tfile
= CStringW(sFilename
);
1696 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1700 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, CPathUtils::GetFileExtFromPath(sFilename
));
1705 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1708 GdiplusShutdown(gdiplusToken
);
1712 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_GDIINIT
);
1714 dc
.SelectObject(oldbm
);
1716 if (!sErrormessage
.IsEmpty())
1718 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseGit"), MB_ICONERROR
);
1721 catch (CException
* pE
)
1723 TCHAR szErrorMsg
[2048];
1724 pE
->GetErrorMessage(szErrorMsg
, 2048);
1726 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseGit"), MB_ICONERROR
);
1731 int CStatGraphDlg::GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
)
1733 UINT num
= 0; // number of image encoders
1734 UINT size
= 0; // size of the image encoder array in bytes
1736 ImageCodecInfo
* pImageCodecInfo
= NULL
;
1738 if (GetImageEncodersSize(&num
, &size
)!=Ok
)
1741 return -1; // Failure
1743 pImageCodecInfo
= (ImageCodecInfo
*)(malloc(size
));
1744 if (pImageCodecInfo
== NULL
)
1745 return -1; // Failure
1747 if (GetImageEncoders(num
, size
, pImageCodecInfo
)==Ok
)
1749 for (UINT j
= 0; j
< num
; ++j
)
1751 if (wcscmp(pImageCodecInfo
[j
].MimeType
, format
) == 0)
1753 *pClsid
= pImageCodecInfo
[j
].Clsid
;
1754 free(pImageCodecInfo
);
1755 return j
; // Success
1759 free (pImageCodecInfo
);
1760 return -1; // Failure
1763 void CStatGraphDlg::StoreCurrentGraphType()
1766 DWORD graphtype
= static_cast<DWORD
>(m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1767 // encode the current chart type
1768 DWORD statspage
= graphtype
*10;
1769 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1773 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1777 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1781 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1785 if (m_GraphType
== MyGraph::PieChart
)
1790 // store current chart type in registry
1791 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseGit\\LastViewedStatsPage"), 0);
1792 lastStatsPage
= statspage
;
1794 CRegDWORD regAuthors
= CRegDWORD(_T("Software\\TortoiseGit\\StatAuthorsCaseSensitive"));
1795 regAuthors
= m_bAuthorsCaseSensitive
;
1797 CRegDWORD regSort
= CRegDWORD(_T("Software\\TortoiseGit\\StatSortByCommitCount"));
1798 regSort
= m_bSortByCommitCount
;
1801 void CStatGraphDlg::ShowErrorMessage()
1803 CFormatMessageWrapper errorDetails
;
1805 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1808 void CStatGraphDlg::ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
/* = false */)
1810 switch (SelectedMetric
)
1813 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1817 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1818 ShowByDate(IDS_STATGRAPH_COMMITSBYDATEY
, IDS_STATGRAPH_COMMITSBYDATE
, m_commitsPerUnitAndAuthor
);
1821 OnBnClickedFetchDiff();
1822 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1823 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_W_Y
, IDS_STATGRAPH_LINES_BYDATE_W
, m_LinesWPerUnitAndAuthor
);
1826 OnBnClickedFetchDiff();
1827 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1828 ShowByDate(IDS_STATGRAPH_LINES_BYDATE_WO_Y
, IDS_STATGRAPH_LINES_BYDATE_WO
, m_LinesWOPerUnitAndAuthor
);
1830 case CommitsByAuthor
:
1831 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1832 ShowCommitsByAuthor();
1834 case PercentageOfAuthorship
:
1835 OnBnClickedFetchDiff();
1836 LoadListOfAuthors(m_PercentageOfAuthorship
, reloadSkiper
, true);
1837 ShowPercentageOfAuthorship();
1844 double CStatGraphDlg::CoeffContribution(int distFromEnd
) { return distFromEnd
? 1.0 / m_CoeffAuthorShip
* distFromEnd
: 1;}
1847 template <class MAP
>
1848 void CStatGraphDlg::DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
)
1851 for (std::list
<tstring
>::const_iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1853 nCommits
+= RollPercentageOfAuthorship(map
[*it
]);
1857 temp
.Format(_T(" (%ld)"), others
.size());
1859 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1861 int group
= m_graph
.AppendGroup(sOthers
);
1862 graphData
->SetData(group
, (int)nCommits
);
1866 template <class MAP
>
1867 void CStatGraphDlg::LoadListOfAuthors (MAP
&map
, bool reloadSkiper
/*= false*/, bool compare
/*= false*/)
1869 m_authorNames
.clear();
1872 for (MAP::const_iterator it
= map
.begin(); it
!= map
.end(); ++it
)
1874 if ((compare
&& RollPercentageOfAuthorship(map
[it
->first
]) != 0) || !compare
)
1875 m_authorNames
.push_back(it
->first
);
1879 // Sort the list of authors based on commit count
1880 m_authorNames
.sort(MoreCommitsThan
< MAP::referent_type
>(map
));
1883 SetSkipper(reloadSkiper
);
1887 void CStatGraphDlg::OnBnClickedFetchDiff()
1891 if (GatherData(TRUE
))
1893 this->m_bDiffFetched
= TRUE
;
1894 GetDlgItem(IDC_CALC_DIFF
)->ShowWindow(!m_bDiffFetched
);