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: if rescale and self.secondary_series:
points = [ points = [
(x, self._scale_diff + (y - self._scale_min_2nd) * self._scale) (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: else:
points = serie.points points = serie.points
@ -121,7 +121,7 @@ class Bar(Graph):
ymax = new_ymax ymax = new_ymax
left_range = abs(self._box.ymax - self._box.ymin) 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 = left_range / right_range
self._scale_diff = self._box.ymin self._scale_diff = self._box.ymin
self._scale_min_2nd = ymin self._scale_min_2nd = ymin

10
pygal/graph/datey.py

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

2
pygal/graph/graph.py

@ -472,7 +472,7 @@ class Graph(BaseGraph):
ymax = self._secondary_max ymax = self._secondary_max
steps = len(y_pos) steps = len(y_pos)
left_range = abs(y_pos[-1] - y_pos[0]) 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) scale = right_range / (steps - 1)
self._y_2nd_labels = [(self._format(ymin + i * scale), pos) self._y_2nd_labels = [(self._format(ymin + i * scale), pos)
for i, pos in enumerate(y_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): def line(self, serie_node, serie, rescale=False):
"""Draw the line serie""" """Draw the line serie"""
if rescale and self.secondary_series: if rescale and self.secondary_series:
points = [] points = [
for x, y in serie.points: (x, self._scale_diff + (y - self._scale_min_2nd) * self._scale)
if y is not None: 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))
else: else:
points = serie.points points = serie.points
view_values = list(map(self.view, points)) view_values = list(map(self.view, points))

4
pygal/graph/verticalpyramid.py

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

Loading…
Cancel
Save