def test_draw(): sheet = Sheet('draw', margin=0, verbose=0) sheet.can.setFillColor('red') sheet.can.circle(0, 200, 100, stroke=1, fill=1) d = Drawing(200, 200) d.add(Rect(100, 0, 100, 120, fillColor=colors.yellow, strokeColor=None)) d.rotate(-45) d.add(Rect(100, 105, 120, 130, fillColor=colors.blue, strokeColor=None)) #d.rotate(45) d.add(String(150, 100, 'Hello World', fontSize=18, fillColor=colors.red)) #d.scale(0.5,0.5) d.wrapOn(sheet.can, 200, 200) d.drawOn(sheet.can, 0, 600) sheet.save()
def _draw_feet(cv, page_size, page_num=None): start_x = int(page_size[0] / 10) width = page_size[0] height = int(page_size[1] / 20) d = Drawing(width, height, vAlign="TOP") feet_line = Line(start_x, height, width - start_x, height) d.add(feet_line) if page_num is not None: x = int(width / 2) y = height - STATE_DEFAULTS['fontSize'] text = String(x, y, str(page_num)) text.fontName = DefaultFontName text.textAnchor = "middle" d.add(text) d.wrapOn(cv, width, height) d.drawOn(cv, 0, 0)
def _draw_header(cv, page_size, content=None): start_x = int(page_size[0] / 10) width = page_size[0] height = int(page_size[1] / 20) d = Drawing(width, height, vAlign="TOP") header_line = Line(start_x, 0, width - start_x, 0) d.add(header_line) if content is not None: x = int(width / 2) y = 5 text = String(x, y, content) text.fontName = DefaultFontName text.textAnchor = "middle" d.add(text) d.wrapOn(cv, width, height) d.drawOn(cv, 0, page_size[1] - height)
def body(): # Body size_y = 0.62 data = [["Sold", "Cash", "Card", "Contingent", "Reserved", "Expected", "Unsold Reserv."]] for cat, value in report_result_dict.iteritems(): size_y = size_y + 1.86 """ if cat == 'all': report_cat_name = 'All' else: report_cat_name = self.report_cat_list[event_id][cat] """ if cat == "all": categorie_name = "All" else: categorie_name = cat_name[cat] p = Paragraph('<para alignment="center"><b>' + categorie_name + "</b></para>", styles["Normal"]) data.append([p, "", "", "", "", "", ""]) if cat == "all": data_for_pie = [ value["a_total_sold"], value["a_sold_cash"], value["a_sold_card"], value["a_sold_conti"], value["a_reserved"], value["a_not_visited"], ] data.append( [ value["a_total_sold"], value["a_sold_cash"], value["a_sold_card"], value["a_sold_conti"], value["a_reserved"], value["a_total_pre"], value["a_not_visited"], ] ) data.append( [ str(value["m_total_sold"]) + unichr(8364), str(value["m_sold_cash"]) + unichr(8364), str(value["m_sold_card"]) + unichr(8364), "-", str(value["m_reserved"]) + unichr(8364), str(value["m_total_pre"]) + unichr(8364), str(value["m_not_visited"]) + unichr(8364), ] ) tstyle = [ ("INNERGRID", (0, 0), (-1, -1), 0.25, colors.grey), ("BOX", (0, 0), (-1, -1), 0.25, colors.black), ("ALIGN", (0, 1), (-1, -1), "RIGHT"), ( "COLBACKGROUNDS", (0, 0), (-1, -1), [ colors.lightpink, colors.lightpink, colors.lightpink, colors.lightpink, colors.lightyellow, colors.lightgrey, colors.lightyellow, ], ), ("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.lightslategray, None, None]), ] t = Table(data) t.setStyle(TableStyle(tstyle)) t.wrapOn(c, 19 * cm, 0 * cm) pos_y = 26.5 - size_y t.drawOn(c, 1 * cm, pos_y * cm) # Price Details # size_y = 0.62 pdata = [] for cat, value in report_result_dict.iteritems(): size_y = size_y + 1.86 if cat == "all": pass else: categorie_name = cat_name[cat] p = Paragraph('<para alignment="center"><b>' + categorie_name + "</b></para>", styles["Normal"]) pdata.append([p]) data_price_titles = [] data_price_amount = [] data_price_total = [] for prow in p_result: if cat == "cat_" + str(prow["cat_id"]): data_price_titles.append(prow["name"]) try: data_price_amount.append(str(value["a_prices"][str(prow["id"])])) except KeyError: data_price_amount.append("0") try: data_price_total.append(str(value["m_prices"][str(prow["id"])]) + unichr(8364)) except KeyError: data_price_total.append("0" + unichr(8364)) print data_price_titles pdata.append(data_price_titles) pdata.append(data_price_amount) pdata.append(data_price_total) tstyle = [ ("INNERGRID", (0, 0), (-1, -1), 0.25, colors.grey), ("BOX", (0, 0), (-1, -1), 0.25, colors.black), ("ALIGN", (0, 1), (-1, -1), "RIGHT"), ("COLBACKGROUNDS", (0, 0), (-1, -1), [colors.lightgrey, colors.whitesmoke]), ("ROWBACKGROUNDS", (0, 0), (-1, -1), [colors.lightslategray, None, None, None]), ] t = Table(pdata) t.setStyle(TableStyle(tstyle)) t.wrapOn(c, 19 * cm, 0 * cm) pos_y = 25 - size_y t.drawOn(c, 1 * cm, pos_y * cm) """ #Pie Chart d = Drawing(500, 500) pc = Pie() pc.x = 65 pc.y = 15 pc.width = 200 pc.height = 200 pc.data = data_for_pie pc.labels = ['Sold','Cash','Card','Contingent','Reserved','Unsold Reserv.'] pc.slices.strokeWidth=0.5 pc.slices[0].popout = 10 #pc.slices[0].strokeWidth = 2 #pc.slices[0].strokeDashArray = [2,2] pc.slices[0].labelRadius = 1.3 pc.slices[0].fontColor = colors.red pc.slices[0].fillColor = colors.lightpink pc.slices[1].fillColor = colors.lightpink pc.slices[2].fillColor = colors.lightpink pc.slices[3].fillColor = colors.lightpink pc.slices[4].fillColor = colors.lightyellow pc.slices[5].fillColor = colors.lightyellow d.add(pc) d.wrapOn(c, 5*cm, 5*cm) d.drawOn(c, 1*cm, 1*cm) """ if event_date == "all": data = [] sold = [] reserved = [] unsold_reserved = [] sold_contingent = [] for key, value in sorted(report_date_dict.iteritems(), key=lambda report_date_dict: report_date_dict[0]): date_day_dt = dt.datetime.strptime(key, "%Y-%m-%d") date_day = date_day_dt.strftime("%Y%m%d") sold.append((int(date_day), value["sold"])) reserved.append((int(date_day), value["reserved"])) unsold_reserved.append((int(date_day), value["unsold_reserved"])) sold_contingent.append((int(date_day), value["sold_contingent"])) data.append(sold) data.append(reserved) data.append(unsold_reserved) data.append(sold_contingent) print data # sample data _colors = ( Color(0.90, 0, 0), Color(0.801961, 0.801961, 0), Color(0.380392, 0.380392, 0), Color(0.580392, 0, 0), ) _catNames = "Sold", "Reserved", "Unsold Reserved", "Contingents" d = Drawing(400, 200) # adding the actual chart here. plot = GridLinePlot() plot.y = 50 plot.x = 15 plot.width = 525 plot.height = 125 plot.xValueAxis.xLabelFormat = "{ddd} {dd}. {mm}." plot.lineLabels.fontSize = 6 plot.lineLabels.boxStrokeWidth = 0.5 plot.lineLabels.visible = 1 plot.lineLabels.boxAnchor = "c" plot.lineLabels.angle = 0 plot.lineLabelNudge = 10 plot.joinedLines = 1 plot.lines.strokeWidth = 1.5 plot.lines[0].strokeColor = _colors[0] plot.lines[1].strokeColor = _colors[1] plot.lines[2].strokeColor = _colors[2] plot.lines[3].strokeColor = _colors[3] # sample data plot.data = data """ plot.data = [[(20010630, 1000), (20011231, 101), (20020630, 100.05), (20021231, 102), (20030630, 103), (20031230, 104), (20040630, 99.200000000000003), (20041231, 99.099999999999994)], [(20010630, 100.8), (20011231, 100.90000000000001), (20020630, 100.2), (20021231, 100.09999999999999), (20030630, 100), (20031230, 100.05), (20040630, 99.900000000000006), (20041231, 99.799999999999997)], [(20010630, 99.700000000000003), (20011231, 99.799999999999997), (20020630, 100), (20021231, 100.01000000000001), (20030630, 95), (20031230, 90), (20040630, 85), (20041231, 80)]] """ # y axis plot.yValueAxis.tickRight = 0 plot.yValueAxis.maximumTicks = 10 # plot.yValueAxis.leftAxisPercent = 0 plot.yValueAxis.tickLeft = 5 plot.yValueAxis.valueMax = None plot.yValueAxis.valueMin = None plot.yValueAxis.rangeRound = "both" plot.yValueAxis.requiredRange = 30 plot.yValueAxis.valueSteps = None plot.yValueAxis.valueStep = None plot.yValueAxis.forceZero = 0 plot.yValueAxis.labels.fontSize = 7 plot.yValueAxis.labels.dy = 0 plot.yValueAxis.avoidBoundFrac = 0.1 # x axis plot.xValueAxis.labels.fontName = "Helvetica" plot.xValueAxis.labels.fontSize = 7 plot.xValueAxis.valueSteps = None plot.xValueAxis.dailyFreq = 0 plot.xValueAxis.gridStrokeWidth = 0.25 plot.xValueAxis.labels.angle = 90 plot.xValueAxis.maximumTicks = 20 plot.xValueAxis.tickDown = 3 plot.xValueAxis.dailyFreq = 0 plot.xValueAxis.bottomAxisLabelSlack = 0 plot.xValueAxis.minimumTickSpacing = 10 plot.xValueAxis.visibleGrid = 0 plot.xValueAxis.gridEnd = 0 plot.xValueAxis.gridStart = 0 plot.xValueAxis.labels.angle = 45 plot.xValueAxis.labels.boxAnchor = "e" plot.xValueAxis.labels.dx = 0 plot.xValueAxis.labels.dy = -5 # adding legend legend = LineLegend() legend.boxAnchor = "sw" legend.x = 20 legend.y = -2 legend.columnMaximum = 1 legend.yGap = 0 legend.deltax = 50 legend.deltay = 0 legend.dx = 10 legend.dy = 1.5 legend.fontSize = 7 legend.alignment = "right" legend.dxTextSpace = 5 legend.colorNamePairs = [(_colors[i], _catNames[i]) for i in xrange(len(plot.data))] d.add(plot) d.add(legend) d.wrapOn(c, 18 * cm, 5 * cm) d.drawOn(c, 1 * cm, 1 * cm) c.showPage()
def generate_page1(c): #Image---------------------------------------------------------------------- im1 = Image.open("left.jpg") c.drawInlineImage(im1, 10, 15, width=546 / 2.3, height=1290 / 2.3) im2 = Image.open("shinken.jpg") c.drawInlineImage(im2, 259, height - 183, width=2434 / 4.4, height=725 / 4.4) im3 = Image.open("skor.jpg") c.drawInlineImage(im3, 259, height - 251, width=2335 / 4.2, height=271 / 4.2) im4 = Image.open("diagram.jpg") c.drawInlineImage(im4, 259, 15, width=2339 / 4.2, height=1367 / 4.2) #grafik1---------------------------------------------------------------------- from reportlab.graphics.shapes import Drawing from reportlab.graphics.charts.barcharts import HorizontalBarChart drawing = Drawing(500, 250) data = [(N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13, N14, N15, N16, N17)] bc = HorizontalBarChart() bc.x = 100 bc.y = 100 bc.height = 250 bc.width = 300 bc.data = data bc.strokeColor = None bc.fillColor = None # bc.bars[0].fillColor = PCMYKColor(92,47,0,33,alpha=95) # bc.bars[0].strokeColor = PCMYKColor(92,47,0,33,alpha=95) # bc.bars[0].fillColor = PCMYKColor(92,32,0,33,alpha=95) # bc.bars[0].strokeColor = PCMYKColor(92,32,0,33,alpha=95) bc.bars[0].fillColor = PCMYKColor(92, 16, 0, 33, alpha=95) bc.bars[0].strokeColor = PCMYKColor(92, 16, 0, 33, alpha=95) # bc.bars[0].fillColor = PCMYKColor(92,7,0,33,alpha=95) # bc.bars[0].strokeColor = PCMYKColor(92,7,0,33,alpha=95) bc.barWidth = 15 bc.valueAxis.valueMin = 0 bc.valueAxis.valueMax = 100 bc.valueAxis.valueStep = 10 bc.valueAxis.visibleAxis = False bc.valueAxis.visibleGrid = False bc.valueAxis.visibleTicks = False bc.valueAxis.forceZero = True bc.valueAxis.visibleLabels = 0 bc.categoryAxis.visibleGrid = False bc.categoryAxis.visibleTicks = False # hidding the ticks remove the label bc.categoryAxis.tickLeft = 0 # a workaround is to set the tick length bc.categoryAxis.tickRight = 0 # to zero. bc.categoryAxis.strokeWidth = 0.25 bc.categoryAxis.labelAxisMode = 'low' bc.categoryAxis.labels.textAnchor = 'end' bc.categoryAxis.labels.angle = 0 bc.categoryAxis.labels.fontName = 'Designosaur-Regular' #bc.categoryAxis.labels.fontColor = PCMYKColor(0,65,100,0,alpha=90) bc.categoryAxis.labels.boxAnchor = 'e' bc.categoryAxis.labels.dx = -5 bc.categoryAxis.labels.dy = 0 bc.categoryAxis.labels.angle = 0 bc.categoryAxis.reverseDirection = 1 bc.categoryAxis.joinAxisMode = 'left' bc.categoryAxis.categoryNames = [ NN1, NN2, NN3, NN4, NN5, NN6, NN7, NN8, NN9, NN10, NN11, NN12, NN13, NN14, NN15, NN16, NN17 ] bc.barLabels.fontName = 'Designosaur-Regular' bc.barLabels.fontSize = 10 bc.barLabels.angle = 0 bc.barLabelFormat = "%.00f%%" bc.barLabels.boxAnchor = 'w' bc.barLabels.boxFillColor = None bc.barLabels.boxStrokeColor = None bc.barLabels.dx = 10 bc.barLabels.dy = 0 #bc.barLabels.dy = -1 bc.barLabels.boxTarget = 'hi' drawing.add(bc) drawing.wrapOn(c, width, height) drawing.drawOn(c, 350, height - 650) #Table--------------------------------------------------------------------- styleBH = styles["Normal"] styleBH.alignment = TA_CENTER styleBH.fontSize = 12 styleBH.fontName = 'Designosaur-Regular' #styleBH.textColor = PCMYKColor(92,7,0,33,alpha=100) isi1 = Paragraph(nama, styleBH) isitabel1 = [[isi1]] table1 = Table(isitabel1, colWidths=[150]) table1.wrapOn(c, width, height) table1.drawOn(c, 54, height - 352) isi2 = Paragraph(kelas, styleBH) isitabel2 = [[isi2]] table2 = Table(isitabel2, colWidths=[150]) table2.wrapOn(c, width, height) table2.drawOn(c, 54, height - 386) isi3 = Paragraph(sekolah, styleBH) isitabel3 = [[isi3]] table3 = Table(isitabel3, colWidths=[150]) table3.wrapOn(c, width, height) table3.drawOn(c, 54, height - 421) isi4 = Paragraph(outlet, styleBH) isitabel4 = [[isi4]] table4 = Table(isitabel4, colWidths=[150]) table4.wrapOn(c, width, height) table4.drawOn(c, 54, height - 455) #Text---------------------------------------------------------------------- #nilai total c.setFillColor(white) c.setStrokeColor(white) if (NTotal == '10.0'): c.setFont("Designosaur-Regular", 35) c.drawString(352, height - 230, NTotal + "/") c.setFont("Designosaur-Regular", 20) c.drawString(395, height - 235, "10") else: c.setFont("Designosaur-Regular", 35) c.drawString(338, height - 230, NTotal + "/") c.setFont("Designosaur-Regular", 20) c.drawString(415, height - 235, "10") #Yang paling tidak dikuasai siswa c.setFont("Designosaur-Regular", 9) c.drawString( 576, height - 205, "Topik yang paling tidak dikuasai peserta Try-Out II :" ) c.drawString(576, height - 216, "1. Mean, Median, dan Modus") c.drawString(576, height - 227, "2. Debit Air") c.drawString(576, height - 238, "3. Bangun Ruang")