Browse Source

Add the ability to inheritate a parametric style from another style

pull/39/head
Florian Mounier 12 years ago
parent
commit
4fb327e030
  1. 6
      demo/moulinrouge/__init__.py
  2. 10
      pygal/style.py

6
demo/moulinrouge/__init__.py

@ -112,15 +112,17 @@ def create_app():
@app.route("/all") @app.route("/all")
@app.route("/all/<style>") @app.route("/all/<style>")
@app.route("/all/<style>/<color>") @app.route("/all/<style>/<color>")
@app.route("/all/<style>/<color>/<base_style>")
@app.route("/all/interpolate=<interpolate>") @app.route("/all/interpolate=<interpolate>")
def all(style='default', color=None, interpolate=None): def all(style='default', color=None, interpolate=None, base_style=None):
width, height = 600, 400 width, height = 600, 400
data = random.randrange(1, 10) data = random.randrange(1, 10)
order = random.randrange(1, 10) order = random.randrange(1, 10)
if color is None: if color is None:
style = styles[style] style = styles[style]
else: else:
style = parametric_styles[style](color) style = parametric_styles[style](
color, base_style=styles[base_style or 'default'])
xy_series = _random(data, order) xy_series = _random(data, order)
other_series = [] other_series = []
for title, values in xy_series: for title, values in xy_series:

10
pygal/style.py

@ -260,7 +260,8 @@ for op in ('lighten', 'darken', 'saturate', 'desaturate', 'rotate'):
def get_style_for(op_name): def get_style_for(op_name):
operation = getattr(colors, op_name) operation = getattr(colors, op_name)
def parametric_style(color, step=10, max_=None, **kwargs): def parametric_style(color, step=10, max_=None,
base_style=None, **kwargs):
if max_ is None: if max_ is None:
violency = { violency = {
'darken': 50, 'darken': 50,
@ -278,7 +279,12 @@ for op in ('lighten', 'darken', 'saturate', 'desaturate', 'rotate'):
return operation(color, percent) return operation(color, percent)
colors = list(map(modifier, range(0, max(2, step)))) colors = list(map(modifier, range(0, max(2, step))))
return Style(colors=colors, **kwargs) if base_style is None:
return Style(colors=colors, **kwargs)
base_style.__dict__.update(kwargs)
base_style._colors = colors
return base_style
return parametric_style return parametric_style

Loading…
Cancel
Save