Browse Source

Adding annotation functionality

pull/337/head
James Portman 9 years ago
parent
commit
8753950a79
  1. 12
      pygal/css/graph.css
  2. 13
      pygal/graph/base.py
  3. 18
      pygal/graph/line.py

12
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;
}

13
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:

18
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

Loading…
Cancel
Save