summaryrefslogtreecommitdiff
path: root/pngchart.py
diff options
context:
space:
mode:
authorPeter Ward <peteraward@gmail.com>2012-07-19 20:08:23 +1000
committerPeter Ward <peteraward@gmail.com>2012-07-19 20:08:23 +1000
commit93ba106c94b7a2d2109842432fed3dbe920c3558 (patch)
tree921f139e0db186f676cba9c3917489479c51ab88 /pngchart.py
parent7fb2789ea7b25a4825ff4b99a832758d3533ded5 (diff)
Move everything into a package.
Diffstat (limited to 'pngchart.py')
-rw-r--r--pngchart.py53
1 files changed, 0 insertions, 53 deletions
diff --git a/pngchart.py b/pngchart.py
deleted file mode 100644
index 5428718..0000000
--- a/pngchart.py
+++ /dev/null
@@ -1,53 +0,0 @@
-from pngcanvas import PNGCanvas
-
-try:
- from itertools import izip as zip
-except ImportError:
- pass
-
-class SimpleLineChart(object):
- def __init__(self, width, height, colours=None, legend=None):
- self.canvas = PNGCanvas(width, height)
-
- self.width = width
- self.height = height
-
- self.colours = colours
- self.legend = legend
-
- self.series = []
-
- def add_data(self, series):
- self.series.append(series)
-
- def render(self):
- max_width = max(map(len, self.series))
- max_height = max(map(max, self.series))
- x_scale = float(self.width) / max_width
- y_scale = float(self.height) / max_height
-
- data = zip(self.series, self.colours or [], self.legend or [])
- for series, colour, legend in data:
- colour = int(colour, 16)
- self.canvas.color = (
- colour>>16 & 0xff,
- colour>>8 & 0xff,
- colour & 0xff,
- 0xff,
- )
- last = None
- for x, y in enumerate(series):
- if y is not None:
- y = self.height - y * y_scale
- if last is not None:
- x *= x_scale
- self.canvas.line(x - x_scale, last, x, y)
- last = y
-
- def download(self, filename):
- self.render()
-
- f = open(filename, 'wb')
- f.write(self.canvas.dump())
- f.close()
-