Skip to content

Commit 2ea43fe

Browse files
committed
Add option -S/--style to choose Pygal style
1 parent ecfaaea commit 2ea43fe

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Version 2.0.0 (under dev)
44

55
- Drop Python 2 support, Python 3.6 is now required.
6+
- Add option `-S` / `--style` to choose Pygal style, defaults to custom style `gitchart_light`.
67
- Convert README and ChangeLog to markdown.
78

89
## Version 1.5 (2020-03-07)

gitchart.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,54 @@
5555
r' *#([0-9]+)'
5656
)
5757

58+
# Pygal style with transparent background and custom colors (dark version)
59+
GITCHART_DARK_STYLE = pygal.style.Style(
60+
plot_background='transparent',
61+
background='#1a1a1a',
62+
foreground='rgba(150, 150, 150, 0.8)',
63+
foreground_strong='rgba(220, 220, 220, 0.8)',
64+
foreground_subtle='rgba(100, 100, 100, 0.4)',
65+
opacity_hover='.4',
66+
colors=('#4444ff', '#8cedff', '#b6e354',
67+
'#feed6c', '#ff9966', '#ff0000',
68+
'#ff00cc', '#899ca1', '#bf4646')
69+
)
70+
71+
# Pygal style with transparent background and custom colors (light version)
72+
GITCHART_LIGHT_STYLE = pygal.style.Style(
73+
plot_background='transparent',
74+
background='transparent',
75+
foreground='rgba(0, 0, 0, 0.7)',
76+
foreground_strong='rgba(0, 0, 0, 0.9)',
77+
foreground_subtle='rgba(0, 0, 0, 0.2)',
78+
opacity_hover='.4',
79+
colors=('#4444ff', '#8cedff', '#b6e354',
80+
'#feed6c', '#ff9966', '#ff0000',
81+
'#ff00cc', '#899ca1', '#bf4646')
82+
)
83+
84+
PYGAL_STYLES = {
85+
'gitchart_dark': GITCHART_DARK_STYLE,
86+
'gitchart_light': GITCHART_LIGHT_STYLE,
87+
'default': pygal.style.DefaultStyle,
88+
'dark': pygal.style.DarkStyle,
89+
'neon': pygal.style.NeonStyle,
90+
'dark_solarized': pygal.style.DarkSolarizedStyle,
91+
'light_solarized': pygal.style.LightSolarizedStyle,
92+
'light': pygal.style.LightStyle,
93+
'clean': pygal.style.CleanStyle,
94+
'red_blue': pygal.style.RedBlueStyle,
95+
'dark_colorized': pygal.style.DarkColorizedStyle,
96+
'light_colorized': pygal.style.LightSolarizedStyle,
97+
'turquoise': pygal.style.TurquoiseStyle,
98+
'light_green': pygal.style.LightGreenStyle,
99+
'dark_green': pygal.style.DarkGreenStyle,
100+
'dark_green_blue': pygal.style.DarkGreenBlueStyle,
101+
'blue': pygal.style.BlueStyle,
102+
}
103+
104+
DEFAULT_STYLE = 'gitchart_light'
105+
58106

59107
# pylint: disable=too-few-public-methods,too-many-instance-attributes
60108
class GitChart:
@@ -77,23 +125,11 @@ class GitChart:
77125
for day in range(1, 8)]
78126
months = [datetime.date(2001, month, 1).strftime('%b')
79127
for month in range(1, 13)]
80-
# Pygal style with transparent background and custom colors
81-
style = pygal.style.Style(
82-
background='transparent',
83-
plot_background='transparent',
84-
foreground='rgba(0, 0, 0, 0.9)',
85-
foreground_light='rgba(0, 0, 0, 0.6)',
86-
foreground_dark='rgba(0, 0, 0, 0.2)',
87-
opacity_hover='.4',
88-
colors=('#9999ff', '#8cedff', '#b6e354',
89-
'#feed6c', '#ff9966', '#ff0000',
90-
'#ff00cc', '#899ca1', '#bf4646')
91-
)
92128

93129
# pylint: disable=too-many-arguments
94130
def __init__(self, chart_name, title=None, repository='.', no_merges=False,
95131
output=None, max_diff=20, sort_max=0, issues_regex='',
96-
js='', in_data=None):
132+
js='', style=DEFAULT_STYLE, in_data=None):
97133
self.chart_name = chart_name
98134
self.title = title if title is not None else self.charts[chart_name]
99135
self.repository = repository
@@ -105,6 +141,7 @@ def __init__(self, chart_name, title=None, repository='.', no_merges=False,
105141
self.sort_max = sort_max
106142
self.issues_regex = issues_regex
107143
self.javascript = js.split(',')
144+
self.style = PYGAL_STYLES[style]
108145
self.in_data = in_data
109146

110147
def _git_command(self, command1, command2=None):
@@ -456,6 +493,12 @@ def main():
456493
'-j', '--js',
457494
default=','.join(pygal_config.js),
458495
help='comma-separated list of javascript files/links used in SVG')
496+
styles = ', '.join(PYGAL_STYLES.keys())
497+
parser.add_argument(
498+
'-S', '--style',
499+
default=DEFAULT_STYLE,
500+
choices=PYGAL_STYLES.keys(),
501+
help=f'Pygal style to use, one of: {styles}')
459502
charts = ', '.join(sorted(GitChart.charts))
460503
parser.add_argument(
461504
'chart',
@@ -492,7 +535,7 @@ def main():
492535
# generate chart
493536
chart = GitChart(args.chart, args.title, args.repo, args.no_merges,
494537
args.output, args.max_diff, args.sort_max,
495-
args.issues_regex, args.js, in_data)
538+
args.issues_regex, args.js, args.style, in_data)
496539
if chart.generate():
497540
sys.exit(0)
498541

0 commit comments

Comments
 (0)