Пример #1
0
 def get_charts(self, request):
     """Return the charts needed for rendering"""
     url = get_absolute_url(request)
     charts = []
     for chart in self.get_chart_infos(request):
         chart['chartoptions_rendered'] = ""
         # 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]
             chart['chartoptions']['is3D'] = False
             rendered = render_chartoptions(chart['chartoptions'])
             chart['chartoptions_rendered'] = rendered
             chart['csv_download_url'] = url + "%s.csv" % chart['id']
             chart['html_download_url'] = url + "%s.html" % chart['id']
         chart['module_id'] = self.get_module_id(chart)
         if self.cells.get_new_row_for_chart(chart['id']):
             chart['module_style'] = "clear: both;"
         else:
             chart['module_style'] = ""
         rendered = render_description(request,
                                       chart.get('description', ''),
                                       chart.get('description_type', ''))
         chart['description_rendered'] = rendered
         # Use an id with the postfox '_div' to make collisions unprobable
         chart['div_id'] = chart['id'] + '_div'
         charts.append(chart)
     return charts
Пример #2
0
    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)
Пример #3
0
 def get_charts(self, request):
     """Return the charts needed for rendering"""
     url = get_absolute_url(request)
     charts = []
     for chart in self.get_chart_infos(request):
         chart['chartoptions_rendered'] = ""
         # 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]
             chart['chartoptions']['is3D'] = False
             rendered = render_chartoptions(chart['chartoptions'])
             chart['chartoptions_rendered'] = rendered
             chart['csv_download_url'] = url + "%s.csv" % chart['id']
             chart['html_download_url'] = url + "%s.html" % chart['id']
         chart['module_id'] = self.get_module_id(chart)
         if self.cells.get_new_row_for_chart(chart['id']):
             chart['module_style'] = "clear: both;"
         else:
             chart['module_style'] = ""
         rendered = render_description(request,
                                       chart.get('description', ''),
                                       chart.get('description_type', ''))
         chart['description_rendered'] = rendered
         # Use an id with the postfox '_div' to make collisions unprobable
         chart['div_id'] = chart['id'] + '_div'
         charts.append(chart)
     return charts
Пример #4
0
    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)