Skip to content

Commit

Permalink
Fix negative and histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jan 4, 2016
1 parent 45da938 commit 8381ea3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions demo/moulinrouge/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,19 @@ def test_bar():

@app.route('/test/bar/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'](
value_font_family='googlefont:Raleway',
value_font_size=46))
bar.add('1', [-1, 2, 3])
bar.add('1', [1, -2, 3])
bar.add('2', [4, -5, 6])
bar.x_labels = [2, 4, 6]
bar.x_labels_major = [4]
return bar.render_response()

@app.route('/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', [
(2, 0, 1),
(4, 1, 3),
Expand Down
10 changes: 7 additions & 3 deletions pygal/graph/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@ def _tooltip_and_print_values(
x_center, y_center = transpose((x + width / 2, y + height / 2))
x_top, y_top = transpose((x + width, y + height))
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(
parent, val, x_center, y_center, "centered",
self._get_x_label(i))

if self.print_values_position == 'top':
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
else:
x = x_center
y = y_bottom - sign * self.style.value_font_size / 2
elif self.print_values_position == 'bottom':
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
else:
x = x_center
Expand Down
5 changes: 5 additions & 0 deletions pygal/graph/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class Histogram(Dual, Bar):
"""Histogram chart class"""
_series_margin = 0

@cached_property
def _values(self):
"""Getter for secondary series values (flattened)"""
return self.yvals

@cached_property
def _secondary_values(self):
"""Getter for secondary series values (flattened)"""
Expand Down

0 comments on commit 8381ea3

Please sign in to comment.