(self)
return '\n\n'.join(return_strings)
Export the story as HTML.
Export the story as HTML.
Export the story as HTML .
def export_story(self):
        """Export the story as HTML."""
        return_strings = [self.HTML_HEADER]

        return_strings.append(
            '<h1>{0:s}</h1>'.format(self._story_title))
        date_now = datetime.datetime.utcnow()
        return_strings.append(
            'Story Metadata:<br/><ul><li><b>Creation Date:</b> {0:s}</li>'
            '<li><b>Created by:</b> {1:s}</li>'
            '<li><b>Report Generated:</b> {2:s}</li>'
            '<li><b>Report Exported by:</b> {3:s}</li></ul>'.format(
                self._creation_date, self._story_author, date_now.isoformat(),
                self._story_exporter))

        md = markdown.Markdown()

        chart_number = 1
        charts = []
        for line_dict in self._data_lines:
            line_type = line_dict.get('type', '')
            if line_type == 'text':
                return_strings.append(
                    md.convert(line_dict.get('value', '')))

            elif line_type == 'aggregation':
                data_dict = line_dict.get('value')
                agg_obj = data_dict.get('aggregation')
                chart_type = data_dict.get('chart_type')
                if chart_type == 'table':
                    df = agg_obj.to_pandas()
                    return_strings.append(self._data_frame_to_html(df))
                else:
                    parameters = data_dict.get('parameters', {})
                    title = parameters.get('title', data_dict.get('name'))
                    chart_color = parameters.get('chart_color')

                    chart = agg_obj.to_chart(
                        chart_name=chart_type, chart_title=title,
                        interactive=True, color=chart_color, as_chart=True)

                    charts.append(chart)
                    return_strings.append(
                        '<div id="vis{0:d}"></div>'.format(chart_number))
                    chart_number += 1

            elif line_type == 'dataframe':
                return_strings.append(
                    self._data_frame_to_html(line_dict.get('value')))

            elif line_type == 'chart':
                data_dict = line_dict.get('value')
                chart = data_dict.get('chart')

                charts.append(chart)
                return_strings.append(
                    '<div id="vis{0:d}"></div>'.format(chart_number))
                chart_number += 1

        if charts:
            return_strings.append('<script type="text/javascript">')
            for index, chart in enumerate(charts):
                vis_nr = index + 1
                return_strings.append(
                    'vegaEmbed(\'#vis{0:d}\', {1:s}).'
                    'catch(console.error);'.format(
                        vis_nr, chart.to_json(indent=None)))
            return_strings.append('</script>')

        return_strings.append('</body></html>')
        return '\n\n'.join(return_strings)
def export_story ( self ) : return_strings = [ self . HTML_HEADER ] return_strings . append ( '<h1>{0:s}</h1>' . format ( self . _story_title ) ) date_now = datetime . datetime . utcnow ( ) return_strings . append ( 'Story Metadata:<br/><ul><li><b>Creation Date:</b> {0:s}</li>' '<li><b>Created by:</b> {1:s}</li>' '<li><b>Report Generated:</b> {2:s}</li>' '<li><b>Report Exported by:</b> {3:s}</li></ul>' . format ( self . _creation_date , self . _story_author , date_now . isoformat ( ) , self . _story_exporter ) ) md = markdown . Markdown ( ) chart_number = 1 charts = [ ] for line_dict in self . _data_lines : line_type = line_dict . get ( 'type' , '' ) if line_type == 'text' : return_strings . append ( md . convert ( line_dict . get ( 'value' , '' ) ) ) elif line_type == 'aggregation' : data_dict = line_dict . get ( 'value' ) agg_obj = data_dict . get ( 'aggregation' ) chart_type = data_dict . get ( 'chart_type' ) if chart_type == 'table' : df = agg_obj . to_pandas ( ) return_strings . append ( self . _data_frame_to_html ( df ) ) else : parameters = data_dict . get ( 'parameters' , { } ) title = parameters . get ( 'title' , data_dict . get ( 'name' ) ) chart_color = parameters . get ( 'chart_color' ) chart = agg_obj . to_chart ( chart_name = chart_type , chart_title = title , interactive = True , color = chart_color , as_chart = True ) charts . append ( chart ) return_strings . append ( '<div id="vis{0:d}"></div>' . format ( chart_number ) ) chart_number += 1 elif line_type == 'dataframe' : return_strings . append ( self . _data_frame_to_html ( line_dict . get ( 'value' ) ) ) elif line_type == 'chart' : data_dict = line_dict . get ( 'value' ) chart = data_dict . get ( 'chart' ) charts . append ( chart ) return_strings . append ( '<div id="vis{0:d}"></div>' . format ( chart_number ) ) chart_number += 1 if charts : return_strings . append ( '<script type="text/javascript">' ) for index , chart in enumerate ( charts ) : vis_nr = index + 1 return_strings . append ( 'vegaEmbed(\'#vis{0:d}\', {1:s}).' 'catch(console.error);' . format ( vis_nr , chart . to_json ( indent = None ) ) ) return_strings . append ( '</script>' ) return_strings . append ( '</body></html>' ) return '\n\n' . join ( return_strings )