Example #1
0
    def __init__(self, desc=None):
        YCategoryAxis.__init__(self)

        self.desc = None
        if isString(desc) is True:
            self.desc = desc

        self.labels.fontName = DefaultFontName
Example #2
0
    def _draw_pie_chart(format_json):
        width = format_json['rect'][2]
        height = format_json['rect'][3]

        d = Drawing(width, height, vAlign="TOP")

        if format_json['data'] is None or type(format_json['data']) is str:
            PDFTemplate._draw_chart_rect(d, 20, 20, width - 40, height - 50,
                                         format_json)
        elif type(format_json['data']) is list:
            cat_names = format_json['category_names']
            data = format_json['data']

            main_title = ""
            if "main_title" in format_json and isString(
                    format_json['main_title']) is True:
                main_title = format_json['main_title']
            main_title_font_name = None
            if "main_title_font_name" in format_json and isString(
                    format_json['main_title_font_name']) is True:
                main_title_font_name = format_json['main_title_font_name']
            main_title_font_size = None
            if "main_title_font_size" in format_json and isNumber(
                    format_json['main_title_font_size']) is True:
                main_title_font_size = format_json['main_title_font_size']
            main_title_font_color = None
            if "main_title_font_color" in format_json:
                main_title_font_color = format_json['main_title_font_color']

            pie_chart = ReportLabPieChart(
                0,
                0,
                width,
                height,
                cat_names,
                data,
                main_title=main_title,
                main_title_font_name=main_title_font_name,
                main_title_font_size=main_title_font_size,
                main_title_font_color=main_title_font_color,
                draw_legend=True)
            d.add(pie_chart)

        return d
Example #3
0
    def args_check(template_content):
        if PDFTemplate.is_dict(template_content) is False:
            raise ValueError("template content is not dict.")

        if "file_name" not in template_content:
            raise ValueError("no file name.")
        if isString(template_content['file_name']) is False:
            raise ValueError("file name error.")

        if "page_size" not in template_content:
            raise ValueError("no page size.")
        if isListOfNumbers(template_content['page_size']) is False:
            raise ValueError("page size error.")
        if len(template_content['page_size']) != 2:
            raise ValueError("page size error.")

        if "coordinate" not in template_content:
            raise ValueError("no page coordinate-system.")
        if template_content['coordinate'] != "left-top":
            raise ValueError(
                "coordinate must be left-top. other not support auto_position."
            )

        if "pages" not in template_content:
            raise ValueError("no pages.")
        if PDFTemplate.is_dict(template_content['pages']) is False:
            raise ValueError("pages is not dict.")
        for page in template_content['pages']:
            page = template_content['pages'][page]
            if "rect" not in page:
                raise ValueError("page no rect.")
            for it in page['items']:
                it = page['items'][it]
                if PDFTemplate.is_dict(it) is False:
                    raise ValueError("item is not dict.")
                if "type" not in it:
                    raise ValueError("item no type.")

                if it['type'] == 'line_chart':
                    PDFTemplate.args_check_line_chart(it)
                elif it['type'] == 'bar_chart':
                    PDFTemplate.args_check_bar_chart(it)
                elif it['type'] == 'pie_chart':
                    PDFTemplate.args_check_pie_chart(it)
Example #4
0
    def __init__(self, desc=None):
        YValueAxis.__init__(self)

        self.desc = None
        if isString(desc) is True:
            self.desc = desc
Example #5
0
    def _draw_bar_chart(format_json):
        width = format_json['rect'][2]
        height = format_json['rect'][3]

        d = Drawing(width, height, vAlign="TOP")

        if format_json['data'] is None or type(format_json['data']) is str:
            PDFTemplate._draw_chart_rect(d, 20, 20, width - 40, height - 50,
                                         format_json)
        elif type(format_json['data']) is list:
            cat_names = format_json['category_names']
            data = format_json['data']
            bar_style = format_json['bar_style']

            style = "parallel"
            if "style" in format_json and isString(
                    format_json['style']) is True:
                style = format_json['style']
            label_format = None
            if "label_format" in format_json and isString(
                    format_json['label_format']) is True:
                label_format = format_json['label_format']
            step_count = 4
            if "step_count" in format_json and isNumber(
                    format_json['step_count']) is True:
                step_count = format_json['step_count']
            legend_names = None
            if "legend_names" in format_json and isListOfStrings(
                    format_json['legend_names']) is True:
                legend_names = format_json['legend_names']
            legend_position = "top-right"
            if "legend_position" in format_json and isString(
                    format_json['legend_position']) is True:
                legend_position = format_json['legend_position']
            legend_adjust_x = 0
            if "legend_adjust_x" in format_json and isNumber(
                    format_json['legend_adjust_x']) is True:
                legend_adjust_x = format_json['legend_adjust_x']
            legend_adjust_y = 0
            if "legend_adjust_y" in format_json and isNumber(
                    format_json['legend_adjust_y']) is True:
                legend_adjust_y = format_json['legend_adjust_y']
            main_title = ""
            if "main_title" in format_json and isString(
                    format_json['main_title']) is True:
                main_title = format_json['main_title']
            main_title_font_name = None
            if "main_title_font_name" in format_json and isString(
                    format_json['main_title_font_name']) is True:
                main_title_font_name = format_json['main_title_font_name']
            main_title_font_size = None
            if "main_title_font_size" in format_json and isNumber(
                    format_json['main_title_font_size']) is True:
                main_title_font_size = format_json['main_title_font_size']
            main_title_font_color = None
            if "main_title_font_color" in format_json:
                main_title_font_color = format_json['main_title_font_color']
            x_desc = None
            if "x_desc" in format_json and isString(
                    format_json['x_desc']) is True:
                x_desc = format_json['x_desc']
            y_desc = None
            if "y_desc" in format_json and isString(
                    format_json['y_desc']) is True:
                y_desc = format_json['y_desc']
            cat_label_all = False
            if "cat_label_all" in format_json:
                cat_label_all = format_json['cat_label_all']
            cat_label_angle = 30
            if "cat_label_angle" in format_json and isNumber(
                    format_json['cat_label_angle']) is True:
                cat_label_angle = format_json['cat_label_angle']

            bar_chart = None
            if bar_style == "horizontal":
                bar_chart = ReportLabHorizontalBarChart(
                    0,
                    0,
                    width,
                    height,
                    cat_names,
                    data,
                    style=style,
                    label_format=label_format,
                    step_count=step_count,
                    legend_names=legend_names,
                    legend_position=legend_position,
                    legend_adjust_x=legend_adjust_x,
                    legend_adjust_y=legend_adjust_y,
                    main_title=main_title,
                    main_title_font_name=main_title_font_name,
                    main_title_font_size=main_title_font_size,
                    main_title_font_color=main_title_font_color,
                    x_desc=x_desc,
                    y_desc=y_desc,
                    cat_label_angle=cat_label_angle,
                    cat_label_all=cat_label_all)
            elif bar_style == "vertical":
                bar_chart = ReportLabVerticalBarChart(
                    0,
                    0,
                    width,
                    height,
                    cat_names,
                    data,
                    style=style,
                    label_format=label_format,
                    step_count=step_count,
                    legend_names=legend_names,
                    legend_position=legend_position,
                    legend_adjust_x=legend_adjust_x,
                    legend_adjust_y=legend_adjust_y,
                    main_title=main_title,
                    main_title_font_name=main_title_font_name,
                    main_title_font_size=main_title_font_size,
                    main_title_font_color=main_title_font_color,
                    x_desc=x_desc,
                    y_desc=y_desc,
                    cat_label_angle=cat_label_angle,
                    cat_label_all=cat_label_all)
            if bar_chart is not None:
                d.add(bar_chart)

        return d