# Commits

committed 8d69421

PEP8 in samples.py.

• Participants
• Parent commits 59167b3
• Branches default

# 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')`
`-`
`-`