예제 #1
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")
예제 #2
0
def HeatmapLegend():
    return MapLegend([(None, "%.1f" % (heat / 10.0),
                       colors.HeatToRGB(heat / 10.0)) for heat in xrange(11)])
예제 #3
0
def HeatmapLegend():
    return MapLegend([(None, "%.1f" % (old_div(heat, 10.0)),
                       colors.HeatToRGB(old_div(heat, 10.0)))
                      for heat in range(11)])