1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "TortoiseProc.h"
21 #include "StatGraphDlg.h"
24 #include "StringUtils.h"
25 #include "PathUtils.h"
26 #include "MessageBox.h"
28 #include "FormatMessageWrapper.h"
35 using namespace Gdiplus
;
37 // BinaryPredicate for comparing authors based on their commit count
38 template<class DataType
>
39 class MoreCommitsThan
: public std::binary_function
<tstring
, tstring
, bool> {
41 typedef std::map
<tstring
, DataType
> MapType
;
42 MoreCommitsThan(MapType
&author_commits
) : m_authorCommits(author_commits
) {}
44 bool operator()(const tstring
& lhs
, const tstring
& rhs
) {
45 return (m_authorCommits
)[lhs
] > (m_authorCommits
)[rhs
];
49 MapType
&m_authorCommits
;
53 IMPLEMENT_DYNAMIC(CStatGraphDlg
, CResizableStandAloneDialog
)
54 CStatGraphDlg::CStatGraphDlg(CWnd
* pParent
/*=NULL*/)
55 : CResizableStandAloneDialog(CStatGraphDlg::IDD
, pParent
)
57 , m_GraphType(MyGraph::Bar
)
58 , m_bAuthorsCaseSensitive(TRUE
)
59 , m_bSortByCommitCount(TRUE
)
67 m_parFileChanges
= NULL
;
72 CStatGraphDlg::~CStatGraphDlg()
78 void CStatGraphDlg::OnOK() {
79 StoreCurrentGraphType();
83 void CStatGraphDlg::OnCancel() {
84 StoreCurrentGraphType();
88 void CStatGraphDlg::DoDataExchange(CDataExchange
* pDX
)
90 CResizableStandAloneDialog::DoDataExchange(pDX
);
91 DDX_Control(pDX
, IDC_GRAPH
, m_graph
);
92 DDX_Control(pDX
, IDC_GRAPHCOMBO
, m_cGraphType
);
93 DDX_Control(pDX
, IDC_SKIPPER
, m_Skipper
);
94 DDX_Check(pDX
, IDC_AUTHORSCASESENSITIVE
, m_bAuthorsCaseSensitive
);
95 DDX_Check(pDX
, IDC_SORTBYCOMMITCOUNT
, m_bSortByCommitCount
);
96 DDX_Control(pDX
, IDC_GRAPHBARBUTTON
, m_btnGraphBar
);
97 DDX_Control(pDX
, IDC_GRAPHBARSTACKEDBUTTON
, m_btnGraphBarStacked
);
98 DDX_Control(pDX
, IDC_GRAPHLINEBUTTON
, m_btnGraphLine
);
99 DDX_Control(pDX
, IDC_GRAPHLINESTACKEDBUTTON
, m_btnGraphLineStacked
);
100 DDX_Control(pDX
, IDC_GRAPHPIEBUTTON
, m_btnGraphPie
);
104 BEGIN_MESSAGE_MAP(CStatGraphDlg
, CResizableStandAloneDialog
)
105 ON_CBN_SELCHANGE(IDC_GRAPHCOMBO
, OnCbnSelchangeGraphcombo
)
107 ON_NOTIFY(TTN_NEEDTEXT
, NULL
, OnNeedText
)
108 ON_BN_CLICKED(IDC_AUTHORSCASESENSITIVE
, &CStatGraphDlg::AuthorsCaseSensitiveChanged
)
109 ON_BN_CLICKED(IDC_SORTBYCOMMITCOUNT
, &CStatGraphDlg::SortModeChanged
)
110 ON_BN_CLICKED(IDC_GRAPHBARBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarbutton
)
111 ON_BN_CLICKED(IDC_GRAPHBARSTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphbarstackedbutton
)
112 ON_BN_CLICKED(IDC_GRAPHLINEBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinebutton
)
113 ON_BN_CLICKED(IDC_GRAPHLINESTACKEDBUTTON
, &CStatGraphDlg::OnBnClickedGraphlinestackedbutton
)
114 ON_BN_CLICKED(IDC_GRAPHPIEBUTTON
, &CStatGraphDlg::OnBnClickedGraphpiebutton
)
115 ON_COMMAND(ID_FILE_SAVESTATGRAPHAS
, &CStatGraphDlg::OnFileSavestatgraphas
)
118 void CStatGraphDlg::LoadStatQueries (__in UINT curStr
, Metrics loadMetric
, bool setDef
/* = false */)
121 temp
.LoadString(curStr
);
122 int sel
= m_cGraphType
.AddString(temp
);
123 m_cGraphType
.SetItemData(sel
, loadMetric
);
125 if (setDef
) m_cGraphType
.SetCurSel(sel
);
128 void CStatGraphDlg::SetSkipper (bool reloadSkiper
)
130 // We need to limit the number of authors due to GUI resource limitation.
131 // However, since author #251 will properly have < 1000th of the commits,
132 // the resolution limit of the screen will already not allow for displaying
133 // it in a reasonable way
135 int max_authors_count
= max(1, (int)min(m_authorNames
.size(), 250) );
136 m_Skipper
.SetRange (1, max_authors_count
);
137 m_Skipper
.SetPageSize(5);
140 m_Skipper
.SetPos (max_authors_count
);
143 BOOL
CStatGraphDlg::OnInitDialog()
145 CResizableStandAloneDialog::OnInitDialog();
147 m_pToolTip
= new CToolTipCtrl
;
148 if (m_pToolTip
->Create(this))
150 m_pToolTip
->AddTool(&m_btnGraphPie
, IDS_STATGRAPH_PIEBUTTON_TT
);
151 m_pToolTip
->AddTool(&m_btnGraphLineStacked
, IDS_STATGRAPH_LINESTACKEDBUTTON_TT
);
152 m_pToolTip
->AddTool(&m_btnGraphLine
, IDS_STATGRAPH_LINEBUTTON_TT
);
153 m_pToolTip
->AddTool(&m_btnGraphBarStacked
, IDS_STATGRAPH_BARSTACKEDBUTTON_TT
);
154 m_pToolTip
->AddTool(&m_btnGraphBar
, IDS_STATGRAPH_BARBUTTON_TT
);
156 m_pToolTip
->Activate(TRUE
);
159 m_bAuthorsCaseSensitive
= DWORD(CRegDWORD(_T("Software\\TortoiseSVN\\StatAuthorsCaseSensitive")));
160 m_bSortByCommitCount
= DWORD(CRegDWORD(_T("Software\\TortoiseSVN\\StatSortByCommitCount")));
163 //Load statistical queries
164 LoadStatQueries(IDS_STATGRAPH_STATS
, AllStat
, true);
165 LoadStatQueries(IDS_STATGRAPH_COMMITSBYDATE
, CommitsByDate
);
166 LoadStatQueries(IDS_STATGRAPH_COMMITSBYAUTHOR
, CommitsByAuthor
);
167 LoadStatQueries(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
, PercentageOfAuthorship
);
169 // set the dialog title to "Statistics - path/to/whatever/we/show/the/statistics/for"
171 GetWindowText(sTitle
);
172 SetWindowText(sTitle
+ _T(" - ") +
173 ( m_path
.IsDirectory() ? m_path
.GetWinPathString() : m_path
.GetFilename()));
175 m_btnGraphBar
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBAR
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
176 m_btnGraphBar
.SizeToContent();
177 m_btnGraphBar
.Invalidate();
178 m_btnGraphBarStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHBARSTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
179 m_btnGraphBarStacked
.SizeToContent();
180 m_btnGraphBarStacked
.Invalidate();
181 m_btnGraphLine
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
182 m_btnGraphLine
.SizeToContent();
183 m_btnGraphLine
.Invalidate();
184 m_btnGraphLineStacked
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHLINESTACKED
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
185 m_btnGraphLineStacked
.SizeToContent();
186 m_btnGraphLineStacked
.Invalidate();
187 m_btnGraphPie
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_GRAPHPIE
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
188 m_btnGraphPie
.SizeToContent();
189 m_btnGraphPie
.Invalidate();
191 AddAnchor(IDC_GRAPHTYPELABEL
, TOP_LEFT
);
192 AddAnchor(IDC_GRAPH
, TOP_LEFT
, BOTTOM_RIGHT
);
193 AddAnchor(IDC_GRAPHCOMBO
, TOP_LEFT
, TOP_RIGHT
);
195 AddAnchor(IDC_NUMWEEK
, TOP_LEFT
);
196 AddAnchor(IDC_NUMWEEKVALUE
, TOP_RIGHT
);
197 AddAnchor(IDC_NUMAUTHOR
, TOP_LEFT
);
198 AddAnchor(IDC_NUMAUTHORVALUE
, TOP_RIGHT
);
199 AddAnchor(IDC_NUMCOMMITS
, TOP_LEFT
);
200 AddAnchor(IDC_NUMCOMMITSVALUE
, TOP_RIGHT
);
201 AddAnchor(IDC_NUMFILECHANGES
, TOP_LEFT
);
202 AddAnchor(IDC_NUMFILECHANGESVALUE
, TOP_RIGHT
);
204 AddAnchor(IDC_AVG
, TOP_RIGHT
);
205 AddAnchor(IDC_MIN
, TOP_RIGHT
);
206 AddAnchor(IDC_MAX
, TOP_RIGHT
);
207 AddAnchor(IDC_COMMITSEACHWEEK
, TOP_LEFT
);
208 AddAnchor(IDC_MOSTACTIVEAUTHOR
, TOP_LEFT
);
209 AddAnchor(IDC_LEASTACTIVEAUTHOR
, TOP_LEFT
);
210 AddAnchor(IDC_MOSTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
211 AddAnchor(IDC_LEASTACTIVEAUTHORNAME
, TOP_LEFT
, TOP_RIGHT
);
212 AddAnchor(IDC_FILECHANGESEACHWEEK
, TOP_LEFT
);
213 AddAnchor(IDC_COMMITSEACHWEEKAVG
, TOP_RIGHT
);
214 AddAnchor(IDC_COMMITSEACHWEEKMIN
, TOP_RIGHT
);
215 AddAnchor(IDC_COMMITSEACHWEEKMAX
, TOP_RIGHT
);
216 AddAnchor(IDC_MOSTACTIVEAUTHORAVG
, TOP_RIGHT
);
217 AddAnchor(IDC_MOSTACTIVEAUTHORMIN
, TOP_RIGHT
);
218 AddAnchor(IDC_MOSTACTIVEAUTHORMAX
, TOP_RIGHT
);
219 AddAnchor(IDC_LEASTACTIVEAUTHORAVG
, TOP_RIGHT
);
220 AddAnchor(IDC_LEASTACTIVEAUTHORMIN
, TOP_RIGHT
);
221 AddAnchor(IDC_LEASTACTIVEAUTHORMAX
, TOP_RIGHT
);
222 AddAnchor(IDC_FILECHANGESEACHWEEKAVG
, TOP_RIGHT
);
223 AddAnchor(IDC_FILECHANGESEACHWEEKMIN
, TOP_RIGHT
);
224 AddAnchor(IDC_FILECHANGESEACHWEEKMAX
, TOP_RIGHT
);
226 AddAnchor(IDC_GRAPHBARBUTTON
, BOTTOM_RIGHT
);
227 AddAnchor(IDC_GRAPHBARSTACKEDBUTTON
, BOTTOM_RIGHT
);
228 AddAnchor(IDC_GRAPHLINEBUTTON
, BOTTOM_RIGHT
);
229 AddAnchor(IDC_GRAPHLINESTACKEDBUTTON
, BOTTOM_RIGHT
);
230 AddAnchor(IDC_GRAPHPIEBUTTON
, BOTTOM_RIGHT
);
232 AddAnchor(IDC_AUTHORSCASESENSITIVE
, BOTTOM_LEFT
);
233 AddAnchor(IDC_SORTBYCOMMITCOUNT
, BOTTOM_LEFT
);
234 AddAnchor(IDC_SKIPPER
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
235 AddAnchor(IDC_SKIPPERLABEL
, BOTTOM_LEFT
);
236 AddAnchor(IDOK
, BOTTOM_RIGHT
);
237 EnableSaveRestore(_T("StatGraphDlg"));
239 // gather statistics data, only needs to be updated when the checkbox with
240 // the case sensitivity of author names is changed
243 // set the min/max values on the skipper
246 // we use a stats page encoding here, 0 stands for the statistics dialog
247 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseSVN\\LastViewedStatsPage"), 0);
249 // open last viewed statistics page as first page
250 int graphtype
= lastStatsPage
/ 10;
251 graphtype
= max(1, min(3, graphtype
));
252 m_cGraphType
.SetCurSel(graphtype
-1);
254 OnCbnSelchangeGraphcombo();
256 int statspage
= lastStatsPage
% 10;
259 m_GraphType
= MyGraph::Bar
;
263 m_GraphType
= MyGraph::Bar
;
267 m_GraphType
= MyGraph::Line
;
271 m_GraphType
= MyGraph::Line
;
275 m_GraphType
= MyGraph::PieChart
;
278 default : return TRUE
;
281 LCID m_locale
= MAKELCID((DWORD
)CRegStdDWORD(_T("Software\\TortoiseSVN\\LanguageID"), MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
)), SORT_DEFAULT
);
283 bool bUseSystemLocale
= !!(DWORD
)CRegStdDWORD(_T("Software\\TortoiseSVN\\UseSystemLocaleForDates"), TRUE
);
284 LCID locale
= bUseSystemLocale
? MAKELCID(MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), SORT_DEFAULT
) : m_locale
;
287 GetLocaleInfo(locale
, LOCALE_IDATE
, &l
, sizeof(TCHAR
));
289 m_langOrder
= (l
> 0) ? l
- '0' : -1;
296 void CStatGraphDlg::ShowLabels(BOOL bShow
)
298 if ((m_parAuthors
==NULL
)||(m_parDates
==NULL
)||(m_parFileChanges
==NULL
))
301 int nCmdShow
= bShow
? SW_SHOW
: SW_HIDE
;
303 GetDlgItem(IDC_GRAPH
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
304 GetDlgItem(IDC_NUMWEEK
)->ShowWindow(nCmdShow
);
305 GetDlgItem(IDC_NUMWEEKVALUE
)->ShowWindow(nCmdShow
);
306 GetDlgItem(IDC_NUMAUTHOR
)->ShowWindow(nCmdShow
);
307 GetDlgItem(IDC_NUMAUTHORVALUE
)->ShowWindow(nCmdShow
);
308 GetDlgItem(IDC_NUMCOMMITS
)->ShowWindow(nCmdShow
);
309 GetDlgItem(IDC_NUMCOMMITSVALUE
)->ShowWindow(nCmdShow
);
310 GetDlgItem(IDC_NUMFILECHANGES
)->ShowWindow(nCmdShow
);
311 GetDlgItem(IDC_NUMFILECHANGESVALUE
)->ShowWindow(nCmdShow
);
313 GetDlgItem(IDC_AVG
)->ShowWindow(nCmdShow
);
314 GetDlgItem(IDC_MIN
)->ShowWindow(nCmdShow
);
315 GetDlgItem(IDC_MAX
)->ShowWindow(nCmdShow
);
316 GetDlgItem(IDC_COMMITSEACHWEEK
)->ShowWindow(nCmdShow
);
317 GetDlgItem(IDC_MOSTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
318 GetDlgItem(IDC_LEASTACTIVEAUTHOR
)->ShowWindow(nCmdShow
);
319 GetDlgItem(IDC_MOSTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
320 GetDlgItem(IDC_LEASTACTIVEAUTHORNAME
)->ShowWindow(nCmdShow
);
321 GetDlgItem(IDC_FILECHANGESEACHWEEK
)->ShowWindow(nCmdShow
);
322 GetDlgItem(IDC_COMMITSEACHWEEKAVG
)->ShowWindow(nCmdShow
);
323 GetDlgItem(IDC_COMMITSEACHWEEKMIN
)->ShowWindow(nCmdShow
);
324 GetDlgItem(IDC_COMMITSEACHWEEKMAX
)->ShowWindow(nCmdShow
);
325 GetDlgItem(IDC_MOSTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
326 GetDlgItem(IDC_MOSTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
327 GetDlgItem(IDC_MOSTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
328 GetDlgItem(IDC_LEASTACTIVEAUTHORAVG
)->ShowWindow(nCmdShow
);
329 GetDlgItem(IDC_LEASTACTIVEAUTHORMIN
)->ShowWindow(nCmdShow
);
330 GetDlgItem(IDC_LEASTACTIVEAUTHORMAX
)->ShowWindow(nCmdShow
);
331 GetDlgItem(IDC_FILECHANGESEACHWEEKAVG
)->ShowWindow(nCmdShow
);
332 GetDlgItem(IDC_FILECHANGESEACHWEEKMIN
)->ShowWindow(nCmdShow
);
333 GetDlgItem(IDC_FILECHANGESEACHWEEKMAX
)->ShowWindow(nCmdShow
);
335 GetDlgItem(IDC_SORTBYCOMMITCOUNT
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
336 GetDlgItem(IDC_SKIPPER
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
337 GetDlgItem(IDC_SKIPPERLABEL
)->ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
338 m_btnGraphBar
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
339 m_btnGraphBarStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
340 m_btnGraphLine
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
341 m_btnGraphLineStacked
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
342 m_btnGraphPie
.ShowWindow(bShow
? SW_HIDE
: SW_SHOW
);
345 void CStatGraphDlg::UpdateWeekCount()
348 if ((!m_parDates
)||(m_parDates
->GetCount()==0))
351 // Already updated? No need to do it again.
355 // Determine first and last date in dates array
356 __time64_t min_date
= (__time64_t
)m_parDates
->GetAt(0);
357 __time64_t max_date
= min_date
;
358 INT_PTR count
= m_parDates
->GetCount();
359 for (INT_PTR i
=0; i
<count
; ++i
)
361 __time64_t d
= (__time64_t
)m_parDates
->GetAt(i
);
362 if (d
< min_date
) min_date
= d
;
363 else if (d
> max_date
) max_date
= d
;
366 // Store start date of the interval in the member variable m_minDate
367 m_minDate
= min_date
;
368 m_maxDate
= max_date
;
370 // How many weeks does the time period cover?
372 // Get time difference between start and end date
373 double secs
= _difftime64(max_date
, m_minDate
);
375 m_nWeeks
= (int)ceil(secs
/ (double) m_SecondsInWeek
);
376 m_nDays
= (int)ceil(secs
/ (double) m_SecondsInDay
);
379 int CStatGraphDlg::GetCalendarWeek(const CTime
& time
)
382 // the calculation of the calendar week is wrong if DST is in effect
383 // and the date to calculate the week for is in DST and within the range
384 // of the DST offset (e.g. one hour).
385 // For example, if DST starts on Sunday march 30 and the date to get the week for
386 // is Monday, march 31, 0:30:00, then the returned week is one week less than
390 // getDSTOffset(const CTime& time)
391 // which returns the DST offset for a given time/date. Then we can use this offset
392 // to correct our GetDays() calculation to get the correct week again
393 // This of course won't work for 'history' dates, because Windows doesn't have
394 // that information (only Vista has such a function: GetTimeZoneInformationForYear() )
397 int iYear
= time
.GetYear();
398 int iFirstDayOfWeek
= 0;
399 int iFirstWeekOfYear
= 0;
401 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, loc
, _countof(loc
));
402 iFirstDayOfWeek
= int(loc
[0]-'0');
403 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, loc
, _countof(loc
));
404 iFirstWeekOfYear
= int(loc
[0]-'0');
405 CTime
dDateFirstJanuary(iYear
,1,1,0,0,0);
406 int iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
409 // 0 Week containing 1/1 is the first week of that year.
410 // 1 First full week following 1/1 is the first week of that year.
411 // 2 First week containing at least four days is the first week of that year.
412 switch (iFirstWeekOfYear
)
416 // Week containing 1/1 is the first week of that year.
418 // check if this week reaches into the next year
419 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
424 iDayOfWeek
= (time
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
426 catch (CException
* e
)
430 CTime dStartOfWeek
= time
-CTimeSpan(iDayOfWeek
,0,0,0);
432 // If this week spans over to 1/1 this is week 1
433 if (dStartOfWeek
+ CTimeSpan(6,0,0,0) >= dDateFirstJanuary
)
435 // we are in the last week of the year that spans over 1/1
440 // Get week day of 1/1
441 dDateFirstJanuary
= CTime(iYear
,1,1,0,0,0);
442 iDayOfWeek
= (dDateFirstJanuary
.GetDayOfWeek() +5 + iFirstDayOfWeek
) % 7;
443 // Just count from 1/1
444 iWeekOfYear
= (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) + 1;
450 // First full week following 1/1 is the first week of that year.
452 // If the 1.1 is the start of the week everything is ok
453 // else we need the next week is the correct result
455 (int)(((time
-dDateFirstJanuary
).GetDays() + iDayOfWeek
) / 7) +
456 (iDayOfWeek
==0 ? 1:0);
458 // If we are in week 0 we are in the first not full week
459 // calculate from the last year
462 // Special case: we are in the week of 1.1 but 1.1. is not on the
463 // start of week. Calculate based on the last year
464 dDateFirstJanuary
= CTime(iYear
-1,1,1,0,0,0);
466 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
467 // and we correct this in the same we we done this before but
468 // the result is now 52 or 53 and not 0
470 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
471 (iDayOfWeek
<=3 ? 1:0);
477 // First week containing at least four days is the first week of that year.
479 // Each year can start with any day of the week. But our
480 // weeks always start with Monday. So we add the day of week
481 // before calculation of the final week of year.
482 // Rule: is the 1.1 a Mo,Tu,We,Th than the week starts on the 1.1 with
483 // week==1, else a week later, so we add one for all those days if
484 // day is less <=3 Mo,Tu,We,Th. Otherwise 1.1 is in the last week of the
487 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
488 (iDayOfWeek
<=3 ? 1:0);
493 // special case week 0. We got a day before the 1.1, 2.1 or 3.1, were the
494 // 1.1. is not a Mo, Tu, We, Th. So the week 1 does not start with the 1.1.
495 // So we calculate the week according to the 1.1 of the year before
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 the result
501 // is now 52 or 53 and not 0
503 (int)(((time
-dDateFirstJanuary
).GetDays()+iDayOfWeek
) / 7) +
504 (iDayOfWeek
<=3 ? 1:0);
506 else if (iWeekOfYear
==53)
508 // special case week 53. Either we got the correct week 53 or we just got the
509 // week 1 of the next year. So is the 1.1.(year+1) also a Mo, Tu, We, Th than
510 // we already have the week 1, otherwise week 53 is correct
512 dDateFirstJanuary
= CTime(iYear
+1,1,1,0,0,0);
514 (dDateFirstJanuary
.GetDayOfWeek()+5+iFirstDayOfWeek
)%7;
515 // 1.1. in week 1 or week 53?
516 iWeekOfYear
= iDayOfWeek
<=3 ? 1:53;
528 void CStatGraphDlg::GatherData()
531 if ((m_parAuthors
==NULL
)||(m_parDates
==NULL
)||(m_parFileChanges
==NULL
))
533 m_nTotalCommits
= m_parAuthors
->GetCount();
534 m_nTotalFileChanges
= 0;
536 // Update m_nWeeks and m_minDate
539 // Now create a mapping that holds the information per week.
540 m_commitsPerUnitAndAuthor
.clear();
541 m_filechangesPerUnitAndAuthor
.clear();
542 m_commitsPerAuthor
.clear();
543 m_PercentageOfAuthorship
.clear();
546 __time64_t d
= (__time64_t
)m_parDates
->GetAt(0);
547 int nLastUnit
= GetUnit(d
);
548 double AllContributionAuthor
= 0;
550 // Now loop over all weeks and gather the info
551 for (LONG i
=0; i
<m_nTotalCommits
; ++i
)
553 // Find the interval number
554 __time64_t commitDate
= (__time64_t
)m_parDates
->GetAt(i
);
555 int u
= GetUnit(commitDate
);
559 // Find the authors name
560 CString sAuth
= m_parAuthors
->GetAt(i
);
561 if (!m_bAuthorsCaseSensitive
)
562 sAuth
= sAuth
.MakeLower();
563 tstring author
= tstring(sAuth
);
564 // Increase total commit count for this author
565 m_commitsPerAuthor
[author
]++;
566 // Increase the commit count for this author in this week
567 m_commitsPerUnitAndAuthor
[interval
][author
]++;
568 CTime t
= m_parDates
->GetAt(i
);
569 m_unitNames
[interval
] = GetUnitLabel(nLastUnit
, t
);
570 // Increase the file change count for this author in this week
571 int fileChanges
= m_parFileChanges
->GetAt(i
);
572 m_filechangesPerUnitAndAuthor
[interval
][author
] += fileChanges
;
573 m_nTotalFileChanges
+= fileChanges
;
575 //calculate Contribution Author
576 double contributionAuthor
= CoeffContribution((int)m_nTotalCommits
- i
-1) * fileChanges
;
577 AllContributionAuthor
+= contributionAuthor
;
578 m_PercentageOfAuthorship
[author
] += contributionAuthor
;
581 // Find first and last interval number.
582 if (!m_commitsPerUnitAndAuthor
.empty())
584 IntervalDataMap::iterator interval_it
= m_commitsPerUnitAndAuthor
.begin();
585 m_firstInterval
= interval_it
->first
;
586 interval_it
= m_commitsPerUnitAndAuthor
.end();
588 m_lastInterval
= interval_it
->first
;
589 // Sanity check - if m_lastInterval is too large it could freeze TSVN and take up all memory!!!
590 assert(m_lastInterval
>= 0 && m_lastInterval
< 10000);
598 // Get a list of authors names
599 LoadListOfAuthors(m_commitsPerAuthor
);
601 // Calculate percent of Contribution Authors
602 for (std::list
<tstring
>::iterator it
= m_authorNames
.begin(); it
!= m_authorNames
.end(); ++it
)
604 m_PercentageOfAuthorship
[*it
] = (m_PercentageOfAuthorship
[*it
] *100)/ AllContributionAuthor
;
607 // All done, now the statistics pages can retrieve the data and
608 // extract the information to be shown.
612 void CStatGraphDlg::FilterSkippedAuthors(std::list
<tstring
>& included_authors
,
613 std::list
<tstring
>& skipped_authors
)
615 included_authors
.clear();
616 skipped_authors
.clear();
618 unsigned int included_authors_count
= m_Skipper
.GetPos();
619 // if we only leave out one author, still include him with his name
620 if (included_authors_count
+ 1 == m_authorNames
.size())
621 ++included_authors_count
;
623 // add the included authors first
624 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
625 while (included_authors_count
> 0 && author_it
!= m_authorNames
.end())
627 // Add him/her to the included list
628 included_authors
.push_back(*author_it
);
630 --included_authors_count
;
633 // If we haven't reached the end yet, copy all remaining authors into the
634 // skipped author list.
635 std::copy(author_it
, m_authorNames
.end(), std::back_inserter(skipped_authors
) );
637 // Sort authors alphabetically if user wants that.
638 if (!m_bSortByCommitCount
)
639 included_authors
.sort();
642 bool CStatGraphDlg::PreViewStat(bool fShowLabels
)
644 if ((m_parAuthors
==NULL
)||(m_parDates
==NULL
)||(m_parFileChanges
==NULL
))
646 ShowLabels(fShowLabels
);
649 if (!fShowLabels
) ClearGraph();
651 // This function relies on a previous call of GatherData().
652 // This can be detected by checking the week count.
653 // If the week count is equal to -1, it hasn't been called before.
656 // If week count is still -1, something bad has happened, probably invalid data!
663 MyGraphSeries
*CStatGraphDlg::PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
/*= NULL*/)
665 if(!PreViewStat(false))
668 // We need at least one author
669 if (m_authorNames
.empty())
672 // Add a single series to the chart
673 MyGraphSeries
* graphData
= new MyGraphSeries();
674 m_graph
.AddSeries(*graphData
);
675 m_graphDataArray
.Add(graphData
);
680 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
681 temp
.LoadString(YAxisLabel
);
682 m_graph
.SetYAxisLabel(temp
);
683 temp
.LoadString(XAxisLabel
);
684 m_graph
.SetXAxisLabel(temp
);
685 temp
.LoadString(GraphTitle
);
686 m_graph
.SetGraphTitle(temp
);
691 void CStatGraphDlg::ShowPercentageOfAuthorship()
694 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIP
,
695 IDS_STATGRAPH_PERCENTAGE_OF_AUTHORSHIPY
,
696 IDS_STATGRAPH_COMMITSBYAUTHORX
);
697 if(graphData
== NULL
) return;
699 // Find out which authors are to be shown and which are to be skipped.
700 std::list
<tstring
> authors
;
701 std::list
<tstring
> others
;
704 FilterSkippedAuthors(authors
, others
);
706 // Loop over all authors in the authors list and
707 // add them to the graph.
711 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
713 int group
= m_graph
.AppendGroup(it
->c_str());
714 graphData
->SetData(group
, RollPercentageOfAuthorship(m_PercentageOfAuthorship
[*it
]));
718 // If we have other authors, count them and their commits.
719 if (others
.size() != 0)
720 DrawOthers(others
, graphData
, m_PercentageOfAuthorship
);
722 // Paint the graph now that we're through.
723 m_graph
.Invalidate();
726 void CStatGraphDlg::ShowCommitsByAuthor()
729 MyGraphSeries
* graphData
= PreViewGraph(IDS_STATGRAPH_COMMITSBYAUTHOR
,
730 IDS_STATGRAPH_COMMITSBYAUTHORY
,
731 IDS_STATGRAPH_COMMITSBYAUTHORX
);
732 if(graphData
== NULL
) return;
734 // Find out which authors are to be shown and which are to be skipped.
735 std::list
<tstring
> authors
;
736 std::list
<tstring
> others
;
737 FilterSkippedAuthors(authors
, others
);
739 // Loop over all authors in the authors list and
740 // add them to the graph.
744 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
746 int group
= m_graph
.AppendGroup(it
->c_str());
747 graphData
->SetData(group
, m_commitsPerAuthor
[*it
]);
751 // If we have other authors, count them and their commits.
752 if (others
.size() != 0)
753 DrawOthers(others
, graphData
, m_commitsPerAuthor
);
755 // Paint the graph now that we're through.
756 m_graph
.Invalidate();
759 void CStatGraphDlg::ShowCommitsByDate()
761 if(!PreViewStat(false)) return;
763 // We need at least one author
764 if (m_authorNames
.empty()) return;
769 m_graph
.SetGraphType(m_GraphType
, m_bStacked
);
770 temp
.LoadString(IDS_STATGRAPH_COMMITSBYDATEY
);
771 m_graph
.SetYAxisLabel(temp
);
772 temp
.LoadString(IDS_STATGRAPH_COMMITSBYDATE
);
773 m_graph
.SetGraphTitle(temp
);
775 m_graph
.SetXAxisLabel(GetUnitString());
777 // Find out which authors are to be shown and which are to be skipped.
778 std::list
<tstring
> authors
;
779 std::list
<tstring
> others
;
780 FilterSkippedAuthors(authors
, others
);
782 // Add a graph series for each author.
783 AuthorDataMap authorGraphMap
;
784 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
785 authorGraphMap
[*it
] = m_graph
.AppendGroup(it
->c_str());
786 // If we have skipped authors, add a graph series for all those.
787 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
791 temp
.Format(_T(" (%ld)"), others
.size());
793 othersName
= (LPCWSTR
)sOthers
;
794 authorGraphMap
[othersName
] = m_graph
.AppendGroup(sOthers
);
797 // Mapping to collect commit counts in each interval
798 AuthorDataMap commitCount
;
800 // Loop over all intervals/weeks and collect filtered data.
801 // Sum up data in each interval until the time unit changes.
802 for (int i
=m_lastInterval
; i
>=m_firstInterval
; --i
)
804 // Collect data for authors listed by name.
807 for (std::list
<tstring
>::iterator it
= authors
.begin(); it
!= authors
.end(); ++it
)
809 // Do we have some data for the current author in the current interval?
810 AuthorDataMap::const_iterator data_it
= m_commitsPerUnitAndAuthor
[i
].find(*it
);
811 if (data_it
== m_commitsPerUnitAndAuthor
[i
].end())
813 commitCount
[*it
] += data_it
->second
;
816 // Collect data for all skipped authors.
819 for (std::list
<tstring
>::iterator it
= others
.begin(); it
!= others
.end(); ++it
)
821 // Do we have some data for the author in the current interval?
822 AuthorDataMap::const_iterator data_it
= m_commitsPerUnitAndAuthor
[i
].find(*it
);
823 if (data_it
== m_commitsPerUnitAndAuthor
[i
].end())
825 commitCount
[othersName
] += data_it
->second
;
829 // Create a new data series for this unit/interval.
830 MyGraphSeries
* graphData
= new MyGraphSeries();
831 // Loop over all created graphs and set the corresponding data.
832 if (authorGraphMap
.size())
834 for (AuthorDataMap::const_iterator it
= authorGraphMap
.begin(); it
!= authorGraphMap
.end(); ++it
)
836 graphData
->SetData(it
->second
, commitCount
[it
->first
]);
839 graphData
->SetLabel(m_unitNames
[i
].c_str());
840 m_graph
.AddSeries(*graphData
);
841 m_graphDataArray
.Add(graphData
);
843 // Reset commit count mapping.
847 // Paint the graph now that we're through.
848 m_graph
.Invalidate();
851 void CStatGraphDlg::ShowStats()
853 if(!PreViewStat(true)) return;
855 // Now we can use the gathered data to update the stats dialog.
856 size_t nAuthors
= m_authorNames
.size();
858 // Find most and least active author names.
859 tstring mostActiveAuthor
;
860 tstring leastActiveAuthor
;
863 mostActiveAuthor
= m_authorNames
.front();
864 leastActiveAuthor
= m_authorNames
.back();
867 // Obtain the statistics for the table.
868 long nCommitsMin
= -1;
869 long nCommitsMax
= -1;
870 long nFileChangesMin
= -1;
871 long nFileChangesMax
= -1;
873 long nMostActiveMaxCommits
= -1;
874 long nMostActiveMinCommits
= -1;
875 long nLeastActiveMaxCommits
= -1;
876 long nLeastActiveMinCommits
= -1;
878 // Loop over all intervals and find min and max values for commit count and file changes.
879 // Also store the stats for the most and least active authors.
880 for (int i
=m_firstInterval
; i
<=m_lastInterval
; ++i
)
882 // Loop over all commits in this interval and count the number of commits by all authors.
884 AuthorDataMap::iterator commit_endit
= m_commitsPerUnitAndAuthor
[i
].end();
885 for (AuthorDataMap::iterator commit_it
= m_commitsPerUnitAndAuthor
[i
].begin();
886 commit_it
!= commit_endit
; ++commit_it
)
888 commitCount
+= commit_it
->second
;
890 if (nCommitsMin
== -1 || commitCount
< nCommitsMin
)
891 nCommitsMin
= commitCount
;
892 if (nCommitsMax
== -1 || commitCount
> nCommitsMax
)
893 nCommitsMax
= commitCount
;
895 // Loop over all commits in this interval and count the number of file changes by all authors.
896 int fileChangeCount
= 0;
897 AuthorDataMap::iterator filechange_endit
= m_filechangesPerUnitAndAuthor
[i
].end();
898 for (AuthorDataMap::iterator filechange_it
= m_filechangesPerUnitAndAuthor
[i
].begin();
899 filechange_it
!= filechange_endit
; ++filechange_it
)
901 fileChangeCount
+= filechange_it
->second
;
903 if (nFileChangesMin
== -1 || fileChangeCount
< nFileChangesMin
)
904 nFileChangesMin
= fileChangeCount
;
905 if (nFileChangesMax
== -1 || fileChangeCount
> nFileChangesMax
)
906 nFileChangesMax
= fileChangeCount
;
908 // also get min/max data for most and least active authors
911 // check if author is present in this interval
912 AuthorDataMap::iterator author_it
= m_commitsPerUnitAndAuthor
[i
].find(mostActiveAuthor
);
914 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
917 authorCommits
= author_it
->second
;
918 if (nMostActiveMaxCommits
== -1 || authorCommits
> nMostActiveMaxCommits
)
919 nMostActiveMaxCommits
= authorCommits
;
920 if (nMostActiveMinCommits
== -1 || authorCommits
< nMostActiveMinCommits
)
921 nMostActiveMinCommits
= authorCommits
;
923 author_it
= m_commitsPerUnitAndAuthor
[i
].find(leastActiveAuthor
);
924 if (author_it
== m_commitsPerUnitAndAuthor
[i
].end())
927 authorCommits
= author_it
->second
;
928 if (nLeastActiveMaxCommits
== -1 || authorCommits
> nLeastActiveMaxCommits
)
929 nLeastActiveMaxCommits
= authorCommits
;
930 if (nLeastActiveMinCommits
== -1 || authorCommits
< nLeastActiveMinCommits
)
931 nLeastActiveMinCommits
= authorCommits
;
934 if (nMostActiveMaxCommits
== -1) nMostActiveMaxCommits
= 0;
935 if (nMostActiveMinCommits
== -1) nMostActiveMinCommits
= 0;
936 if (nLeastActiveMaxCommits
== -1) nLeastActiveMaxCommits
= 0;
937 if (nLeastActiveMinCommits
== -1) nLeastActiveMinCommits
= 0;
939 int nWeeks
= m_lastInterval
-m_firstInterval
;
942 // Adjust the labels with the unit type (week, month, ...)
944 labelText
.Format(IDS_STATGRAPH_NUMBEROFUNIT
, GetUnitString());
945 SetDlgItemText(IDC_NUMWEEK
, labelText
);
946 labelText
.Format(IDS_STATGRAPH_COMMITSBYUNIT
, GetUnitString());
947 SetDlgItemText(IDC_COMMITSEACHWEEK
, labelText
);
948 labelText
.Format(IDS_STATGRAPH_FILECHANGESBYUNIT
, GetUnitString());
949 SetDlgItemText(IDC_FILECHANGESEACHWEEK
, labelText
);
950 // We have now all data we want and we can fill in the labels...
952 number
.Format(_T("%ld"), nWeeks
);
953 SetDlgItemText(IDC_NUMWEEKVALUE
, number
);
954 number
.Format(_T("%ld"), nAuthors
);
955 SetDlgItemText(IDC_NUMAUTHORVALUE
, number
);
956 number
.Format(_T("%ld"), m_nTotalCommits
);
957 SetDlgItemText(IDC_NUMCOMMITSVALUE
, number
);
958 number
.Format(_T("%ld"), m_nTotalFileChanges
);
959 //SetDlgItemText(IDC_NUMFILECHANGESVALUE, number);
961 number
.Format(_T("%ld"), m_parAuthors
->GetCount() / nWeeks
);
962 SetDlgItemText(IDC_COMMITSEACHWEEKAVG
, number
);
963 number
.Format(_T("%ld"), nCommitsMax
);
964 SetDlgItemText(IDC_COMMITSEACHWEEKMAX
, number
);
965 number
.Format(_T("%ld"), nCommitsMin
);
966 SetDlgItemText(IDC_COMMITSEACHWEEKMIN
, number
);
968 number
.Format(_T("%ld"), m_nTotalFileChanges
/ nWeeks
);
969 //SetDlgItemText(IDC_FILECHANGESEACHWEEKAVG, number);
970 number
.Format(_T("%ld"), nFileChangesMax
);
971 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMAX, number);
972 number
.Format(_T("%ld"), nFileChangesMin
);
973 //SetDlgItemText(IDC_FILECHANGESEACHWEEKMIN, number);
977 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, _T(""));
978 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, _T("0"));
979 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, _T("0"));
980 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, _T("0"));
981 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, _T(""));
982 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, _T("0"));
983 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, _T("0"));
984 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, _T("0"));
988 SetDlgItemText(IDC_MOSTACTIVEAUTHORNAME
, mostActiveAuthor
.c_str());
989 number
.Format(_T("%ld"), m_commitsPerAuthor
[mostActiveAuthor
] / nWeeks
);
990 SetDlgItemText(IDC_MOSTACTIVEAUTHORAVG
, number
);
991 number
.Format(_T("%ld"), nMostActiveMaxCommits
);
992 SetDlgItemText(IDC_MOSTACTIVEAUTHORMAX
, number
);
993 number
.Format(_T("%ld"), nMostActiveMinCommits
);
994 SetDlgItemText(IDC_MOSTACTIVEAUTHORMIN
, number
);
996 SetDlgItemText(IDC_LEASTACTIVEAUTHORNAME
, leastActiveAuthor
.c_str());
997 number
.Format(_T("%ld"), m_commitsPerAuthor
[leastActiveAuthor
] / nWeeks
);
998 SetDlgItemText(IDC_LEASTACTIVEAUTHORAVG
, number
);
999 number
.Format(_T("%ld"), nLeastActiveMaxCommits
);
1000 SetDlgItemText(IDC_LEASTACTIVEAUTHORMAX
, number
);
1001 number
.Format(_T("%ld"), nLeastActiveMinCommits
);
1002 SetDlgItemText(IDC_LEASTACTIVEAUTHORMIN
, number
);
1006 int CStatGraphDlg::RollPercentageOfAuthorship(double it
)
1007 { return (int)it
+ (it
- (int)it
>= 0.5);}
1009 void CStatGraphDlg::OnCbnSelchangeGraphcombo()
1013 Metrics useMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1019 m_btnGraphLine
.EnableWindow(TRUE
);
1020 m_btnGraphLineStacked
.EnableWindow(TRUE
);
1021 m_btnGraphPie
.EnableWindow(TRUE
);
1022 m_GraphType
= MyGraph::Line
;
1025 case PercentageOfAuthorship
:
1026 case CommitsByAuthor
:
1028 m_btnGraphLine
.EnableWindow(FALSE
);
1029 m_btnGraphLineStacked
.EnableWindow(FALSE
);
1030 m_btnGraphPie
.EnableWindow(TRUE
);
1031 m_GraphType
= MyGraph::Bar
;
1039 int CStatGraphDlg::GetUnitCount()
1046 return (m_nWeeks
/4)+1;
1048 return (m_nWeeks
/13)+1; // quarters
1049 return (m_nWeeks
/52)+1;
1052 int CStatGraphDlg::GetUnit(const CTime
& time
)
1055 return time
.GetMonth()*100 + time
.GetDay(); // month*100+day as the unit
1057 return GetCalendarWeek(time
);
1059 return time
.GetMonth();
1061 return ((time
.GetMonth()-1)/3)+1; // quarters
1062 return time
.GetYear();
1065 CStatGraphDlg::UnitType
CStatGraphDlg::GetUnitType()
1078 CString
CStatGraphDlg::GetUnitString()
1081 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXDAY
));
1083 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXWEEK
));
1085 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXMONTH
));
1087 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXQUARTER
));
1088 return CString(MAKEINTRESOURCE(IDS_STATGRAPH_COMMITSBYDATEXYEAR
));
1091 CString
CStatGraphDlg::GetUnitLabel(int unit
, CTime
&lasttime
)
1094 switch (GetUnitType())
1098 // month*100+day as the unit
1099 int day
= unit
% 100;
1100 int month
= unit
/ 100;
1101 switch (m_langOrder
)
1103 case 0: // month day year
1104 temp
.Format(_T("%d/%d/%.2d"), month
, day
, lasttime
.GetYear()%100);
1106 case 1: // day month year
1108 temp
.Format(_T("%d/%d/%.2d"), day
, month
, lasttime
.GetYear()%100);
1110 case 2: // year month day
1111 temp
.Format(_T("%.2d/%d/%d"), lasttime
.GetYear()%100, month
, day
);
1118 int year
= lasttime
.GetYear();
1119 if ((unit
== 1)&&(lasttime
.GetMonth() == 12))
1122 switch (m_langOrder
)
1124 case 0: // month day year
1125 case 1: // day month year
1127 temp
.Format(_T("%d/%.2d"), unit
, year
%100);
1129 case 2: // year month day
1130 temp
.Format(_T("%.2d/%d"), year
%100, unit
);
1136 switch (m_langOrder
)
1138 case 0: // month day year
1139 case 1: // day month year
1141 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1143 case 2: // year month day
1144 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1149 switch (m_langOrder
)
1151 case 0: // month day year
1152 case 1: // day month year
1154 temp
.Format(_T("%d/%.2d"), unit
, lasttime
.GetYear()%100);
1156 case 2: // year month day
1157 temp
.Format(_T("%.2d/%d"), lasttime
.GetYear()%100, unit
);
1162 temp
.Format(_T("%d"), unit
);
1168 void CStatGraphDlg::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
1170 if (nSBCode
== TB_THUMBTRACK
)
1171 return CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1173 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1174 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1177 void CStatGraphDlg::OnNeedText(NMHDR
*pnmh
, LRESULT
* /*pResult*/)
1179 TOOLTIPTEXT
* pttt
= (TOOLTIPTEXT
*) pnmh
;
1180 if (pttt
->hdr
.idFrom
== (UINT
) m_Skipper
.GetSafeHwnd())
1182 size_t included_authors_count
= m_Skipper
.GetPos();
1183 // if we only leave out one author, still include him with his name
1184 if (included_authors_count
+ 1 == m_authorNames
.size())
1185 ++included_authors_count
;
1187 // find the minimum number of commits that the shown authors have
1188 int min_commits
= 0;
1189 included_authors_count
= min(included_authors_count
, m_authorNames
.size());
1190 std::list
<tstring
>::iterator author_it
= m_authorNames
.begin();
1191 advance(author_it
, included_authors_count
);
1192 if (author_it
!= m_authorNames
.begin())
1193 min_commits
= m_commitsPerAuthor
[ *(--author_it
) ];
1196 int percentage
= int(min_commits
*100.0/(m_nTotalCommits
? m_nTotalCommits
: 1));
1197 string
.Format(IDS_STATGRAPH_AUTHORSLIDER_TT
, m_Skipper
.GetPos(), min_commits
, percentage
);
1198 ::lstrcpy(pttt
->szText
, (LPCTSTR
) string
);
1202 void CStatGraphDlg::AuthorsCaseSensitiveChanged()
1204 UpdateData(); // update checkbox state
1205 GatherData(); // first regenerate the statistics data
1206 RedrawGraph(); // then update the current statistics page
1209 void CStatGraphDlg::SortModeChanged()
1211 UpdateData(); // update checkbox state
1212 RedrawGraph(); // then update the current statistics page
1215 void CStatGraphDlg::ClearGraph()
1218 for (int j
=0; j
<m_graphDataArray
.GetCount(); ++j
)
1219 delete ((MyGraphSeries
*)m_graphDataArray
.GetAt(j
));
1220 m_graphDataArray
.RemoveAll();
1223 void CStatGraphDlg::RedrawGraph()
1225 EnableDisableMenu();
1226 m_btnGraphBar
.SetState(BST_UNCHECKED
);
1227 m_btnGraphBarStacked
.SetState(BST_UNCHECKED
);
1228 m_btnGraphLine
.SetState(BST_UNCHECKED
);
1229 m_btnGraphLineStacked
.SetState(BST_UNCHECKED
);
1230 m_btnGraphPie
.SetState(BST_UNCHECKED
);
1232 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1234 m_btnGraphBarStacked
.SetState(BST_CHECKED
);
1236 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1238 m_btnGraphBar
.SetState(BST_CHECKED
);
1240 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1242 m_btnGraphLineStacked
.SetState(BST_CHECKED
);
1244 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1246 m_btnGraphLine
.SetState(BST_CHECKED
);
1248 if (m_GraphType
== MyGraph::PieChart
)
1250 m_btnGraphPie
.SetState(BST_CHECKED
);
1254 ShowSelectStat((Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()), true);
1256 void CStatGraphDlg::OnBnClickedGraphbarbutton()
1258 m_GraphType
= MyGraph::Bar
;
1263 void CStatGraphDlg::OnBnClickedGraphbarstackedbutton()
1265 m_GraphType
= MyGraph::Bar
;
1270 void CStatGraphDlg::OnBnClickedGraphlinebutton()
1272 m_GraphType
= MyGraph::Line
;
1277 void CStatGraphDlg::OnBnClickedGraphlinestackedbutton()
1279 m_GraphType
= MyGraph::Line
;
1284 void CStatGraphDlg::OnBnClickedGraphpiebutton()
1286 m_GraphType
= MyGraph::PieChart
;
1291 BOOL
CStatGraphDlg::PreTranslateMessage(MSG
* pMsg
)
1293 if (NULL
!= m_pToolTip
)
1294 m_pToolTip
->RelayEvent(pMsg
);
1296 return CStandAloneDialogTmpl
<CResizableDialog
>::PreTranslateMessage(pMsg
);
1299 void CStatGraphDlg::EnableDisableMenu()
1301 UINT nEnable
= MF_BYCOMMAND
;
1303 Metrics SelectMetric
= (Metrics
) m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel());
1305 nEnable
|= (SelectMetric
> TextStatStart
&& SelectMetric
< TextStatEnd
)
1306 ? (MF_DISABLED
| MF_GRAYED
) : MF_ENABLED
;
1308 GetMenu()->EnableMenuItem(ID_FILE_SAVESTATGRAPHAS
, nEnable
);
1311 void CStatGraphDlg::OnFileSavestatgraphas()
1314 int filterindex
= 0;
1315 if (CAppUtils::FileOpenSave(tempfile
, &filterindex
, IDS_REVGRAPH_SAVEPIC
, IDS_PICTUREFILEFILTER
, false, m_hWnd
))
1317 // if the user doesn't specify a file extension, default to
1318 // wmf and add that extension to the filename. But only if the
1319 // user chose the 'pictures' filter. The filename isn't changed
1320 // if the 'All files' filter was chosen.
1322 int dotPos
= tempfile
.ReverseFind('.');
1323 int slashPos
= tempfile
.ReverseFind('\\');
1324 if (dotPos
> slashPos
)
1325 extension
= tempfile
.Mid(dotPos
);
1326 if ((filterindex
== 1)&&(extension
.IsEmpty()))
1328 extension
= _T(".wmf");
1329 tempfile
+= extension
;
1331 SaveGraph(tempfile
);
1335 void CStatGraphDlg::SaveGraph(CString sFilename
)
1337 CString extension
= CPathUtils::GetFileExtFromPath(sFilename
);
1338 if (extension
.CompareNoCase(_T(".wmf"))==0)
1340 // save the graph as an enhanced meta file
1341 CMyMetaFileDC wmfDC
;
1342 wmfDC
.CreateEnhanced(NULL
, sFilename
, NULL
, _T("TortoiseSVN\0Statistics\0\0"));
1343 wmfDC
.SetAttribDC(GetDC()->GetSafeHdc());
1345 m_graph
.DrawGraph(wmfDC
);
1346 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
1347 DeleteEnhMetaFile(hemf
);
1351 // save the graph as a pixel picture instead of a vector picture
1352 // create dc to paint on
1355 CWindowDC
ddc(this);
1357 if (!dc
.CreateCompatibleDC(&ddc
))
1363 GetDlgItem(IDC_GRAPH
)->GetClientRect(&rect
);
1364 HBITMAP hbm
= ::CreateCompatibleBitmap(ddc
.m_hDC
, rect
.Width(), rect
.Height());
1370 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1371 // paint the whole graph
1373 m_graph
.DrawGraph(dc
);
1374 // now use GDI+ to save the picture
1376 GdiplusStartupInput gdiplusStartupInput
;
1377 ULONG_PTR gdiplusToken
;
1378 CString sErrormessage
;
1379 if (GdiplusStartup( &gdiplusToken
, &gdiplusStartupInput
, NULL
)==Ok
)
1382 Bitmap
bitmap(hbm
, NULL
);
1383 if (bitmap
.GetLastStatus()==Ok
)
1385 // Get the CLSID of the encoder.
1387 if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".png"))==0)
1388 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1389 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpg"))==0)
1390 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1391 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".jpeg"))==0)
1392 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1393 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".bmp"))==0)
1394 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1395 else if (CPathUtils::GetFileExtFromPath(sFilename
).CompareNoCase(_T(".gif"))==0)
1396 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1399 sFilename
+= _T(".jpg");
1400 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1404 CStringW tfile
= CStringW(sFilename
);
1405 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1409 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, CPathUtils::GetFileExtFromPath(sFilename
));
1414 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1417 GdiplusShutdown(gdiplusToken
);
1421 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_GDIINIT
);
1423 dc
.SelectObject(oldbm
);
1425 if (!sErrormessage
.IsEmpty())
1427 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseSVN"), MB_ICONERROR
);
1430 catch (CException
* pE
)
1432 TCHAR szErrorMsg
[2048];
1433 pE
->GetErrorMessage(szErrorMsg
, 2048);
1435 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseSVN"), MB_ICONERROR
);
1440 int CStatGraphDlg::GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
)
1442 UINT num
= 0; // number of image encoders
1443 UINT size
= 0; // size of the image encoder array in bytes
1445 ImageCodecInfo
* pImageCodecInfo
= NULL
;
1447 if (GetImageEncodersSize(&num
, &size
)!=Ok
)
1450 return -1; // Failure
1452 pImageCodecInfo
= (ImageCodecInfo
*)(malloc(size
));
1453 if (pImageCodecInfo
== NULL
)
1454 return -1; // Failure
1456 if (GetImageEncoders(num
, size
, pImageCodecInfo
)==Ok
)
1458 for (UINT j
= 0; j
< num
; ++j
)
1460 if (wcscmp(pImageCodecInfo
[j
].MimeType
, format
) == 0)
1462 *pClsid
= pImageCodecInfo
[j
].Clsid
;
1463 free(pImageCodecInfo
);
1464 return j
; // Success
1468 free (pImageCodecInfo
);
1469 return -1; // Failure
1472 void CStatGraphDlg::StoreCurrentGraphType()
1475 DWORD graphtype
= static_cast<DWORD
>(m_cGraphType
.GetItemData(m_cGraphType
.GetCurSel()));
1476 // encode the current chart type
1477 DWORD statspage
= graphtype
*10;
1478 if ((m_GraphType
== MyGraph::Bar
)&&(m_bStacked
))
1482 if ((m_GraphType
== MyGraph::Bar
)&&(!m_bStacked
))
1486 if ((m_GraphType
== MyGraph::Line
)&&(m_bStacked
))
1490 if ((m_GraphType
== MyGraph::Line
)&&(!m_bStacked
))
1494 if (m_GraphType
== MyGraph::PieChart
)
1499 // store current chart type in registry
1500 CRegDWORD lastStatsPage
= CRegDWORD(_T("Software\\TortoiseSVN\\LastViewedStatsPage"), 0);
1501 lastStatsPage
= statspage
;
1503 CRegDWORD regAuthors
= CRegDWORD(_T("Software\\TortoiseSVN\\StatAuthorsCaseSensitive"));
1504 regAuthors
= m_bAuthorsCaseSensitive
;
1506 CRegDWORD regSort
= CRegDWORD(_T("Software\\TortoiseSVN\\StatSortByCommitCount"));
1507 regSort
= m_bSortByCommitCount
;
1510 void CStatGraphDlg::ShowErrorMessage()
1512 CFormatMessageWrapper errorDetails
;
1514 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1517 void CStatGraphDlg::ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
/* = false */)
1519 switch (SelectedMetric
)
1522 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1526 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1527 ShowCommitsByDate();
1529 case CommitsByAuthor
:
1530 LoadListOfAuthors(m_commitsPerAuthor
, reloadSkiper
);
1531 ShowCommitsByAuthor();
1533 case PercentageOfAuthorship
:
1534 LoadListOfAuthors(m_PercentageOfAuthorship
, reloadSkiper
, true);
1535 ShowPercentageOfAuthorship();
1542 double CStatGraphDlg::CoeffContribution(int distFromEnd
) { return distFromEnd
? 1.0 / m_CoeffAuthorShip
* distFromEnd
: 1;}
1545 template <class MAP
>
1546 void CStatGraphDlg::DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
)
1549 for (std::list
<tstring
>::const_iterator it
= others
.begin(); it
!= others
.end(); ++it
)
1551 nCommits
+= RollPercentageOfAuthorship(map
[*it
]);
1555 temp
.Format(_T(" (%ld)"), others
.size());
1557 CString
sOthers(MAKEINTRESOURCE(IDS_STATGRAPH_OTHERGROUP
));
1559 int group
= m_graph
.AppendGroup(sOthers
);
1560 graphData
->SetData(group
, (int)nCommits
);
1564 template <class MAP
>
1565 void CStatGraphDlg::LoadListOfAuthors (MAP
&map
, bool reloadSkiper
/*= false*/, bool compare
/*= false*/)
1567 m_authorNames
.clear();
1570 for (MAP::const_iterator it
= map
.begin(); it
!= map
.end(); ++it
)
1572 if ((compare
&& RollPercentageOfAuthorship(map
[it
->first
]) != 0) || !compare
)
1573 m_authorNames
.push_back(it
->first
);
1577 // Sort the list of authors based on commit count
1578 m_authorNames
.sort(MoreCommitsThan
< MAP::referent_type
>(map
));
1581 SetSkipper(reloadSkiper
);