Browse Source

Add `dynamic_print_values` to show print_values on legend hover. (Fix #279)

pull/280/head
Florian Mounier 9 years ago
parent
commit
7bccd1e586
  1. 3
      demo/moulinrouge/tests.py
  2. 6
      docs/changelog.rst
  3. 14
      docs/documentation/configuration/data.rst
  4. 4
      pygal/config.py
  5. 8
      pygal/css/graph.css
  6. 5
      pygal/graph/graph.py

3
demo/moulinrouge/tests.py

@ -54,6 +54,7 @@ def get_test_routes(app):
bar.title = 'Wow ! Such Chart !'
bar.x_title = 'Many x labels'
bar.y_title = 'Much y labels'
bar.dynamic_print_values = True
bar.add('Red serie', [
{'value': 10,
@ -343,7 +344,7 @@ def get_test_routes(app):
@app.route('/test/bar')
def test_bar():
bar = Bar()
bar = Bar(dynamic_print_values=True)
bar.add('1', [1, 2, 3])
bar.add('2', [4, 5, 6])
bar.x_labels = ['a']

6
docs/changelog.rst

@ -2,6 +2,12 @@
Changelog
=========
2.0.9 UNRELEASED
================
* Add `dynamic_print_values` to show print_values on legend hover. (Fix #279)
2.0.8
=====

14
docs/documentation/configuration/data.rst

@ -39,6 +39,20 @@ When using pygal to display static charts for printing for example you can chose
value_colors=('white',)))
chart.add('line', [0, 12, 31, 8, 28, 0])
dynamic_print_values
--------------------
Show print_values only on legend hover.
.. pygal-code::
from pygal.style import DefaultStyle
chart = pygal.Bar(dynamic_print_values=True, style=DefaultStyle(
value_font_family='googlefont:Raleway',
value_font_size=30,
value_colors=('white',)))
chart.add('line', [0, 12, 31, 8, 28, 0])
print_zeroes
------------

4
pygal/config.py

@ -458,6 +458,10 @@ class Config(CommonConfig):
False, bool,
"Text", "Display value labels")
dynamic_print_values = Key(
False, bool,
"Text", "Show values only on hover")
truncate_legend = Key(
None, int, "Text",
"Legend string length truncation threshold",

8
pygal/css/graph.css

@ -119,3 +119,11 @@
{{ id }}.tooltip text {
fill-opacity: 1;
}
{{ id }}.showable {
visibility: hidden;
}
{{ id }}.showable.shown {
visibility: visible;
}

5
pygal/graph/graph.py

@ -472,10 +472,11 @@ class Graph(PublicApi):
).text = label
y += self.style.value_font_size
if self.print_values:
if self.print_values or self.dynamic_print_values:
self.svg.node(
serie_node['text_overlay'], 'text',
class_='centered value',
class_='centered value%s' % (
' showable' if self.dynamic_print_values else ''),
x=x,
y=y + self.style.value_font_size / 3
).text = value if self.print_zeroes or value != '0' else ''

Loading…
Cancel
Save