예제 #1
0
def render_graph_image(graph_artwork, graph_data_range, graph_render_options):
    width_ex, height_ex = graph_render_options["size"]
    mm_per_ex = get_mm_per_ex(graph_render_options["font_size"])

    legend_height = graph_legend_height(graph_artwork, graph_render_options)
    image_height = (height_ex * mm_per_ex) + legend_height

    # TODO: Better use reporting.get_report_instance()
    doc = pdf.Document(font_family="Helvetica",
                       font_size=graph_render_options["font_size"],
                       lineheight=1.2,
                       pagesize=(width_ex * mm_per_ex, image_height),
                       margins=(0, 0, 0, 0))
    instance = {
        "document": doc,
        "options": {},
        # Keys not set here. Do we need them?
        #instance["range"] = from_until
        #instance["range_title"] = range_title
        #instance["macros"] = create_report_macros(report, from_until, range_title)
        #instance["report"] = report
    }

    render_graph_pdf(instance,
                     graph_artwork,
                     graph_data_range,
                     graph_render_options,
                     pos_left=0.0,
                     pos_top=0.0,
                     total_width=(width_ex * mm_per_ex),
                     total_height=image_height)

    pdf_graph = doc.end(do_send=False)
    #open("/tmp/x.pdf", "w").write(pdf_graph)
    return pdf.pdf2png(pdf_graph)
예제 #2
0
def graph_image_data_range(graph_render_options, start_time, end_time):
    mm_per_ex = get_mm_per_ex(graph_render_options["font_size"])
    width_mm = graph_render_options["size"][0] * mm_per_ex
    return compute_pdf_graph_data_range(width_mm, start_time, end_time)
예제 #3
0
def graph_image_data_range(
    graph_render_options: GraphRenderOptions, start_time: Timestamp, end_time: Timestamp
) -> GraphDataRange:
    mm_per_ex = get_mm_per_ex(graph_render_options["font_size"])
    width_mm = graph_render_options["size"][0] * mm_per_ex
    return compute_pdf_graph_data_range(width_mm, start_time, end_time)