Browse Source

Fix edge cases with datey and secondary axes

pull/58/head
Florian Mounier 12 years ago
parent
commit
6003e65ef1
  1. 4
      pygal/graph/bar.py
  2. 10
      pygal/graph/datey.py
  3. 2
      pygal/graph/graph.py
  4. 8
      pygal/graph/line.py
  5. 4
      pygal/graph/verticalpyramid.py

4
pygal/graph/bar.py

@ -63,7 +63,7 @@ class Bar(Graph):
if rescale and self.secondary_series:
points = [
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
for x, y in serie.points]
for x, y in serie.points if y is not None]
else:
points = serie.points
@ -121,7 +121,7 @@ class Bar(Graph):
ymax = new_ymax
left_range = abs(self._box.ymax - self._box.ymin)
right_range = abs(ymax - ymin)
right_range = abs(ymax - ymin) or 1
self._scale = left_range / right_range
self._scale_diff = self._box.ymin
self._scale_min_2nd = ymin

10
pygal/graph/datey.py

@ -50,7 +50,7 @@ class DateY(XY):
def _todate(self, d):
""" Converts a number to a date """
return str(self._offset + datetime.timedelta(seconds=d))
return str(self._offset + datetime.timedelta(seconds=d or 0))
def _tonumber(self, d):
""" Converts a date to a number """
@ -71,7 +71,7 @@ class DateY(XY):
for val in serie.values
if val[0] is not None]
or [datetime.datetime.fromtimestamp(0)])
for serie in self.series:
for serie in self.all_series:
serie.values = [(self._tonumber(v[0]), v[1]) for v in serie.values]
xvals = [val[0]
@ -89,7 +89,7 @@ class DateY(XY):
else:
rng = None
for serie in self.series:
for serie in self.all_series:
serie.points = serie.values
if self.interpolate and rng:
vals = list(zip(*sorted(
@ -99,10 +99,10 @@ class DateY(XY):
if self.interpolate and rng:
xvals = [val[0]
for serie in self.series
for serie in self.all_series
for val in serie.interpolated]
yvals = [val[1]
for serie in self.series
for serie in self.all_series
for val in serie.interpolated]
if xvals:
xmin = min(xvals)

2
pygal/graph/graph.py

@ -472,7 +472,7 @@ class Graph(BaseGraph):
ymax = self._secondary_max
steps = len(y_pos)
left_range = abs(y_pos[-1] - y_pos[0])
right_range = abs(ymax - ymin)
right_range = abs(ymax - ymin) or 1
scale = right_range / (steps - 1)
self._y_2nd_labels = [(self._format(ymin + i * scale), pos)
for i, pos in enumerate(y_pos)]

8
pygal/graph/line.py

@ -60,11 +60,9 @@ class Line(Graph):
def line(self, serie_node, serie, rescale=False):
"""Draw the line serie"""
if rescale and self.secondary_series:
points = []
for x, y in serie.points:
if y is not None:
y = self._scale_diff + (y - self._scale_min_2nd) * self._scale
points.append((x, y))
points = [
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
for x, y in serie.points if y is not None]
else:
points = serie.points
view_values = list(map(self.view, points))

4
pygal/graph/verticalpyramid.py

@ -22,7 +22,6 @@ Pyramid chart
"""
from __future__ import division
from pygal.util import compute_scale, safe_enumerate
from pygal.adapters import positive
from pygal.graph.stackedbar import StackedBar
@ -33,7 +32,8 @@ class VerticalPyramid(StackedBar):
_adapters = [positive]
def _format(self, value):
return super(VerticalPyramid, self)._format(abs(value))
value = value and abs(value)
return super(VerticalPyramid, self)._format(value)
def _get_separated_values(self, secondary=False):
series = self.secondary_series if secondary else self.series

Loading…
Cancel
Save