Commits

Ralph Bean committed e8dadfd

Awesome

  • Participants
  • Parent commits 74bd184

Comments (0)

Files changed (4)

File tw2/jquery/plugins/jqplot/base.py

 
+import tw2.core as twc
 import tw2.jquery.base as twjq_c
 import defaults
 
     modname = 'tw2.jquery.plugins.jqplot',
     subdir = '',
 )
-
 jqplot_js = twjq_c.jQueryPluginJSLink(
     name=defaults._jqplot_name_,
     version=defaults._jqplot_version_,
     subdir = '',
 )
 
+class JQPlotPluginJSLink(twjq_c.jQueryPluginJSLink):
+    jqplugin = twc.Param('(string) Name of the jqplot plugin')
+    name=defaults._jqplot_name_
+    version=defaults._jqplot_version_
+    variant='min'
+    modname='tw2.jquery.plugins.jqplot'
+    basename='jqplot.%(jqplugin)s'
+    subdir = 'plugins'
+
+    @property
+    def substitutions(self):
+        subs = super(JQPlotPluginJSLink, self).substitutions
+        subs.update(dict(jqplugin=self.jqplugin))
+        return subs
+
 __all__ = ['jqplot_js', 'jqplot_css']
+
+jqplugins = [
+    'barRenderer',
+    'BezierCurveRenderer',
+    'blockRenderer',
+    'bubbleRenderer',
+    'canvasAxisLabelRenderer',
+    'canvasAxisTickRenderer',
+    'categoryAxisRenderer',
+    'ciParser',
+    'cursor',
+    'dateAxisRenderer',
+    'donutRenderer',
+    'dragable',
+    'enhancedLegendRenderer',
+    'funnelRenderer',
+    'highlighter',
+    'json2',
+    'logAxisRenderer',
+    'mekkoAxisRenderer',
+    'mekkoRenderer',
+    'meterGaugeRenderer',
+    'ohlcRenderer',
+    'pieRenderer',
+    'pointLabels',
+    'trendline',
+]
+
+jqplugins_links = dict(
+    [("%s_js" % jqp, JQPlotPluginJSLink(jqplugin=jqp)) for jqp in jqplugins])
+
+locals().update(**jqplugins_links)
+__all__.extend(jqplugins_links.keys())

File tw2/jquery/plugins/jqplot/samples.py

 
 See http://toscawidgets.org/documentation/WidgetBrowser for more information
 """
+
+import tw2.core as twc
+
 from widgets import JQPlotWidget
+from base import dateAxisRenderer_js
+
 from random import random
 from random import randint
-from math import sin
+from math import sin, cos
 
-n = 20
+from time import time
+
+def make_data():
+    """ Sin of the times! """
+    now = int(time())
+    n = 20.0
+    tsteps = 100
+    tspan = range(now-tsteps, now)
+    series1 = [[i*1000,sin(i/n)] for i in tspan]
+    series2 = [[i*1000,abs(sin(i/n))**((i%(2*n))/n)] for i in tspan]
+    series3 = [[i*1000,cos(i/(n+1))*1.5] for i in tspan]
+    series4 = [[series2[i][0], series2[i][1] * series3[i][1]]
+               for i in range(len(series3))]
+    data = [series1, series2, series3,series4]
+    return data
+
+data = make_data()
 
 class DemoJQPlotWidget(JQPlotWidget):
+    def prepare(self):
+        self.resources.append(dateAxisRenderer_js)
+        super(DemoJQPlotWidget, self).prepare()
+
+    data = data
     options = {
-        'title' : 'just a test title'
+        'title' : 'Sine of the times (tw2)',
+        'series' : [ {'showMarker' : False} for d in data ],
+        'axes' : {
+            'xaxis' : {
+                'renderer' : twc.JSSymbol('$.jqplot.DateAxisRenderer'),
+                'tickOptions' : {
+                    'formatString' : '%T'
+                },
+            },
+        },
     }
-    data = [
-        [[i, random()*i/float(n)] for i in range(n)],
-        [[i, random()*sin(3.14*(i/float(n)))] for i in range(n)],
-        [[i, random()/(i+1)] for i in range(n)],
-        [[i, random()*i + i] for i in range(n)],
-    ]
-

File tw2/jquery/plugins/jqplot/templates/jqplot.mak

 <script type="text/javascript">
 $(document).ready(
     function(){
+		$.jqplot.config.enablePlugins = true;
 		$.jqplot(
 			'${w.selector}',
 			${w._data},

File tw2/jquery/plugins/jqplot/widgets.py

     options = twc.Param("Configuration options to pass to jqplot", default={})
 
     def prepare(self):
-        super(JQPlotWidget, self).prepare()
         self._data = encoder.encode(self.data)
         self._options = encoder.encode(self.options)
+        super(JQPlotWidget, self).prepare()