web/views/plots.py
changeset 4252 6c4f109c2b03
parent 4045 f4a52abb6f4f
parent 4212 ab6573088b4a
child 4320 4efd4c306746
--- a/web/views/plots.py	Mon Jan 18 19:05:08 2010 +0100
+++ b/web/views/plots.py	Mon Jan 18 19:21:30 2010 +0100
@@ -1,7 +1,7 @@
 """basic plot views
 
 :organization: Logilab
-:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL.
+:copyright: 2007-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
@@ -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 = []