def drawRamka(self, can, y, text, type): #global styleN self.styleN.alignment = TA_JUSTIFY self.styleN.fontName = 'AdonisC' leading = self.styleN.leading can.setLineWidth(.8) text = Paragraph(text, self.styleN) lines = text.breakLines(530) textHeight = leading * len(lines.lines) can.setStrokeColor(HexColor("0x00b0f0")) can.rect(30, y - textHeight - 10 - 5, 540, textHeight + 10 + 5) # Рамка head = type headWidth = stringWidth(head, 'HelveticaNeueC', 10) can.setFillColor(HexColor("0x00b0f0")) can.rect(30 + 15, y - 10, 30 + headWidth + 5, 20, fill=1) # прямоугольник в шапке (сверху) can.setFillColor(white) can.setFont("HelveticaNeueC", 10) can.drawString(30 + 15 + 30, y - 5, head) # надпись в шапке can.setFillColor(black) text.wrapOn(can, 530, textHeight) text.drawOn(can, 30 + 5, y - textHeight - 10)
def create_header(self): headerCanvas = Drawing() headerRect = Rect(0, 0, width=self.width, height=50) headerRect.fillColor = HexColor("#607D8B") headerRect.strokeColor = HexColor("#607D8B") headerCanvas.add(headerRect) renderPDF.draw(headerCanvas, self.c, 0, self.height - 50) _header_styles = ParagraphStyle( "Header", parent=self.styles["Heading1"], textColor=white, fontName='Helvetica' ) p = Paragraph("Kit Trading Fund Report", style = _header_styles) p.wrapOn(self.c, self.width, self.height - 50) p.drawOn(self.c, *self.coord(75, 10, mm)) _sub_header_styles = ParagraphStyle( "SubHeader", parent=self.styles["Heading4"], textColor=white, fontName='Helvetica' ) p = Paragraph("Monthly Report: January 2016", style = _sub_header_styles) p.wrapOn(self.c, self.width, self.height - 50) p.drawOn(self.c, *self.coord(85, 16, mm))
def prop_plot(data, xmin=False, ymin=False, xlabel="Temperatrure / K", ylabel="Heat Capacity / a.u."): lpt, _, _ = PGPlot.line_plot([[tuple(d) for d in data]], [HexColor(source_color("trans"))], [1.0], max([d[0] for d in data]), max([d[1] for d in data]), min([d[0] for d in data]) if xmin else 0.0, min([d[1] for d in data]) if ymin else 0.0) drw = Drawing(width=500, height=220) lpt.x, lpt.y = 100, 15 lpt.width, lpt.height = 300, 180 drw.add(lpt) drw.add( String(410, 2, xlabel, fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) drw.add( String(82, drw.height - 13, ylabel, fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) return drw
def add_findings_by_provider_chart(): drawing = Drawing(300, 200) data = get_findings_by_provider() maxVal = max(data[0]) if (maxVal > 1000): multiplier = 1000 step = 4 * multiplier else: multiplier = 100 step = 4 * multiplier value_step = int(ceil(maxVal / step)) * multiplier if (value_step < 10): value_step = 10 bar = HorizontalBarChart() bar.x = 30 bar.y = 0 bar.height = 100 bar.width = 400 bar.data = data bar.strokeColor = colors.white bar.valueAxis.valueMin = 0 bar.valueAxis.valueMax = maxVal * 2 ## graph displa twice as much as max violation bar.valueAxis.valueStep = value_step ## Convert to neartest 100 bar.categoryAxis.labels.boxAnchor = 'ne' bar.categoryAxis.labels.dx = -10 bar.categoryAxis.labels.dy = -2 bar.categoryAxis.labels.fontName = 'Helvetica' bar.categoryAxis.categoryNames = ["AWS", "Azure"] bar.bars[(0, 0)].fillColor = HexColor("#434476") bar.bars[(0, 1)].fillColor = HexColor("#B170DB") bar.barWidth = 3.5 bar.barSpacing = 0.1 bar.barLabelFormat = '%d' bar.barLabels.nudge = 15 bar.bars[0].strokeColor = None drawing.add(bar) # add_legend(drawing, bar) yLabel = Label() yLabel.setText("Number of Findings") yLabel.fontSize = 10 yLabel.fontName = 'Helvetica' yLabel.dx = 250 yLabel.dy = -30 chartLabel = Label() chartLabel.setText("Findings by Provider") chartLabel.fontSize = 10 chartLabel.fillColor = HexColor("#737373") chartLabel.fontName = 'Helvetica-Bold' chartLabel.dx = 250 chartLabel.dy = 160 drawing.add(chartLabel) drawing.add(yLabel) fields.append(drawing)
def add_trends_new_resolved_findings_chart(): drawing = Drawing(200, 200) data, month = get_new_resolved_trends() max_val_new_findings = max(data[0]) max_val_resolved_findings = max(data[1]) maxVal = max(max_val_new_findings, max_val_resolved_findings) if (maxVal > 1000): multiplier = 1000 step = 4 * multiplier else: multiplier = 100 step = 4 * multiplier value_step = int(ceil(maxVal / step)) * multiplier if (value_step < 10): value_step = 1 bar = VerticalBarChart() bar.x = 25 bar.y = -35 bar.height = 100 bar.width = doc.width bar.barWidth = 2 bar.data = data bar.valueAxis.valueMin = 0 bar.valueAxis.valueMax = int( maxVal * 2) ## graph displa twice as much as max violation bar.valueAxis.valueStep = value_step ## Convert to neartest step bar.categoryAxis.categoryNames = month bar.bars[0].strokeColor = None bar.bars[1].strokeColor = None bar.bars[0].fillColor = HexColor("#E57300") bar.bars[1].fillColor = HexColor("#408F00") chartLabel = Label() chartLabel.setText("Trends - New Findings") chartLabel.fontSize = 10 chartLabel.fillColor = HexColor("#737373") chartLabel.fontName = 'Helvetica-Bold' chartLabel.dx = 250 chartLabel.dy = 90 legend = Legend() legend.alignment = 'right' legend.colorNamePairs = [[HexColor("#E57300"), "New Findings"], [HexColor("#408F00"), "Resolved Findings"]] legend.columnMaximum = 2 legend.x = 400 legend.y = 120 drawing.add(legend) drawing.add(chartLabel) drawing.add(bar) fields.append(drawing)
def add_top_10_accounts_by_open_findings(): result = add_para("Table: Top 10 Accounts by Open Findings") fields.append(result) fields.append(add_para("<br></br>")) sectionTable = Table([[ "Provider", "Cloud Account", "Open Findings", "Suppressed\nFindings", "Resolved\nFindings" ]], [70, 170, 120, 70, 70], 35) sectionTable.setStyle( TableStyle([('BACKGROUND', (0, 0), (-1, -1), HexColor("#3a7c91")), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('TEXTCOLOR', (0, 0), (-1, 0), colors.white), ('FONTSIZE', (0, 0), (-1, -1), 12), ('FONT', (0, 0), (-1, -1), 'Helvetica')])) data = get_high_med_low_top_10_violations() columns = ["", "", "High", "Medium", "Low", "", ""] for d in data: # Added to support word wrap for account IDs # In case of Azure, the subscription ID is long d[1] = Paragraph(d[1], style=styles["BodyText"]) data.insert(0, columns) accountsTable = Table(data, [70, 170, 40, 45, 35, 70, 70], 35) accountsTable.setStyle( TableStyle([ ('BACKGROUND', (0, 0), (-1, 0), HexColor("#3a7c91")), #('SPAN', (0,0), (1,0)), ('TEXTCOLOR', (2, 0), (2, -1), colors.red), ('TEXTCOLOR', (3, 0), (3, -1), colors.darkorange), ('TEXTCOLOR', (4, 0), (4, -1), colors.orange), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONTSIZE', (0, 0), (-1, -1), 10), ('FONT', (0, 0), (-1, -1), 'Helvetica') ])) data_len = len(data) for each in range(data_len): if each % 2 == 0: bg_color = colors.whitesmoke else: bg_color = colors.white accountsTable.setStyle( TableStyle([('BACKGROUND', (0, each), (-1, each), bg_color)])) finalTable = Table([[sectionTable], [accountsTable]], 440) finalTable.setStyle( TableStyle([('SPAN', (0, 0), (-1, 0)), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('FONTSIZE', (0, 0), (-1, -1), 10), ('FONT', (0, 0), (-1, -1), 'Helvetica')])) fields.append(finalTable)
def draw(self): self.canv.setFillColor(HexColor("#364151")) self.canv.rect(-1.25*cm, 0.0, A4[0]+0.1*cm, cm, stroke=False, fill=True) self.canv.setFillColor(HexColor("#ffffff")) self.canv.drawCentredString( A4[0]/2.0, 0.35*cm, self._device_name )
def send_pdf(bill_object): print bill_object.user username = bill_object.user.username month = bill_object.month bill_unit = bill_object.billing_units bill_amount = bill_object.bill_amount billname = str(username) + str(month) + ".pdf" path = os.path.join(dir_path + "/static", billname) c = canvas.Canvas(billname, pagesize=letter) c.drawImage('powerheader.jpg', 2, 670, 600, 95) c.drawImage('2.jpg', 2, 120, 620, 115) c.drawImage('header.jpg', 5, 700) c.drawInlineImage('3.jpg', 5, 702, 105, 70) c.setFillColor(HexColor('#ffffff')) c.setFontSize(size=12) c.setFillColor(HexColor('#000000')) c.drawString( 15, 630, "--------------------------------------------------------------------------------------------------------------------------------------------------" ) c.drawString( 15, 200, "--------------------------------------------------------------------------------------------------------------------------------------------------" ) #c.drawString(20, 600, "Customer_ID :") #c.drawString(250,600,str(bill_object.user.connection.id.customer_id)) c.drawString(20, 550, "Name:") c.drawString(250, 550, username) #c.drawString(20,500,"Address:") c.drawString(20, 500, "month:") c.drawString(20, 500, month) #address = (billing_object.user.connection.survey_number+billing_object.user.connection.society_name+billing_object.user.connection.village+billing_object.user.connection.taluka+billing_object.user.connection.district+billing_object.user.connection.pincode) #c.drawString(250,500,str(address)) # c.drawString(20, 450, "Mobile No:") # c.drawString(250,450,str(billing_object.user.phone)) c.drawString(20, 400, "Billing_units:") c.drawString(250, 400, bill_unit) # c.drawString(20, 350, "Month :") # c.drawString(250,350,str(billing_object.month)) c.drawString(20, 300, "Billing Amount:") c.drawString(250, 300, bill_amount) # c.drawString(20, 250, "Last Date:") # c.drawString(250, 250, str(billing_object.last_date)) qr_code = qr.QrCodeWidget(bill_object.id) bounds = qr_code.getBounds() width = bounds[2] - bounds[0] height = bounds[3] - bounds[1] d = Drawing(110, 110, transform=[110. / width, 0, 0, 110. / height, 0, 0]) d.add(qr_code) renderPDF.draw(d, c, 490, 520) c.drawImage('3.jpg', 2, -5, 620, 200) c.save()
def conv_plot(conv_data, conv_maxs): data = [] colors = [] widths = [] names = [] for k, u in sorted(conv_data.items(), key=lambda x: int(x[0])): data.append([(float(d[0]), float(d[1][0])) for d in u]) data.append([(float(d[0]), float(d[1][1])) for d in u]) colors += [HexColor(multi_color(int(k)))] * 2 widths += [2.0, 0.2] names += [[multi_name(int(k)), HexColor(multi_color(int(k)))]] lpt, _, _ = PGPlot.line_plot(data, colors, widths, conv_maxs[0], conv_maxs[1]) drw = Drawing(width=500, height=220) lpt.x, lpt.y = 100, 15 lpt.width, lpt.height = 300, 180 drw.add(lpt) sh = drw.height - 35 dsh = 10 sx = [10, 30] for na, cl in names: drw.add( Line(lpt.x + sx[0], sh, lpt.x + sx[1], sh, strokeColor=cl, strokeWidth=2.0)) drw.add( String(lpt.x + sx[1] + 3, sh - 3, na, fontName="Arial", fontSize=10, fillColor=cl)) sh -= dsh drw.add( String(410, 2, "Total # of Config.", fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) drw.add( String(82, drw.height - 13, "# of Converged Config.", fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) return drw
def add_azure_findings_by_severity_chart(): drawing = Drawing(doc.width / 2 - 18, doc.height / 2 - 45) aws, azure = get_all_violations_by_severity() rules = [azure] maxVal = max(rules[0]) if (maxVal > 1000): multiplier = 1000 step = 4 * multiplier else: multiplier = 100 step = 4 * multiplier value_step = int(ceil(maxVal / step)) * multiplier if (value_step < 10): value_step = 1 bar = VerticalBarChart() bar.x = 10 bar.y = 70 bar.height = doc.height / 4 bar.width = doc.width / 2 - 40 bar.barWidth = 2 bar.barSpacing = 0.5 bar.data = rules bar.valueAxis.valueMin = 0 bar.valueAxis.valueMax = int( maxVal * 1.5) ## graph displa twice as much as max violation bar.valueAxis.valueStep = value_step ## Convert to neartest 10 bar.categoryAxis.categoryNames = ["high", "medium", "low"] bar.barLabelFormat = '%d' bar.barLabels.nudge = 15 bar.bars[0].fillColor = HexColor("#B170DB") bar.bars[0].strokeColor = None bar.categoryAxis.labels.boxAnchor = 'n' chartLabel = Label() chartLabel.setText("Findings by Severity - Azure") chartLabel.fontSize = 10 chartLabel.fontName = 'Helvetica-Bold' chartLabel.fillColor = HexColor("#737373") chartLabel.dx = doc.rightMargin chartLabel.dy = doc.height - 80 drawing.add(chartLabel) drawing.add(bar) fields.append(drawing)