saving images
diff --git a/chart/charts.py b/chart/charts.py
index 331afae..d4ecfae 100644
--- a/chart/charts.py
+++ b/chart/charts.py
@@ -1,12 +1,24 @@
+import hashlib
+import os
+import threading
+
from GChartWrapper import VerticalBarGroup
from GChartWrapper import Line
from GChartWrapper import constants
+from config import CHARTS_IMG_PATH
+
COLORS = ["1569C7", "81D8D0", "307D7E", "5CB3FF", "blue", "indigo"]
constants.MARKERS += 'E' # append E marker to available markers
+def save_image(chart, img_path):
+ t = threading.Thread(target=chart.save, kwargs={'fname': img_path})
+ t.daemon = True
+ t.start()
+
+
def render_vertical_bar(title, legend, dataset, width=700, height=400, scale_x=None,
scale_y=None):
"""
@@ -77,7 +89,12 @@
bar.color(*COLORS[:len(values)])
bar.size(width, height)
- return bar
+ img_name = hashlib.md5(str(bar)).hexdigest() + ".png"
+ img_path = os.path.join(CHARTS_IMG_PATH, img_name)
+ if not os.path.exists(img_path):
+ save_image(bar, img_path)
+ return str(bar)
+ return img_path
def render_lines(title, legend, dataset, scale_x, width=700, height=400):
@@ -93,4 +110,12 @@
line.legend(*legend)
line.color(*COLORS[:len(legend)])
line.size(width, height)
- return str(line)
+
+ import pdb;pdb.set_trace()
+
+ img_name = hashlib.md5(str(line)).hexdigest() + ".png"
+ img_path = os.path.join(CHARTS_IMG_PATH, img_name)
+ if not os.path.exists(img_path):
+ save_image(line, img_path)
+ return str(line)
+ return img_path