Commits

Ralph Bean  committed ff5cdc1 Merge

Merge branch 'release/2.0.2'

  • Participants
  • Parent commits 28b057f, 639b7a5

Comments (0)

Files changed (3)

 
 setup(
     name='tw2.jqplugins.jqplot',
-    version='2.0.0',
+    version='2.0.2',
     description='toscawidgets2 wrapper for the jqPlot jQuery plugin',
     long_description=long_description,
     author='Ralph Bean',

File tw2/jqplugins/jqplot/samples.py

 
 from time import time
 
+
 def find_bounds(data):
-    minx = min( [min( [point[0] for point in series] ) for series in data])
-    maxx = max( [max( [point[0] for point in series] ) for series in data])
-    miny = min( [min( [point[1] for point in series] ) for series in data])
-    maxy = max( [max( [point[1] for point in series] ) for series in data])
+    minx = min([min([point[0] for point in series]) for series in data])
+    maxx = max([max([point[0] for point in series]) for series in data])
+    miny = min([min([point[1] for point in series]) for series in data])
+    maxy = max([max([point[1] for point in series]) for series in data])
     miny -= 0.1
     maxy += 0.1
     return minx, maxx, miny, maxy
 
+
 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]
+    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]
+    data = [series1, series2, series3, series4]
     return data
 
 data = make_data()
 
+
 class DemoJQPlotWidget(JQPlotWidget):
     def prepare(self):
         self.resources.append(dateAxisRenderer_js)
 
     data = data
     options = {
-        'legend' : { 'show' : True },
-        'title' : 'Sine of the times (tw2)',
-        'series' : [ {'showMarker' : False} for d in data ],
-        'axes' : {
-            'xaxis' : {
-                'renderer' : twc.JSSymbol('$.jqplot.DateAxisRenderer'),
-                'tickOptions' : {
-                    'formatString' : '%T'
+        'legend': {'show': True},
+        'title': 'Sine of the times (tw2)',
+        'series': [{'showMarker': False} for d in data],
+        'axes': {
+            'xaxis': {
+                'renderer': twc.JSSymbol('$.jqplot.DateAxisRenderer'),
+                'tickOptions': {
+                    'formatString': '%T'
                 },
             },
         },
     }
 
+
 class DemoPollingJQPlotWidget(PollingJQPlotWidget):
     def prepare(self):
         self.resources.append(dateAxisRenderer_js)
 
     data = data
     options = {
-        'legend' : { 'show' : True },
-        'title' : '(Polling) Sine of the times (tw2)',
-        'series' : [ {'showMarker' : False} for d in data ],
-        'axes' : {
-            'xaxis' : {
-                'renderer' : twc.JSSymbol('$.jqplot.DateAxisRenderer'),
-                'tickOptions' : {
-                    'formatString' : '%T'
+        'legend': {'show': True},
+        'title': '(Polling) Sine of the times (tw2)',
+        'series': [{'showMarker': False} for d in data],
+        'axes': {
+            'xaxis': {
+                'renderer': twc.JSSymbol('$.jqplot.DateAxisRenderer'),
+                'tickOptions': {
+                    'formatString': '%T'
                 },
             },
         },
         data = make_data()
         minx, maxx, miny, maxy = find_bounds(data)
         options = {
-            'axes' : {
-                'xaxis' : { 'min' : minx, 'max' : maxx },
-                'yaxis' : { 'min' : miny, 'max' : maxy },
+            'axes': {
+                'xaxis': {'min': minx, 'max': maxx},
+                'yaxis': {'min': miny, 'max': maxy},
             }
         }
         json = encoder.encode(dict(data=data, options=options))
 import tw2.core as twc
 mw = twc.core.request_local()['middleware']
 mw.controllers.register(DemoPollingJQPlotWidget, 'jqplot_datasource')
-
-

File tw2/jqplugins/jqplot/widgets.py

 
 
 class JQPlotWidget(tw2_jq_ui.JQueryUIWidget):
+    width = twc.Param("Width of the chart.", default="550px")
+    height = twc.Param("Height of the chart.", default="300px")
+    style = twc.Variable(attribute=True)
+
     resources = [
         tw2.jquery.jquery_js,
         tw2_jq_ui.jquery_ui_js, tw2_jq_ui.jquery_ui_css,
     def prepare(self):
         self._data = encoder.encode(self.data)
         self._options = encoder.encode(self.options)
+        self.style = "width:%s;height:%s;" % (self.width, self.height)
         super(JQPlotWidget, self).prepare()
 
 class PollingJQPlotWidget(JQPlotWidget):
     template = "tw2.jqplugins.jqplot.templates.pollster"
 
-    url = twc.Param("(string) A url to poll")
+    url = twc.Param("(string) A url to poll", default='')
     url_kwargs = twc.Param("(dict) A dict for a query str", default={})
     interval = twc.Param("(int) milliseconds between pulls", default=0)