diff --git a/pygal/css/graph.css b/pygal/css/graph.css index a638fb7..2dd2eaa 100644 --- a/pygal/css/graph.css +++ b/pygal/css/graph.css @@ -150,3 +150,15 @@ stroke: {{ style.background }}; stroke-width: 2px; } + +{{ id }}.annotation.center { + text-anchor: middle; +} + +{{ id }}.annotation.right { + text-anchor: start; +} + +{{ id }}.annotation.left { + text-anchor: end; +} diff --git a/pygal/graph/base.py b/pygal/graph/base.py index b0bd939..9cb8cc0 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -158,9 +158,16 @@ class BaseGraph(object): elif not is_list_like(value): value = (value, self.zero) if self._x_adapt: - value = ( - self._x_adapt(value[0]), - self._adapt(value[1])) + if len(value) == 3: + value = ( + self._x_adapt(value[0]), + self._adapt(value[1]), + value[2]) + else: + value = ( + self._x_adapt(value[0]), + self._adapt(value[1])) + if isinstance(self, BaseMap): value = (self._adapt(value[0]), value[1]) else: diff --git a/pygal/graph/line.py b/pygal/graph/line.py index e7a1e4c..5f4e05c 100644 --- a/pygal/graph/line.py +++ b/pygal/graph/line.py @@ -133,6 +133,24 @@ class Line(Graph): y + self.style.value_font_size, metadata) + serie.show_annotations = True + if serie.show_annotations: + for i, (_, _, annotation) in enumerate(serie.values): + x = view_values[i][0] + y = view_values[i][1] + + shift_x = 0 + shift_y = -7 + + # TODO: draw it on the left of the point if its past half way across the X axis - how to tell? + self.svg.node( + serie_node['plot'], 'text', class_='text annotation point_annotation', + x=x, + y=y, + dx=shift_x, + dy=shift_y + ).text = annotation + if serie.stroke: if self.interpolate: points = serie.interpolated