tw2.jqplugins.jqplot

TW2 widget wrapper the jquery ui jqplot

Get the source from http://github.com/toscawidgets/tw2.jqplugins.jqplot

JQPlotWidget
  • options
    • Configuration options to pass to jqplot
  • events
    • (dict) (BETA) javascript callbacks for events
  • width
    • Width of the chart.
  • height
    • Height of the chart.
  • data
    • A list of list of tuples to plot.
class DemoJQPlotWidget(JQPlotWidget):
    def prepare(self):
        self.resources.append(dateAxisRenderer_js)
        super(DemoJQPlotWidget, self).prepare()
    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'
                },
            },
        },
    }
<%namespace name="tw" module="tw2.core.mako_util"/>
<div>
<div ${tw.attrs(attrs=w.attrs)}></div>
<script type="text/javascript">
$(document).ready(
    function(){
		doJQPlotWidget(
			'${w.selector}',
			${w._data | n},
			${w._options | n}
		);
    }
);
</script>
</div>

PollingJQPlotWidget
  • options
    • Configuration options to pass to jqplot
  • events
    • (dict) (BETA) javascript callbacks for events
  • width
    • Width of the chart.
  • height
    • Height of the chart.
  • data
    • A list of list of tuples to plot.
  • url
    • (string) A url to poll
  • url_kwargs
    • (dict) A dict for a query str
  • interval
    • (int) milliseconds between pulls
class DemoPollingJQPlotWidget(PollingJQPlotWidget):
    def prepare(self):
        self.resources.append(dateAxisRenderer_js)
        super(DemoPollingJQPlotWidget, self).prepare()
    url = '/jqplot_datasource/'
    url_kwargs = {}
    interval = 2000
    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'
                },
            },
        },
    }
    @classmethod
    def request(cls, req):
        import webob
        data = make_data()
        minx, maxx, miny, maxy = find_bounds(data)
        options = {
            'axes': {
                'xaxis': {'min': minx, 'max': maxx},
                'yaxis': {'min': miny, 'max': maxy},
            }
        }
        json = encoder.encode(dict(data=data, options=options))
        return webob.Response(json, content_type="application/json")
<%namespace name="tw" module="tw2.core.mako_util"/>
<div>
<div ${tw.attrs(attrs=w.attrs)}></div>
<script type="text/javascript">
    $(document).ready(
      function(){
        doPollingJQPlotWidget(
          // selector
          '${w.selector}',
          // data
          ${w._data | n},
          // options
          ${w._options | n},
          // url
          '${w.url}',
          // url_kwargs
          ${w.url_kwargs | n},
          // interval
          ${str(w.interval)}
        );
      }
    );
</script>
</div>