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)):