diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index e12cb39..3ef2c7a 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -353,11 +353,11 @@ def get_test_routes(app): @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] @@ -365,7 +365,7 @@ def get_test_routes(app): @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), diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index d8c8d1f..83e42d3 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -67,21 +67,25 @@ class Bar(Graph): 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 diff --git a/pygal/graph/histogram.py b/pygal/graph/histogram.py index 45defb3..a27b05d 100644 --- a/pygal/graph/histogram.py +++ b/pygal/graph/histogram.py @@ -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)"""