Browse Source

Reverse horizontal series. Fix #229

pull/222/merge
Florian Mounier 10 years ago
parent
commit
3827cee67f
  1. 10
      pygal/graph/bar.py
  2. 2
      pygal/graph/base.py
  3. 2
      pygal/graph/histogram.py
  4. 2
      pygal/graph/stackedbar.py
  5. 4
      pygal/graph/verticalpyramid.py

10
pygal/graph/bar.py

@ -36,14 +36,18 @@ class Bar(Graph):
self._x_ranges = None self._x_ranges = None
super(Bar, self).__init__(*args, **kwargs) super(Bar, self).__init__(*args, **kwargs)
def _bar(self, serie, parent, x, y, i, zero, secondary=False): def _bar(self, serie, parent, x, y, zero, secondary=False):
width = (self.view.x(1) - self.view.x(0)) / self._len width = (self.view.x(1) - self.view.x(0)) / self._len
x, y = self.view((x, y)) x, y = self.view((x, y))
series_margin = width * self._series_margin series_margin = width * self._series_margin
x += series_margin x += series_margin
width -= 2 * series_margin width -= 2 * series_margin
width /= self._order width /= self._order
x += serie.index * width if self.horizontal:
i = self._order - serie.index
else:
i = serie.index
x += i * width
serie_margin = width * self._serie_margin serie_margin = width * self._serie_margin
x += serie_margin x += serie_margin
width -= 2 * serie_margin width -= 2 * serie_margin
@ -77,7 +81,7 @@ class Bar(Graph):
val = self._format(serie.values[i]) val = self._format(serie.values[i])
x_center, y_center = self._bar( x_center, y_center = self._bar(
serie, bar, x, y, i, self.zero, secondary=rescale) serie, bar, x, y, self.zero, secondary=rescale)
self._tooltip_data( self._tooltip_data(
bar, val, x_center, y_center, classes="centered") bar, val, x_center, y_center, classes="centered")
self._static_value(serie_node, val, x_center, y_center) self._static_value(serie_node, val, x_center, y_center)

2
pygal/graph/base.py

@ -185,11 +185,11 @@ class BaseGraph(object):
if getattr(self, 'y_labels', None) is not None: if getattr(self, 'y_labels', None) is not None:
self.y_labels = list(self.y_labels) self.y_labels = list(self.y_labels)
self.state = State(self, **kwargs) self.state = State(self, **kwargs)
self.horizontal = getattr(self, 'horizontal', False)
self.series = self.prepare_values( self.series = self.prepare_values(
self.raw_series) or [] self.raw_series) or []
self.secondary_series = self.prepare_values( self.secondary_series = self.prepare_values(
self.raw_series2, len(self.series)) or [] self.raw_series2, len(self.series)) or []
self.horizontal = getattr(self, 'horizontal', False)
self.svg = Svg(self) self.svg = Svg(self)
self._x_labels = None self._x_labels = None
self._y_labels = None self._y_labels = None

2
pygal/graph/histogram.py

@ -63,7 +63,7 @@ class Histogram(Graph):
sum(map(abs, self.xvals)) != 0, sum(map(abs, self.xvals)) != 0,
sum(map(abs, self.yvals)) != 0)) sum(map(abs, self.yvals)) != 0))
def _bar(self, serie, parent, x0, x1, y, i, zero, secondary=False): def _bar(self, serie, parent, x0, x1, y, zero, secondary=False):
x, y = self.view((x0, y)) x, y = self.view((x0, y))
x1, _ = self.view((x1, y)) x1, _ = self.view((x1, y))
width = x1 - x width = x1 - x

2
pygal/graph/stackedbar.py

@ -92,7 +92,7 @@ class StackedBar(Bar):
self._secondary_max = (positive_vals and max( self._secondary_max = (positive_vals and max(
max(positive_vals), self.zero)) or self.zero max(positive_vals), self.zero)) or self.zero
def _bar(self, serie, parent, x, y, i, zero, secondary=False): def _bar(self, serie, parent, x, y, zero, secondary=False):
if secondary: if secondary:
cumulation = (self.secondary_negative_cumulation cumulation = (self.secondary_negative_cumulation
if y < self.zero else if y < self.zero else

4
pygal/graph/verticalpyramid.py

@ -56,8 +56,8 @@ class VerticalPyramid(StackedBar):
self._secondary_max = max(max(positive_vals), max(negative_vals)) self._secondary_max = max(max(positive_vals), max(negative_vals))
self._secondary_min = - self._secondary_max self._secondary_min = - self._secondary_max
def _bar(self, serie, parent, x, y, i, zero, secondary=False): def _bar(self, serie, parent, x, y, zero, secondary=False):
if serie.index % 2: if serie.index % 2:
y = -y y = -y
return super(VerticalPyramid, self)._bar( return super(VerticalPyramid, self)._bar(
serie, parent, x, y, i, zero, secondary) serie, parent, x, y, zero, secondary)

Loading…
Cancel
Save