def render_html(self, request): """Render a resource as HTML""" cells = self.layout.get_cells() restyler = BoxRestyler(request, cells) packages = set(['corechart']) chart = restyler.get_chart_infos(request)[0] if 'charttype' in chart and 'data' in chart: if chart['charttype'] in ['Table', 'ImageSparkLine']: packages.add(chart['charttype'].lower()) self.javascript = render_javascript([ chart, ], packages) # Render the chart to JSon if not JSON in chart or chart[JSON] is None: pass elif not 'charttype' in chart: pass else: chart['data'] = chart[JSON] # Prepare the packages are needed by the google chart tools if chart['charttype'] == 'Table': packages.add(chart['charttype'].lower()) if chart['charttype'] == 'ImageSparkLine': # Box uses CSS from table, so we have to add it here packages.add('table') packages.add(chart['charttype'].lower()) chart['chartoptions']['is3D'] = False rendered = render_chartoptions(chart['chartoptions']) chart['chartoptions_rendered'] = rendered rendered = render_description(request, chart.get('description', ''), chart.get('description_type', '')) chart['description_rendered'] = rendered if 'chartoptions' in chart: # Depending on the chart type different JavaScript libraries # need to be used self.chart_type = chart['charttype'] # Sometimes it is necessary to override the width and height # completely from the outside by just passing the width and height # through the url. This is useful when doing screenshots. if 'width' in request.GET: # width can be overridden from the request query width = int(request.GET['width']) chart['chartoptions']['width'] = width if 'height' in request.GET: # height can be overridden from the request query height = int(request.GET['height']) chart['chartoptions']['height'] = height # Now render the chart options with the new values rendered = render_chartoptions(chart['chartoptions']) chart['chartoptions_rendered'] = rendered # Use the chart id without a postfix as we do for boxes on a page chart['div_id'] = chart['id'] self.charts = [chart] self.javascript = render_javascript(self.charts, packages)
def render_html(self, request): """Render a resource as HTML""" cells = self.layout.get_cells() restyler = BoxRestyler(request, cells) packages = set(['corechart']) chart = restyler.get_chart_infos(request)[0] if 'charttype' in chart and 'data' in chart: if chart['charttype'] in ['Table', 'ImageSparkLine']: packages.add(chart['charttype'].lower()) self.javascript = render_javascript([chart, ], packages) # Render the chart to JSon if not JSON in chart or chart[JSON] is None: pass elif not 'charttype' in chart: pass else: chart['data'] = chart[JSON] # Prepare the packages are needed by the google chart tools if chart['charttype'] == 'Table': packages.add(chart['charttype'].lower()) if chart['charttype'] == 'ImageSparkLine': # Box uses CSS from table, so we have to add it here packages.add('table') packages.add(chart['charttype'].lower()) chart['chartoptions']['is3D'] = False rendered = render_chartoptions(chart['chartoptions']) chart['chartoptions_rendered'] = rendered rendered = render_description(request, chart.get('description', ''), chart.get('description_type', '')) chart['description_rendered'] = rendered if 'chartoptions' in chart: # Depending on the chart type different JavaScript libraries # need to be used self.chart_type = chart['charttype'] # Sometimes it is necessary to override the width and height # completely from the outside by just passing the width and height # through the url. This is useful when doing screenshots. if 'width' in request.GET: # width can be overridden from the request query width = int(request.GET['width']) chart['chartoptions']['width'] = width if 'height' in request.GET: # height can be overridden from the request query height = int(request.GET['height']) chart['chartoptions']['height'] = height # Now render the chart options with the new values rendered = render_chartoptions(chart['chartoptions']) chart['chartoptions_rendered'] = rendered # Use the chart id without a postfix as we do for boxes on a page chart['div_id'] = chart['id'] self.charts = [chart] self.javascript = render_javascript(self.charts, packages)
def __init__(self, request, cells): resource_provider = ResourceProvider() self.resource = Resource(resource_provider) self.cells = cells self.resources = self.get_resources() self.charts = self.get_charts(request) self.packages = self.get_packages() self.javascript = render_javascript(self.charts, self.packages)