'Time plot report page
@param r: the S3Request instance
@param attr: controller attributes for the request'

def timeplot(self, r, **attr):

    output = {}
    resource = self.get_target(r)
    tablename = resource.tablename
    get_config = resource.get_config
    show_filter_form = False
    if (r.representation in ('html', 'iframe')):
        filter_widgets = get_config('filter_widgets', None)
        if (filter_widgets and (not self.hide_filter)):
            from s3filter import S3FilterForm
            show_filter_form = True
            S3FilterForm.apply_filter_defaults(r, resource)
    (report_vars, get_vars) = self.get_options(r, resource)
    timestamp = get_vars.get('timestamp')
    (event_start, event_end) = self.parse_timestamp(timestamp)
    fact = get_vars.get('fact')
    try:
        facts = S3TimeSeriesFact.parse(fact)
    except SyntaxError:
        r.error(400, sys.exc_info()[1])
    baseline = get_vars.get('baseline')
    rows = get_vars.get('rows')
    cols = get_vars.get('cols')
    start = get_vars.get('start')
    end = get_vars.get('end')
    slots = get_vars.get('slots')
    ts = S3TimeSeries(resource, start=start, end=end, slots=slots, event_start=event_start, event_end=event_end, rows=rows, cols=cols, facts=facts, baseline=baseline)
    data = ts.as_dict()
    widget_id = 'timeplot'
    if (r.representation in ('html', 'iframe')):
        output['title'] = self.crud_string(tablename, 'title_report')
        if show_filter_form:
            advanced = False
            for widget in filter_widgets:
                if (('hidden' in widget.opts) and widget.opts.hidden):
                    advanced = get_config('report_advanced', True)
                    break
            filter_formstyle = get_config('filter_formstyle', None)
            filter_form = S3FilterForm(filter_widgets, formstyle=filter_formstyle, advanced=advanced, submit=False, _class='filter-form', _id=('%s-filter-form' % widget_id))
            fresource = current.s3db.resource(tablename)
            alias = (resource.alias if resource.parent else None)
            filter_widgets = filter_form.fields(fresource, r.get_vars, alias=alias)
        else:
            filter_widgets = None
        ajax_vars = Storage(r.get_vars)
        ajax_vars.update(get_vars)
        filter_url = r.url(method='', representation='', vars=ajax_vars.fromkeys((k for k in ajax_vars if (k not in report_vars))))
        ajaxurl = attr.get('ajaxurl', r.url(method='timeplot', representation='json', vars=ajax_vars))
        output = S3TimePlotForm(resource).html(data, get_vars=get_vars, filter_widgets=filter_widgets, ajaxurl=ajaxurl, filter_url=filter_url, widget_id=widget_id)
        output['title'] = self.crud_string(tablename, 'title_report')
        output['report_type'] = 'timeplot'
        self._view(r, 'timeplot.html')
        response = current.response
        response.view = self._view(r, 'report.html')
    elif (r.representation == 'json'):
        output = json.dumps(data, separators=SEPARATORS)
    else:
        r.error(415, current.ERROR.BAD_FORMAT)
    return output
