Browse Source

Fix datetimeline time data. Fix #193.

pull/219/merge
Florian Mounier 10 years ago
parent
commit
aa795a15ba
  1. 15
      demo/moulinrouge/tests.py
  2. 2
      pygal/graph/time.py
  3. 9
      pygal/svg.py

15
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())))

2
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

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

Loading…
Cancel
Save