Browse Source

Better sparklines with labels. Fix #239

pull/242/head
Florian Mounier 10 years ago
parent
commit
310961a627
  1. 23
      demo/moulinrouge/tests.py
  2. 10
      docs/documentation/sparks.rst
  3. 2
      pygal/graph/public.py

23
demo/moulinrouge/tests.py

@ -672,6 +672,29 @@ def get_test_routes(app):
graph.legend_at_bottom = True graph.legend_at_bottom = True
return graph.render_response() return graph.render_response()
@app.route('/test/sparkline/label/<chart>')
def test_sparkline_label_for(chart):
graph = CHARTS_BY_NAME[chart](**dict(
width=200,
height=50,
show_dots=False,
show_legend=False,
# show_y_labels=False,
# show_x_labels=False,
spacing=0,
margin=5,
min_scale=2,
max_scale=2,
explicit_size=True
))
graph.add('1', [1, 3, 12, 3, 4, None, 9])
graph.add('2', [7, -4, 10, None, 8, 3, 1])
graph.add('3', [7, -14, -10, None, 8, 3, 1])
graph.add('4', [7, 4, -10, None, 8, 3, 1])
graph.x_labels = ('a', 'b', 'c', 'd', 'e', 'f', 'g')
graph.legend_at_bottom = True
return graph.render_response()
@app.route('/test/normal/<chart>') @app.route('/test/normal/<chart>')
def test_normal_for(chart): def test_normal_for(chart):
graph = CHARTS_BY_NAME[chart]() graph = CHARTS_BY_NAME[chart]()

10
docs/documentation/sparks.rst

@ -32,6 +32,16 @@ Sparklines support the same options as normal charts but for those that are over
chart.add('', [1, 3, 5, 16, 13, 3, 7, 9, 2, 1, 4, 9, 12, 10, 12, 16, 14, 12, 7, 2]) chart.add('', [1, 3, 5, 16, 13, 3, 7, 9, 2, 1, 4, 9, 12, 10, 12, 16, 14, 12, 7, 2])
chart.render_sparkline(width=500, height=25, show_dots=True) chart.render_sparkline(width=500, height=25, show_dots=True)
With labels:
.. pygal-code:: sparkline
from pygal.style import LightSolarizedStyle
chart = pygal.Line(style=LightSolarizedStyle)
chart.add('', [1, 3, 5, 16, 13, 3, 7])
chart.x_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
chart.render_sparkline(show_x_labels=True, show_y_labels=True)
Sparktext Sparktext
--------- ---------

2
pygal/graph/public.py

@ -139,6 +139,8 @@ class PublicApi(BaseGraph):
show_y_labels=False, show_y_labels=False,
spacing=0, spacing=0,
margin=5, margin=5,
min_scale=1,
max_scale=2,
explicit_size=True explicit_size=True
) )
spark_options.update(kwargs) spark_options.update(kwargs)

Loading…
Cancel
Save