コード例 #1
0
ファイル: test_barchart.py プロジェクト: applepolice/pointer
def create_bar_graph():
    """
    Creates a bar graph in a PDF
    """
    d = Drawing(280, 250)
    bar = VerticalBarChart()
    bar.x = 50
    bar.y = 85
    data = [[1, 2, 3, None, None, None, 5],
            [10, 5, 2, 6, 8, 3, 5],
            [5, 7, 2, 8, 8, 2, 5],
            [2, 10, 2, 1, 8, 9, 5],
            ]
    bar.data = data
    bar.categoryAxis.categoryNames = ['Year1', 'Year2', 'Year3',
                                      'Year4', 'Year5', 'Year6',
                                      'Year7']

    bar.bars[0].fillColor = PCMYKColor(0, 100, 100, 40, alpha=85)
    bar.bars[1].fillColor = PCMYKColor(23, 51, 0, 4, alpha=85)
    bar.bars.fillColor = PCMYKColor(100, 0, 90, 50, alpha=85)

    d.add(bar, '')

    d.save(formats=['pdf'], outDir='.', fnRoot='test')
コード例 #2
0
def overview_year_spend_by_month(c, w, h):
    my_data = data.monthly_total(year)
    total_budget = data.budget()
    left_budget = (total_budget - sum(my_data)) / (12 - month)
    for i in range(month, 12):
        my_data[i] = left_budget
    d = Drawing(0, 0)
    bar = VerticalBarChart()
    bar.x = 150
    bar.y = 150
    bar.data = [my_data]
    bar.valueAxis.valueMin = 0
    bar.categoryAxis.categoryNames = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
        'Nov', 'Dec'
    ]
    bar.categoryAxis.labels.fontName = serif_font
    bar.valueAxis.labels.fontName = serif_font
    bar.categoryAxis.labels.boxAnchor = 'n'
    bar.categoryAxis.labels.angle = 90
    bar.categoryAxis.labels.dy = -15
    bar.categoryAxis.labels.dx = -10
    bar.bars[0].fillColor = PCMYKColor(150, 150, 150, 150, alpha=85)
    bar.bars[(0, month - 1)].fillColor = PCMYKColor(150, 0, 0, 0, alpha=85)
    for i in range(month, 13):
        bar.bars[(0, i)].fillColor = PCMYKColor(0, 150, 150, 0, alpha=85)
    d.add(bar, '')
    d.drawOn(c, w, h)
コード例 #3
0
    def create_body_service(self):
        sql_query = """SELECT `service_name` AS 'Name', `transport_protocol` AS 'Protocol', `file_name` AS 'File Name', `udp_command` AS 'UDP Msg.', `service_description` AS 'Description', 
                        `destination_example` AS 'Example of Destination', 
                        (SELECT `event_date` FROM LOGGING_EVENTS WHERE LOGGING_EVENTS.event_table='SERVICES' AND LOGGING_EVENTS.`event_name`=SERVICES.`service_name` ORDER BY `event_date` DESC LIMIT 1) AS 'Last Update',
                        (SELECT COUNT(`destination_id`) FROM DESTINATIONS WHERE SERVICES.service_id=DESTINATIONS.service_id) AS 'Total Destination'
                        FROM SERVICES WHERE `transport_protocol`='{trans_prot}';"""

        protocol_main_main = {
            'tcp': (PCMYKColor(93, 45, 0, 53), '#084278'),
            'udp': (PCMYKColor(0, 66, 59, 45), '#8C2F39'),
            'other': (PCMYKColor(10, 13, 61, 4), '#DCD55F')
        }

        sql_type = "SELECT COUNT(`service_id`) FROM SERVICES WHERE `transport_protocol`={protocol};"
        protocol_num = map(
            lambda item: self.db.select(
                sql_type.format(protocol=int(item)
                                if type(item) == int else '"{}"'.format(item)))
            [0][0], protocol_main_main)

        self.flowables.append(
            Paragraph("<strong>TOTAL TRANSPORT PROTOCOL RATIO</strong>",
                      style=self.sp_topic))
        self.flowables.append(
            self.create_pie_chart(
                data_list=protocol_num,
                label_list=[i.upper() for i in protocol_main_main],
                user_color=[
                    protocol_main_main[i][0] for i in protocol_main_main
                ]))

        self.flowables.append(
            Paragraph("<strong>SUMMARY SERVICE INFORMATION</strong>",
                      style=self.sp_topic))
        self.break_part(1)
        for key, val in zip(protocol_main_main, protocol_num):
            self.flowables.append(
                Paragraph(
                    "TOTAL <strong><font color='{col}'>{main}</font></strong> service:{tab}{val} service(s)"
                    .format(main=key.upper(),
                            val=val,
                            tab=self.tab,
                            col=protocol_main_main[key][1]),
                    style=self.sp_left))
            self.create_table_with_sql(sql_query.format(trans_prot=key),
                                       max_height=32)
            self.break_part(1)

        self.break_part(1)

        self.flowables.append(
            Paragraph("<strong>SUMMARY SERVICE STATUS</strong>",
                      style=self.sp_topic))
        self.break_part(1)
        running = "SELECT (SELECT `probe_name` FROM PROBES WHERE PROBES.probe_id=(SELECT `probe_id` FROM CLUSTERS WHERE CLUSTERS.cluster_id=RUNNING_SERVICES.cluster_id)) AS 'Probe Name', (SELECT `service_name` FROM SERVICES WHERE RUNNING_SERVICES.service_id=SERVICES.service_id) AS 'Service Name', `running_svc_status` AS 'Status' FROM RUNNING_SERVICES;"
        self.create_table_with_sql(running)

        self.break_part(1)

        self.create_service_statistic_result()
コード例 #4
0
ファイル: chart.py プロジェクト: kappelgkd/Projetos
    def create_table(self):
        """
        Create a table in PDF.
        """

        self._add(self, TableWidget(), name='table')

        self.table.data = [['Q1', 'Questão 01', '4 Pontos'],
                           ['Q2', 'Questão 02', '3 Pontos'],
                           ['Q3', 'Questão 03', '1 Pontos'],
                           ['Q4', 'Questão 04', '2 Pontos']]

        for i in range(len(self.chart.data)):
            self.chart.bars[i].name = self.table.data[i][0]

        self.table.height = 45
        self.table.borderStrokeColor = PCMYKColor(0, 12, 24, 36)
        self.table.fillColor = PCMYKColor(0, 3, 7, 6)
        self.table.borderStrokeWidth = 0.5
        self.table.horizontalDividerStrokeColor = PCMYKColor(0, 12, 24, 36)
        self.table.verticalDividerStrokeColor = colors.black
        self.table.horizontalDividerStrokeWidth = 0.5
        self.table.verticalDividerStrokeWidth = 0.5
        self.table.fontName = 'Times-Bold'
        self.table.fontSize = 7
        self.table.fontColor = colors.black
        self.table.alignment = 'left'
        self.table.width = 380
コード例 #5
0
def category_predicted_spending(c, category, h, w):
    """
    Creates a bar graph in a PDF
    """
    my_data = []
    for i in range(1, month + 1):
        my_data.append(round(data.category_data(category, i, year)))
    budget = data.category_budget(category)
    re_budget = (budget - sum(my_data)) / (12 - month)
    for x in range(month, 12):
        my_data.append(re_budget)

    d = Drawing(0, 0)
    bar = VerticalBarChart()
    bar.x = 150
    bar.y = 150
    bar.data = [my_data]
    bar.valueAxis.valueMin = 0
    bar.categoryAxis.categoryNames = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
        'Nov', 'Dec'
    ]
    bar.categoryAxis.labels.fontName = serif_font
    bar.valueAxis.labels.fontName = serif_font
    bar.categoryAxis.labels.boxAnchor = 'n'
    bar.categoryAxis.labels.angle = 90
    bar.categoryAxis.labels.dy = -15
    bar.categoryAxis.labels.dx = -10
    #below change monnth number based upon current month
    bar.bars[0].fillColor = PCMYKColor(150, 150, 150, 150, alpha=85)
    for i in range(month, 12):
        bar.bars[(0, i)].fillColor = PCMYKColor(0, 150, 150, 0, alpha=85)
    d.add(bar, '')
    d.drawOn(c, h, w)
コード例 #6
0
        def horizontal_bar_graph(self):
            """
            Draws a horizontal bar chart

            :return: horizontal bar chart
            """
            drawing = Drawing(200, 50)
            graph = HorizontalBarChart()
            graph.x = self.graph_x
            graph.y = self.graph_y

            graph.width = self.width
            graph.height = self.height

            graph.valueAxis.valueMin = self.value_min
            graph.valueAxis.valueMax = self.value_max
            graph.valueAxis.valueStep = self.value_step

            graph.data = self.data
            graph.categoryAxis.categoryNames = self.categories

            graph.barLabels.nudge = 15
            graph.barLabelFormat = '%d'
            graph.barLabels.dx = 0
            graph.barLabels.dy = 7
            graph.barLabels.boxAnchor = 'n'
            graph.barLabels.fontName = 'Vera'
            graph.barLabels.fontSize = 10

            graph.bars[0].fillColor = PCMYKColor(45, 45, 0, 0, alpha=85)
            graph.bars[1].fillColor = PCMYKColor(64, 75, 0, 18, alpha=95)
            graph.bars.fillColor = PCMYKColor(64, 62, 0, 18, alpha=85)
            drawing.add(graph, '')

            return [drawing]
コード例 #7
0
    def _rgbFind(self, color):
        "see if it matches any existing color in my list"
        C = self.cmykColors
        if isinstance(color, (list, tuple)):
            if len(color) == 3: color = Color(color[0], color[1], color[2])
            elif len(color) == 4:
                color = CMYKColor(color[0], color[1], color[2], color[3])
            else:
                raise ValueError("bad color %s" % repr(color))
        isCMYK = isinstance(color, CMYKColor)
        if not isCMYK:
            if isinstance(color, str):
                color = toColor(color)
            if colorDistance(color, black) < 1e-8:
                isCMYK = 1
                color = PCMYKColor(0, 0, 0, 100, 100)
            elif colorDistance(color, white) < 1e-8:
                isCMYK = 1
                color = PCMYKColor(0, 0, 0, 0, 100)
        rgb = color.red, color.green, color.blue
        if isCMYK:
            if color not in C: C.append(color)
            return self._setCMYKColor(color)
        else:
            for c in C:
                if (c.red, c.green, c.blue) == rgb:
                    return self._setCMYKColor(c)

        return '%s setrgbcolor' % fp_str(rgb)
コード例 #8
0
def monthly_spending_bar(c, category, h, w):
    """
    Creates a bar graph in a PDF
    """
    my_data = []
    for i in range(1, 12 + 1):
        my_data.append(data.category_data(category.lower(), i, year))
    for i in range(month, 12):
        my_data[i] = 0
    #d = Drawing(300, 250)
    d = Drawing(0, 0)
    bar = VerticalBarChart()
    bar.x = 150
    bar.y = 150
    bar.data = [my_data]
    bar.valueAxis.valueMin = 0
    bar.categoryAxis.categoryNames = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
        'Nov', 'Dec'
    ]
    bar.categoryAxis.labels.fontName = serif_font
    bar.valueAxis.labels.fontName = serif_font
    bar.categoryAxis.labels.boxAnchor = 'n'
    bar.categoryAxis.labels.angle = 90
    bar.categoryAxis.labels.dy = -15
    bar.categoryAxis.labels.dx = -10
    #below change monnth number based upon current month
    bar.bars[0].fillColor = PCMYKColor(150, 150, 150, 150, alpha=85)
    bar.bars[(0, month - 1)].fillColor = PCMYKColor(150, 0, 0, 0, alpha=85)
    d.add(bar, '')
    d.drawOn(c, 200, 480)
コード例 #9
0
 def create_performance_chart(self):
     chartCanvas = Drawing()
     chartCanvas.hAlign = 'CENTER'
     chart = SimpleTimeSeriesPlot()
     chart.height = 150
     chart.width = self.width - 100
     chart.lines[0].strokeColor = PCMYKColor(100,0,90,50,alpha=100)
     chart.lines.strokeWidth     = 2
     chart.lines[1].strokeColor = PCMYKColor(0,100,100,40,alpha=100)
     chart.xValueAxis.xLabelFormat            = '{mm}/{YY}'
     chart.data = [[('20120101', 100), ('20120102', 100), ('20120103', 101), ('20120104', 101), ('20120105', 102), ('20120106', 101), ('20120107', 101), ('20120108', 101), ('20120109', 102), ('20120110', 103), ('20120111', 103), ('20120112', 104), ('20120113', 103), ('20120114', 103), ('20120115', 103), ('20120116', 103), ('20120117', 103), ('20120118', 105), ('20120119', 106), ('20120120', 106), ('20120121', 106), ('20120122', 106), ('20120123', 106), ('20120124', 107), ('20120125', 108), ('20120126', 107), ('20120127', 107), ('20120128', 107), ('20120129', 107), ('20120130', 107), ('20120131', 107), ('20120201', 109), ('20120202', 109), ('20120203', 111), ('20120204', 111), ('20120205', 111), ('20120206', 111), ('20120207', 111), ('20120208', 111), ('20120209', 110), ('20120210', 109), ('20120211', 109), ('20120212', 109), ('20120213', 110), ('20120214', 110), ('20120215', 109), ('20120216', 111), ('20120217', 111), ('20120218', 111), ('20120219', 111), ('20120220', 111), ('20120221', 111), ('20120222', 111), ('20120223', 112), ('20120224', 111), ('20120225', 111), ('20120226', 111), ('20120227', 111), ('20120228', 111), ('20120229', 110), ('20120301', 111), ('20120302', 109), ('20120303', 109), ('20120304', 109), ('20120305', 109), ('20120306', 106), ('20120307', 108), ('20120308', 109), ('20120309', 111), ('20120310', 111), ('20120311', 111), ('20120312', 110), ('20120313', 113), ('20120314', 112), ('20120315', 113), ('20120316', 112), ('20120317', 112), ('20120318', 112), ('20120319', 113), ('20120320', 112), ('20120321', 112), ('20120322', 110), ('20120323', 111), ('20120324', 111), ('20120325', 111), ('20120326', 113), ('20120327', 113), ('20120328', 112), ('20120329', 112), ('20120330', 112), ('20120331', 112), ('20120401', 112), ('20120402', 113), ('20120403', 112), ('20120404', 110), ('20120405', 110), ('20120406', 110), ('20120407', 110), ('20120408', 110), ('20120409', 108), ('20120410', 106), ('20120411', 107), ('20120412', 109), ('20120413', 107), ('20120414', 107), ('20120415', 107), ('20120416', 107), ('20120417', 109), ('20120418', 108), ('20120419', 108), ('20120420', 108), ('20120421', 108), ('20120422', 108), ('20120423', 106), ('20120424', 107), ('20120425', 109), ('20120426', 110), ('20120427', 111), ('20120428', 111), ('20120429', 111), ('20120430', 110), ('20120501', 110), ('20120502', 110), ('20120503', 108), ('20120504', 106), ('20120505', 106), ('20120506', 106), ('20120507', 106), ('20120508', 106), ('20120509', 105), ('20120510', 106), ('20120511', 105), ('20120512', 105), ('20120513', 105), ('20120514', 104), ('20120515', 103), ('20120516', 103), ('20120517', 101), ('20120518', 100), ('20120519', 100), ('20120520', 100), ('20120521', 102), ('20120522', 102), ('20120523', 102), ('20120524', 102), ('20120525', 102), ('20120526', 102), ('20120527', 102), ('20120528', 102), ('20120529', 104), ('20120530', 102), ('20120531', 101), ('20120601', 98), ('20120602', 98), ('20120603', 98), ('20120604', 98), ('20120605', 99), ('20120606', 102), ('20120607', 101), ('20120608', 102), ('20120609', 102), ('20120610', 102), ('20120611', 100), ('20120612', 101), ('20120613', 99), ('20120614', 100), ('20120615', 101), ('20120616', 101), ('20120617', 101), ('20120618', 102), ('20120619', 103), ('20120620', 103), ('20120621', 100), ('20120622', 101), ('20120623', 101), ('20120624', 101), ('20120625', 99), ('20120626', 99), ('20120627', 100), ('20120628', 100), ('20120629', 103), ('20120630', 103), ('20120701', 103), ('20120702', 104), ('20120703', 106), ('20120704', 106), ('20120705', 106), ('20120706', 104), ('20120707', 104), ('20120708', 104), ('20120709', 104), ('20120710', 102), ('20120711', 102), ('20120712', 102), ('20120713', 103), ('20120714', 103), ('20120715', 103), ('20120716', 102), ('20120717', 103), ('20120718', 104), ('20120719', 104), ('20120720', 102), ('20120721', 102), ('20120722', 102), ('20120723', 101), ('20120724', 99), ('20120725', 100), ('20120726', 101), ('20120727', 104), ('20120728', 104), ('20120729', 104), ('20120730', 103), ('20120731', 103), ('20120801', 101), ('20120802', 101), ('20120803', 103), ('20120804', 103), ('20120805', 103), ('20120806', 104), ('20120807', 105), ('20120808', 105), ('20120809', 106), ('20120810', 106), ('20120811', 106), ('20120812', 106), ('20120813', 105), ('20120814', 105), ('20120815', 106), ('20120816', 107), ('20120817', 108), ('20120818', 108), ('20120819', 108), ('20120820', 107), ('20120821', 107), ('20120822', 107), ('20120823', 106), ('20120824', 106), ('20120825', 106), ('20120826', 106), ('20120827', 106), ('20120828', 107), ('20120829', 107), ('20120830', 106), ('20120831', 106), ('20120901', 106), ('20120902', 106), ('20120903', 106), ('20120904', 107), ('20120905', 107), ('20120906', 110), ('20120907', 110), ('20120908', 110), ('20120909', 110), ('20120910', 110), ('20120911', 110), ('20120912', 111), ('20120913', 112), ('20120914', 114), ('20120915', 114), ('20120916', 114), ('20120917', 113), ('20120918', 112), ('20120919', 112), ('20120920', 111), ('20120921', 111), ('20120922', 111), ('20120923', 111), ('20120924', 111), ('20120925', 109), ('20120926', 108), ('20120927', 110), ('20120928', 109), ('20120929', 109), ('20120930', 109), ('20121001', 109), ('20121002', 109), ('20121003', 109), ('20121004', 110), ('20121005', 110), ('20121006', 110), ('20121007', 110), ('20121008', 109), ('20121009', 108), ('20121010', 108), ('20121011', 108), ('20121012', 107), ('20121013', 107), ('20121014', 107), ('20121015', 108), ('20121016', 109), ('20121017', 110), ('20121018', 110), ('20121019', 108), ('20121020', 108), ('20121021', 108), ('20121022', 108), ('20121023', 107), ('20121024', 107), ('20121025', 107), ('20121026', 107), ('20121027', 107), ('20121028', 107), ('20121029', 107), ('20121030', 107), ('20121031', 109), ('20121101', 111), ('20121102', 109), ('20121103', 109), ('20121104', 109), ('20121105', 110), ('20121106', 111), ('20121107', 108), ('20121108', 107), ('20121109', 107), ('20121110', 107), ('20121111', 107), ('20121112', 107), ('20121113', 106), ('20121114', 104), ('20121115', 104), ('20121116', 105), ('20121117', 105), ('20121118', 105), ('20121119', 107), ('20121120', 107), ('20121121', 108), ('20121122', 108), ('20121123', 109), ('20121124', 109), ('20121125', 109), ('20121126', 109), ('20121127', 109), ('20121128', 109), ('20121129', 110), ('20121130', 110), ('20121201', 110), ('20121202', 110), ('20121203', 110), ('20121204', 110), ('20121205', 110), ('20121206', 110), ('20121207', 110), ('20121208', 110), ('20121209', 110), ('20121210', 111), ('20121211', 112), ('20121212', 112), ('20121213', 111), ('20121214', 111), ('20121215', 111), ('20121216', 111), ('20121217', 112), ('20121218', 114), ('20121219', 114), ('20121220', 114), ('20121221', 113), ('20121222', 113), ('20121223', 113), ('20121224', 113), ('20121225', 113), ('20121226', 112), ('20121227', 112), ('20121228', 112), ('20121229', 112), ('20121230', 112), ('20121231', 114)], [('20120101', 100), ('20120102', 100), ('20120103', 101), ('20120104', 100), ('20120105', 101), ('20120106', 101), ('20120107', 101), ('20120108', 101), ('20120109', 101), ('20120110', 103), ('20120111', 103), ('20120112', 104), ('20120113', 103), ('20120114', 103), ('20120115', 103), ('20120116', 103), ('20120117', 103), ('20120118', 105), ('20120119', 105), ('20120120', 105), ('20120121', 105), ('20120122', 105), ('20120123', 105), ('20120124', 106), ('20120125', 107), ('20120126', 107), ('20120127', 107), ('20120128', 107), ('20120129', 107), ('20120130', 107), ('20120131', 107), ('20120201', 109), ('20120202', 109), ('20120203', 112), ('20120204', 112), ('20120205', 112), ('20120206', 111), ('20120207', 111), ('20120208', 111), ('20120209', 111), ('20120210', 109), ('20120211', 109), ('20120212', 109), ('20120213', 111), ('20120214', 110), ('20120215', 109), ('20120216', 112), ('20120217', 111), ('20120218', 111), ('20120219', 111), ('20120220', 111), ('20120221', 111), ('20120222', 110), ('20120223', 112), ('20120224', 111), ('20120225', 111), ('20120226', 111), ('20120227', 111), ('20120228', 111), ('20120229', 109), ('20120301', 110), ('20120302', 108), ('20120303', 108), ('20120304', 108), ('20120305', 108), ('20120306', 106), ('20120307', 107), ('20120308', 109), ('20120309', 110), ('20120310', 110), ('20120311', 110), ('20120312', 110), ('20120313', 112), ('20120314', 111), ('20120315', 112), ('20120316', 112), ('20120317', 112), ('20120318', 112), ('20120319', 113), ('20120320', 112), ('20120321', 112), ('20120322', 111), ('20120323', 112), ('20120324', 112), ('20120325', 112), ('20120326', 114), ('20120327', 113), ('20120328', 112), ('20120329', 112), ('20120330', 112), ('20120331', 112), ('20120401', 112), ('20120402', 113), ('20120403', 113), ('20120404', 111), ('20120405', 110), ('20120406', 110), ('20120407', 110), ('20120408', 110), ('20120409', 108), ('20120410', 106), ('20120411', 107), ('20120412', 109), ('20120413', 107), ('20120414', 107), ('20120415', 107), ('20120416', 108), ('20120417', 109), ('20120418', 108), ('20120419', 108), ('20120420', 108), ('20120421', 108), ('20120422', 108), ('20120423', 107), ('20120424', 108), ('20120425', 110), ('20120426', 110), ('20120427', 111), ('20120428', 111), ('20120429', 111), ('20120430', 110), ('20120501', 110), ('20120502', 110), ('20120503', 109), ('20120504', 107), ('20120505', 107), ('20120506', 107), ('20120507', 107), ('20120508', 107), ('20120509', 106), ('20120510', 107), ('20120511', 107), ('20120512', 107), ('20120513', 107), ('20120514', 105), ('20120515', 105), ('20120516', 104), ('20120517', 102), ('20120518', 101), ('20120519', 101), ('20120520', 101), ('20120521', 103), ('20120522', 103), ('20120523', 103), ('20120524', 103), ('20120525', 103), ('20120526', 103), ('20120527', 103), ('20120528', 103), ('20120529', 105), ('20120530', 103), ('20120531', 103), ('20120601', 100), ('20120602', 100), ('20120603', 100), ('20120604', 100), ('20120605', 101), ('20120606', 103), ('20120607', 103), ('20120608', 104), ('20120609', 104), ('20120610', 104), ('20120611', 101), ('20120612', 103), ('20120613', 102), ('20120614', 103), ('20120615', 104), ('20120616', 104), ('20120617', 104), ('20120618', 104), ('20120619', 106), ('20120620', 106), ('20120621', 103), ('20120622', 105), ('20120623', 105), ('20120624', 105), ('20120625', 103), ('20120626', 103), ('20120627', 105), ('20120628', 105), ('20120629', 108), ('20120630', 108), ('20120701', 108), ('20120702', 109), ('20120703', 111), ('20120704', 111), ('20120705', 111), ('20120706', 109), ('20120707', 109), ('20120708', 109), ('20120709', 109), ('20120710', 108), ('20120711', 107), ('20120712', 107), ('20120713', 108), ('20120714', 108), ('20120715', 108), ('20120716', 108), ('20120717', 108), ('20120718', 109), ('20120719', 109), ('20120720', 107), ('20120721', 107), ('20120722', 107), ('20120723', 105), ('20120724', 104), ('20120725', 104), ('20120726', 105), ('20120727', 108), ('20120728', 108), ('20120729', 108), ('20120730', 107), ('20120731', 107), ('20120801', 104), ('20120802', 104), ('20120803', 107), ('20120804', 107), ('20120805', 107), ('20120806', 108), ('20120807', 109), ('20120808', 108), ('20120809', 109), ('20120810', 109), ('20120811', 109), ('20120812', 109), ('20120813', 108), ('20120814', 108), ('20120815', 109), ('20120816', 110), ('20120817', 111), ('20120818', 111), ('20120819', 111), ('20120820', 111), ('20120821', 110), ('20120822', 110), ('20120823', 109), ('20120824', 110), ('20120825', 110), ('20120826', 110), ('20120827', 110), ('20120828', 110), ('20120829', 111), ('20120830', 110), ('20120831', 110), ('20120901', 110), ('20120902', 110), ('20120903', 110), ('20120904', 111), ('20120905', 111), ('20120906', 114), ('20120907', 114), ('20120908', 114), ('20120909', 114), ('20120910', 114), ('20120911', 114), ('20120912', 115), ('20120913', 116), ('20120914', 117), ('20120915', 117), ('20120916', 117), ('20120917', 117), ('20120918', 116), ('20120919', 116), ('20120920', 116), ('20120921', 116), ('20120922', 116), ('20120923', 116), ('20120924', 116), ('20120925', 114), ('20120926', 113), ('20120927', 115), ('20120928', 114), ('20120929', 114), ('20120930', 114), ('20121001', 114), ('20121002', 114), ('20121003', 114), ('20121004', 115), ('20121005', 114), ('20121006', 114), ('20121007', 114), ('20121008', 114), ('20121009', 112), ('20121010', 112), ('20121011', 113), ('20121012', 112), ('20121013', 112), ('20121014', 112), ('20121015', 113), ('20121016', 113), ('20121017', 114), ('20121018', 114), ('20121019', 112), ('20121020', 112), ('20121021', 112), ('20121022', 111), ('20121023', 111), ('20121024', 111), ('20121025', 111), ('20121026', 110), ('20121027', 110), ('20121028', 110), ('20121029', 110), ('20121030', 110), ('20121031', 111), ('20121101', 113), ('20121102', 111), ('20121103', 111), ('20121104', 111), ('20121105', 111), ('20121106', 112), ('20121107', 109), ('20121108', 108), ('20121109', 108), ('20121110', 108), ('20121111', 108), ('20121112', 108), ('20121113', 107), ('20121114', 105), ('20121115', 105), ('20121116', 106), ('20121117', 106), ('20121118', 106), ('20121119', 108), ('20121120', 108), ('20121121', 109), ('20121122', 109), ('20121123', 110), ('20121124', 110), ('20121125', 110), ('20121126', 110), ('20121127', 110), ('20121128', 111), ('20121129', 112), ('20121130', 112), ('20121201', 112), ('20121202', 112), ('20121203', 112), ('20121204', 112), ('20121205', 112), ('20121206', 112), ('20121207', 112), ('20121208', 112), ('20121209', 112), ('20121210', 112), ('20121211', 114), ('20121212', 113), ('20121213', 112), ('20121214', 112), ('20121215', 112), ('20121216', 112), ('20121217', 114), ('20121218', 115), ('20121219', 116), ('20121220', 116), ('20121221', 116), ('20121222', 116), ('20121223', 116), ('20121224', 115), ('20121225', 115), ('20121226', 114), ('20121227', 114), ('20121228', 113), ('20121229', 113), ('20121230', 113), ('20121231', 116)]]
     chartCanvas.add(chart)
     renderPDF.draw(chartCanvas, self.c, 40, self.height - 400)
コード例 #10
0
def create_bar_graph(arr, name, title, c, m, y, k):
    d = Drawing(280, 250)
    bar = VerticalBarChart()
    bar.x = 50
    bar.y = 85
    data = [arr]
    bar.data = data
    bar.categoryAxis.categoryNames = title

    bar.bars[0].fillColor = PCMYKColor(c, m, y, k, alpha=85)
    # bar.bars[1].fillColor = PCMYKColor(23, 51, 0, 4, alpha=85)
    bar.bars.fillColor = PCMYKColor(100, 0, 90, 50, alpha=85)

    d.add(bar, '')
    d.save(formats=['pdf'], outDir='.', fnRoot=statsPath + name)
コード例 #11
0
ファイル: chart.py プロジェクト: kappelgkd/Projetos
    def insert_legend(self):
        """
        Insert legend into graphic
        """

        self._add(self, Legend(), name='legend')

        self.legend.deltay = 8
        self.legend.fontName = 'Helvetica'
        self.legend.fontSize = 5
        self.legend.strokeWidth = 0.5
        self.legend.strokeColor = PCMYKColor(0, 0, 0, 100)
        self.legend.alignment = 'right'
        self.legend.columnMaximum = 3
        self.legend.boxAnchor = 'sw'
        self.legend.y = 75
        self.legend.x = 24
        self.legend.dx = 8
        self.legend.dy = 5
        self.legend.dxTextSpace = 5
        self.legend.deltax = 0
        self.legend.colorNamePairs = Auto(obj=self.chart)

        self.chart.bars[0].fillColor = self.random_color()
        self.chart.bars[1].fillColor = self.random_color()
        self.chart.bars[2].fillColor = self.random_color()
        self.chart.bars[3].fillColor = self.random_color()
コード例 #12
0
ファイル: reporting.py プロジェクト: vjymits/utm
        def __init__(self, pie_data, width=400, height=200):
            apply(Drawing.__init__, (self, width, height))
            self._add(self, Pie(), name='chart', validate=None, desc=None)
            self.chart.x = 20
            self.chart.y = (self.height - self.chart.height) / 2
            self.chart.slices.strokeWidth = 1
            self.chart.slices.popout = 1
            self.chart.direction = 'clockwise'
            self.chart.width = self.chart.height
            self.chart.startAngle = 90
            self.chart.slices[0].popout = 10
            self._add(self, Legend(), name='legend', validate=None, desc=None)
            self.legend.x = width - 20
            self.legend.y = 0
            self.legend.boxAnchor = 'se'
            self.legend.subCols[1].align = 'right'
            # these data can be read from external sources
            data = []
            categories = []
            for d in pie_data.keys():
                categories.append(d)
                data.append(pie_data.get(d, 0))
            #data                = (9, 7, 6, 4, 2.5, 1.0)
            #categories          = ('A','B','C','D','E','F',)

            colors = [
                PCMYKColor(0, 1, 550, x)
                for x in (1030, 2080, 3060, 440, 4520, 2225)
            ]
            self.chart.data = data
            self.chart.labels = map(str, self.chart.data)
            self.legend.colorNamePairs = zip(colors, categories)
            for i, color in enumerate(colors):
                self.chart.slices[i].fillColor = color
コード例 #13
0
ファイル: chart.py プロジェクト: kappelgkd/Projetos
    def random_color(self):
        """
        Get a random color.
        """

        value = lambda: random.randint(0, 100)

        return PCMYKColor(value(), value(), value(), value(), alpha=100)
コード例 #14
0
def get_color_with_opacity(color, opacity):
    color = color.lower()
    if (color == "red"): return PCMYKColor(0, 100, 100, 0).clone(alpha=opacity)
    if (color == "orange"):
        return PCMYKColor(0, 50, 100, 0).clone(alpha=opacity)
    if (color == "black"): return PCMYKColor(0, 0, 0, 100).clone(alpha=opacity)
    if (color == "blue"): return PCMYKColor(100, 50, 0, 0).clone(alpha=opacity)
    if (color == "pink"): return PCMYKColor(0, 100, 0, 0).clone(alpha=opacity)
    if (color == "purple"):
        return PCMYKColor(50, 100, 0, 0).clone(alpha=opacity)
    if (color == "brown"):
        return PCMYKColor(30, 60, 90, 40).clone(alpha=opacity)
    if (color == "green"):
        return PCMYKColor(100, 0, 100, 0).clone(alpha=opacity)
    if (color == "yellow"):
        return PCMYKColor(0, 0, 100, 0).clone(alpha=opacity)

    print("(get_color_with_opacity)Color not found. Returned purple")
    return PCMYKColor(50, 100, 0, 0).clone(alpha=opacity)
コード例 #15
0
def parse_color(value):
    from reportlab.lib.colors import HexColor, PCMYKColor
    match = COLOR_HEXA_PATTERN.search(value)
    if match:
        hex = match.group(1).lower()
        return HexColor(f'0x{hex}')
    match = COLOR_CMYK_PATTERN.search(value)
    if match:
        cmyk = [int(x) for x in match.group(1).split(",")]
        return PCMYKColor(*cmyk)
    raise ValueError(f"The '{value}' is not a valid color.")
コード例 #16
0
ファイル: Practice.py プロジェクト: RMACR7LP/Programacion1
 def create_bar_graph():
     d = Drawing(250, 220)
     bar = VerticalBarChart()
     bar.x = 50  
     bar.y = 85
     data = [[12,2,3,None,None,None,5],
             [5,7,2,8,8,2,5],
             [2,10,2,1,8,9,5],
             ]
     bar.data = data
     bar.categoryAxis.categoryNames = ['Year2', 'Year3',
                                     'Year4', 'Year5', 'Year6',
                                     'Year7']
     
     bar.bars[0].fillColor   = PCMYKColor(0,100,100,40,alpha=85)
     bar.bars[1].fillColor   = PCMYKColor(23,51,0,4,alpha=85)
     bar.bars.fillColor       = PCMYKColor(100,0,90,50,alpha=85)
 
     d.add(bar, '')
 
     d.save(formats=['jpg'], outDir='.', fnRoot='grafica')
コード例 #17
0
    def create_pie_chart(self, data_list, label_list, user_color=None):
        # print data_list
        # print label_list

        label_list = map(lambda item: item.upper(), label_list)

        data = [(item / (sum(data_list) * 1.0)) * 100 for item in data_list]

        if user_color != None:
            usage_color = user_color
        else:
            random_range = [randint(0, 100) for i in range(len(data_list))]
            usage_color = map(
                lambda item: PCMYKColor(randint(0, item), randint(0, item),
                                        randint(0, item), randint(0, item)),
                random_range)
            print user_color

        # u_color = [colors.lawngreen, colors.red, colors.gray]
        # color = [colors.lawngreen, colors.red, colors.gray]
        # u_master = [randint(0, 100) for i in range(4)]
        # u_color = [PCMYKColor(randint(0, u_master[0]), randint(0, u_master[1]), randint(0, u_master[2]), randint(0, u_master[3])) for i in range(3)]
        # print u_color
        # color = u_color

        d = Drawing()
        pie = Pie()
        pie.x = 200
        pie.y = 85
        pie.data = data
        pie.labels = label_list

        for i, color in enumerate(usage_color):
            pie.slices[i].fillColor = color

        pie.slices.strokeWidth = 0.5
        pie.slices.popout = 1.5
        pie._seriesCount = 3
        pie.sideLabels = 1

        legend = Legend()
        legend.alignment = 'right'
        legend.x = 0
        legend.y = 75
        legend.colorNamePairs = [
            (z, (x, '     {val:.2f}%'.format(val=y)))
            for x, y, z in zip(pie.labels, data, usage_color)
        ]
        d.add(legend)
        d.add(pie)

        self.flowables.append(d)
コード例 #18
0
 def __init__(self,width=400,height=200,*args,**kw):
     Drawing.__init__(self,width,height,*args,**kw)
     fontSize    = 8
     fontName    = 'Helvetica'
     #pie
     self._add(self,Pie(),name='pie',validate=None,desc=None)
     self.pie.strokeWidth       = 1
     self.pie.slices.strokeColor       = PCMYKColor(0,0,0,0)
     self.pie.slices.strokeWidth       = 1
     #legend
     self._add(self,Legend(),name='legend',validate=None,desc=None)
     self.legend.columnMaximum    = 99
     self.legend.alignment='right'
     self.legend.dx               = 6
     self.legend.dy               = 6
     self.legend.dxTextSpace      = 5
     self.legend.deltay           = 10
     self.legend.strokeWidth      = 0
     self.legend.subCols[0].minWidth = 75
     self.legend.subCols[0].align = 'left'
     self.legend.subCols[1].minWidth = 25
     self.legend.subCols[1].align = 'right'
     # sample data
     colors= [PCMYKColor(100,67,0,23,alpha=100), PCMYKColor(70,46,0,16,alpha=100), PCMYKColor(50,33,0,11,alpha=100), PCMYKColor(30,20,0,7,alpha=100), PCMYKColor(20,13,0,4,alpha=100), PCMYKColor(10,7,0,3,alpha=100), PCMYKColor(0,0,0,100,alpha=100), PCMYKColor(0,0,0,70,alpha=100), PCMYKColor(0,0,0,50,alpha=100), PCMYKColor(0,0,0,30,alpha=100), PCMYKColor(0,0,0,20,alpha=100), PCMYKColor(0,0,0,10,alpha=100)]
     self.pie.data= [56.0, 12.199999999999999, 28.5, 3.3999999999999999]
     for i in range(len(self.pie.data)): self.pie.slices[i].fillColor = colors[i]
     self.height      = 200
     self.legend.boxAnchor      = 'c'
     self.legend.y              = 100
     self.pie.strokeColor      = PCMYKColor(0,0,0,0,alpha=100)
     self.pie.slices[1].fillColor             = PCMYKColor(100,60,0,50,alpha=100)
     self.pie.slices[2].fillColor             = PCMYKColor(0,100,100,40,alpha=100)
     self.pie.slices[3].fillColor             = PCMYKColor(66,13,0,22,alpha=100)
     self.pie.slices[0].fillColor             = PCMYKColor(100,0,90,50,alpha=100)
     self.legend.colorNamePairs = [(PCMYKColor(100,0,90,50,alpha=100), ('BP', '56.0%')), (PCMYKColor(100,60,0,50,alpha=100), ('BT', '12.2%')), (PCMYKColor(0,100,100,40,alpha=100), ('Tesco', '28.5%')), (PCMYKColor(66,13,0,22,alpha=100), ('Persimmon', '3.4%'))]
     self.width       = 400
     self.legend.x              = 350
     self.pie.width            = 150
     self.pie.height           = 150
     self.pie.y                = 25
     self.pie.x                = 25
コード例 #19
0
        def create_bar_graph():

            e = Drawing(280, 250)
            bar = VerticalBarChart()
            bar.x = 60
            bar.y = 85
            data = [[empresa.media_Financeiro_Estrutural, empresa.media_Marketing, empresa.media_Pessoas_Processos]]
            bar.data = data
            bar.categoryAxis.categoryNames = ['Financeiro/Estrutural', 'Marketing', 'Pessoas/Processos']
            
            bar.categoryAxis.labels.fontName = 'Hind-Light'
            bar.categoryAxis.labels.fontSize = 5
            
            bar.bars[0].fillColor = PCMYKColor(100,0,90,50,alpha=85)
            
            e.add(bar, '')
コード例 #20
0
    def test0(self):
        "This should open in full screen mode."
        import os
        from reportlab.pdfgen.canvas import Canvas
        from reportlab.lib.colors import PCMYKColor, PCMYKColorSep
        filename = 'test_pdfgen_overprint.pdf'
        desc = "Overprint/knockout tests for ReportLab library"

        black = PCMYKColor(0,0,0,100)
        cyan = PCMYKColorSep(100,0,0,0,spotName='myCyan')
        magenta = PCMYKColorSep(0,100,0,0,spotName='myMagenta')

        c = Canvas(filename)
        c.setFillColor(black)
        c.setFont('Helvetica', 20)
        c.drawString(100, 700, desc)

        c.setFont('Helvetica', 10)
        c.drawString(100, 670, "To view this page properly you probably need to enable 'overprint preview' in Acrobat Reader")
        c.drawString(100, 658, "or use a tool like Illustrator, Quark or Acrobat to view separated plates. Starting in")
        c.drawString(100, 646, "Acrobat Reader 9 there is a setting that lets you turn on the overprint preview, although")
        c.drawString(100, 634, "it's not on by default (Preferences > Page Display > Use Overprint Preview: Always).")
        
        c.drawString(100, 616, "In the top example, the magenta rectangle overprints the cyan one. In the lower one, it")
        c.drawString(100, 604, "'knocks out' the cyan underneath which is the default in PDF. This means that the overlap")
        c.drawString(100, 592, "area of the first example should show blue, because the two colours merge. However, in many")
        c.drawString(100, 580, "PDF viewers and cheap printers, both examples will probably look the same - magenta")
        c.drawString(100, 568, "rectangle knocks out part of the cyan one.")
        
        c.drawString(100, 550, "If you can view the separated CMYK plates in a tool like Illustrator, on the cyan plate")
        c.drawString(100, 538, "you should see the top rectangle as complete and the bottom one has a chunk knocked out of")
        c.drawString(100, 526, "the top right corner.")

        c.setFillOverprint(True)
        c.setFillColor(cyan)
        c.rect(100, 300, 200, 100, fill=True, stroke=False)
        c.setFillColor(magenta)
        c.rect(200, 350, 200, 100, fill=True, stroke=False)

        c.setFillOverprint(False)
        c.setFillColor(cyan)
        c.rect(100, 100, 200, 100, fill=True, stroke=False)
        c.setFillColor(magenta)
        c.rect(200, 150, 200, 100, fill=True, stroke=False)

        c.save()
        assert os.path.exists(filename)
コード例 #21
0
    def make_y_axis(self, y_label, y_min, y_max, y_step):

        self._add(self,
                  Label(),
                  name='YLabel',
                  validate=None,
                  desc="The label on the vertical axis")

        self.YLabel.fontName = 'Helvetica'
        self.YLabel.fontSize = 10
        self.YLabel.x = 20
        self.YLabel.y = 140
        self.YLabel.angle = 90
        self.YLabel.textAnchor = 'middle'
        self.YLabel.maxWidth = 200
        self.YLabel.height = 20
        self.YLabel._text = y_label

        self.chart.yValueAxis.valueMin = y_min
        self.chart.yValueAxis.valueMax = y_max
        self.chart.yValueAxis.valueStep = y_step
        self.chart.yValueAxis.visibleGrid = 1
        self.chart.yValueAxis.visibleAxis = 1
        self.chart.yValueAxis.visibleTicks = 0
        self.chart.yValueAxis.labels.fontName = "Helvetica"
        self.chart.yValueAxis.labels.fontSize = 10
        self.chart.yValueAxis.labelTextFormat = '%0.0f'
        self.chart.yValueAxis.strokeWidth = 0
        self.chart.yValueAxis.gridStrokeWidth = 0.25
        self.chart.yValueAxis.labels.rightPadding = 5
        self.chart.yValueAxis.maximumTicks = 15
        self.chart.yValueAxis.rangeRound = 'both'
        self.chart.yValueAxis.avoidBoundFrac = 0.1
        self.chart.yValueAxis.labels.dx = 3
        self.chart.yValueAxis.forceZero = 0
        self.chart.yValueAxis.gridStrokeColor = PCMYKColor(100,
                                                           100,
                                                           100,
                                                           100,
                                                           alpha=100)
        self.chart.yValueAxis.visible = 1
        self.chart.yValueAxis.strokeColor = black
        self.chart.yValueAxis.labelTextScale = 1
        self.chart.yValueAxis.labels.fillColor = black
コード例 #22
0
ファイル: chart.py プロジェクト: kappelgkd/Projetos
    def create_graphic(self):
        """
        Create a graphic.
        """

        self._add(self, VerticalBarChart(), name='chart')

        self.chart.data = [[4], [3], [1], [2]]

        self.chart.x = 140
        self.chart.y = 75
        self.chart.height = 73
        self.chart.width = 250

        self.chart.fillColor = None
        self.chart.barWidth = 2
        self.chart.groupSpacing = 5
        self.chart.barSpacing = 0.5
        self.chart.bars.strokeWidth = 0.5
        self.chart.bars.strokeColor = PCMYKColor(0, 0, 0, 100)

        # Vertical axes
        self.chart.valueAxis.labels.fontName = 'Helvetica'
        self.chart.valueAxis.labels.fontSize = 5
        self.chart.valueAxis.visibleGrid = False
        self.chart.valueAxis.visibleTicks = False
        self.chart.valueAxis.valueMin = 0
        self.chart.valueAxis.valueMax = 4
        self.chart.valueAxis.valueStep = 1

        # Horizontal axes
        self.chart.categoryAxis.strokeWidth = 0.25
        self.chart.categoryAxis.visibleGrid = False
        self.chart.categoryAxis.visibleTicks = False
        self.chart.categoryAxis.labels.boxAnchor = 'e'
        self.chart.categoryAxis.labels.fontSize = 8
        self.chart.categoryAxis.categoryNames = ['Questões']
コード例 #23
0
# -*- coding: utf-8 -*-
import cairo
import io
from math import sin, cos, radians
from reportlab.pdfgen import canvas
from reportlab.lib.colors import PCMYKColor
import textwrap
import pathlib
import sys

from .regex_objs import house_number_re_tuple, house_number_arrow_re_tuple
from .pdf_utils import create_cairo_font_face_for_file

COLOR_WHITE = PCMYKColor(0, 0, 0, 0)
COLOR_DARK_BLUE = PCMYKColor(75, 65, 0, 75)
# пока будет так, если цвета не подойдут поменяю

REGULAR = 'regular'
SEMI_BOLD = 'semi-bold'
BOLD = 'bold'

THIN = 'thin'
WIDE = 'wide'

LVL1 = 'lvl1'  # (основной)
SLASH = 'lvl2_slash'
LVL2C = 'lvl2c'  # (литера)
LVL2S = 'lvl2s'  # (номер после дроби)
LVL3 = 'lvl3'  # (Літера номеру після дробу)
LVL_A1 = 'lvl_a1'
LVL_A2C = 'lvl_a2c'
コード例 #24
0
    def __init__(self,
                 series_colors_cmyk,
                 box_width,
                 box_height,
                 chart_width,
                 chart_height,
                 width=550,
                 height=215,
                 *args,
                 **kw):
        Drawing.__init__(self, width, height, *args, **kw)
        Drawing.hAlign = 'CENTER'

        font_name = 'Helvetica'
        # self.width = 550
        # self.height = 240
        self.width = box_width
        self.height = box_height
        self._add(self, LinePlot(), name='chart', validate=None, desc=None)
        self._add(self, LineLegend(), name='legend', validate=None, desc=None)

        # self.chart.width = 490
        # self.chart.height = 150
        self.chart.width = chart_width
        self.chart.height = chart_height
        self.chart.y = 60
        self.chart.x = 45
        self.chart.strokeWidth = 1

        for color in series_colors_cmyk:
            index = series_colors_cmyk.index(color)
            self.chart.lines[index].strokeColor = PCMYKColor(color[0],
                                                             color[1],
                                                             color[2],
                                                             color[3],
                                                             alpha=color[4])
            self.chart.lines[index].symbol = makeMarker('FilledCircle')
            self.chart.lines[index].symbol.strokeColor = PCMYKColor(
                color[0], color[1], color[2], color[3], alpha=color[4])
            self.chart.lines[index].symbol.size = 5
        self.chart.lines.strokeWidth = 2

        self.legend.colorNamePairs = Auto(obj=self.chart)
        self.legend.x = 5
        self.legend.y = 30
        # set size of swatches
        self.legend.dx = 0
        self.legend.dy = 0
        self.legend.fontName = font_name
        self.legend.fontSize = 8
        self.legend.alignment = 'right'
        self.legend.columnMaximum = 2
        self.legend.dxTextSpace = 4
        self.legend.variColumn = 1
        self.legend.boxAnchor = 'nw'
        self.legend.deltay = 15
        self.legend.autoXPadding = 20

        self.background = Rect(0,
                               0,
                               self.width,
                               self.height,
                               strokeWidth=0,
                               fillColor=PCMYKColor(0, 0, 10, 0))
        self.background.strokeColor = black
        self.background.fillOpacity = 0.25
        self.background.strokeWidth = 0
        self.background.x = 0
        self.background.fillColor = PCMYKColor(16, 12, 13, 0, alpha=30)
コード例 #25
0
try:
    assert os.path.isdir(sys.argv[1]), 'Font path must be a valid directory'
except IndexError:
    raise Exception('First argument must be a font directory.')

font_dir = sys.argv[1]

registerFont(TTFont('OpenSans', os.path.join(font_dir,
                                             'OpenSans-Regular.ttf')))
registerFont(
    TTFont('OpenSansBold', os.path.join(font_dir, 'OpenSans-Bold.ttf')))

PT_PER_MM = 360.0 / 127.0

blue = PCMYKColor(70, 0, 0, 100)
black = PCMYKColor(0, 0, 0, 100)
grey = PCMYKColor(0.0, 0.0, 0.0, 60)

# PCMYKColorSep( 0.0, 100.0, 91.0, 0.0, spotName='PANTONE 485 CV',density=100) # what is this?


class Text(object):
    font = 'OpenSans'

    def __init__(
        self,
        text,
        font=None,
        colour=None,
        x=0,
コード例 #26
0
ファイル: gen_cert.py プロジェクト: ishwon/gen_cert
import haslib
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.colors import PCMYKColor
from reportlab.pdfbase.pdfmetrics import stringWidth

#page_width = defaultPageSize[0]
#page_height = defaultPageSize[1]
packet = StringIO.StringIO()
# Create a new PDF with reportlab
attendee = sys.argv[1]
# Creating a certificate hash code
hasher = hashlib.md5(attendee)
certID = base64.urlsafe_b64encode(hasher.digest()[0:5])
# attendee_width = stringWidth(attendee, "Times-Roman", 30)
gold = PCMYKColor(26,23,45,11)
can = canvas.Canvas(packet, pagesize=letter)
can.setFillColor(gold)
can.setFont("Times-Roman", 50)
# Specify the x,y coordinate for attendee name
can.drawCentredString(420, 225, attendee, mode=None)
# Specify Font size & coordinates for certificate number
black = PCMYKColor(0,0,0,61)
can.setFillColor(black)
can.setFont("Courier", 8)
can.drawString(668, 75, "Cert ID: 13-"+certID, mode=None)
can.save()

# Move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
コード例 #27
0
# coding: utf-8
import pytest
from reportlab.lib.colors import HexColor, PCMYKColor


@pytest.fixture
def parse_color():
    from flashcards.__main__ import parse_color
    return parse_color


@pytest.mark.parametrize('color_value, expected_color', [
    (
        '0,100,100,10',
        PCMYKColor(0, 100, 100, 10),
    ),
    (
        '5,10,15,20',
        PCMYKColor(5, 10, 15, 20),
    ),
    (
        '#ff0000',
        HexColor('0xff0000'),
    ),
])
def test_config(parse_color, color_value, expected_color):
    color = parse_color(color_value)
    assert color == expected_color
コード例 #28
0
    def __init__(self,
                 data: list,
                 font,
                 font_size,
                 x_axis_params,
                 box_width,
                 box_height,
                 chart_width,
                 chart_height,
                 width=550,
                 height=215,
                 *args,
                 **kw):
        logger.debug(
            "Generating 3D horizontal bar chart with data:\n{0}\n".format(
                json.dumps(data, indent=2)))

        num_teams = len(data)
        sorted_data = sorted(data, key=lambda x: x[3])

        data_colors = [[0, 0, 0, 0, 100]] * num_teams

        data_min = sorted_data[0]
        data_max = sorted_data[-1]

        data_without_min_max = sorted_data[1:-1]

        data_colors[data_min[0]] = [100, 0, 100, 0, 100]  # green
        data_colors[data_max[0]] = [0, 100, 100, 0, 100]  # red

        count = 1
        for team in data_without_min_max:
            data_colors[team[0]] = [
                100 - ((100 / num_teams) * count), (100 / num_teams) * count,
                100, 0, 100
            ]
            count += 1

        Drawing.__init__(self, width, height, *args, **kw)
        self._add(self,
                  HorizontalBarChart3D(),
                  name="chart",
                  validate=None,
                  desc=None)
        self._add(self,
                  Label(),
                  name="XLabel",
                  validate=None,
                  desc="The label on the horizontal axis")

        self.width = box_width
        self.height = box_height

        self.chart.x = 3.5 * len(max([team[1] for team in data], key=len))
        self.chart.y = -20

        self.chart.data = [[team[3] for team in data]]
        self.chart.width = chart_width
        self.chart.height = chart_height

        self.XLabel.fontName = font
        self.XLabel.fontSize = font_size
        self.XLabel.x = 275
        self.XLabel.y = -50
        self.XLabel.textAnchor = "middle"
        self.XLabel.maxWidth = 500
        self.XLabel.height = 20
        self.XLabel._text = x_axis_params[0]

        self.chart.valueAxis.forceZero = 1
        self.chart.valueAxis.visibleTicks = True
        self.chart.valueAxis.labels.boxAnchor = "autox"
        self.chart.valueAxis.valueMin = x_axis_params[1]
        self.chart.valueAxis.valueMax = x_axis_params[2]
        self.chart.valueAxis.valueStep = x_axis_params[3]
        self.chart.valueAxis.labels.fontName = font
        self.chart.valueAxis.labels.fontSize = font_size - 4
        self.chart.valueAxis.labels.rightPadding = 0
        self.chart.valueAxis.labels.dx = 1

        self.chart.categoryAxis.categoryNames = [team[1] for team in data]
        self.chart.categoryAxis.labels.fontName = font
        self.chart.categoryAxis.labels.fontSize = font_size - 4
        for i in range(0, num_teams):
            self.chart.categoryAxis.labels[i].fillColor = PCMYKColor(
                *data_colors[i])

        self.chart.barWidth = 20
        for i in range(0, num_teams):
            self.chart.bars[(0, i)].fillColor = PCMYKColor(*data_colors[i])
コード例 #29
0
ファイル: excelcolors.py プロジェクト: fhelmli/homeNOWG2
#import pythonista
# define standard colors to mimic those used by Microsoft Excel
from reportlab.lib.colors import CMYKColor, PCMYKColor

#colour names as comments at the end of each line are as a memory jogger ONLY
#NOT HTML named colours!

#Main colours as used for bars etc
color01 = PCMYKColor(40, 40, 0, 0)  # Lavender
color02 = PCMYKColor(0, 66, 33, 39)  # Maroon
color03 = PCMYKColor(0, 0, 20, 0)  # Yellow
color04 = PCMYKColor(20, 0, 0, 0)  # Cyan
color05 = PCMYKColor(0, 100, 0, 59)  # Purple
color06 = PCMYKColor(0, 49, 49, 0)  # Salmon
color07 = PCMYKColor(100, 49, 0, 19)  # Blue
color08 = PCMYKColor(20, 20, 0, 0)  # PaleLavender
color09 = PCMYKColor(100, 100, 0, 49)  # NavyBlue
color10 = PCMYKColor(0, 100, 0, 0)  # Purple

#Highlight colors - eg for the tops of bars
color01Light = PCMYKColor(39, 39, 0, 25)  # Light Lavender
color02Light = PCMYKColor(0, 66, 33, 54)  # Light Maroon
color03Light = PCMYKColor(0, 0, 19, 25)  # Light Yellow
color04Light = PCMYKColor(19, 0, 0, 25)  # Light Cyan
color05Light = PCMYKColor(0, 100, 0, 69)  # Light Purple
color06Light = PCMYKColor(0, 49, 49, 25)  # Light Salmon
color07Light = PCMYKColor(100, 49, 0, 39)  # Light Blue
color08Light = PCMYKColor(19, 19, 0, 25)  # Light PaleLavender
color09Light = PCMYKColor(100, 100, 0, 62)  # Light NavyBlue
color10Light = PCMYKColor(0, 100, 0, 25)  # Light Purple
コード例 #30
0
                    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")