Browse Source

Fix negative and histogram

pull/293/head
Florian Mounier 9 years ago
parent
commit
8381ea3539
  1. 6
      demo/moulinrouge/tests.py
  2. 10
      pygal/graph/bar.py
  3. 5
      pygal/graph/histogram.py

6
demo/moulinrouge/tests.py

@ -353,11 +353,11 @@ def get_test_routes(app):
@app.route('/test/bar/position') @app.route('/test/bar/position')
def test_bar_print_values_position(): def test_bar_print_values_position():
bar = HorizontalBar(print_values=True, print_values_position='top', bar = StackedBar(print_values=True, print_values_position='top', zero=2,
style=styles['default']( style=styles['default'](
value_font_family='googlefont:Raleway', value_font_family='googlefont:Raleway',
value_font_size=46)) value_font_size=46))
bar.add('1', [-1, 2, 3]) bar.add('1', [1, -2, 3])
bar.add('2', [4, -5, 6]) bar.add('2', [4, -5, 6])
bar.x_labels = [2, 4, 6] bar.x_labels = [2, 4, 6]
bar.x_labels_major = [4] bar.x_labels_major = [4]
@ -365,7 +365,7 @@ def get_test_routes(app):
@app.route('/test/histogram') @app.route('/test/histogram')
def test_histogram(): def test_histogram():
hist = Histogram(style=styles['neon']) hist = Histogram(print_values=True, print_values_position='top', style=styles['neon'])
hist.add('1', [ hist.add('1', [
(2, 0, 1), (2, 0, 1),
(4, 1, 3), (4, 1, 3),

10
pygal/graph/bar.py

@ -67,21 +67,25 @@ class Bar(Graph):
x_center, y_center = transpose((x + width / 2, y + height / 2)) x_center, y_center = transpose((x + width / 2, y + height / 2))
x_top, y_top = transpose((x + width, y + height)) x_top, y_top = transpose((x + width, y + height))
x_bottom, y_bottom = transpose((x, y)) x_bottom, y_bottom = transpose((x, y))
sign = -1 if height < self.zero else 1 if self._dual:
v = serie.values[i][0]
else:
v = serie.values[i]
sign = -1 if v < self.zero else 1
self._tooltip_data( self._tooltip_data(
parent, val, x_center, y_center, "centered", parent, val, x_center, y_center, "centered",
self._get_x_label(i)) self._get_x_label(i))
if self.print_values_position == 'top': if self.print_values_position == 'top':
if self.horizontal: if self.horizontal:
x = x_bottom - sign * self.style.value_font_size / 2 x = x_bottom + sign * self.style.value_font_size / 2
y = y_center y = y_center
else: else:
x = x_center x = x_center
y = y_bottom - sign * self.style.value_font_size / 2 y = y_bottom - sign * self.style.value_font_size / 2
elif self.print_values_position == 'bottom': elif self.print_values_position == 'bottom':
if self.horizontal: if self.horizontal:
x = x_top - sign * self.style.value_font_size / 2 x = x_top + sign * self.style.value_font_size / 2
y = y_center y = y_center
else: else:
x = x_center x = x_center

5
pygal/graph/histogram.py

@ -33,6 +33,11 @@ class Histogram(Dual, Bar):
"""Histogram chart class""" """Histogram chart class"""
_series_margin = 0 _series_margin = 0
@cached_property
def _values(self):
"""Getter for secondary series values (flattened)"""
return self.yvals
@cached_property @cached_property
def _secondary_values(self): def _secondary_values(self):
"""Getter for secondary series values (flattened)""" """Getter for secondary series values (flattened)"""

Loading…
Cancel
Save