From cbe70dd899bab374dfb02a5b325dd8a979adf441 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 28 Sep 2012 10:49:58 +0200 Subject: [PATCH] Remove value from dict this fixes #4 and fix zero value in gauge --- demo/moulinrouge/tests.py | 8 +++++++- pygal/css/graph.css | 2 +- pygal/graph/gauge.py | 7 ++++--- pygal/test/test_graph.py | 2 ++ pygal/util.py | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 7406709..241f1eb 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -25,7 +25,7 @@ def get_test_routes(app): @app.route('/test/bar_links') def test_bar_links(): - bar = Bar(style=styles['neon']) + bar = Gauge(style=styles['neon']) bar.add('1234', [ {'value': 10, 'label': 'Ten', @@ -106,6 +106,12 @@ def get_test_routes(app): graph.add('2', [7, -4, 10, None, 8, 3, 1]) return graph.render_response() + @app.route('/test/negative/') + def test_negative_for(chart): + graph = CHARTS_BY_NAME[chart](interpolate='cubic') + graph.add('1', [10, 0, -10]) + return graph.render_response() + @app.route('/test/stacked') def test_stacked(): stacked = StackedBar() diff --git a/pygal/css/graph.css b/pygal/css/graph.css index 7b7f5c4..40fcd28 100644 --- a/pygal/css/graph.css +++ b/pygal/css/graph.css @@ -58,7 +58,7 @@ text.no_data { stroke-dasharray: 4,4; } -.axis .major.line { +.axis .major.guide.line { stroke-dasharray: 6,6; } .axis text.major { diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 989afe3..b8c7e02 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -50,7 +50,7 @@ class Gauge(Graph): def needle(self, serie_node, serie,): thickness = .05 for i, value in enumerate(serie.values): - if not value: + if value is None: continue theta = self.arc_pos(value) fmt = lambda x: '%f %f' % x @@ -90,8 +90,9 @@ class Gauge(Graph): self.svg.line( guides, [self.view((0, theta)), self.view((.95, theta))], close=True, - class_='guide line %s' % ('major' - if i in (0, len(self._x_labels) - 1) else '')) + class_='guide line %s' % ( + 'major' if i in (0, len(self._x_labels) - 1) + else '')) x, y = self.view((.9, theta)) self.svg.node(guides, 'text', diff --git a/pygal/test/test_graph.py b/pygal/test/test_graph.py index ae1c7ff..57901fc 100644 --- a/pygal/test/test_graph.py +++ b/pygal/test/test_graph.py @@ -86,6 +86,8 @@ def test_metadata(Chart): 'Five', 'http://7.example.com/', 'Seven'): assert md in cut(q('desc'), 'text') + assert len(v) == len(q('.tooltip-trigger').siblings('.value')) + def test_empty_lists(Chart): chart = Chart() diff --git a/pygal/util.py b/pygal/util.py index 9b62379..b224741 100644 --- a/pygal/util.py +++ b/pygal/util.py @@ -323,7 +323,7 @@ def prepare_values(raw, config, cls): (width - len(raw_values)) * [None] # aligning values if len(raw_values) < width else [])): if isinstance(raw_value, dict): - value = dict(raw_value).pop('value') + value = raw_value.pop('value') metadata[index] = raw_value else: value = raw_value