From 7bccd1e586b653c35343037046e3a05d4e848634 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 30 Oct 2015 17:56:54 +0100 Subject: [PATCH] Add `dynamic_print_values` to show print_values on legend hover. (Fix #279) --- demo/moulinrouge/tests.py | 3 ++- docs/changelog.rst | 6 ++++++ docs/documentation/configuration/data.rst | 14 ++++++++++++++ pygal/config.py | 4 ++++ pygal/css/graph.css | 8 ++++++++ pygal/graph/graph.py | 5 +++-- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 183b007..dbe80b0 100644 --- a/demo/moulinrouge/tests.py +++ b/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'] diff --git a/docs/changelog.rst b/docs/changelog.rst index bafec30..6344d3e 100644 --- a/docs/changelog.rst +++ b/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 ===== diff --git a/docs/documentation/configuration/data.rst b/docs/documentation/configuration/data.rst index 6d9fad0..04ec317 100644 --- a/docs/documentation/configuration/data.rst +++ b/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 ------------ diff --git a/pygal/config.py b/pygal/config.py index b56c174..faadb73 100644 --- a/pygal/config.py +++ b/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", diff --git a/pygal/css/graph.css b/pygal/css/graph.css index 7e93d53..95563c5 100644 --- a/pygal/css/graph.css +++ b/pygal/css/graph.css @@ -119,3 +119,11 @@ {{ id }}.tooltip text { fill-opacity: 1; } + +{{ id }}.showable { + visibility: hidden; +} + +{{ id }}.showable.shown { + visibility: visible; +} diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index a381a37..eb5cebc 100644 --- a/pygal/graph/graph.py +++ b/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 ''