Python Прямоугольник отчета не отображается за текстом - PullRequest
0 голосов
/ 20 апреля 2020

Я создаю PDF-файл, в котором я пытаюсь показать текст поверх цветного прямоугольника, но прямоугольник всегда отображается поверх текста, и я не могу получить прямоугольник позади.

def coloured_box(self, metric: str, x: float, y: float):
    """
    Draw a coloured box where the colour is determined on the rank of the metric.
    :param metric: The metric to make the box for
    :param x: The left of box
    :param y: The bottom of the box
    :return: A coloured box drawn
    """
    width = 50
    if metric in ['transfers', 'nad', 'failures']:
        inverse = True
    else:
        inverse = False
    # Return the colour values to fill the rect (this works)
    fill_colour = self.fill_colour(self.ranks(metric, 'rank'), self.ranks(metric, 'total'), inverse)
    self.report.setFillColorRGB(fill_colour[0], fill_colour[1], fill_colour[2])
    self.report.rect(x-width/2, y, width=width, height=20, stroke=0, fill=1)

# Draw coloured boxes
self.coloured_box('pba', x, top - 25 - 35 * 1)
self.coloured_box('cf', x, top - 25 - 35 * 2)
self.coloured_box('transfers', x, top - 25 - 35 * 3)
self.coloured_box('nad', x, top - 25 - 35 * 4)
self.coloured_box('failures', x, top - 25 - 35 * 5)

# Draw Values
self.default_text()  # Makes the text black and default size and font (
self.report.drawCentredString(x, top - 20 - 35 * 1, str(self.ranks('pba', 'value')))
self.report.drawCentredString(x, top - 20 - 35 * 2, str(self.ranks('cf', 'value')))
self.report.drawCentredString(x, top - 20 - 35 * 3, str(self.ranks('transfers', 'value')))
self.report.drawCentredString(x, top - 20 - 35 * 4, str(self.ranks('nad', 'value')))
self.report.drawCentredString(x, top - 20 - 35 * 5, str(self.ranks('failures', 'value')))

Rect показывается поверх текста, а не текст поверх прямоугольника :

...