do not recompute the plot on subsequent onload events #615338 stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 05 Jan 2010 18:28:27 +0100
branchstable
changeset 4209 8712d699beb2
parent 4208 b2826afdaf8c
child 4210 9d9be21640ac
do not recompute the plot on subsequent onload events #615338
web/views/plots.py
--- a/web/views/plots.py	Tue Jan 05 17:04:29 2010 +0100
+++ b/web/views/plots.py	Tue Jan 05 18:28:27 2010 +0100
@@ -78,15 +78,19 @@
 
 class FlotPlotWidget(PlotWidget):
     """PlotRenderer widget using Flot"""
-    onload = u'''
-%(plotdefs)s
-jQuery.plot(jQuery("#%(figid)s"), [%(plotdata)s],
-    {points: {show: true},
-     lines: {show: true},
-     grid: {hoverable: true},
-     xaxis: {mode: %(mode)s}});
-jQuery("#%(figid)s").bind("plothover", onPlotHover);
-'''
+    onload = u"""
+var fig = jQuery("#%(figid)s");
+if (fig.attr('cubicweb:type') != 'prepared-plot') {
+    %(plotdefs)s
+    jQuery.plot(jQuery("#%(figid)s"), [%(plotdata)s],
+        {points: {show: true},
+         lines: {show: true},
+         grid: {hoverable: true},
+         xaxis: {mode: %(mode)s}});
+    jQuery("#%(figid)s").bind("plothover", onPlotHover);
+    fig.attr('cubicweb:type','prepared-plot');
+}
+"""
 
     def __init__(self, labels, plots, timemode=False):
         self.labels = labels
@@ -102,8 +106,9 @@
         return dumps(plot)
 
     def _render(self, req, width=500, height=400):
-        # XXX IE requires excanvas.js
-        req.add_js( ('jquery.flot.js', 'cubicweb.flot.js', 'excanvas.js') )
+        if req.ie_browser():
+            req.add_js('excanvas.js')
+        req.add_js(('jquery.flot.js', 'cubicweb.flot.js'))
         figid = u'figure%s' % req.varmaker.next()
         plotdefs = []
         plotdata = []