Browse Source

Add a way to specify style/color on nodes. References: #184

pull/158/merge
Florian Mounier 10 years ago
parent
commit
505a117fe4
  1. 13
      demo/moulinrouge/tests.py
  2. 9
      pygal/util.py

13
demo/moulinrouge/tests.py

@ -535,4 +535,17 @@ def get_test_routes(app):
graph.legend_at_bottom = True
return graph.render_response()
@app.route('/test/custom_metadata/<chart>')
def test_custom_metadata_for(chart):
c = CHARTS_BY_NAME[chart]()
c.add('1', [
{'style': 'fill: red', 'value': 1},
{'color': 'blue', 'value': 2},
{'style': 'fill: red; stroke: yellow', 'value': 3}])
c.add('2', [
{'value': 4},
{'color': 'green', 'value': 5},
6])
return c.render_response()
return list(sorted(filter(lambda x: x.startswith('test'), locals())))

9
pygal/util.py

@ -239,11 +239,20 @@ def decorate(svg, node, metadata):
xlink = {'href': xlink, 'target': '_blank'}
node = svg.node(node, 'a', **xlink)
if 'color' in metadata:
color = metadata.pop('color')
node.attrib['style'] = 'fill: %s; stroke: %s' % (
color, color)
if 'style' in metadata:
node.attrib['style'] = metadata.pop('style')
for key, value in metadata.items():
if key == 'xlink' and isinstance(value, dict):
value = value.get('href', value)
if value:
svg.node(node, 'desc', class_=key).text = to_unicode(value)
return node

Loading…
Cancel
Save