diff --git a/pygal/base.py b/pygal/base.py index deca0eb..1456f04 100644 --- a/pygal/base.py +++ b/pygal/base.py @@ -7,7 +7,7 @@ class BaseGraph(object): self.draw() return self.svg.render() - def _in_browser(self): + def _in_browser(self, *args, **kwargs): from lxml.html import open_in_browser - self.draw() + self.draw(*args, **kwargs) open_in_browser(self.svg.root, encoding='utf-8') diff --git a/pygal/line.py b/pygal/line.py index 1466ff6..36e135a 100644 --- a/pygal/line.py +++ b/pygal/line.py @@ -6,12 +6,14 @@ from pygal.base import BaseGraph class Line(BaseGraph): """Line graph""" - def __init__(self, width, height, scale_int=False): + def __init__(self, width, height, precision=5, + format='g', style=None): self.width = width self.height = height - self.svg = Svg(width, height) + self.svg = Svg(width, height, style=style) self.label_font_size = 12 - self.scale_int = scale_int + self.format = format + self.precision = precision self.series = [] self.x_labels = self.y_labels = self.title = None @@ -24,8 +26,9 @@ class Line(BaseGraph): label = ymin labels = [] while label < ymax: - lbl = int(label) if self.scale_int else label - labels.append(Label(str(lbl), lbl)) + labels.append( + Label(('{:.%d%s}' % ( + self.precision, self.format)).format(label), label)) label += step return labels diff --git a/pygal/style.py b/pygal/style.py index a56018e..3f44f18 100644 --- a/pygal/style.py +++ b/pygal/style.py @@ -28,3 +28,12 @@ class Style(object): return '\n'.join(map(color, enumerate(self._colors))) DefaultStyle = Style() +LightStyle = Style( + background='transparent', + plot_background='rgba(0, 0, 255, 0.1)', + foreground='rgba(0, 0, 0, 0.7)', + foreground_light='rgba(0, 0, 0, 0.9)', + foreground_dark='rgba(0, 0, 0, 0.5)', + colors=('#242424', '#9f6767', '#92ac68', + '#d0d293', '#9aacc3', '#bb77a4', + '#77bbb5', '#777777')) diff --git a/pygal/svg.py b/pygal/svg.py index 80d6760..d7d364b 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -8,10 +8,11 @@ class Svg(object): """Svg object""" ns = 'http://www.w3.org/2000/svg' - def __init__(self, width, height, base_css=None): + def __init__(self, width, height, base_css=None, style=None): self.width = width self.height = height self.margin = () + self.style = style or DefaultStyle self.root = etree.Element( "{%s}svg" % self.ns, attrib={ @@ -40,7 +41,7 @@ class Svg(object): .replace(' }}', '\x00') .replace('}', '}}') .replace('\x00', '}') - .format(style=DefaultStyle)) + .format(style=self.style)) def node(self, parent=None, tag='g', attrib=None, **extras): if parent is None: diff --git a/pygal/test/test_line.py b/pygal/test/test_line.py index cdf2dd4..cf8bbe2 100644 --- a/pygal/test/test_line.py +++ b/pygal/test/test_line.py @@ -1,14 +1,14 @@ -from pygal import Serie, Margin, Label from pygal.line import Line +from pygal.style import LightStyle from math import cos, sin def test_simple_line(): - line = Line(800, 600) - line.add('test1', [cos(x / 10.) for x in range(-30, 30, 5)]) - line.add('test2', [sin(x / 10.) for x in range(-30, 30, 5)]) - line.add('test3', [cos(x / 10.) - sin(x / 10.) for x in range(-30, 30, 5)]) - line.x_labels = map(str, range(-30, 30, 5)) - # line.y_labels = [Label(str(lbl / 100.), lbl / 100.) for lbl in range(20)] + line = Line(800, 600, style=LightStyle, precision=2, format='f') + rng = range(-30, 30, 5) + line.add('test1', [cos(x / 10.) for x in rng]) + line.add('test2', [sin(x / 10.) for x in rng]) + line.add('test3', [cos(x / 10.) - sin(x / 10.) for x in rng]) + line.x_labels = map(str, rng) line.title = "cos sin and cos - sin" line._in_browser()