API

Render dwo dimensional iterable into customized SVG image.

debug class-attribute

Raise an exception if any element fails to provide color or text.

default_color class-attribute

Color to be used when color(e, x, y) raises or returns None.

default_text class-attribute

Text to be used when text(e, x, y) raises.

flip_x class-attribute

Whether or not to flip X axis.

flip_y class-attribute

Whether or not to flip Y axis.

legend class-attribute

Whether or not to display legend. If legend is empty, it will be hidden anyway.

transpose class-attribute

Whether or not to transpose entire data set.

__init__(self, target) special

If target iterable target is mutable, it can be modified after creating instance of this class.

Source code in gridview/gridview.py
42
43
44
def __init__(self, target):
    """If target iterable `target` is mutable, it can be modified after creating instance of this class."""
    self._target = target

color(self, e, x, y)

Abstract method that returns color assigned to element e. Coordinates are provided as x and y. Color should be HTML compatible, (e.g. '#ff0000' or 'red'). Optionally color can be suffixed with label that builds up legend, e.g. '#ff0000:foobar'. If raises or returns None, default_color will be used.

Source code in gridview/gridview.py
64
65
66
67
def color(self, e, x, y):
    """Abstract method that returns color assigned to element `e`. Coordinates are provided as `x` and `y`. Color should be HTML compatible, (e.g. `'#ff0000'` or `'red'`). Optionally color can be suffixed with label that builds up legend, e.g. `'#ff0000:foobar'`. If raises or returns `None`, `default_color` will be used.
    """
    return None

save(self, path)

Save SVG image into path.

Source code in gridview/gridview.py
46
47
48
49
50
51
52
53
54
55
56
57
58
def save(self, path):
    """Save SVG image into `path`."""
    grid, styles, max_text_size = self._wrap_elements()
    legend_items, max_label_width = self._build_legend(styles)
    grid_cols = len(grid)
    grid_rows = max(len(column) for column in grid)
    if self.transpose:
        grid_cols, grid_rows = grid_rows, grid_cols
    dim = Dimensions(grid_cols, grid_rows, max_text_size, max_label_width, legend_items)
    dwg_size = (dim.image_width, dim.image_height)
    dwg, dwg_styles = self._new_dwg(dim, styles, path, size=dwg_size)
    self._draw_grid(dwg, dim, dwg_styles, grid, legend_items)
    dwg.save()

text(self, e, x, y)

Abstract method that returns stringified version of element e. Coordinates are provided as x and y. If raises, default_text will be used. If returns None, str(e) will be used.

Source code in gridview/gridview.py
60
61
62
def text(self, e, x, y):
    """Abstract method that returns stringified version of element `e`. Coordinates are provided as `x` and `y`. If raises, `default_text` will be used. If returns `None`, `str(e)` will be used."""
    return None