From aa795a15babbe44047a6baac26d86415a1a23af0 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 23 Jun 2015 10:49:25 +0200 Subject: [PATCH] Fix datetimeline time data. Fix #193. --- demo/moulinrouge/tests.py | 15 ++++++++++++++- pygal/graph/time.py | 2 +- pygal/svg.py | 9 +++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 06930e6..968cb1e 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -4,7 +4,7 @@ from pygal import ( Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, StackedLine, XY, CHARTS_BY_NAME, Config, Line, Worldmap, Histogram, Box, SwissMapCantons, FrenchMapDepartments, FrenchMapRegions, Pie, Treemap, TimeLine, DateLine, - SupranationalWorldmap) + DateTimeLine, SupranationalWorldmap) from pygal.style import styles, Style, RotateStyle @@ -642,4 +642,17 @@ def get_test_routes(app): line.add('zeroes 2', [0]) return line.render_response() + @app.route('/test/datetimeline') + def test_datetimeline(): + line = DateTimeLine() + line.add('dt', [ + (datetime(2013, 1, 12, 8, 0), 300), + (datetime(2013, 1, 12, 12), 412), + (datetime(2013, 2, 22, 12), 823), + (datetime(2013, 2, 22, 20), 672) + ]) + line.x_value_formatter = lambda x: x.strftime("%Y-%m-%d") + line.x_label_rotation = 45 + return line.render_response() + return list(sorted(filter(lambda x: x.startswith('test'), locals()))) diff --git a/pygal/graph/time.py b/pygal/graph/time.py index 2c10f60..570c71f 100644 --- a/pygal/graph/time.py +++ b/pygal/graph/time.py @@ -32,7 +32,7 @@ def datetime_to_timestamp(x): def date_to_datetime(x): - if isinstance(x, date): + if not isinstance(x, datetime) and isinstance(x, date): return datetime.combine(x, time()) return x diff --git a/pygal/svg.py b/pygal/svg.py index 169f33d..21b1747 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -124,10 +124,11 @@ class Svg(object): common_script = self.node(self.defs, 'script', type='text/javascript') def get_js_dict(): - return dict((k, getattr(self.graph.state, k)) - for k in dir(self.graph.config) - if not k.startswith('_') and not hasattr( - getattr(self.graph.config, k), '__call__')) + return dict( + (k, getattr(self.graph.state, k)) + for k in dir(self.graph.config) + if not k.startswith('_') and hasattr(self.graph.state, k) and + not hasattr(getattr(self.graph.state, k), '__call__')) def json_default(o): if isinstance(o, (datetime, date)):