4949
5050from pygal import Bar , Dot , Pie
5151from pygal .style import Style
52+ from pygal .config import Config
5253
53- VERSION = '1.2-dev '
54+ VERSION = '1.2'
5455
5556
5657class GitChart (object ):
@@ -84,13 +85,14 @@ class GitChart(object):
8485 '#ff00cc' , '#899ca1' , '#bf4646' ))
8586
8687 def __init__ (self , chart_name , title = None , repository = '.' , output = None ,
87- max_diff = 20 , sort_max = 0 , in_data = None ):
88+ max_diff = 20 , sort_max = 0 , js = None , in_data = None ):
8889 self .chart_name = chart_name
8990 self .title = title if title is not None else self .charts [chart_name ]
9091 self .repository = repository
9192 self .output = output
9293 self .max_diff = max_diff
9394 self .sort_max = sort_max
95+ self .js = js .split (',' )
9496 self .in_data = in_data
9597
9698 def _git_command (self , command1 , command2 = None ):
@@ -121,7 +123,7 @@ def _generate_bar_chart(self, data, sorted_keys=None, max_keys=0,
121123 """Generate a bar chart."""
122124 bar_chart = Bar (style = self .style , show_legend = False ,
123125 x_label_rotation = x_label_rotation ,
124- label_font_size = 12 )
126+ label_font_size = 12 , js = self . js )
125127 bar_chart .title = self .title
126128 # sort and keep max entries (if asked)
127129 if self .sort_max != 0 :
@@ -154,7 +156,7 @@ def _chart_authors(self):
154156 stdout = self ._git_command (['git' , 'log' , '--pretty=short' ],
155157 ['git' , 'shortlog' , '-sn' ])
156158 pie_chart = Pie (style = self .style , truncate_legend = 100 ,
157- value_font_size = 12 )
159+ value_font_size = 12 , js = self . js )
158160 pie_chart .title = self .title
159161 count = 0
160162 count_others = 0
@@ -194,7 +196,7 @@ def _chart_commits_hour_week(self):
194196 for line in stdout :
195197 wday , _ , _ , _ , hour , _ = line .split ()
196198 commits [wday [:- 1 ]][hour .split (':' )[0 ]] += 1
197- dot_chart = Dot (style = self .style )
199+ dot_chart = Dot (style = self .style , js = self . js )
198200 dot_chart .title = self .title
199201 dot_chart .x_labels = ['{0:02d}' .format (hh ) for hh in range (0 , 24 )]
200202 for day in self .weekdays :
@@ -313,7 +315,7 @@ def _chart_files_type(self):
313315 ext = '(no extension)'
314316 extensions [ext ] = extensions .get (ext , 0 ) + 1
315317 pie_chart = Pie (style = self .style , truncate_legend = 100 ,
316- value_font_size = 12 )
318+ value_font_size = 12 , js = self . js )
317319 pie_chart .title = self .title
318320 count = 0
319321 count_others = 0
@@ -357,6 +359,7 @@ def generate(self):
357359def main ():
358360 """Main function, entry point."""
359361 # parse command line arguments
362+ pygal_config = Config ()
360363 parser = argparse .ArgumentParser (
361364 formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
362365 description = 'Generate statistic charts for a git repository.' ,
@@ -381,6 +384,10 @@ def main():
381384 'number will reverse the sort (only for charts: commits_hour_day, '
382385 'commits_day, commits_day_week, commits_month, commits_year, '
383386 'commits_year_month, commits_version); 0=no sort/max' )
387+ parser .add_argument (
388+ '-j' , '--js' ,
389+ default = ',' .join (pygal_config .js ),
390+ help = 'comma-separated list of the two javascript files used in SVG' )
384391 parser .add_argument (
385392 'chart' ,
386393 metavar = 'chart' , choices = sorted (GitChart .charts ),
@@ -398,6 +405,11 @@ def main():
398405 sys .exit (1 )
399406 args = parser .parse_args (sys .argv [1 :])
400407
408+ # check javascript files
409+ js = args .js .split (',' )
410+ if not js or len (js ) != 2 or not js [0 ] or not js [1 ]:
411+ sys .exit ('ERROR: invalid javascript files' )
412+
401413 # read data on standard input
402414 in_data = ''
403415 while True :
@@ -411,7 +423,7 @@ def main():
411423
412424 # generate chart
413425 chart = GitChart (args .chart , args .title , args .repo , args .output ,
414- args .max_diff , args .sort_max , in_data )
426+ args .max_diff , args .sort_max , args . js , in_data )
415427 if chart .generate ():
416428 sys .exit (0 )
417429
0 commit comments