Exemple #1
0
    def render_full(self, target, **options):
        orientation = options.pop("orientation", "vertical")

        cells = []
        for sigil, description, bg in target.legend:
            bg = colors.RGBToXTerm(*bg)
            fg = colors.XTermTextForBackground(bg)
            if sigil:
                title = "%s (%s)" % (description, sigil)
            else:
                title = description
            cell = text.Cell(value=title,
                             highlights=[dict(bg=bg, fg=fg, start=0, end=-1)],
                             colorizer=self.renderer.colorizer,
                             padding=2,
                             align="c")
            cells.append(cell)

        if orientation == "vertical":
            legend = text.StackedCell(*cells, table_align=False)
        elif orientation == "horizontal":
            legend = text.JoinedCell(*cells)
        else:
            raise ValueError("Invalid orientation %s." % orientation)

        if target.notes:
            cell = text.Cell(target.notes)
            legend = text.StackedCell(cell, legend, table_align=False)

        return legend
Exemple #2
0
    def render_full(self, target, **options):
        column_headers = []
        row_headers = []

        for row_header in target.row_headers or ():
            row_headers.append(text.Cell(row_header, align="r", padding=1))

        # If we're prepending row headers we need an extra column on the left.
        if row_headers:
            column_headers.append(text.Cell(target.caption or "-", padding=1))
        for column_header in target.column_headers:
            column_headers.append(
                text.Cell(column_header, align="c", padding=1))

        rows = [text.JoinedCell(*column_headers, tablesep="")]
        for idx, row in enumerate(target.rows):
            cells = []
            if row_headers:
                cells.append(row_headers[idx])

            for cell in row:
                fg = cell.get("fg")
                bg = cell.get("bg")
                heat = cell.get("heat")
                if heat and not bg:
                    bg = colors.HeatToRGB(heat, greyscale=target.greyscale)

                bg = colors.RGBToXTerm(*bg) if bg else None

                if bg and not fg:
                    fg = colors.XTermTextForBackground(bg)

                cells.append(
                    text.Cell(value=unicode(cell.get("value", "-")),
                              highlights=[
                                  dict(bg=bg,
                                       fg=fg,
                                       start=0,
                                       end=-1,
                                       bold=True)
                              ],
                              colorizer=self.renderer.colorizer,
                              padding=1))

            rows.append(text.JoinedCell(*cells, tablesep="", align="l"))

        return text.StackedCell(*rows, align="l")