Browse Source

Trying some scale

pull/8/head
Florian Mounier 13 years ago
parent
commit
6dc912dffa
  1. 10
      pygal/line.py
  2. 9
      pygal/svg.py

10
pygal/line.py

@ -17,9 +17,15 @@ class Line(BaseGraph):
Serie(title, values)) Serie(title, values))
def draw(self): def draw(self):
self.svg.graph() min_value = min((val
for serie in self.series
for val in serie.values))
max_value = max((val
for serie in self.series
for val in serie.values))
self.svg.graph(min_value, max_value)
for serie in self.series: for serie in self.series:
n_values = len(serie.values) n_values = len(serie.values) - 1
x_spacing = self.width / n_values x_spacing = self.width / n_values
self.svg.line([ self.svg.line([
(i * x_spacing, v) (i * x_spacing, v)

9
pygal/svg.py

@ -35,15 +35,18 @@ class Svg(object):
def format_coords(self, xy): def format_coords(self, xy):
return '%f %f' % xy return '%f %f' % xy
def graph(self): def graph(self, min_value, max_value):
self.graph = self.node(id='graph') self.graph = self.node(
id='graph',
transform="scale(1, %d) translate(0, %d)" % (
self.height / (max_value - min_value), -min_value))
self.node(self.graph, 'rect', id='graph_background', self.node(self.graph, 'rect', id='graph_background',
x=0, y=0, width=self.width, height=self.height) x=0, y=0, width=self.width, height=self.height)
def line(self, values, origin=None): def line(self, values, origin=None):
origin = self.format_coords(origin or values[0]) origin = self.format_coords(origin or values[0])
values = ' '.join(map(self.format_coords, values)) values = ' '.join(map(self.format_coords, values))
self.node(self.graph, 'path', self.node(self.graph, 'path', style="stroke: blue",
d='M%s L%s' % (origin, values)) d='M%s L%s' % (origin, values))
def render(self): def render(self):

Loading…
Cancel
Save